Skip to content

Commit

Permalink
Merge branch 'main' into ndaliya/baggage_implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored Apr 21, 2021
2 parents 6100c6b + ae060d1 commit a908768
Show file tree
Hide file tree
Showing 38 changed files with 410 additions and 339 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ having C++ compiler with [supported C++ standards](#supported-c-versions).

Please refer to [INSTALL.md](./INSTALL.md).

## Quick Start
## Getting Started

As an application owner or the library author, you can find the getting started guide and reference documentation on [opentelemetry-cpp.readthedocs.io](https://opentelemetry-cpp.readthedocs.io/en/latest/)

The `examples/simple` directory contains a minimal program demonstrating how to
instrument a small library using a simple `processor` and console `exporter`,
Expand Down
2 changes: 1 addition & 1 deletion api/docs/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ EXCLUDE_PATTERNS =
# Note that the wildcards are matched against the file with absolute path, so to
# exclude all test directories use the pattern */test/*

EXCLUDE_SYMBOLS =
EXCLUDE_SYMBOLS = "AttributeType"

# The EXAMPLE_PATH tag can be used to specify one or more files or directories
# that contain example code fragments that are included (see the \include
Expand Down
49 changes: 35 additions & 14 deletions api/include/opentelemetry/common/attribute_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,67 @@
OPENTELEMETRY_BEGIN_NAMESPACE
namespace common
{
/// OpenTelemetry signals can be enriched by adding attributes. The
/// \c AttributeValue type is defined as a variant of all attribute value
/// types the OpenTelemetry C++ API supports.
///
/// The following attribute value types are supported by the OpenTelemetry
/// specification:
/// - Primitive types: string, boolean, double precision floating point
/// (IEEE 754-1985) or signed 64 bit integer.
/// - Homogenous arrays of primitive type values.
///
/// \warning
/// \parblock The OpenTelemetry C++ API currently supports several attribute
/// value types that are not covered by the OpenTelemetry specification:
/// - \c uint64_t
/// - \c nostd::span<const uint64_t>
/// - \c nostd::span<uint8_t>
///
/// Those types are reserved for future use and currently should not be
/// used. There are no guarantees around how those values are handled by
/// exporters.
/// \endparblock
using AttributeValue =
nostd::variant<bool,
int32_t,
int64_t,
uint32_t,
uint64_t,
double,
nostd::string_view,
#ifdef HAVE_SPAN_BYTE
// TODO: 8-bit byte arrays / binary blobs are not part of OT spec yet!
// Ref: https:/open-telemetry/opentelemetry-specification/issues/780
nostd::span<const uint8_t>,
#endif
nostd::span<const bool>,
nostd::span<const int32_t>,
nostd::span<const int64_t>,
nostd::span<const uint32_t>,
nostd::span<const uint64_t>,
nostd::span<const double>,
nostd::span<const nostd::string_view>>;
nostd::span<const nostd::string_view>,
// Not currently supported by the specification, but reserved for future use.
// Added to provide support for all primitive C++ types.
uint64_t,
// Not currently supported by the specification, but reserved for future use.
// Added to provide support for all primitive C++ types.
nostd::span<const uint64_t>,
// Not currently supported by the specification, but reserved for future use.
// See https:/open-telemetry/opentelemetry-specification/issues/780
nostd::span<const uint8_t>>;

enum AttributeType
{
kTypeBool,
kTypeInt,
kTypeInt64,
kTypeUInt,
kTypeUInt64,
kTypeDouble,
kTypeString,
#ifdef HAVE_SPAN_BYTE
kTypeSpanByte,
#endif
kTypeSpanBool,
kTypeSpanInt,
kTypeSpanInt64,
kTypeSpanUInt,
kTypeSpanUInt64,
kTypeSpanDouble,
kTypeSpanString
kTypeSpanString,
kTypeUInt64,
kTypeSpanUInt64,
kTypeSpanByte
};

} // namespace common
Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/context/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class Context
next_ = nostd::shared_ptr<DataList>{nullptr};
}

DataList &operator=(DataList &&other)
DataList &operator=(DataList &&other) noexcept
{
key_length_ = other.key_length_;
value_ = std::move(other.value_);
Expand Down
2 changes: 2 additions & 0 deletions api/include/opentelemetry/context/runtime_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class RuntimeContextStorage
*/
virtual bool Detach(Token &token) noexcept = 0;

virtual ~RuntimeContextStorage(){};

protected:
nostd::unique_ptr<Token> CreateToken(const Context &context) noexcept
{
Expand Down
4 changes: 2 additions & 2 deletions examples/batch/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ void initTracer()
// We export `kNumSpans` after every `schedule_delay_millis` milliseconds.
options.max_export_batch_size = kNumSpans;

auto processor = std::shared_ptr<sdktrace::SpanProcessor>(
auto processor = std::unique_ptr<sdktrace::SpanProcessor>(
new sdktrace::BatchSpanProcessor(std::move(exporter), options));

auto provider = nostd::shared_ptr<opentelemetry::trace::TracerProvider>(
new sdktrace::TracerProvider(processor));
new sdktrace::TracerProvider(std::move(processor)));
// Set the global trace provider.
opentelemetry::trace::Provider::SetTracerProvider(provider);
}
Expand Down
42 changes: 42 additions & 0 deletions examples/http/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
cc_binary(
name = "example_http_client",
srcs = [
"client.cc",
"tracer_common.hpp",
],
# TODO: Move copts/linkopts for static CURL usage into shared bzl file.
copts = [
"-DCURL_STATICLIB",
"-DWITH_CURL",
],
linkopts = select({
"//bazel:windows": [
"-DEFAULTLIB:advapi32.lib",
"-DEFAULTLIB:crypt32.lib",
"-DEFAULTLIB:Normaliz.lib",
],
"//conditions:default": [],
}),
deps = [
"//api",
"//exporters/ostream:ostream_span_exporter",
"//ext:headers",
"//ext/src/http/client/curl:http_client_curl",
"//sdk/src/trace",
],
)

cc_binary(
name = "example_http_server",
srcs = [
"server.cc",
"server.hpp",
"tracer_common.hpp",
],
deps = [
"//api",
"//exporters/ostream:ostream_span_exporter",
"//ext:headers",
"//sdk/src/trace",
],
)
9 changes: 5 additions & 4 deletions examples/http/tracer_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ namespace {
void initTracer() {
auto exporter = std::unique_ptr<sdktrace::SpanExporter>(
new opentelemetry::exporter::trace::OStreamSpanExporter);
auto processor = std::shared_ptr<sdktrace::SpanProcessor>(
auto processor = std::unique_ptr<sdktrace::SpanProcessor>(
new sdktrace::SimpleSpanProcessor(std::move(exporter)));
auto provider = nostd::shared_ptr<opentelemetry::trace::TracerProvider>(
new sdktrace::TracerProvider(processor, opentelemetry::sdk::resource::Resource::Create({}),
std::make_shared<opentelemetry::sdk::trace::AlwaysOnSampler>()));
// Default is an always-on sampler.
auto context = std::make_shared<sdktrace::TracerContext>(std::move(processor));
auto provider = nostd::shared_ptr<opentelemetry::trace::TracerProvider>(
new sdktrace::TracerProvider(context));
// Set the global trace provider
opentelemetry::trace::Provider::SetTracerProvider(provider);
}
Expand Down
7 changes: 4 additions & 3 deletions examples/multithreaded/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ void initTracer()
{
auto exporter = std::unique_ptr<sdktrace::SpanExporter>(
new opentelemetry::exporter::trace::OStreamSpanExporter);
auto processor = std::shared_ptr<sdktrace::SpanProcessor>(
auto processor = std::unique_ptr<sdktrace::SpanProcessor>(
new sdktrace::SimpleSpanProcessor(std::move(exporter)));
auto provider = nostd::shared_ptr<opentelemetry::trace::TracerProvider>(
new sdktrace::TracerProvider(processor, opentelemetry::sdk::resource::Resource::Create({})));
auto provider =
nostd::shared_ptr<opentelemetry::trace::TracerProvider>(new sdktrace::TracerProvider(
std::move(processor), opentelemetry::sdk::resource::Resource::Create({})));
// Set the global trace provider
opentelemetry::trace::Provider::SetTracerProvider(provider);
}
Expand Down
5 changes: 3 additions & 2 deletions examples/otlp/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ void InitTracer()
{
// Create OTLP exporter instance
auto exporter = std::unique_ptr<sdktrace::SpanExporter>(new otlp::OtlpExporter(opts));
auto processor = std::shared_ptr<sdktrace::SpanProcessor>(
auto processor = std::unique_ptr<sdktrace::SpanProcessor>(
new sdktrace::SimpleSpanProcessor(std::move(exporter)));
auto provider = nostd::shared_ptr<trace::TracerProvider>(new sdktrace::TracerProvider(processor));
auto provider =
nostd::shared_ptr<trace::TracerProvider>(new sdktrace::TracerProvider(std::move(processor)));
// Set the global trace provider
trace::Provider::SetTracerProvider(provider);
}
Expand Down
5 changes: 2 additions & 3 deletions examples/simple/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ void initTracer()
{
auto exporter = std::unique_ptr<sdktrace::SpanExporter>(
new opentelemetry::exporter::trace::OStreamSpanExporter);
auto processor = std::shared_ptr<sdktrace::SpanProcessor>(
auto processor = std::unique_ptr<sdktrace::SpanProcessor>(
new sdktrace::SimpleSpanProcessor(std::move(exporter)));
auto provider = nostd::shared_ptr<opentelemetry::trace::TracerProvider>(
new sdktrace::TracerProvider(processor, opentelemetry::sdk::resource::Resource::Create({}),
std::make_shared<opentelemetry::sdk::trace::AlwaysOnSampler>()));
new sdktrace::TracerProvider(std::move(processor)));

// Set the global trace provider
opentelemetry::trace::Provider::SetTracerProvider(provider);
Expand Down
19 changes: 6 additions & 13 deletions exporters/etw/include/opentelemetry/exporters/etw/etw_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ using PropertyVariant =
double,
std::string,
const char *,
#ifdef HAVE_SPAN_BYTE
// TODO: 8-bit byte arrays / binary blobs are not part of OT spec yet!
// 8-bit byte arrays / binary blobs are not part of OT spec yet!
// Ref: https:/open-telemetry/opentelemetry-specification/issues/780
std::vector<uint8_t>,
#endif
std::vector<bool>,
std::vector<int32_t>,
std::vector<int64_t>,
Expand All @@ -65,9 +63,7 @@ enum PropertyType
kTypeDouble,
kTypeString,
kTypeCString,
#ifdef HAVE_SPAN_BYTE
kTypeSpanByte,
#endif
kTypeSpanBool,
kTypeSpanInt,
kTypeSpanInt64,
Expand Down Expand Up @@ -229,11 +225,11 @@ class PropertyValue : public PropertyVariant
PropertyVariant::operator=(nostd::string_view(nostd::get<nostd::string_view>(v)).data());
break;
};
#ifdef HAVE_SPAN_BYTE

case common::AttributeType::kTypeSpanByte:
PropertyVariant::operator=(to_vector(nostd::get<nostd::span<const uint8_t>>(v)));
break;
#endif

case common::AttributeType::kTypeSpanBool:
PropertyVariant::operator=(to_vector(nostd::get<nostd::span<const bool>>(v)));
break;
Expand Down Expand Up @@ -306,13 +302,10 @@ class PropertyValue : public PropertyVariant
return nostd::string_view(data, (data) ? strlen(data) : 0);
break;
}

#ifdef HAVE_SPAN_BYTE
case common::AttributeType::kTypeSpanByte:
value = to_span(nostd::get<std::vector<uint8_t>>(self));
case PropertyType::kTypeSpanByte: {
value = to_span(nostd::get<std::vector<uint8_t>>(*this));
break;
#endif

}
case PropertyType::kTypeSpanBool: {
const auto &vec = nostd::get<std::vector<bool>>(*this);
// FIXME: sort out how to remap from vector<bool> to span<bool>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,7 @@ class ETWProvider
# endif

// TODO: arrays are not supported yet
# ifdef HAVE_SPAN_BYTE
case common::AttributeType::TYPE_SPAN_BYTE:
# endif
case PropertyType::kTypeSpanByte:
case PropertyType::kTypeSpanBool:
case PropertyType::kTypeSpanInt:
case PropertyType::kTypeSpanInt64:
Expand Down Expand Up @@ -531,9 +529,7 @@ class ETWProvider
# endif

// TODO: arrays are not supported
# ifdef HAVE_SPAN_BYTE
case PropertyType::kTypeSpanByte:
# endif
case PropertyType::kTypeSpanBool:
case PropertyType::kTypeSpanInt:
case PropertyType::kTypeSpanInt64:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ class OStreamSpanExporter final : public sdktrace::SpanExporter
#if __cplusplus < 201402L
nostd::visit(OwnedAttributeValueVisitor(*this), value);
#else
nostd::visit([this](auto &&arg) { print_value(arg); }, value);
nostd::visit(
[this](auto &&arg) {
/* explicit this is needed by some gcc versions (observed with v5.4.0)*/
this->print_value(arg);
},
value);
#endif
}

Expand Down
8 changes: 0 additions & 8 deletions exporters/otlp/src/recordable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,8 @@ namespace otlp

//
// See `attribute_value.h` for details.
// Expecting to remove the two feature gates for:
// - HAVE_SPAN_BYTE - proposal for binary type or byte array (uint8_t[]).
//
#if defined(HAVE_SPAN_BYTE)
const int kAttributeValueSize = 15;
#else
const int kAttributeValueSize = 14;
#endif

void Recordable::SetIdentity(const opentelemetry::trace::SpanContext &span_context,
opentelemetry::trace::SpanId parent_span_id) noexcept
Expand Down Expand Up @@ -70,15 +64,13 @@ void PopulateAttribute(opentelemetry::proto::common::v1::KeyValue *attribute,
attribute->mutable_value()->set_string_value(nostd::get<nostd::string_view>(value).data(),
nostd::get<nostd::string_view>(value).size());
}
#ifdef HAVE_SPAN_BYTE
else if (nostd::holds_alternative<nostd::span<const uint8_t>>(value))
{
for (const auto &val : nostd::get<nostd::span<const uint8_t>>(value))
{
attribute->mutable_value()->mutable_array_value()->add_values()->set_int_value(val);
}
}
#endif
else if (nostd::holds_alternative<nostd::span<const bool>>(value))
{
for (const auto &val : nostd::get<nostd::span<const bool>>(value))
Expand Down
6 changes: 3 additions & 3 deletions exporters/otlp/test/otlp_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ TEST_F(OtlpExporterTestPeer, ExportIntegrationTest)

auto exporter = GetExporter(stub_interface);

auto processor = std::shared_ptr<sdk::trace::SpanProcessor>(
auto processor = std::unique_ptr<sdk::trace::SpanProcessor>(
new sdk::trace::SimpleSpanProcessor(std::move(exporter)));
auto provider =
nostd::shared_ptr<trace::TracerProvider>(new sdk::trace::TracerProvider(processor));
auto provider = nostd::shared_ptr<trace::TracerProvider>(
new sdk::trace::TracerProvider(std::move(processor)));
auto tracer = provider->GetTracer("test");

EXPECT_CALL(*mock_stub, Export(_, _, _))
Expand Down
Loading

0 comments on commit a908768

Please sign in to comment.