From b253a2018e7c5e851fef4d716d032c953e521b2b Mon Sep 17 00:00:00 2001 From: PaurushGarg Date: Wed, 29 Sep 2021 13:53:47 -0700 Subject: [PATCH 01/16] fix-368: Consistent NameSpace Scope Resolution in .cc files --- .../propagation/baggage_propagator_test.cc | 2 +- api/test/common/kv_properties_test.cc | 19 +-- .../propagation/composite_propagator_test.cc | 6 +- api/test/logs/logger_test.cc | 18 ++- api/test/metrics/meter_provider_test.cc | 15 +- api/test/nostd/utility_test.cc | 28 ++-- api/test/trace/noop_test.cc | 2 +- .../propagation/http_text_format_test.cc | 4 +- api/test/trace/provider_test.cc | 14 +- api/test/trace/span_benchmark.cc | 7 +- api/test/trace/span_context_test.cc | 5 +- docs/building-with-stdlib.md | 2 +- examples/batch/main.cc | 17 ++- examples/grpc/client.cc | 20 +-- examples/grpc/server.cc | 14 +- examples/http/client.cc | 31 +++-- examples/http/server.cc | 11 +- examples/metrics_simple/main.cc | 15 +- examples/multi_processor/main.cc | 18 +-- examples/multithreaded/main.cc | 14 +- examples/otlp/http_main.cc | 2 +- examples/plugin/plugin/factory_impl.cc | 23 ++-- examples/plugin/plugin/tracer.cc | 10 +- examples/simple/main.cc | 6 +- examples/zipkin/main.cc | 7 +- examples/zpages/zpages_example.cc | 9 +- .../elasticsearch/src/es_log_exporter.cc | 2 +- exporters/jaeger/src/recordable.cc | 9 +- .../jaeger/test/jaeger_recordable_test.cc | 37 ++--- exporters/ostream/src/span_exporter.cc | 13 +- exporters/ostream/test/ostream_log_test.cc | 33 +++-- .../ostream/test/ostream_metrics_test.cc | 45 +++--- exporters/ostream/test/ostream_span_test.cc | 81 +++++------ exporters/otlp/src/otlp_http_exporter.cc | 6 +- exporters/otlp/src/otlp_recordable.cc | 55 ++++---- .../otlp/test/otlp_grpc_exporter_benchmark.cc | 8 +- .../otlp/test/otlp_http_exporter_test.cc | 23 ++-- exporters/otlp/test/otlp_recordable_test.cc | 33 +++-- .../test/prometheus_collector_test.cc | 14 +- exporters/zipkin/src/recordable.cc | 33 +++-- .../zipkin/test/zipkin_recordable_test.cc | 62 +++++---- .../client/curl/http_client_factory_curl.cc | 14 +- ext/src/zpages/tracez_http_server.cc | 21 +-- ext/src/zpages/tracez_processor.cc | 5 +- ext/test/http/curl_http_test.cc | 9 +- ext/test/w3c_tracecontext_test/main.cc | 45 +++--- ext/test/zpages/threadsafe_span_data_test.cc | 26 ++-- .../zpages/tracez_data_aggregator_test.cc | 44 +++--- ext/test/zpages/tracez_processor_test.cc | 38 ++--- sdk/src/logs/logger.cc | 26 ++-- sdk/src/logs/logger_provider.cc | 17 ++- sdk/src/metrics/meter_provider.cc | 7 +- sdk/src/trace/random_id_generator.cc | 14 +- sdk/src/trace/span.cc | 11 +- sdk/src/trace/tracer_context.cc | 5 +- sdk/src/trace/tracer_provider.cc | 15 +- sdk/test/logs/log_record_test.cc | 26 ++-- sdk/test/logs/logger_provider_sdk_test.cc | 18 +-- sdk/test/logs/logger_sdk_test.cc | 9 +- sdk/test/logs/simple_log_processor_test.cc | 5 +- sdk/test/metrics/exact_aggregator_test.cc | 31 +++-- sdk/test/metrics/gauge_aggregator_test.cc | 23 ++-- sdk/test/metrics/histogram_aggregator_test.cc | 2 +- sdk/test/metrics/meter_test.cc | 38 ++--- .../min_max_sum_count_aggregator_test.cc | 25 ++-- sdk/test/metrics/sketch_aggregator_test.cc | 4 +- sdk/test/metrics/ungrouped_processor_test.cc | 130 +++++++++--------- sdk/test/resource/resource_test.cc | 37 ++--- sdk/test/trace/always_off_sampler_test.cc | 8 +- sdk/test/trace/parent_sampler_test.cc | 4 +- sdk/test/trace/sampler_benchmark.cc | 7 +- sdk/test/trace/span_data_test.cc | 53 +++---- sdk/test/trace/trace_id_ratio_sampler_test.cc | 19 +-- sdk/test/trace/tracer_test.cc | 29 ++-- 74 files changed, 830 insertions(+), 708 deletions(-) diff --git a/api/test/baggage/propagation/baggage_propagator_test.cc b/api/test/baggage/propagation/baggage_propagator_test.cc index 0f1f8f338c..126adf5a20 100644 --- a/api/test/baggage/propagation/baggage_propagator_test.cc +++ b/api/test/baggage/propagation/baggage_propagator_test.cc @@ -48,7 +48,7 @@ TEST(BaggagePropagatorTest, ExtractAndInjectBaggage) { // create header string for baggage larger than allowed size (kMaxKeyValueSize) std::string very_large_baggage_header = - std::string(baggage::Baggage::kMaxKeyValueSize / 2 + 1, 'k') + "=" + + std::string(baggage::Baggage::kMaxKeyValueSize / 2 + 1, 'k') + "=" std::string(baggage::Baggage::kMaxKeyValueSize / 2 + 1, 'v'); std::map baggages = { diff --git a/api/test/common/kv_properties_test.cc b/api/test/common/kv_properties_test.cc index e5d9a2439e..69fd795cb5 100644 --- a/api/test/common/kv_properties_test.cc +++ b/api/test/common/kv_properties_test.cc @@ -13,11 +13,12 @@ using namespace opentelemetry; using opentelemetry::common::KeyValueProperties; +namespace nostd = opentelemetry::nostd; // Test constructor that takes a key-value pair TEST(EntryTest, KeyValueConstruction) { - opentelemetry::nostd::string_view key = "test_key"; - opentelemetry::nostd::string_view val = "test_value"; + nostd::string_view key = "test_key"; + nostd::string_view val = "test_value"; KeyValueProperties::Entry e(key, val); EXPECT_EQ(key.size(), e.GetKey().size()); @@ -49,7 +50,7 @@ TEST(EntryTest, Assignment) TEST(EntryTest, SetValue) { KeyValueProperties::Entry e("test_key", "test_value"); - opentelemetry::nostd::string_view new_val = "new_value"; + nostd::string_view new_val = "new_value"; e.SetValue(new_val); EXPECT_EQ(new_val.size(), e.GetValue().size()); @@ -65,7 +66,7 @@ TEST(KVStringTokenizer, SinglePair) { bool valid_kv; nostd::string_view key, value; - opentelemetry::nostd::string_view str = "k1=v1"; + nostd::string_view str = "k1=v1"; KeyValueStringTokenizerOptions opts; KeyValueStringTokenizer tk(str, opts); EXPECT_TRUE(tk.next(valid_kv, key, value)); @@ -79,7 +80,7 @@ TEST(KVStringTokenizer, AcceptEmptyEntries) { bool valid_kv; nostd::string_view key, value; - opentelemetry::nostd::string_view str = ":k1=v1::k2=v2: "; + nostd::string_view str = ":k1=v1::k2=v2: "; KeyValueStringTokenizerOptions opts; opts.member_separator = ':'; opts.ignore_empty_members = false; @@ -100,7 +101,7 @@ TEST(KVStringTokenizer, AcceptEmptyEntries) TEST(KVStringTokenizer, ValidPairsWithEmptyEntries) { - opentelemetry::nostd::string_view str = "k1:v1===k2:v2=="; + nostd::string_view str = "k1:v1===k2:v2=="; bool valid_kv; nostd::string_view key, value; KeyValueStringTokenizerOptions opts; @@ -123,7 +124,7 @@ TEST(KVStringTokenizer, ValidPairsWithEmptyEntries) TEST(KVStringTokenizer, InvalidPairs) { - opentelemetry::nostd::string_view str = "k1=v1,invalid ,, k2=v2 ,invalid"; + nostd::string_view str = "k1=v1,invalid ,, k2=v2 ,invalid"; KeyValueStringTokenizer tk(str); bool valid_kv; nostd::string_view key, value; @@ -218,8 +219,8 @@ TEST(KeyValueProperties, GetAllEntries) std::vector> kv_pairs = { {"k1", "v1"}, {"k2", "v2"}, {"k3", "v3"}}; const size_t kNumPairs = 3; - opentelemetry::nostd::string_view keys[kNumPairs] = {"k1", "k2", "k3"}; - opentelemetry::nostd::string_view values[kNumPairs] = {"v1", "v2", "v3"}; + nostd::string_view keys[kNumPairs] = {"k1", "k2", "k3"}; + nostd::string_view values[kNumPairs] = {"v1", "v2", "v3"}; auto kv_properties = KeyValueProperties(kv_pairs); size_t index = 0; diff --git a/api/test/context/propagation/composite_propagator_test.cc b/api/test/context/propagation/composite_propagator_test.cc index d516fe17d2..918f8cedd4 100644 --- a/api/test/context/propagation/composite_propagator_test.cc +++ b/api/test/context/propagation/composite_propagator_test.cc @@ -118,7 +118,7 @@ TEST_F(CompositePropagatorTest, Inject) return true; }); EXPECT_EQ(fields.size(), 3); - EXPECT_EQ(fields[0], opentelemetry::trace::propagation::kTraceParent); - EXPECT_EQ(fields[1], opentelemetry::trace::propagation::kTraceState); - EXPECT_EQ(fields[2], opentelemetry::trace::propagation::kB3CombinedHeader); + EXPECT_EQ(fields[0], trace::propagation::kTraceParent); + EXPECT_EQ(fields[1], trace::propagation::kTraceState); + EXPECT_EQ(fields[2], trace::propagation::kB3CombinedHeader); } diff --git a/api/test/logs/logger_test.cc b/api/test/logs/logger_test.cc index 107dbe5ec0..0c5e9b2160 100644 --- a/api/test/logs/logger_test.cc +++ b/api/test/logs/logger_test.cc @@ -18,6 +18,10 @@ using opentelemetry::logs::Severity; using opentelemetry::nostd::shared_ptr; using opentelemetry::nostd::span; using opentelemetry::nostd::string_view; +namespace common = opentelemetry::common; +namespace nostd = opentelemetry::nostd; +namespace trace = opentelemetry::trace; + // Check that the default logger is a noop logger instance TEST(Logger, GetLoggerDefault) @@ -72,17 +76,17 @@ TEST(Logger, LogMethodOverloads) // Define a basic Logger class class TestLogger : public Logger { - const opentelemetry::nostd::string_view GetName() noexcept override { return "test logger"; } + const nostd::string_view GetName() noexcept override { return "test logger"; } void Log(Severity severity, string_view name, string_view body, - const opentelemetry::common::KeyValueIterable &resource, - const opentelemetry::common::KeyValueIterable &attributes, - opentelemetry::trace::TraceId trace_id, - opentelemetry::trace::SpanId span_id, - opentelemetry::trace::TraceFlags trace_flags, - opentelemetry::common::SystemTimestamp timestamp) noexcept override + const common::KeyValueIterable &resource, + const common::KeyValueIterable &attributes, + trace::TraceId trace_id, + trace::SpanId span_id, + trace::TraceFlags trace_flags, + common::SystemTimestamp timestamp) noexcept override {} }; diff --git a/api/test/metrics/meter_provider_test.cc b/api/test/metrics/meter_provider_test.cc index 862ce4a7fe..9a50406086 100644 --- a/api/test/metrics/meter_provider_test.cc +++ b/api/test/metrics/meter_provider_test.cc @@ -9,14 +9,15 @@ using opentelemetry::metrics::Meter; using opentelemetry::metrics::MeterProvider; using opentelemetry::metrics::Provider; +namespace nostd = opentelemetry::nostd; class TestProvider : public MeterProvider { - opentelemetry::nostd::shared_ptr GetMeter( - opentelemetry::nostd::string_view library_name, - opentelemetry::nostd::string_view library_version) override + nostd::shared_ptr GetMeter( + nostd::string_view library_name, + nostd::string_view library_version) override { - return opentelemetry::nostd::shared_ptr(nullptr); + return nostd::shared_ptr(nullptr); } }; @@ -28,16 +29,16 @@ TEST(Provider, GetMeterProviderDefault) TEST(Provider, SetMeterProvider) { - auto tf = opentelemetry::nostd::shared_ptr(new TestProvider()); + auto tf = nostd::shared_ptr(new TestProvider()); Provider::SetMeterProvider(tf); ASSERT_EQ(tf, Provider::GetMeterProvider()); } TEST(Provider, MultipleMeterProviders) { - auto tf = opentelemetry::nostd::shared_ptr(new TestProvider()); + auto tf = nostd::shared_ptr(new TestProvider()); Provider::SetMeterProvider(tf); - auto tf2 = opentelemetry::nostd::shared_ptr(new TestProvider()); + auto tf2 = nostd::shared_ptr(new TestProvider()); Provider::SetMeterProvider(tf2); ASSERT_NE(Provider::GetMeterProvider(), tf); diff --git a/api/test/nostd/utility_test.cc b/api/test/nostd/utility_test.cc index c6ee9e2102..d81de1f980 100644 --- a/api/test/nostd/utility_test.cc +++ b/api/test/nostd/utility_test.cc @@ -9,13 +9,15 @@ #include +namespace nostd = opentelemetry::nostd; + template -auto IsDataCallable(const T &t) -> decltype(opentelemetry::nostd::data(t), std::true_type{}); +auto IsDataCallable(const T &t) -> decltype(nostd::data(t), std::true_type{}); std::false_type IsDataCallable(...); template -auto IsSizeCallable(const T &t) -> decltype(opentelemetry::nostd::size(t), std::true_type{}); +auto IsSizeCallable(const T &t) -> decltype(nostd::size(t), std::true_type{}); std::false_type IsSizeCallable(...); @@ -27,9 +29,9 @@ TEST(UtilityTest, Data) int x = 0; std::ignore = x; - EXPECT_EQ(opentelemetry::nostd::data(v), v.data()); - EXPECT_EQ(opentelemetry::nostd::data(array), array); - EXPECT_EQ(opentelemetry::nostd::data(list), list.begin()); + EXPECT_EQ(nostd::data(v), v.data()); + EXPECT_EQ(nostd::data(array), array); + EXPECT_EQ(nostd::data(list), list.begin()); EXPECT_FALSE(decltype(IsDataCallable(x)){}); } @@ -40,18 +42,18 @@ TEST(UtilityTest, Size) int x = 0; std::ignore = x; - EXPECT_EQ(opentelemetry::nostd::size(v), v.size()); - EXPECT_EQ(opentelemetry::nostd::size(array), 3); + EXPECT_EQ(nostd::size(v), v.size()); + EXPECT_EQ(nostd::size(array), 3); EXPECT_FALSE(decltype(IsSizeCallable(x)){}); } TEST(UtilityTest, MakeIndexSequence) { - EXPECT_TRUE((std::is_same, - opentelemetry::nostd::index_sequence<>>::value)); - EXPECT_TRUE((std::is_same, - opentelemetry::nostd::index_sequence<0>>::value)); - EXPECT_TRUE((std::is_same, - opentelemetry::nostd::index_sequence<0, 1>>::value)); + EXPECT_TRUE((std::is_same, + nostd::index_sequence<>>::value)); + EXPECT_TRUE((std::is_same, + nostd::index_sequence<0>>::value)); + EXPECT_TRUE((std::is_same, + nostd::index_sequence<0, 1>>::value)); } diff --git a/api/test/trace/noop_test.cc b/api/test/trace/noop_test.cc index b17faf64d4..130496faf0 100644 --- a/api/test/trace/noop_test.cc +++ b/api/test/trace/noop_test.cc @@ -36,7 +36,7 @@ TEST(NoopTest, UseNoopTracers) EXPECT_EQ(s1->IsRecording(), false); - s1->SetStatus(opentelemetry::trace::StatusCode::kUnset, "span unset"); + s1->SetStatus(trace_api::StatusCode::kUnset, "span unset"); s1->UpdateName("test_name"); diff --git a/api/test/trace/propagation/http_text_format_test.cc b/api/test/trace/propagation/http_text_format_test.cc index a815920a83..d42d508860 100644 --- a/api/test/trace/propagation/http_text_format_test.cc +++ b/api/test/trace/propagation/http_text_format_test.cc @@ -206,6 +206,6 @@ TEST(GlobalPropagator, SetAndGet) return true; }); EXPECT_EQ(fields.size(), 2); - EXPECT_EQ(fields[0], opentelemetry::trace::propagation::kTraceParent); - EXPECT_EQ(fields[1], opentelemetry::trace::propagation::kTraceState); + EXPECT_EQ(fields[0], trace::propagation::kTraceParent); + EXPECT_EQ(fields[1], trace::propagation::kTraceState); } diff --git a/api/test/trace/provider_test.cc b/api/test/trace/provider_test.cc index ca4555535c..d3ef5874d5 100644 --- a/api/test/trace/provider_test.cc +++ b/api/test/trace/provider_test.cc @@ -10,14 +10,16 @@ using opentelemetry::trace::Provider; using opentelemetry::trace::Tracer; using opentelemetry::trace::TracerProvider; +namespace nostd = opentelemetry::nostd; + class TestProvider : public TracerProvider { - opentelemetry::nostd::shared_ptr GetTracer( - opentelemetry::nostd::string_view library_name, - opentelemetry::nostd::string_view library_version, - opentelemetry::nostd::string_view schema_url) override + nostd::shared_ptr GetTracer( + nostd::string_view library_name, + nostd::string_view library_version, + nostd::string_view schema_url) override { - return opentelemetry::nostd::shared_ptr(nullptr); + return nostd::shared_ptr(nullptr); } }; @@ -29,7 +31,7 @@ TEST(Provider, GetTracerProviderDefault) TEST(Provider, SetTracerProvider) { - auto tf = opentelemetry::nostd::shared_ptr(new TestProvider()); + auto tf = nostd::shared_ptr(new TestProvider()); Provider::SetTracerProvider(tf); ASSERT_EQ(tf, Provider::GetTracerProvider()); } diff --git a/api/test/trace/span_benchmark.cc b/api/test/trace/span_benchmark.cc index 238e8ca8a0..ef14cd4ca3 100644 --- a/api/test/trace/span_benchmark.cc +++ b/api/test/trace/span_benchmark.cc @@ -14,13 +14,14 @@ using opentelemetry::trace::SpanContext; namespace trace_api = opentelemetry::trace; namespace nostd = opentelemetry::nostd; +namespace context = opentelemetry::context; namespace { -std::shared_ptr initTracer() +std::shared_ptr initTracer() { - return std::shared_ptr(new trace_api::NoopTracer()); + return std::shared_ptr(new trace_api::NoopTracer()); } // Test to measure performance for span creation @@ -108,7 +109,7 @@ void BM_SpanCreationWitContextPropagation(benchmark::State &state) while (state.KeepRunning()) { - auto current_ctx = opentelemetry::context::RuntimeContext::GetCurrent(); + auto current_ctx = context::RuntimeContext::GetCurrent(); auto outer_span_context = SpanContext(trace_id, span_id, trace_api::TraceFlags(), false); auto outer_span = nostd::shared_ptr(new trace_api::DefaultSpan(outer_span_context)); diff --git a/api/test/trace/span_context_test.cc b/api/test/trace/span_context_test.cc index c56b6df6dd..a3fd9a84a7 100644 --- a/api/test/trace/span_context_test.cc +++ b/api/test/trace/span_context_test.cc @@ -8,6 +8,7 @@ #include using opentelemetry::trace::SpanContext; +namespace trace_api = opentelemetry::trace; TEST(SpanContextTest, IsSampled) { @@ -49,6 +50,6 @@ TEST(SpanContextTest, Invalid) EXPECT_FALSE(s1.IsValid()); // Test that trace id and span id are invalid - EXPECT_EQ(s1.trace_id(), opentelemetry::trace::TraceId()); - EXPECT_EQ(s1.span_id(), opentelemetry::trace::SpanId()); + EXPECT_EQ(s1.trace_id(), trace_api::TraceId()); + EXPECT_EQ(s1.span_id(), trace_api::SpanId()); } diff --git a/docs/building-with-stdlib.md b/docs/building-with-stdlib.md index 26e09f9d39..25ba8be07c 100644 --- a/docs/building-with-stdlib.md +++ b/docs/building-with-stdlib.md @@ -5,7 +5,7 @@ process (environment where ABI compat is not a requirement), or for "header-only" implementation of SDK. Proposed approach cannot be employed for shared libs in environments where ABI -compatibility is required. OpenTelemetry SDK binary compiled with `compiler A + +compatibility is required. OpenTelemetry SDK binary compiled with `compiler A STL B` will not be ABI -compatible with the main executable compiled with `compiler C + STL D`. diff --git a/examples/batch/main.cc b/examples/batch/main.cc index 3c9a168071..f03f58fb58 100644 --- a/examples/batch/main.cc +++ b/examples/batch/main.cc @@ -11,6 +11,9 @@ #include constexpr int kNumSpans = 10; +namespace trace_api = opentelemetry::trace; +namespace resource = opentelemetry::sdk::resource; +namespace exporter_trace = opentelemetry::exporter::trace; namespace { @@ -18,7 +21,7 @@ namespace void initTracer() { auto exporter = std::unique_ptr( - new opentelemetry::exporter::trace::OStreamSpanExporter); + new exporter_trace::OStreamSpanExporter); // CONFIGURE BATCH SPAN PROCESSOR PARAMETERS @@ -31,22 +34,22 @@ void initTracer() // We export `kNumSpans` after every `schedule_delay_millis` milliseconds. options.max_export_batch_size = kNumSpans; - opentelemetry::sdk::resource::ResourceAttributes attributes = {{"service", "test_service"}, + resource::ResourceAttributes attributes = {{"service", "test_service"}, {"version", (uint32_t)1}}; - auto resource = opentelemetry::sdk::resource::Resource::Create(attributes); + auto resource = resource::Resource::Create(attributes); auto processor = std::unique_ptr( new sdktrace::BatchSpanProcessor(std::move(exporter), options)); - auto provider = nostd::shared_ptr( + auto provider = nostd::shared_ptr( new sdktrace::TracerProvider(std::move(processor), resource)); // Set the global trace provider. - opentelemetry::trace::Provider::SetTracerProvider(provider); + trace_api::Provider::SetTracerProvider(provider); } -nostd::shared_ptr get_tracer() +nostd::shared_ptr get_tracer() { - auto provider = opentelemetry::trace::Provider::GetTracerProvider(); + auto provider = trace_api::Provider::GetTracerProvider(); return provider->GetTracer("foo_library"); } diff --git a/examples/grpc/client.cc b/examples/grpc/client.cc index 21149c1958..2b51058dba 100644 --- a/examples/grpc/client.cc +++ b/examples/grpc/client.cc @@ -25,7 +25,7 @@ using grpc_example::GreetResponse; namespace { - +namespace context = opentelemetry::context; using namespace opentelemetry::trace; class GreeterClient { @@ -40,8 +40,8 @@ class GreeterClient ClientContext context; request.set_request("Nice to meet you!"); - opentelemetry::trace::StartSpanOptions options; - options.kind = opentelemetry::trace::SpanKind::kClient; + StartSpanOptions options; + options.kind = SpanKind::kClient; std::string span_name = "GreeterClient/Greet"; auto span = get_tracer("grpc")->StartSpan( @@ -56,16 +56,16 @@ class GreeterClient auto scope = get_tracer("grpc-client")->WithActiveSpan(span); // inject current context to grpc metadata - auto current_ctx = opentelemetry::context::RuntimeContext::GetCurrent(); + auto current_ctx = context::RuntimeContext::GetCurrent(); GrpcClientCarrier carrier(&context); - auto prop = opentelemetry::context::propagation::GlobalTextMapPropagator::GetGlobalPropagator(); + auto prop = context::propagation::GlobalTextMapPropagator::GetGlobalPropagator(); prop->Inject(carrier, current_ctx); // Send request to server Status status = stub_->Greet(&context, request, &response); if (status.ok()) { - span->SetStatus(opentelemetry::trace::StatusCode::kOk); + span->SetStatus(StatusCode::kOk); span->SetAttribute(OTEL_CPP_GET_ATTR(AttrRpcGrpcStatusCode), status.error_code()); // Make sure to end your spans! span->End(); @@ -74,7 +74,7 @@ class GreeterClient else { std::cout << status.error_code() << ": " << status.error_message() << std::endl; - span->SetStatus(opentelemetry::trace::StatusCode::kError); + span->SetStatus(StatusCode::kError); span->SetAttribute(OTEL_CPP_GET_ATTR(AttrRpcGrpcStatusCode), status.error_code()); // Make sure to end your spans! span->End(); @@ -99,9 +99,9 @@ int main(int argc, char **argv) { initTracer(); // set global propagator - opentelemetry::context::propagation::GlobalTextMapPropagator::SetGlobalPropagator( - nostd::shared_ptr( - new opentelemetry::trace::propagation::HttpTraceContext())); + context::propagation::GlobalTextMapPropagator::SetGlobalPropagator( + nostd::shared_ptr( + new propagation::HttpTraceContext())); constexpr uint16_t default_port = 8800; uint16_t port; if (argc > 1) diff --git a/examples/grpc/server.cc b/examples/grpc/server.cc index c5ee379baf..472d429975 100644 --- a/examples/grpc/server.cc +++ b/examples/grpc/server.cc @@ -35,6 +35,8 @@ using Span = opentelemetry::trace::Span; using SpanContext = opentelemetry::trace::SpanContext; using namespace opentelemetry::trace; +namespace context = opentelemetry::context; + namespace { class GreeterServer final : public Greeter::Service @@ -50,16 +52,16 @@ class GreeterServer final : public Greeter::Service } // Create a SpanOptions object and set the kind to Server to inform OpenTel. - opentelemetry::trace::StartSpanOptions options; - options.kind = opentelemetry::trace::SpanKind::kServer; + StartSpanOptions options; + options.kind = SpanKind::kServer; // extract context from grpc metadata GrpcServerCarrier carrier(context); - auto prop = opentelemetry::context::propagation::GlobalTextMapPropagator::GetGlobalPropagator(); - auto current_ctx = opentelemetry::context::RuntimeContext::GetCurrent(); + auto prop = context::propagation::GlobalTextMapPropagator::GetGlobalPropagator(); + auto current_ctx = context::RuntimeContext::GetCurrent(); auto new_context = prop->Extract(carrier, current_ctx); - options.parent = opentelemetry::trace::GetSpan(new_context)->GetContext(); + options.parent = GetSpan(new_context)->GetContext(); std::string span_name = "GreeterService/Greet"; auto span = @@ -81,7 +83,7 @@ class GreeterServer final : public Greeter::Service response->set_response(message); span->AddEvent("Response sent to client"); - span->SetStatus(opentelemetry::trace::StatusCode::kOk); + span->SetStatus(StatusCode::kOk); // Make sure to end your spans! span->End(); return Status::OK; diff --git a/examples/http/client.cc b/examples/http/client.cc index 99874fa55c..1d574cb7d5 100644 --- a/examples/http/client.cc +++ b/examples/http/client.cc @@ -10,14 +10,17 @@ namespace { using namespace opentelemetry::trace; +namespace http_client = opentelemetry::ext::http::client; +namespace context = opentelemetry::context; +namespace nostd = opentelemetry::nostd; void sendRequest(const std::string &url) { - auto http_client = opentelemetry::ext::http::client::HttpClientFactory::CreateSync(); + auto http_client = http_client::HttpClientFactory::CreateSync(); // start active span - opentelemetry::trace::StartSpanOptions options; - options.kind = opentelemetry::trace::SpanKind::kClient; // client + StartSpanOptions options; + options.kind = SpanKind::kClient; // client opentelemetry::ext::http::common::UrlParser url_parser(url); std::string span_name = url_parser.path_; @@ -30,35 +33,35 @@ void sendRequest(const std::string &url) auto scope = get_tracer("http-client")->WithActiveSpan(span); // inject current context into http header - auto current_ctx = opentelemetry::context::RuntimeContext::GetCurrent(); - HttpTextMapCarrier carrier; - auto prop = opentelemetry::context::propagation::GlobalTextMapPropagator::GetGlobalPropagator(); + auto current_ctx = context::RuntimeContext::GetCurrent(); + HttpTextMapCarrier carrier; + auto prop = context::propagation::GlobalTextMapPropagator::GetGlobalPropagator(); prop->Inject(carrier, current_ctx); // send http request - opentelemetry::ext::http::client::Result result = http_client->Get(url, carrier.headers_); + http_client::Result result = http_client->Get(url, carrier.headers_); if (result) { // set span attributes auto status_code = result.GetResponse().GetStatusCode(); span->SetAttribute(OTEL_CPP_GET_ATTR(AttrHttpStatusCode), status_code); - result.GetResponse().ForEachHeader([&span](opentelemetry::nostd::string_view header_name, - opentelemetry::nostd::string_view header_value) { + result.GetResponse().ForEachHeader([&span](nostd::string_view header_name, + nostd::string_view header_value) { span->SetAttribute("http.header." + std::string(header_name.data()), header_value); return true; }); if (status_code >= 400) { - span->SetStatus(opentelemetry::trace::StatusCode::kError); + span->SetStatus(StatusCode::kError); } } else { - span->SetStatus(opentelemetry::trace::StatusCode::kError, - "Response Status :" + + span->SetStatus(StatusCode::kError, + "Response Status :" std::to_string(static_cast::type>( + http_client::SessionState>::type>( result.GetSessionState()))); } // end span and export data @@ -85,7 +88,7 @@ int main(int argc, char *argv[]) port = default_port; } - std::string url = "http://" + std::string(default_host) + ":" + std::to_string(port) + + std::string url = "http://" + std::string(default_host) + ":" + std::to_string(port) std::string(default_path); sendRequest(url); } diff --git a/examples/http/server.cc b/examples/http/server.cc index fd509c8b67..eee8d5353d 100644 --- a/examples/http/server.cc +++ b/examples/http/server.cc @@ -13,6 +13,7 @@ namespace { using namespace opentelemetry::trace; +namespace context = opentelemetry::context; uint16_t server_port = 8800; constexpr const char *server_name = "localhost"; @@ -23,15 +24,15 @@ class RequestHandler : public HTTP_SERVER_NS::HttpRequestCallback virtual int onHttpRequest(HTTP_SERVER_NS::HttpRequest const &request, HTTP_SERVER_NS::HttpResponse &response) override { - opentelemetry::trace::StartSpanOptions options; - options.kind = opentelemetry::trace::SpanKind::kServer; // server + StartSpanOptions options; + options.kind = SpanKind::kServer; // server std::string span_name = request.uri; // extract context from http header const HttpTextMapCarrier> carrier( (std::map &)request.headers); - auto prop = opentelemetry::context::propagation::GlobalTextMapPropagator::GetGlobalPropagator(); - auto current_ctx = opentelemetry::context::RuntimeContext::GetCurrent(); + auto prop = context::propagation::GlobalTextMapPropagator::GetGlobalPropagator(); + auto current_ctx = context::RuntimeContext::GetCurrent(); auto new_context = prop->Extract(carrier, current_ctx); options.parent = GetSpan(new_context)->GetContext(); @@ -80,7 +81,7 @@ int main(int argc, char *argv[]) RequestHandler req_handler; http_server.AddHandler("/helloworld", &req_handler); auto root_span = get_tracer("http_server")->StartSpan(__func__); - opentelemetry::trace::Scope scope(root_span); + Scope scope(root_span); http_server.Start(); std::cout << "Server is running..Press ctrl-c to exit...\n"; while (1) diff --git a/examples/metrics_simple/main.cc b/examples/metrics_simple/main.cc index fe0e7df4bb..1174f368d5 100644 --- a/examples/metrics_simple/main.cc +++ b/examples/metrics_simple/main.cc @@ -11,12 +11,15 @@ namespace sdkmetrics = opentelemetry::sdk::metrics; namespace nostd = opentelemetry::nostd; +namespace exportermetrics = opentelemetry::exporter::metrics; +namespace metrics_api = opentelemetry::metrics; + int main() { // Initialize and set the global MeterProvider auto provider = nostd::shared_ptr(new sdkmetrics::MeterProvider); - opentelemetry::metrics::Provider::SetMeterProvider(provider); + metrics_api::Provider::SetMeterProvider(provider); // Get the Meter from the MeterProvider nostd::shared_ptr meter = provider->GetMeter("Test", "0.1.0"); @@ -25,9 +28,9 @@ int main() sdkmetrics::PushController ControllerStateless( meter, std::unique_ptr( - new opentelemetry::exporter::metrics::OStreamMetricsExporter), + new exportermetrics::OStreamMetricsExporter), std::shared_ptr( - new opentelemetry::sdk::metrics::UngroupedMetricsProcessor(false)), + new sdkmetrics::UngroupedMetricsProcessor(false)), .05); // Create and instrument @@ -36,7 +39,7 @@ int main() // Create a labelset std::map labels = {{"key", "value"}}; - auto labelkv = opentelemetry::common::KeyValueIterableView{labels}; + auto labelkv = common::KeyValueIterableView{labels}; // Create arrays of instrument and values to add to them metrics_api::SynchronousInstrument *iinstr_arr[] = {intupdowncounter.get(), @@ -92,9 +95,9 @@ int main() sdkmetrics::PushController ControllerStateful( meter, std::unique_ptr( - new opentelemetry::exporter::metrics::OStreamMetricsExporter), + new exportermetrics::OStreamMetricsExporter), std::shared_ptr( - new opentelemetry::sdk::metrics::UngroupedMetricsProcessor(true)), + new sdkmetrics::UngroupedMetricsProcessor(true)), .05); // Start exporting from the Controller with Stateful Processor diff --git a/examples/multi_processor/main.cc b/examples/multi_processor/main.cc index 8246a2ec91..792fcfe4da 100644 --- a/examples/multi_processor/main.cc +++ b/examples/multi_processor/main.cc @@ -12,6 +12,8 @@ #include "opentelemetry/exporters/ostream/span_exporter.h" using opentelemetry::exporter::memory::InMemorySpanExporter; +namespace trace_api = opentelemetry::trace; +namespace trace_sdk = opentelemetry::sdk::trace; InMemorySpanExporter *memory_span_exporter; @@ -32,18 +34,18 @@ void initTracer() auto processor2 = std::unique_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter2))); - auto provider = nostd::shared_ptr( + auto provider = nostd::shared_ptr( new sdktrace::TracerProvider(std::move(processor1))); provider->AddProcessor(std::move(processor2)); // Set the global trace provider - opentelemetry::trace::Provider::SetTracerProvider(std::move(provider)); + trace_api::Provider::SetTracerProvider(std::move(provider)); } -void dumpSpans(std::vector> &spans) +void dumpSpans(std::vector> &spans) { - char span_buf[opentelemetry::trace::SpanId::kSize * 2]; - char trace_buf[opentelemetry::trace::TraceId::kSize * 2]; - char parent_span_buf[opentelemetry::trace::SpanId::kSize * 2]; + char span_buf[trace_api::SpanId::kSize * 2]; + char trace_buf[trace_api::TraceId::kSize * 2]; + char parent_span_buf[trace_api::SpanId::kSize * 2]; std::cout << "\nSpans from memory :" << std::endl; for (auto &span : spans) @@ -60,11 +62,11 @@ void dumpSpans(std::vector> std::cout << "\t\tDescription: " << span->GetDescription() << std::endl; std::cout << "\t\tSpan kind:" - << static_cast::type>( + << static_cast::type>( span->GetSpanKind()) << std::endl; std::cout << "\t\tSpan Status: " - << static_cast::type>( + << static_cast::type>( span->GetStatus()) << std::endl; } diff --git a/examples/multithreaded/main.cc b/examples/multithreaded/main.cc index b245aad5aa..24514fc949 100644 --- a/examples/multithreaded/main.cc +++ b/examples/multithreaded/main.cc @@ -13,6 +13,8 @@ #include #include +namespace trace_api = opentelemetry::trace; + namespace { void initTracer() @@ -22,15 +24,15 @@ void initTracer() auto processor = std::unique_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); auto provider = - nostd::shared_ptr(new sdktrace::TracerProvider( + nostd::shared_ptr(new sdktrace::TracerProvider( std::move(processor), opentelemetry::sdk::resource::Resource::Create({}))); // Set the global trace provider - opentelemetry::trace::Provider::SetTracerProvider(provider); + trace_api::Provider::SetTracerProvider(provider); } -nostd::shared_ptr get_tracer() +nostd::shared_ptr get_tracer() { - auto provider = opentelemetry::trace::Provider::GetTracerProvider(); + auto provider = trace_api::Provider::GetTracerProvider(); return provider->GetTracer("foo_library"); } } // namespace @@ -45,7 +47,7 @@ void run_threads() // This shows how one can effectively use Scope objects to correctly // parent spans across threads. threads.push_back(std::thread([=] { - opentelemetry::trace::Scope scope(thread_span); + trace_api::Scope scope(thread_span); auto thread_span = get_tracer()->StartSpan(std::string("thread ") + std::to_string(thread_num)); })); @@ -59,7 +61,7 @@ int main() initTracer(); auto root_span = get_tracer()->StartSpan(__func__); - opentelemetry::trace::Scope scope(root_span); + trace_api::Scope scope(root_span); run_threads(); } diff --git a/examples/otlp/http_main.cc b/examples/otlp/http_main.cc index a35fb4b35b..76cd21df9e 100644 --- a/examples/otlp/http_main.cc +++ b/examples/otlp/http_main.cc @@ -47,7 +47,7 @@ int main(int argc, char *argv[]) std::string binary_mode = argv[3]; if (binary_mode.size() >= 3 && binary_mode.substr(0, 3) == "bin") { - opts.content_type = opentelemetry::exporter::otlp::HttpRequestContentType::kBinary; + opts.content_type = otlp::HttpRequestContentType::kBinary; } } } diff --git a/examples/plugin/plugin/factory_impl.cc b/examples/plugin/plugin/factory_impl.cc index 59effb739e..fd1504be60 100644 --- a/examples/plugin/plugin/factory_impl.cc +++ b/examples/plugin/plugin/factory_impl.cc @@ -5,7 +5,10 @@ #include "opentelemetry/plugin/hook.h" #include "tracer.h" -class TracerHandle final : public opentelemetry::plugin::TracerHandle +namespace nostd = opentelemetry::nostd; +namespace plugin = opentelemetry::plugin; + +class TracerHandle final : public plugin::TracerHandle { public: explicit TracerHandle(std::shared_ptr &&tracer) noexcept : tracer_{std::move(tracer)} {} @@ -17,31 +20,31 @@ class TracerHandle final : public opentelemetry::plugin::TracerHandle std::shared_ptr tracer_; }; -class FactoryImpl final : public opentelemetry::plugin::Factory::FactoryImpl +class FactoryImpl final : public plugin::Factory::FactoryImpl { public: // opentelemetry::plugin::Factory::FactoryImpl - opentelemetry::nostd::unique_ptr MakeTracerHandle( - opentelemetry::nostd::string_view tracer_config, - opentelemetry::nostd::unique_ptr &error_message) const noexcept override + nostd::unique_ptr MakeTracerHandle( + nostd::string_view tracer_config, + nostd::unique_ptr &error_message) const noexcept override { std::shared_ptr tracer{new (std::nothrow) Tracer{""}}; if (tracer == nullptr) { return nullptr; } - return opentelemetry::nostd::unique_ptr{new (std::nothrow) + return nostd::unique_ptr{new (std::nothrow) TracerHandle{std::move(tracer)}}; } }; -static opentelemetry::nostd::unique_ptr -MakeFactoryImpl(const opentelemetry::plugin::LoaderInfo &loader_info, - opentelemetry::nostd::unique_ptr &error_message) noexcept +static nostd::unique_ptr +MakeFactoryImpl(const plugin::LoaderInfo &loader_info, + nostd::unique_ptr &error_message) noexcept { (void)loader_info; (void)error_message; - return opentelemetry::nostd::unique_ptr{ + return nostd::unique_ptr{ new (std::nothrow) FactoryImpl{}}; } diff --git a/examples/plugin/plugin/tracer.cc b/examples/plugin/plugin/tracer.cc index 541f2a8225..212969af68 100644 --- a/examples/plugin/plugin/tracer.cc +++ b/examples/plugin/plugin/tracer.cc @@ -19,8 +19,8 @@ class Span final : public trace::Span public: Span(std::shared_ptr &&tracer, nostd::string_view name, - const opentelemetry::common::KeyValueIterable & /*attributes*/, - const opentelemetry::trace::SpanContextKeyValueIterable & /*links*/, + const common::KeyValueIterable & /*attributes*/, + const trace::SpanContextKeyValueIterable & /*links*/, const trace::StartSpanOptions & /*options*/) noexcept : tracer_{std::move(tracer)}, name_{name}, span_context_{trace::SpanContext::GetInvalid()} { @@ -67,10 +67,10 @@ Tracer::Tracer(nostd::string_view /*output*/) {} nostd::shared_ptr Tracer::StartSpan( nostd::string_view name, - const opentelemetry::common::KeyValueIterable &attributes, - const opentelemetry::trace::SpanContextKeyValueIterable &links, + const common::KeyValueIterable &attributes, + const trace::SpanContextKeyValueIterable &links, const trace::StartSpanOptions &options) noexcept { - return nostd::shared_ptr{ + return nostd::shared_ptr{ new (std::nothrow) Span{this->shared_from_this(), name, attributes, links, options}}; } diff --git a/examples/simple/main.cc b/examples/simple/main.cc index 3d7102d009..d27511aa64 100644 --- a/examples/simple/main.cc +++ b/examples/simple/main.cc @@ -9,6 +9,8 @@ #include "foo_library/foo_library.h" #include "opentelemetry/exporters/ostream/span_exporter.h" +namespace trace_api = opentelemetry::trace; + namespace { void initTracer() @@ -17,11 +19,11 @@ void initTracer() new opentelemetry::exporter::trace::OStreamSpanExporter); auto processor = std::unique_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); - auto provider = nostd::shared_ptr( + auto provider = nostd::shared_ptr( new sdktrace::TracerProvider(std::move(processor))); // Set the global trace provider - opentelemetry::trace::Provider::SetTracerProvider(provider); + trace_api::Provider::SetTracerProvider(provider); } } // namespace diff --git a/examples/zipkin/main.cc b/examples/zipkin/main.cc index 3ae7539cda..4ecf110c2a 100644 --- a/examples/zipkin/main.cc +++ b/examples/zipkin/main.cc @@ -12,16 +12,17 @@ namespace trace = opentelemetry::trace; namespace nostd = opentelemetry::nostd; namespace sdktrace = opentelemetry::sdk::trace; namespace zipkin = opentelemetry::exporter::zipkin; +namespace resource = opentelemetry::sdk::resource; namespace { -opentelemetry::exporter::zipkin::ZipkinExporterOptions opts; +zipkin::ZipkinExporterOptions opts; void InitTracer() { // Create zipkin exporter instance - opentelemetry::sdk::resource::ResourceAttributes attributes = { + resource::ResourceAttributes attributes = { {"service.name", "zipkin_demo_service"}}; - auto resource = opentelemetry::sdk::resource::Resource::Create(attributes); + auto resource = resource::Resource::Create(attributes); auto exporter = std::unique_ptr(new zipkin::ZipkinExporter(opts)); auto processor = std::unique_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); diff --git a/examples/zpages/zpages_example.cc b/examples/zpages/zpages_example.cc index a4f0e6bbf0..2691a73158 100644 --- a/examples/zpages/zpages_example.cc +++ b/examples/zpages/zpages_example.cc @@ -12,6 +12,7 @@ #include "opentelemetry/ext/zpages/zpages.h" // Required file include for zpages using opentelemetry::common::SteadyTimestamp; +namespace trace_api = opentelemetry::trace; int main(int argc, char *argv[]) { @@ -23,7 +24,7 @@ int main(int argc, char *argv[]) * Note that the webserver is destroyed after the application ends execution. */ ZPages::Initialize(); - auto tracer = opentelemetry::trace::Provider::GetTracerProvider()->GetTracer(""); + auto tracer = trace_api::Provider::GetTracerProvider()->GetTracer(""); std::cout << "This example for zPages creates a few types of spans and then " << "creates a span every second for the duration of the application" @@ -33,14 +34,14 @@ int main(int argc, char *argv[]) std::map attribute_map; attribute_map["completed_search_for"] = "Unknown user"; tracer->StartSpan("find user", attribute_map) - ->SetStatus(opentelemetry::trace::StatusCode::kError, "User not found"); + ->SetStatus(trace_api::StatusCode::kError, "User not found"); // Long time duration span std::map attribute_map2; attribute_map2["completed_search_for"] = "John Doe"; - opentelemetry::trace::StartSpanOptions start; + trace_api::StartSpanOptions start; start.start_steady_time = SteadyTimestamp(nanoseconds(1)); - opentelemetry::trace::EndSpanOptions end; + trace_api::EndSpanOptions end; end.end_steady_time = SteadyTimestamp(nanoseconds(1000000000000)); tracer->StartSpan("find user", attribute_map2, start)->End(end); diff --git a/exporters/elasticsearch/src/es_log_exporter.cc b/exporters/elasticsearch/src/es_log_exporter.cc index 777bfb9426..8d01c98248 100644 --- a/exporters/elasticsearch/src/es_log_exporter.cc +++ b/exporters/elasticsearch/src/es_log_exporter.cc @@ -71,7 +71,7 @@ class ResponseHandler : public http_client::EventHandler // Callback method when an http event occurs void OnEvent(http_client::SessionState state, - opentelemetry::nostd::string_view reason) noexcept override + nostd::string_view reason) noexcept override { // If any failure event occurs, release the condition variable to unblock main thread switch (state) diff --git a/exporters/jaeger/src/recordable.cc b/exporters/jaeger/src/recordable.cc index 0e78ee3d71..fe18bbaa39 100644 --- a/exporters/jaeger/src/recordable.cc +++ b/exporters/jaeger/src/recordable.cc @@ -11,6 +11,7 @@ namespace jaeger { using namespace opentelemetry::sdk::resource; +namespace trace_api = opentelemetry::trace; JaegerRecordable::JaegerRecordable() : span_{new thrift::Span} {} @@ -187,19 +188,19 @@ void JaegerRecordable::SetSpanKind(trace::SpanKind span_kind) noexcept // map SpanKind to Jaeger tag span.kind. switch (span_kind) { - case opentelemetry::trace::SpanKind::kClient: { + case trace_api::SpanKind::kClient: { span_kind_str = "client"; break; } - case opentelemetry::trace::SpanKind::kServer: { + case trace_api::SpanKind::kServer: { span_kind_str = "server"; break; } - case opentelemetry::trace::SpanKind::kConsumer: { + case trace_api::SpanKind::kConsumer: { span_kind_str = "consumer"; break; } - case opentelemetry::trace::SpanKind::kProducer: { + case trace_api::SpanKind::kProducer: { span_kind_str = "producer"; break; } diff --git a/exporters/jaeger/test/jaeger_recordable_test.cc b/exporters/jaeger/test/jaeger_recordable_test.cc index 04a114c3f7..075b09c642 100644 --- a/exporters/jaeger/test/jaeger_recordable_test.cc +++ b/exporters/jaeger/test/jaeger_recordable_test.cc @@ -13,6 +13,7 @@ namespace trace = opentelemetry::trace; namespace nostd = opentelemetry::nostd; namespace sdktrace = opentelemetry::sdk::trace; +namespace common = opentelemetry::common; using namespace jaegertracing; using namespace opentelemetry::exporter::jaeger; @@ -20,7 +21,7 @@ using namespace opentelemetry::sdk::instrumentationlibrary; TEST(JaegerSpanRecordable, SetIdentity) { - opentelemetry::exporter::jaeger::JaegerRecordable rec; + JaegerRecordable rec; int64_t trace_id_val[2] = {0x0000000000000000, 0x1000000000000000}; int64_t span_id_val = 0x2000000000000000; @@ -35,18 +36,18 @@ TEST(JaegerSpanRecordable, SetIdentity) const trace::SpanId parent_span_id( nostd::span(reinterpret_cast(&parent_span_id_val), 8)); - const opentelemetry::trace::SpanContext span_context{ + const trace::SpanContext span_context{ trace_id, span_id, - opentelemetry::trace::TraceFlags{opentelemetry::trace::TraceFlags::kIsSampled}, true}; + trace::TraceFlags{trace::TraceFlags::kIsSampled}, true}; rec.SetIdentity(span_context, parent_span_id); std::unique_ptr span{rec.Span()}; #if JAEGER_IS_LITTLE_ENDIAN == 1 - EXPECT_EQ(span->traceIdLow, opentelemetry::exporter::jaeger::otel_bswap_64(trace_id_val[1])); - EXPECT_EQ(span->traceIdHigh, opentelemetry::exporter::jaeger::otel_bswap_64(trace_id_val[0])); - EXPECT_EQ(span->spanId, opentelemetry::exporter::jaeger::otel_bswap_64(span_id_val)); - EXPECT_EQ(span->parentSpanId, opentelemetry::exporter::jaeger::otel_bswap_64(parent_span_id_val)); + EXPECT_EQ(span->traceIdLow, otel_bswap_64(trace_id_val[1])); + EXPECT_EQ(span->traceIdHigh, otel_bswap_64(trace_id_val[0])); + EXPECT_EQ(span->spanId, otel_bswap_64(span_id_val)); + EXPECT_EQ(span->parentSpanId, otel_bswap_64(parent_span_id_val)); #else EXPECT_EQ(span->traceIdLow, trace_id_val[0]); EXPECT_EQ(span->traceIdHigh, trace_id_val[1]); @@ -57,7 +58,7 @@ TEST(JaegerSpanRecordable, SetIdentity) TEST(JaegerSpanRecordable, SetName) { - opentelemetry::exporter::jaeger::JaegerRecordable rec; + JaegerRecordable rec; nostd::string_view name = "Test Span"; rec.SetName(name); @@ -69,10 +70,10 @@ TEST(JaegerSpanRecordable, SetName) TEST(JaegerSpanRecordable, SetStartTime) { - opentelemetry::exporter::jaeger::JaegerRecordable rec; + JaegerRecordable rec; std::chrono::system_clock::time_point start_time = std::chrono::system_clock::now(); - opentelemetry::common::SystemTimestamp start_timestamp(start_time); + common::SystemTimestamp start_timestamp(start_time); uint64_t unix_start = std::chrono::duration_cast(start_time.time_since_epoch()).count(); rec.SetStartTime(start_timestamp); @@ -84,9 +85,9 @@ TEST(JaegerSpanRecordable, SetStartTime) TEST(JaegerSpanRecordable, SetDuration) { - opentelemetry::exporter::jaeger::JaegerRecordable rec; + JaegerRecordable rec; - opentelemetry::common::SystemTimestamp start_timestamp; + common::SystemTimestamp start_timestamp; std::chrono::microseconds duration(10); uint64_t unix_end = duration.count(); @@ -102,7 +103,7 @@ TEST(JaegerSpanRecordable, SetDuration) TEST(JaegerSpanRecordable, SetStatus) { - opentelemetry::exporter::jaeger::JaegerRecordable rec; + JaegerRecordable rec; const char *error_description = "Error test"; rec.SetStatus(trace::StatusCode::kError, error_description); @@ -125,12 +126,12 @@ TEST(JaegerSpanRecordable, SetStatus) TEST(JaegerSpanRecordable, AddEvent) { - opentelemetry::exporter::jaeger::JaegerRecordable rec; + JaegerRecordable rec; nostd::string_view name = "Test Event"; std::chrono::system_clock::time_point event_time = std::chrono::system_clock::now(); - opentelemetry::common::SystemTimestamp event_timestamp(event_time); + common::SystemTimestamp event_timestamp(event_time); uint64_t epoch_us = std::chrono::duration_cast(event_time.time_since_epoch()).count(); @@ -142,7 +143,7 @@ TEST(JaegerSpanRecordable, AddEvent) rec.AddEvent( "Test Event", event_timestamp, - opentelemetry::common::KeyValueIterableView>(attributes)); + common::KeyValueIterableView>(attributes)); thrift::Log log = rec.Logs().at(0); EXPECT_EQ(log.timestamp, epoch_us); auto tags = log.fields; @@ -159,7 +160,7 @@ TEST(JaegerSpanRecordable, AddEvent) TEST(JaegerSpanRecordable, SetInstrumentationLibrary) { - opentelemetry::exporter::jaeger::JaegerRecordable rec; + JaegerRecordable rec; std::string library_name = "opentelemetry-cpp"; std::string library_version = "0.1.0"; @@ -181,7 +182,7 @@ TEST(JaegerSpanRecordable, SetInstrumentationLibrary) TEST(JaegerSpanRecordable, SetResource) { - opentelemetry::exporter::jaeger::JaegerRecordable rec; + JaegerRecordable rec; const std::string service_name_key = "service.name"; std::string service_name_value = "test-jaeger-service-name"; diff --git a/exporters/ostream/src/span_exporter.cc b/exporters/ostream/src/span_exporter.cc index cbf3e7a5af..a83c31dfc4 100644 --- a/exporters/ostream/src/span_exporter.cc +++ b/exporters/ostream/src/span_exporter.cc @@ -7,6 +7,7 @@ namespace nostd = opentelemetry::nostd; namespace sdktrace = opentelemetry::sdk::trace; +namespace trace_api = opentelemetry::trace; OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -14,19 +15,19 @@ namespace exporter namespace trace { -std::ostream &operator<<(std::ostream &os, opentelemetry::trace::SpanKind span_kind) +std::ostream &operator<<(std::ostream &os, trace_api::SpanKind span_kind) { switch (span_kind) { - case opentelemetry::trace::SpanKind::kClient: + case trace_api::SpanKind::kClient: return os << "Client"; - case opentelemetry::trace::SpanKind::kInternal: + case trace_api::SpanKind::kInternal: return os << "Internal"; - case opentelemetry::trace::SpanKind::kServer: + case trace_api::SpanKind::kServer: return os << "Server"; - case opentelemetry::trace::SpanKind::kProducer: + case trace_api::SpanKind::kProducer: return os << "Producer"; - case opentelemetry::trace::SpanKind::kConsumer: + case trace_api::SpanKind::kConsumer: return os << "Consumer"; }; return os << ""; diff --git a/exporters/ostream/test/ostream_log_test.cc b/exporters/ostream/test/ostream_log_test.cc index 80589a8898..7398058c83 100644 --- a/exporters/ostream/test/ostream_log_test.cc +++ b/exporters/ostream/test/ostream_log_test.cc @@ -16,6 +16,9 @@ namespace sdklogs = opentelemetry::sdk::logs; namespace logs_api = opentelemetry::logs; namespace nostd = opentelemetry::nostd; +namespace exporterlogs = opentelemetry::exporter::logs; +namespace common = opentelemetry::common; + OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -27,7 +30,7 @@ namespace logs TEST(OStreamLogExporter, Shutdown) { auto exporter = - std::unique_ptr(new opentelemetry::exporter::logs::OStreamLogExporter); + std::unique_ptr(new exporterlogs::OStreamLogExporter); // Save cout's original buffer here std::streambuf *original = std::cout.rdbuf(); @@ -56,7 +59,7 @@ TEST(OStreamLogExporter, Shutdown) TEST(OstreamLogExporter, DefaultLogRecordToCout) { auto exporter = std::unique_ptr( - new opentelemetry::exporter::logs::OStreamLogExporter(std::cout)); + new exporterlogs::OStreamLogExporter(std::cout)); // Save cout's original buffer here std::streambuf *original = std::cout.rdbuf(); @@ -95,7 +98,7 @@ TEST(OStreamLogExporter, SimpleLogToCout) { // Initialize an Ostream exporter to std::cout auto exporter = std::unique_ptr( - new opentelemetry::exporter::logs::OStreamLogExporter(std::cout)); + new exporterlogs::OStreamLogExporter(std::cout)); // Save original stream buffer, then redirect cout to our new stream buffer std::streambuf *original = std::cout.rdbuf(); @@ -104,7 +107,7 @@ TEST(OStreamLogExporter, SimpleLogToCout) // Pass a default recordable created by the exporter to be exported // Create a log record and manually timestamp, severity, name, message - opentelemetry::common::SystemTimestamp now(std::chrono::system_clock::now()); + common::SystemTimestamp now(std::chrono::system_clock::now()); auto record = std::unique_ptr(new sdklogs::LogRecord()); record->SetTimestamp(now); @@ -120,8 +123,8 @@ TEST(OStreamLogExporter, SimpleLogToCout) std::string expectedOutput = "{\n" - " timestamp : " + - std::to_string(now.time_since_epoch().count()) + + " timestamp : " + std::to_string(now.time_since_epoch().count()) "\n" " severity_num : 1\n" " severity_text : TRACE\n" @@ -144,7 +147,7 @@ TEST(OStreamLogExporter, LogWithStringAttributesToCerr) { // Initialize an Ostream exporter to cerr auto exporter = std::unique_ptr( - new opentelemetry::exporter::logs::OStreamLogExporter(std::cerr)); + new exporterlogs::OStreamLogExporter(std::cerr)); // Save original stream buffer, then redirect cout to our new stream buffer std::streambuf *original = std::cerr.rdbuf(); @@ -191,7 +194,7 @@ TEST(OStreamLogExporter, LogWithVariantTypesToClog) // Initialize an Ostream exporter to cerr auto exporter = std::unique_ptr( - new opentelemetry::exporter::logs::OStreamLogExporter(std::clog)); + new exporterlogs::OStreamLogExporter(std::clog)); // Save original stream buffer, then redirect cout to our new stream buffer std::streambuf *original = std::clog.rdbuf(); @@ -203,13 +206,13 @@ TEST(OStreamLogExporter, LogWithVariantTypesToClog) // Set resources for this log record of only integer types as the value std::array array1 = {1, 2, 3}; - opentelemetry::nostd::span data1{array1.data(), array1.size()}; + nostd::span data1{array1.data(), array1.size()}; record->SetResource("res1", data1); // Set resources for this log record of bool types as the value // e.g. key/value is a par of type std::array array = {false, true, false}; - record->SetAttribute("attr1", opentelemetry::nostd::span{array.data(), array.size()}); + record->SetAttribute("attr1", nostd::span{array.data(), array.size()}); // Log a record to clog exporter->Export(nostd::span>(&record, 1)); @@ -241,7 +244,7 @@ TEST(OStreamLogExporter, IntegrationTest) { // Initialize a logger auto exporter = - std::unique_ptr(new opentelemetry::exporter::logs::OStreamLogExporter); + std::unique_ptr(new exporterlogs::OStreamLogExporter); auto processor = std::shared_ptr(new sdklogs::SimpleLogProcessor(std::move(exporter))); auto sdkProvider = std::shared_ptr(new sdklogs::LoggerProvider()); @@ -259,8 +262,8 @@ TEST(OStreamLogExporter, IntegrationTest) std::cout.rdbuf(stdcoutOutput.rdbuf()); // Write a log to ostream exporter - opentelemetry::common::SystemTimestamp now(std::chrono::system_clock::now()); - logger->Log(opentelemetry::logs::Severity::kDebug, "", "Hello", {}, {}, {}, {}, {}, now); + common::SystemTimestamp now(std::chrono::system_clock::now()); + logger->Log(logs_api::Severity::kDebug, "", "Hello", {}, {}, {}, {}, {}, now); // Restore cout's original streambuf std::cout.rdbuf(original); @@ -268,8 +271,8 @@ TEST(OStreamLogExporter, IntegrationTest) // Compare actual vs expected outputs std::string expectedOutput = "{\n" - " timestamp : " + - std::to_string(now.time_since_epoch().count()) + + " timestamp : " + std::to_string(now.time_since_epoch().count()) "\n" " severity_num : 5\n" " severity_text : DEBUG\n" diff --git a/exporters/ostream/test/ostream_metrics_test.cc b/exporters/ostream/test/ostream_metrics_test.cc index d86a41b382..bbb203ca7d 100644 --- a/exporters/ostream/test/ostream_metrics_test.cc +++ b/exporters/ostream/test/ostream_metrics_test.cc @@ -18,14 +18,15 @@ namespace sdkmetrics = opentelemetry::sdk::metrics; namespace metrics_api = opentelemetry::metrics; namespace nostd = opentelemetry::nostd; +namespace exportermetrics = opentelemetry::exporter::metrics; TEST(OStreamMetricsExporter, PrintCounter) { auto exporter = std::unique_ptr( - new opentelemetry::exporter::metrics::OStreamMetricsExporter); + new exportermetrics::OStreamMetricsExporter); - auto aggregator = std::shared_ptr>( - new opentelemetry::sdk::metrics::CounterAggregator( + auto aggregator = std::shared_ptr>( + new sdkmetrics::CounterAggregator( metrics_api::InstrumentKind::Counter)); aggregator->update(5.5); @@ -62,10 +63,10 @@ TEST(OStreamMetricsExporter, PrintCounter) TEST(OStreamMetricsExporter, PrintMinMaxSumCount) { auto exporter = std::unique_ptr( - new opentelemetry::exporter::metrics::OStreamMetricsExporter); + new exportermetrics::OStreamMetricsExporter); - auto aggregator = std::shared_ptr>( - new opentelemetry::sdk::metrics::MinMaxSumCountAggregator( + auto aggregator = std::shared_ptr>( + new sdkmetrics::MinMaxSumCountAggregator( metrics_api::InstrumentKind::Counter)); aggregator->update(1); @@ -106,10 +107,10 @@ TEST(OStreamMetricsExporter, PrintMinMaxSumCount) TEST(OStreamMetricsExporter, PrintGauge) { auto exporter = std::unique_ptr( - new opentelemetry::exporter::metrics::OStreamMetricsExporter); + new exportermetrics::OStreamMetricsExporter); - auto aggregator = std::shared_ptr>( - new opentelemetry::sdk::metrics::GaugeAggregator( + auto aggregator = std::shared_ptr>( + new sdkmetrics::GaugeAggregator( metrics_api::InstrumentKind::Counter)); aggregator->update(1); @@ -139,8 +140,8 @@ TEST(OStreamMetricsExporter, PrintGauge) " description : description\n" " labels : labels\n" " last value : 9\n" - " timestamp : " + - std::to_string(aggregator->get_checkpoint_timestamp().time_since_epoch().count()) + + " timestamp : " + std::to_string(aggregator->get_checkpoint_timestamp().time_since_epoch().count()) "\n" "}\n"; @@ -150,14 +151,14 @@ TEST(OStreamMetricsExporter, PrintGauge) TEST(OStreamMetricsExporter, PrintExact) { auto exporter = std::unique_ptr( - new opentelemetry::exporter::metrics::OStreamMetricsExporter); + new exportermetrics::OStreamMetricsExporter); - auto aggregator = std::shared_ptr>( - new opentelemetry::sdk::metrics::ExactAggregator(metrics_api::InstrumentKind::Counter, + auto aggregator = std::shared_ptr>( + new sdkmetrics::ExactAggregator(metrics_api::InstrumentKind::Counter, true)); - auto aggregator2 = std::shared_ptr>( - new opentelemetry::sdk::metrics::ExactAggregator(metrics_api::InstrumentKind::Counter, + auto aggregator2 = std::shared_ptr>( + new sdkmetrics::ExactAggregator(metrics_api::InstrumentKind::Counter, false)); for (int i = 0; i < 10; i++) @@ -207,11 +208,11 @@ TEST(OStreamMetricsExporter, PrintExact) TEST(OStreamMetricsExporter, PrintHistogram) { auto exporter = std::unique_ptr( - new opentelemetry::exporter::metrics::OStreamMetricsExporter); + new exportermetrics::OStreamMetricsExporter); std::vector boundaries{10, 20, 30, 40, 50}; - auto aggregator = std::shared_ptr>( - new opentelemetry::sdk::metrics::HistogramAggregator( + auto aggregator = std::shared_ptr>( + new sdkmetrics::HistogramAggregator( metrics_api::InstrumentKind::Counter, boundaries)); for (float i = 0; i < 60; i++) @@ -252,11 +253,11 @@ TEST(OStreamMetricsExporter, PrintHistogram) TEST(OStreamMetricsExporter, PrintSketch) { auto exporter = std::unique_ptr( - new opentelemetry::exporter::metrics::OStreamMetricsExporter); + new exportermetrics::OStreamMetricsExporter); std::vector boundaries{1, 3, 5, 7, 9}; - auto aggregator = std::shared_ptr>( - new opentelemetry::sdk::metrics::SketchAggregator(metrics_api::InstrumentKind::Counter, + auto aggregator = std::shared_ptr>( + new sdkmetrics::SketchAggregator(metrics_api::InstrumentKind::Counter, .000005)); for (int i = 0; i < 10; i++) diff --git a/exporters/ostream/test/ostream_span_test.cc b/exporters/ostream/test/ostream_span_test.cc index c72372adc7..1952fc8fdb 100644 --- a/exporters/ostream/test/ostream_span_test.cc +++ b/exporters/ostream/test/ostream_span_test.cc @@ -24,6 +24,7 @@ namespace common = opentelemetry::common; namespace nostd = opentelemetry::nostd; namespace sdktrace = opentelemetry::sdk::trace; namespace resource = opentelemetry::sdk::resource; +namespace exportertrace = opentelemetry::exporter::trace; using Attributes = std::initializer_list>; @@ -39,7 +40,7 @@ class TestResource : public resource::Resource TEST(OStreamSpanExporter, Shutdown) { auto exporter = std::unique_ptr( - new opentelemetry::exporter::trace::OStreamSpanExporter); + new exportertrace::OStreamSpanExporter); auto processor = std::shared_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); @@ -79,7 +80,7 @@ TEST(OStreamSpanExporter, PrintDefaultSpan) { std::stringstream output; auto exporter = std::unique_ptr( - new opentelemetry::exporter::trace::OStreamSpanExporter(output)); + new exportertrace::OStreamSpanExporter(output)); auto processor = std::shared_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); @@ -94,7 +95,7 @@ TEST(OStreamSpanExporter, PrintSpanWithBasicFields) { std::stringstream output; auto exporter = std::unique_ptr( - new opentelemetry::exporter::trace::OStreamSpanExporter(output)); + new exportertrace::OStreamSpanExporter(output)); auto processor = std::shared_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); @@ -103,24 +104,24 @@ TEST(OStreamSpanExporter, PrintSpanWithBasicFields) constexpr uint8_t trace_id_buf[] = {1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8}; constexpr uint8_t span_id_buf[] = {1, 2, 3, 4, 5, 6, 7, 8}; constexpr uint8_t parent_span_id_buf[] = {8, 7, 6, 5, 4, 3, 2, 1}; - opentelemetry::trace::TraceId trace_id{trace_id_buf}; - opentelemetry::trace::SpanId span_id{span_id_buf}; - opentelemetry::trace::SpanId parent_span_id{parent_span_id_buf}; - const auto trace_state = opentelemetry::trace::TraceState::GetDefault()->Set("state1", "value"); - const opentelemetry::trace::SpanContext span_context{ + trace::TraceId trace_id{trace_id_buf}; + trace::SpanId span_id{span_id_buf}; + trace::SpanId parent_span_id{parent_span_id_buf}; + const auto trace_state = trace::TraceState::GetDefault()->Set("state1", "value"); + const trace::SpanContext span_context{ trace_id, span_id, - opentelemetry::trace::TraceFlags{opentelemetry::trace::TraceFlags::kIsSampled}, true, + trace::TraceFlags{trace::TraceFlags::kIsSampled}, true, trace_state}; recordable->SetIdentity(span_context, parent_span_id); recordable->SetName("Test Span"); - opentelemetry::common::SystemTimestamp now(std::chrono::system_clock::now()); + common::SystemTimestamp now(std::chrono::system_clock::now()); recordable->SetStartTime(now); recordable->SetDuration(std::chrono::nanoseconds(100)); - recordable->SetStatus(opentelemetry::trace::StatusCode::kOk, "Test Description"); - recordable->SetSpanKind(opentelemetry::trace::SpanKind::kClient); + recordable->SetStatus(trace::StatusCode::kOk, "Test Description"); + recordable->SetSpanKind(trace::SpanKind::kClient); - TestResource resource1(opentelemetry::sdk::resource::ResourceAttributes({{"key1", "val1"}})); + TestResource resource1(resource::ResourceAttributes({{"key1", "val1"}})); recordable->SetResource(resource1); processor->OnEnd(std::move(recordable)); @@ -134,8 +135,8 @@ TEST(OStreamSpanExporter, PrintSpanWithBasicFields) " span_id : 0102030405060708\n" " tracestate : state1=value\n" " parent_span_id: 0807060504030201\n" - " start : " + - start + + " start : " + start "\n" " duration : 100\n" " description : Test Description\n" @@ -155,7 +156,7 @@ TEST(OStreamSpanExporter, PrintSpanWithAttribute) { std::stringstream output; auto exporter = std::unique_ptr( - new opentelemetry::exporter::trace::OStreamSpanExporter(output)); + new exportertrace::OStreamSpanExporter(output)); auto processor = std::shared_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); @@ -191,14 +192,14 @@ TEST(OStreamSpanExporter, PrintSpanWithArrayAttribute) { std::stringstream output; auto exporter = std::unique_ptr( - new opentelemetry::exporter::trace::OStreamSpanExporter(output)); + new exportertrace::OStreamSpanExporter(output)); auto processor = std::shared_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); auto recordable = processor->MakeRecordable(); std::array array1 = {1, 2, 3}; - opentelemetry::nostd::span span1{array1.data(), array1.size()}; + nostd::span span1{array1.data(), array1.size()}; recordable->SetAttribute("array1", span1); processor->OnEnd(std::move(recordable)); @@ -229,13 +230,13 @@ TEST(OStreamSpanExporter, PrintSpanWithEvents) { std::stringstream output; auto exporter = std::unique_ptr( - new opentelemetry::exporter::trace::OStreamSpanExporter(output)); + new exportertrace::OStreamSpanExporter(output)); auto processor = std::shared_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); auto recordable = processor->MakeRecordable(); - opentelemetry::common::SystemTimestamp now(std::chrono::system_clock::now()); - opentelemetry::common::SystemTimestamp next(std::chrono::system_clock::now() + + common::SystemTimestamp now(std::chrono::system_clock::now()); + common::SystemTimestamp next(std::chrono::system_clock::now() std::chrono::seconds(1)); std::string now_str = std::to_string(now.time_since_epoch().count()); @@ -263,15 +264,15 @@ TEST(OStreamSpanExporter, PrintSpanWithEvents) " events : \n" "\t{\n" "\t name : hello\n" - "\t timestamp : " + - now_str + + "\t timestamp : " + now_str "\n" "\t attributes : \n" "\t}\n" "\t{\n" "\t name : world\n" - "\t timestamp : " + - next_str + + "\t timestamp : " + next_str "\n" "\t attributes : \n" "\t\tattr1: string\n" @@ -287,34 +288,34 @@ TEST(OStreamSpanExporter, PrintSpanWithLinks) { std::stringstream output; auto exporter = std::unique_ptr( - new opentelemetry::exporter::trace::OStreamSpanExporter(output)); + new exportertrace::OStreamSpanExporter(output)); auto processor = std::shared_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); auto recordable = processor->MakeRecordable(); // produce valid SpanContext with pseudo span and trace Id. - uint8_t span_id_buf[opentelemetry::trace::SpanId::kSize] = { + uint8_t span_id_buf[trace::SpanId::kSize] = { 1, }; - opentelemetry::trace::SpanId span_id{span_id_buf}; - uint8_t trace_id_buf[opentelemetry::trace::TraceId::kSize] = { + trace::SpanId span_id{span_id_buf}; + uint8_t trace_id_buf[trace::TraceId::kSize] = { 2, }; - opentelemetry::trace::TraceId trace_id{trace_id_buf}; - const auto span_context = opentelemetry::trace::SpanContext( + trace::TraceId trace_id{trace_id_buf}; + const auto span_context = trace::SpanContext( trace_id, span_id, - opentelemetry::trace::TraceFlags{opentelemetry::trace::TraceFlags::kIsSampled}, true); + trace::TraceFlags{trace::TraceFlags::kIsSampled}, true); // and another to check preserving order. - uint8_t span_id_buf2[opentelemetry::trace::SpanId::kSize] = { + uint8_t span_id_buf2[trace::SpanId::kSize] = { 3, }; - opentelemetry::trace::SpanId span_id2{span_id_buf2}; - const auto span_context2 = opentelemetry::trace::SpanContext( + trace::SpanId span_id2{span_id_buf2}; + const auto span_context2 = trace::SpanContext( trace_id, span_id2, - opentelemetry::trace::TraceFlags{opentelemetry::trace::TraceFlags::kIsSampled}, true, - opentelemetry::trace::TraceState::FromHeader("state1=value")); + trace::TraceFlags{trace::TraceFlags::kIsSampled}, true, + trace::TraceState::FromHeader("state1=value")); recordable->AddLink(span_context); recordable->AddLink(span_context2, @@ -360,7 +361,7 @@ TEST(OStreamSpanExporter, PrintSpanWithLinks) TEST(OStreamSpanExporter, PrintSpanToCout) { auto exporter = std::unique_ptr( - new opentelemetry::exporter::trace::OStreamSpanExporter); + new exportertrace::OStreamSpanExporter); auto processor = std::shared_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); @@ -375,7 +376,7 @@ TEST(OStreamSpanExporter, PrintSpanToCout) TEST(OStreamSpanExporter, PrintSpanToCerr) { auto exporter = std::unique_ptr( - new opentelemetry::exporter::trace::OStreamSpanExporter(std::cerr)); + new exportertrace::OStreamSpanExporter(std::cerr)); auto processor = std::shared_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); @@ -390,7 +391,7 @@ TEST(OStreamSpanExporter, PrintSpanToCerr) TEST(OStreamSpanExporter, PrintSpanToClog) { auto exporter = std::unique_ptr( - new opentelemetry::exporter::trace::OStreamSpanExporter(std::clog)); + new exportertrace::OStreamSpanExporter(std::clog)); auto processor = std::shared_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); diff --git a/exporters/otlp/src/otlp_http_exporter.cc b/exporters/otlp/src/otlp_http_exporter.cc index d27c9fac3b..973a2714b0 100644 --- a/exporters/otlp/src/otlp_http_exporter.cc +++ b/exporters/otlp/src/otlp_http_exporter.cc @@ -71,8 +71,8 @@ class ResponseHandler : public http_client::EventHandler { std::stringstream ss; ss << "[OTLP HTTP Exporter] Status:" << response.GetStatusCode() << "Header:"; - response.ForEachHeader([&ss](opentelemetry::nostd::string_view header_name, - opentelemetry::nostd::string_view header_value) { + response.ForEachHeader([&ss](nostd::string_view header_name, + nostd::string_view header_value) { ss << "\t" << header_name.data() << " : " << header_value.data() << ","; return true; }); @@ -109,7 +109,7 @@ class ResponseHandler : public http_client::EventHandler // Callback method when an http event occurs void OnEvent(http_client::SessionState state, - opentelemetry::nostd::string_view reason) noexcept override + nostd::string_view reason) noexcept override { // If any failure event occurs, release the condition variable to unblock main thread switch (state) diff --git a/exporters/otlp/src/otlp_recordable.cc b/exporters/otlp/src/otlp_recordable.cc index b319a5ea9c..da3cc0103c 100644 --- a/exporters/otlp/src/otlp_recordable.cc +++ b/exporters/otlp/src/otlp_recordable.cc @@ -9,14 +9,19 @@ namespace exporter namespace otlp { +namespace trace = opentelemetry::trace; +namespace nostd = opentelemetry::nostd; +namespace proto = opentelemetry::proto; +namespace common = opentelemetry::common; + // // See `attribute_value.h` for details. // const int kAttributeValueSize = 16; const int kOwnedAttributeValueSize = 15; -void OtlpRecordable::SetIdentity(const opentelemetry::trace::SpanContext &span_context, - opentelemetry::trace::SpanId parent_span_id) noexcept +void OtlpRecordable::SetIdentity(const trace::SpanContext &span_context, + trace::SpanId parent_span_id) noexcept { span_.set_trace_id(reinterpret_cast(span_context.trace_id().Id().data()), trace::TraceId::kSize); @@ -27,14 +32,14 @@ void OtlpRecordable::SetIdentity(const opentelemetry::trace::SpanContext &span_c span_.set_trace_state(span_context.trace_state()->ToHeader()); } -void PopulateAttribute(opentelemetry::proto::common::v1::KeyValue *attribute, +void PopulateAttribute(proto::common::v1::KeyValue *attribute, nostd::string_view key, - const opentelemetry::common::AttributeValue &value) + const common::AttributeValue &value) { // Assert size of variant to ensure that this method gets updated if the variant // definition changes static_assert( - nostd::variant_size::value == kAttributeValueSize, + nostd::variant_size::value == kAttributeValueSize, "AttributeValue contains unknown type"); attribute->set_key(key.data(), key.size()); @@ -132,7 +137,7 @@ void PopulateAttribute(opentelemetry::proto::common::v1::KeyValue *attribute, } /** Maps from C++ attribute into OTLP proto attribute. */ -void PopulateAttribute(opentelemetry::proto::common::v1::KeyValue *attribute, +void PopulateAttribute(proto::common::v1::KeyValue *attribute, nostd::string_view key, const sdk::common::OwnedAttributeValue &value) { @@ -271,13 +276,13 @@ proto::common::v1::InstrumentationLibrary OtlpRecordable::GetProtoInstrumentatio return instrumentation_library; } -void OtlpRecordable::SetResource(const opentelemetry::sdk::resource::Resource &resource) noexcept +void OtlpRecordable::SetResource(const sdk::resource::Resource &resource) noexcept { resource_ = &resource; }; void OtlpRecordable::SetAttribute(nostd::string_view key, - const opentelemetry::common::AttributeValue &value) noexcept + const common::AttributeValue &value) noexcept { auto *attribute = span_.add_attributes(); PopulateAttribute(attribute, key, value); @@ -297,7 +302,7 @@ void OtlpRecordable::AddEvent(nostd::string_view name, }); } -void OtlpRecordable::AddLink(const opentelemetry::trace::SpanContext &span_context, +void OtlpRecordable::AddLink(const trace::SpanContext &span_context, const common::KeyValueIterable &attributes) noexcept { auto *link = span_.add_links(); @@ -314,7 +319,7 @@ void OtlpRecordable::AddLink(const opentelemetry::trace::SpanContext &span_conte void OtlpRecordable::SetStatus(trace::StatusCode code, nostd::string_view description) noexcept { - span_.mutable_status()->set_code(opentelemetry::proto::trace::v1::Status_StatusCode(code)); + span_.mutable_status()->set_code(proto::trace::v1::Status_StatusCode(code)); if (code == trace::StatusCode::kError) { span_.mutable_status()->set_message(description.data(), description.size()); @@ -326,49 +331,49 @@ void OtlpRecordable::SetName(nostd::string_view name) noexcept span_.set_name(name.data(), name.size()); } -void OtlpRecordable::SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept +void OtlpRecordable::SetSpanKind(trace::SpanKind span_kind) noexcept { - opentelemetry::proto::trace::v1::Span_SpanKind proto_span_kind = - opentelemetry::proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_UNSPECIFIED; + proto::trace::v1::Span_SpanKind proto_span_kind = + proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_UNSPECIFIED; switch (span_kind) { - case opentelemetry::trace::SpanKind::kInternal: + case trace::SpanKind::kInternal: proto_span_kind = - opentelemetry::proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_INTERNAL; + proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_INTERNAL; break; - case opentelemetry::trace::SpanKind::kServer: + case trace::SpanKind::kServer: proto_span_kind = - opentelemetry::proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_SERVER; + proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_SERVER; break; - case opentelemetry::trace::SpanKind::kClient: + case trace::SpanKind::kClient: proto_span_kind = - opentelemetry::proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_CLIENT; + proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_CLIENT; break; - case opentelemetry::trace::SpanKind::kProducer: + case trace::SpanKind::kProducer: proto_span_kind = - opentelemetry::proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_PRODUCER; + proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_PRODUCER; break; - case opentelemetry::trace::SpanKind::kConsumer: + case trace::SpanKind::kConsumer: proto_span_kind = - opentelemetry::proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_CONSUMER; + proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_CONSUMER; break; default: // shouldn't reach here. proto_span_kind = - opentelemetry::proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_UNSPECIFIED; + proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_UNSPECIFIED; } span_.set_kind(proto_span_kind); } -void OtlpRecordable::SetStartTime(opentelemetry::common::SystemTimestamp start_time) noexcept +void OtlpRecordable::SetStartTime(common::SystemTimestamp start_time) noexcept { span_.set_start_time_unix_nano(start_time.time_since_epoch().count()); } diff --git a/exporters/otlp/test/otlp_grpc_exporter_benchmark.cc b/exporters/otlp/test/otlp_grpc_exporter_benchmark.cc index e5dac38ba4..b2d37738f2 100644 --- a/exporters/otlp/test/otlp_grpc_exporter_benchmark.cc +++ b/exporters/otlp/test/otlp_grpc_exporter_benchmark.cc @@ -12,6 +12,8 @@ namespace exporter namespace otlp { +namespace trace_api = opentelemetry::trace; + const int kBatchSize = 200; const int kNumAttributes = 5; const int kNumIterations = 1000; @@ -22,10 +24,10 @@ const trace::SpanId kSpanId(std::array({0, 2})); const trace::SpanId kParentSpanId(std::array({0, 0, 0, 0, 0, 0, 0, 3})); -const auto kTraceState = opentelemetry::trace::TraceState::GetDefault() -> Set("key1", "value"); -const opentelemetry::trace::SpanContext kSpanContext{ +const auto kTraceState = trace_api::TraceState::GetDefault() -> Set("key1", "value"); +const trace_api::SpanContext kSpanContext{ kTraceId, kSpanId, - opentelemetry::trace::TraceFlags{opentelemetry::trace::TraceFlags::kIsSampled}, true, + trace_api::TraceFlags{trace_api::TraceFlags::kIsSampled}, true, kTraceState}; // ----------------------- Helper classes and functions ------------------------ diff --git a/exporters/otlp/test/otlp_http_exporter_test.cc b/exporters/otlp/test/otlp_http_exporter_test.cc index 413bf7c1a1..d8e5940af5 100644 --- a/exporters/otlp/test/otlp_http_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_exporter_test.cc @@ -32,6 +32,9 @@ namespace exporter namespace otlp { +namespace trace_api = opentelemetry::trace; +namespace resource = opentelemetry::sdk::resource; + template static nostd::span MakeSpan(T (&array)[N]) { @@ -187,7 +190,7 @@ TEST_F(OtlpHttpExporterTestPeer, ExportJsonIntegrationTest) size_t old_count = getCurrentRequestCount(); auto exporter = GetExporter(HttpRequestContentType::kJson); - opentelemetry::sdk::resource::ResourceAttributes resource_attributes = { + resource::ResourceAttributes resource_attributes = { {"service.name", "unit_test_service"}, {"tenant.id", "test_user"}}; resource_attributes["bool_value"] = true; resource_attributes["int32_value"] = static_cast(1); @@ -202,7 +205,7 @@ TEST_F(OtlpHttpExporterTestPeer, ExportJsonIntegrationTest) resource_attributes["vec_uint64_value"] = std::vector{7, 8}; resource_attributes["vec_double_value"] = std::vector{3.2, 3.3}; resource_attributes["vec_string_value"] = std::vector{"vector", "string"}; - auto resource = opentelemetry::sdk::resource::Resource::Create(resource_attributes); + auto resource = resource::Resource::Create(resource_attributes); auto processor_opts = sdk::trace::BatchSpanProcessorOptions(); processor_opts.max_export_batch_size = 5; @@ -215,18 +218,18 @@ TEST_F(OtlpHttpExporterTestPeer, ExportJsonIntegrationTest) std::string report_trace_id; { - char trace_id_hex[2 * opentelemetry::trace::TraceId::kSize] = {0}; + char trace_id_hex[2 * trace_api::TraceId::kSize] = {0}; auto tracer = provider->GetTracer("test"); auto parent_span = tracer->StartSpan("Test parent span"); - opentelemetry::trace::StartSpanOptions child_span_opts = {}; + trace_api::StartSpanOptions child_span_opts = {}; child_span_opts.parent = parent_span->GetContext(); auto child_span = tracer->StartSpan("Test child span", child_span_opts); child_span->End(); parent_span->End(); - nostd::get(child_span_opts.parent) + nostd::get(child_span_opts.parent) .trace_id() .ToLowerBase16(MakeSpan(trace_id_hex)); report_trace_id.assign(trace_id_hex, sizeof(trace_id_hex)); @@ -248,7 +251,7 @@ TEST_F(OtlpHttpExporterTestPeer, ExportBinaryIntegrationTest) auto exporter = GetExporter(HttpRequestContentType::kBinary); - opentelemetry::sdk::resource::ResourceAttributes resource_attributes = { + resource::ResourceAttributes resource_attributes = { {"service.name", "unit_test_service"}, {"tenant.id", "test_user"}}; resource_attributes["bool_value"] = true; resource_attributes["int32_value"] = static_cast(1); @@ -263,7 +266,7 @@ TEST_F(OtlpHttpExporterTestPeer, ExportBinaryIntegrationTest) resource_attributes["vec_uint64_value"] = std::vector{7, 8}; resource_attributes["vec_double_value"] = std::vector{3.2, 3.3}; resource_attributes["vec_string_value"] = std::vector{"vector", "string"}; - auto resource = opentelemetry::sdk::resource::Resource::Create(resource_attributes); + auto resource = resource::Resource::Create(resource_attributes); auto processor_opts = sdk::trace::BatchSpanProcessorOptions(); processor_opts.max_export_batch_size = 5; @@ -277,18 +280,18 @@ TEST_F(OtlpHttpExporterTestPeer, ExportBinaryIntegrationTest) std::string report_trace_id; { - uint8_t trace_id_binary[opentelemetry::trace::TraceId::kSize] = {0}; + uint8_t trace_id_binary[trace_api::TraceId::kSize] = {0}; auto tracer = provider->GetTracer("test"); auto parent_span = tracer->StartSpan("Test parent span"); - opentelemetry::trace::StartSpanOptions child_span_opts = {}; + trace_api::StartSpanOptions child_span_opts = {}; child_span_opts.parent = parent_span->GetContext(); auto child_span = tracer->StartSpan("Test child span", child_span_opts); child_span->End(); parent_span->End(); - nostd::get(child_span_opts.parent) + nostd::get(child_span_opts.parent) .trace_id() .CopyBytesTo(MakeSpan(trace_id_binary)); report_trace_id.assign(reinterpret_cast(trace_id_binary), sizeof(trace_id_binary)); diff --git a/exporters/otlp/test/otlp_recordable_test.cc b/exporters/otlp/test/otlp_recordable_test.cc index ddefe58843..2669482ad3 100644 --- a/exporters/otlp/test/otlp_recordable_test.cc +++ b/exporters/otlp/test/otlp_recordable_test.cc @@ -9,18 +9,23 @@ namespace exporter { namespace otlp { +namespace trace_api = opentelemetry::trace; +namespace trace_sdk = opentelemetry::sdk::trace; +namespace resource = opentelemetry::sdk::resource; +namespace proto = opentelemetry::proto; + TEST(OtlpRecordable, SetIdentity) { constexpr uint8_t trace_id_buf[] = {1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8}; constexpr uint8_t span_id_buf[] = {1, 2, 3, 4, 5, 6, 7, 8}; constexpr uint8_t parent_span_id_buf[] = {8, 7, 6, 5, 4, 3, 2, 1}; - opentelemetry::trace::TraceId trace_id{trace_id_buf}; - opentelemetry::trace::SpanId span_id{span_id_buf}; - opentelemetry::trace::SpanId parent_span_id{parent_span_id_buf}; - const auto trace_state = opentelemetry::trace::TraceState::GetDefault()->Set("key1", "value"); - const opentelemetry::trace::SpanContext span_context{ + trace_api::TraceId trace_id{trace_id_buf}; + trace_api::SpanId span_id{span_id_buf}; + trace_api::SpanId parent_span_id{parent_span_id_buf}; + const auto trace_state = trace_api::TraceState::GetDefault()->Set("key1", "value"); + const trace_api::SpanContext span_context{ trace_id, span_id, - opentelemetry::trace::TraceFlags{opentelemetry::trace::TraceFlags::kIsSampled}, true, + trace_api::TraceFlags{trace_api::TraceFlags::kIsSampled}, true, trace_state}; OtlpRecordable rec; @@ -47,16 +52,16 @@ TEST(OtlpRecordable, SetName) TEST(OtlpRecordable, SetSpanKind) { OtlpRecordable rec; - opentelemetry::trace::SpanKind span_kind = opentelemetry::trace::SpanKind::kServer; + trace_api::SpanKind span_kind = trace_api::SpanKind::kServer; rec.SetSpanKind(span_kind); EXPECT_EQ(rec.span().kind(), - opentelemetry::proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_SERVER); + proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_SERVER); } TEST(OtlpRecordable, SetInstrumentationLibrary) { OtlpRecordable rec; - auto inst_lib = opentelemetry::sdk::trace::InstrumentationLibrary::Create("test", "v1"); + auto inst_lib = trace_sdk::InstrumentationLibrary::Create("test", "v1"); rec.SetInstrumentationLibrary(*inst_lib); auto proto_instr_libr = rec.GetProtoInstrumentationLibrary(); EXPECT_EQ(proto_instr_libr.name(), inst_lib->GetName()); @@ -68,7 +73,7 @@ TEST(OtlpRecordable, SetInstrumentationLibraryWithSchemaURL) OtlpRecordable rec; const std::string expected_schema_url{"https://opentelemetry.io/schemas/1.2.0"}; auto inst_lib = - opentelemetry::sdk::trace::InstrumentationLibrary::Create("test", "v1", expected_schema_url); + trace_sdk::InstrumentationLibrary::Create("test", "v1", expected_schema_url); rec.SetInstrumentationLibrary(*inst_lib); EXPECT_EQ(expected_schema_url, rec.GetInstrumentationLibrarySchemaURL()); } @@ -109,14 +114,14 @@ TEST(OtlpRecordable, SetStatus) rec1.SetStatus(code_error, description); EXPECT_EQ(rec1.span().status().code(), - opentelemetry::proto::trace::v1::Status_StatusCode(code_error)); + proto::trace::v1::Status_StatusCode(code_error)); EXPECT_EQ(rec1.span().status().message(), description); OtlpRecordable rec2; trace::StatusCode code_ok(trace::StatusCode::kOk); rec2.SetStatus(code_ok, description); EXPECT_EQ(rec2.span().status().code(), - opentelemetry::proto::trace::v1::Status_StatusCode(code_ok)); + proto::trace::v1::Status_StatusCode(code_ok)); EXPECT_EQ(rec2.span().status().message(), ""); } @@ -192,7 +197,7 @@ TEST(OtlpRecordable, SetResource) const std::string service_name_key = "service.name"; std::string service_name = "test-otlp"; auto resource = - opentelemetry::sdk::resource::Resource::Create({{service_name_key, service_name}}); + resource::Resource::Create({{service_name_key, service_name}}); rec.SetResource(resource); auto proto_resource = rec.ProtoResource(); @@ -214,7 +219,7 @@ TEST(OtlpRecordable, SetResourceWithSchemaURL) const std::string service_name_key = "service.name"; const std::string service_name = "test-otlp"; const std::string expected_schema_url = "https://opentelemetry.io/schemas/1.2.0"; - auto resource = opentelemetry::sdk::resource::Resource::Create({{service_name_key, service_name}}, + auto resource = resource::Resource::Create({{service_name_key, service_name}}, expected_schema_url); rec.SetResource(resource); diff --git a/exporters/prometheus/test/prometheus_collector_test.cc b/exporters/prometheus/test/prometheus_collector_test.cc index 662fbf4f3e..1c202a1f6e 100644 --- a/exporters/prometheus/test/prometheus_collector_test.cc +++ b/exporters/prometheus/test/prometheus_collector_test.cc @@ -20,6 +20,8 @@ # include "opentelemetry/version.h" using opentelemetry::exporter::prometheus::PrometheusCollector; +namespace metric_api = opentelemetry::metrics; + OPENTELEMETRY_BEGIN_NAMESPACE @@ -36,35 +38,35 @@ std::shared_ptr> CreateAgg(metric_sdk::AggregatorKind { case metric_sdk::AggregatorKind::Counter: { aggregator = std::shared_ptr>( - new metric_sdk::CounterAggregator(opentelemetry::metrics::InstrumentKind::Counter)); + new metric_sdk::CounterAggregator(metric_api::InstrumentKind::Counter)); break; } case metric_sdk::AggregatorKind::MinMaxSumCount: { aggregator = std::shared_ptr>(new metric_sdk::MinMaxSumCountAggregator( - opentelemetry::metrics::InstrumentKind::Counter)); + metric_api::InstrumentKind::Counter)); break; } case metric_sdk::AggregatorKind::Gauge: { aggregator = std::shared_ptr>( - new metric_sdk::GaugeAggregator(opentelemetry::metrics::InstrumentKind::Counter)); + new metric_sdk::GaugeAggregator(metric_api::InstrumentKind::Counter)); break; } case metric_sdk::AggregatorKind::Sketch: { aggregator = std::shared_ptr>(new metric_sdk::SketchAggregator( - opentelemetry::metrics::InstrumentKind::Counter, 0.000005)); + metric_api::InstrumentKind::Counter, 0.000005)); break; } case metric_sdk::AggregatorKind::Histogram: { std::vector boundaries{10, 20}; aggregator = std::shared_ptr>(new metric_sdk::HistogramAggregator( - opentelemetry::metrics::InstrumentKind::Counter, boundaries)); + metric_api::InstrumentKind::Counter, boundaries)); break; } case metric_sdk::AggregatorKind::Exact: { aggregator = std::shared_ptr>(new metric_sdk::ExactAggregator( - opentelemetry::metrics::InstrumentKind::Counter, exactMode)); + metric_api::InstrumentKind::Counter, exactMode)); break; } default: diff --git a/exporters/zipkin/src/recordable.cc b/exporters/zipkin/src/recordable.cc index e9da830348..d4b2d515fc 100644 --- a/exporters/zipkin/src/recordable.cc +++ b/exporters/zipkin/src/recordable.cc @@ -14,13 +14,16 @@ namespace zipkin { using namespace opentelemetry::sdk::resource; +namespace trace_api = opentelemetry::trace; +namespace common = opentelemetry::common; +namespace sdk = opentelemetry::sdk; // constexpr needs keys to be constexpr, const is next best to use. -static const std::map kSpanKindMap = { - {opentelemetry::trace::SpanKind::kClient, "CLIENT"}, - {opentelemetry::trace::SpanKind::kServer, "SERVER"}, - {opentelemetry::trace::SpanKind::kConsumer, "CONSUMER"}, - {opentelemetry::trace::SpanKind::kProducer, "PRODUCER"}, +static const std::map kSpanKindMap = { + {trace_api::SpanKind::kClient, "CLIENT"}, + {trace_api::SpanKind::kServer, "SERVER"}, + {trace_api::SpanKind::kConsumer, "CONSUMER"}, + {trace_api::SpanKind::kProducer, "PRODUCER"}, }; // @@ -28,8 +31,8 @@ static const std::map kSpanKindMap // const int kAttributeValueSize = 16; -void Recordable::SetIdentity(const opentelemetry::trace::SpanContext &span_context, - opentelemetry::trace::SpanId parent_span_id) noexcept +void Recordable::SetIdentity(const trace_api::SpanContext &span_context, + trace_api::SpanId parent_span_id) noexcept { char trace_id_lower_base16[trace::TraceId::kSize * 2] = {0}; span_context.trace_id().ToLowerBase16(trace_id_lower_base16); @@ -48,12 +51,12 @@ void Recordable::SetIdentity(const opentelemetry::trace::SpanContext &span_conte void PopulateAttribute(nlohmann::json &attribute, nostd::string_view key, - const opentelemetry::common::AttributeValue &value) + const common::AttributeValue &value) { // Assert size of variant to ensure that this method gets updated if the variant // definition changes static_assert( - nostd::variant_size::value == kAttributeValueSize, + nostd::variant_size::value == kAttributeValueSize, "AttributeValue contains unknown type"); if (nostd::holds_alternative(value)) @@ -156,7 +159,7 @@ void PopulateAttribute(nlohmann::json &attribute, } void Recordable::SetAttribute(nostd::string_view key, - const opentelemetry::common::AttributeValue &value) noexcept + const common::AttributeValue &value) noexcept { if (!span_.contains("tags")) { @@ -187,7 +190,7 @@ void Recordable::AddEvent(nostd::string_view name, span_["annotations"].push_back(annotation); } -void Recordable::AddLink(const opentelemetry::trace::SpanContext &span_context, +void Recordable::AddLink(const trace_api::SpanContext &span_context, const common::KeyValueIterable &attributes) noexcept { // TODO: Currently not supported by specs: @@ -211,7 +214,7 @@ void Recordable::SetName(nostd::string_view name) noexcept span_["name"] = name.data(); } -void Recordable::SetResource(const opentelemetry::sdk::resource::Resource &resource) noexcept +void Recordable::SetResource(const sdk::resource::Resource &resource) noexcept { // only service.name attribute is supported by specs as of now. auto attributes = resource.GetAttributes(); @@ -221,7 +224,7 @@ void Recordable::SetResource(const opentelemetry::sdk::resource::Resource &resou } } -void Recordable::SetStartTime(opentelemetry::common::SystemTimestamp start_time) noexcept +void Recordable::SetStartTime(common::SystemTimestamp start_time) noexcept { span_["timestamp"] = std::chrono::duration_cast(start_time.time_since_epoch()).count(); @@ -232,7 +235,7 @@ void Recordable::SetDuration(std::chrono::nanoseconds duration) noexcept span_["duration"] = std::chrono::duration_cast(duration).count(); } -void Recordable::SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept +void Recordable::SetSpanKind(trace_api::SpanKind span_kind) noexcept { auto span_iter = kSpanKindMap.find(span_kind); if (span_iter != kSpanKindMap.end()) @@ -242,7 +245,7 @@ void Recordable::SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept } void Recordable::SetInstrumentationLibrary( - const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary + const sdk::instrumentationlibrary::InstrumentationLibrary &instrumentation_library) noexcept { span_["tags"]["otel.library.name"] = instrumentation_library.GetName(); diff --git a/exporters/zipkin/test/zipkin_recordable_test.cc b/exporters/zipkin/test/zipkin_recordable_test.cc index dd66a058eb..315069b3da 100644 --- a/exporters/zipkin/test/zipkin_recordable_test.cc +++ b/exporters/zipkin/test/zipkin_recordable_test.cc @@ -17,6 +17,8 @@ namespace trace = opentelemetry::trace; namespace nostd = opentelemetry::nostd; namespace sdktrace = opentelemetry::sdk::trace; +namespace common = opentelemetry::common; +namespace zipkin = opentelemetry::exporter::zipkin; using json = nlohmann::json; // Testing Shutdown functionality of OStreamSpanExporter, should expect no data to be sent to Stream @@ -25,7 +27,7 @@ TEST(ZipkinSpanRecordable, SetIdentity) json j_span = {{"id", "0000000000000002"}, {"parentId", "0000000000000003"}, {"traceId", "00000000000000000000000000000001"}}; - opentelemetry::exporter::zipkin::Recordable rec; + zipkin::Recordable rec; const trace::TraceId trace_id(std::array( {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1})); @@ -35,9 +37,9 @@ TEST(ZipkinSpanRecordable, SetIdentity) const trace::SpanId parent_span_id( std::array({0, 0, 0, 0, 0, 0, 0, 3})); - const opentelemetry::trace::SpanContext span_context{ + const trace::SpanContext span_context{ trace_id, span_id, - opentelemetry::trace::TraceFlags{opentelemetry::trace::TraceFlags::kIsSampled}, true}; + trace::TraceFlags{trace::TraceFlags::kIsSampled}, true}; rec.SetIdentity(span_context, parent_span_id); EXPECT_EQ(rec.span(), j_span); @@ -48,7 +50,7 @@ TEST(ZipkinSpanRecordable, SetIdentity) TEST(ZipkinSpanRecordable, SetIdentityEmptyParent) { json j_span = {{"id", "0000000000000002"}, {"traceId", "00000000000000000000000000000001"}}; - opentelemetry::exporter::zipkin::Recordable rec; + zipkin::Recordable rec; const trace::TraceId trace_id(std::array( {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1})); @@ -58,9 +60,9 @@ TEST(ZipkinSpanRecordable, SetIdentityEmptyParent) const trace::SpanId parent_span_id( std::array({0, 0, 0, 0, 0, 0, 0, 0})); - const opentelemetry::trace::SpanContext span_context{ + const trace::SpanContext span_context{ trace_id, span_id, - opentelemetry::trace::TraceFlags{opentelemetry::trace::TraceFlags::kIsSampled}, true}; + trace::TraceFlags{trace::TraceFlags::kIsSampled}, true}; rec.SetIdentity(span_context, parent_span_id); EXPECT_EQ(rec.span(), j_span); @@ -70,16 +72,16 @@ TEST(ZipkinSpanRecordable, SetName) { nostd::string_view name = "Test Span"; json j_span = {{"name", name}}; - opentelemetry::exporter::zipkin::Recordable rec; + zipkin::Recordable rec; rec.SetName(name); EXPECT_EQ(rec.span(), j_span); } TEST(ZipkinSpanRecordable, SetStartTime) { - opentelemetry::exporter::zipkin::Recordable rec; + zipkin::Recordable rec; std::chrono::system_clock::time_point start_time = std::chrono::system_clock::now(); - opentelemetry::common::SystemTimestamp start_timestamp(start_time); + common::SystemTimestamp start_timestamp(start_time); uint64_t unix_start = std::chrono::duration_cast(start_time.time_since_epoch()).count(); @@ -94,9 +96,9 @@ TEST(ZipkinSpanRecordable, SetDuration) std::chrono::microseconds durationMS = std::chrono::duration_cast(durationNS); // in ms json j_span = {{"duration", durationMS.count()}, {"timestamp", 0}}; - opentelemetry::exporter::zipkin::Recordable rec; + zipkin::Recordable rec; // Start time is 0 - opentelemetry::common::SystemTimestamp start_timestamp; + common::SystemTimestamp start_timestamp; rec.SetStartTime(start_timestamp); rec.SetDuration(durationNS); @@ -111,7 +113,7 @@ TEST(ZipkinSpanRecordable, SetInstrumentationLibrary) const char *library_version = "0.5.0"; json j_span = { {"tags", {{"otel.library.name", library_name}, {"otel.library.version", library_version}}}}; - opentelemetry::exporter::zipkin::Recordable rec; + zipkin::Recordable rec; rec.SetInstrumentationLibrary(*InstrumentationLibrary::Create(library_name, library_version)); @@ -124,7 +126,7 @@ TEST(ZipkinSpanRecordable, SetStatus) std::vector status_codes = {trace::StatusCode::kError, trace::StatusCode::kOk}; for (auto &status_code : status_codes) { - opentelemetry::exporter::zipkin::Recordable rec; + zipkin::Recordable rec; trace::StatusCode code(status_code); json j_span; if (status_code == trace::StatusCode::kError) @@ -140,20 +142,20 @@ TEST(ZipkinSpanRecordable, SetStatus) TEST(ZipkinSpanRecordable, SetSpanKind) { json j_json_client = {{"kind", "CLIENT"}}; - opentelemetry::exporter::zipkin::Recordable rec; - rec.SetSpanKind(opentelemetry::trace::SpanKind::kClient); + zipkin::Recordable rec; + rec.SetSpanKind(trace::SpanKind::kClient); EXPECT_EQ(rec.span(), j_json_client); } TEST(ZipkinSpanRecordable, AddEventDefault) { - opentelemetry::exporter::zipkin::Recordable rec; + zipkin::Recordable rec; nostd::string_view name = "Test Event"; std::chrono::system_clock::time_point event_time = std::chrono::system_clock::now(); - opentelemetry::common::SystemTimestamp event_timestamp(event_time); + common::SystemTimestamp event_timestamp(event_time); - rec.opentelemetry::sdk::trace::Recordable::AddEvent(name, event_timestamp); + rec.sdktrace::Recordable::AddEvent(name, event_timestamp); uint64_t unix_event_time = std::chrono::duration_cast(event_time.time_since_epoch()).count(); @@ -166,10 +168,10 @@ TEST(ZipkinSpanRecordable, AddEventDefault) TEST(ZipkinSpanRecordable, AddEventWithAttributes) { - opentelemetry::exporter::zipkin::Recordable rec; + zipkin::Recordable rec; std::chrono::system_clock::time_point event_time = std::chrono::system_clock::now(); - opentelemetry::common::SystemTimestamp event_timestamp(event_time); + common::SystemTimestamp event_timestamp(event_time); uint64_t unix_event_time = std::chrono::duration_cast(event_time.time_since_epoch()).count(); @@ -180,7 +182,7 @@ TEST(ZipkinSpanRecordable, AddEventWithAttributes) {keys[0], values[0]}, {keys[1], values[1]}, {keys[2], values[2]}}; rec.AddEvent("Test Event", event_timestamp, - opentelemetry::common::KeyValueIterableView>(attributes)); + common::KeyValueIterableView>(attributes)); nlohmann::json j_span = { {"annotations", @@ -192,17 +194,17 @@ TEST(ZipkinSpanRecordable, AddEventWithAttributes) // Test non-int single types. Int single types are tested using templates (see IntAttributeTest) TEST(ZipkinSpanRecordable, SetSingleAtrribute) { - opentelemetry::exporter::zipkin::Recordable rec; + zipkin::Recordable rec; nostd::string_view bool_key = "bool_attr"; - opentelemetry::common::AttributeValue bool_val(true); + common::AttributeValue bool_val(true); rec.SetAttribute(bool_key, bool_val); nostd::string_view double_key = "double_attr"; - opentelemetry::common::AttributeValue double_val(3.3); + common::AttributeValue double_val(3.3); rec.SetAttribute(double_key, double_val); nostd::string_view str_key = "str_attr"; - opentelemetry::common::AttributeValue str_val(nostd::string_view("Test")); + common::AttributeValue str_val(nostd::string_view("Test")); rec.SetAttribute(str_key, str_val); nlohmann::json j_span = { {"tags", {{"bool_attr", true}, {"double_attr", 3.3}, {"str_attr", "Test"}}}}; @@ -213,7 +215,7 @@ TEST(ZipkinSpanRecordable, SetSingleAtrribute) // Test non-int array types. Int array types are tested using templates (see IntAttributeTest) TEST(ZipkinSpanRecordable, SetArrayAtrribute) { - opentelemetry::exporter::zipkin::Recordable rec; + zipkin::Recordable rec; nlohmann::json j_span = {{"tags", {{"bool_arr_attr", {true, false, true}}, {"double_arr_attr", {22.3, 33.4, 44.5}}, @@ -237,7 +239,7 @@ TEST(ZipkinSpanRecordable, SetArrayAtrribute) TEST(ZipkinSpanRecordable, SetResource) { - opentelemetry::exporter::zipkin::Recordable rec; + zipkin::Recordable rec; std::string service_name = "test"; auto resource = opentelemetry::sdk::resource::Resource::Create({{"service.name", service_name}}); rec.SetResource(resource); @@ -262,9 +264,9 @@ TYPED_TEST(ZipkinIntAttributeTest, SetIntSingleAttribute) { using IntType = typename TestFixture::IntParamType; IntType i = 2; - opentelemetry::common::AttributeValue int_val(i); + common::AttributeValue int_val(i); - opentelemetry::exporter::zipkin::Recordable rec; + zipkin::Recordable rec; rec.SetAttribute("int_attr", int_val); nlohmann::json j_span = {{"tags", {{"int_attr", 2}}}}; EXPECT_EQ(rec.span(), j_span); @@ -278,7 +280,7 @@ TYPED_TEST(ZipkinIntAttributeTest, SetIntArrayAttribute) IntType int_arr[kArraySize] = {4, 5, 6}; nostd::span int_span(int_arr); - opentelemetry::exporter::zipkin::Recordable rec; + zipkin::Recordable rec; rec.SetAttribute("int_arr_attr", int_span); nlohmann::json j_span = {{"tags", {{"int_arr_attr", {4, 5, 6}}}}}; EXPECT_EQ(rec.span(), j_span); diff --git a/ext/src/http/client/curl/http_client_factory_curl.cc b/ext/src/http/client/curl/http_client_factory_curl.cc index 51c90ee0c9..8d2da108f1 100644 --- a/ext/src/http/client/curl/http_client_factory_curl.cc +++ b/ext/src/http/client/curl/http_client_factory_curl.cc @@ -5,14 +5,16 @@ #include "opentelemetry/ext/http/client/http_client.h" #include "opentelemetry/ext/http/client/http_client_factory.h" -std::shared_ptr -opentelemetry::ext::http::client::HttpClientFactory::Create() +namespace http_client = opentelemetry::ext::http::client; + +std::shared_ptr +http_client::HttpClientFactory::Create() { - return std::make_shared(); + return std::make_shared(); } -std::shared_ptr -opentelemetry::ext::http::client::HttpClientFactory::CreateSync() +std::shared_ptr +http_client::HttpClientFactory::CreateSync() { - return std::make_shared(); + return std::make_shared(); } \ No newline at end of file diff --git a/ext/src/zpages/tracez_http_server.cc b/ext/src/zpages/tracez_http_server.cc index 958d1c708c..a5d0072787 100644 --- a/ext/src/zpages/tracez_http_server.cc +++ b/ext/src/zpages/tracez_http_server.cc @@ -8,6 +8,7 @@ namespace ext { namespace zpages { +namespace nostd = opentelemetry::nostd; json TracezHttpServer::GetAggregations() { @@ -123,34 +124,34 @@ json TracezHttpServer::GetAttributesJSON( switch (val.index()) { case 0: - attributes_json[key] = opentelemetry::nostd::get<0>(val); + attributes_json[key] = nostd::get<0>(val); break; case 1: - attributes_json[key] = opentelemetry::nostd::get<1>(val); + attributes_json[key] = nostd::get<1>(val); break; case 2: - attributes_json[key] = opentelemetry::nostd::get<2>(val); + attributes_json[key] = nostd::get<2>(val); break; case 3: - attributes_json[key] = opentelemetry::nostd::get<3>(val); + attributes_json[key] = nostd::get<3>(val); break; case 4: - attributes_json[key] = opentelemetry::nostd::get<4>(val); + attributes_json[key] = nostd::get<4>(val); break; case 5: - attributes_json[key] = opentelemetry::nostd::get<5>(val); + attributes_json[key] = nostd::get<5>(val); break; case 6: - attributes_json[key] = opentelemetry::nostd::get<6>(val); + attributes_json[key] = nostd::get<6>(val); break; case 7: - attributes_json[key] = opentelemetry::nostd::get<7>(val); + attributes_json[key] = nostd::get<7>(val); break; case 8: - attributes_json[key] = opentelemetry::nostd::get<8>(val); + attributes_json[key] = nostd::get<8>(val); break; case 9: - attributes_json[key] = opentelemetry::nostd::get<9>(val); + attributes_json[key] = nostd::get<9>(val); break; } } diff --git a/ext/src/zpages/tracez_processor.cc b/ext/src/zpages/tracez_processor.cc index d6108e1997..8054274e8d 100644 --- a/ext/src/zpages/tracez_processor.cc +++ b/ext/src/zpages/tracez_processor.cc @@ -8,15 +8,16 @@ namespace ext { namespace zpages { +namespace trace_sdk = opentelemetry::sdk::trace; -void TracezSpanProcessor::OnStart(opentelemetry::sdk::trace::Recordable &span, +void TracezSpanProcessor::OnStart(trace_sdk::Recordable &span, const opentelemetry::trace::SpanContext &parent_context) noexcept { shared_data_->OnStart(static_cast(&span)); } void TracezSpanProcessor::OnEnd( - std::unique_ptr &&span) noexcept + std::unique_ptr &&span) noexcept { shared_data_->OnEnd( std::unique_ptr(static_cast(span.release()))); diff --git a/ext/test/http/curl_http_test.cc b/ext/test/http/curl_http_test.cc index 121dbd143a..a737ac8a89 100644 --- a/ext/test/http/curl_http_test.cc +++ b/ext/test/http/curl_http_test.cc @@ -20,13 +20,14 @@ namespace curl = opentelemetry::ext::http::client::curl; namespace http_client = opentelemetry::ext::http::client; +namespace nostd = opentelemetry::nostd; class CustomEventHandler : public http_client::EventHandler { public: virtual void OnResponse(http_client::Response &response) noexcept override{}; virtual void OnEvent(http_client::SessionState state, - opentelemetry::nostd::string_view reason) noexcept override + nostd::string_view reason) noexcept override {} virtual void OnConnecting(const http_client::SSLCertificate &) noexcept {} virtual ~CustomEventHandler() = default; @@ -166,8 +167,8 @@ TEST_F(BasicCurlHttpTests, HttpResponse) const char *b = "test-data"; http_client::Body body = {b, b + strlen(b)}; int count = 0; - res.ForEachHeader("name1", [&count](opentelemetry::nostd::string_view name, - opentelemetry::nostd::string_view value) { + res.ForEachHeader("name1", [&count](nostd::string_view name, + nostd::string_view value) { if (name != "name1") return false; if (value != "value1_1" && value != "value1_2") @@ -178,7 +179,7 @@ TEST_F(BasicCurlHttpTests, HttpResponse) ASSERT_EQ(count, 2); count = 0; res.ForEachHeader( - [&count](opentelemetry::nostd::string_view name, opentelemetry::nostd::string_view value) { + [&count](nostd::string_view name, nostd::string_view value) { if (name != "name1" && name != "name2" && name != "name3") return false; if (value != "value1_1" && value != "value1_2" && value != "value2" && value != "value3") diff --git a/ext/test/w3c_tracecontext_test/main.cc b/ext/test/w3c_tracecontext_test/main.cc index bc0f9bd65d..07291caaf4 100644 --- a/ext/test/w3c_tracecontext_test/main.cc +++ b/ext/test/w3c_tracecontext_test/main.cc @@ -14,11 +14,16 @@ #include #include "nlohmann/json.hpp" +namespace trace_api = opentelemetry::trace; +namespace http_client = opentelemetry::ext::http::client; +namespace curl = opentelemetry::ext::http::client::curl; +namespace context = opentelemetry::context; + namespace { -static opentelemetry::trace::propagation::HttpTraceContext propagator_format; +static trace_api::propagation::HttpTraceContext propagator_format; -class TextMapCarrierTest : public opentelemetry::context::propagation::TextMapCarrier +class TextMapCarrierTest : public context::propagation::TextMapCarrier { public: TextMapCarrierTest(std::map &headers) : headers_(headers) {} @@ -48,15 +53,15 @@ void initTracer() std::vector> processors; processors.push_back(std::move(processor)); auto context = std::make_shared(std::move(processors)); - auto provider = nostd::shared_ptr( + auto provider = nostd::shared_ptr( new sdktrace::TracerProvider(context)); // Set the global trace provider - opentelemetry::trace::Provider::SetTracerProvider(provider); + trace_api::Provider::SetTracerProvider(provider); } -nostd::shared_ptr get_tracer() +nostd::shared_ptr get_tracer() { - auto provider = opentelemetry::trace::Provider::GetTracerProvider(); + auto provider = trace_api::Provider::GetTracerProvider(); return provider->GetTracer("w3c_tracecontext_test"); } @@ -79,45 +84,45 @@ struct Uri // A noop event handler for making HTTP requests. We don't care about response bodies and error // messages. -class NoopEventHandler : public opentelemetry::ext::http::client::EventHandler +class NoopEventHandler : public http_client::EventHandler { public: - void OnEvent(opentelemetry::ext::http::client::SessionState state, + void OnEvent(http_client::SessionState state, opentelemetry::nostd::string_view reason) noexcept override {} - void OnConnecting(const opentelemetry::ext::http::client::SSLCertificate &) noexcept override {} + void OnConnecting(const http_client::SSLCertificate &) noexcept override {} - void OnResponse(opentelemetry::ext::http::client::Response &response) noexcept override {} + void OnResponse(http_client::Response &response) noexcept override {} }; } // namespace // Sends an HTTP POST request to the given url, with the given body. -void send_request(opentelemetry::ext::http::client::curl::HttpClient &client, +void send_request(curl::HttpClient &client, const std::string &url, const std::string &body) { - static std::unique_ptr handler( + static std::unique_ptr handler( new NoopEventHandler()); auto request_span = get_tracer()->StartSpan(__func__); - opentelemetry::trace::Scope scope(request_span); + trace_api::Scope scope(request_span); Uri uri{url}; auto session = client.CreateSession(url); auto request = session->CreateRequest(); - request->SetMethod(opentelemetry::ext::http::client::Method::Post); + request->SetMethod(http_client::Method::Post); request->SetUri(uri.path); - opentelemetry::ext::http::client::Body b = {body.c_str(), body.c_str() + body.size()}; + http_client::Body b = {body.c_str(), body.c_str() + body.size()}; request->SetBody(b); request->AddHeader("Content-Type", "application/json"); request->AddHeader("Content-Length", std::to_string(body.size())); std::map headers; TextMapCarrierTest carrier(headers); - propagator_format.Inject(carrier, opentelemetry::context::RuntimeContext::GetCurrent()); + propagator_format.Inject(carrier, context::RuntimeContext::GetCurrent()); for (auto const &hdr : headers) { @@ -150,10 +155,10 @@ int main(int argc, char *argv[]) } auto root_span = get_tracer()->StartSpan(__func__); - opentelemetry::trace::Scope scope(root_span); + trace_api::Scope scope(root_span); testing::HttpServer server(default_host, port); - opentelemetry::ext::http::client::curl::HttpClient client; + curl::HttpClient client; testing::HttpRequestCallback test_cb{ [&](testing::HttpRequest const &req, testing::HttpResponse &resp) { @@ -164,9 +169,9 @@ int main(int argc, char *argv[]) for (auto &part : body) { const TextMapCarrierTest carrier((std::map &)req.headers); - auto current_ctx = opentelemetry::context::RuntimeContext::GetCurrent(); + auto current_ctx = context::RuntimeContext::GetCurrent(); auto ctx = propagator_format.Extract(carrier, current_ctx); - auto token = opentelemetry::context::RuntimeContext::Attach(ctx); + auto token = context::RuntimeContext::Attach(ctx); auto url = part["url"].get(); auto arguments = part["arguments"].dump(); diff --git a/ext/test/zpages/threadsafe_span_data_test.cc b/ext/test/zpages/threadsafe_span_data_test.cc index 9078203ef3..e540e36e28 100644 --- a/ext/test/zpages/threadsafe_span_data_test.cc +++ b/ext/test/zpages/threadsafe_span_data_test.cc @@ -13,10 +13,12 @@ using opentelemetry::ext::zpages::ThreadsafeSpanData; using opentelemetry::sdk::common::AttributeConverter; using opentelemetry::sdk::common::OwnedAttributeValue; +namespace trace_api = opentelemetry::trace; + TEST(ThreadsafeSpanData, DefaultValues) { - opentelemetry::trace::SpanContext empty_span_context{false, false}; - opentelemetry::trace::SpanId zero_span_id; + trace_api::SpanContext empty_span_context{false, false}; + trace_api::SpanId zero_span_id; ThreadsafeSpanData data; ASSERT_EQ(data.GetTraceId(), empty_span_context.trace_id()); @@ -24,7 +26,7 @@ TEST(ThreadsafeSpanData, DefaultValues) ASSERT_EQ(data.GetSpanContext(), empty_span_context); ASSERT_EQ(data.GetParentSpanId(), zero_span_id); ASSERT_EQ(data.GetName(), ""); - ASSERT_EQ(data.GetStatus(), opentelemetry::trace::StatusCode::kUnset); + ASSERT_EQ(data.GetStatus(), trace_api::StatusCode::kUnset); ASSERT_EQ(data.GetDescription(), ""); ASSERT_EQ(data.GetStartTime().time_since_epoch(), std::chrono::nanoseconds(0)); ASSERT_EQ(data.GetDuration(), std::chrono::nanoseconds(0)); @@ -36,21 +38,21 @@ TEST(ThreadsafeSpanData, Set) constexpr uint8_t trace_id_buf[] = {1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8}; constexpr uint8_t span_id_buf[] = {1, 2, 3, 4, 5, 6, 7, 8}; constexpr uint8_t parent_span_id_buf[] = {8, 7, 6, 5, 4, 3, 2, 1}; - opentelemetry::trace::TraceId trace_id{trace_id_buf}; - opentelemetry::trace::SpanId span_id{span_id_buf}; - opentelemetry::trace::SpanId parent_span_id{parent_span_id_buf}; - const auto trace_state = opentelemetry::trace::TraceState::GetDefault()->Set("key1", "value"); - const opentelemetry::trace::SpanContext span_context{ + trace_api::TraceId trace_id{trace_id_buf}; + trace_api::SpanId span_id{span_id_buf}; + trace_api::SpanId parent_span_id{parent_span_id_buf}; + const auto trace_state = trace_api::TraceState::GetDefault()->Set("key1", "value"); + const trace_api::SpanContext span_context{ trace_id, span_id, - opentelemetry::trace::TraceFlags{opentelemetry::trace::TraceFlags::kIsSampled}, true, + trace_api::TraceFlags{trace_api::TraceFlags::kIsSampled}, true, trace_state}; opentelemetry::common::SystemTimestamp now(std::chrono::system_clock::now()); ThreadsafeSpanData data; data.SetIdentity(span_context, parent_span_id); data.SetName("span name"); - data.SetSpanKind(opentelemetry::trace::SpanKind::kServer); - data.SetStatus(opentelemetry::trace::StatusCode::kOk, "description"); + data.SetSpanKind(trace_api::SpanKind::kServer); + data.SetStatus(trace_api::StatusCode::kOk, "description"); data.SetStartTime(now); data.SetDuration(std::chrono::nanoseconds(1000000)); data.SetAttribute("attr1", (int64_t)314159); @@ -64,7 +66,7 @@ TEST(ThreadsafeSpanData, Set) ASSERT_EQ(trace_state_key1_value, "value"); ASSERT_EQ(data.GetParentSpanId(), parent_span_id); ASSERT_EQ(data.GetName(), "span name"); - ASSERT_EQ(data.GetStatus(), opentelemetry::trace::StatusCode::kOk); + ASSERT_EQ(data.GetStatus(), trace_api::StatusCode::kOk); ASSERT_EQ(data.GetDescription(), "description"); ASSERT_EQ(data.GetStartTime().time_since_epoch(), now.time_since_epoch()); ASSERT_EQ(data.GetDuration(), std::chrono::nanoseconds(1000000)); diff --git a/ext/test/zpages/tracez_data_aggregator_test.cc b/ext/test/zpages/tracez_data_aggregator_test.cc index 5139c9e914..0cb647fac4 100644 --- a/ext/test/zpages/tracez_data_aggregator_test.cc +++ b/ext/test/zpages/tracez_data_aggregator_test.cc @@ -14,6 +14,8 @@ using namespace opentelemetry::sdk::trace; using namespace opentelemetry::ext::zpages; namespace nostd = opentelemetry::nostd; namespace common = opentelemetry::common; +namespace trace_api = opentelemetry::trace; + using opentelemetry::common::SteadyTimestamp; using opentelemetry::trace::Span; @@ -44,13 +46,13 @@ class TracezDataAggregatorTest : public ::testing::Test processors.push_back(std::move(processor)); auto context = std::make_shared(std::move(processors), resource); - tracer = std::shared_ptr(new Tracer(context)); + tracer = std::shared_ptr(new Tracer(context)); tracez_data_aggregator = std::unique_ptr( new TracezDataAggregator(shared_data, milliseconds(10))); } std::unique_ptr tracez_data_aggregator; - std::shared_ptr tracer; + std::shared_ptr tracer; }; /** @@ -133,9 +135,9 @@ TEST_F(TracezDataAggregatorTest, SingleRunningSpan) TEST_F(TracezDataAggregatorTest, SingleCompletedSpan) { // Start and end the span at a specified times - opentelemetry::trace::StartSpanOptions start; + trace_api::StartSpanOptions start; start.start_steady_time = SteadyTimestamp(nanoseconds(10)); - opentelemetry::trace::EndSpanOptions end; + trace_api::EndSpanOptions end; end.end_steady_time = SteadyTimestamp(nanoseconds(40)); tracer->StartSpan(span_name1, start)->End(end); @@ -164,7 +166,7 @@ TEST_F(TracezDataAggregatorTest, SingleErrorSpan) { // Start and end a single error span auto span = tracer->StartSpan(span_name1); - span->SetStatus(opentelemetry::trace::StatusCode::kError, "span cancelled"); + span->SetStatus(trace_api::StatusCode::kError, "span cancelled"); span->End(); std::this_thread::sleep_for(milliseconds(500)); auto data = tracez_data_aggregator->GetAggregatedTracezData(); @@ -257,8 +259,8 @@ TEST_F(TracezDataAggregatorTest, MultipleCompletedSpan) {}, {}, {nanoseconds(9999999999999)}}}}); - opentelemetry::trace::StartSpanOptions start; - opentelemetry::trace::EndSpanOptions end; + trace_api::StartSpanOptions start; + trace_api::EndSpanOptions end; for (auto &span : span_name_to_duration) { for (auto &buckets : span.second) @@ -328,7 +330,7 @@ TEST_F(TracezDataAggregatorTest, MultipleErrorSpans) for (auto error_desc : span_error.second) { auto span = tracer->StartSpan(span_error.first); - span->SetStatus(opentelemetry::trace::StatusCode::kError, error_desc); + span->SetStatus(trace_api::StatusCode::kError, error_desc); span->End(); } } @@ -408,7 +410,7 @@ TEST_F(TracezDataAggregatorTest, ErrorSampleSpansOverCapacity) for (auto span_error_description : span_error_descriptions) { auto span = tracer->StartSpan(span_name1); - span->SetStatus(opentelemetry::trace::StatusCode::kError, span_error_description); + span->SetStatus(trace_api::StatusCode::kError, span_error_description); span->End(); } @@ -443,8 +445,8 @@ TEST_F(TracezDataAggregatorTest, ErrorSampleSpansOverCapacity) */ TEST_F(TracezDataAggregatorTest, CompletedSampleSpansOverCapacity) { - opentelemetry::trace::StartSpanOptions start; - opentelemetry::trace::EndSpanOptions end; + trace_api::StartSpanOptions start; + trace_api::EndSpanOptions end; // Start and end 6 spans with the same name that fall into the first latency // bucket @@ -498,7 +500,7 @@ TEST_F(TracezDataAggregatorTest, SpanNameInAlphabeticalOrder) auto span_first = tracer->StartSpan(span_name2); tracer->StartSpan(span_name1)->End(); auto span_third = tracer->StartSpan(span_name3); - span_third->SetStatus(opentelemetry::trace::StatusCode::kError, "span cancelled"); + span_third->SetStatus(trace_api::StatusCode::kError, "span cancelled"); span_third->End(); std::this_thread::sleep_for(milliseconds(500)); // Get data and check if span name exists in aggregation @@ -550,9 +552,9 @@ TEST_F(TracezDataAggregatorTest, AdditionToRunningSpans) * aggregated data is updated correctly **/ TEST_F(TracezDataAggregatorTest, RemovalOfRunningSpanWhenCompleted) { - opentelemetry::trace::StartSpanOptions start; + trace_api::StartSpanOptions start; start.start_steady_time = SteadyTimestamp(nanoseconds(10)); - opentelemetry::trace::EndSpanOptions end; + trace_api::EndSpanOptions end; end.end_steady_time = SteadyTimestamp(nanoseconds(40)); // Start a span and make sure data is updated @@ -589,9 +591,9 @@ TEST_F(TracezDataAggregatorTest, RemovalOfRunningSpanWhenCompleted) TEST_F(TracezDataAggregatorTest, RunningSpanChangesNameBeforeCompletion) { - opentelemetry::trace::StartSpanOptions start; + trace_api::StartSpanOptions start; start.start_steady_time = SteadyTimestamp(nanoseconds(10)); - opentelemetry::trace::EndSpanOptions end; + trace_api::EndSpanOptions end; end.end_steady_time = SteadyTimestamp(nanoseconds(40)); // Start a span and make sure data is updated @@ -632,8 +634,8 @@ TEST_F(TracezDataAggregatorTest, RunningSpanChangesNameBeforeCompletion) * fall in the correct bucket **/ TEST_F(TracezDataAggregatorTest, EdgeSpanLatenciesFallInCorrectBoundaries) { - opentelemetry::trace::StartSpanOptions start; - opentelemetry::trace::EndSpanOptions end; + trace_api::StartSpanOptions start; + trace_api::EndSpanOptions end; // Start and end 6 spans with the same name that fall into the first latency // bucket @@ -669,16 +671,16 @@ TEST_F(TracezDataAggregatorTest, EdgeSpanLatenciesFallInCorrectBoundaries) * calls to the data aggegator with no change in data **/ TEST_F(TracezDataAggregatorTest, NoChangeInBetweenCallsToAggregator) { - opentelemetry::trace::StartSpanOptions start; + trace_api::StartSpanOptions start; start.start_steady_time = SteadyTimestamp(nanoseconds(1)); - opentelemetry::trace::EndSpanOptions end; + trace_api::EndSpanOptions end; end.end_steady_time = SteadyTimestamp(nanoseconds(1)); tracer->StartSpan(span_name1, start)->End(end); auto running_span = tracer->StartSpan(span_name2); auto span = tracer->StartSpan(span_name3); - span->SetStatus(opentelemetry::trace::StatusCode::kError, "span cancelled"); + span->SetStatus(trace_api::StatusCode::kError, "span cancelled"); span->End(); std::this_thread::sleep_for(milliseconds(500)); auto data = tracez_data_aggregator->GetAggregatedTracezData(); diff --git a/ext/test/zpages/tracez_processor_test.cc b/ext/test/zpages/tracez_processor_test.cc index f96385acda..b9fe2aa740 100644 --- a/ext/test/zpages/tracez_processor_test.cc +++ b/ext/test/zpages/tracez_processor_test.cc @@ -15,6 +15,10 @@ using namespace opentelemetry::sdk::trace; using namespace opentelemetry::ext::zpages; +namespace trace_api = opentelemetry::trace; +namespace nostd = opentelemetry::nostd; + + //////////////////////////////////// TEST HELPER FUNCTIONS ////////////////////////////// /* @@ -150,8 +154,8 @@ void GetManySnapshots(std::shared_ptr &data, int i) * in vector. Used for testing thread safety */ void StartManySpans( - std::vector> &spans, - std::shared_ptr tracer, + std::vector> &spans, + std::shared_ptr tracer, int i) { for (; i > 0; i--) @@ -162,7 +166,7 @@ void StartManySpans( * Helper function that ends all spans in the passed in span vector. Used * for testing thread safety */ -void EndAllSpans(std::vector> &spans) +void EndAllSpans(std::vector> &spans) { for (auto &span : spans) span->End(); @@ -189,7 +193,7 @@ class TracezProcessor : public ::testing::Test // all the tests use shared data, and we want to make sure this works correctly. auto context = std::make_shared(std::move(processors), resource); - tracer = std::shared_ptr(new Tracer(context)); + tracer = std::shared_ptr(new Tracer(context)); auto spans = shared_data->GetSpanSnapshot(); running = spans.running; completed = std::move(spans.completed); @@ -199,10 +203,10 @@ class TracezProcessor : public ::testing::Test std::shared_ptr shared_data; std::shared_ptr processor; - std::shared_ptr tracer; + std::shared_ptr tracer; std::vector span_names; - std::vector> span_vars; + std::vector> span_vars; std::unordered_set running; std::vector> completed; @@ -518,8 +522,8 @@ TEST_F(TracezProcessor, FlushShutdown) */ TEST_F(TracezProcessor, RunningThreadSafety) { - std::vector> spans1; - std::vector> spans2; + std::vector> spans1; + std::vector> spans2; std::thread start1(StartManySpans, std::ref(spans1), tracer, 500); std::thread start2(StartManySpans, std::ref(spans2), tracer, 500); @@ -536,8 +540,8 @@ TEST_F(TracezProcessor, RunningThreadSafety) */ TEST_F(TracezProcessor, CompletedThreadSafety) { - std::vector> spans1; - std::vector> spans2; + std::vector> spans1; + std::vector> spans2; StartManySpans(spans1, tracer, 500); StartManySpans(spans2, tracer, 500); @@ -554,7 +558,7 @@ TEST_F(TracezProcessor, CompletedThreadSafety) */ TEST_F(TracezProcessor, SnapshotThreadSafety) { - std::vector> spans; + std::vector> spans; std::thread snap1(GetManySnapshots, std::ref(shared_data), 500); std::thread snap2(GetManySnapshots, std::ref(shared_data), 500); @@ -578,8 +582,8 @@ TEST_F(TracezProcessor, SnapshotThreadSafety) */ TEST_F(TracezProcessor, RunningCompletedThreadSafety) { - std::vector> spans1; - std::vector> spans2; + std::vector> spans1; + std::vector> spans2; StartManySpans(spans1, tracer, 500); @@ -597,7 +601,7 @@ TEST_F(TracezProcessor, RunningCompletedThreadSafety) */ TEST_F(TracezProcessor, RunningSnapshotThreadSafety) { - std::vector> spans; + std::vector> spans; std::thread start(StartManySpans, std::ref(spans), tracer, 500); std::thread snapshots(GetManySnapshots, std::ref(shared_data), 500); @@ -613,7 +617,7 @@ TEST_F(TracezProcessor, RunningSnapshotThreadSafety) */ TEST_F(TracezProcessor, SnapshotCompletedThreadSafety) { - std::vector> spans; + std::vector> spans; StartManySpans(spans, tracer, 500); @@ -629,8 +633,8 @@ TEST_F(TracezProcessor, SnapshotCompletedThreadSafety) */ TEST_F(TracezProcessor, RunningSnapshotCompletedThreadSafety) { - std::vector> spans1; - std::vector> spans2; + std::vector> spans1; + std::vector> spans2; StartManySpans(spans1, tracer, 500); diff --git a/sdk/src/logs/logger.cc b/sdk/src/logs/logger.cc index fe61dd4ce8..aa634b5b8b 100644 --- a/sdk/src/logs/logger.cc +++ b/sdk/src/logs/logger.cc @@ -12,12 +12,16 @@ namespace sdk { namespace logs { -Logger::Logger(opentelemetry::nostd::string_view name, + namespace trace_api = opentelemetry::trace; +namespace nostd = opentelemetry::nostd; +namespace common = opentelemetry::common; + +Logger::Logger(nostd::string_view name, std::shared_ptr logger_provider) noexcept : logger_name_(std::string(name)), logger_provider_(logger_provider) {} -const opentelemetry::nostd::string_view Logger::GetName() noexcept +const nostd::string_view Logger::GetName() noexcept { return logger_name_; } @@ -30,12 +34,12 @@ const opentelemetry::nostd::string_view Logger::GetName() noexcept void Logger::Log(opentelemetry::logs::Severity severity, nostd::string_view name, nostd::string_view body, - const opentelemetry::common::KeyValueIterable &resource, - const opentelemetry::common::KeyValueIterable &attributes, - opentelemetry::trace::TraceId trace_id, - opentelemetry::trace::SpanId span_id, - opentelemetry::trace::TraceFlags trace_flags, - opentelemetry::common::SystemTimestamp timestamp) noexcept + const common::KeyValueIterable &resource, + const common::KeyValueIterable &attributes, + trace_api::TraceId trace_id, + trace_api::SpanId span_id, + trace_api::TraceFlags trace_flags, + common::SystemTimestamp timestamp) noexcept { // If this logger does not have a processor, no need to create a log record auto processor = logger_provider_.lock()->GetProcessor(); @@ -60,19 +64,19 @@ void Logger::Log(opentelemetry::logs::Severity severity, recordable->SetBody(body); resource.ForEachKeyValue( - [&](nostd::string_view key, opentelemetry::common::AttributeValue value) noexcept { + [&](nostd::string_view key, common::AttributeValue value) noexcept { recordable->SetResource(key, value); return true; }); attributes.ForEachKeyValue( - [&](nostd::string_view key, opentelemetry::common::AttributeValue value) noexcept { + [&](nostd::string_view key, common::AttributeValue value) noexcept { recordable->SetAttribute(key, value); return true; }); // Inject trace_id/span_id/trace_flags if none is set by user - auto provider = opentelemetry::trace::Provider::GetTracerProvider(); + auto provider = trace_api::Provider::GetTracerProvider(); auto tracer = provider->GetTracer(logger_name_); auto span_context = tracer->GetCurrentSpan()->GetContext(); diff --git a/sdk/src/logs/logger_provider.cc b/sdk/src/logs/logger_provider.cc index 24718a3c22..b80cb643ab 100644 --- a/sdk/src/logs/logger_provider.cc +++ b/sdk/src/logs/logger_provider.cc @@ -5,6 +5,9 @@ # include "opentelemetry/sdk/logs/logger_provider.h" +namespace nostd = opentelemetry::nostd; +namespace logs = opentelemetry::logs; + OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { @@ -13,9 +16,9 @@ namespace logs LoggerProvider::LoggerProvider() noexcept : processor_{nullptr} {} -opentelemetry::nostd::shared_ptr LoggerProvider::GetLogger( - opentelemetry::nostd::string_view name, - opentelemetry::nostd::string_view options) noexcept +nostd::shared_ptr LoggerProvider::GetLogger( + nostd::string_view name, + nostd::string_view options) noexcept { // Ensure only one thread can read/write from the map of loggers std::lock_guard lock_guard{mu_}; @@ -24,7 +27,7 @@ opentelemetry::nostd::shared_ptr LoggerProvider::Ge auto loggerkv = loggers_.find(name.data()); if (loggerkv != loggers_.end()) { - return opentelemetry::nostd::shared_ptr(loggerkv->second); + return nostd::shared_ptr(loggerkv->second); } // Check if creating a new logger would exceed the max number of loggers @@ -42,14 +45,14 @@ opentelemetry::nostd::shared_ptr LoggerProvider::Ge // If no logger with that name exists yet, create it and add it to the map of loggers - opentelemetry::nostd::shared_ptr logger( + nostd::shared_ptr logger( new Logger(name, this->shared_from_this())); loggers_[name.data()] = logger; return logger; } -opentelemetry::nostd::shared_ptr LoggerProvider::GetLogger( - opentelemetry::nostd::string_view name, +nostd::shared_ptr LoggerProvider::GetLogger( + nostd::string_view name, nostd::span args) noexcept { // Currently, no args support diff --git a/sdk/src/metrics/meter_provider.cc b/sdk/src/metrics/meter_provider.cc index 903ba76e06..09d85dd3b3 100644 --- a/sdk/src/metrics/meter_provider.cc +++ b/sdk/src/metrics/meter_provider.cc @@ -9,15 +9,18 @@ namespace sdk { namespace metrics { +namespace nostd = opentelemetry::nostd; +namespace metrics_api = opentelemetry::metrics; + MeterProvider::MeterProvider(std::string library_name, std::string library_version) noexcept : meter_(new Meter(library_name, library_version)) {} -opentelemetry::nostd::shared_ptr MeterProvider::GetMeter( +nostd::shared_ptr MeterProvider::GetMeter( nostd::string_view library_name, nostd::string_view library_version) noexcept { - return opentelemetry::nostd::shared_ptr(meter_); + return nostd::shared_ptr(meter_); } } // namespace metrics diff --git a/sdk/src/trace/random_id_generator.cc b/sdk/src/trace/random_id_generator.cc index 78bc2a4117..36c036f6c2 100644 --- a/sdk/src/trace/random_id_generator.cc +++ b/sdk/src/trace/random_id_generator.cc @@ -10,19 +10,21 @@ namespace sdk { namespace trace { +namespace trace_api = opentelemetry::trace; -opentelemetry::trace::SpanId RandomIdGenerator::GenerateSpanId() noexcept + +trace_api::SpanId RandomIdGenerator::GenerateSpanId() noexcept { - uint8_t span_id_buf[opentelemetry::trace::SpanId::kSize]; + uint8_t span_id_buf[trace_api::SpanId::kSize]; sdk::common::Random::GenerateRandomBuffer(span_id_buf); - return opentelemetry::trace::SpanId(span_id_buf); + return trace_api::SpanId(span_id_buf); } -opentelemetry::trace::TraceId RandomIdGenerator::GenerateTraceId() noexcept +trace_api::TraceId RandomIdGenerator::GenerateTraceId() noexcept { - uint8_t trace_id_buf[opentelemetry::trace::TraceId::kSize]; + uint8_t trace_id_buf[trace_api::TraceId::kSize]; sdk::common::Random::GenerateRandomBuffer(trace_id_buf); - return opentelemetry::trace::TraceId(trace_id_buf); + return trace_api::TraceId(trace_id_buf); } } // namespace trace } // namespace sdk diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index 35d8658d7c..587b9415eb 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -16,6 +16,7 @@ namespace trace using opentelemetry::common::SteadyTimestamp; using opentelemetry::common::SystemTimestamp; +namespace common = opentelemetry::common; namespace { @@ -46,7 +47,7 @@ SteadyTimestamp NowOr(const SteadyTimestamp &steady) Span::Span(std::shared_ptr &&tracer, nostd::string_view name, - const opentelemetry::common::KeyValueIterable &attributes, + const common::KeyValueIterable &attributes, const trace_api::SpanContextKeyValueIterable &links, const trace_api::StartSpanOptions &options, const trace_api::SpanContext &parent_span_context, @@ -68,13 +69,13 @@ Span::Span(std::shared_ptr &&tracer, : trace_api::SpanId()); attributes.ForEachKeyValue( - [&](nostd::string_view key, opentelemetry::common::AttributeValue value) noexcept { + [&](nostd::string_view key, common::AttributeValue value) noexcept { recordable_->SetAttribute(key, value); return true; }); links.ForEachKeyValue([&](opentelemetry::trace::SpanContext span_context, - const opentelemetry::common::KeyValueIterable &attributes) { + const common::KeyValueIterable &attributes) { recordable_->AddLink(span_context, attributes); return true; }); @@ -92,7 +93,7 @@ Span::~Span() } void Span::SetAttribute(nostd::string_view key, - const opentelemetry::common::AttributeValue &value) noexcept + const common::AttributeValue &value) noexcept { std::lock_guard lock_guard{mu_}; @@ -121,7 +122,7 @@ void Span::AddEvent(nostd::string_view name, SystemTimestamp timestamp) noexcept void Span::AddEvent(nostd::string_view name, SystemTimestamp timestamp, - const opentelemetry::common::KeyValueIterable &attributes) noexcept + const common::KeyValueIterable &attributes) noexcept { std::lock_guard lock_guard{mu_}; if (recordable_ == nullptr) diff --git a/sdk/src/trace/tracer_context.cc b/sdk/src/trace/tracer_context.cc index eaab96154c..d204218021 100644 --- a/sdk/src/trace/tracer_context.cc +++ b/sdk/src/trace/tracer_context.cc @@ -9,9 +9,10 @@ namespace sdk { namespace trace { +namespace resource = opentelemetry::sdk::resource; TracerContext::TracerContext(std::vector> &&processors, - opentelemetry::sdk::resource::Resource resource, + resource::Resource resource, std::unique_ptr sampler, std::unique_ptr id_generator) noexcept : resource_(resource), @@ -25,7 +26,7 @@ Sampler &TracerContext::GetSampler() const noexcept return *sampler_; } -const opentelemetry::sdk::resource::Resource &TracerContext::GetResource() const noexcept +const resource::Resource &TracerContext::GetResource() const noexcept { return resource_; } diff --git a/sdk/src/trace/tracer_provider.cc b/sdk/src/trace/tracer_provider.cc index 13628094e4..1a4e5c7eb7 100644 --- a/sdk/src/trace/tracer_provider.cc +++ b/sdk/src/trace/tracer_provider.cc @@ -9,12 +9,15 @@ namespace sdk { namespace trace { +namespace resource = opentelemetry::sdk::resource; +namespace trace_api = opentelemetry::trace; + TracerProvider::TracerProvider(std::shared_ptr context) noexcept : context_{context} {} TracerProvider::TracerProvider(std::unique_ptr processor, - opentelemetry::sdk::resource::Resource resource, + resource::Resource resource, std::unique_ptr sampler, std::unique_ptr id_generator) noexcept { @@ -25,7 +28,7 @@ TracerProvider::TracerProvider(std::unique_ptr processor, } TracerProvider::TracerProvider(std::vector> &&processors, - opentelemetry::sdk::resource::Resource resource, + resource::Resource resource, std::unique_ptr sampler, std::unique_ptr id_generator) noexcept { @@ -33,7 +36,7 @@ TracerProvider::TracerProvider(std::vector> &&pro std::move(id_generator)); } -nostd::shared_ptr TracerProvider::GetTracer( +nostd::shared_ptr TracerProvider::GetTracer( nostd::string_view library_name, nostd::string_view library_version, nostd::string_view schema_url) noexcept @@ -55,14 +58,14 @@ nostd::shared_ptr TracerProvider::GetTracer( auto &tracer_lib = tracer->GetInstrumentationLibrary(); if (tracer_lib.equal(library_name, library_version, schema_url)) { - return nostd::shared_ptr{tracer}; + return nostd::shared_ptr{tracer}; } } auto lib = InstrumentationLibrary::Create(library_name, library_version, schema_url); tracers_.push_back(std::shared_ptr( new sdk::trace::Tracer(context_, std::move(lib)))); - return nostd::shared_ptr{tracers_.back()}; + return nostd::shared_ptr{tracers_.back()}; } void TracerProvider::AddProcessor(std::unique_ptr processor) noexcept @@ -70,7 +73,7 @@ void TracerProvider::AddProcessor(std::unique_ptr processor) noex context_->AddProcessor(std::move(processor)); } -const opentelemetry::sdk::resource::Resource &TracerProvider::GetResource() const noexcept +const resource::Resource &TracerProvider::GetResource() const noexcept { return context_->GetResource(); } diff --git a/sdk/test/logs/log_record_test.cc b/sdk/test/logs/log_record_test.cc index 8750627d5b..1bb071a98a 100644 --- a/sdk/test/logs/log_record_test.cc +++ b/sdk/test/logs/log_record_test.cc @@ -11,16 +11,20 @@ # include using opentelemetry::sdk::logs::LogRecord; +namespace trace_api = opentelemetry::trace; +namespace logs_api = opentelemetry::logs; +namespace nostd = opentelemetry::nostd; + // Test what a default LogRecord with no fields set holds TEST(LogRecord, GetDefaultValues) { - opentelemetry::trace::TraceId zero_trace_id; - opentelemetry::trace::SpanId zero_span_id; - opentelemetry::trace::TraceFlags zero_trace_flags; + trace_api::TraceId zero_trace_id; + trace_api::SpanId zero_span_id; + trace_api::TraceFlags zero_trace_flags; LogRecord record; - ASSERT_EQ(record.GetSeverity(), opentelemetry::logs::Severity::kInvalid); + ASSERT_EQ(record.GetSeverity(), logs_api::Severity::kInvalid); ASSERT_EQ(record.GetName(), ""); ASSERT_EQ(record.GetBody(), ""); ASSERT_EQ(record.GetResource().size(), 0); @@ -34,14 +38,14 @@ TEST(LogRecord, GetDefaultValues) // Test LogRecord fields are properly set and get TEST(LogRecord, SetAndGet) { - opentelemetry::trace::TraceId trace_id; - opentelemetry::trace::SpanId span_id; - opentelemetry::trace::TraceFlags trace_flags; + trace_api::TraceId trace_id; + trace_api::SpanId span_id; + trace_api::TraceFlags trace_flags; opentelemetry::common::SystemTimestamp now(std::chrono::system_clock::now()); // Set all fields of the LogRecord LogRecord record; - record.SetSeverity(opentelemetry::logs::Severity::kInvalid); + record.SetSeverity(logs_api::Severity::kInvalid); record.SetName("Log name"); record.SetBody("Message"); record.SetResource("res1", (bool)true); @@ -52,11 +56,11 @@ TEST(LogRecord, SetAndGet) record.SetTimestamp(now); // Test that all fields match what was set - ASSERT_EQ(record.GetSeverity(), opentelemetry::logs::Severity::kInvalid); + ASSERT_EQ(record.GetSeverity(), logs_api::Severity::kInvalid); ASSERT_EQ(record.GetName(), "Log name"); ASSERT_EQ(record.GetBody(), "Message"); - ASSERT_EQ(opentelemetry::nostd::get(record.GetResource().at("res1")), 1); - ASSERT_EQ(opentelemetry::nostd::get(record.GetAttributes().at("attr1")), 314159); + ASSERT_EQ(nostd::get(record.GetResource().at("res1")), 1); + ASSERT_EQ(nostd::get(record.GetAttributes().at("attr1")), 314159); ASSERT_EQ(record.GetTraceId(), trace_id); ASSERT_EQ(record.GetSpanId(), span_id); ASSERT_EQ(record.GetTraceFlags(), trace_flags); diff --git a/sdk/test/logs/logger_provider_sdk_test.cc b/sdk/test/logs/logger_provider_sdk_test.cc index fd2d70415e..0ce2554e70 100644 --- a/sdk/test/logs/logger_provider_sdk_test.cc +++ b/sdk/test/logs/logger_provider_sdk_test.cc @@ -14,20 +14,22 @@ # include using namespace opentelemetry::sdk::logs; +namespace logs_api = opentelemetry::logs; +namespace nostd = opentelemetry::nostd; TEST(LoggerProviderSDK, PushToAPI) { - auto lp = opentelemetry::nostd::shared_ptr( - new opentelemetry::sdk::logs::LoggerProvider()); - opentelemetry::logs::Provider::SetLoggerProvider(lp); + auto lp = nostd::shared_ptr( + new opentelemetry::sdk::logs_api::LoggerProvider()); + logs_api::Provider::SetLoggerProvider(lp); // Check that the loggerprovider was correctly pushed into the API - ASSERT_EQ(lp, opentelemetry::logs::Provider::GetLoggerProvider()); + ASSERT_EQ(lp, logs_api::Provider::GetLoggerProvider()); } TEST(LoggerProviderSDK, LoggerProviderGetLoggerSimple) { - auto lp = std::shared_ptr(new LoggerProvider()); + auto lp = std::shared_ptr(new LoggerProvider()); auto logger1 = lp->GetLogger("logger1"); auto logger2 = lp->GetLogger("logger2"); @@ -49,13 +51,13 @@ TEST(LoggerProviderSDK, LoggerProviderLoggerArguments) // Currently, arguments are not supported by the loggers. // TODO: Once the logging spec defines what arguments are allowed, add more // detail to this test - auto lp = std::shared_ptr(new LoggerProvider()); + auto lp = std::shared_ptr(new LoggerProvider()); auto logger1 = lp->GetLogger("logger1", ""); // Check GetLogger(logger_name, args) - std::array sv{"string"}; - opentelemetry::nostd::span args{sv}; + std::array sv{"string"}; + nostd::span args{sv}; auto logger2 = lp->GetLogger("logger2", args); } diff --git a/sdk/test/logs/logger_sdk_test.cc b/sdk/test/logs/logger_sdk_test.cc index fbc7947752..26632f1f91 100644 --- a/sdk/test/logs/logger_sdk_test.cc +++ b/sdk/test/logs/logger_sdk_test.cc @@ -9,6 +9,7 @@ # include using namespace opentelemetry::sdk::logs; +namespace logs_api = opentelemetry::logs; TEST(LoggerSDK, LogToNullProcessor) { @@ -16,7 +17,7 @@ TEST(LoggerSDK, LogToNullProcessor) // even when there is no processor set // since it calls Processor::OnReceive() - auto lp = std::shared_ptr(new LoggerProvider()); + auto lp = std::shared_ptr(new LoggerProvider()); auto logger = lp->GetLogger("logger"); // Log a sample log record to a nullptr processor @@ -64,7 +65,7 @@ class MockProcessor final : public LogProcessor TEST(LoggerSDK, LogToAProcessor) { // Create an API LoggerProvider and logger - auto api_lp = std::shared_ptr(new LoggerProvider()); + auto api_lp = std::shared_ptr(new LoggerProvider()); auto logger = api_lp->GetLogger("logger"); // Cast the API LoggerProvider to an SDK Logger Provider and assert that it is still the same @@ -81,9 +82,9 @@ TEST(LoggerSDK, LogToAProcessor) ASSERT_EQ(processor, lp->GetProcessor()); // Check that the recordable created by the Log() statement is set properly - logger->Log(opentelemetry::logs::Severity::kWarn, "Log Name", "Log Message"); + logger->Log(logs_api::Severity::kWarn, "Log Name", "Log Message"); - ASSERT_EQ(shared_recordable->GetSeverity(), opentelemetry::logs::Severity::kWarn); + ASSERT_EQ(shared_recordable->GetSeverity(), logs_api::Severity::kWarn); ASSERT_EQ(shared_recordable->GetName(), "Log Name"); ASSERT_EQ(shared_recordable->GetBody(), "Log Message"); } diff --git a/sdk/test/logs/simple_log_processor_test.cc b/sdk/test/logs/simple_log_processor_test.cc index e2f2ad2b6e..ee05b302bc 100644 --- a/sdk/test/logs/simple_log_processor_test.cc +++ b/sdk/test/logs/simple_log_processor_test.cc @@ -15,6 +15,7 @@ using namespace opentelemetry::sdk::logs; using namespace opentelemetry::sdk::common; +namespace nostd = opentelemetry::nostd; /* * A test exporter that can return a vector of all the records it has received, @@ -38,7 +39,7 @@ class TestExporter final : public LogExporter // Stores the names of the log records this exporter receives to an internal list ExportResult Export( - const opentelemetry::nostd::span> &records) noexcept override + const nostd::span> &records) noexcept override { *batch_size_received = records.size(); for (auto &record : records) @@ -134,7 +135,7 @@ class FailShutDownExporter final : public LogExporter } ExportResult Export( - const opentelemetry::nostd::span> &records) noexcept override + const nostd::span> &records) noexcept override { return ExportResult::kSuccess; } diff --git a/sdk/test/metrics/exact_aggregator_test.cc b/sdk/test/metrics/exact_aggregator_test.cc index 88ce1a4432..d68389c6c6 100644 --- a/sdk/test/metrics/exact_aggregator_test.cc +++ b/sdk/test/metrics/exact_aggregator_test.cc @@ -9,10 +9,11 @@ # include "opentelemetry/sdk/metrics/aggregator/exact_aggregator.h" using namespace opentelemetry::sdk::metrics; +namespace metrics_api = opentelemetry::metrics; TEST(ExactAggregatorOrdered, Update) { - ExactAggregator agg(opentelemetry::metrics::InstrumentKind::Counter); + ExactAggregator agg(metrics_api::InstrumentKind::Counter); std::vector correct; @@ -33,7 +34,7 @@ TEST(ExactAggregatorOrdered, Update) TEST(ExactAggregatorOrdered, Checkpoint) { - ExactAggregator agg(opentelemetry::metrics::InstrumentKind::Counter); + ExactAggregator agg(metrics_api::InstrumentKind::Counter); std::vector correct; @@ -48,8 +49,8 @@ TEST(ExactAggregatorOrdered, Checkpoint) TEST(ExactAggregatorOrdered, Merge) { - ExactAggregator agg1(opentelemetry::metrics::InstrumentKind::Counter); - ExactAggregator agg2(opentelemetry::metrics::InstrumentKind::Counter); + ExactAggregator agg1(metrics_api::InstrumentKind::Counter); + ExactAggregator agg2(metrics_api::InstrumentKind::Counter); agg1.update(1); agg2.update(2); @@ -64,8 +65,8 @@ TEST(ExactAggregatorOrdered, BadMerge) { // This verifies that we encounter and error when we try to merge // two aggregators of different numeric types together. - ExactAggregator agg1(opentelemetry::metrics::InstrumentKind::Counter); - ExactAggregator agg2(opentelemetry::metrics::InstrumentKind::ValueRecorder); + ExactAggregator agg1(metrics_api::InstrumentKind::Counter); + ExactAggregator agg2(metrics_api::InstrumentKind::ValueRecorder); agg1.update(1); agg2.update(2); @@ -81,10 +82,10 @@ TEST(ExactAggregatorOrdered, Types) { // This test verifies that we do not encounter any errors when // using various numeric types. - ExactAggregator agg_int(opentelemetry::metrics::InstrumentKind::Counter); - ExactAggregator agg_long(opentelemetry::metrics::InstrumentKind::Counter); - ExactAggregator agg_float(opentelemetry::metrics::InstrumentKind::Counter); - ExactAggregator agg_double(opentelemetry::metrics::InstrumentKind::Counter); + ExactAggregator agg_int(metrics_api::InstrumentKind::Counter); + ExactAggregator agg_long(metrics_api::InstrumentKind::Counter); + ExactAggregator agg_float(metrics_api::InstrumentKind::Counter); + ExactAggregator agg_double(metrics_api::InstrumentKind::Counter); for (int i = 1; i <= 5; ++i) { @@ -111,7 +112,7 @@ TEST(ExactAggregatorOrdered, Types) TEST(ExactAggregatorQuant, Update) { - ExactAggregator agg(opentelemetry::metrics::InstrumentKind::Counter, true); + ExactAggregator agg(metrics_api::InstrumentKind::Counter, true); std::vector correct; @@ -135,7 +136,7 @@ TEST(ExactAggregatorQuant, Checkpoint) // This test verifies that the aggregator updates correctly when // quantile estimation is turned on. - ExactAggregator agg(opentelemetry::metrics::InstrumentKind::Counter, true); + ExactAggregator agg(metrics_api::InstrumentKind::Counter, true); std::vector correct; @@ -159,7 +160,7 @@ TEST(ExactAggregatorQuant, Quantile) // This test verifies that the quantile estimation function returns // the correct values. - ExactAggregator agg(opentelemetry::metrics::InstrumentKind::Counter, true); + ExactAggregator agg(metrics_api::InstrumentKind::Counter, true); std::vector tmp{3, 9, 42, 57, 163, 210, 272, 300}; for (int i : tmp) @@ -176,7 +177,7 @@ TEST(ExactAggregatorInOrder, Quantile) { // This test verifies that if the user has an exact aggregator in "in-order" mode // an exception will be thrown if they call the quantile() function. - ExactAggregator agg(opentelemetry::metrics::InstrumentKind::Counter); + ExactAggregator agg(metrics_api::InstrumentKind::Counter); std::vector tmp{3, 9, 42, 57, 163, 210, 272, 300}; for (int i : tmp) @@ -202,7 +203,7 @@ TEST(ExactAggregatorQuant, Concurrency) { // This test checks that the aggregator updates appropriately // when called in a multi-threaded context. - ExactAggregator agg(opentelemetry::metrics::InstrumentKind::Counter, true); + ExactAggregator agg(metrics_api::InstrumentKind::Counter, true); std::thread first(&callback, std::ref(agg)); std::thread second(&callback, std::ref(agg)); diff --git a/sdk/test/metrics/gauge_aggregator_test.cc b/sdk/test/metrics/gauge_aggregator_test.cc index b2721b8b51..d79a3c7d43 100644 --- a/sdk/test/metrics/gauge_aggregator_test.cc +++ b/sdk/test/metrics/gauge_aggregator_test.cc @@ -8,12 +8,13 @@ # include "opentelemetry/sdk/metrics/aggregator/gauge_aggregator.h" using namespace opentelemetry::sdk::metrics; +namespace metrics_api = opentelemetry::metrics; TEST(GaugeAggregator, Update) { // This tests that the aggregator updates the maintained value correctly // after a call to the update() function. - auto agg = new GaugeAggregator(opentelemetry::metrics::InstrumentKind::Counter); + auto agg = new GaugeAggregator(metrics_api::InstrumentKind::Counter); // Verify default value ASSERT_EQ(agg->get_values()[0], 0); @@ -36,7 +37,7 @@ TEST(GaugeAggregator, Checkpoint) // This tests that the aggregator correctly updates the // checkpoint_ value after a call to update() followed // by a call to checkpoint(). - GaugeAggregator agg(opentelemetry::metrics::InstrumentKind::Counter); + GaugeAggregator agg(metrics_api::InstrumentKind::Counter); // Verify default checkpoint, before updates ASSERT_EQ(agg.get_checkpoint()[0], 0); @@ -52,8 +53,8 @@ TEST(GaugeAggregator, Merge) { // This tests that the values_ vector is updated correctly after // two aggregators are merged together. - GaugeAggregator agg1(opentelemetry::metrics::InstrumentKind::Counter); - GaugeAggregator agg2(opentelemetry::metrics::InstrumentKind::Counter); + GaugeAggregator agg1(metrics_api::InstrumentKind::Counter); + GaugeAggregator agg2(metrics_api::InstrumentKind::Counter); agg1.update(1); agg2.update(2); @@ -68,8 +69,8 @@ TEST(GaugeAggregator, BadMerge) { // This verifies that we encounter and error when we try to merge // two aggregators of different numeric types together. - GaugeAggregator agg1(opentelemetry::metrics::InstrumentKind::Counter); - GaugeAggregator agg2(opentelemetry::metrics::InstrumentKind::ValueRecorder); + GaugeAggregator agg1(metrics_api::InstrumentKind::Counter); + GaugeAggregator agg2(metrics_api::InstrumentKind::ValueRecorder); agg1.update(1); agg2.update(2); @@ -84,10 +85,10 @@ TEST(GaugeAggregator, Types) { // This test verifies that we do not encounter any errors when // using various numeric types. - GaugeAggregator agg_int(opentelemetry::metrics::InstrumentKind::Counter); - GaugeAggregator agg_long(opentelemetry::metrics::InstrumentKind::Counter); - GaugeAggregator agg_float(opentelemetry::metrics::InstrumentKind::Counter); - GaugeAggregator agg_double(opentelemetry::metrics::InstrumentKind::Counter); + GaugeAggregator agg_int(metrics_api::InstrumentKind::Counter); + GaugeAggregator agg_long(metrics_api::InstrumentKind::Counter); + GaugeAggregator agg_float(metrics_api::InstrumentKind::Counter); + GaugeAggregator agg_double(metrics_api::InstrumentKind::Counter); for (int i = 1; i <= 10; ++i) { @@ -119,7 +120,7 @@ TEST(GaugeAggregator, Concurrency) { // This test checks that the aggregator updates appropriately // when called in a multi-threaded context. - GaugeAggregator agg(opentelemetry::metrics::InstrumentKind::Counter); + GaugeAggregator agg(metrics_api::InstrumentKind::Counter); std::thread first(&callback, std::ref(agg)); std::thread second(&callback, std::ref(agg)); diff --git a/sdk/test/metrics/histogram_aggregator_test.cc b/sdk/test/metrics/histogram_aggregator_test.cc index eec00e8360..03d849919b 100644 --- a/sdk/test/metrics/histogram_aggregator_test.cc +++ b/sdk/test/metrics/histogram_aggregator_test.cc @@ -87,7 +87,7 @@ TEST(Histogram, Merge) alpha.merge(beta); alpha.checkpoint(); - EXPECT_EQ(alpha.get_checkpoint()[0], std::accumulate(vals.begin(), vals.end(), 0) + + EXPECT_EQ(alpha.get_checkpoint()[0], std::accumulate(vals.begin(), vals.end(), 0) std::accumulate(otherVals.begin(), otherVals.end(), 0)); EXPECT_EQ(alpha.get_checkpoint()[1], vals.size() + otherVals.size()); diff --git a/sdk/test/metrics/meter_test.cc b/sdk/test/metrics/meter_test.cc index 3c708fca92..dd2bbb858e 100644 --- a/sdk/test/metrics/meter_test.cc +++ b/sdk/test/metrics/meter_test.cc @@ -9,6 +9,8 @@ using namespace opentelemetry::sdk::metrics; namespace metrics_api = opentelemetry::metrics; +namespace common = opentelemetry::common; +namespace nostd = opentelemetry::nostd; OPENTELEMETRY_BEGIN_NAMESPACE @@ -74,13 +76,13 @@ TEST(Meter, CollectSyncInstruments) auto counter = m.NewShortCounter("Test-counter", "For testing", "Unitless", true); std::map labels = {{"Key", "Value"}}; - auto labelkv = opentelemetry::common::KeyValueIterableView{labels}; + auto labelkv = common::KeyValueIterableView{labels}; counter->add(1, labelkv); std::vector res = m.Collect(); auto agg_var = res[0].GetAggregator(); - auto agg = opentelemetry::nostd::get<0>(agg_var); + auto agg = nostd::get<0>(agg_var); ASSERT_EQ(agg->get_checkpoint()[0], 1); @@ -91,7 +93,7 @@ TEST(Meter, CollectSyncInstruments) res = m.Collect(); agg_var = res[0].GetAggregator(); - agg = opentelemetry::nostd::get<0>(agg_var); + agg = nostd::get<0>(agg_var); ASSERT_EQ(agg->get_checkpoint()[0], 10); } @@ -106,7 +108,7 @@ TEST(Meter, CollectDeletedSync) ASSERT_EQ(m.Collect().size(), 0); std::map labels = {{"Key", "Value"}}; - auto labelkv = opentelemetry::common::KeyValueIterableView{labels}; + auto labelkv = common::KeyValueIterableView{labels}; { auto counter = m.NewShortCounter("Test-counter", "For testing", "Unitless", true); counter->add(1, labelkv); @@ -114,13 +116,13 @@ TEST(Meter, CollectDeletedSync) std::vector res = m.Collect(); auto agg_var = res[0].GetAggregator(); - auto agg = opentelemetry::nostd::get<0>(agg_var); + auto agg = nostd::get<0>(agg_var); ASSERT_EQ(agg->get_checkpoint()[0], 1); } // Dummy function for asynchronous instrument constructors. -void Callback(opentelemetry::metrics::ObserverResult result) +void Callback(metrics_api::ObserverResult result) { std::map labels = {{"key", "value"}}; auto labelkv = common::KeyValueIterableView{labels}; @@ -139,13 +141,13 @@ TEST(Meter, CollectAsyncInstruments) m.NewShortSumObserver("Test-counter", "For testing", "Unitless", true, &ShortCallback); std::map labels = {{"Key", "Value"}}; - auto labelkv = opentelemetry::common::KeyValueIterableView{labels}; + auto labelkv = common::KeyValueIterableView{labels}; sumobs->observe(1, labelkv); std::vector res = m.Collect(); auto agg_var = res[0].GetAggregator(); - auto agg = opentelemetry::nostd::get<0>(agg_var); + auto agg = nostd::get<0>(agg_var); ASSERT_EQ(agg->get_checkpoint()[0], 1); @@ -156,7 +158,7 @@ TEST(Meter, CollectAsyncInstruments) res = m.Collect(); agg_var = res[0].GetAggregator(); - agg = opentelemetry::nostd::get<0>(agg_var); + agg = nostd::get<0>(agg_var); ASSERT_EQ(agg->get_checkpoint()[0], 10); } @@ -171,7 +173,7 @@ TEST(Meter, CollectDeletedAsync) ASSERT_EQ(m.Collect().size(), 0); std::map labels = {{"Key", "Value"}}; - auto labelkv = opentelemetry::common::KeyValueIterableView{labels}; + auto labelkv = common::KeyValueIterableView{labels}; { auto sumobs = m.NewShortSumObserver("Test-counter", "For testing", "Unitless", true, &Callback); sumobs->observe(1, labelkv); @@ -179,7 +181,7 @@ TEST(Meter, CollectDeletedAsync) std::vector res = m.Collect(); auto agg_var = res[0].GetAggregator(); - auto agg = opentelemetry::nostd::get<0>(agg_var); + auto agg = nostd::get<0>(agg_var); ASSERT_EQ(agg->get_checkpoint()[0], 1); } @@ -196,7 +198,7 @@ TEST(Meter, RecordBatch) auto dcounter = m.NewDoubleCounter("Test-dcounter", "For testing", "Unitless", true); std::map labels = {{"Key", "Value"}}; - auto labelkv = opentelemetry::common::KeyValueIterableView{labels}; + auto labelkv = common::KeyValueIterableView{labels}; metrics_api::SynchronousInstrument *sinstr_arr[] = {scounter.get()}; short svalues_arr[] = {1}; @@ -207,7 +209,7 @@ TEST(Meter, RecordBatch) m.RecordShortBatch(labelkv, sinstrs, svalues); std::vector res = m.Collect(); auto short_agg_var = res[0].GetAggregator(); - auto short_agg = opentelemetry::nostd::get<0>(short_agg_var); + auto short_agg = nostd::get<0>(short_agg_var); ASSERT_EQ(short_agg->get_checkpoint()[0], 1); metrics_api::SynchronousInstrument *iinstr_arr[] = {icounter.get()}; @@ -219,7 +221,7 @@ TEST(Meter, RecordBatch) m.RecordIntBatch(labelkv, iinstrs, ivalues); res = m.Collect(); auto int_agg_var = res[0].GetAggregator(); - auto int_agg = opentelemetry::nostd::get<1>(int_agg_var); + auto int_agg = nostd::get<1>(int_agg_var); ASSERT_EQ(int_agg->get_checkpoint()[0], 1); metrics_api::SynchronousInstrument *finstr_arr[] = {fcounter.get()}; @@ -231,7 +233,7 @@ TEST(Meter, RecordBatch) m.RecordFloatBatch(labelkv, finstrs, fvalues); res = m.Collect(); auto float_agg_var = res[0].GetAggregator(); - auto float_agg = opentelemetry::nostd::get<2>(float_agg_var); + auto float_agg = nostd::get<2>(float_agg_var); ASSERT_EQ(float_agg->get_checkpoint()[0], 1.0); metrics_api::SynchronousInstrument *dinstr_arr[] = {dcounter.get()}; @@ -243,7 +245,7 @@ TEST(Meter, RecordBatch) m.RecordDoubleBatch(labelkv, dinstrs, dvalues); res = m.Collect(); auto double_agg_var = res[0].GetAggregator(); - auto double_agg = opentelemetry::nostd::get<3>(double_agg_var); + auto double_agg = nostd::get<3>(double_agg_var); ASSERT_EQ(double_agg->get_checkpoint()[0], 1.0); } @@ -251,7 +253,7 @@ TEST(Meter, DisableCollectSync) { Meter m("Test"); std::map labels = {{"Key", "Value"}}; - auto labelkv = opentelemetry::common::KeyValueIterableView{labels}; + auto labelkv = common::KeyValueIterableView{labels}; auto c = m.NewShortCounter("c", "", "", false); c->add(1, labelkv); ASSERT_EQ(m.Collect().size(), 0); @@ -261,7 +263,7 @@ TEST(Meter, DisableCollectAsync) { Meter m("Test"); std::map labels = {{"Key", "Value"}}; - auto labelkv = opentelemetry::common::KeyValueIterableView{labels}; + auto labelkv = common::KeyValueIterableView{labels}; auto c = m.NewShortValueObserver("c", "", "", false, &ShortCallback); c->observe(1, labelkv); ASSERT_EQ(m.Collect().size(), 0); diff --git a/sdk/test/metrics/min_max_sum_count_aggregator_test.cc b/sdk/test/metrics/min_max_sum_count_aggregator_test.cc index 62b2b6763d..a1cb36c0cf 100644 --- a/sdk/test/metrics/min_max_sum_count_aggregator_test.cc +++ b/sdk/test/metrics/min_max_sum_count_aggregator_test.cc @@ -8,12 +8,13 @@ # include "opentelemetry/sdk/metrics/aggregator/min_max_sum_count_aggregator.h" using namespace opentelemetry::sdk::metrics; +namespace metrics_api = opentelemetry::metrics; TEST(MinMaxSumCountAggregator, Update) { // This tests that the aggregator updates the maintained value correctly // after a call to the update() function. - MinMaxSumCountAggregator agg(opentelemetry::metrics::InstrumentKind::Counter); + MinMaxSumCountAggregator agg(metrics_api::InstrumentKind::Counter); auto value_set = agg.get_values(); ASSERT_EQ(value_set[0], 0); ASSERT_EQ(value_set[1], 0); @@ -37,7 +38,7 @@ TEST(MinMaxSumCountAggregator, FirstUpdate) { // This tests that the aggregator appropriately maintains the min and // max values after a single update call. - MinMaxSumCountAggregator agg(opentelemetry::metrics::InstrumentKind::Counter); + MinMaxSumCountAggregator agg(metrics_api::InstrumentKind::Counter); agg.update(1); auto value_set = agg.get_values(); ASSERT_EQ(value_set[0], 1); // min @@ -51,7 +52,7 @@ TEST(MinMaxSumCountAggregator, Checkpoint) // This test verifies that the default checkpoint is set correctly // and that the checkpoint values update correctly after a call // to the checkpoint() function. - MinMaxSumCountAggregator agg(opentelemetry::metrics::InstrumentKind::Counter); + MinMaxSumCountAggregator agg(metrics_api::InstrumentKind::Counter); // Verify that the default checkpoint is set correctly. auto checkpoint_set = agg.get_checkpoint(); @@ -87,8 +88,8 @@ TEST(MinMaxSumCountAggregator, Merge) { // This tests that the values_ vector is updated correctly after // two aggregators are merged together. - MinMaxSumCountAggregator agg1(opentelemetry::metrics::InstrumentKind::Counter); - MinMaxSumCountAggregator agg2(opentelemetry::metrics::InstrumentKind::Counter); + MinMaxSumCountAggregator agg1(metrics_api::InstrumentKind::Counter); + MinMaxSumCountAggregator agg2(metrics_api::InstrumentKind::Counter); // 1 + 2 + 3 + ... + 10 = 55 for (int i = 1; i <= 10; ++i) @@ -116,8 +117,8 @@ TEST(MinMaxSumCountAggregator, BadMerge) { // This verifies that we encounter and error when we try to merge // two aggregators of different numeric types together. - MinMaxSumCountAggregator agg1(opentelemetry::metrics::InstrumentKind::Counter); - MinMaxSumCountAggregator agg2(opentelemetry::metrics::InstrumentKind::ValueRecorder); + MinMaxSumCountAggregator agg1(metrics_api::InstrumentKind::Counter); + MinMaxSumCountAggregator agg2(metrics_api::InstrumentKind::ValueRecorder); agg1.update(1); agg2.update(2); @@ -136,10 +137,10 @@ TEST(MinMaxSumCountAggregator, Types) { // This test verifies that we do not encounter any errors when // using various numeric types. - MinMaxSumCountAggregator agg_int(opentelemetry::metrics::InstrumentKind::Counter); - MinMaxSumCountAggregator agg_long(opentelemetry::metrics::InstrumentKind::Counter); - MinMaxSumCountAggregator agg_float(opentelemetry::metrics::InstrumentKind::Counter); - MinMaxSumCountAggregator agg_double(opentelemetry::metrics::InstrumentKind::Counter); + MinMaxSumCountAggregator agg_int(metrics_api::InstrumentKind::Counter); + MinMaxSumCountAggregator agg_long(metrics_api::InstrumentKind::Counter); + MinMaxSumCountAggregator agg_float(metrics_api::InstrumentKind::Counter); + MinMaxSumCountAggregator agg_double(metrics_api::InstrumentKind::Counter); for (int i = 1; i <= 10; ++i) { @@ -191,7 +192,7 @@ TEST(MinMaxSumCountAggregator, Concurrency) { // This test checks that the aggregator updates appropriately // when called in a multi-threaded context. - MinMaxSumCountAggregator agg(opentelemetry::metrics::InstrumentKind::Counter); + MinMaxSumCountAggregator agg(metrics_api::InstrumentKind::Counter); std::thread first(&callback, std::ref(agg)); std::thread second(&callback, std::ref(agg)); diff --git a/sdk/test/metrics/sketch_aggregator_test.cc b/sdk/test/metrics/sketch_aggregator_test.cc index c17900e0a6..43ff0607c5 100644 --- a/sdk/test/metrics/sketch_aggregator_test.cc +++ b/sdk/test/metrics/sketch_aggregator_test.cc @@ -150,7 +150,7 @@ TEST(Sketch, MergeSmall) alpha.merge(beta); alpha.checkpoint(); - EXPECT_EQ(alpha.get_checkpoint()[0], std::accumulate(vals.begin(), vals.end(), 0) + + EXPECT_EQ(alpha.get_checkpoint()[0], std::accumulate(vals.begin(), vals.end(), 0) std::accumulate(otherVals.begin(), otherVals.end(), 0)); EXPECT_EQ(alpha.get_checkpoint()[1], vals.size() + otherVals.size()); @@ -178,7 +178,7 @@ TEST(Sketch, MergeLarge) alpha.merge(beta); alpha.checkpoint(); - EXPECT_EQ(alpha.get_checkpoint()[0], std::accumulate(vals.begin(), vals.end(), 0) + + EXPECT_EQ(alpha.get_checkpoint()[0], std::accumulate(vals.begin(), vals.end(), 0) std::accumulate(otherVals.begin(), otherVals.end(), 0)); EXPECT_EQ(alpha.get_checkpoint()[1], vals.size() + otherVals.size()); diff --git a/sdk/test/metrics/ungrouped_processor_test.cc b/sdk/test/metrics/ungrouped_processor_test.cc index 6bfbd0cde3..eef8babc77 100644 --- a/sdk/test/metrics/ungrouped_processor_test.cc +++ b/sdk/test/metrics/ungrouped_processor_test.cc @@ -16,14 +16,14 @@ namespace nostd = opentelemetry::nostd; TEST(UngroupedMetricsProcessor, UngroupedProcessorFinishedCollectionStateless) { auto processor = std::unique_ptr( - new opentelemetry::sdk::metrics::UngroupedMetricsProcessor(false)); + new sdkmetrics::UngroupedMetricsProcessor(false)); - auto aggregator = std::shared_ptr>( - new opentelemetry::sdk::metrics::CounterAggregator( + auto aggregator = std::shared_ptr>( + new sdkmetrics::CounterAggregator( metrics_api::InstrumentKind::Counter)); - auto aggregator2 = std::shared_ptr>( - new opentelemetry::sdk::metrics::CounterAggregator( + auto aggregator2 = std::shared_ptr>( + new sdkmetrics::CounterAggregator( metrics_api::InstrumentKind::Counter)); aggregator->update(5.5); @@ -53,14 +53,14 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorFinishedCollectionStateless) TEST(UngroupedMetricsProcessor, UngroupedProcessorFinishedCollectionStateful) { auto processor = std::unique_ptr( - new opentelemetry::sdk::metrics::UngroupedMetricsProcessor(true)); + new sdkmetrics::UngroupedMetricsProcessor(true)); - auto aggregator = std::shared_ptr>( - new opentelemetry::sdk::metrics::CounterAggregator( + auto aggregator = std::shared_ptr>( + new sdkmetrics::CounterAggregator( metrics_api::InstrumentKind::Counter)); - auto aggregator2 = std::shared_ptr>( - new opentelemetry::sdk::metrics::CounterAggregator( + auto aggregator2 = std::shared_ptr>( + new sdkmetrics::CounterAggregator( metrics_api::InstrumentKind::Counter)); aggregator->update(5.5); @@ -88,10 +88,10 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorFinishedCollectionStateful) TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStatelessShort) { auto processor = std::unique_ptr( - new opentelemetry::sdk::metrics::UngroupedMetricsProcessor(false)); + new sdkmetrics::UngroupedMetricsProcessor(false)); - auto aggregator = std::shared_ptr>( - new opentelemetry::sdk::metrics::CounterAggregator( + auto aggregator = std::shared_ptr>( + new sdkmetrics::CounterAggregator( metrics_api::InstrumentKind::Counter)); aggregator->update(4); @@ -113,10 +113,10 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateles TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStatelessInt) { auto processor = std::unique_ptr( - new opentelemetry::sdk::metrics::UngroupedMetricsProcessor(false)); + new sdkmetrics::UngroupedMetricsProcessor(false)); - auto aggregator = std::shared_ptr>( - new opentelemetry::sdk::metrics::CounterAggregator( + auto aggregator = std::shared_ptr>( + new sdkmetrics::CounterAggregator( metrics_api::InstrumentKind::Counter)); aggregator->update(5); @@ -137,10 +137,10 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateles TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStatelessFloat) { auto processor = std::unique_ptr( - new opentelemetry::sdk::metrics::UngroupedMetricsProcessor(false)); + new sdkmetrics::UngroupedMetricsProcessor(false)); - auto aggregator = std::shared_ptr>( - new opentelemetry::sdk::metrics::CounterAggregator( + auto aggregator = std::shared_ptr>( + new sdkmetrics::CounterAggregator( metrics_api::InstrumentKind::Counter)); aggregator->update(8.5); @@ -162,10 +162,10 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateles TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStatelessDouble) { auto processor = std::unique_ptr( - new opentelemetry::sdk::metrics::UngroupedMetricsProcessor(false)); + new sdkmetrics::UngroupedMetricsProcessor(false)); - auto aggregator = std::shared_ptr>( - new opentelemetry::sdk::metrics::CounterAggregator( + auto aggregator = std::shared_ptr>( + new sdkmetrics::CounterAggregator( metrics_api::InstrumentKind::Counter)); aggregator->update(5.5); @@ -192,14 +192,14 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateles TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStatefulShort) { auto processor = std::unique_ptr( - new opentelemetry::sdk::metrics::UngroupedMetricsProcessor(true)); + new sdkmetrics::UngroupedMetricsProcessor(true)); - auto aggregator = std::shared_ptr>( - new opentelemetry::sdk::metrics::CounterAggregator( + auto aggregator = std::shared_ptr>( + new sdkmetrics::CounterAggregator( metrics_api::InstrumentKind::Counter)); - auto aggregator_test = std::shared_ptr>( - new opentelemetry::sdk::metrics::CounterAggregator( + auto aggregator_test = std::shared_ptr>( + new sdkmetrics::CounterAggregator( metrics_api::InstrumentKind::Counter)); aggregator->update(5); @@ -237,14 +237,14 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStatefulInt) { auto processor = std::unique_ptr( - new opentelemetry::sdk::metrics::UngroupedMetricsProcessor(true)); + new sdkmetrics::UngroupedMetricsProcessor(true)); - auto aggregator = std::shared_ptr>( - new opentelemetry::sdk::metrics::CounterAggregator( + auto aggregator = std::shared_ptr>( + new sdkmetrics::CounterAggregator( metrics_api::InstrumentKind::Counter)); - auto aggregator_test = std::shared_ptr>( - new opentelemetry::sdk::metrics::CounterAggregator( + auto aggregator_test = std::shared_ptr>( + new sdkmetrics::CounterAggregator( metrics_api::InstrumentKind::Counter)); aggregator->update(5); @@ -280,14 +280,14 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStatefulFloat) { auto processor = std::unique_ptr( - new opentelemetry::sdk::metrics::UngroupedMetricsProcessor(true)); + new sdkmetrics::UngroupedMetricsProcessor(true)); - auto aggregator = std::shared_ptr>( - new opentelemetry::sdk::metrics::CounterAggregator( + auto aggregator = std::shared_ptr>( + new sdkmetrics::CounterAggregator( metrics_api::InstrumentKind::Counter)); - auto aggregator_test = std::shared_ptr>( - new opentelemetry::sdk::metrics::CounterAggregator( + auto aggregator_test = std::shared_ptr>( + new sdkmetrics::CounterAggregator( metrics_api::InstrumentKind::Counter)); aggregator->update(5); @@ -325,14 +325,14 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStatefulDouble) { auto processor = std::unique_ptr( - new opentelemetry::sdk::metrics::UngroupedMetricsProcessor(true)); + new sdkmetrics::UngroupedMetricsProcessor(true)); - auto aggregator = std::shared_ptr>( - new opentelemetry::sdk::metrics::CounterAggregator( + auto aggregator = std::shared_ptr>( + new sdkmetrics::CounterAggregator( metrics_api::InstrumentKind::Counter)); - auto aggregator_test = std::shared_ptr>( - new opentelemetry::sdk::metrics::CounterAggregator( + auto aggregator_test = std::shared_ptr>( + new sdkmetrics::CounterAggregator( metrics_api::InstrumentKind::Counter)); aggregator->update(5.5); @@ -370,14 +370,14 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStatefulMinMaxSumCount) { auto processor = std::unique_ptr( - new opentelemetry::sdk::metrics::UngroupedMetricsProcessor(true)); + new sdkmetrics::UngroupedMetricsProcessor(true)); - auto aggregator = std::shared_ptr>( - new opentelemetry::sdk::metrics::MinMaxSumCountAggregator( + auto aggregator = std::shared_ptr>( + new sdkmetrics::MinMaxSumCountAggregator( metrics_api::InstrumentKind::Counter)); - auto aggregator2 = std::shared_ptr>( - new opentelemetry::sdk::metrics::MinMaxSumCountAggregator( + auto aggregator2 = std::shared_ptr>( + new sdkmetrics::MinMaxSumCountAggregator( metrics_api::InstrumentKind::Counter)); aggregator->update(1.1); @@ -417,10 +417,10 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStatefulGauge) { auto processor = std::unique_ptr( - new opentelemetry::sdk::metrics::UngroupedMetricsProcessor(true)); + new sdkmetrics::UngroupedMetricsProcessor(true)); - auto aggregator = std::shared_ptr>( - new opentelemetry::sdk::metrics::GaugeAggregator( + auto aggregator = std::shared_ptr>( + new sdkmetrics::GaugeAggregator( metrics_api::InstrumentKind::Counter)); aggregator->update(1.1); @@ -456,14 +456,14 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStatefulExact) { auto processor = std::unique_ptr( - new opentelemetry::sdk::metrics::UngroupedMetricsProcessor(true)); + new sdkmetrics::UngroupedMetricsProcessor(true)); - auto aggregator = std::shared_ptr>( - new opentelemetry::sdk::metrics::ExactAggregator(metrics_api::InstrumentKind::Counter, + auto aggregator = std::shared_ptr>( + new sdkmetrics::ExactAggregator(metrics_api::InstrumentKind::Counter, false)); - auto aggregator2 = std::shared_ptr>( - new opentelemetry::sdk::metrics::ExactAggregator(metrics_api::InstrumentKind::Counter, + auto aggregator2 = std::shared_ptr>( + new sdkmetrics::ExactAggregator(metrics_api::InstrumentKind::Counter, false)); aggregator->update(1.1); @@ -504,15 +504,15 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStatefulHistogram) { auto processor = std::unique_ptr( - new opentelemetry::sdk::metrics::UngroupedMetricsProcessor(true)); + new sdkmetrics::UngroupedMetricsProcessor(true)); std::vector boundaries{10, 20, 30, 40, 50}; - auto aggregator = std::shared_ptr>( - new opentelemetry::sdk::metrics::HistogramAggregator( + auto aggregator = std::shared_ptr>( + new sdkmetrics::HistogramAggregator( metrics_api::InstrumentKind::Counter, boundaries)); - auto aggregator2 = std::shared_ptr>( - new opentelemetry::sdk::metrics::HistogramAggregator( + auto aggregator2 = std::shared_ptr>( + new sdkmetrics::HistogramAggregator( metrics_api::InstrumentKind::Counter, boundaries)); for (int i = 0; i < 60; i++) @@ -567,14 +567,14 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStatefulSketch) { auto processor = std::unique_ptr( - new opentelemetry::sdk::metrics::UngroupedMetricsProcessor(true)); + new sdkmetrics::UngroupedMetricsProcessor(true)); - auto aggregator = std::shared_ptr>( - new opentelemetry::sdk::metrics::SketchAggregator(metrics_api::InstrumentKind::Counter, + auto aggregator = std::shared_ptr>( + new sdkmetrics::SketchAggregator(metrics_api::InstrumentKind::Counter, .00005)); - auto test_aggregator = std::shared_ptr>( - new opentelemetry::sdk::metrics::SketchAggregator(metrics_api::InstrumentKind::Counter, + auto test_aggregator = std::shared_ptr>( + new sdkmetrics::SketchAggregator(metrics_api::InstrumentKind::Counter, .00005)); for (int i = 0; i < 60; i++) diff --git a/sdk/test/resource/resource_test.cc b/sdk/test/resource/resource_test.cc index 37abb1d0fc..3fdaea4983 100644 --- a/sdk/test/resource/resource_test.cc +++ b/sdk/test/resource/resource_test.cc @@ -19,6 +19,7 @@ #endif using namespace opentelemetry::sdk::resource; +namespace nostd = opentelemetry::nostd; class TestResource : public Resource { @@ -46,14 +47,14 @@ TEST(ResourceTest, create_without_servicename) EXPECT_TRUE(expected_attributes.find(e.first) != expected_attributes.end()); if (expected_attributes.find(e.first) != expected_attributes.end()) if (e.first == "version") - EXPECT_EQ(opentelemetry::nostd::get(expected_attributes.find(e.first)->second), - opentelemetry::nostd::get(e.second)); + EXPECT_EQ(nostd::get(expected_attributes.find(e.first)->second), + nostd::get(e.second)); else if (e.first == "cost") - EXPECT_EQ(opentelemetry::nostd::get(expected_attributes.find(e.first)->second), - opentelemetry::nostd::get(e.second)); + EXPECT_EQ(nostd::get(expected_attributes.find(e.first)->second), + nostd::get(e.second)); else - EXPECT_EQ(opentelemetry::nostd::get(expected_attributes.find(e.first)->second), - opentelemetry::nostd::get(e.second)); + EXPECT_EQ(nostd::get(expected_attributes.find(e.first)->second), + nostd::get(e.second)); } EXPECT_EQ(received_attributes.size(), expected_attributes.size()); // for missing service.name } @@ -78,14 +79,14 @@ TEST(ResourceTest, create_with_servicename) if (expected_attributes.find(e.first) != expected_attributes.end()) { if (e.first == "version") - EXPECT_EQ(opentelemetry::nostd::get(expected_attributes.find(e.first)->second), - opentelemetry::nostd::get(e.second)); + EXPECT_EQ(nostd::get(expected_attributes.find(e.first)->second), + nostd::get(e.second)); else if (e.first == "cost") - EXPECT_EQ(opentelemetry::nostd::get(expected_attributes.find(e.first)->second), - opentelemetry::nostd::get(e.second)); + EXPECT_EQ(nostd::get(expected_attributes.find(e.first)->second), + nostd::get(e.second)); else - EXPECT_EQ(opentelemetry::nostd::get(expected_attributes.find(e.first)->second), - opentelemetry::nostd::get(e.second)); + EXPECT_EQ(nostd::get(expected_attributes.find(e.first)->second), + nostd::get(e.second)); } } EXPECT_EQ(received_attributes.size(), expected_attributes.size()); // for missing service.name @@ -106,8 +107,8 @@ TEST(ResourceTest, create_with_emptyatrributes) { EXPECT_TRUE(expected_attributes.find(e.first) != expected_attributes.end()); if (expected_attributes.find(e.first) != expected_attributes.end()) - EXPECT_EQ(opentelemetry::nostd::get(expected_attributes.find(e.first)->second), - opentelemetry::nostd::get(e.second)); + EXPECT_EQ(nostd::get(expected_attributes.find(e.first)->second), + nostd::get(e.second)); } EXPECT_EQ(received_attributes.size(), expected_attributes.size()); // for missing service.name } @@ -137,7 +138,7 @@ TEST(ResourceTest, Merge) if (expected_attributes.find(e.first) != expected_attributes.end()) { EXPECT_EQ(expected_attributes.find(e.first)->second, - opentelemetry::nostd::get(e.second)); + nostd::get(e.second)); } } EXPECT_EQ(received_attributes.size(), expected_attributes.size()); @@ -159,7 +160,7 @@ TEST(ResourceTest, MergeEmptyString) if (expected_attributes.find(e.first) != expected_attributes.end()) { EXPECT_EQ(expected_attributes.find(e.first)->second, - opentelemetry::nostd::get(e.second)); + nostd::get(e.second)); } } EXPECT_EQ(received_attributes.size(), expected_attributes.size()); @@ -182,7 +183,7 @@ TEST(ResourceTest, OtelResourceDetector) if (expected_attributes.find(e.first) != expected_attributes.end()) { EXPECT_EQ(expected_attributes.find(e.first)->second, - opentelemetry::nostd::get(e.second)); + nostd::get(e.second)); } } EXPECT_EQ(received_attributes.size(), expected_attributes.size()); @@ -210,7 +211,7 @@ TEST(ResourceTest, OtelResourceDetectorEmptyEnv) if (expected_attributes.find(e.first) != expected_attributes.end()) { EXPECT_EQ(expected_attributes.find(e.first)->second, - opentelemetry::nostd::get(e.second)); + nostd::get(e.second)); } } EXPECT_EQ(received_attributes.size(), expected_attributes.size()); diff --git a/sdk/test/trace/always_off_sampler_test.cc b/sdk/test/trace/always_off_sampler_test.cc index 5a51549626..f96dc18cc4 100644 --- a/sdk/test/trace/always_off_sampler_test.cc +++ b/sdk/test/trace/always_off_sampler_test.cc @@ -8,13 +8,15 @@ using opentelemetry::sdk::trace::AlwaysOffSampler; using opentelemetry::sdk::trace::Decision; using opentelemetry::trace::SpanContext; +namespace trace_api = opentelemetry::trace; + TEST(AlwaysOffSampler, ShouldSample) { AlwaysOffSampler sampler; - opentelemetry::trace::TraceId trace_id; - opentelemetry::trace::SpanKind span_kind = opentelemetry::trace::SpanKind::kInternal; + trace_api::TraceId trace_id; + trace_api::SpanKind span_kind = trace_api::SpanKind::kInternal; using M = std::map; M m1 = {{}}; @@ -23,7 +25,7 @@ TEST(AlwaysOffSampler, ShouldSample) L l1 = {{SpanContext(false, false), {}}, {SpanContext(false, false), {}}}; opentelemetry::common::KeyValueIterableView view{m1}; - opentelemetry::trace::SpanContextKeyValueIterableView links{l1}; + trace_api::SpanContextKeyValueIterableView links{l1}; auto sampling_result = sampler.ShouldSample(SpanContext::GetInvalid(), trace_id, "", span_kind, view, links); diff --git a/sdk/test/trace/parent_sampler_test.cc b/sdk/test/trace/parent_sampler_test.cc index 5f2c8cdd91..2aa482c422 100644 --- a/sdk/test/trace/parent_sampler_test.cc +++ b/sdk/test/trace/parent_sampler_test.cc @@ -25,7 +25,7 @@ TEST(ParentBasedSampler, ShouldSample) uint8_t span_id_buffer[trace_api::SpanId::kSize] = {1}; trace_api::SpanId span_id{span_id_buffer}; - opentelemetry::trace::SpanKind span_kind = opentelemetry::trace::SpanKind::kInternal; + trace_api::SpanKind span_kind = trace_api::SpanKind::kInternal; using M = std::map; M m1 = {{}}; @@ -34,7 +34,7 @@ TEST(ParentBasedSampler, ShouldSample) opentelemetry::common::KeyValueIterableView view{m1}; trace_api::SpanContextKeyValueIterableView links{l1}; - auto trace_state = opentelemetry::trace::TraceState::FromHeader("congo=t61rcWkgMzE"); + auto trace_state = trace_api::TraceState::FromHeader("congo=t61rcWkgMzE"); trace_api::SpanContext parent_context_sampled(trace_id, span_id, trace_api::TraceFlags{1}, false, trace_state); trace_api::SpanContext parent_context_nonsampled(trace_id, span_id, trace_api::TraceFlags{0}, diff --git a/sdk/test/trace/sampler_benchmark.cc b/sdk/test/trace/sampler_benchmark.cc index b09cb5b0cd..a47e9ca1f5 100644 --- a/sdk/test/trace/sampler_benchmark.cc +++ b/sdk/test/trace/sampler_benchmark.cc @@ -19,6 +19,7 @@ using namespace opentelemetry::sdk::trace; using opentelemetry::exporter::memory::InMemorySpanExporter; using opentelemetry::trace::SpanContext; +namespace trace_api = opentelemetry::trace; namespace { @@ -63,8 +64,8 @@ BENCHMARK(BM_TraceIdRatioBasedSamplerConstruction); // Sampler Helper Function void BenchmarkShouldSampler(Sampler &sampler, benchmark::State &state) { - opentelemetry::trace::TraceId trace_id; - opentelemetry::trace::SpanKind span_kind = opentelemetry::trace::SpanKind::kInternal; + trace_api::TraceId trace_id; + trace_api::SpanKind span_kind = trace_api::SpanKind::kInternal; using M = std::map; M m1 = {{}}; @@ -126,7 +127,7 @@ void BenchmarkSpanCreation(std::shared_ptr sampler, benchmark::State &s processors.push_back(std::move(processor)); auto context = std::make_shared(std::move(processors)); auto resource = opentelemetry::sdk::resource::Resource::Create({}); - auto tracer = std::shared_ptr(new Tracer(context)); + auto tracer = std::shared_ptr(new Tracer(context)); while (state.KeepRunning()) { diff --git a/sdk/test/trace/span_data_test.cc b/sdk/test/trace/span_data_test.cc index 5d9dcbb5f7..42f884a9d7 100644 --- a/sdk/test/trace/span_data_test.cc +++ b/sdk/test/trace/span_data_test.cc @@ -10,11 +10,14 @@ #include using opentelemetry::sdk::trace::SpanData; +namespace trace_api = opentelemetry::trace; +namespace common = opentelemetry::common; +namespace nostd = opentelemetry::nostd; TEST(SpanData, DefaultValues) { - opentelemetry::trace::SpanContext empty_span_context{false, false}; - opentelemetry::trace::SpanId zero_span_id; + trace_api::SpanContext empty_span_context{false, false}; + trace_api::SpanId zero_span_id; SpanData data; ASSERT_EQ(data.GetTraceId(), empty_span_context.trace_id()); @@ -22,7 +25,7 @@ TEST(SpanData, DefaultValues) ASSERT_EQ(data.GetSpanContext(), empty_span_context); ASSERT_EQ(data.GetParentSpanId(), zero_span_id); ASSERT_EQ(data.GetName(), ""); - ASSERT_EQ(data.GetStatus(), opentelemetry::trace::StatusCode::kUnset); + ASSERT_EQ(data.GetStatus(), trace_api::StatusCode::kUnset); ASSERT_EQ(data.GetDescription(), ""); ASSERT_EQ(data.GetStartTime().time_since_epoch(), std::chrono::nanoseconds(0)); ASSERT_EQ(data.GetDuration(), std::chrono::nanoseconds(0)); @@ -35,21 +38,21 @@ TEST(SpanData, Set) constexpr uint8_t trace_id_buf[] = {1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8}; constexpr uint8_t span_id_buf[] = {1, 2, 3, 4, 5, 6, 7, 8}; constexpr uint8_t parent_span_id_buf[] = {8, 7, 6, 5, 4, 3, 2, 1}; - opentelemetry::trace::TraceId trace_id{trace_id_buf}; - opentelemetry::trace::SpanId span_id{span_id_buf}; - opentelemetry::trace::SpanId parent_span_id{parent_span_id_buf}; - const auto trace_state = opentelemetry::trace::TraceState::GetDefault()->Set("key1", "value"); - const opentelemetry::trace::SpanContext span_context{ + trace_api::TraceId trace_id{trace_id_buf}; + trace_api::SpanId span_id{span_id_buf}; + trace_api::SpanId parent_span_id{parent_span_id_buf}; + const auto trace_state = trace_api::TraceState::GetDefault()->Set("key1", "value"); + const trace_api::SpanContext span_context{ trace_id, span_id, - opentelemetry::trace::TraceFlags{opentelemetry::trace::TraceFlags::kIsSampled}, true, + trace_api::TraceFlags{trace_api::TraceFlags::kIsSampled}, true, trace_state}; - opentelemetry::common::SystemTimestamp now(std::chrono::system_clock::now()); + common::SystemTimestamp now(std::chrono::system_clock::now()); SpanData data; data.SetIdentity(span_context, parent_span_id); data.SetName("span name"); - data.SetSpanKind(opentelemetry::trace::SpanKind::kServer); - data.SetStatus(opentelemetry::trace::StatusCode::kOk, "description"); + data.SetSpanKind(trace_api::SpanKind::kServer); + data.SetStatus(trace_api::StatusCode::kOk, "description"); data.SetStartTime(now); data.SetDuration(std::chrono::nanoseconds(1000000)); data.SetAttribute("attr1", (int64_t)314159); @@ -63,12 +66,12 @@ TEST(SpanData, Set) ASSERT_EQ(trace_state_key1_value, "value"); ASSERT_EQ(data.GetParentSpanId(), parent_span_id); ASSERT_EQ(data.GetName(), "span name"); - ASSERT_EQ(data.GetSpanKind(), opentelemetry::trace::SpanKind::kServer); - ASSERT_EQ(data.GetStatus(), opentelemetry::trace::StatusCode::kOk); + ASSERT_EQ(data.GetSpanKind(), trace_api::SpanKind::kServer); + ASSERT_EQ(data.GetStatus(), trace_api::StatusCode::kOk); ASSERT_EQ(data.GetDescription(), "description"); ASSERT_EQ(data.GetStartTime().time_since_epoch(), now.time_since_epoch()); ASSERT_EQ(data.GetDuration(), std::chrono::nanoseconds(1000000)); - ASSERT_EQ(opentelemetry::nostd::get(data.GetAttributes().at("attr1")), 314159); + ASSERT_EQ(nostd::get(data.GetAttributes().at("attr1")), 314159); ASSERT_EQ(data.GetEvents().at(0).GetName(), "event1"); ASSERT_EQ(data.GetEvents().at(0).GetTimestamp(), now); } @@ -84,12 +87,12 @@ TEST(SpanData, EventAttributes) data.AddEvent( "Test Event", std::chrono::system_clock::now(), - opentelemetry::common::KeyValueIterableView>(attributes)); + common::KeyValueIterableView>(attributes)); for (int i = 0; i < kNumAttributes; i++) { EXPECT_EQ( - opentelemetry::nostd::get(data.GetEvents().at(0).GetAttributes().at(keys[i])), + nostd::get(data.GetEvents().at(0).GetAttributes().at(keys[i])), values[i]); } } @@ -114,26 +117,26 @@ TEST(SpanData, Links) {keys[0], values[0]}, {keys[1], values[1]}, {keys[2], values[2]}}; // produce valid SpanContext with pseudo span and trace Id. - uint8_t span_id_buf[opentelemetry::trace::SpanId::kSize] = { + uint8_t span_id_buf[trace_api::SpanId::kSize] = { 1, }; - opentelemetry::trace::SpanId span_id{span_id_buf}; - uint8_t trace_id_buf[opentelemetry::trace::TraceId::kSize] = { + trace_api::SpanId span_id{span_id_buf}; + uint8_t trace_id_buf[trace_api::TraceId::kSize] = { 2, }; - opentelemetry::trace::TraceId trace_id{trace_id_buf}; - const auto span_context = opentelemetry::trace::SpanContext( + trace_api::TraceId trace_id{trace_id_buf}; + const auto span_context = trace_api::SpanContext( trace_id, span_id, - opentelemetry::trace::TraceFlags{opentelemetry::trace::TraceFlags::kIsSampled}, true); + trace_api::TraceFlags{trace_api::TraceFlags::kIsSampled}, true); data.AddLink( span_context, - opentelemetry::common::KeyValueIterableView>(attributes)); + common::KeyValueIterableView>(attributes)); EXPECT_EQ(data.GetLinks().at(0).GetSpanContext(), span_context); for (int i = 0; i < kNumAttributes; i++) { - EXPECT_EQ(opentelemetry::nostd::get(data.GetLinks().at(0).GetAttributes().at(keys[i])), + EXPECT_EQ(nostd::get(data.GetLinks().at(0).GetAttributes().at(keys[i])), values[i]); } } diff --git a/sdk/test/trace/trace_id_ratio_sampler_test.cc b/sdk/test/trace/trace_id_ratio_sampler_test.cc index 610c0bd9e7..1741d6b488 100644 --- a/sdk/test/trace/trace_id_ratio_sampler_test.cc +++ b/sdk/test/trace/trace_id_ratio_sampler_test.cc @@ -13,6 +13,7 @@ using opentelemetry::sdk::common::Random; using opentelemetry::sdk::trace::Decision; using opentelemetry::sdk::trace::TraceIdRatioBasedSampler; namespace trace_api = opentelemetry::trace; +namespace common = opentelemetry::common; namespace { @@ -34,7 +35,7 @@ int RunShouldSampleCountDecision(trace_api::SpanContext &context, { int actual_count = 0; - opentelemetry::trace::SpanKind span_kind = opentelemetry::trace::SpanKind::kInternal; + trace_api::SpanKind span_kind = trace_api::SpanKind::kInternal; using M = std::map; M m1 = {{}}; @@ -42,7 +43,7 @@ int RunShouldSampleCountDecision(trace_api::SpanContext &context, using L = std::vector>>; L l1 = {{trace_api::SpanContext(false, false), {}}, {trace_api::SpanContext(false, false), {}}}; - opentelemetry::common::KeyValueIterableView view{m1}; + common::KeyValueIterableView view{m1}; trace_api::SpanContextKeyValueIterableView links{l1}; for (int i = 0; i < iterations; ++i) @@ -50,7 +51,7 @@ int RunShouldSampleCountDecision(trace_api::SpanContext &context, uint8_t buf[16] = {0}; Random::GenerateRandomBuffer(buf); - opentelemetry::trace::TraceId trace_id(buf); + trace_api::TraceId trace_id(buf); auto result = sampler.ShouldSample(context, trace_id, "", span_kind, view, links); if (result.decision == Decision::RECORD_AND_SAMPLE) @@ -65,9 +66,9 @@ int RunShouldSampleCountDecision(trace_api::SpanContext &context, TEST(TraceIdRatioBasedSampler, ShouldSampleWithoutContext) { - opentelemetry::trace::TraceId invalid_trace_id; + trace_api::TraceId invalid_trace_id; - opentelemetry::trace::SpanKind span_kind = opentelemetry::trace::SpanKind::kInternal; + trace_api::SpanKind span_kind = trace_api::SpanKind::kInternal; using M = std::map; M m1 = {{}}; @@ -75,7 +76,7 @@ TEST(TraceIdRatioBasedSampler, ShouldSampleWithoutContext) using L = std::vector>>; L l1 = {{trace_api::SpanContext(false, false), {}}, {trace_api::SpanContext(false, false), {}}}; - opentelemetry::common::KeyValueIterableView view{m1}; + common::KeyValueIterableView view{m1}; trace_api::SpanContextKeyValueIterableView links{l1}; TraceIdRatioBasedSampler s1(0.01); @@ -87,7 +88,7 @@ TEST(TraceIdRatioBasedSampler, ShouldSampleWithoutContext) ASSERT_EQ(nullptr, sampling_result.attributes); constexpr uint8_t buf[] = {0, 0, 0, 0, 0, 0, 0, 0x80, 0, 0, 0, 0, 0, 0, 0, 0}; - opentelemetry::trace::TraceId valid_trace_id(buf); + trace_api::TraceId valid_trace_id(buf); sampling_result = s1.ShouldSample(trace_api::SpanContext::GetInvalid(), valid_trace_id, "", span_kind, view, links); @@ -128,7 +129,7 @@ TEST(TraceIdRatioBasedSampler, ShouldSampleWithContext) uint8_t span_id_buffer[trace_api::SpanId::kSize] = {1}; trace_api::SpanId span_id{span_id_buffer}; - opentelemetry::trace::SpanKind span_kind = opentelemetry::trace::SpanKind::kInternal; + trace_api::SpanKind span_kind = trace_api::SpanKind::kInternal; trace_api::SpanContext c1(trace_id, span_id, trace_api::TraceFlags{0}, false); trace_api::SpanContext c2(trace_id, span_id, trace_api::TraceFlags{1}, false); trace_api::SpanContext c3(trace_id, span_id, trace_api::TraceFlags{0}, true); @@ -140,7 +141,7 @@ TEST(TraceIdRatioBasedSampler, ShouldSampleWithContext) using L = std::vector>>; L l1 = {{trace_api::SpanContext(false, false), {}}, {trace_api::SpanContext(false, false), {}}}; - opentelemetry::common::KeyValueIterableView view{m1}; + common::KeyValueIterableView view{m1}; trace_api::SpanContextKeyValueIterableView links{l1}; TraceIdRatioBasedSampler s1(0.01); diff --git a/sdk/test/trace/tracer_test.cc b/sdk/test/trace/tracer_test.cc index 94e57a4cd7..98ef9607da 100644 --- a/sdk/test/trace/tracer_test.cc +++ b/sdk/test/trace/tracer_test.cc @@ -19,6 +19,7 @@ using opentelemetry::common::SteadyTimestamp; using opentelemetry::common::SystemTimestamp; namespace nostd = opentelemetry::nostd; namespace common = opentelemetry::common; +namespace trace_api = opentelemetry::trace; using opentelemetry::common::KeyValueIterableView; using opentelemetry::exporter::memory::InMemorySpanData; using opentelemetry::exporter::memory::InMemorySpanExporter; @@ -37,8 +38,8 @@ class MockSampler final : public Sampler trace_api::TraceId trace_id, nostd::string_view /*name*/, trace_api::SpanKind /*span_kind*/, - const opentelemetry::common::KeyValueIterable & /*attributes*/, - const opentelemetry::trace::SpanContextKeyValueIterable & /*links*/) noexcept override + const common::KeyValueIterable & /*attributes*/, + const trace_api::SpanContextKeyValueIterable & /*links*/) noexcept override { // Sample only if valid trace_id ( This is to test Sampler get's valid trace id) if (trace_id.IsValid()) @@ -46,8 +47,8 @@ class MockSampler final : public Sampler // Return two pairs of attributes. These attributes should be added to the // span attributes return {Decision::RECORD_AND_SAMPLE, - nostd::unique_ptr>( - new const std::map( + nostd::unique_ptr>( + new const std::map( {{"sampling_attr1", 123}, {"sampling_attr2", "string"}}))}; } else @@ -66,14 +67,14 @@ class MockSampler final : public Sampler */ class MockIdGenerator : public IdGenerator { - opentelemetry::trace::SpanId GenerateSpanId() noexcept override + trace_api::SpanId GenerateSpanId() noexcept override { - return opentelemetry::trace::SpanId(buf_span); + return trace_api::SpanId(buf_span); } - opentelemetry::trace::TraceId GenerateTraceId() noexcept override + trace_api::TraceId GenerateTraceId() noexcept override { - return opentelemetry::trace::TraceId(buf_trace); + return trace_api::TraceId(buf_trace); } uint8_t buf_span[8] = {1, 2, 3, 4, 5, 6, 7, 8}; uint8_t buf_trace[16] = {1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1}; @@ -81,16 +82,16 @@ class MockIdGenerator : public IdGenerator namespace { -std::shared_ptr initTracer(std::unique_ptr &&exporter) +std::shared_ptr initTracer(std::unique_ptr &&exporter) { auto processor = std::unique_ptr(new SimpleSpanProcessor(std::move(exporter))); std::vector> processors; processors.push_back(std::move(processor)); auto context = std::make_shared(std::move(processors)); - return std::shared_ptr(new Tracer(context)); + return std::shared_ptr(new Tracer(context)); } -std::shared_ptr initTracer( +std::shared_ptr initTracer( std::unique_ptr &&exporter, // For testing, just shove a pointer over, we'll take it over. Sampler *sampler, @@ -103,7 +104,7 @@ std::shared_ptr initTracer( auto context = std::make_shared(std::move(processors), resource, std::unique_ptr(sampler), std::unique_ptr(id_generator)); - return std::shared_ptr(new Tracer(context)); + return std::shared_ptr(new Tracer(context)); } } // namespace @@ -200,11 +201,11 @@ TEST(Tracer, StartSpanWithOptionsTime) std::shared_ptr span_data = exporter->GetData(); auto tracer = initTracer(std::move(exporter)); - opentelemetry::trace::StartSpanOptions start; + trace_api::StartSpanOptions start; start.start_system_time = SystemTimestamp(std::chrono::nanoseconds(300)); start.start_steady_time = SteadyTimestamp(std::chrono::nanoseconds(10)); - opentelemetry::trace::EndSpanOptions end; + trace_api::EndSpanOptions end; end.end_steady_time = SteadyTimestamp(std::chrono::nanoseconds(40)); tracer->StartSpan("span 1", start)->End(end); From 4cab069ea8816cc2650c4c1e05b0c408a797a668 Mon Sep 17 00:00:00 2001 From: PaurushGarg Date: Wed, 29 Sep 2021 14:53:37 -0700 Subject: [PATCH 02/16] Adding back the + signs that got deleted automatically --- .../baggage/propagation/baggage_propagator_test.cc | 2 +- examples/http/client.cc | 4 ++-- exporters/ostream/test/ostream_log_test.cc | 8 ++++---- exporters/ostream/test/ostream_metrics_test.cc | 4 ++-- exporters/ostream/test/ostream_span_test.cc | 14 +++++++------- sdk/test/metrics/histogram_aggregator_test.cc | 2 +- sdk/test/metrics/sketch_aggregator_test.cc | 4 ++-- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/api/test/baggage/propagation/baggage_propagator_test.cc b/api/test/baggage/propagation/baggage_propagator_test.cc index 126adf5a20..0f1f8f338c 100644 --- a/api/test/baggage/propagation/baggage_propagator_test.cc +++ b/api/test/baggage/propagation/baggage_propagator_test.cc @@ -48,7 +48,7 @@ TEST(BaggagePropagatorTest, ExtractAndInjectBaggage) { // create header string for baggage larger than allowed size (kMaxKeyValueSize) std::string very_large_baggage_header = - std::string(baggage::Baggage::kMaxKeyValueSize / 2 + 1, 'k') + "=" + std::string(baggage::Baggage::kMaxKeyValueSize / 2 + 1, 'k') + "=" + std::string(baggage::Baggage::kMaxKeyValueSize / 2 + 1, 'v'); std::map baggages = { diff --git a/examples/http/client.cc b/examples/http/client.cc index 1d574cb7d5..0a725a69c8 100644 --- a/examples/http/client.cc +++ b/examples/http/client.cc @@ -59,7 +59,7 @@ void sendRequest(const std::string &url) else { span->SetStatus(StatusCode::kError, - "Response Status :" + "Response Status :" + std::to_string(static_cast::type>( result.GetSessionState()))); @@ -88,7 +88,7 @@ int main(int argc, char *argv[]) port = default_port; } - std::string url = "http://" + std::string(default_host) + ":" + std::to_string(port) + std::string url = "http://" + std::string(default_host) + ":" + std::to_string(port) + std::string(default_path); sendRequest(url); } diff --git a/exporters/ostream/test/ostream_log_test.cc b/exporters/ostream/test/ostream_log_test.cc index 7398058c83..85b1c0b4ba 100644 --- a/exporters/ostream/test/ostream_log_test.cc +++ b/exporters/ostream/test/ostream_log_test.cc @@ -123,8 +123,8 @@ TEST(OStreamLogExporter, SimpleLogToCout) std::string expectedOutput = "{\n" - " timestamp : " - std::to_string(now.time_since_epoch().count()) + " timestamp : " + + std::to_string(now.time_since_epoch().count()) + "\n" " severity_num : 1\n" " severity_text : TRACE\n" @@ -271,8 +271,8 @@ TEST(OStreamLogExporter, IntegrationTest) // Compare actual vs expected outputs std::string expectedOutput = "{\n" - " timestamp : " - std::to_string(now.time_since_epoch().count()) + " timestamp : " + + std::to_string(now.time_since_epoch().count()) + "\n" " severity_num : 5\n" " severity_text : DEBUG\n" diff --git a/exporters/ostream/test/ostream_metrics_test.cc b/exporters/ostream/test/ostream_metrics_test.cc index bbb203ca7d..2891c0e822 100644 --- a/exporters/ostream/test/ostream_metrics_test.cc +++ b/exporters/ostream/test/ostream_metrics_test.cc @@ -140,8 +140,8 @@ TEST(OStreamMetricsExporter, PrintGauge) " description : description\n" " labels : labels\n" " last value : 9\n" - " timestamp : " - std::to_string(aggregator->get_checkpoint_timestamp().time_since_epoch().count()) + " timestamp : " + + std::to_string(aggregator->get_checkpoint_timestamp().time_since_epoch().count()) + "\n" "}\n"; diff --git a/exporters/ostream/test/ostream_span_test.cc b/exporters/ostream/test/ostream_span_test.cc index 1952fc8fdb..4ffd1b1feb 100644 --- a/exporters/ostream/test/ostream_span_test.cc +++ b/exporters/ostream/test/ostream_span_test.cc @@ -135,8 +135,8 @@ TEST(OStreamSpanExporter, PrintSpanWithBasicFields) " span_id : 0102030405060708\n" " tracestate : state1=value\n" " parent_span_id: 0807060504030201\n" - " start : " - start + " start : " + + start + "\n" " duration : 100\n" " description : Test Description\n" @@ -236,7 +236,7 @@ TEST(OStreamSpanExporter, PrintSpanWithEvents) auto recordable = processor->MakeRecordable(); common::SystemTimestamp now(std::chrono::system_clock::now()); - common::SystemTimestamp next(std::chrono::system_clock::now() + common::SystemTimestamp next(std::chrono::system_clock::now() + std::chrono::seconds(1)); std::string now_str = std::to_string(now.time_since_epoch().count()); @@ -264,15 +264,15 @@ TEST(OStreamSpanExporter, PrintSpanWithEvents) " events : \n" "\t{\n" "\t name : hello\n" - "\t timestamp : " - now_str + "\t timestamp : " + + now_str + "\n" "\t attributes : \n" "\t}\n" "\t{\n" "\t name : world\n" - "\t timestamp : " - next_str + "\t timestamp : " + + next_str + "\n" "\t attributes : \n" "\t\tattr1: string\n" diff --git a/sdk/test/metrics/histogram_aggregator_test.cc b/sdk/test/metrics/histogram_aggregator_test.cc index 03d849919b..eec00e8360 100644 --- a/sdk/test/metrics/histogram_aggregator_test.cc +++ b/sdk/test/metrics/histogram_aggregator_test.cc @@ -87,7 +87,7 @@ TEST(Histogram, Merge) alpha.merge(beta); alpha.checkpoint(); - EXPECT_EQ(alpha.get_checkpoint()[0], std::accumulate(vals.begin(), vals.end(), 0) + EXPECT_EQ(alpha.get_checkpoint()[0], std::accumulate(vals.begin(), vals.end(), 0) + std::accumulate(otherVals.begin(), otherVals.end(), 0)); EXPECT_EQ(alpha.get_checkpoint()[1], vals.size() + otherVals.size()); diff --git a/sdk/test/metrics/sketch_aggregator_test.cc b/sdk/test/metrics/sketch_aggregator_test.cc index 43ff0607c5..c17900e0a6 100644 --- a/sdk/test/metrics/sketch_aggregator_test.cc +++ b/sdk/test/metrics/sketch_aggregator_test.cc @@ -150,7 +150,7 @@ TEST(Sketch, MergeSmall) alpha.merge(beta); alpha.checkpoint(); - EXPECT_EQ(alpha.get_checkpoint()[0], std::accumulate(vals.begin(), vals.end(), 0) + EXPECT_EQ(alpha.get_checkpoint()[0], std::accumulate(vals.begin(), vals.end(), 0) + std::accumulate(otherVals.begin(), otherVals.end(), 0)); EXPECT_EQ(alpha.get_checkpoint()[1], vals.size() + otherVals.size()); @@ -178,7 +178,7 @@ TEST(Sketch, MergeLarge) alpha.merge(beta); alpha.checkpoint(); - EXPECT_EQ(alpha.get_checkpoint()[0], std::accumulate(vals.begin(), vals.end(), 0) + EXPECT_EQ(alpha.get_checkpoint()[0], std::accumulate(vals.begin(), vals.end(), 0) + std::accumulate(otherVals.begin(), otherVals.end(), 0)); EXPECT_EQ(alpha.get_checkpoint()[1], vals.size() + otherVals.size()); From 92467abd46b303f34c49369cf925f014bade2391 Mon Sep 17 00:00:00 2001 From: PaurushGarg Date: Wed, 29 Sep 2021 15:43:06 -0700 Subject: [PATCH 03/16] adding + symbol back that got removed by git push --- docs/building-with-stdlib.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/building-with-stdlib.md b/docs/building-with-stdlib.md index 25ba8be07c..26e09f9d39 100644 --- a/docs/building-with-stdlib.md +++ b/docs/building-with-stdlib.md @@ -5,7 +5,7 @@ process (environment where ABI compat is not a requirement), or for "header-only" implementation of SDK. Proposed approach cannot be employed for shared libs in environments where ABI -compatibility is required. OpenTelemetry SDK binary compiled with `compiler A +compatibility is required. OpenTelemetry SDK binary compiled with `compiler A + STL B` will not be ABI -compatible with the main executable compiled with `compiler C + STL D`. From d29acdb922cc217da5d7e1b4395c24af36906fed Mon Sep 17 00:00:00 2001 From: PaurushGarg Date: Tue, 5 Oct 2021 07:25:15 -0700 Subject: [PATCH 04/16] Removing errors related to logs/metrics test --- examples/metrics_simple/main.cc | 7 ++++--- sdk/src/logs/logger_provider.cc | 14 +++++++------- sdk/test/logs/logger_provider_sdk_test.cc | 4 ++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/examples/metrics_simple/main.cc b/examples/metrics_simple/main.cc index 1174f368d5..3c093029b2 100644 --- a/examples/metrics_simple/main.cc +++ b/examples/metrics_simple/main.cc @@ -9,10 +9,11 @@ # include "opentelemetry/sdk/metrics/meter_provider.h" # include "opentelemetry/sdk/metrics/ungrouped_processor.h" -namespace sdkmetrics = opentelemetry::sdk::metrics; -namespace nostd = opentelemetry::nostd; +namespace sdkmetrics = opentelemetry::sdk::metrics; +namespace nostd = opentelemetry::nostd; +namespace common = opentelemetry::common; namespace exportermetrics = opentelemetry::exporter::metrics; -namespace metrics_api = opentelemetry::metrics; +namespace metrics_api = opentelemetry::metrics; int main() diff --git a/sdk/src/logs/logger_provider.cc b/sdk/src/logs/logger_provider.cc index b80cb643ab..5a34be4053 100644 --- a/sdk/src/logs/logger_provider.cc +++ b/sdk/src/logs/logger_provider.cc @@ -5,18 +5,18 @@ # include "opentelemetry/sdk/logs/logger_provider.h" -namespace nostd = opentelemetry::nostd; -namespace logs = opentelemetry::logs; - OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace logs { +namespace nostd = opentelemetry::nostd; +namespace logs_api = opentelemetry::logs; + LoggerProvider::LoggerProvider() noexcept : processor_{nullptr} {} -nostd::shared_ptr LoggerProvider::GetLogger( +nostd::shared_ptr LoggerProvider::GetLogger( nostd::string_view name, nostd::string_view options) noexcept { @@ -27,7 +27,7 @@ nostd::shared_ptr LoggerProvider::GetLogger( auto loggerkv = loggers_.find(name.data()); if (loggerkv != loggers_.end()) { - return nostd::shared_ptr(loggerkv->second); + return nostd::shared_ptr(loggerkv->second); } // Check if creating a new logger would exceed the max number of loggers @@ -45,13 +45,13 @@ nostd::shared_ptr LoggerProvider::GetLogger( // If no logger with that name exists yet, create it and add it to the map of loggers - nostd::shared_ptr logger( + nostd::shared_ptr logger( new Logger(name, this->shared_from_this())); loggers_[name.data()] = logger; return logger; } -nostd::shared_ptr LoggerProvider::GetLogger( +nostd::shared_ptr LoggerProvider::GetLogger( nostd::string_view name, nostd::span args) noexcept { diff --git a/sdk/test/logs/logger_provider_sdk_test.cc b/sdk/test/logs/logger_provider_sdk_test.cc index 0ce2554e70..f18025c0ff 100644 --- a/sdk/test/logs/logger_provider_sdk_test.cc +++ b/sdk/test/logs/logger_provider_sdk_test.cc @@ -15,12 +15,12 @@ using namespace opentelemetry::sdk::logs; namespace logs_api = opentelemetry::logs; -namespace nostd = opentelemetry::nostd; +namespace nostd = opentelemetry::nostd; TEST(LoggerProviderSDK, PushToAPI) { auto lp = nostd::shared_ptr( - new opentelemetry::sdk::logs_api::LoggerProvider()); + new opentelemetry::sdk::logs::LoggerProvider()); logs_api::Provider::SetLoggerProvider(lp); // Check that the loggerprovider was correctly pushed into the API From 98d4f9faef50fec6246238531e5bff71c7eb7c6d Mon Sep 17 00:00:00 2001 From: PaurushGarg Date: Tue, 5 Oct 2021 09:09:15 -0700 Subject: [PATCH 05/16] Formatted files using format.sh --- api/test/common/kv_properties_test.cc | 4 +- api/test/logs/logger_test.cc | 5 +- api/test/metrics/meter_provider_test.cc | 5 +- api/test/nostd/utility_test.cc | 9 +-- api/test/trace/provider_test.cc | 9 +-- examples/batch/main.cc | 14 ++-- examples/grpc/server.cc | 2 +- examples/http/client.cc | 25 ++++--- examples/http/server.cc | 2 +- examples/metrics_simple/main.cc | 7 +- examples/multithreaded/main.cc | 5 +- examples/plugin/plugin/factory_impl.cc | 16 ++-- examples/plugin/plugin/tracer.cc | 9 +-- examples/zipkin/main.cc | 7 +- .../elasticsearch/src/es_log_exporter.cc | 3 +- .../jaeger/test/jaeger_recordable_test.cc | 10 +-- exporters/ostream/src/span_exporter.cc | 4 +- exporters/ostream/test/ostream_log_test.cc | 33 ++++---- .../ostream/test/ostream_metrics_test.cc | 53 ++++++------- exporters/ostream/test/ostream_span_test.cc | 67 ++++++++--------- exporters/otlp/src/otlp_http_exporter.cc | 13 ++-- exporters/otlp/src/otlp_recordable.cc | 31 +++----- .../otlp/test/otlp_grpc_exporter_benchmark.cc | 4 +- .../otlp/test/otlp_http_exporter_test.cc | 74 +++++++++--------- exporters/otlp/test/otlp_recordable_test.cc | 26 +++---- .../test/prometheus_collector_test.cc | 19 ++--- exporters/zipkin/src/recordable.cc | 15 ++-- .../zipkin/test/zipkin_recordable_test.cc | 10 +-- .../client/curl/http_client_factory_curl.cc | 6 +- ext/src/zpages/tracez_processor.cc | 3 +- ext/test/http/curl_http_test.cc | 25 +++---- ext/test/w3c_tracecontext_test/main.cc | 13 ++-- ext/test/zpages/threadsafe_span_data_test.cc | 5 +- .../zpages/tracez_data_aggregator_test.cc | 4 +- ext/test/zpages/tracez_processor_test.cc | 10 +-- sdk/src/logs/logger.cc | 29 ++++--- sdk/src/logs/logger_provider.cc | 12 ++- sdk/src/metrics/meter_provider.cc | 4 +- sdk/src/trace/random_id_generator.cc | 1 - sdk/src/trace/span.cc | 12 ++- sdk/src/trace/tracer_provider.cc | 2 +- sdk/test/logs/log_record_test.cc | 5 +- sdk/test/logs/logger_provider_sdk_test.cc | 4 +- sdk/test/logs/simple_log_processor_test.cc | 6 +- sdk/test/metrics/meter_test.cc | 4 +- sdk/test/metrics/ungrouped_processor_test.cc | 75 +++++++------------ sdk/test/resource/resource_test.cc | 12 +-- sdk/test/trace/always_off_sampler_test.cc | 1 - sdk/test/trace/parent_sampler_test.cc | 4 +- sdk/test/trace/span_data_test.cc | 27 +++---- sdk/test/trace/trace_id_ratio_sampler_test.cc | 2 +- sdk/test/trace/tracer_test.cc | 14 +--- 52 files changed, 318 insertions(+), 443 deletions(-) diff --git a/api/test/common/kv_properties_test.cc b/api/test/common/kv_properties_test.cc index 69fd795cb5..fb07c35b0f 100644 --- a/api/test/common/kv_properties_test.cc +++ b/api/test/common/kv_properties_test.cc @@ -218,10 +218,10 @@ TEST(KeyValueProperties, GetAllEntries) { std::vector> kv_pairs = { {"k1", "v1"}, {"k2", "v2"}, {"k3", "v3"}}; - const size_t kNumPairs = 3; + const size_t kNumPairs = 3; nostd::string_view keys[kNumPairs] = {"k1", "k2", "k3"}; nostd::string_view values[kNumPairs] = {"v1", "v2", "v3"}; - auto kv_properties = KeyValueProperties(kv_pairs); + auto kv_properties = KeyValueProperties(kv_pairs); size_t index = 0; kv_properties.GetAllEntries( diff --git a/api/test/logs/logger_test.cc b/api/test/logs/logger_test.cc index 0c5e9b2160..99c7474280 100644 --- a/api/test/logs/logger_test.cc +++ b/api/test/logs/logger_test.cc @@ -19,9 +19,8 @@ using opentelemetry::nostd::shared_ptr; using opentelemetry::nostd::span; using opentelemetry::nostd::string_view; namespace common = opentelemetry::common; -namespace nostd = opentelemetry::nostd; -namespace trace = opentelemetry::trace; - +namespace nostd = opentelemetry::nostd; +namespace trace = opentelemetry::trace; // Check that the default logger is a noop logger instance TEST(Logger, GetLoggerDefault) diff --git a/api/test/metrics/meter_provider_test.cc b/api/test/metrics/meter_provider_test.cc index 9a50406086..9e22d44cca 100644 --- a/api/test/metrics/meter_provider_test.cc +++ b/api/test/metrics/meter_provider_test.cc @@ -13,9 +13,8 @@ namespace nostd = opentelemetry::nostd; class TestProvider : public MeterProvider { - nostd::shared_ptr GetMeter( - nostd::string_view library_name, - nostd::string_view library_version) override + nostd::shared_ptr GetMeter(nostd::string_view library_name, + nostd::string_view library_version) override { return nostd::shared_ptr(nullptr); } diff --git a/api/test/nostd/utility_test.cc b/api/test/nostd/utility_test.cc index d81de1f980..821b2a70a4 100644 --- a/api/test/nostd/utility_test.cc +++ b/api/test/nostd/utility_test.cc @@ -50,10 +50,7 @@ TEST(UtilityTest, Size) TEST(UtilityTest, MakeIndexSequence) { - EXPECT_TRUE((std::is_same, - nostd::index_sequence<>>::value)); - EXPECT_TRUE((std::is_same, - nostd::index_sequence<0>>::value)); - EXPECT_TRUE((std::is_same, - nostd::index_sequence<0, 1>>::value)); + EXPECT_TRUE((std::is_same, nostd::index_sequence<>>::value)); + EXPECT_TRUE((std::is_same, nostd::index_sequence<0>>::value)); + EXPECT_TRUE((std::is_same, nostd::index_sequence<0, 1>>::value)); } diff --git a/api/test/trace/provider_test.cc b/api/test/trace/provider_test.cc index d3ef5874d5..3c4bd1e74e 100644 --- a/api/test/trace/provider_test.cc +++ b/api/test/trace/provider_test.cc @@ -10,14 +10,13 @@ using opentelemetry::trace::Provider; using opentelemetry::trace::Tracer; using opentelemetry::trace::TracerProvider; -namespace nostd = opentelemetry::nostd; +namespace nostd = opentelemetry::nostd; class TestProvider : public TracerProvider { - nostd::shared_ptr GetTracer( - nostd::string_view library_name, - nostd::string_view library_version, - nostd::string_view schema_url) override + nostd::shared_ptr GetTracer(nostd::string_view library_name, + nostd::string_view library_version, + nostd::string_view schema_url) override { return nostd::shared_ptr(nullptr); } diff --git a/examples/batch/main.cc b/examples/batch/main.cc index f03f58fb58..a435abebe5 100644 --- a/examples/batch/main.cc +++ b/examples/batch/main.cc @@ -10,9 +10,9 @@ #include #include -constexpr int kNumSpans = 10; -namespace trace_api = opentelemetry::trace; -namespace resource = opentelemetry::sdk::resource; +constexpr int kNumSpans = 10; +namespace trace_api = opentelemetry::trace; +namespace resource = opentelemetry::sdk::resource; namespace exporter_trace = opentelemetry::exporter::trace; namespace @@ -20,8 +20,7 @@ namespace void initTracer() { - auto exporter = std::unique_ptr( - new exporter_trace::OStreamSpanExporter); + auto exporter = std::unique_ptr(new exporter_trace::OStreamSpanExporter); // CONFIGURE BATCH SPAN PROCESSOR PARAMETERS @@ -34,9 +33,8 @@ void initTracer() // We export `kNumSpans` after every `schedule_delay_millis` milliseconds. options.max_export_batch_size = kNumSpans; - resource::ResourceAttributes attributes = {{"service", "test_service"}, - {"version", (uint32_t)1}}; - auto resource = resource::Resource::Create(attributes); + resource::ResourceAttributes attributes = {{"service", "test_service"}, {"version", (uint32_t)1}}; + auto resource = resource::Resource::Create(attributes); auto processor = std::unique_ptr( new sdktrace::BatchSpanProcessor(std::move(exporter), options)); diff --git a/examples/grpc/server.cc b/examples/grpc/server.cc index 472d429975..c7930ffd1a 100644 --- a/examples/grpc/server.cc +++ b/examples/grpc/server.cc @@ -58,7 +58,7 @@ class GreeterServer final : public Greeter::Service // extract context from grpc metadata GrpcServerCarrier carrier(context); - auto prop = context::propagation::GlobalTextMapPropagator::GetGlobalPropagator(); + auto prop = context::propagation::GlobalTextMapPropagator::GetGlobalPropagator(); auto current_ctx = context::RuntimeContext::GetCurrent(); auto new_context = prop->Extract(carrier, current_ctx); options.parent = GetSpan(new_context)->GetContext(); diff --git a/examples/http/client.cc b/examples/http/client.cc index 0a725a69c8..ec4f4dbfd5 100644 --- a/examples/http/client.cc +++ b/examples/http/client.cc @@ -11,8 +11,8 @@ namespace using namespace opentelemetry::trace; namespace http_client = opentelemetry::ext::http::client; -namespace context = opentelemetry::context; -namespace nostd = opentelemetry::nostd; +namespace context = opentelemetry::context; +namespace nostd = opentelemetry::nostd; void sendRequest(const std::string &url) { @@ -45,11 +45,11 @@ void sendRequest(const std::string &url) // set span attributes auto status_code = result.GetResponse().GetStatusCode(); span->SetAttribute(OTEL_CPP_GET_ATTR(AttrHttpStatusCode), status_code); - result.GetResponse().ForEachHeader([&span](nostd::string_view header_name, - nostd::string_view header_value) { - span->SetAttribute("http.header." + std::string(header_name.data()), header_value); - return true; - }); + result.GetResponse().ForEachHeader( + [&span](nostd::string_view header_name, nostd::string_view header_value) { + span->SetAttribute("http.header." + std::string(header_name.data()), header_value); + return true; + }); if (status_code >= 400) { @@ -58,11 +58,12 @@ void sendRequest(const std::string &url) } else { - span->SetStatus(StatusCode::kError, - "Response Status :" + - std::to_string(static_cast::type>( - result.GetSessionState()))); + span->SetStatus( + StatusCode::kError, + "Response Status :" + + std::to_string( + static_cast::type>( + result.GetSessionState()))); } // end span and export data span->End(); diff --git a/examples/http/server.cc b/examples/http/server.cc index eee8d5353d..82ff0eaf54 100644 --- a/examples/http/server.cc +++ b/examples/http/server.cc @@ -31,7 +31,7 @@ class RequestHandler : public HTTP_SERVER_NS::HttpRequestCallback // extract context from http header const HttpTextMapCarrier> carrier( (std::map &)request.headers); - auto prop = context::propagation::GlobalTextMapPropagator::GetGlobalPropagator(); + auto prop = context::propagation::GlobalTextMapPropagator::GetGlobalPropagator(); auto current_ctx = context::RuntimeContext::GetCurrent(); auto new_context = prop->Extract(carrier, current_ctx); options.parent = GetSpan(new_context)->GetContext(); diff --git a/examples/metrics_simple/main.cc b/examples/metrics_simple/main.cc index 3c093029b2..2babd38d19 100644 --- a/examples/metrics_simple/main.cc +++ b/examples/metrics_simple/main.cc @@ -15,7 +15,6 @@ namespace common = opentelemetry::common; namespace exportermetrics = opentelemetry::exporter::metrics; namespace metrics_api = opentelemetry::metrics; - int main() { // Initialize and set the global MeterProvider @@ -28,8 +27,7 @@ int main() // Create the controller with Stateless Metrics Processor sdkmetrics::PushController ControllerStateless( meter, - std::unique_ptr( - new exportermetrics::OStreamMetricsExporter), + std::unique_ptr(new exportermetrics::OStreamMetricsExporter), std::shared_ptr( new sdkmetrics::UngroupedMetricsProcessor(false)), .05); @@ -95,8 +93,7 @@ int main() // Do the same thing for stateful to see the difference sdkmetrics::PushController ControllerStateful( meter, - std::unique_ptr( - new exportermetrics::OStreamMetricsExporter), + std::unique_ptr(new exportermetrics::OStreamMetricsExporter), std::shared_ptr( new sdkmetrics::UngroupedMetricsProcessor(true)), .05); diff --git a/examples/multithreaded/main.cc b/examples/multithreaded/main.cc index 24514fc949..16823b21d4 100644 --- a/examples/multithreaded/main.cc +++ b/examples/multithreaded/main.cc @@ -23,9 +23,8 @@ void initTracer() new opentelemetry::exporter::trace::OStreamSpanExporter); auto processor = std::unique_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); - auto provider = - nostd::shared_ptr(new sdktrace::TracerProvider( - std::move(processor), opentelemetry::sdk::resource::Resource::Create({}))); + auto provider = nostd::shared_ptr(new sdktrace::TracerProvider( + std::move(processor), opentelemetry::sdk::resource::Resource::Create({}))); // Set the global trace provider trace_api::Provider::SetTracerProvider(provider); } diff --git a/examples/plugin/plugin/factory_impl.cc b/examples/plugin/plugin/factory_impl.cc index fd1504be60..b3bafe7053 100644 --- a/examples/plugin/plugin/factory_impl.cc +++ b/examples/plugin/plugin/factory_impl.cc @@ -5,8 +5,8 @@ #include "opentelemetry/plugin/hook.h" #include "tracer.h" -namespace nostd = opentelemetry::nostd; -namespace plugin = opentelemetry::plugin; +namespace nostd = opentelemetry::nostd; +namespace plugin = opentelemetry::plugin; class TracerHandle final : public plugin::TracerHandle { @@ -33,19 +33,17 @@ class FactoryImpl final : public plugin::Factory::FactoryImpl { return nullptr; } - return nostd::unique_ptr{new (std::nothrow) - TracerHandle{std::move(tracer)}}; + return nostd::unique_ptr{new (std::nothrow) TracerHandle{std::move(tracer)}}; } }; -static nostd::unique_ptr -MakeFactoryImpl(const plugin::LoaderInfo &loader_info, - nostd::unique_ptr &error_message) noexcept +static nostd::unique_ptr MakeFactoryImpl( + const plugin::LoaderInfo &loader_info, + nostd::unique_ptr &error_message) noexcept { (void)loader_info; (void)error_message; - return nostd::unique_ptr{ - new (std::nothrow) FactoryImpl{}}; + return nostd::unique_ptr{new (std::nothrow) FactoryImpl{}}; } OPENTELEMETRY_DEFINE_PLUGIN_HOOK(MakeFactoryImpl); diff --git a/examples/plugin/plugin/tracer.cc b/examples/plugin/plugin/tracer.cc index 212969af68..517575c947 100644 --- a/examples/plugin/plugin/tracer.cc +++ b/examples/plugin/plugin/tracer.cc @@ -65,11 +65,10 @@ class Span final : public trace::Span Tracer::Tracer(nostd::string_view /*output*/) {} -nostd::shared_ptr Tracer::StartSpan( - nostd::string_view name, - const common::KeyValueIterable &attributes, - const trace::SpanContextKeyValueIterable &links, - const trace::StartSpanOptions &options) noexcept +nostd::shared_ptr Tracer::StartSpan(nostd::string_view name, + const common::KeyValueIterable &attributes, + const trace::SpanContextKeyValueIterable &links, + const trace::StartSpanOptions &options) noexcept { return nostd::shared_ptr{ new (std::nothrow) Span{this->shared_from_this(), name, attributes, links, options}}; diff --git a/examples/zipkin/main.cc b/examples/zipkin/main.cc index 4ecf110c2a..376c6aeff1 100644 --- a/examples/zipkin/main.cc +++ b/examples/zipkin/main.cc @@ -12,7 +12,7 @@ namespace trace = opentelemetry::trace; namespace nostd = opentelemetry::nostd; namespace sdktrace = opentelemetry::sdk::trace; namespace zipkin = opentelemetry::exporter::zipkin; -namespace resource = opentelemetry::sdk::resource; +namespace resource = opentelemetry::sdk::resource; namespace { @@ -20,9 +20,8 @@ zipkin::ZipkinExporterOptions opts; void InitTracer() { // Create zipkin exporter instance - resource::ResourceAttributes attributes = { - {"service.name", "zipkin_demo_service"}}; - auto resource = resource::Resource::Create(attributes); + resource::ResourceAttributes attributes = {{"service.name", "zipkin_demo_service"}}; + auto resource = resource::Resource::Create(attributes); auto exporter = std::unique_ptr(new zipkin::ZipkinExporter(opts)); auto processor = std::unique_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); diff --git a/exporters/elasticsearch/src/es_log_exporter.cc b/exporters/elasticsearch/src/es_log_exporter.cc index 8d01c98248..1fbbcce807 100644 --- a/exporters/elasticsearch/src/es_log_exporter.cc +++ b/exporters/elasticsearch/src/es_log_exporter.cc @@ -70,8 +70,7 @@ class ResponseHandler : public http_client::EventHandler } // Callback method when an http event occurs - void OnEvent(http_client::SessionState state, - nostd::string_view reason) noexcept override + void OnEvent(http_client::SessionState state, nostd::string_view reason) noexcept override { // If any failure event occurs, release the condition variable to unblock main thread switch (state) diff --git a/exporters/jaeger/test/jaeger_recordable_test.cc b/exporters/jaeger/test/jaeger_recordable_test.cc index 075b09c642..48c2003a98 100644 --- a/exporters/jaeger/test/jaeger_recordable_test.cc +++ b/exporters/jaeger/test/jaeger_recordable_test.cc @@ -36,9 +36,8 @@ TEST(JaegerSpanRecordable, SetIdentity) const trace::SpanId parent_span_id( nostd::span(reinterpret_cast(&parent_span_id_val), 8)); - const trace::SpanContext span_context{ - trace_id, span_id, - trace::TraceFlags{trace::TraceFlags::kIsSampled}, true}; + const trace::SpanContext span_context{trace_id, span_id, + trace::TraceFlags{trace::TraceFlags::kIsSampled}, true}; rec.SetIdentity(span_context, parent_span_id); std::unique_ptr span{rec.Span()}; @@ -141,9 +140,8 @@ TEST(JaegerSpanRecordable, AddEvent) std::map attributes = { {keys[0], values[0]}, {keys[1], values[1]}, {keys[2], values[2]}}; - rec.AddEvent( - "Test Event", event_timestamp, - common::KeyValueIterableView>(attributes)); + rec.AddEvent("Test Event", event_timestamp, + common::KeyValueIterableView>(attributes)); thrift::Log log = rec.Logs().at(0); EXPECT_EQ(log.timestamp, epoch_us); auto tags = log.fields; diff --git a/exporters/ostream/src/span_exporter.cc b/exporters/ostream/src/span_exporter.cc index a83c31dfc4..df4c674424 100644 --- a/exporters/ostream/src/span_exporter.cc +++ b/exporters/ostream/src/span_exporter.cc @@ -5,8 +5,8 @@ #include -namespace nostd = opentelemetry::nostd; -namespace sdktrace = opentelemetry::sdk::trace; +namespace nostd = opentelemetry::nostd; +namespace sdktrace = opentelemetry::sdk::trace; namespace trace_api = opentelemetry::trace; OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/exporters/ostream/test/ostream_log_test.cc b/exporters/ostream/test/ostream_log_test.cc index 85b1c0b4ba..a21be32f29 100644 --- a/exporters/ostream/test/ostream_log_test.cc +++ b/exporters/ostream/test/ostream_log_test.cc @@ -13,12 +13,11 @@ # include # include -namespace sdklogs = opentelemetry::sdk::logs; -namespace logs_api = opentelemetry::logs; -namespace nostd = opentelemetry::nostd; -namespace exporterlogs = opentelemetry::exporter::logs; -namespace common = opentelemetry::common; - +namespace sdklogs = opentelemetry::sdk::logs; +namespace logs_api = opentelemetry::logs; +namespace nostd = opentelemetry::nostd; +namespace exporterlogs = opentelemetry::exporter::logs; +namespace common = opentelemetry::common; OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -29,8 +28,7 @@ namespace logs // Test that when OStream Log exporter is shutdown, no logs should be sent to stream TEST(OStreamLogExporter, Shutdown) { - auto exporter = - std::unique_ptr(new exporterlogs::OStreamLogExporter); + auto exporter = std::unique_ptr(new exporterlogs::OStreamLogExporter); // Save cout's original buffer here std::streambuf *original = std::cout.rdbuf(); @@ -58,8 +56,8 @@ TEST(OStreamLogExporter, Shutdown) // This function tests MakeRecordable() as well as Export(). TEST(OstreamLogExporter, DefaultLogRecordToCout) { - auto exporter = std::unique_ptr( - new exporterlogs::OStreamLogExporter(std::cout)); + auto exporter = + std::unique_ptr(new exporterlogs::OStreamLogExporter(std::cout)); // Save cout's original buffer here std::streambuf *original = std::cout.rdbuf(); @@ -97,8 +95,8 @@ TEST(OstreamLogExporter, DefaultLogRecordToCout) TEST(OStreamLogExporter, SimpleLogToCout) { // Initialize an Ostream exporter to std::cout - auto exporter = std::unique_ptr( - new exporterlogs::OStreamLogExporter(std::cout)); + auto exporter = + std::unique_ptr(new exporterlogs::OStreamLogExporter(std::cout)); // Save original stream buffer, then redirect cout to our new stream buffer std::streambuf *original = std::cout.rdbuf(); @@ -146,8 +144,8 @@ TEST(OStreamLogExporter, SimpleLogToCout) TEST(OStreamLogExporter, LogWithStringAttributesToCerr) { // Initialize an Ostream exporter to cerr - auto exporter = std::unique_ptr( - new exporterlogs::OStreamLogExporter(std::cerr)); + auto exporter = + std::unique_ptr(new exporterlogs::OStreamLogExporter(std::cerr)); // Save original stream buffer, then redirect cout to our new stream buffer std::streambuf *original = std::cerr.rdbuf(); @@ -193,8 +191,8 @@ TEST(OStreamLogExporter, LogWithVariantTypesToClog) { // Initialize an Ostream exporter to cerr - auto exporter = std::unique_ptr( - new exporterlogs::OStreamLogExporter(std::clog)); + auto exporter = + std::unique_ptr(new exporterlogs::OStreamLogExporter(std::clog)); // Save original stream buffer, then redirect cout to our new stream buffer std::streambuf *original = std::clog.rdbuf(); @@ -243,8 +241,7 @@ TEST(OStreamLogExporter, LogWithVariantTypesToClog) TEST(OStreamLogExporter, IntegrationTest) { // Initialize a logger - auto exporter = - std::unique_ptr(new exporterlogs::OStreamLogExporter); + auto exporter = std::unique_ptr(new exporterlogs::OStreamLogExporter); auto processor = std::shared_ptr(new sdklogs::SimpleLogProcessor(std::move(exporter))); auto sdkProvider = std::shared_ptr(new sdklogs::LoggerProvider()); diff --git a/exporters/ostream/test/ostream_metrics_test.cc b/exporters/ostream/test/ostream_metrics_test.cc index 2891c0e822..69d4a8ef00 100644 --- a/exporters/ostream/test/ostream_metrics_test.cc +++ b/exporters/ostream/test/ostream_metrics_test.cc @@ -15,19 +15,18 @@ # include -namespace sdkmetrics = opentelemetry::sdk::metrics; -namespace metrics_api = opentelemetry::metrics; -namespace nostd = opentelemetry::nostd; -namespace exportermetrics = opentelemetry::exporter::metrics; +namespace sdkmetrics = opentelemetry::sdk::metrics; +namespace metrics_api = opentelemetry::metrics; +namespace nostd = opentelemetry::nostd; +namespace exportermetrics = opentelemetry::exporter::metrics; TEST(OStreamMetricsExporter, PrintCounter) { - auto exporter = std::unique_ptr( - new exportermetrics::OStreamMetricsExporter); + auto exporter = + std::unique_ptr(new exportermetrics::OStreamMetricsExporter); auto aggregator = std::shared_ptr>( - new sdkmetrics::CounterAggregator( - metrics_api::InstrumentKind::Counter)); + new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(5.5); aggregator->checkpoint(); @@ -62,12 +61,11 @@ TEST(OStreamMetricsExporter, PrintCounter) TEST(OStreamMetricsExporter, PrintMinMaxSumCount) { - auto exporter = std::unique_ptr( - new exportermetrics::OStreamMetricsExporter); + auto exporter = + std::unique_ptr(new exportermetrics::OStreamMetricsExporter); auto aggregator = std::shared_ptr>( - new sdkmetrics::MinMaxSumCountAggregator( - metrics_api::InstrumentKind::Counter)); + new sdkmetrics::MinMaxSumCountAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(1); aggregator->update(2); @@ -106,12 +104,11 @@ TEST(OStreamMetricsExporter, PrintMinMaxSumCount) TEST(OStreamMetricsExporter, PrintGauge) { - auto exporter = std::unique_ptr( - new exportermetrics::OStreamMetricsExporter); + auto exporter = + std::unique_ptr(new exportermetrics::OStreamMetricsExporter); auto aggregator = std::shared_ptr>( - new sdkmetrics::GaugeAggregator( - metrics_api::InstrumentKind::Counter)); + new sdkmetrics::GaugeAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(1); aggregator->update(9); @@ -150,16 +147,14 @@ TEST(OStreamMetricsExporter, PrintGauge) TEST(OStreamMetricsExporter, PrintExact) { - auto exporter = std::unique_ptr( - new exportermetrics::OStreamMetricsExporter); + auto exporter = + std::unique_ptr(new exportermetrics::OStreamMetricsExporter); auto aggregator = std::shared_ptr>( - new sdkmetrics::ExactAggregator(metrics_api::InstrumentKind::Counter, - true)); + new sdkmetrics::ExactAggregator(metrics_api::InstrumentKind::Counter, true)); auto aggregator2 = std::shared_ptr>( - new sdkmetrics::ExactAggregator(metrics_api::InstrumentKind::Counter, - false)); + new sdkmetrics::ExactAggregator(metrics_api::InstrumentKind::Counter, false)); for (int i = 0; i < 10; i++) { @@ -207,13 +202,12 @@ TEST(OStreamMetricsExporter, PrintExact) TEST(OStreamMetricsExporter, PrintHistogram) { - auto exporter = std::unique_ptr( - new exportermetrics::OStreamMetricsExporter); + auto exporter = + std::unique_ptr(new exportermetrics::OStreamMetricsExporter); std::vector boundaries{10, 20, 30, 40, 50}; auto aggregator = std::shared_ptr>( - new sdkmetrics::HistogramAggregator( - metrics_api::InstrumentKind::Counter, boundaries)); + new sdkmetrics::HistogramAggregator(metrics_api::InstrumentKind::Counter, boundaries)); for (float i = 0; i < 60; i++) { @@ -252,13 +246,12 @@ TEST(OStreamMetricsExporter, PrintHistogram) TEST(OStreamMetricsExporter, PrintSketch) { - auto exporter = std::unique_ptr( - new exportermetrics::OStreamMetricsExporter); + auto exporter = + std::unique_ptr(new exportermetrics::OStreamMetricsExporter); std::vector boundaries{1, 3, 5, 7, 9}; auto aggregator = std::shared_ptr>( - new sdkmetrics::SketchAggregator(metrics_api::InstrumentKind::Counter, - .000005)); + new sdkmetrics::SketchAggregator(metrics_api::InstrumentKind::Counter, .000005)); for (int i = 0; i < 10; i++) { diff --git a/exporters/ostream/test/ostream_span_test.cc b/exporters/ostream/test/ostream_span_test.cc index 4ffd1b1feb..1ebe898b26 100644 --- a/exporters/ostream/test/ostream_span_test.cc +++ b/exporters/ostream/test/ostream_span_test.cc @@ -19,11 +19,11 @@ using namespace opentelemetry::exporter::ostream::test; -namespace trace = opentelemetry::trace; -namespace common = opentelemetry::common; -namespace nostd = opentelemetry::nostd; -namespace sdktrace = opentelemetry::sdk::trace; -namespace resource = opentelemetry::sdk::resource; +namespace trace = opentelemetry::trace; +namespace common = opentelemetry::common; +namespace nostd = opentelemetry::nostd; +namespace sdktrace = opentelemetry::sdk::trace; +namespace resource = opentelemetry::sdk::resource; namespace exportertrace = opentelemetry::exporter::trace; using Attributes = std::initializer_list>; @@ -39,8 +39,7 @@ class TestResource : public resource::Resource // Testing Shutdown functionality of OStreamSpanExporter, should expect no data to be sent to Stream TEST(OStreamSpanExporter, Shutdown) { - auto exporter = std::unique_ptr( - new exportertrace::OStreamSpanExporter); + auto exporter = std::unique_ptr(new exportertrace::OStreamSpanExporter); auto processor = std::shared_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); @@ -79,8 +78,8 @@ constexpr const char *kDefaultSpanPrinted = TEST(OStreamSpanExporter, PrintDefaultSpan) { std::stringstream output; - auto exporter = std::unique_ptr( - new exportertrace::OStreamSpanExporter(output)); + auto exporter = + std::unique_ptr(new exportertrace::OStreamSpanExporter(output)); auto processor = std::shared_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); @@ -94,8 +93,8 @@ TEST(OStreamSpanExporter, PrintDefaultSpan) TEST(OStreamSpanExporter, PrintSpanWithBasicFields) { std::stringstream output; - auto exporter = std::unique_ptr( - new exportertrace::OStreamSpanExporter(output)); + auto exporter = + std::unique_ptr(new exportertrace::OStreamSpanExporter(output)); auto processor = std::shared_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); @@ -109,9 +108,7 @@ TEST(OStreamSpanExporter, PrintSpanWithBasicFields) trace::SpanId parent_span_id{parent_span_id_buf}; const auto trace_state = trace::TraceState::GetDefault()->Set("state1", "value"); const trace::SpanContext span_context{ - trace_id, span_id, - trace::TraceFlags{trace::TraceFlags::kIsSampled}, true, - trace_state}; + trace_id, span_id, trace::TraceFlags{trace::TraceFlags::kIsSampled}, true, trace_state}; recordable->SetIdentity(span_context, parent_span_id); recordable->SetName("Test Span"); @@ -155,8 +152,8 @@ TEST(OStreamSpanExporter, PrintSpanWithBasicFields) TEST(OStreamSpanExporter, PrintSpanWithAttribute) { std::stringstream output; - auto exporter = std::unique_ptr( - new exportertrace::OStreamSpanExporter(output)); + auto exporter = + std::unique_ptr(new exportertrace::OStreamSpanExporter(output)); auto processor = std::shared_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); @@ -191,8 +188,8 @@ TEST(OStreamSpanExporter, PrintSpanWithAttribute) TEST(OStreamSpanExporter, PrintSpanWithArrayAttribute) { std::stringstream output; - auto exporter = std::unique_ptr( - new exportertrace::OStreamSpanExporter(output)); + auto exporter = + std::unique_ptr(new exportertrace::OStreamSpanExporter(output)); auto processor = std::shared_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); @@ -229,15 +226,14 @@ TEST(OStreamSpanExporter, PrintSpanWithArrayAttribute) TEST(OStreamSpanExporter, PrintSpanWithEvents) { std::stringstream output; - auto exporter = std::unique_ptr( - new exportertrace::OStreamSpanExporter(output)); + auto exporter = + std::unique_ptr(new exportertrace::OStreamSpanExporter(output)); auto processor = std::shared_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); auto recordable = processor->MakeRecordable(); common::SystemTimestamp now(std::chrono::system_clock::now()); - common::SystemTimestamp next(std::chrono::system_clock::now() + - std::chrono::seconds(1)); + common::SystemTimestamp next(std::chrono::system_clock::now() + std::chrono::seconds(1)); std::string now_str = std::to_string(now.time_since_epoch().count()); std::string next_str = std::to_string(next.time_since_epoch().count()); @@ -287,8 +283,8 @@ TEST(OStreamSpanExporter, PrintSpanWithEvents) TEST(OStreamSpanExporter, PrintSpanWithLinks) { std::stringstream output; - auto exporter = std::unique_ptr( - new exportertrace::OStreamSpanExporter(output)); + auto exporter = + std::unique_ptr(new exportertrace::OStreamSpanExporter(output)); auto processor = std::shared_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); @@ -303,19 +299,17 @@ TEST(OStreamSpanExporter, PrintSpanWithLinks) 2, }; trace::TraceId trace_id{trace_id_buf}; - const auto span_context = trace::SpanContext( - trace_id, span_id, - trace::TraceFlags{trace::TraceFlags::kIsSampled}, true); + const auto span_context = + trace::SpanContext(trace_id, span_id, trace::TraceFlags{trace::TraceFlags::kIsSampled}, true); // and another to check preserving order. uint8_t span_id_buf2[trace::SpanId::kSize] = { 3, }; trace::SpanId span_id2{span_id_buf2}; - const auto span_context2 = trace::SpanContext( - trace_id, span_id2, - trace::TraceFlags{trace::TraceFlags::kIsSampled}, true, - trace::TraceState::FromHeader("state1=value")); + const auto span_context2 = + trace::SpanContext(trace_id, span_id2, trace::TraceFlags{trace::TraceFlags::kIsSampled}, true, + trace::TraceState::FromHeader("state1=value")); recordable->AddLink(span_context); recordable->AddLink(span_context2, @@ -360,8 +354,7 @@ TEST(OStreamSpanExporter, PrintSpanWithLinks) // Test with the three common ostreams, tests are more of a sanity check and usage examples. TEST(OStreamSpanExporter, PrintSpanToCout) { - auto exporter = std::unique_ptr( - new exportertrace::OStreamSpanExporter); + auto exporter = std::unique_ptr(new exportertrace::OStreamSpanExporter); auto processor = std::shared_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); @@ -375,8 +368,8 @@ TEST(OStreamSpanExporter, PrintSpanToCout) TEST(OStreamSpanExporter, PrintSpanToCerr) { - auto exporter = std::unique_ptr( - new exportertrace::OStreamSpanExporter(std::cerr)); + auto exporter = + std::unique_ptr(new exportertrace::OStreamSpanExporter(std::cerr)); auto processor = std::shared_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); @@ -390,8 +383,8 @@ TEST(OStreamSpanExporter, PrintSpanToCerr) TEST(OStreamSpanExporter, PrintSpanToClog) { - auto exporter = std::unique_ptr( - new exportertrace::OStreamSpanExporter(std::clog)); + auto exporter = + std::unique_ptr(new exportertrace::OStreamSpanExporter(std::clog)); auto processor = std::shared_ptr( new sdktrace::SimpleSpanProcessor(std::move(exporter))); diff --git a/exporters/otlp/src/otlp_http_exporter.cc b/exporters/otlp/src/otlp_http_exporter.cc index 973a2714b0..cc618d755f 100644 --- a/exporters/otlp/src/otlp_http_exporter.cc +++ b/exporters/otlp/src/otlp_http_exporter.cc @@ -71,11 +71,11 @@ class ResponseHandler : public http_client::EventHandler { std::stringstream ss; ss << "[OTLP HTTP Exporter] Status:" << response.GetStatusCode() << "Header:"; - response.ForEachHeader([&ss](nostd::string_view header_name, - nostd::string_view header_value) { - ss << "\t" << header_name.data() << " : " << header_value.data() << ","; - return true; - }); + response.ForEachHeader( + [&ss](nostd::string_view header_name, nostd::string_view header_value) { + ss << "\t" << header_name.data() << " : " << header_value.data() << ","; + return true; + }); ss << "Body:" << body_; OTEL_INTERNAL_LOG_DEBUG(ss.str()); } @@ -108,8 +108,7 @@ class ResponseHandler : public http_client::EventHandler } // Callback method when an http event occurs - void OnEvent(http_client::SessionState state, - nostd::string_view reason) noexcept override + void OnEvent(http_client::SessionState state, nostd::string_view reason) noexcept override { // If any failure event occurs, release the condition variable to unblock main thread switch (state) diff --git a/exporters/otlp/src/otlp_recordable.cc b/exporters/otlp/src/otlp_recordable.cc index da3cc0103c..778da7fd0d 100644 --- a/exporters/otlp/src/otlp_recordable.cc +++ b/exporters/otlp/src/otlp_recordable.cc @@ -9,11 +9,11 @@ namespace exporter namespace otlp { -namespace trace = opentelemetry::trace; -namespace nostd = opentelemetry::nostd; -namespace proto = opentelemetry::proto; +namespace trace = opentelemetry::trace; +namespace nostd = opentelemetry::nostd; +namespace proto = opentelemetry::proto; namespace common = opentelemetry::common; - + // // See `attribute_value.h` for details. // @@ -38,9 +38,8 @@ void PopulateAttribute(proto::common::v1::KeyValue *attribute, { // Assert size of variant to ensure that this method gets updated if the variant // definition changes - static_assert( - nostd::variant_size::value == kAttributeValueSize, - "AttributeValue contains unknown type"); + static_assert(nostd::variant_size::value == kAttributeValueSize, + "AttributeValue contains unknown type"); attribute->set_key(key.data(), key.size()); @@ -340,34 +339,28 @@ void OtlpRecordable::SetSpanKind(trace::SpanKind span_kind) noexcept { case trace::SpanKind::kInternal: - proto_span_kind = - proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_INTERNAL; + proto_span_kind = proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_INTERNAL; break; case trace::SpanKind::kServer: - proto_span_kind = - proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_SERVER; + proto_span_kind = proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_SERVER; break; case trace::SpanKind::kClient: - proto_span_kind = - proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_CLIENT; + proto_span_kind = proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_CLIENT; break; case trace::SpanKind::kProducer: - proto_span_kind = - proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_PRODUCER; + proto_span_kind = proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_PRODUCER; break; case trace::SpanKind::kConsumer: - proto_span_kind = - proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_CONSUMER; + proto_span_kind = proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_CONSUMER; break; default: // shouldn't reach here. - proto_span_kind = - proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_UNSPECIFIED; + proto_span_kind = proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_UNSPECIFIED; } span_.set_kind(proto_span_kind); diff --git a/exporters/otlp/test/otlp_grpc_exporter_benchmark.cc b/exporters/otlp/test/otlp_grpc_exporter_benchmark.cc index b2d37738f2..ec90556e88 100644 --- a/exporters/otlp/test/otlp_grpc_exporter_benchmark.cc +++ b/exporters/otlp/test/otlp_grpc_exporter_benchmark.cc @@ -26,9 +26,7 @@ const trace::SpanId kParentSpanId(std::array Set("key1", "value"); const trace_api::SpanContext kSpanContext{ - kTraceId, kSpanId, - trace_api::TraceFlags{trace_api::TraceFlags::kIsSampled}, true, - kTraceState}; + kTraceId, kSpanId, trace_api::TraceFlags{trace_api::TraceFlags::kIsSampled}, true, kTraceState}; // ----------------------- Helper classes and functions ------------------------ diff --git a/exporters/otlp/test/otlp_http_exporter_test.cc b/exporters/otlp/test/otlp_http_exporter_test.cc index d8e5940af5..56c6d9c6cf 100644 --- a/exporters/otlp/test/otlp_http_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_exporter_test.cc @@ -33,7 +33,7 @@ namespace otlp { namespace trace_api = opentelemetry::trace; -namespace resource = opentelemetry::sdk::resource; +namespace resource = opentelemetry::sdk::resource; template static nostd::span MakeSpan(T (&array)[N]) @@ -190,21 +190,21 @@ TEST_F(OtlpHttpExporterTestPeer, ExportJsonIntegrationTest) size_t old_count = getCurrentRequestCount(); auto exporter = GetExporter(HttpRequestContentType::kJson); - resource::ResourceAttributes resource_attributes = { - {"service.name", "unit_test_service"}, {"tenant.id", "test_user"}}; - resource_attributes["bool_value"] = true; - resource_attributes["int32_value"] = static_cast(1); - resource_attributes["uint32_value"] = static_cast(2); - resource_attributes["int64_value"] = static_cast(0x1100000000LL); - resource_attributes["uint64_value"] = static_cast(0x1200000000ULL); - resource_attributes["double_value"] = static_cast(3.1); - resource_attributes["vec_bool_value"] = std::vector{true, false, true}; - resource_attributes["vec_int32_value"] = std::vector{1, 2}; - resource_attributes["vec_uint32_value"] = std::vector{3, 4}; - resource_attributes["vec_int64_value"] = std::vector{5, 6}; - resource_attributes["vec_uint64_value"] = std::vector{7, 8}; - resource_attributes["vec_double_value"] = std::vector{3.2, 3.3}; - resource_attributes["vec_string_value"] = std::vector{"vector", "string"}; + resource::ResourceAttributes resource_attributes = {{"service.name", "unit_test_service"}, + {"tenant.id", "test_user"}}; + resource_attributes["bool_value"] = true; + resource_attributes["int32_value"] = static_cast(1); + resource_attributes["uint32_value"] = static_cast(2); + resource_attributes["int64_value"] = static_cast(0x1100000000LL); + resource_attributes["uint64_value"] = static_cast(0x1200000000ULL); + resource_attributes["double_value"] = static_cast(3.1); + resource_attributes["vec_bool_value"] = std::vector{true, false, true}; + resource_attributes["vec_int32_value"] = std::vector{1, 2}; + resource_attributes["vec_uint32_value"] = std::vector{3, 4}; + resource_attributes["vec_int64_value"] = std::vector{5, 6}; + resource_attributes["vec_uint64_value"] = std::vector{7, 8}; + resource_attributes["vec_double_value"] = std::vector{3.2, 3.3}; + resource_attributes["vec_string_value"] = std::vector{"vector", "string"}; auto resource = resource::Resource::Create(resource_attributes); auto processor_opts = sdk::trace::BatchSpanProcessorOptions(); @@ -219,11 +219,11 @@ TEST_F(OtlpHttpExporterTestPeer, ExportJsonIntegrationTest) std::string report_trace_id; { char trace_id_hex[2 * trace_api::TraceId::kSize] = {0}; - auto tracer = provider->GetTracer("test"); - auto parent_span = tracer->StartSpan("Test parent span"); + auto tracer = provider->GetTracer("test"); + auto parent_span = tracer->StartSpan("Test parent span"); trace_api::StartSpanOptions child_span_opts = {}; - child_span_opts.parent = parent_span->GetContext(); + child_span_opts.parent = parent_span->GetContext(); auto child_span = tracer->StartSpan("Test child span", child_span_opts); child_span->End(); @@ -251,21 +251,21 @@ TEST_F(OtlpHttpExporterTestPeer, ExportBinaryIntegrationTest) auto exporter = GetExporter(HttpRequestContentType::kBinary); - resource::ResourceAttributes resource_attributes = { - {"service.name", "unit_test_service"}, {"tenant.id", "test_user"}}; - resource_attributes["bool_value"] = true; - resource_attributes["int32_value"] = static_cast(1); - resource_attributes["uint32_value"] = static_cast(2); - resource_attributes["int64_value"] = static_cast(0x1100000000LL); - resource_attributes["uint64_value"] = static_cast(0x1200000000ULL); - resource_attributes["double_value"] = static_cast(3.1); - resource_attributes["vec_bool_value"] = std::vector{true, false, true}; - resource_attributes["vec_int32_value"] = std::vector{1, 2}; - resource_attributes["vec_uint32_value"] = std::vector{3, 4}; - resource_attributes["vec_int64_value"] = std::vector{5, 6}; - resource_attributes["vec_uint64_value"] = std::vector{7, 8}; - resource_attributes["vec_double_value"] = std::vector{3.2, 3.3}; - resource_attributes["vec_string_value"] = std::vector{"vector", "string"}; + resource::ResourceAttributes resource_attributes = {{"service.name", "unit_test_service"}, + {"tenant.id", "test_user"}}; + resource_attributes["bool_value"] = true; + resource_attributes["int32_value"] = static_cast(1); + resource_attributes["uint32_value"] = static_cast(2); + resource_attributes["int64_value"] = static_cast(0x1100000000LL); + resource_attributes["uint64_value"] = static_cast(0x1200000000ULL); + resource_attributes["double_value"] = static_cast(3.1); + resource_attributes["vec_bool_value"] = std::vector{true, false, true}; + resource_attributes["vec_int32_value"] = std::vector{1, 2}; + resource_attributes["vec_uint32_value"] = std::vector{3, 4}; + resource_attributes["vec_int64_value"] = std::vector{5, 6}; + resource_attributes["vec_uint64_value"] = std::vector{7, 8}; + resource_attributes["vec_double_value"] = std::vector{3.2, 3.3}; + resource_attributes["vec_string_value"] = std::vector{"vector", "string"}; auto resource = resource::Resource::Create(resource_attributes); auto processor_opts = sdk::trace::BatchSpanProcessorOptions(); @@ -281,11 +281,11 @@ TEST_F(OtlpHttpExporterTestPeer, ExportBinaryIntegrationTest) std::string report_trace_id; { uint8_t trace_id_binary[trace_api::TraceId::kSize] = {0}; - auto tracer = provider->GetTracer("test"); - auto parent_span = tracer->StartSpan("Test parent span"); + auto tracer = provider->GetTracer("test"); + auto parent_span = tracer->StartSpan("Test parent span"); trace_api::StartSpanOptions child_span_opts = {}; - child_span_opts.parent = parent_span->GetContext(); + child_span_opts.parent = parent_span->GetContext(); auto child_span = tracer->StartSpan("Test child span", child_span_opts); child_span->End(); diff --git a/exporters/otlp/test/otlp_recordable_test.cc b/exporters/otlp/test/otlp_recordable_test.cc index 2669482ad3..3c98e16491 100644 --- a/exporters/otlp/test/otlp_recordable_test.cc +++ b/exporters/otlp/test/otlp_recordable_test.cc @@ -11,8 +11,8 @@ namespace otlp { namespace trace_api = opentelemetry::trace; namespace trace_sdk = opentelemetry::sdk::trace; -namespace resource = opentelemetry::sdk::resource; -namespace proto = opentelemetry::proto; +namespace resource = opentelemetry::sdk::resource; +namespace proto = opentelemetry::proto; TEST(OtlpRecordable, SetIdentity) { @@ -24,8 +24,7 @@ TEST(OtlpRecordable, SetIdentity) trace_api::SpanId parent_span_id{parent_span_id_buf}; const auto trace_state = trace_api::TraceState::GetDefault()->Set("key1", "value"); const trace_api::SpanContext span_context{ - trace_id, span_id, - trace_api::TraceFlags{trace_api::TraceFlags::kIsSampled}, true, + trace_id, span_id, trace_api::TraceFlags{trace_api::TraceFlags::kIsSampled}, true, trace_state}; OtlpRecordable rec; @@ -54,8 +53,7 @@ TEST(OtlpRecordable, SetSpanKind) OtlpRecordable rec; trace_api::SpanKind span_kind = trace_api::SpanKind::kServer; rec.SetSpanKind(span_kind); - EXPECT_EQ(rec.span().kind(), - proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_SERVER); + EXPECT_EQ(rec.span().kind(), proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_SERVER); } TEST(OtlpRecordable, SetInstrumentationLibrary) @@ -72,8 +70,7 @@ TEST(OtlpRecordable, SetInstrumentationLibraryWithSchemaURL) { OtlpRecordable rec; const std::string expected_schema_url{"https://opentelemetry.io/schemas/1.2.0"}; - auto inst_lib = - trace_sdk::InstrumentationLibrary::Create("test", "v1", expected_schema_url); + auto inst_lib = trace_sdk::InstrumentationLibrary::Create("test", "v1", expected_schema_url); rec.SetInstrumentationLibrary(*inst_lib); EXPECT_EQ(expected_schema_url, rec.GetInstrumentationLibrarySchemaURL()); } @@ -113,15 +110,13 @@ TEST(OtlpRecordable, SetStatus) nostd::string_view description = "For test"; rec1.SetStatus(code_error, description); - EXPECT_EQ(rec1.span().status().code(), - proto::trace::v1::Status_StatusCode(code_error)); + EXPECT_EQ(rec1.span().status().code(), proto::trace::v1::Status_StatusCode(code_error)); EXPECT_EQ(rec1.span().status().message(), description); OtlpRecordable rec2; trace::StatusCode code_ok(trace::StatusCode::kOk); rec2.SetStatus(code_ok, description); - EXPECT_EQ(rec2.span().status().code(), - proto::trace::v1::Status_StatusCode(code_ok)); + EXPECT_EQ(rec2.span().status().code(), proto::trace::v1::Status_StatusCode(code_ok)); EXPECT_EQ(rec2.span().status().message(), ""); } @@ -196,8 +191,7 @@ TEST(OtlpRecordable, SetResource) OtlpRecordable rec; const std::string service_name_key = "service.name"; std::string service_name = "test-otlp"; - auto resource = - resource::Resource::Create({{service_name_key, service_name}}); + auto resource = resource::Resource::Create({{service_name_key, service_name}}); rec.SetResource(resource); auto proto_resource = rec.ProtoResource(); @@ -219,8 +213,8 @@ TEST(OtlpRecordable, SetResourceWithSchemaURL) const std::string service_name_key = "service.name"; const std::string service_name = "test-otlp"; const std::string expected_schema_url = "https://opentelemetry.io/schemas/1.2.0"; - auto resource = resource::Resource::Create({{service_name_key, service_name}}, - expected_schema_url); + auto resource = + resource::Resource::Create({{service_name_key, service_name}}, expected_schema_url); rec.SetResource(resource); EXPECT_EQ(expected_schema_url, rec.GetResourceSchemaURL()); diff --git a/exporters/prometheus/test/prometheus_collector_test.cc b/exporters/prometheus/test/prometheus_collector_test.cc index 1c202a1f6e..52d98b11d7 100644 --- a/exporters/prometheus/test/prometheus_collector_test.cc +++ b/exporters/prometheus/test/prometheus_collector_test.cc @@ -22,7 +22,6 @@ using opentelemetry::exporter::prometheus::PrometheusCollector; namespace metric_api = opentelemetry::metrics; - OPENTELEMETRY_BEGIN_NAMESPACE /** @@ -42,9 +41,8 @@ std::shared_ptr> CreateAgg(metric_sdk::AggregatorKind break; } case metric_sdk::AggregatorKind::MinMaxSumCount: { - aggregator = - std::shared_ptr>(new metric_sdk::MinMaxSumCountAggregator( - metric_api::InstrumentKind::Counter)); + aggregator = std::shared_ptr>( + new metric_sdk::MinMaxSumCountAggregator(metric_api::InstrumentKind::Counter)); break; } case metric_sdk::AggregatorKind::Gauge: { @@ -53,20 +51,19 @@ std::shared_ptr> CreateAgg(metric_sdk::AggregatorKind break; } case metric_sdk::AggregatorKind::Sketch: { - aggregator = std::shared_ptr>(new metric_sdk::SketchAggregator( - metric_api::InstrumentKind::Counter, 0.000005)); + aggregator = std::shared_ptr>( + new metric_sdk::SketchAggregator(metric_api::InstrumentKind::Counter, 0.000005)); break; } case metric_sdk::AggregatorKind::Histogram: { std::vector boundaries{10, 20}; - aggregator = - std::shared_ptr>(new metric_sdk::HistogramAggregator( - metric_api::InstrumentKind::Counter, boundaries)); + aggregator = std::shared_ptr>( + new metric_sdk::HistogramAggregator(metric_api::InstrumentKind::Counter, boundaries)); break; } case metric_sdk::AggregatorKind::Exact: { - aggregator = std::shared_ptr>(new metric_sdk::ExactAggregator( - metric_api::InstrumentKind::Counter, exactMode)); + aggregator = std::shared_ptr>( + new metric_sdk::ExactAggregator(metric_api::InstrumentKind::Counter, exactMode)); break; } default: diff --git a/exporters/zipkin/src/recordable.cc b/exporters/zipkin/src/recordable.cc index d4b2d515fc..0e2f55cd6d 100644 --- a/exporters/zipkin/src/recordable.cc +++ b/exporters/zipkin/src/recordable.cc @@ -15,8 +15,8 @@ namespace zipkin using namespace opentelemetry::sdk::resource; namespace trace_api = opentelemetry::trace; -namespace common = opentelemetry::common; -namespace sdk = opentelemetry::sdk; +namespace common = opentelemetry::common; +namespace sdk = opentelemetry::sdk; // constexpr needs keys to be constexpr, const is next best to use. static const std::map kSpanKindMap = { @@ -55,9 +55,8 @@ void PopulateAttribute(nlohmann::json &attribute, { // Assert size of variant to ensure that this method gets updated if the variant // definition changes - static_assert( - nostd::variant_size::value == kAttributeValueSize, - "AttributeValue contains unknown type"); + static_assert(nostd::variant_size::value == kAttributeValueSize, + "AttributeValue contains unknown type"); if (nostd::holds_alternative(value)) { @@ -158,8 +157,7 @@ void PopulateAttribute(nlohmann::json &attribute, } } -void Recordable::SetAttribute(nostd::string_view key, - const common::AttributeValue &value) noexcept +void Recordable::SetAttribute(nostd::string_view key, const common::AttributeValue &value) noexcept { if (!span_.contains("tags")) { @@ -245,8 +243,7 @@ void Recordable::SetSpanKind(trace_api::SpanKind span_kind) noexcept } void Recordable::SetInstrumentationLibrary( - const sdk::instrumentationlibrary::InstrumentationLibrary - &instrumentation_library) noexcept + const sdk::instrumentationlibrary::InstrumentationLibrary &instrumentation_library) noexcept { span_["tags"]["otel.library.name"] = instrumentation_library.GetName(); span_["tags"]["otel.library.version"] = instrumentation_library.GetVersion(); diff --git a/exporters/zipkin/test/zipkin_recordable_test.cc b/exporters/zipkin/test/zipkin_recordable_test.cc index 315069b3da..967aebaaba 100644 --- a/exporters/zipkin/test/zipkin_recordable_test.cc +++ b/exporters/zipkin/test/zipkin_recordable_test.cc @@ -37,9 +37,8 @@ TEST(ZipkinSpanRecordable, SetIdentity) const trace::SpanId parent_span_id( std::array({0, 0, 0, 0, 0, 0, 0, 3})); - const trace::SpanContext span_context{ - trace_id, span_id, - trace::TraceFlags{trace::TraceFlags::kIsSampled}, true}; + const trace::SpanContext span_context{trace_id, span_id, + trace::TraceFlags{trace::TraceFlags::kIsSampled}, true}; rec.SetIdentity(span_context, parent_span_id); EXPECT_EQ(rec.span(), j_span); @@ -60,9 +59,8 @@ TEST(ZipkinSpanRecordable, SetIdentityEmptyParent) const trace::SpanId parent_span_id( std::array({0, 0, 0, 0, 0, 0, 0, 0})); - const trace::SpanContext span_context{ - trace_id, span_id, - trace::TraceFlags{trace::TraceFlags::kIsSampled}, true}; + const trace::SpanContext span_context{trace_id, span_id, + trace::TraceFlags{trace::TraceFlags::kIsSampled}, true}; rec.SetIdentity(span_context, parent_span_id); EXPECT_EQ(rec.span(), j_span); diff --git a/ext/src/http/client/curl/http_client_factory_curl.cc b/ext/src/http/client/curl/http_client_factory_curl.cc index 8d2da108f1..262dfde63c 100644 --- a/ext/src/http/client/curl/http_client_factory_curl.cc +++ b/ext/src/http/client/curl/http_client_factory_curl.cc @@ -7,14 +7,12 @@ namespace http_client = opentelemetry::ext::http::client; -std::shared_ptr -http_client::HttpClientFactory::Create() +std::shared_ptr http_client::HttpClientFactory::Create() { return std::make_shared(); } -std::shared_ptr -http_client::HttpClientFactory::CreateSync() +std::shared_ptr http_client::HttpClientFactory::CreateSync() { return std::make_shared(); } \ No newline at end of file diff --git a/ext/src/zpages/tracez_processor.cc b/ext/src/zpages/tracez_processor.cc index 8054274e8d..1e9115eb98 100644 --- a/ext/src/zpages/tracez_processor.cc +++ b/ext/src/zpages/tracez_processor.cc @@ -16,8 +16,7 @@ void TracezSpanProcessor::OnStart(trace_sdk::Recordable &span, shared_data_->OnStart(static_cast(&span)); } -void TracezSpanProcessor::OnEnd( - std::unique_ptr &&span) noexcept +void TracezSpanProcessor::OnEnd(std::unique_ptr &&span) noexcept { shared_data_->OnEnd( std::unique_ptr(static_cast(span.release()))); diff --git a/ext/test/http/curl_http_test.cc b/ext/test/http/curl_http_test.cc index a737ac8a89..2101a8bdd5 100644 --- a/ext/test/http/curl_http_test.cc +++ b/ext/test/http/curl_http_test.cc @@ -20,14 +20,13 @@ namespace curl = opentelemetry::ext::http::client::curl; namespace http_client = opentelemetry::ext::http::client; -namespace nostd = opentelemetry::nostd; +namespace nostd = opentelemetry::nostd; class CustomEventHandler : public http_client::EventHandler { public: virtual void OnResponse(http_client::Response &response) noexcept override{}; - virtual void OnEvent(http_client::SessionState state, - nostd::string_view reason) noexcept override + virtual void OnEvent(http_client::SessionState state, nostd::string_view reason) noexcept override {} virtual void OnConnecting(const http_client::SSLCertificate &) noexcept {} virtual ~CustomEventHandler() = default; @@ -167,8 +166,7 @@ TEST_F(BasicCurlHttpTests, HttpResponse) const char *b = "test-data"; http_client::Body body = {b, b + strlen(b)}; int count = 0; - res.ForEachHeader("name1", [&count](nostd::string_view name, - nostd::string_view value) { + res.ForEachHeader("name1", [&count](nostd::string_view name, nostd::string_view value) { if (name != "name1") return false; if (value != "value1_1" && value != "value1_2") @@ -178,15 +176,14 @@ TEST_F(BasicCurlHttpTests, HttpResponse) }); ASSERT_EQ(count, 2); count = 0; - res.ForEachHeader( - [&count](nostd::string_view name, nostd::string_view value) { - if (name != "name1" && name != "name2" && name != "name3") - return false; - if (value != "value1_1" && value != "value1_2" && value != "value2" && value != "value3") - return false; - count++; - return true; - }); + res.ForEachHeader([&count](nostd::string_view name, nostd::string_view value) { + if (name != "name1" && name != "name2" && name != "name3") + return false; + if (value != "value1_1" && value != "value1_2" && value != "value2" && value != "value3") + return false; + count++; + return true; + }); ASSERT_EQ(count, 4); } diff --git a/ext/test/w3c_tracecontext_test/main.cc b/ext/test/w3c_tracecontext_test/main.cc index 07291caaf4..a9a334d613 100644 --- a/ext/test/w3c_tracecontext_test/main.cc +++ b/ext/test/w3c_tracecontext_test/main.cc @@ -52,9 +52,9 @@ void initTracer() new sdktrace::SimpleSpanProcessor(std::move(exporter))); std::vector> processors; processors.push_back(std::move(processor)); - auto context = std::make_shared(std::move(processors)); - auto provider = nostd::shared_ptr( - new sdktrace::TracerProvider(context)); + auto context = std::make_shared(std::move(processors)); + auto provider = + nostd::shared_ptr(new sdktrace::TracerProvider(context)); // Set the global trace provider trace_api::Provider::SetTracerProvider(provider); } @@ -98,12 +98,9 @@ class NoopEventHandler : public http_client::EventHandler } // namespace // Sends an HTTP POST request to the given url, with the given body. -void send_request(curl::HttpClient &client, - const std::string &url, - const std::string &body) +void send_request(curl::HttpClient &client, const std::string &url, const std::string &body) { - static std::unique_ptr handler( - new NoopEventHandler()); + static std::unique_ptr handler(new NoopEventHandler()); auto request_span = get_tracer()->StartSpan(__func__); trace_api::Scope scope(request_span); diff --git a/ext/test/zpages/threadsafe_span_data_test.cc b/ext/test/zpages/threadsafe_span_data_test.cc index e540e36e28..cee29672ed 100644 --- a/ext/test/zpages/threadsafe_span_data_test.cc +++ b/ext/test/zpages/threadsafe_span_data_test.cc @@ -13,7 +13,7 @@ using opentelemetry::ext::zpages::ThreadsafeSpanData; using opentelemetry::sdk::common::AttributeConverter; using opentelemetry::sdk::common::OwnedAttributeValue; -namespace trace_api = opentelemetry::trace; +namespace trace_api = opentelemetry::trace; TEST(ThreadsafeSpanData, DefaultValues) { @@ -43,8 +43,7 @@ TEST(ThreadsafeSpanData, Set) trace_api::SpanId parent_span_id{parent_span_id_buf}; const auto trace_state = trace_api::TraceState::GetDefault()->Set("key1", "value"); const trace_api::SpanContext span_context{ - trace_id, span_id, - trace_api::TraceFlags{trace_api::TraceFlags::kIsSampled}, true, + trace_id, span_id, trace_api::TraceFlags{trace_api::TraceFlags::kIsSampled}, true, trace_state}; opentelemetry::common::SystemTimestamp now(std::chrono::system_clock::now()); diff --git a/ext/test/zpages/tracez_data_aggregator_test.cc b/ext/test/zpages/tracez_data_aggregator_test.cc index 0cb647fac4..f56bbceb9e 100644 --- a/ext/test/zpages/tracez_data_aggregator_test.cc +++ b/ext/test/zpages/tracez_data_aggregator_test.cc @@ -12,8 +12,8 @@ using namespace opentelemetry::sdk::trace; using namespace opentelemetry::ext::zpages; -namespace nostd = opentelemetry::nostd; -namespace common = opentelemetry::common; +namespace nostd = opentelemetry::nostd; +namespace common = opentelemetry::common; namespace trace_api = opentelemetry::trace; using opentelemetry::common::SteadyTimestamp; diff --git a/ext/test/zpages/tracez_processor_test.cc b/ext/test/zpages/tracez_processor_test.cc index b9fe2aa740..1cadd5ec27 100644 --- a/ext/test/zpages/tracez_processor_test.cc +++ b/ext/test/zpages/tracez_processor_test.cc @@ -16,8 +16,7 @@ using namespace opentelemetry::sdk::trace; using namespace opentelemetry::ext::zpages; namespace trace_api = opentelemetry::trace; -namespace nostd = opentelemetry::nostd; - +namespace nostd = opentelemetry::nostd; //////////////////////////////////// TEST HELPER FUNCTIONS ////////////////////////////// @@ -153,10 +152,9 @@ void GetManySnapshots(std::shared_ptr &data, int i) * Helper function that creates i spans, which are added into the passed * in vector. Used for testing thread safety */ -void StartManySpans( - std::vector> &spans, - std::shared_ptr tracer, - int i) +void StartManySpans(std::vector> &spans, + std::shared_ptr tracer, + int i) { for (; i > 0; i--) spans.push_back(tracer->StartSpan("span")); diff --git a/sdk/src/logs/logger.cc b/sdk/src/logs/logger.cc index aa634b5b8b..735b527b80 100644 --- a/sdk/src/logs/logger.cc +++ b/sdk/src/logs/logger.cc @@ -12,12 +12,11 @@ namespace sdk { namespace logs { - namespace trace_api = opentelemetry::trace; -namespace nostd = opentelemetry::nostd; -namespace common = opentelemetry::common; +namespace trace_api = opentelemetry::trace; +namespace nostd = opentelemetry::nostd; +namespace common = opentelemetry::common; -Logger::Logger(nostd::string_view name, - std::shared_ptr logger_provider) noexcept +Logger::Logger(nostd::string_view name, std::shared_ptr logger_provider) noexcept : logger_name_(std::string(name)), logger_provider_(logger_provider) {} @@ -63,17 +62,15 @@ void Logger::Log(opentelemetry::logs::Severity severity, recordable->SetName(name); recordable->SetBody(body); - resource.ForEachKeyValue( - [&](nostd::string_view key, common::AttributeValue value) noexcept { - recordable->SetResource(key, value); - return true; - }); - - attributes.ForEachKeyValue( - [&](nostd::string_view key, common::AttributeValue value) noexcept { - recordable->SetAttribute(key, value); - return true; - }); + resource.ForEachKeyValue([&](nostd::string_view key, common::AttributeValue value) noexcept { + recordable->SetResource(key, value); + return true; + }); + + attributes.ForEachKeyValue([&](nostd::string_view key, common::AttributeValue value) noexcept { + recordable->SetAttribute(key, value); + return true; + }); // Inject trace_id/span_id/trace_flags if none is set by user auto provider = trace_api::Provider::GetTracerProvider(); diff --git a/sdk/src/logs/logger_provider.cc b/sdk/src/logs/logger_provider.cc index 5a34be4053..58e6a75ea4 100644 --- a/sdk/src/logs/logger_provider.cc +++ b/sdk/src/logs/logger_provider.cc @@ -11,14 +11,13 @@ namespace sdk namespace logs { -namespace nostd = opentelemetry::nostd; -namespace logs_api = opentelemetry::logs; +namespace nostd = opentelemetry::nostd; +namespace logs_api = opentelemetry::logs; LoggerProvider::LoggerProvider() noexcept : processor_{nullptr} {} -nostd::shared_ptr LoggerProvider::GetLogger( - nostd::string_view name, - nostd::string_view options) noexcept +nostd::shared_ptr LoggerProvider::GetLogger(nostd::string_view name, + nostd::string_view options) noexcept { // Ensure only one thread can read/write from the map of loggers std::lock_guard lock_guard{mu_}; @@ -45,8 +44,7 @@ nostd::shared_ptr LoggerProvider::GetLogger( // If no logger with that name exists yet, create it and add it to the map of loggers - nostd::shared_ptr logger( - new Logger(name, this->shared_from_this())); + nostd::shared_ptr logger(new Logger(name, this->shared_from_this())); loggers_[name.data()] = logger; return logger; } diff --git a/sdk/src/metrics/meter_provider.cc b/sdk/src/metrics/meter_provider.cc index 09d85dd3b3..d639a994bc 100644 --- a/sdk/src/metrics/meter_provider.cc +++ b/sdk/src/metrics/meter_provider.cc @@ -9,8 +9,8 @@ namespace sdk { namespace metrics { -namespace nostd = opentelemetry::nostd; -namespace metrics_api = opentelemetry::metrics; +namespace nostd = opentelemetry::nostd; +namespace metrics_api = opentelemetry::metrics; MeterProvider::MeterProvider(std::string library_name, std::string library_version) noexcept : meter_(new Meter(library_name, library_version)) diff --git a/sdk/src/trace/random_id_generator.cc b/sdk/src/trace/random_id_generator.cc index 36c036f6c2..e2fa5b0987 100644 --- a/sdk/src/trace/random_id_generator.cc +++ b/sdk/src/trace/random_id_generator.cc @@ -12,7 +12,6 @@ namespace trace { namespace trace_api = opentelemetry::trace; - trace_api::SpanId RandomIdGenerator::GenerateSpanId() noexcept { uint8_t span_id_buf[trace_api::SpanId::kSize]; diff --git a/sdk/src/trace/span.cc b/sdk/src/trace/span.cc index 587b9415eb..dff84a22b7 100644 --- a/sdk/src/trace/span.cc +++ b/sdk/src/trace/span.cc @@ -68,11 +68,10 @@ Span::Span(std::shared_ptr &&tracer, ? parent_span_context.span_id() : trace_api::SpanId()); - attributes.ForEachKeyValue( - [&](nostd::string_view key, common::AttributeValue value) noexcept { - recordable_->SetAttribute(key, value); - return true; - }); + attributes.ForEachKeyValue([&](nostd::string_view key, common::AttributeValue value) noexcept { + recordable_->SetAttribute(key, value); + return true; + }); links.ForEachKeyValue([&](opentelemetry::trace::SpanContext span_context, const common::KeyValueIterable &attributes) { @@ -92,8 +91,7 @@ Span::~Span() End(); } -void Span::SetAttribute(nostd::string_view key, - const common::AttributeValue &value) noexcept +void Span::SetAttribute(nostd::string_view key, const common::AttributeValue &value) noexcept { std::lock_guard lock_guard{mu_}; diff --git a/sdk/src/trace/tracer_provider.cc b/sdk/src/trace/tracer_provider.cc index 1a4e5c7eb7..5182fd1d22 100644 --- a/sdk/src/trace/tracer_provider.cc +++ b/sdk/src/trace/tracer_provider.cc @@ -9,7 +9,7 @@ namespace sdk { namespace trace { -namespace resource = opentelemetry::sdk::resource; +namespace resource = opentelemetry::sdk::resource; namespace trace_api = opentelemetry::trace; TracerProvider::TracerProvider(std::shared_ptr context) noexcept diff --git a/sdk/test/logs/log_record_test.cc b/sdk/test/logs/log_record_test.cc index 1bb071a98a..9443091691 100644 --- a/sdk/test/logs/log_record_test.cc +++ b/sdk/test/logs/log_record_test.cc @@ -12,9 +12,8 @@ using opentelemetry::sdk::logs::LogRecord; namespace trace_api = opentelemetry::trace; -namespace logs_api = opentelemetry::logs; -namespace nostd = opentelemetry::nostd; - +namespace logs_api = opentelemetry::logs; +namespace nostd = opentelemetry::nostd; // Test what a default LogRecord with no fields set holds TEST(LogRecord, GetDefaultValues) diff --git a/sdk/test/logs/logger_provider_sdk_test.cc b/sdk/test/logs/logger_provider_sdk_test.cc index f18025c0ff..5c0be6fb94 100644 --- a/sdk/test/logs/logger_provider_sdk_test.cc +++ b/sdk/test/logs/logger_provider_sdk_test.cc @@ -19,8 +19,8 @@ namespace nostd = opentelemetry::nostd; TEST(LoggerProviderSDK, PushToAPI) { - auto lp = nostd::shared_ptr( - new opentelemetry::sdk::logs::LoggerProvider()); + auto lp = + nostd::shared_ptr(new opentelemetry::sdk::logs::LoggerProvider()); logs_api::Provider::SetLoggerProvider(lp); // Check that the loggerprovider was correctly pushed into the API diff --git a/sdk/test/logs/simple_log_processor_test.cc b/sdk/test/logs/simple_log_processor_test.cc index ee05b302bc..3b89d60994 100644 --- a/sdk/test/logs/simple_log_processor_test.cc +++ b/sdk/test/logs/simple_log_processor_test.cc @@ -38,8 +38,7 @@ class TestExporter final : public LogExporter } // Stores the names of the log records this exporter receives to an internal list - ExportResult Export( - const nostd::span> &records) noexcept override + ExportResult Export(const nostd::span> &records) noexcept override { *batch_size_received = records.size(); for (auto &record : records) @@ -134,8 +133,7 @@ class FailShutDownExporter final : public LogExporter return std::unique_ptr(new LogRecord()); } - ExportResult Export( - const nostd::span> &records) noexcept override + ExportResult Export(const nostd::span> &records) noexcept override { return ExportResult::kSuccess; } diff --git a/sdk/test/metrics/meter_test.cc b/sdk/test/metrics/meter_test.cc index dd2bbb858e..f26cd2940d 100644 --- a/sdk/test/metrics/meter_test.cc +++ b/sdk/test/metrics/meter_test.cc @@ -9,8 +9,8 @@ using namespace opentelemetry::sdk::metrics; namespace metrics_api = opentelemetry::metrics; -namespace common = opentelemetry::common; -namespace nostd = opentelemetry::nostd; +namespace common = opentelemetry::common; +namespace nostd = opentelemetry::nostd; OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/sdk/test/metrics/ungrouped_processor_test.cc b/sdk/test/metrics/ungrouped_processor_test.cc index eef8babc77..378f7b49ee 100644 --- a/sdk/test/metrics/ungrouped_processor_test.cc +++ b/sdk/test/metrics/ungrouped_processor_test.cc @@ -19,12 +19,10 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorFinishedCollectionStateless) new sdkmetrics::UngroupedMetricsProcessor(false)); auto aggregator = std::shared_ptr>( - new sdkmetrics::CounterAggregator( - metrics_api::InstrumentKind::Counter)); + new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); auto aggregator2 = std::shared_ptr>( - new sdkmetrics::CounterAggregator( - metrics_api::InstrumentKind::Counter)); + new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(5.5); aggregator->checkpoint(); @@ -56,12 +54,10 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorFinishedCollectionStateful) new sdkmetrics::UngroupedMetricsProcessor(true)); auto aggregator = std::shared_ptr>( - new sdkmetrics::CounterAggregator( - metrics_api::InstrumentKind::Counter)); + new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); auto aggregator2 = std::shared_ptr>( - new sdkmetrics::CounterAggregator( - metrics_api::InstrumentKind::Counter)); + new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(5.5); aggregator->checkpoint(); @@ -91,8 +87,7 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateles new sdkmetrics::UngroupedMetricsProcessor(false)); auto aggregator = std::shared_ptr>( - new sdkmetrics::CounterAggregator( - metrics_api::InstrumentKind::Counter)); + new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(4); aggregator->checkpoint(); @@ -116,8 +111,7 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateles new sdkmetrics::UngroupedMetricsProcessor(false)); auto aggregator = std::shared_ptr>( - new sdkmetrics::CounterAggregator( - metrics_api::InstrumentKind::Counter)); + new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(5); aggregator->checkpoint(); @@ -140,8 +134,7 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateles new sdkmetrics::UngroupedMetricsProcessor(false)); auto aggregator = std::shared_ptr>( - new sdkmetrics::CounterAggregator( - metrics_api::InstrumentKind::Counter)); + new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(8.5); aggregator->checkpoint(); @@ -165,8 +158,7 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateles new sdkmetrics::UngroupedMetricsProcessor(false)); auto aggregator = std::shared_ptr>( - new sdkmetrics::CounterAggregator( - metrics_api::InstrumentKind::Counter)); + new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(5.5); aggregator->checkpoint(); @@ -195,12 +187,10 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful new sdkmetrics::UngroupedMetricsProcessor(true)); auto aggregator = std::shared_ptr>( - new sdkmetrics::CounterAggregator( - metrics_api::InstrumentKind::Counter)); + new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); auto aggregator_test = std::shared_ptr>( - new sdkmetrics::CounterAggregator( - metrics_api::InstrumentKind::Counter)); + new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(5); aggregator_test->update(5); @@ -240,12 +230,10 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful new sdkmetrics::UngroupedMetricsProcessor(true)); auto aggregator = std::shared_ptr>( - new sdkmetrics::CounterAggregator( - metrics_api::InstrumentKind::Counter)); + new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); auto aggregator_test = std::shared_ptr>( - new sdkmetrics::CounterAggregator( - metrics_api::InstrumentKind::Counter)); + new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(5); aggregator_test->update(5); @@ -283,12 +271,10 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful new sdkmetrics::UngroupedMetricsProcessor(true)); auto aggregator = std::shared_ptr>( - new sdkmetrics::CounterAggregator( - metrics_api::InstrumentKind::Counter)); + new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); auto aggregator_test = std::shared_ptr>( - new sdkmetrics::CounterAggregator( - metrics_api::InstrumentKind::Counter)); + new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(5); aggregator_test->update(5); @@ -328,12 +314,10 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful new sdkmetrics::UngroupedMetricsProcessor(true)); auto aggregator = std::shared_ptr>( - new sdkmetrics::CounterAggregator( - metrics_api::InstrumentKind::Counter)); + new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); auto aggregator_test = std::shared_ptr>( - new sdkmetrics::CounterAggregator( - metrics_api::InstrumentKind::Counter)); + new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(5.5); aggregator_test->update(5.5); @@ -373,12 +357,10 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful new sdkmetrics::UngroupedMetricsProcessor(true)); auto aggregator = std::shared_ptr>( - new sdkmetrics::MinMaxSumCountAggregator( - metrics_api::InstrumentKind::Counter)); + new sdkmetrics::MinMaxSumCountAggregator(metrics_api::InstrumentKind::Counter)); auto aggregator2 = std::shared_ptr>( - new sdkmetrics::MinMaxSumCountAggregator( - metrics_api::InstrumentKind::Counter)); + new sdkmetrics::MinMaxSumCountAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(1.1); aggregator->update(2.2); @@ -420,8 +402,7 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful new sdkmetrics::UngroupedMetricsProcessor(true)); auto aggregator = std::shared_ptr>( - new sdkmetrics::GaugeAggregator( - metrics_api::InstrumentKind::Counter)); + new sdkmetrics::GaugeAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(1.1); aggregator->update(2.2); @@ -459,12 +440,10 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful new sdkmetrics::UngroupedMetricsProcessor(true)); auto aggregator = std::shared_ptr>( - new sdkmetrics::ExactAggregator(metrics_api::InstrumentKind::Counter, - false)); + new sdkmetrics::ExactAggregator(metrics_api::InstrumentKind::Counter, false)); auto aggregator2 = std::shared_ptr>( - new sdkmetrics::ExactAggregator(metrics_api::InstrumentKind::Counter, - false)); + new sdkmetrics::ExactAggregator(metrics_api::InstrumentKind::Counter, false)); aggregator->update(1.1); aggregator->update(2.2); @@ -508,12 +487,10 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful std::vector boundaries{10, 20, 30, 40, 50}; auto aggregator = std::shared_ptr>( - new sdkmetrics::HistogramAggregator( - metrics_api::InstrumentKind::Counter, boundaries)); + new sdkmetrics::HistogramAggregator(metrics_api::InstrumentKind::Counter, boundaries)); auto aggregator2 = std::shared_ptr>( - new sdkmetrics::HistogramAggregator( - metrics_api::InstrumentKind::Counter, boundaries)); + new sdkmetrics::HistogramAggregator(metrics_api::InstrumentKind::Counter, boundaries)); for (int i = 0; i < 60; i++) { @@ -570,12 +547,10 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful new sdkmetrics::UngroupedMetricsProcessor(true)); auto aggregator = std::shared_ptr>( - new sdkmetrics::SketchAggregator(metrics_api::InstrumentKind::Counter, - .00005)); + new sdkmetrics::SketchAggregator(metrics_api::InstrumentKind::Counter, .00005)); auto test_aggregator = std::shared_ptr>( - new sdkmetrics::SketchAggregator(metrics_api::InstrumentKind::Counter, - .00005)); + new sdkmetrics::SketchAggregator(metrics_api::InstrumentKind::Counter, .00005)); for (int i = 0; i < 60; i++) { diff --git a/sdk/test/resource/resource_test.cc b/sdk/test/resource/resource_test.cc index 3fdaea4983..ad79ac8e1d 100644 --- a/sdk/test/resource/resource_test.cc +++ b/sdk/test/resource/resource_test.cc @@ -137,8 +137,7 @@ TEST(ResourceTest, Merge) EXPECT_TRUE(expected_attributes.find(e.first) != expected_attributes.end()); if (expected_attributes.find(e.first) != expected_attributes.end()) { - EXPECT_EQ(expected_attributes.find(e.first)->second, - nostd::get(e.second)); + EXPECT_EQ(expected_attributes.find(e.first)->second, nostd::get(e.second)); } } EXPECT_EQ(received_attributes.size(), expected_attributes.size()); @@ -159,8 +158,7 @@ TEST(ResourceTest, MergeEmptyString) EXPECT_TRUE(expected_attributes.find(e.first) != expected_attributes.end()); if (expected_attributes.find(e.first) != expected_attributes.end()) { - EXPECT_EQ(expected_attributes.find(e.first)->second, - nostd::get(e.second)); + EXPECT_EQ(expected_attributes.find(e.first)->second, nostd::get(e.second)); } } EXPECT_EQ(received_attributes.size(), expected_attributes.size()); @@ -182,8 +180,7 @@ TEST(ResourceTest, OtelResourceDetector) EXPECT_TRUE(expected_attributes.find(e.first) != expected_attributes.end()); if (expected_attributes.find(e.first) != expected_attributes.end()) { - EXPECT_EQ(expected_attributes.find(e.first)->second, - nostd::get(e.second)); + EXPECT_EQ(expected_attributes.find(e.first)->second, nostd::get(e.second)); } } EXPECT_EQ(received_attributes.size(), expected_attributes.size()); @@ -210,8 +207,7 @@ TEST(ResourceTest, OtelResourceDetectorEmptyEnv) EXPECT_TRUE(expected_attributes.find(e.first) != expected_attributes.end()); if (expected_attributes.find(e.first) != expected_attributes.end()) { - EXPECT_EQ(expected_attributes.find(e.first)->second, - nostd::get(e.second)); + EXPECT_EQ(expected_attributes.find(e.first)->second, nostd::get(e.second)); } } EXPECT_EQ(received_attributes.size(), expected_attributes.size()); diff --git a/sdk/test/trace/always_off_sampler_test.cc b/sdk/test/trace/always_off_sampler_test.cc index f96dc18cc4..1c32bd5a8f 100644 --- a/sdk/test/trace/always_off_sampler_test.cc +++ b/sdk/test/trace/always_off_sampler_test.cc @@ -10,7 +10,6 @@ using opentelemetry::sdk::trace::Decision; using opentelemetry::trace::SpanContext; namespace trace_api = opentelemetry::trace; - TEST(AlwaysOffSampler, ShouldSample) { AlwaysOffSampler sampler; diff --git a/sdk/test/trace/parent_sampler_test.cc b/sdk/test/trace/parent_sampler_test.cc index 2aa482c422..124287598d 100644 --- a/sdk/test/trace/parent_sampler_test.cc +++ b/sdk/test/trace/parent_sampler_test.cc @@ -26,8 +26,8 @@ TEST(ParentBasedSampler, ShouldSample) trace_api::SpanId span_id{span_id_buffer}; trace_api::SpanKind span_kind = trace_api::SpanKind::kInternal; - using M = std::map; - M m1 = {{}}; + using M = std::map; + M m1 = {{}}; using L = std::vector>>; L l1 = {{trace_api::SpanContext(false, false), {}}, {trace_api::SpanContext(false, false), {}}}; diff --git a/sdk/test/trace/span_data_test.cc b/sdk/test/trace/span_data_test.cc index 42f884a9d7..7a6c66c91e 100644 --- a/sdk/test/trace/span_data_test.cc +++ b/sdk/test/trace/span_data_test.cc @@ -11,8 +11,8 @@ using opentelemetry::sdk::trace::SpanData; namespace trace_api = opentelemetry::trace; -namespace common = opentelemetry::common; -namespace nostd = opentelemetry::nostd; +namespace common = opentelemetry::common; +namespace nostd = opentelemetry::nostd; TEST(SpanData, DefaultValues) { @@ -43,8 +43,7 @@ TEST(SpanData, Set) trace_api::SpanId parent_span_id{parent_span_id_buf}; const auto trace_state = trace_api::TraceState::GetDefault()->Set("key1", "value"); const trace_api::SpanContext span_context{ - trace_id, span_id, - trace_api::TraceFlags{trace_api::TraceFlags::kIsSampled}, true, + trace_id, span_id, trace_api::TraceFlags{trace_api::TraceFlags::kIsSampled}, true, trace_state}; common::SystemTimestamp now(std::chrono::system_clock::now()); @@ -85,15 +84,12 @@ TEST(SpanData, EventAttributes) std::map attributes = { {keys[0], values[0]}, {keys[1], values[1]}, {keys[2], values[2]}}; - data.AddEvent( - "Test Event", std::chrono::system_clock::now(), - common::KeyValueIterableView>(attributes)); + data.AddEvent("Test Event", std::chrono::system_clock::now(), + common::KeyValueIterableView>(attributes)); for (int i = 0; i < kNumAttributes; i++) { - EXPECT_EQ( - nostd::get(data.GetEvents().at(0).GetAttributes().at(keys[i])), - values[i]); + EXPECT_EQ(nostd::get(data.GetEvents().at(0).GetAttributes().at(keys[i])), values[i]); } } @@ -126,17 +122,14 @@ TEST(SpanData, Links) }; trace_api::TraceId trace_id{trace_id_buf}; const auto span_context = trace_api::SpanContext( - trace_id, span_id, - trace_api::TraceFlags{trace_api::TraceFlags::kIsSampled}, true); + trace_id, span_id, trace_api::TraceFlags{trace_api::TraceFlags::kIsSampled}, true); - data.AddLink( - span_context, - common::KeyValueIterableView>(attributes)); + data.AddLink(span_context, + common::KeyValueIterableView>(attributes)); EXPECT_EQ(data.GetLinks().at(0).GetSpanContext(), span_context); for (int i = 0; i < kNumAttributes; i++) { - EXPECT_EQ(nostd::get(data.GetLinks().at(0).GetAttributes().at(keys[i])), - values[i]); + EXPECT_EQ(nostd::get(data.GetLinks().at(0).GetAttributes().at(keys[i])), values[i]); } } diff --git a/sdk/test/trace/trace_id_ratio_sampler_test.cc b/sdk/test/trace/trace_id_ratio_sampler_test.cc index 1741d6b488..1b0088f134 100644 --- a/sdk/test/trace/trace_id_ratio_sampler_test.cc +++ b/sdk/test/trace/trace_id_ratio_sampler_test.cc @@ -13,7 +13,7 @@ using opentelemetry::sdk::common::Random; using opentelemetry::sdk::trace::Decision; using opentelemetry::sdk::trace::TraceIdRatioBasedSampler; namespace trace_api = opentelemetry::trace; -namespace common = opentelemetry::common; +namespace common = opentelemetry::common; namespace { diff --git a/sdk/test/trace/tracer_test.cc b/sdk/test/trace/tracer_test.cc index 98ef9607da..b3d44a9811 100644 --- a/sdk/test/trace/tracer_test.cc +++ b/sdk/test/trace/tracer_test.cc @@ -17,8 +17,8 @@ using namespace opentelemetry::sdk::trace; using namespace opentelemetry::sdk::resource; using opentelemetry::common::SteadyTimestamp; using opentelemetry::common::SystemTimestamp; -namespace nostd = opentelemetry::nostd; -namespace common = opentelemetry::common; +namespace nostd = opentelemetry::nostd; +namespace common = opentelemetry::common; namespace trace_api = opentelemetry::trace; using opentelemetry::common::KeyValueIterableView; using opentelemetry::exporter::memory::InMemorySpanData; @@ -67,15 +67,9 @@ class MockSampler final : public Sampler */ class MockIdGenerator : public IdGenerator { - trace_api::SpanId GenerateSpanId() noexcept override - { - return trace_api::SpanId(buf_span); - } + trace_api::SpanId GenerateSpanId() noexcept override { return trace_api::SpanId(buf_span); } - trace_api::TraceId GenerateTraceId() noexcept override - { - return trace_api::TraceId(buf_trace); - } + trace_api::TraceId GenerateTraceId() noexcept override { return trace_api::TraceId(buf_trace); } uint8_t buf_span[8] = {1, 2, 3, 4, 5, 6, 7, 8}; uint8_t buf_trace[16] = {1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1}; }; From 29f9601caf27814fa784236b42e3e77e98c8fc61 Mon Sep 17 00:00:00 2001 From: PaurushGarg Date: Tue, 5 Oct 2021 10:01:13 -0700 Subject: [PATCH 06/16] Reversing changes in kv_properties_test.cc --- api/test/common/kv_properties_test.cc | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/api/test/common/kv_properties_test.cc b/api/test/common/kv_properties_test.cc index fb07c35b0f..e5d9a2439e 100644 --- a/api/test/common/kv_properties_test.cc +++ b/api/test/common/kv_properties_test.cc @@ -13,12 +13,11 @@ using namespace opentelemetry; using opentelemetry::common::KeyValueProperties; -namespace nostd = opentelemetry::nostd; // Test constructor that takes a key-value pair TEST(EntryTest, KeyValueConstruction) { - nostd::string_view key = "test_key"; - nostd::string_view val = "test_value"; + opentelemetry::nostd::string_view key = "test_key"; + opentelemetry::nostd::string_view val = "test_value"; KeyValueProperties::Entry e(key, val); EXPECT_EQ(key.size(), e.GetKey().size()); @@ -50,7 +49,7 @@ TEST(EntryTest, Assignment) TEST(EntryTest, SetValue) { KeyValueProperties::Entry e("test_key", "test_value"); - nostd::string_view new_val = "new_value"; + opentelemetry::nostd::string_view new_val = "new_value"; e.SetValue(new_val); EXPECT_EQ(new_val.size(), e.GetValue().size()); @@ -66,7 +65,7 @@ TEST(KVStringTokenizer, SinglePair) { bool valid_kv; nostd::string_view key, value; - nostd::string_view str = "k1=v1"; + opentelemetry::nostd::string_view str = "k1=v1"; KeyValueStringTokenizerOptions opts; KeyValueStringTokenizer tk(str, opts); EXPECT_TRUE(tk.next(valid_kv, key, value)); @@ -80,7 +79,7 @@ TEST(KVStringTokenizer, AcceptEmptyEntries) { bool valid_kv; nostd::string_view key, value; - nostd::string_view str = ":k1=v1::k2=v2: "; + opentelemetry::nostd::string_view str = ":k1=v1::k2=v2: "; KeyValueStringTokenizerOptions opts; opts.member_separator = ':'; opts.ignore_empty_members = false; @@ -101,7 +100,7 @@ TEST(KVStringTokenizer, AcceptEmptyEntries) TEST(KVStringTokenizer, ValidPairsWithEmptyEntries) { - nostd::string_view str = "k1:v1===k2:v2=="; + opentelemetry::nostd::string_view str = "k1:v1===k2:v2=="; bool valid_kv; nostd::string_view key, value; KeyValueStringTokenizerOptions opts; @@ -124,7 +123,7 @@ TEST(KVStringTokenizer, ValidPairsWithEmptyEntries) TEST(KVStringTokenizer, InvalidPairs) { - nostd::string_view str = "k1=v1,invalid ,, k2=v2 ,invalid"; + opentelemetry::nostd::string_view str = "k1=v1,invalid ,, k2=v2 ,invalid"; KeyValueStringTokenizer tk(str); bool valid_kv; nostd::string_view key, value; @@ -218,10 +217,10 @@ TEST(KeyValueProperties, GetAllEntries) { std::vector> kv_pairs = { {"k1", "v1"}, {"k2", "v2"}, {"k3", "v3"}}; - const size_t kNumPairs = 3; - nostd::string_view keys[kNumPairs] = {"k1", "k2", "k3"}; - nostd::string_view values[kNumPairs] = {"v1", "v2", "v3"}; - auto kv_properties = KeyValueProperties(kv_pairs); + const size_t kNumPairs = 3; + opentelemetry::nostd::string_view keys[kNumPairs] = {"k1", "k2", "k3"}; + opentelemetry::nostd::string_view values[kNumPairs] = {"v1", "v2", "v3"}; + auto kv_properties = KeyValueProperties(kv_pairs); size_t index = 0; kv_properties.GetAllEntries( From c191c2f4eb7f443ed3a2a382417472f20d91122a Mon Sep 17 00:00:00 2001 From: PaurushGarg Date: Tue, 5 Oct 2021 13:03:49 -0700 Subject: [PATCH 07/16] Removing with OTLP exporter errors --- sdk/test/trace/sampler_benchmark.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sdk/test/trace/sampler_benchmark.cc b/sdk/test/trace/sampler_benchmark.cc index a47e9ca1f5..b09cb5b0cd 100644 --- a/sdk/test/trace/sampler_benchmark.cc +++ b/sdk/test/trace/sampler_benchmark.cc @@ -19,7 +19,6 @@ using namespace opentelemetry::sdk::trace; using opentelemetry::exporter::memory::InMemorySpanExporter; using opentelemetry::trace::SpanContext; -namespace trace_api = opentelemetry::trace; namespace { @@ -64,8 +63,8 @@ BENCHMARK(BM_TraceIdRatioBasedSamplerConstruction); // Sampler Helper Function void BenchmarkShouldSampler(Sampler &sampler, benchmark::State &state) { - trace_api::TraceId trace_id; - trace_api::SpanKind span_kind = trace_api::SpanKind::kInternal; + opentelemetry::trace::TraceId trace_id; + opentelemetry::trace::SpanKind span_kind = opentelemetry::trace::SpanKind::kInternal; using M = std::map; M m1 = {{}}; @@ -127,7 +126,7 @@ void BenchmarkSpanCreation(std::shared_ptr sampler, benchmark::State &s processors.push_back(std::move(processor)); auto context = std::make_shared(std::move(processors)); auto resource = opentelemetry::sdk::resource::Resource::Create({}); - auto tracer = std::shared_ptr(new Tracer(context)); + auto tracer = std::shared_ptr(new Tracer(context)); while (state.KeepRunning()) { From d7dc0b74bd0dbbd32ad8b4d1fa14e8622e36d481 Mon Sep 17 00:00:00 2001 From: PaurushGarg Date: Tue, 5 Oct 2021 15:39:49 -0700 Subject: [PATCH 08/16] Removing Errors --- sdk/test/trace/tracer_test.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sdk/test/trace/tracer_test.cc b/sdk/test/trace/tracer_test.cc index b3d44a9811..5aad3c32e6 100644 --- a/sdk/test/trace/tracer_test.cc +++ b/sdk/test/trace/tracer_test.cc @@ -17,14 +17,13 @@ using namespace opentelemetry::sdk::trace; using namespace opentelemetry::sdk::resource; using opentelemetry::common::SteadyTimestamp; using opentelemetry::common::SystemTimestamp; -namespace nostd = opentelemetry::nostd; -namespace common = opentelemetry::common; -namespace trace_api = opentelemetry::trace; using opentelemetry::common::KeyValueIterableView; using opentelemetry::exporter::memory::InMemorySpanData; using opentelemetry::exporter::memory::InMemorySpanExporter; using opentelemetry::trace::SpanContext; - +namespace nostd = opentelemetry::nostd; +namespace common = opentelemetry::common; +namespace trace_api = opentelemetry::trace; /** * A mock sampler with ShouldSample returning: * Decision::RECORD_AND_SAMPLE if trace_id is valid From b90ae15bded75236a4f20eccb0b0c0c7cafc6064 Mon Sep 17 00:00:00 2001 From: PaurushGarg Date: Mon, 11 Oct 2021 11:40:00 -0700 Subject: [PATCH 09/16] Removing with and without OTLP exporter errors --- sdk/test/trace/tracer_test.cc | 36 ++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/sdk/test/trace/tracer_test.cc b/sdk/test/trace/tracer_test.cc index 5aad3c32e6..94e57a4cd7 100644 --- a/sdk/test/trace/tracer_test.cc +++ b/sdk/test/trace/tracer_test.cc @@ -17,13 +17,13 @@ using namespace opentelemetry::sdk::trace; using namespace opentelemetry::sdk::resource; using opentelemetry::common::SteadyTimestamp; using opentelemetry::common::SystemTimestamp; +namespace nostd = opentelemetry::nostd; +namespace common = opentelemetry::common; using opentelemetry::common::KeyValueIterableView; using opentelemetry::exporter::memory::InMemorySpanData; using opentelemetry::exporter::memory::InMemorySpanExporter; using opentelemetry::trace::SpanContext; -namespace nostd = opentelemetry::nostd; -namespace common = opentelemetry::common; -namespace trace_api = opentelemetry::trace; + /** * A mock sampler with ShouldSample returning: * Decision::RECORD_AND_SAMPLE if trace_id is valid @@ -37,8 +37,8 @@ class MockSampler final : public Sampler trace_api::TraceId trace_id, nostd::string_view /*name*/, trace_api::SpanKind /*span_kind*/, - const common::KeyValueIterable & /*attributes*/, - const trace_api::SpanContextKeyValueIterable & /*links*/) noexcept override + const opentelemetry::common::KeyValueIterable & /*attributes*/, + const opentelemetry::trace::SpanContextKeyValueIterable & /*links*/) noexcept override { // Sample only if valid trace_id ( This is to test Sampler get's valid trace id) if (trace_id.IsValid()) @@ -46,8 +46,8 @@ class MockSampler final : public Sampler // Return two pairs of attributes. These attributes should be added to the // span attributes return {Decision::RECORD_AND_SAMPLE, - nostd::unique_ptr>( - new const std::map( + nostd::unique_ptr>( + new const std::map( {{"sampling_attr1", 123}, {"sampling_attr2", "string"}}))}; } else @@ -66,25 +66,31 @@ class MockSampler final : public Sampler */ class MockIdGenerator : public IdGenerator { - trace_api::SpanId GenerateSpanId() noexcept override { return trace_api::SpanId(buf_span); } + opentelemetry::trace::SpanId GenerateSpanId() noexcept override + { + return opentelemetry::trace::SpanId(buf_span); + } - trace_api::TraceId GenerateTraceId() noexcept override { return trace_api::TraceId(buf_trace); } + opentelemetry::trace::TraceId GenerateTraceId() noexcept override + { + return opentelemetry::trace::TraceId(buf_trace); + } uint8_t buf_span[8] = {1, 2, 3, 4, 5, 6, 7, 8}; uint8_t buf_trace[16] = {1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1}; }; namespace { -std::shared_ptr initTracer(std::unique_ptr &&exporter) +std::shared_ptr initTracer(std::unique_ptr &&exporter) { auto processor = std::unique_ptr(new SimpleSpanProcessor(std::move(exporter))); std::vector> processors; processors.push_back(std::move(processor)); auto context = std::make_shared(std::move(processors)); - return std::shared_ptr(new Tracer(context)); + return std::shared_ptr(new Tracer(context)); } -std::shared_ptr initTracer( +std::shared_ptr initTracer( std::unique_ptr &&exporter, // For testing, just shove a pointer over, we'll take it over. Sampler *sampler, @@ -97,7 +103,7 @@ std::shared_ptr initTracer( auto context = std::make_shared(std::move(processors), resource, std::unique_ptr(sampler), std::unique_ptr(id_generator)); - return std::shared_ptr(new Tracer(context)); + return std::shared_ptr(new Tracer(context)); } } // namespace @@ -194,11 +200,11 @@ TEST(Tracer, StartSpanWithOptionsTime) std::shared_ptr span_data = exporter->GetData(); auto tracer = initTracer(std::move(exporter)); - trace_api::StartSpanOptions start; + opentelemetry::trace::StartSpanOptions start; start.start_system_time = SystemTimestamp(std::chrono::nanoseconds(300)); start.start_steady_time = SteadyTimestamp(std::chrono::nanoseconds(10)); - trace_api::EndSpanOptions end; + opentelemetry::trace::EndSpanOptions end; end.end_steady_time = SteadyTimestamp(std::chrono::nanoseconds(40)); tracer->StartSpan("span 1", start)->End(end); From b04e37e082c3fd0230a7321c639b1afc4cd528e4 Mon Sep 17 00:00:00 2001 From: PaurushGarg Date: Mon, 11 Oct 2021 14:39:33 -0700 Subject: [PATCH 10/16] Resolving error of with and without OTLP Exporter --- .../zpages/tracez_data_aggregator_test.cc | 48 +++++++++---------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/ext/test/zpages/tracez_data_aggregator_test.cc b/ext/test/zpages/tracez_data_aggregator_test.cc index f56bbceb9e..5139c9e914 100644 --- a/ext/test/zpages/tracez_data_aggregator_test.cc +++ b/ext/test/zpages/tracez_data_aggregator_test.cc @@ -12,10 +12,8 @@ using namespace opentelemetry::sdk::trace; using namespace opentelemetry::ext::zpages; -namespace nostd = opentelemetry::nostd; -namespace common = opentelemetry::common; -namespace trace_api = opentelemetry::trace; - +namespace nostd = opentelemetry::nostd; +namespace common = opentelemetry::common; using opentelemetry::common::SteadyTimestamp; using opentelemetry::trace::Span; @@ -46,13 +44,13 @@ class TracezDataAggregatorTest : public ::testing::Test processors.push_back(std::move(processor)); auto context = std::make_shared(std::move(processors), resource); - tracer = std::shared_ptr(new Tracer(context)); + tracer = std::shared_ptr(new Tracer(context)); tracez_data_aggregator = std::unique_ptr( new TracezDataAggregator(shared_data, milliseconds(10))); } std::unique_ptr tracez_data_aggregator; - std::shared_ptr tracer; + std::shared_ptr tracer; }; /** @@ -135,9 +133,9 @@ TEST_F(TracezDataAggregatorTest, SingleRunningSpan) TEST_F(TracezDataAggregatorTest, SingleCompletedSpan) { // Start and end the span at a specified times - trace_api::StartSpanOptions start; + opentelemetry::trace::StartSpanOptions start; start.start_steady_time = SteadyTimestamp(nanoseconds(10)); - trace_api::EndSpanOptions end; + opentelemetry::trace::EndSpanOptions end; end.end_steady_time = SteadyTimestamp(nanoseconds(40)); tracer->StartSpan(span_name1, start)->End(end); @@ -166,7 +164,7 @@ TEST_F(TracezDataAggregatorTest, SingleErrorSpan) { // Start and end a single error span auto span = tracer->StartSpan(span_name1); - span->SetStatus(trace_api::StatusCode::kError, "span cancelled"); + span->SetStatus(opentelemetry::trace::StatusCode::kError, "span cancelled"); span->End(); std::this_thread::sleep_for(milliseconds(500)); auto data = tracez_data_aggregator->GetAggregatedTracezData(); @@ -259,8 +257,8 @@ TEST_F(TracezDataAggregatorTest, MultipleCompletedSpan) {}, {}, {nanoseconds(9999999999999)}}}}); - trace_api::StartSpanOptions start; - trace_api::EndSpanOptions end; + opentelemetry::trace::StartSpanOptions start; + opentelemetry::trace::EndSpanOptions end; for (auto &span : span_name_to_duration) { for (auto &buckets : span.second) @@ -330,7 +328,7 @@ TEST_F(TracezDataAggregatorTest, MultipleErrorSpans) for (auto error_desc : span_error.second) { auto span = tracer->StartSpan(span_error.first); - span->SetStatus(trace_api::StatusCode::kError, error_desc); + span->SetStatus(opentelemetry::trace::StatusCode::kError, error_desc); span->End(); } } @@ -410,7 +408,7 @@ TEST_F(TracezDataAggregatorTest, ErrorSampleSpansOverCapacity) for (auto span_error_description : span_error_descriptions) { auto span = tracer->StartSpan(span_name1); - span->SetStatus(trace_api::StatusCode::kError, span_error_description); + span->SetStatus(opentelemetry::trace::StatusCode::kError, span_error_description); span->End(); } @@ -445,8 +443,8 @@ TEST_F(TracezDataAggregatorTest, ErrorSampleSpansOverCapacity) */ TEST_F(TracezDataAggregatorTest, CompletedSampleSpansOverCapacity) { - trace_api::StartSpanOptions start; - trace_api::EndSpanOptions end; + opentelemetry::trace::StartSpanOptions start; + opentelemetry::trace::EndSpanOptions end; // Start and end 6 spans with the same name that fall into the first latency // bucket @@ -500,7 +498,7 @@ TEST_F(TracezDataAggregatorTest, SpanNameInAlphabeticalOrder) auto span_first = tracer->StartSpan(span_name2); tracer->StartSpan(span_name1)->End(); auto span_third = tracer->StartSpan(span_name3); - span_third->SetStatus(trace_api::StatusCode::kError, "span cancelled"); + span_third->SetStatus(opentelemetry::trace::StatusCode::kError, "span cancelled"); span_third->End(); std::this_thread::sleep_for(milliseconds(500)); // Get data and check if span name exists in aggregation @@ -552,9 +550,9 @@ TEST_F(TracezDataAggregatorTest, AdditionToRunningSpans) * aggregated data is updated correctly **/ TEST_F(TracezDataAggregatorTest, RemovalOfRunningSpanWhenCompleted) { - trace_api::StartSpanOptions start; + opentelemetry::trace::StartSpanOptions start; start.start_steady_time = SteadyTimestamp(nanoseconds(10)); - trace_api::EndSpanOptions end; + opentelemetry::trace::EndSpanOptions end; end.end_steady_time = SteadyTimestamp(nanoseconds(40)); // Start a span and make sure data is updated @@ -591,9 +589,9 @@ TEST_F(TracezDataAggregatorTest, RemovalOfRunningSpanWhenCompleted) TEST_F(TracezDataAggregatorTest, RunningSpanChangesNameBeforeCompletion) { - trace_api::StartSpanOptions start; + opentelemetry::trace::StartSpanOptions start; start.start_steady_time = SteadyTimestamp(nanoseconds(10)); - trace_api::EndSpanOptions end; + opentelemetry::trace::EndSpanOptions end; end.end_steady_time = SteadyTimestamp(nanoseconds(40)); // Start a span and make sure data is updated @@ -634,8 +632,8 @@ TEST_F(TracezDataAggregatorTest, RunningSpanChangesNameBeforeCompletion) * fall in the correct bucket **/ TEST_F(TracezDataAggregatorTest, EdgeSpanLatenciesFallInCorrectBoundaries) { - trace_api::StartSpanOptions start; - trace_api::EndSpanOptions end; + opentelemetry::trace::StartSpanOptions start; + opentelemetry::trace::EndSpanOptions end; // Start and end 6 spans with the same name that fall into the first latency // bucket @@ -671,16 +669,16 @@ TEST_F(TracezDataAggregatorTest, EdgeSpanLatenciesFallInCorrectBoundaries) * calls to the data aggegator with no change in data **/ TEST_F(TracezDataAggregatorTest, NoChangeInBetweenCallsToAggregator) { - trace_api::StartSpanOptions start; + opentelemetry::trace::StartSpanOptions start; start.start_steady_time = SteadyTimestamp(nanoseconds(1)); - trace_api::EndSpanOptions end; + opentelemetry::trace::EndSpanOptions end; end.end_steady_time = SteadyTimestamp(nanoseconds(1)); tracer->StartSpan(span_name1, start)->End(end); auto running_span = tracer->StartSpan(span_name2); auto span = tracer->StartSpan(span_name3); - span->SetStatus(trace_api::StatusCode::kError, "span cancelled"); + span->SetStatus(opentelemetry::trace::StatusCode::kError, "span cancelled"); span->End(); std::this_thread::sleep_for(milliseconds(500)); auto data = tracez_data_aggregator->GetAggregatedTracezData(); From 2f759de454280f11ec4a444d050c91e171ea491f Mon Sep 17 00:00:00 2001 From: PaurushGarg Date: Mon, 11 Oct 2021 15:20:30 -0700 Subject: [PATCH 11/16] Resolving with OTLP errors --- ext/test/zpages/tracez_processor_test.cc | 40 +++++++++++------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/ext/test/zpages/tracez_processor_test.cc b/ext/test/zpages/tracez_processor_test.cc index 1cadd5ec27..f96385acda 100644 --- a/ext/test/zpages/tracez_processor_test.cc +++ b/ext/test/zpages/tracez_processor_test.cc @@ -15,9 +15,6 @@ using namespace opentelemetry::sdk::trace; using namespace opentelemetry::ext::zpages; -namespace trace_api = opentelemetry::trace; -namespace nostd = opentelemetry::nostd; - //////////////////////////////////// TEST HELPER FUNCTIONS ////////////////////////////// /* @@ -152,9 +149,10 @@ void GetManySnapshots(std::shared_ptr &data, int i) * Helper function that creates i spans, which are added into the passed * in vector. Used for testing thread safety */ -void StartManySpans(std::vector> &spans, - std::shared_ptr tracer, - int i) +void StartManySpans( + std::vector> &spans, + std::shared_ptr tracer, + int i) { for (; i > 0; i--) spans.push_back(tracer->StartSpan("span")); @@ -164,7 +162,7 @@ void StartManySpans(std::vector> &spans, * Helper function that ends all spans in the passed in span vector. Used * for testing thread safety */ -void EndAllSpans(std::vector> &spans) +void EndAllSpans(std::vector> &spans) { for (auto &span : spans) span->End(); @@ -191,7 +189,7 @@ class TracezProcessor : public ::testing::Test // all the tests use shared data, and we want to make sure this works correctly. auto context = std::make_shared(std::move(processors), resource); - tracer = std::shared_ptr(new Tracer(context)); + tracer = std::shared_ptr(new Tracer(context)); auto spans = shared_data->GetSpanSnapshot(); running = spans.running; completed = std::move(spans.completed); @@ -201,10 +199,10 @@ class TracezProcessor : public ::testing::Test std::shared_ptr shared_data; std::shared_ptr processor; - std::shared_ptr tracer; + std::shared_ptr tracer; std::vector span_names; - std::vector> span_vars; + std::vector> span_vars; std::unordered_set running; std::vector> completed; @@ -520,8 +518,8 @@ TEST_F(TracezProcessor, FlushShutdown) */ TEST_F(TracezProcessor, RunningThreadSafety) { - std::vector> spans1; - std::vector> spans2; + std::vector> spans1; + std::vector> spans2; std::thread start1(StartManySpans, std::ref(spans1), tracer, 500); std::thread start2(StartManySpans, std::ref(spans2), tracer, 500); @@ -538,8 +536,8 @@ TEST_F(TracezProcessor, RunningThreadSafety) */ TEST_F(TracezProcessor, CompletedThreadSafety) { - std::vector> spans1; - std::vector> spans2; + std::vector> spans1; + std::vector> spans2; StartManySpans(spans1, tracer, 500); StartManySpans(spans2, tracer, 500); @@ -556,7 +554,7 @@ TEST_F(TracezProcessor, CompletedThreadSafety) */ TEST_F(TracezProcessor, SnapshotThreadSafety) { - std::vector> spans; + std::vector> spans; std::thread snap1(GetManySnapshots, std::ref(shared_data), 500); std::thread snap2(GetManySnapshots, std::ref(shared_data), 500); @@ -580,8 +578,8 @@ TEST_F(TracezProcessor, SnapshotThreadSafety) */ TEST_F(TracezProcessor, RunningCompletedThreadSafety) { - std::vector> spans1; - std::vector> spans2; + std::vector> spans1; + std::vector> spans2; StartManySpans(spans1, tracer, 500); @@ -599,7 +597,7 @@ TEST_F(TracezProcessor, RunningCompletedThreadSafety) */ TEST_F(TracezProcessor, RunningSnapshotThreadSafety) { - std::vector> spans; + std::vector> spans; std::thread start(StartManySpans, std::ref(spans), tracer, 500); std::thread snapshots(GetManySnapshots, std::ref(shared_data), 500); @@ -615,7 +613,7 @@ TEST_F(TracezProcessor, RunningSnapshotThreadSafety) */ TEST_F(TracezProcessor, SnapshotCompletedThreadSafety) { - std::vector> spans; + std::vector> spans; StartManySpans(spans, tracer, 500); @@ -631,8 +629,8 @@ TEST_F(TracezProcessor, SnapshotCompletedThreadSafety) */ TEST_F(TracezProcessor, RunningSnapshotCompletedThreadSafety) { - std::vector> spans1; - std::vector> spans2; + std::vector> spans1; + std::vector> spans2; StartManySpans(spans1, tracer, 500); From e67a6df273991c58033cd1f2a3f8c62dca4eaaa6 Mon Sep 17 00:00:00 2001 From: PaurushGarg Date: Sun, 7 Nov 2021 22:04:16 -0800 Subject: [PATCH 12/16] Fixing the review comments on consistent namespace of sdk and namespace aliases in header files --- .vscode/settings.json | 7 + api/include/opentelemetry/trace/noop.h | 2 + .../opentelemetry/trace/span_context.h | 23 +- examples/batch/main.cc | 12 +- examples/grpc/client.cc | 2 +- examples/grpc/tracer_common.h | 33 +- examples/http/tracer_common.h | 24 +- examples/jaeger/main.cc | 16 +- examples/metrics_simple/main.cc | 20 +- examples/multi_processor/main.cc | 15 +- examples/multithreaded/main.cc | 10 +- examples/otlp/grpc_main.cc | 16 +- examples/otlp/http_main.cc | 16 +- examples/simple/main.cc | 11 +- examples/zipkin/main.cc | 18 +- .../exporters/elasticsearch/es_log_exporter.h | 10 +- .../opentelemetry/exporters/etw/etw_logger.h | 41 ++- .../exporters/etw/etw_logger_exporter.h | 2 - .../opentelemetry/exporters/etw/etw_tracer.h | 143 +++++---- .../exporters/etw/etw_tracer_exporter.h | 2 - .../exporters/jaeger/jaeger_exporter.h | 12 +- .../exporters/ostream/metrics_exporter.h | 22 +- .../exporters/ostream/span_exporter.h | 26 +- exporters/ostream/src/span_exporter.cc | 17 +- .../ostream/test/ostream_metrics_test.cc | 68 ++-- exporters/ostream/test/ostream_span_test.cc | 62 ++-- .../prometheus/prometheus_collector.h | 7 +- .../prometheus/prometheus_exporter_utils.h | 24 +- .../exporters/zipkin/zipkin_exporter.h | 12 +- .../ext/http/client/curl/http_client_curl.h | 85 +++-- .../http/client/curl/http_operation_curl.h | 52 +-- .../sdk/_metrics/aggregator/aggregator.h | 9 +- .../_metrics/aggregator/counter_aggregator.h | 4 +- .../_metrics/aggregator/exact_aggregator.h | 4 +- .../_metrics/aggregator/gauge_aggregator.h | 4 +- .../aggregator/histogram_aggregator.h | 4 +- .../aggregator/min_max_sum_count_aggregator.h | 4 +- .../_metrics/aggregator/sketch_aggregator.h | 6 +- .../sdk/_metrics/async_instruments.h | 28 +- .../opentelemetry/sdk/_metrics/controller.h | 6 +- .../opentelemetry/sdk/_metrics/instrument.h | 29 +- .../opentelemetry/sdk/_metrics/meter.h | 160 +++++----- .../opentelemetry/sdk/_metrics/processor.h | 6 +- .../opentelemetry/sdk/_metrics/record.h | 2 - .../sdk/_metrics/sync_instruments.h | 55 ++-- sdk/include/opentelemetry/sdk/trace/sampler.h | 12 +- .../sdk/trace/samplers/always_off.h | 10 +- .../sdk/trace/samplers/always_on.h | 10 +- .../opentelemetry/sdk/trace/samplers/parent.h | 10 +- .../sdk/trace/samplers/trace_id_ratio.h | 9 +- sdk/src/trace/samplers/parent.cc | 2 + sdk/src/trace/span.h | 26 +- sdk/test/_metrics/ungrouped_processor_test.cc | 300 +++++++++--------- sdk/test/trace/always_on_sampler_test.cc | 1 + 54 files changed, 765 insertions(+), 746 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000..e9ddeba5ba --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "files.associations": { + "typeinfo": "cpp", + "__locale": "cpp", + "memory": "cpp" + } +} \ No newline at end of file diff --git a/api/include/opentelemetry/trace/noop.h b/api/include/opentelemetry/trace/noop.h index 27cfaee4ad..1257ebd279 100644 --- a/api/include/opentelemetry/trace/noop.h +++ b/api/include/opentelemetry/trace/noop.h @@ -19,6 +19,8 @@ #include +namespace trace_api = opentelemetry::trace; + OPENTELEMETRY_BEGIN_NAMESPACE namespace trace { diff --git a/api/include/opentelemetry/trace/span_context.h b/api/include/opentelemetry/trace/span_context.h index a69a6d6230..da4ce37ce6 100644 --- a/api/include/opentelemetry/trace/span_context.h +++ b/api/include/opentelemetry/trace/span_context.h @@ -12,8 +12,6 @@ OPENTELEMETRY_BEGIN_NAMESPACE namespace trace { -namespace trace_api = opentelemetry::trace; - /* SpanContext contains the state that must propagate to child Spans and across * process boundaries. It contains TraceId and SpanId, TraceFlags, TraceState * and whether it was propagated from a remote parent. @@ -31,7 +29,7 @@ class SpanContext final SpanContext(bool sampled_flag, bool is_remote) : trace_id_(), span_id_(), - trace_flags_(trace_api::TraceFlags((uint8_t)sampled_flag)), + trace_flags_(trace::TraceFlags((uint8_t)sampled_flag)), is_remote_(is_remote), trace_state_(TraceState::GetDefault()) {} @@ -54,19 +52,16 @@ class SpanContext final bool IsValid() const noexcept { return trace_id_.IsValid() && span_id_.IsValid(); } // @returns the trace_flags associated with this span_context - const trace_api::TraceFlags &trace_flags() const noexcept { return trace_flags_; } + const trace::TraceFlags &trace_flags() const noexcept { return trace_flags_; } // @returns the trace_id associated with this span_context - const trace_api::TraceId &trace_id() const noexcept { return trace_id_; } + const trace::TraceId &trace_id() const noexcept { return trace_id_; } // @returns the span_id associated with this span_context - const trace_api::SpanId &span_id() const noexcept { return span_id_; } + const trace::SpanId &span_id() const noexcept { return span_id_; } // @returns the trace_state associated with this span_context - const nostd::shared_ptr trace_state() const noexcept - { - return trace_state_; - } + const nostd::shared_ptr trace_state() const noexcept { return trace_state_; } /* * @param that SpanContext for comparing. @@ -88,11 +83,11 @@ class SpanContext final bool IsSampled() const noexcept { return trace_flags_.IsSampled(); } private: - trace_api::TraceId trace_id_; - trace_api::SpanId span_id_; - trace_api::TraceFlags trace_flags_; + trace::TraceId trace_id_; + trace::SpanId span_id_; + trace::TraceFlags trace_flags_; bool is_remote_; - nostd::shared_ptr trace_state_; + nostd::shared_ptr trace_state_; }; } // namespace trace OPENTELEMETRY_END_NAMESPACE diff --git a/examples/batch/main.cc b/examples/batch/main.cc index a435abebe5..9a4606ef55 100644 --- a/examples/batch/main.cc +++ b/examples/batch/main.cc @@ -14,17 +14,19 @@ constexpr int kNumSpans = 10; namespace trace_api = opentelemetry::trace; namespace resource = opentelemetry::sdk::resource; namespace exporter_trace = opentelemetry::exporter::trace; +namespace trace_sdk = opentelemetry::sdk::trace; +namespace nostd = opentelemetry::nostd; namespace { void initTracer() { - auto exporter = std::unique_ptr(new exporter_trace::OStreamSpanExporter); + auto exporter = std::unique_ptr(new exporter_trace::OStreamSpanExporter); // CONFIGURE BATCH SPAN PROCESSOR PARAMETERS - sdktrace::BatchSpanProcessorOptions options{}; + trace_sdk::BatchSpanProcessorOptions options{}; // We make the queue size `KNumSpans`*2+5 because when the queue is half full, a preemptive notif // is sent to start an export call, which we want to avoid in this simple example. options.max_queue_size = kNumSpans * 2 + 5; @@ -36,11 +38,11 @@ void initTracer() resource::ResourceAttributes attributes = {{"service", "test_service"}, {"version", (uint32_t)1}}; auto resource = resource::Resource::Create(attributes); - auto processor = std::unique_ptr( - new sdktrace::BatchSpanProcessor(std::move(exporter), options)); + auto processor = std::unique_ptr( + new trace_sdk::BatchSpanProcessor(std::move(exporter), options)); auto provider = nostd::shared_ptr( - new sdktrace::TracerProvider(std::move(processor), resource)); + new trace_sdk::TracerProvider(std::move(processor), resource)); // Set the global trace provider. trace_api::Provider::SetTracerProvider(provider); } diff --git a/examples/grpc/client.cc b/examples/grpc/client.cc index 2b51058dba..bd520920d1 100644 --- a/examples/grpc/client.cc +++ b/examples/grpc/client.cc @@ -100,7 +100,7 @@ int main(int argc, char **argv) initTracer(); // set global propagator context::propagation::GlobalTextMapPropagator::SetGlobalPropagator( - nostd::shared_ptr( + opentelemetry::nostd::shared_ptr( new propagation::HttpTraceContext())); constexpr uint16_t default_port = 8800; uint16_t port; diff --git a/examples/grpc/tracer_common.h b/examples/grpc/tracer_common.h index 8d1df41ad4..13474a732f 100644 --- a/examples/grpc/tracer_common.h +++ b/examples/grpc/tracer_common.h @@ -27,9 +27,14 @@ class GrpcClientCarrier : public opentelemetry::context::propagation::TextMapCar public: GrpcClientCarrier(ClientContext *context) : context_(context) {} GrpcClientCarrier() = default; - virtual nostd::string_view Get(nostd::string_view key) const noexcept override { return ""; } + virtual opentelemetry::nostd::string_view Get( + opentelemetry::nostd::string_view key) const noexcept override + { + return ""; + } - virtual void Set(nostd::string_view key, nostd::string_view value) noexcept override + virtual void Set(opentelemetry::nostd::string_view key, + opentelemetry::nostd::string_view value) noexcept override { std::cout << " Client ::: Adding " << key << " " << value << "\n"; context_->AddMetadata(key.data(), value.data()); @@ -43,7 +48,8 @@ class GrpcServerCarrier : public opentelemetry::context::propagation::TextMapCar public: GrpcServerCarrier(ServerContext *context) : context_(context) {} GrpcServerCarrier() = default; - virtual nostd::string_view Get(nostd::string_view key) const noexcept override + virtual opentelemetry::nostd::string_view Get( + opentelemetry::nostd::string_view key) const noexcept override { auto it = context_->client_metadata().find(key.data()); if (it != context_->client_metadata().end()) @@ -53,7 +59,8 @@ class GrpcServerCarrier : public opentelemetry::context::propagation::TextMapCar return ""; } - virtual void Set(nostd::string_view key, nostd::string_view value) noexcept override + virtual void Set(opentelemetry::nostd::string_view key, + opentelemetry::nostd::string_view value) noexcept override { // Not required for server } @@ -63,26 +70,26 @@ class GrpcServerCarrier : public opentelemetry::context::propagation::TextMapCar void initTracer() { - auto exporter = std::unique_ptr( + auto exporter = std::unique_ptr( new opentelemetry::exporter::trace::OStreamSpanExporter); - auto processor = std::unique_ptr( - new sdktrace::SimpleSpanProcessor(std::move(exporter))); - std::vector> processors; + auto processor = std::unique_ptr( + new opentelemetry::sdk::trace::SimpleSpanProcessor(std::move(exporter))); + std::vector> processors; processors.push_back(std::move(processor)); // Default is an always-on sampler. - auto context = std::make_shared(std::move(processors)); - auto provider = nostd::shared_ptr( - new sdktrace::TracerProvider(context)); + auto context = std::make_shared(std::move(processors)); + auto provider = opentelemetry::nostd::shared_ptr( + new opentelemetry::sdk::trace::TracerProvider(context)); // Set the global trace provider opentelemetry::trace::Provider::SetTracerProvider(provider); // set global propagator opentelemetry::context::propagation::GlobalTextMapPropagator::SetGlobalPropagator( - nostd::shared_ptr( + opentelemetry::nostd::shared_ptr( new opentelemetry::trace::propagation::HttpTraceContext())); } -nostd::shared_ptr get_tracer(std::string tracer_name) +opentelemetry::nostd::shared_ptr get_tracer(std::string tracer_name) { auto provider = opentelemetry::trace::Provider::GetTracerProvider(); return provider->GetTracer(tracer_name); diff --git a/examples/http/tracer_common.h b/examples/http/tracer_common.h index 41dbfd29c1..619aed622b 100644 --- a/examples/http/tracer_common.h +++ b/examples/http/tracer_common.h @@ -26,7 +26,8 @@ class HttpTextMapCarrier : public opentelemetry::context::propagation::TextMapCa public: HttpTextMapCarrier(T &headers) : headers_(headers) {} HttpTextMapCarrier() = default; - virtual nostd::string_view Get(nostd::string_view key) const noexcept override + virtual opentelemetry::nostd::string_view Get( + opentelemetry::nostd::string_view key) const noexcept override { std::string key_to_compare = key.data(); // Header's first letter seems to be automatically capitaliazed by our test http-server, so @@ -47,7 +48,8 @@ class HttpTextMapCarrier : public opentelemetry::context::propagation::TextMapCa return ""; } - virtual void Set(nostd::string_view key, nostd::string_view value) noexcept override + virtual void Set(opentelemetry::nostd::string_view key, + opentelemetry::nostd::string_view value) noexcept override { headers_.insert(std::pair(std::string(key), std::string(value))); } @@ -57,26 +59,26 @@ class HttpTextMapCarrier : public opentelemetry::context::propagation::TextMapCa void initTracer() { - auto exporter = std::unique_ptr( + auto exporter = std::unique_ptr( new opentelemetry::exporter::trace::OStreamSpanExporter); - auto processor = std::unique_ptr( - new sdktrace::SimpleSpanProcessor(std::move(exporter))); - std::vector> processors; + auto processor = std::unique_ptr( + new opentelemetry::sdk::trace::SimpleSpanProcessor(std::move(exporter))); + std::vector> processors; processors.push_back(std::move(processor)); // Default is an always-on sampler. - auto context = std::make_shared(std::move(processors)); - auto provider = nostd::shared_ptr( - new sdktrace::TracerProvider(context)); + auto context = std::make_shared(std::move(processors)); + auto provider = opentelemetry::nostd::shared_ptr( + new opentelemetry::sdk::trace::TracerProvider(context)); // Set the global trace provider opentelemetry::trace::Provider::SetTracerProvider(provider); // set global propagator opentelemetry::context::propagation::GlobalTextMapPropagator::SetGlobalPropagator( - nostd::shared_ptr( + opentelemetry::nostd::shared_ptr( new opentelemetry::trace::propagation::HttpTraceContext())); } -nostd::shared_ptr get_tracer(std::string tracer_name) +opentelemetry::nostd::shared_ptr get_tracer(std::string tracer_name) { auto provider = opentelemetry::trace::Provider::GetTracerProvider(); return provider->GetTracer(tracer_name); diff --git a/examples/jaeger/main.cc b/examples/jaeger/main.cc index 4005e3960f..d0f507fd47 100644 --- a/examples/jaeger/main.cc +++ b/examples/jaeger/main.cc @@ -12,10 +12,10 @@ # include "foo_library/foo_library.h" #endif -namespace trace = opentelemetry::trace; -namespace nostd = opentelemetry::nostd; -namespace sdktrace = opentelemetry::sdk::trace; -namespace jaeger = opentelemetry::exporter::jaeger; +namespace trace = opentelemetry::trace; +namespace nostd = opentelemetry::nostd; +namespace trace_sdk = opentelemetry::sdk::trace; +namespace jaeger = opentelemetry::exporter::jaeger; namespace { @@ -23,11 +23,11 @@ opentelemetry::exporter::jaeger::JaegerExporterOptions opts; void InitTracer() { // Create Jaeger exporter instance - auto exporter = std::unique_ptr(new jaeger::JaegerExporter(opts)); - auto processor = std::unique_ptr( - new sdktrace::SimpleSpanProcessor(std::move(exporter))); + auto exporter = std::unique_ptr(new jaeger::JaegerExporter(opts)); + auto processor = std::unique_ptr( + new trace_sdk::SimpleSpanProcessor(std::move(exporter))); auto provider = - nostd::shared_ptr(new sdktrace::TracerProvider(std::move(processor))); + nostd::shared_ptr(new trace_sdk::TracerProvider(std::move(processor))); // Set the global trace provider trace::Provider::SetTracerProvider(provider); } diff --git a/examples/metrics_simple/main.cc b/examples/metrics_simple/main.cc index 99a0218c50..3a18a52f32 100644 --- a/examples/metrics_simple/main.cc +++ b/examples/metrics_simple/main.cc @@ -9,7 +9,7 @@ # include "opentelemetry/sdk/_metrics/meter_provider.h" # include "opentelemetry/sdk/_metrics/ungrouped_processor.h" -namespace sdkmetrics = opentelemetry::sdk::metrics; +namespace metric_sdk = opentelemetry::sdk::metrics; namespace nostd = opentelemetry::nostd; namespace common = opentelemetry::common; namespace exportermetrics = opentelemetry::exporter::metrics; @@ -18,18 +18,18 @@ namespace metrics_api = opentelemetry::metrics; int main() { // Initialize and set the global MeterProvider - auto provider = nostd::shared_ptr(new sdkmetrics::MeterProvider); + auto provider = nostd::shared_ptr(new metric_sdk::MeterProvider); metrics_api::Provider::SetMeterProvider(provider); // Get the Meter from the MeterProvider nostd::shared_ptr meter = provider->GetMeter("Test", "0.1.0"); // Create the controller with Stateless Metrics Processor - sdkmetrics::PushController ControllerStateless( + metric_sdk::PushController ControllerStateless( meter, - std::unique_ptr(new exportermetrics::OStreamMetricsExporter), - std::shared_ptr( - new sdkmetrics::UngroupedMetricsProcessor(false)), + std::unique_ptr(new exportermetrics::OStreamMetricsExporter), + std::shared_ptr( + new metric_sdk::UngroupedMetricsProcessor(false)), .05); // Create and instrument @@ -91,11 +91,11 @@ int main() ControllerStateless.stop(); // Do the same thing for stateful to see the difference - sdkmetrics::PushController ControllerStateful( + metric_sdk::PushController ControllerStateful( meter, - std::unique_ptr(new exportermetrics::OStreamMetricsExporter), - std::shared_ptr( - new sdkmetrics::UngroupedMetricsProcessor(true)), + std::unique_ptr(new exportermetrics::OStreamMetricsExporter), + std::shared_ptr( + new metric_sdk::UngroupedMetricsProcessor(true)), .05); // Start exporting from the Controller with Stateful Processor diff --git a/examples/multi_processor/main.cc b/examples/multi_processor/main.cc index dddecce38c..f57da5e228 100644 --- a/examples/multi_processor/main.cc +++ b/examples/multi_processor/main.cc @@ -18,6 +18,7 @@ using opentelemetry::exporter::memory::InMemorySpanExporter; namespace trace_api = opentelemetry::trace; namespace trace_sdk = opentelemetry::sdk::trace; +namespace nostd = opentelemetry::nostd; InMemorySpanExporter *memory_span_exporter; @@ -25,21 +26,21 @@ namespace { void initTracer() { - auto exporter1 = std::unique_ptr( + auto exporter1 = std::unique_ptr( new opentelemetry::exporter::trace::OStreamSpanExporter); - auto processor1 = std::unique_ptr( - new sdktrace::SimpleSpanProcessor(std::move(exporter1))); + auto processor1 = std::unique_ptr( + new trace_sdk::SimpleSpanProcessor(std::move(exporter1))); - auto exporter2 = std::unique_ptr(new InMemorySpanExporter()); + auto exporter2 = std::unique_ptr(new InMemorySpanExporter()); // fetch the exporter for dumping data later memory_span_exporter = dynamic_cast(exporter2.get()); - auto processor2 = std::unique_ptr( - new sdktrace::SimpleSpanProcessor(std::move(exporter2))); + auto processor2 = std::unique_ptr( + new trace_sdk::SimpleSpanProcessor(std::move(exporter2))); auto provider = nostd::shared_ptr( - new sdktrace::TracerProvider(std::move(processor1))); + new trace_sdk::TracerProvider(std::move(processor1))); provider->AddProcessor(std::move(processor2)); // Set the global trace provider trace_api::Provider::SetTracerProvider(std::move(provider)); diff --git a/examples/multithreaded/main.cc b/examples/multithreaded/main.cc index 16823b21d4..17efbb8bf5 100644 --- a/examples/multithreaded/main.cc +++ b/examples/multithreaded/main.cc @@ -14,16 +14,18 @@ #include namespace trace_api = opentelemetry::trace; +namespace trace_sdk = opentelemetry::sdk::trace; +namespace nostd = opentelemetry::nostd; namespace { void initTracer() { - auto exporter = std::unique_ptr( + auto exporter = std::unique_ptr( new opentelemetry::exporter::trace::OStreamSpanExporter); - auto processor = std::unique_ptr( - new sdktrace::SimpleSpanProcessor(std::move(exporter))); - auto provider = nostd::shared_ptr(new sdktrace::TracerProvider( + auto processor = std::unique_ptr( + new trace_sdk::SimpleSpanProcessor(std::move(exporter))); + auto provider = nostd::shared_ptr(new trace_sdk::TracerProvider( std::move(processor), opentelemetry::sdk::resource::Resource::Create({}))); // Set the global trace provider trace_api::Provider::SetTracerProvider(provider); diff --git a/examples/otlp/grpc_main.cc b/examples/otlp/grpc_main.cc index 303479f4a5..2e5eff486e 100644 --- a/examples/otlp/grpc_main.cc +++ b/examples/otlp/grpc_main.cc @@ -15,10 +15,10 @@ # include "foo_library/foo_library.h" #endif -namespace trace = opentelemetry::trace; -namespace nostd = opentelemetry::nostd; -namespace sdktrace = opentelemetry::sdk::trace; -namespace otlp = opentelemetry::exporter::otlp; +namespace trace = opentelemetry::trace; +namespace nostd = opentelemetry::nostd; +namespace trace_sdk = opentelemetry::sdk::trace; +namespace otlp = opentelemetry::exporter::otlp; namespace { @@ -26,11 +26,11 @@ opentelemetry::exporter::otlp::OtlpGrpcExporterOptions opts; void InitTracer() { // Create OTLP exporter instance - auto exporter = std::unique_ptr(new otlp::OtlpGrpcExporter(opts)); - auto processor = std::unique_ptr( - new sdktrace::SimpleSpanProcessor(std::move(exporter))); + auto exporter = std::unique_ptr(new otlp::OtlpGrpcExporter(opts)); + auto processor = std::unique_ptr( + new trace_sdk::SimpleSpanProcessor(std::move(exporter))); auto provider = - nostd::shared_ptr(new sdktrace::TracerProvider(std::move(processor))); + nostd::shared_ptr(new trace_sdk::TracerProvider(std::move(processor))); // Set the global trace provider trace::Provider::SetTracerProvider(provider); } diff --git a/examples/otlp/http_main.cc b/examples/otlp/http_main.cc index e4b1432724..8a0b07a142 100644 --- a/examples/otlp/http_main.cc +++ b/examples/otlp/http_main.cc @@ -14,10 +14,10 @@ # include "foo_library/foo_library.h" #endif -namespace trace = opentelemetry::trace; -namespace nostd = opentelemetry::nostd; -namespace sdktrace = opentelemetry::sdk::trace; -namespace otlp = opentelemetry::exporter::otlp; +namespace trace = opentelemetry::trace; +namespace nostd = opentelemetry::nostd; +namespace trace_sdk = opentelemetry::sdk::trace; +namespace otlp = opentelemetry::exporter::otlp; namespace { @@ -25,11 +25,11 @@ opentelemetry::exporter::otlp::OtlpHttpExporterOptions opts; void InitTracer() { // Create OTLP exporter instance - auto exporter = std::unique_ptr(new otlp::OtlpHttpExporter(opts)); - auto processor = std::unique_ptr( - new sdktrace::SimpleSpanProcessor(std::move(exporter))); + auto exporter = std::unique_ptr(new otlp::OtlpHttpExporter(opts)); + auto processor = std::unique_ptr( + new trace_sdk::SimpleSpanProcessor(std::move(exporter))); auto provider = - nostd::shared_ptr(new sdktrace::TracerProvider(std::move(processor))); + nostd::shared_ptr(new trace_sdk::TracerProvider(std::move(processor))); // Set the global trace provider trace::Provider::SetTracerProvider(provider); } diff --git a/examples/simple/main.cc b/examples/simple/main.cc index 604f9a492c..d022e5c23f 100644 --- a/examples/simple/main.cc +++ b/examples/simple/main.cc @@ -14,17 +14,18 @@ #include "opentelemetry/exporters/ostream/span_exporter.h" namespace trace_api = opentelemetry::trace; - +namespace trace_sdk = opentelemetry::sdk::trace; +namespace nostd = opentelemetry::nostd; namespace { void initTracer() { - auto exporter = std::unique_ptr( + auto exporter = std::unique_ptr( new opentelemetry::exporter::trace::OStreamSpanExporter); - auto processor = std::unique_ptr( - new sdktrace::SimpleSpanProcessor(std::move(exporter))); + auto processor = std::unique_ptr( + new trace_sdk::SimpleSpanProcessor(std::move(exporter))); auto provider = nostd::shared_ptr( - new sdktrace::TracerProvider(std::move(processor))); + new trace_sdk::TracerProvider(std::move(processor))); // Set the global trace provider trace_api::Provider::SetTracerProvider(provider); diff --git a/examples/zipkin/main.cc b/examples/zipkin/main.cc index 8fde8a48f1..3521147494 100644 --- a/examples/zipkin/main.cc +++ b/examples/zipkin/main.cc @@ -12,11 +12,11 @@ # include "foo_library/foo_library.h" #endif -namespace trace = opentelemetry::trace; -namespace nostd = opentelemetry::nostd; -namespace sdktrace = opentelemetry::sdk::trace; -namespace zipkin = opentelemetry::exporter::zipkin; -namespace resource = opentelemetry::sdk::resource; +namespace trace = opentelemetry::trace; +namespace nostd = opentelemetry::nostd; +namespace trace_sdk = opentelemetry::sdk::trace; +namespace zipkin = opentelemetry::exporter::zipkin; +namespace resource = opentelemetry::sdk::resource; namespace { @@ -26,11 +26,11 @@ void InitTracer() // Create zipkin exporter instance resource::ResourceAttributes attributes = {{"service.name", "zipkin_demo_service"}}; auto resource = resource::Resource::Create(attributes); - auto exporter = std::unique_ptr(new zipkin::ZipkinExporter(opts)); - auto processor = std::unique_ptr( - new sdktrace::SimpleSpanProcessor(std::move(exporter))); + auto exporter = std::unique_ptr(new zipkin::ZipkinExporter(opts)); + auto processor = std::unique_ptr( + new trace_sdk::SimpleSpanProcessor(std::move(exporter))); auto provider = nostd::shared_ptr( - new sdktrace::TracerProvider(std::move(processor), resource)); + new trace_sdk::TracerProvider(std::move(processor), resource)); // Set the global trace provider trace::Provider::SetTracerProvider(provider); } diff --git a/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_exporter.h b/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_exporter.h index 74d1edeba6..a14409af1d 100644 --- a/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_exporter.h +++ b/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_exporter.h @@ -13,9 +13,6 @@ # include # include -namespace nostd = opentelemetry::nostd; -namespace sdklogs = opentelemetry::sdk::logs; - OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { @@ -63,7 +60,7 @@ struct ElasticsearchExporterOptions /** * The ElasticsearchLogExporter exports logs to Elasticsearch in JSON format */ -class ElasticsearchLogExporter final : public sdklogs::LogExporter +class ElasticsearchLogExporter final : public opentelemetry::sdk::logs::LogExporter { public: /** @@ -80,7 +77,7 @@ class ElasticsearchLogExporter final : public sdklogs::LogExporter /** * Creates a recordable that stores the data in a JSON object */ - std::unique_ptr MakeRecordable() noexcept override; + std::unique_ptr MakeRecordable() noexcept override; /** * Exports a vector of log records to the Elasticsearch instance. Guaranteed to return after a @@ -88,7 +85,8 @@ class ElasticsearchLogExporter final : public sdklogs::LogExporter * @param records A list of log records to send to Elasticsearch. */ sdk::common::ExportResult Export( - const nostd::span> &records) noexcept override; + const opentelemetry::nostd::span> + &records) noexcept override; /** * Shutdown this exporter. diff --git a/exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h b/exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h index b0fc7c73ec..3420b3f5db 100644 --- a/exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h +++ b/exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h @@ -31,9 +31,6 @@ # include "opentelemetry/exporters/etw/etw_provider.h" # include "opentelemetry/exporters/etw/utils.h" -namespace logs = opentelemetry::logs; -namespace trace = opentelemetry::trace; - OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { @@ -45,7 +42,7 @@ class LoggerProvider; /** * @brief Logger class that allows to send logs to ETW Provider. */ -class Logger : public logs::Logger +class Logger : public opentelemetry::logs::Logger { /** @@ -94,21 +91,21 @@ class Logger : public logs::Logger Logger(etw::LoggerProvider &parent, nostd::string_view providerId = "", ETWProvider::EventFormat encoding = ETWProvider::EventFormat::ETW_MANIFEST) - : logs::Logger(), + : opentelemetry::logs::Logger(), loggerProvider_(parent), provId(providerId.data(), providerId.size()), encoding(encoding), provHandle(initProvHandle()) {} - void Log(logs::Severity severity, + void Log(opentelemetry::logs::Severity severity, nostd::string_view name, nostd::string_view body, const common::KeyValueIterable &resource, const common::KeyValueIterable &attributes, - trace::TraceId trace_id, - trace::SpanId span_id, - trace::TraceFlags trace_flags, + opentelemetry::trace::TraceId trace_id, + opentelemetry::trace::SpanId span_id, + opentelemetry::trace::TraceFlags trace_flags, common::SystemTimestamp timestamp) noexcept override { @@ -129,13 +126,13 @@ class Logger : public logs::Logger return Log(severity, name, body, evtCopy, trace_id, span_id, trace_flags, timestamp); } - virtual void Log(logs::Severity severity, + virtual void Log(opentelemetry::logs::Severity severity, nostd::string_view name, nostd::string_view body, Properties &evt, - trace::TraceId trace_id, - trace::SpanId span_id, - trace::TraceFlags trace_flags, + opentelemetry::trace::TraceId trace_id, + opentelemetry::trace::SpanId span_id, + opentelemetry::trace::TraceFlags trace_flags, common::SystemTimestamp timestamp) noexcept { // Populate Etw.EventName attribute at envelope level @@ -187,7 +184,7 @@ class Logger : public logs::Logger /** * @brief ETW LoggerProvider */ -class LoggerProvider : public logs::LoggerProvider +class LoggerProvider : public opentelemetry::logs::LoggerProvider { public: /** @@ -199,7 +196,7 @@ class LoggerProvider : public logs::LoggerProvider * @brief Construct instance of LoggerProvider with given options * @param options Configuration options */ - LoggerProvider(TelemetryProviderOptions options) : logs::LoggerProvider() + LoggerProvider(TelemetryProviderOptions options) : opentelemetry::logs::LoggerProvider() { GetOption(options, "enableTraceId", config_.enableTraceId, true); GetOption(options, "enableSpanId", config_.enableSpanId, true); @@ -209,7 +206,7 @@ class LoggerProvider : public logs::LoggerProvider config_.encoding = GetEncoding(options); } - LoggerProvider() : logs::LoggerProvider() + LoggerProvider() : opentelemetry::logs::LoggerProvider() { config_.encoding = ETWProvider::EventFormat::ETW_MANIFEST; } @@ -225,16 +222,18 @@ class LoggerProvider : public logs::LoggerProvider * - "XML" - XML events (reserved for future use) * @return */ - nostd::shared_ptr GetLogger(nostd::string_view name, - nostd::string_view args = "") override + nostd::shared_ptr GetLogger(nostd::string_view name, + nostd::string_view args = "") override { UNREFERENCED_PARAMETER(args); ETWProvider::EventFormat evtFmt = config_.encoding; - return nostd::shared_ptr{new (std::nothrow) etw::Logger(*this, name, evtFmt)}; + return nostd::shared_ptr{new (std::nothrow) + etw::Logger(*this, name, evtFmt)}; } - nostd::shared_ptr GetLogger(nostd::string_view name, - nostd::span args) override + nostd::shared_ptr GetLogger( + nostd::string_view name, + nostd::span args) override { return GetLogger(name, args[0]); } diff --git a/exporters/etw/include/opentelemetry/exporters/etw/etw_logger_exporter.h b/exporters/etw/include/opentelemetry/exporters/etw/etw_logger_exporter.h index 45dda860a4..936fe15ca5 100644 --- a/exporters/etw/include/opentelemetry/exporters/etw/etw_logger_exporter.h +++ b/exporters/etw/include/opentelemetry/exporters/etw/etw_logger_exporter.h @@ -27,6 +27,4 @@ # include "opentelemetry/exporters/etw/utils.h" -namespace logs = opentelemetry::logs; -namespace trace = opentelemetry::trace; #endif // ENABLE_LOGS_PREVIEW diff --git a/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h b/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h index f0e3ac5e58..0efbf66745 100644 --- a/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h +++ b/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h @@ -40,8 +40,6 @@ #include "opentelemetry/exporters/etw/etw_provider.h" #include "opentelemetry/exporters/etw/utils.h" -namespace trace = opentelemetry::trace; - OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { @@ -64,21 +62,22 @@ class Span; template SpanType *new_span(TracerType *objPtr, nostd::string_view name, - const trace::StartSpanOptions &options) + const opentelemetry::trace::StartSpanOptions &options) { return new (std::nothrow) SpanType{*objPtr, name, options}; } /** - * @brief Template that allows to convert etw::Span pointer to smart shared pointer to `trace::Span` + * @brief Template that allows to convert etw::Span pointer to smart shared pointer to + * `opentelemetry::trace::Span` * @tparam SpanType Expected to be etw::Span * @param ptr Pointer to etw::Span - * @return Smart shared pointer to `trace::Span` + * @return Smart shared pointer to `opentelemetry::trace::Span` */ template -nostd::shared_ptr to_span_ptr(SpanType *ptr) +nostd::shared_ptr to_span_ptr(SpanType *ptr) { - return nostd::shared_ptr{ptr}; + return nostd::shared_ptr{ptr}; } class TracerProvider; @@ -155,7 +154,7 @@ void UpdateStatus(T &t, Properties &props) /** * @brief Tracer class that allows to send spans to ETW Provider. */ -class Tracer : public trace::Tracer +class Tracer : public opentelemetry::trace::Tracer { /** @@ -178,7 +177,7 @@ class Tracer : public trace::Tracer */ ETWProvider::Handle &provHandle; - trace::TraceId traceId_; + opentelemetry::trace::TraceId traceId_; std::atomic isClosed_{true}; @@ -201,22 +200,23 @@ class Tracer : public trace::Tracer * @param links */ virtual void DecorateLinks(Properties &attributes, - const trace::SpanContextKeyValueIterable &links) const + const opentelemetry::trace::SpanContextKeyValueIterable &links) const { // Add `SpanLinks` attribute if the list is not empty if (links.size()) { size_t idx = 0; std::string linksValue; - links.ForEachKeyValue([&](trace::SpanContext ctx, const common::KeyValueIterable &) { - if (!linksValue.empty()) - { - linksValue += ','; - linksValue += ToLowerBase16(ctx.span_id()); - } - idx++; - return true; - }); + links.ForEachKeyValue( + [&](opentelemetry::trace::SpanContext ctx, const common::KeyValueIterable &) { + if (!linksValue.empty()) + { + linksValue += ','; + linksValue += ToLowerBase16(ctx.span_id()); + } + idx++; + return true; + }); attributes[ETW_FIELD_SPAN_LINKS] = linksValue; } } @@ -227,12 +227,13 @@ class Tracer : public trace::Tracer * @param */ virtual void EndSpan(const Span &span, - const trace::Span *parentSpan = nullptr, - const trace::EndSpanOptions & = {}) + const opentelemetry::trace::Span *parentSpan = nullptr, + const opentelemetry::trace::EndSpanOptions & = {}) { - const auto &cfg = GetConfiguration(tracerProvider_); - const trace::Span &spanBase = reinterpret_cast(span); - auto spanContext = spanBase.GetContext(); + const auto &cfg = GetConfiguration(tracerProvider_); + const opentelemetry::trace::Span &spanBase = + reinterpret_cast(span); + auto spanContext = spanBase.GetContext(); // Populate Span with presaved attributes Span ¤tSpan = const_cast(span); @@ -316,13 +317,13 @@ class Tracer : public trace::Tracer // Duration of Span in milliseconds evt[ETW_FIELD_DURATION] = endTimeMs - startTimeMs; // Presently we assume that all spans are server spans - evt[ETW_FIELD_SPAN_KIND] = uint32_t(trace::SpanKind::kServer); + evt[ETW_FIELD_SPAN_KIND] = uint32_t(opentelemetry::trace::SpanKind::kServer); UpdateStatus(currentSpan, evt); etwProvider().write(provHandle, evt, ActivityIdPtr, RelatedActivityIdPtr, 0, encoding); } } - const trace::TraceId &trace_id() { return traceId_; } + const opentelemetry::trace::TraceId &trace_id() { return traceId_; } friend class Span; @@ -346,7 +347,7 @@ class Tracer : public trace::Tracer Tracer(etw::TracerProvider &parent, nostd::string_view providerId = "", ETWProvider::EventFormat encoding = ETWProvider::EventFormat::ETW_MANIFEST) - : trace::Tracer(), + : opentelemetry::trace::Tracer(), tracerProvider_(parent), provId(providerId.data(), providerId.size()), encoding(encoding), @@ -357,9 +358,9 @@ class Tracer : public trace::Tracer CoCreateGuid(&trace_id); // Populate TraceId of the Tracer with the above GUID const auto *traceIdPtr = reinterpret_cast(std::addressof(trace_id)); - nostd::span traceIdBytes( - traceIdPtr, traceIdPtr + trace::TraceId::kSize); - traceId_ = trace::TraceId(traceIdBytes); + nostd::span traceIdBytes( + traceIdPtr, traceIdPtr + opentelemetry::trace::TraceId::kSize); + traceId_ = opentelemetry::trace::TraceId(traceIdBytes); } /** @@ -370,11 +371,11 @@ class Tracer : public trace::Tracer * @param options Span options * @return */ - nostd::shared_ptr StartSpan( + nostd::shared_ptr StartSpan( nostd::string_view name, const common::KeyValueIterable &attributes, - const trace::SpanContextKeyValueIterable &links, - const trace::StartSpanOptions &options = {}) noexcept override + const opentelemetry::trace::SpanContextKeyValueIterable &links, + const opentelemetry::trace::StartSpanOptions &options = {}) noexcept override { #ifdef RTTI_ENABLED common::KeyValueIterable &attribs = const_cast(attributes); @@ -397,21 +398,21 @@ class Tracer : public trace::Tracer * @param options Span options * @return */ - virtual nostd::shared_ptr StartSpan( + virtual nostd::shared_ptr StartSpan( nostd::string_view name, Properties &evt, - const trace::SpanContextKeyValueIterable &links, - const trace::StartSpanOptions &options = {}) noexcept + const opentelemetry::trace::SpanContextKeyValueIterable &links, + const opentelemetry::opentelemetry::trace::StartSpanOptions &options = {}) noexcept { const auto &cfg = GetConfiguration(tracerProvider_); // Parent Context: // - either use current span // - or attach to parent SpanContext specified in options - trace::SpanContext parentContext = GetCurrentSpan()->GetContext(); - if (nostd::holds_alternative(options.parent)) + opentelemetry::trace::SpanContext parentContext = GetCurrentSpan()->GetContext(); + if (nostd::holds_alternative(options.parent)) { - auto span_context = nostd::get(options.parent); + auto span_context = nostd::get(options.parent); if (span_context.IsValid()) { parentContext = span_context; @@ -434,8 +435,8 @@ class Tracer : public trace::Tracer // This template pattern allows us to forward-declare the etw::Span, // create an instance of it, then assign it to tracer::Span result. - auto currentSpan = new_span(this, name, options); - nostd::shared_ptr result = to_span_ptr(currentSpan); + auto currentSpan = new_span(this, name, options); + nostd::shared_ptr result = to_span_ptr(currentSpan); auto spanContext = result->GetContext(); @@ -525,7 +526,7 @@ class Tracer : public trace::Tracer * @param attributes Event attributes. * @return */ - void AddEvent(trace::Span &span, + void AddEvent(opentelemetry::trace::Span &span, nostd::string_view name, common::SystemTimestamp timestamp, const common::KeyValueIterable &attributes) noexcept @@ -552,7 +553,7 @@ class Tracer : public trace::Tracer * @param attributes Event attributes. * @return */ - void AddEvent(trace::Span &span, + void AddEvent(opentelemetry::trace::Span &span, nostd::string_view name, common::SystemTimestamp timestamp, Properties &evt) noexcept @@ -610,7 +611,7 @@ class Tracer : public trace::Tracer * @param timestamp Event timestamp. * @return */ - void AddEvent(trace::Span &span, + void AddEvent(opentelemetry::trace::Span &span, nostd::string_view name, common::SystemTimestamp timestamp) noexcept { @@ -622,7 +623,7 @@ class Tracer : public trace::Tracer * @param span Spab. * @param name Event name. */ - void AddEvent(trace::Span &span, nostd::string_view name) + void AddEvent(opentelemetry::trace::Span &span, nostd::string_view name) { AddEvent(span, name, std::chrono::system_clock::now(), sdk::GetEmptyAttributes()); } @@ -636,7 +637,7 @@ class Tracer : public trace::Tracer /** * @brief etw::Span allows to send event data to ETW listener. */ -class Span : public trace::Span +class Span : public opentelemetry::trace::Span { protected: friend class Tracer; @@ -649,7 +650,7 @@ class Span : public trace::Span common::SystemTimestamp start_time_; common::SystemTimestamp end_time_; - trace::StatusCode status_code_{trace::StatusCode::kUnset}; + opentelemetry::trace::StatusCode status_code_{opentelemetry::trace::StatusCode::kUnset}; std::string status_description_; /** @@ -683,9 +684,9 @@ class Span : public trace::Span */ Span *GetParent() const { return parent_; } - trace::SpanContext context_; + opentelemetry::trace::SpanContext context_; - const trace::SpanContext CreateContext() + const opentelemetry::trace::SpanContext CreateContext() { GUID activity_id; // Generate random GUID @@ -693,17 +694,17 @@ class Span : public trace::Span const auto *activityIdPtr = reinterpret_cast(std::addressof(activity_id)); // Populate SpanId with that GUID - nostd::span spanIdBytes( - activityIdPtr, activityIdPtr + trace::SpanId::kSize); - const trace::SpanId spanId(spanIdBytes); + nostd::span spanIdBytes( + activityIdPtr, activityIdPtr + opentelemetry::trace::SpanId::kSize); + const opentelemetry::trace::SpanId spanId(spanIdBytes); // Inherit trace_id from Tracer - const trace::TraceId traceId{owner_.trace_id()}; + const opentelemetry::trace::TraceId traceId{owner_.trace_id()}; // TODO: TraceFlags are not supported by ETW exporter. - const trace::TraceFlags flags{0}; + const opentelemetry::trace::TraceFlags flags{0}; // TODO: Remote parent is not supported by ETW exporter. const bool hasRemoteParent = false; - return trace::SpanContext{traceId, spanId, flags, hasRemoteParent}; + return opentelemetry::trace::SpanContext{traceId, spanId, flags, hasRemoteParent}; } public: @@ -714,7 +715,8 @@ class Span : public trace::Span void UpdateStatus(Properties &evt) { /* Should we avoid populating this extra field if status is unset? */ - if ((status_code_ == trace::StatusCode::kUnset) || (status_code_ == trace::StatusCode::kOk)) + if ((status_code_ == opentelemetry::trace::StatusCode::kUnset) || + (status_code_ == opentelemetry::trace::StatusCode::kOk)) { evt[ETW_FIELD_SUCCESS] = "True"; evt[ETW_FIELD_STATUSCODE] = uint32_t(status_code_); @@ -756,9 +758,9 @@ class Span : public trace::Span */ Span(Tracer &owner, nostd::string_view name, - const trace::StartSpanOptions &options, + const opentelemetry::trace::StartSpanOptions &options, Span *parent = nullptr) noexcept - : trace::Span(), + : opentelemetry::trace::Span(), owner_(owner), parent_(parent), context_(CreateContext()), @@ -811,7 +813,8 @@ class Span : public trace::Span * @param description Span description. * @return */ - void SetStatus(trace::StatusCode code, nostd::string_view description) noexcept override + void SetStatus(opentelemetry::trace::StatusCode code, + nostd::string_view description) noexcept override { status_code_ = code; status_description_ = description.data(); @@ -865,7 +868,7 @@ class Span : public trace::Span * @param EndSpanOptions * @return */ - void End(const trace::EndSpanOptions &options = {}) noexcept override + void End(const opentelemetry::trace::EndSpanOptions &options = {}) noexcept override { end_time_ = std::chrono::system_clock::now(); @@ -879,7 +882,7 @@ class Span : public trace::Span * @brief Obtain SpanContext * @return */ - trace::SpanContext GetContext() const noexcept override { return context_; } + opentelemetry::trace::SpanContext GetContext() const noexcept override { return context_; } /** * @brief Check if Span is recording data. @@ -903,13 +906,13 @@ class Span : public trace::Span /// Get Owner tracer of this Span /// /// - trace::Tracer &tracer() const noexcept { return this->owner_; } + opentelemetry::trace::Tracer &tracer() const noexcept { return this->owner_; } }; /** * @brief ETW TracerProvider */ -class TracerProvider : public trace::TracerProvider +class TracerProvider : public opentelemetry::trace::TracerProvider { public: /** @@ -921,7 +924,7 @@ class TracerProvider : public trace::TracerProvider * @brief Construct instance of TracerProvider with given options * @param options Configuration options */ - TracerProvider(TelemetryProviderOptions options) : trace::TracerProvider() + TracerProvider(TelemetryProviderOptions options) : opentelemetry::trace::TracerProvider() { // By default we ensure that all events carry their with TraceId and SpanId GetOption(options, "enableTraceId", config_.enableTraceId, true); @@ -952,7 +955,7 @@ class TracerProvider : public trace::TracerProvider config_.encoding = GetEncoding(options); } - TracerProvider() : trace::TracerProvider() + TracerProvider() : opentelemetry::trace::TracerProvider() { config_.enableTraceId = true; config_.enableSpanId = true; @@ -974,14 +977,16 @@ class TracerProvider : public trace::TracerProvider * - "XML" - XML events (reserved for future use) * @return */ - nostd::shared_ptr GetTracer(nostd::string_view name, - nostd::string_view args = "", - nostd::string_view schema_url = "") override + nostd::shared_ptr GetTracer( + nostd::string_view name, + nostd::string_view args = "", + nostd::string_view schema_url = "") override { UNREFERENCED_PARAMETER(args); UNREFERENCED_PARAMETER(schema_url); ETWProvider::EventFormat evtFmt = config_.encoding; - return nostd::shared_ptr{new (std::nothrow) Tracer(*this, name, evtFmt)}; + return nostd::shared_ptr{new (std::nothrow) + Tracer(*this, name, evtFmt)}; } }; diff --git a/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer_exporter.h b/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer_exporter.h index 4c12681021..b28f1a0219 100644 --- a/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer_exporter.h +++ b/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer_exporter.h @@ -26,5 +26,3 @@ #include "opentelemetry/exporters/etw/etw_tracer.h" #include "opentelemetry/exporters/etw/utils.h" - -namespace trace = opentelemetry::trace; diff --git a/exporters/jaeger/include/opentelemetry/exporters/jaeger/jaeger_exporter.h b/exporters/jaeger/include/opentelemetry/exporters/jaeger/jaeger_exporter.h index 31f6a8bf35..da2ed33719 100644 --- a/exporters/jaeger/include/opentelemetry/exporters/jaeger/jaeger_exporter.h +++ b/exporters/jaeger/include/opentelemetry/exporters/jaeger/jaeger_exporter.h @@ -33,10 +33,7 @@ struct JaegerExporterOptions ext::http::client::Headers headers; }; -namespace trace_sdk = opentelemetry::sdk::trace; -namespace sdk_common = opentelemetry::sdk::common; - -class JaegerExporter final : public trace_sdk::SpanExporter +class JaegerExporter final : public opentelemetry::sdk::trace::SpanExporter { public: /** @@ -53,14 +50,15 @@ class JaegerExporter final : public trace_sdk::SpanExporter * Create a span recordable. * @return a new initialized Recordable object. */ - std::unique_ptr MakeRecordable() noexcept override; + std::unique_ptr MakeRecordable() noexcept override; /** * Export a batch of spans. * @param spans a span of unique pointers to span recordables. */ - sdk_common::ExportResult Export( - const nostd::span> &spans) noexcept override; + opentelemetry::sdk::common::ExportResult Export( + const nostd::span> &spans) noexcept + override; /** * Shutdown the exporter. diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/metrics_exporter.h b/exporters/ostream/include/opentelemetry/exporters/ostream/metrics_exporter.h index 82eceb18e0..5ae168aa0d 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/metrics_exporter.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/metrics_exporter.h @@ -13,8 +13,6 @@ # include "opentelemetry/sdk/_metrics/record.h" OPENTELEMETRY_BEGIN_NAMESPACE -namespace sdkmetrics = opentelemetry::sdk::metrics; - namespace exporter { namespace metrics @@ -23,7 +21,7 @@ namespace metrics /** * The OStreamMetricsExporter exports record data through an ostream */ -class OStreamMetricsExporter final : public sdkmetrics::MetricsExporter +class OStreamMetricsExporter final : public opentelemetry::sdk::metrics::MetricsExporter { public: /** @@ -34,7 +32,7 @@ class OStreamMetricsExporter final : public sdkmetrics::MetricsExporter explicit OStreamMetricsExporter(std::ostream &sout = std::cout) noexcept; sdk::common::ExportResult Export( - const std::vector &records) noexcept override; + const std::vector &records) noexcept override; private: std::ostream &sout_; @@ -45,33 +43,33 @@ class OStreamMetricsExporter final : public sdkmetrics::MetricsExporter * custom printing. */ template - void PrintAggregatorVariant(sdkmetrics::AggregatorVariant value) + void PrintAggregatorVariant(opentelemetry::sdk::metrics::AggregatorVariant value) { - auto agg = nostd::get>>(value); + auto agg = nostd::get>>(value); auto aggKind = agg->get_aggregator_kind(); if (!agg) return; switch (aggKind) { - case sdkmetrics::AggregatorKind::Counter: { + case opentelemetry::sdk::metrics::AggregatorKind::Counter: { sout_ << "\n sum : " << agg->get_checkpoint()[0]; } break; - case sdkmetrics::AggregatorKind::MinMaxSumCount: { + case opentelemetry::sdk::metrics::AggregatorKind::MinMaxSumCount: { auto mmsc = agg->get_checkpoint(); sout_ << "\n min : " << mmsc[0] << "\n max : " << mmsc[1] << "\n sum : " << mmsc[2] << "\n count : " << mmsc[3]; } break; - case sdkmetrics::AggregatorKind::Gauge: { + case opentelemetry::sdk::metrics::AggregatorKind::Gauge: { auto timestamp = agg->get_checkpoint_timestamp(); sout_ << "\n last value : " << agg->get_checkpoint()[0] << "\n timestamp : " << std::to_string(timestamp.time_since_epoch().count()); } break; - case sdkmetrics::AggregatorKind::Exact: { + case opentelemetry::sdk::metrics::AggregatorKind::Exact: { // TODO: Find better way to print quantiles if (agg->get_quant_estimation()) { @@ -101,7 +99,7 @@ class OStreamMetricsExporter final : public sdkmetrics::MetricsExporter } } break; - case sdkmetrics::AggregatorKind::Histogram: { + case opentelemetry::sdk::metrics::AggregatorKind::Histogram: { auto boundaries = agg->get_boundaries(); auto counts = agg->get_counts(); @@ -130,7 +128,7 @@ class OStreamMetricsExporter final : public sdkmetrics::MetricsExporter sout_ << ']'; } break; - case sdkmetrics::AggregatorKind::Sketch: { + case opentelemetry::sdk::metrics::AggregatorKind::Sketch: { auto boundaries = agg->get_boundaries(); auto counts = agg->get_counts(); diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h b/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h index 52849b5c18..58c52989a2 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h @@ -12,10 +12,6 @@ #include #include -namespace nostd = opentelemetry::nostd; -namespace sdktrace = opentelemetry::sdk::trace; -namespace sdkcommon = opentelemetry::sdk::common; - OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { @@ -25,7 +21,7 @@ namespace trace /** * The OStreamSpanExporter exports span data through an ostream */ -class OStreamSpanExporter final : public sdktrace::SpanExporter +class OStreamSpanExporter final : public opentelemetry::sdk::trace::SpanExporter { public: /** @@ -35,10 +31,11 @@ class OStreamSpanExporter final : public sdktrace::SpanExporter */ explicit OStreamSpanExporter(std::ostream &sout = std::cout) noexcept; - std::unique_ptr MakeRecordable() noexcept override; + std::unique_ptr MakeRecordable() noexcept override; sdk::common::ExportResult Export( - const nostd::span> &spans) noexcept override; + const opentelemetry::nostd::span> + &spans) noexcept override; bool Shutdown( std::chrono::microseconds timeout = std::chrono::microseconds::max()) noexcept override; @@ -98,12 +95,12 @@ class OStreamSpanExporter final : public sdktrace::SpanExporter #endif - void print_value(const sdkcommon::OwnedAttributeValue &value) + void print_value(const opentelemetry::sdk::common::OwnedAttributeValue &value) { #if __cplusplus < 201402L - nostd::visit(OwnedAttributeValueVisitor(*this), value); + opentelemetry::nostd::visit(OwnedAttributeValueVisitor(*this), value); #else - nostd::visit( + opentelemetry::nostd::visit( [this](auto &&arg) { /* explicit this is needed by some gcc versions (observed with v5.4.0)*/ this->print_value(arg); @@ -113,12 +110,13 @@ class OStreamSpanExporter final : public sdktrace::SpanExporter } // various print helpers - void printAttributes(const std::unordered_map &map, - const std::string prefix = "\n\t"); + void printAttributes( + const std::unordered_map &map, + const std::string prefix = "\n\t"); - void printEvents(const std::vector &events); + void printEvents(const std::vector &events); - void printLinks(const std::vector &links); + void printLinks(const std::vector &links); void printResources(const opentelemetry::sdk::resource::Resource &resources); diff --git a/exporters/ostream/src/span_exporter.cc b/exporters/ostream/src/span_exporter.cc index df4c674424..48d81f0d69 100644 --- a/exporters/ostream/src/span_exporter.cc +++ b/exporters/ostream/src/span_exporter.cc @@ -6,8 +6,9 @@ #include namespace nostd = opentelemetry::nostd; -namespace sdktrace = opentelemetry::sdk::trace; +namespace trace_sdk = opentelemetry::sdk::trace; namespace trace_api = opentelemetry::trace; +namespace sdkcommon = opentelemetry::sdk::common; OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -35,13 +36,13 @@ std::ostream &operator<<(std::ostream &os, trace_api::SpanKind span_kind) OStreamSpanExporter::OStreamSpanExporter(std::ostream &sout) noexcept : sout_(sout) {} -std::unique_ptr OStreamSpanExporter::MakeRecordable() noexcept +std::unique_ptr OStreamSpanExporter::MakeRecordable() noexcept { - return std::unique_ptr(new sdktrace::SpanData); + return std::unique_ptr(new trace_sdk::SpanData); } sdk::common::ExportResult OStreamSpanExporter::Export( - const nostd::span> &spans) noexcept + const nostd::span> &spans) noexcept { if (isShutdown_) { @@ -50,8 +51,8 @@ sdk::common::ExportResult OStreamSpanExporter::Export( for (auto &recordable : spans) { - auto span = std::unique_ptr( - static_cast(recordable.release())); + auto span = std::unique_ptr( + static_cast(recordable.release())); if (span != nullptr) { @@ -109,7 +110,7 @@ void OStreamSpanExporter::printAttributes( } } -void OStreamSpanExporter::printEvents(const std::vector &events) +void OStreamSpanExporter::printEvents(const std::vector &events) { for (const auto &event : events) { @@ -122,7 +123,7 @@ void OStreamSpanExporter::printEvents(const std::vector } } -void OStreamSpanExporter::printLinks(const std::vector &links) +void OStreamSpanExporter::printLinks(const std::vector &links) { for (const auto &link : links) { diff --git a/exporters/ostream/test/ostream_metrics_test.cc b/exporters/ostream/test/ostream_metrics_test.cc index 94507e4ed3..f5539c3d49 100644 --- a/exporters/ostream/test/ostream_metrics_test.cc +++ b/exporters/ostream/test/ostream_metrics_test.cc @@ -15,7 +15,7 @@ # include -namespace sdkmetrics = opentelemetry::sdk::metrics; +namespace metric_sdk = opentelemetry::sdk::metrics; namespace metrics_api = opentelemetry::metrics; namespace nostd = opentelemetry::nostd; namespace exportermetrics = opentelemetry::exporter::metrics; @@ -23,16 +23,16 @@ namespace exportermetrics = opentelemetry::exporter::metrics; TEST(OStreamMetricsExporter, PrintCounter) { auto exporter = - std::unique_ptr(new exportermetrics::OStreamMetricsExporter); + std::unique_ptr(new exportermetrics::OStreamMetricsExporter); - auto aggregator = std::shared_ptr>( - new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); + auto aggregator = std::shared_ptr>( + new metric_sdk::CounterAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(5.5); aggregator->checkpoint(); - sdkmetrics::Record r("name", "description", "labels", aggregator); - std::vector records; + metric_sdk::Record r("name", "description", "labels", aggregator); + std::vector records; records.push_back(r); // Create stringstream to redirect to @@ -62,17 +62,17 @@ TEST(OStreamMetricsExporter, PrintCounter) TEST(OStreamMetricsExporter, PrintMinMaxSumCount) { auto exporter = - std::unique_ptr(new exportermetrics::OStreamMetricsExporter); + std::unique_ptr(new exportermetrics::OStreamMetricsExporter); - auto aggregator = std::shared_ptr>( - new sdkmetrics::MinMaxSumCountAggregator(metrics_api::InstrumentKind::Counter)); + auto aggregator = std::shared_ptr>( + new metric_sdk::MinMaxSumCountAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(1); aggregator->update(2); aggregator->checkpoint(); - sdkmetrics::Record r("name", "description", "labels", aggregator); - std::vector records; + metric_sdk::Record r("name", "description", "labels", aggregator); + std::vector records; records.push_back(r); // Create stringstream to redirect to @@ -105,17 +105,17 @@ TEST(OStreamMetricsExporter, PrintMinMaxSumCount) TEST(OStreamMetricsExporter, PrintGauge) { auto exporter = - std::unique_ptr(new exportermetrics::OStreamMetricsExporter); + std::unique_ptr(new exportermetrics::OStreamMetricsExporter); - auto aggregator = std::shared_ptr>( - new sdkmetrics::GaugeAggregator(metrics_api::InstrumentKind::Counter)); + auto aggregator = std::shared_ptr>( + new metric_sdk::GaugeAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(1); aggregator->update(9); aggregator->checkpoint(); - sdkmetrics::Record r("name", "description", "labels", aggregator); - std::vector records; + metric_sdk::Record r("name", "description", "labels", aggregator); + std::vector records; records.push_back(r); // Create stringstream to redirect to @@ -148,13 +148,13 @@ TEST(OStreamMetricsExporter, PrintGauge) TEST(OStreamMetricsExporter, PrintExact) { auto exporter = - std::unique_ptr(new exportermetrics::OStreamMetricsExporter); + std::unique_ptr(new exportermetrics::OStreamMetricsExporter); - auto aggregator = std::shared_ptr>( - new sdkmetrics::ExactAggregator(metrics_api::InstrumentKind::Counter, true)); + auto aggregator = std::shared_ptr>( + new metric_sdk::ExactAggregator(metrics_api::InstrumentKind::Counter, true)); - auto aggregator2 = std::shared_ptr>( - new sdkmetrics::ExactAggregator(metrics_api::InstrumentKind::Counter, false)); + auto aggregator2 = std::shared_ptr>( + new metric_sdk::ExactAggregator(metrics_api::InstrumentKind::Counter, false)); for (int i = 0; i < 10; i++) { @@ -164,9 +164,9 @@ TEST(OStreamMetricsExporter, PrintExact) aggregator->checkpoint(); aggregator2->checkpoint(); - sdkmetrics::Record r("name", "description", "labels", aggregator); - sdkmetrics::Record r2("name", "description", "labels", aggregator2); - std::vector records; + metric_sdk::Record r("name", "description", "labels", aggregator); + metric_sdk::Record r2("name", "description", "labels", aggregator2); + std::vector records; records.push_back(r); records.push_back(r2); @@ -203,11 +203,11 @@ TEST(OStreamMetricsExporter, PrintExact) TEST(OStreamMetricsExporter, PrintHistogram) { auto exporter = - std::unique_ptr(new exportermetrics::OStreamMetricsExporter); + std::unique_ptr(new exportermetrics::OStreamMetricsExporter); std::vector boundaries{10, 20, 30, 40, 50}; - auto aggregator = std::shared_ptr>( - new sdkmetrics::HistogramAggregator(metrics_api::InstrumentKind::Counter, boundaries)); + auto aggregator = std::shared_ptr>( + new metric_sdk::HistogramAggregator(metrics_api::InstrumentKind::Counter, boundaries)); for (float i = 0; i < 60; i++) { @@ -215,8 +215,8 @@ TEST(OStreamMetricsExporter, PrintHistogram) } aggregator->checkpoint(); - sdkmetrics::Record r("name", "description", "labels", aggregator); - std::vector records; + metric_sdk::Record r("name", "description", "labels", aggregator); + std::vector records; records.push_back(r); // Create stringstream to redirect to @@ -247,11 +247,11 @@ TEST(OStreamMetricsExporter, PrintHistogram) TEST(OStreamMetricsExporter, PrintSketch) { auto exporter = - std::unique_ptr(new exportermetrics::OStreamMetricsExporter); + std::unique_ptr(new exportermetrics::OStreamMetricsExporter); std::vector boundaries{1, 3, 5, 7, 9}; - auto aggregator = std::shared_ptr>( - new sdkmetrics::SketchAggregator(metrics_api::InstrumentKind::Counter, .000005)); + auto aggregator = std::shared_ptr>( + new metric_sdk::SketchAggregator(metrics_api::InstrumentKind::Counter, .000005)); for (int i = 0; i < 10; i++) { @@ -259,8 +259,8 @@ TEST(OStreamMetricsExporter, PrintSketch) } aggregator->checkpoint(); - sdkmetrics::Record r("name", "description", "labels", aggregator); - std::vector records; + metric_sdk::Record r("name", "description", "labels", aggregator); + std::vector records; records.push_back(r); // Create stringstream to redirect to diff --git a/exporters/ostream/test/ostream_span_test.cc b/exporters/ostream/test/ostream_span_test.cc index 1ebe898b26..4d0ca8728e 100644 --- a/exporters/ostream/test/ostream_span_test.cc +++ b/exporters/ostream/test/ostream_span_test.cc @@ -22,7 +22,7 @@ using namespace opentelemetry::exporter::ostream::test; namespace trace = opentelemetry::trace; namespace common = opentelemetry::common; namespace nostd = opentelemetry::nostd; -namespace sdktrace = opentelemetry::sdk::trace; +namespace trace_sdk = opentelemetry::sdk::trace; namespace resource = opentelemetry::sdk::resource; namespace exportertrace = opentelemetry::exporter::trace; @@ -39,9 +39,9 @@ class TestResource : public resource::Resource // Testing Shutdown functionality of OStreamSpanExporter, should expect no data to be sent to Stream TEST(OStreamSpanExporter, Shutdown) { - auto exporter = std::unique_ptr(new exportertrace::OStreamSpanExporter); - auto processor = std::shared_ptr( - new sdktrace::SimpleSpanProcessor(std::move(exporter))); + auto exporter = std::unique_ptr(new exportertrace::OStreamSpanExporter); + auto processor = std::shared_ptr( + new trace_sdk::SimpleSpanProcessor(std::move(exporter))); auto recordable = processor->MakeRecordable(); recordable->SetName("Test Span"); @@ -79,9 +79,9 @@ TEST(OStreamSpanExporter, PrintDefaultSpan) { std::stringstream output; auto exporter = - std::unique_ptr(new exportertrace::OStreamSpanExporter(output)); - auto processor = std::shared_ptr( - new sdktrace::SimpleSpanProcessor(std::move(exporter))); + std::unique_ptr(new exportertrace::OStreamSpanExporter(output)); + auto processor = std::shared_ptr( + new trace_sdk::SimpleSpanProcessor(std::move(exporter))); auto recordable = processor->MakeRecordable(); @@ -94,9 +94,9 @@ TEST(OStreamSpanExporter, PrintSpanWithBasicFields) { std::stringstream output; auto exporter = - std::unique_ptr(new exportertrace::OStreamSpanExporter(output)); - auto processor = std::shared_ptr( - new sdktrace::SimpleSpanProcessor(std::move(exporter))); + std::unique_ptr(new exportertrace::OStreamSpanExporter(output)); + auto processor = std::shared_ptr( + new trace_sdk::SimpleSpanProcessor(std::move(exporter))); auto recordable = processor->MakeRecordable(); @@ -153,9 +153,9 @@ TEST(OStreamSpanExporter, PrintSpanWithAttribute) { std::stringstream output; auto exporter = - std::unique_ptr(new exportertrace::OStreamSpanExporter(output)); - auto processor = std::shared_ptr( - new sdktrace::SimpleSpanProcessor(std::move(exporter))); + std::unique_ptr(new exportertrace::OStreamSpanExporter(output)); + auto processor = std::shared_ptr( + new trace_sdk::SimpleSpanProcessor(std::move(exporter))); auto recordable = processor->MakeRecordable(); @@ -189,9 +189,9 @@ TEST(OStreamSpanExporter, PrintSpanWithArrayAttribute) { std::stringstream output; auto exporter = - std::unique_ptr(new exportertrace::OStreamSpanExporter(output)); - auto processor = std::shared_ptr( - new sdktrace::SimpleSpanProcessor(std::move(exporter))); + std::unique_ptr(new exportertrace::OStreamSpanExporter(output)); + auto processor = std::shared_ptr( + new trace_sdk::SimpleSpanProcessor(std::move(exporter))); auto recordable = processor->MakeRecordable(); @@ -227,9 +227,9 @@ TEST(OStreamSpanExporter, PrintSpanWithEvents) { std::stringstream output; auto exporter = - std::unique_ptr(new exportertrace::OStreamSpanExporter(output)); - auto processor = std::shared_ptr( - new sdktrace::SimpleSpanProcessor(std::move(exporter))); + std::unique_ptr(new exportertrace::OStreamSpanExporter(output)); + auto processor = std::shared_ptr( + new trace_sdk::SimpleSpanProcessor(std::move(exporter))); auto recordable = processor->MakeRecordable(); common::SystemTimestamp now(std::chrono::system_clock::now()); @@ -284,9 +284,9 @@ TEST(OStreamSpanExporter, PrintSpanWithLinks) { std::stringstream output; auto exporter = - std::unique_ptr(new exportertrace::OStreamSpanExporter(output)); - auto processor = std::shared_ptr( - new sdktrace::SimpleSpanProcessor(std::move(exporter))); + std::unique_ptr(new exportertrace::OStreamSpanExporter(output)); + auto processor = std::shared_ptr( + new trace_sdk::SimpleSpanProcessor(std::move(exporter))); auto recordable = processor->MakeRecordable(); @@ -354,9 +354,9 @@ TEST(OStreamSpanExporter, PrintSpanWithLinks) // Test with the three common ostreams, tests are more of a sanity check and usage examples. TEST(OStreamSpanExporter, PrintSpanToCout) { - auto exporter = std::unique_ptr(new exportertrace::OStreamSpanExporter); - auto processor = std::shared_ptr( - new sdktrace::SimpleSpanProcessor(std::move(exporter))); + auto exporter = std::unique_ptr(new exportertrace::OStreamSpanExporter); + auto processor = std::shared_ptr( + new trace_sdk::SimpleSpanProcessor(std::move(exporter))); auto recordable = processor->MakeRecordable(); @@ -369,9 +369,9 @@ TEST(OStreamSpanExporter, PrintSpanToCout) TEST(OStreamSpanExporter, PrintSpanToCerr) { auto exporter = - std::unique_ptr(new exportertrace::OStreamSpanExporter(std::cerr)); - auto processor = std::shared_ptr( - new sdktrace::SimpleSpanProcessor(std::move(exporter))); + std::unique_ptr(new exportertrace::OStreamSpanExporter(std::cerr)); + auto processor = std::shared_ptr( + new trace_sdk::SimpleSpanProcessor(std::move(exporter))); auto recordable = processor->MakeRecordable(); @@ -384,9 +384,9 @@ TEST(OStreamSpanExporter, PrintSpanToCerr) TEST(OStreamSpanExporter, PrintSpanToClog) { auto exporter = - std::unique_ptr(new exportertrace::OStreamSpanExporter(std::clog)); - auto processor = std::shared_ptr( - new sdktrace::SimpleSpanProcessor(std::move(exporter))); + std::unique_ptr(new exportertrace::OStreamSpanExporter(std::clog)); + auto processor = std::shared_ptr( + new trace_sdk::SimpleSpanProcessor(std::move(exporter))); auto recordable = processor->MakeRecordable(); diff --git a/exporters/prometheus/include/opentelemetry/exporters/prometheus/prometheus_collector.h b/exporters/prometheus/include/opentelemetry/exporters/prometheus/prometheus_collector.h index 69d7754ad6..fcb08d4d35 100644 --- a/exporters/prometheus/include/opentelemetry/exporters/prometheus/prometheus_collector.h +++ b/exporters/prometheus/include/opentelemetry/exporters/prometheus/prometheus_collector.h @@ -14,7 +14,6 @@ # include "prometheus_exporter_utils.h" namespace prometheus_client = ::prometheus; -namespace metric_sdk = opentelemetry::sdk::metrics; OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -48,14 +47,14 @@ class PrometheusCollector : public prometheus_client::Collectable * * @param records a collection of records to add to the metricsToCollect collection */ - void AddMetricData(const std::vector &records); + void AddMetricData(const std::vector &records); /** * Get the current collection in the collector. * * @return the current metricsToCollect collection */ - std::vector GetCollection(); + std::vector GetCollection(); /** * Gets the maximum size of the collection. @@ -71,7 +70,7 @@ class PrometheusCollector : public prometheus_client::Collectable * to a collection so Collect() is able to clear the collection, even * though it is a const function. */ - std::unique_ptr> metrics_to_collect_; + std::unique_ptr> metrics_to_collect_; /** * Maximum size of the metricsToCollect collection. diff --git a/exporters/prometheus/include/opentelemetry/exporters/prometheus/prometheus_exporter_utils.h b/exporters/prometheus/include/opentelemetry/exporters/prometheus/prometheus_exporter_utils.h index a1fb3cd754..7efea9d397 100644 --- a/exporters/prometheus/include/opentelemetry/exporters/prometheus/prometheus_exporter_utils.h +++ b/exporters/prometheus/include/opentelemetry/exporters/prometheus/prometheus_exporter_utils.h @@ -10,8 +10,6 @@ # include "opentelemetry/sdk/_metrics/record.h" # include "prometheus/metric_family.h" -namespace metric_sdk = opentelemetry::sdk::metrics; - OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { @@ -31,13 +29,13 @@ class PrometheusExporterUtils * @return a collection of translated metrics that is acceptable by Prometheus */ static std::vector<::prometheus::MetricFamily> TranslateToPrometheus( - const std::vector &records); + const std::vector &records); private: /** * Set value to metric family according to record */ - static void SetMetricFamily(metric_sdk::Record &record, + static void SetMetricFamily(opentelemetry::sdk::metrics::Record &record, ::prometheus::MetricFamily *metric_family); /** @@ -53,14 +51,15 @@ class PrometheusExporterUtils * Set value to metric family for different aggregator */ template - static void SetMetricFamilyByAggregator(std::shared_ptr> aggregator, - std::string labels_str, - ::prometheus::MetricFamily *metric_family); + static void SetMetricFamilyByAggregator( + std::shared_ptr> aggregator, + std::string labels_str, + ::prometheus::MetricFamily *metric_family); /** * Translate the OTel metric type to Prometheus metric type */ - static ::prometheus::MetricType TranslateType(metric_sdk::AggregatorKind kind); + static ::prometheus::MetricType TranslateType(opentelemetry::sdk::metrics::AggregatorKind kind); /** * Set metric data for: @@ -103,7 +102,7 @@ class PrometheusExporterUtils */ template static void SetData(std::vector values, - metric_sdk::AggregatorKind kind, + opentelemetry::sdk::metrics::AggregatorKind kind, const std::vector &quantiles, const std::string &labels, std::chrono::nanoseconds time, @@ -129,8 +128,9 @@ class PrometheusExporterUtils * Build a quantiles vector from aggregator */ template - static std::vector GetQuantilesVector(std::shared_ptr> aggregator, - const std::vector &quantile_points); + static std::vector GetQuantilesVector( + std::shared_ptr> aggregator, + const std::vector &quantile_points); /** * Handle Counter and Gauge. @@ -159,7 +159,7 @@ class PrometheusExporterUtils */ template static void SetValue(std::vector values, - metric_sdk::AggregatorKind kind, + opentelemetry::sdk::metrics::AggregatorKind kind, std::vector quantiles, ::prometheus::ClientMetric *metric, bool do_quantile, diff --git a/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h b/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h index 4cd0a2f24e..0bb3eb8c76 100644 --- a/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h +++ b/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h @@ -47,13 +47,10 @@ struct ZipkinExporterOptions ext::http::client::Headers headers = {{"content-type", "application/json"}}; }; -namespace trace_sdk = opentelemetry::sdk::trace; -namespace http_client = opentelemetry::ext::http::client; - /** * The Zipkin exporter exports span data in JSON format as expected by Zipkin */ -class ZipkinExporter final : public trace_sdk::SpanExporter +class ZipkinExporter final : public opentelemetry::sdk::trace::SpanExporter { public: /** @@ -70,14 +67,15 @@ class ZipkinExporter final : public trace_sdk::SpanExporter * Create a span recordable. * @return a newly initialized Recordable object */ - std::unique_ptr MakeRecordable() noexcept override; + std::unique_ptr MakeRecordable() noexcept override; /** * Export a batch of span recordables in JSON format. * @param spans a span of unique pointers to span recordables */ sdk::common::ExportResult Export( - const nostd::span> &spans) noexcept override; + const nostd::span> &spans) noexcept + override; /** * Shut down the exporter. @@ -96,7 +94,7 @@ class ZipkinExporter final : public trace_sdk::SpanExporter // The configuration options associated with this exporter. bool isShutdown_ = false; ZipkinExporterOptions options_; - std::shared_ptr http_client_; + std::shared_ptr http_client_; opentelemetry::ext::http::common::UrlParser url_parser_; nlohmann::json local_end_point_; }; diff --git a/ext/include/opentelemetry/ext/http/client/curl/http_client_curl.h b/ext/include/opentelemetry/ext/http/client/curl/http_client_curl.h index 126b09acf8..32d0a96783 100644 --- a/ext/include/opentelemetry/ext/http/client/curl/http_client_curl.h +++ b/ext/include/opentelemetry/ext/http/client/curl/http_client_curl.h @@ -22,17 +22,22 @@ namespace client namespace curl { -namespace http_client = opentelemetry::ext::http::client; -const http_client::StatusCode Http_Ok = 200; +const opentelemetry::ext::http::client::StatusCode Http_Ok = 200; -class Request : public http_client::Request +class Request : public opentelemetry::ext::http::client::Request { public: - Request() : method_(http_client::Method::Get), uri_("/") {} + Request() : method_(opentelemetry::ext::http::client::Method::Get), uri_("/") {} - void SetMethod(http_client::Method method) noexcept override { method_ = method; } + void SetMethod(opentelemetry::ext::http::client::Method method) noexcept override + { + method_ = method; + } - void SetBody(http_client::Body &body) noexcept override { body_ = std::move(body); } + void SetBody(opentelemetry::ext::http::client::Body &body) noexcept override + { + body_ = std::move(body); + } void AddHeader(nostd::string_view name, nostd::string_view value) noexcept override { @@ -59,19 +64,22 @@ class Request : public http_client::Request } public: - http_client::Method method_; - http_client::Body body_; - http_client::Headers headers_; + opentelemetry::ext::http::client::Method method_; + opentelemetry::ext::http::client::Body body_; + opentelemetry::ext::http::client::Headers headers_; std::string uri_; std::chrono::milliseconds timeout_ms_{5000}; // ms }; -class Response : public http_client::Response +class Response : public opentelemetry::ext::http::client::Response { public: Response() : status_code_(Http_Ok) {} - virtual const http_client::Body &GetBody() const noexcept override { return body_; } + virtual const opentelemetry::ext::http::client::Body &GetBody() const noexcept override + { + return body_; + } virtual bool ForEachHeader( nostd::function_ref callable) @@ -103,17 +111,20 @@ class Response : public http_client::Response return true; } - virtual http_client::StatusCode GetStatusCode() const noexcept override { return status_code_; } + virtual opentelemetry::ext::http::client::StatusCode GetStatusCode() const noexcept override + { + return status_code_; + } public: Headers headers_; - http_client::Body body_; - http_client::StatusCode status_code_; + opentelemetry::ext::http::client::Body body_; + opentelemetry::ext::http::client::StatusCode status_code_; }; class HttpClient; -class Session : public http_client::Session +class Session : public opentelemetry::ext::http::client::Session { public: Session(HttpClient &http_client, @@ -125,13 +136,14 @@ class Session : public http_client::Session host_ = scheme + "://" + host + ":" + std::to_string(port) + "/"; } - std::shared_ptr CreateRequest() noexcept override + std::shared_ptr CreateRequest() noexcept override { http_request_.reset(new Request()); return http_request_; } - virtual void SendRequest(http_client::EventHandler &callback) noexcept override + virtual void SendRequest( + opentelemetry::ext::http::client::EventHandler &callback) noexcept override { is_session_active_ = true; std::string url = host_ + std::string(http_request_->uri_); @@ -143,7 +155,7 @@ class Session : public http_client::Session if (operation.WasAborted()) { // Manually cancelled - callback_ptr->OnEvent(http_client::SessionState::Cancelled, ""); + callback_ptr->OnEvent(opentelemetry::ext::http::client::SessionState::Cancelled, ""); } if (operation.GetResponseCode() >= CURL_LAST) @@ -182,22 +194,23 @@ class Session : public http_client::Session bool is_session_active_; }; -class HttpClientSync : public http_client::HttpClientSync +class HttpClientSync : public opentelemetry::ext::http::client::HttpClientSync { public: HttpClientSync() { curl_global_init(CURL_GLOBAL_ALL); } - http_client::Result Get(const nostd::string_view &url, - const http_client::Headers &headers) noexcept override + opentelemetry::ext::http::client::Result Get( + const nostd::string_view &url, + const opentelemetry::ext::http::client::Headers &headers) noexcept override { - http_client::Body body; - HttpOperation curl_operation(http_client::Method::Get, url.data(), nullptr, RequestMode::Sync, - headers, body); + opentelemetry::ext::http::client::Body body; + HttpOperation curl_operation(opentelemetry::ext::http::client::Method::Get, url.data(), nullptr, + RequestMode::Sync, headers, body); curl_operation.SendSync(); auto session_state = curl_operation.GetSessionState(); if (curl_operation.WasAborted()) { - session_state = http_client::SessionState::Cancelled; + session_state = opentelemetry::ext::http::client::SessionState::Cancelled; } auto response = std::unique_ptr(new Response()); if (curl_operation.GetResponseCode() >= CURL_LAST) @@ -208,20 +221,21 @@ class HttpClientSync : public http_client::HttpClientSync response->body_ = curl_operation.GetResponseBody(); response->status_code_ = curl_operation.GetResponseCode(); } - return http_client::Result(std::move(response), session_state); + return opentelemetry::ext::http::client::Result(std::move(response), session_state); } - http_client::Result Post(const nostd::string_view &url, - const Body &body, - const http_client::Headers &headers) noexcept override + opentelemetry::ext::http::client::Result Post( + const nostd::string_view &url, + const Body &body, + const opentelemetry::ext::http::client::Headers &headers) noexcept override { - HttpOperation curl_operation(http_client::Method::Post, url.data(), nullptr, RequestMode::Sync, - headers, body); + HttpOperation curl_operation(opentelemetry::ext::http::client::Method::Post, url.data(), + nullptr, RequestMode::Sync, headers, body); curl_operation.SendSync(); auto session_state = curl_operation.GetSessionState(); if (curl_operation.WasAborted()) { - session_state = http_client::SessionState::Cancelled; + session_state = opentelemetry::ext::http::client::SessionState::Cancelled; } auto response = std::unique_ptr(new Response()); if (curl_operation.GetResponseCode() >= CURL_LAST) @@ -233,19 +247,20 @@ class HttpClientSync : public http_client::HttpClientSync response->status_code_ = curl_operation.GetResponseCode(); } - return http_client::Result(std::move(response), session_state); + return opentelemetry::ext::http::client::Result(std::move(response), session_state); } ~HttpClientSync() { curl_global_cleanup(); } }; -class HttpClient : public http_client::HttpClient +class HttpClient : public opentelemetry::ext::http::client::HttpClient { public: // The call (curl_global_init) is not thread safe. Ensure this is called only once. HttpClient() : next_session_id_{0} { curl_global_init(CURL_GLOBAL_ALL); } - std::shared_ptr CreateSession(nostd::string_view url) noexcept override + std::shared_ptr CreateSession( + nostd::string_view url) noexcept override { auto parsedUrl = common::UrlParser(std::string(url)); if (!parsedUrl.success_) diff --git a/ext/include/opentelemetry/ext/http/client/curl/http_operation_curl.h b/ext/include/opentelemetry/ext/http/client/curl/http_operation_curl.h index 9aafbbf27c..fa727899e4 100644 --- a/ext/include/opentelemetry/ext/http/client/curl/http_operation_curl.h +++ b/ext/include/opentelemetry/ext/http/client/curl/http_operation_curl.h @@ -29,7 +29,6 @@ namespace client { namespace curl { -namespace http_client = opentelemetry::ext::http::client; const std::chrono::milliseconds default_http_conn_timeout(5000); // ms const std::string http_status_regexp = "HTTP\\/\\d\\.\\d (\\d+)\\ .*"; const std::string http_header_regexp = "(.*)\\: (.*)\\n*"; @@ -43,7 +42,7 @@ enum class RequestMode class HttpOperation { public: - void DispatchEvent(http_client::SessionState type, std::string reason = "") + void DispatchEvent(opentelemetry::ext::http::client::SessionState type, std::string reason = "") { if (request_mode_ == RequestMode::Async && callback_ != nullptr) { @@ -69,13 +68,15 @@ class HttpOperation * @param raw_response whether to parse the response * @param httpConnTimeout HTTP connection timeout in seconds */ - HttpOperation(http_client::Method method, + HttpOperation(opentelemetry::ext::http::client::Method method, std::string url, - http_client::EventHandler *callback, + opentelemetry::ext::http::client::EventHandler *callback, RequestMode request_mode = RequestMode::Async, // Default empty headers and empty request body - const http_client::Headers &request_headers = http_client::Headers(), - const http_client::Body &request_body = http_client::Body(), + const opentelemetry::ext::http::client::Headers &request_headers = + opentelemetry::ext::http::client::Headers(), + const opentelemetry::ext::http::client::Body &request_body = + opentelemetry::ext::http::client::Body(), // Default connectivity and response size options bool is_raw_response = false, std::chrono::milliseconds http_conn_timeout = default_http_conn_timeout) @@ -102,7 +103,7 @@ class HttpOperation if (!curl_) { res_ = CURLE_FAILED_INIT; - DispatchEvent(http_client::SessionState::CreateFailed); + DispatchEvent(opentelemetry::ext::http::client::SessionState::CreateFailed); return; } @@ -129,7 +130,7 @@ class HttpOperation curl_easy_setopt(curl_, CURLOPT_HTTPHEADER, headers_chunk_); } - DispatchEvent(http_client::SessionState::Created); + DispatchEvent(opentelemetry::ext::http::client::SessionState::Created); } /** @@ -144,7 +145,7 @@ class HttpOperation result_.wait(); } // TBD - Need to be uncomment. This will callback instance is deleted. - // DispatchEvent(http_client::SessionState::Destroy); + // DispatchEvent(opentelemetry::ext::http::client::SessionState::Destroy); res_ = CURLE_OK; curl_easy_cleanup(curl_); curl_slist_free_all(headers_chunk_); @@ -175,7 +176,7 @@ class HttpOperation if (!curl_) { res_ = CURLE_FAILED_INIT; - DispatchEvent(http_client::SessionState::SendFailed); + DispatchEvent(opentelemetry::ext::http::client::SessionState::SendFailed); return res_; } @@ -185,11 +186,11 @@ class HttpOperation // Perform initial connect, handling the timeout if needed curl_easy_setopt(curl_, CURLOPT_CONNECT_ONLY, 1L); curl_easy_setopt(curl_, CURLOPT_TIMEOUT, http_conn_timeout_.count() / 1000); - DispatchEvent(http_client::SessionState::Connecting); + DispatchEvent(opentelemetry::ext::http::client::SessionState::Connecting); res_ = curl_easy_perform(curl_); if (CURLE_OK != res_) { - DispatchEvent(http_client::SessionState::ConnectFailed, + DispatchEvent(opentelemetry::ext::http::client::SessionState::ConnectFailed, curl_easy_strerror(res_)); // couldn't connect - stage 1 return res_; } @@ -203,7 +204,7 @@ class HttpOperation if (CURLE_OK != res_) { - DispatchEvent(http_client::SessionState::ConnectFailed, + DispatchEvent(opentelemetry::ext::http::client::SessionState::ConnectFailed, curl_easy_strerror(res_)); // couldn't connect - stage 2 return res_; } @@ -214,12 +215,12 @@ class HttpOperation { res_ = CURLE_OPERATION_TIMEDOUT; DispatchEvent( - http_client::SessionState::ConnectFailed, + opentelemetry::ext::http::client::SessionState::ConnectFailed, " Is aborted: " + std::to_string(is_aborted_.load())); // couldn't connect - stage 3 return res_; } - DispatchEvent(http_client::SessionState::Connected); + DispatchEvent(opentelemetry::ext::http::client::SessionState::Connected); // once connection is there - switch back to easy perform for HTTP post curl_easy_setopt(curl_, CURLOPT_CONNECT_ONLY, 0); @@ -238,14 +239,14 @@ class HttpOperation } // TODO: only two methods supported for now - POST and GET - if (method_ == http_client::Method::Post) + if (method_ == opentelemetry::ext::http::client::Method::Post) { // POST curl_easy_setopt(curl_, CURLOPT_POST, true); curl_easy_setopt(curl_, CURLOPT_POSTFIELDS, (const char *)request); curl_easy_setopt(curl_, CURLOPT_POSTFIELDSIZE, req_size); } - else if (method_ == http_client::Method::Get) + else if (method_ == opentelemetry::ext::http::client::Method::Get) { // GET } @@ -258,12 +259,13 @@ class HttpOperation // abort if slower than 4kb/sec during 30 seconds curl_easy_setopt(curl_, CURLOPT_LOW_SPEED_TIME, 30L); curl_easy_setopt(curl_, CURLOPT_LOW_SPEED_LIMIT, 4096); - DispatchEvent(http_client::SessionState::Sending); + DispatchEvent(opentelemetry::ext::http::client::SessionState::Sending); res_ = curl_easy_perform(curl_); if (CURLE_OK != res_) { - DispatchEvent(http_client::SessionState::SendFailed, curl_easy_strerror(res_)); + DispatchEvent(opentelemetry::ext::http::client::SessionState::SendFailed, + curl_easy_strerror(res_)); return res_; } @@ -281,7 +283,7 @@ class HttpOperation /* libcurl is nice enough to parse the http response code itself: */ curl_easy_getinfo(curl_, CURLINFO_RESPONSE_CODE, &res_); // We got some response from server. Dump the contents. - DispatchEvent(http_client::SessionState::Response); + DispatchEvent(opentelemetry::ext::http::client::SessionState::Response); // This function returns: // - on success: HTTP status code. @@ -313,7 +315,7 @@ class HttpOperation /** * Get last session state. */ - http_client::SessionState GetSessionState() { return session_state_; } + opentelemetry::ext::http::client::SessionState GetSessionState() { return session_state_; } /** * Get whether or not response was programmatically aborted @@ -410,15 +412,15 @@ class HttpOperation CURL *curl_; // Local curl instance CURLcode res_; // Curl result OR HTTP status code if successful - http_client::EventHandler *callback_; + opentelemetry::ext::http::client::EventHandler *callback_; // Request values - http_client::Method method_; + opentelemetry::ext::http::client::Method method_; std::string url_; const Headers &request_headers_; - const http_client::Body &request_body_; + const opentelemetry::ext::http::client::Body &request_body_; struct curl_slist *headers_chunk_ = nullptr; - http_client::SessionState session_state_; + opentelemetry::ext::http::client::SessionState session_state_; // Processed response headers and body std::vector resp_headers_; diff --git a/sdk/include/opentelemetry/sdk/_metrics/aggregator/aggregator.h b/sdk/include/opentelemetry/sdk/_metrics/aggregator/aggregator.h index fb90256d76..897a7f86a0 100644 --- a/sdk/include/opentelemetry/sdk/_metrics/aggregator/aggregator.h +++ b/sdk/include/opentelemetry/sdk/_metrics/aggregator/aggregator.h @@ -10,8 +10,6 @@ # include "opentelemetry/common/timestamp.h" # include "opentelemetry/version.h" -namespace metrics_api = opentelemetry::metrics; - OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { @@ -91,7 +89,10 @@ class Aggregator * @param none * @return the InstrumentKind of the aggregator's owner */ - virtual opentelemetry::metrics::InstrumentKind get_instrument_kind() final { return kind_; } + virtual opentelemetry::opentelemetry::metrics::InstrumentKind get_instrument_kind() final + { + return kind_; + } /** * Returns the type of this aggregator @@ -146,7 +147,7 @@ class Aggregator protected: std::vector values_; std::vector checkpoint_; - opentelemetry::metrics::InstrumentKind kind_; + opentelemetry::opentelemetry::metrics::InstrumentKind kind_; std::mutex mu_; AggregatorKind agg_kind_; bool updated_; diff --git a/sdk/include/opentelemetry/sdk/_metrics/aggregator/counter_aggregator.h b/sdk/include/opentelemetry/sdk/_metrics/aggregator/counter_aggregator.h index 2189dcc934..b9842e8e0a 100644 --- a/sdk/include/opentelemetry/sdk/_metrics/aggregator/counter_aggregator.h +++ b/sdk/include/opentelemetry/sdk/_metrics/aggregator/counter_aggregator.h @@ -10,8 +10,6 @@ # include "opentelemetry/sdk/_metrics/aggregator/aggregator.h" # include "opentelemetry/version.h" -namespace metrics_api = opentelemetry::metrics; - OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { @@ -23,7 +21,7 @@ class CounterAggregator final : public Aggregator { public: - CounterAggregator(metrics_api::InstrumentKind kind) + CounterAggregator(opentelemetry::metrics::InstrumentKind kind) { this->kind_ = kind; this->values_ = std::vector(1, 0); diff --git a/sdk/include/opentelemetry/sdk/_metrics/aggregator/exact_aggregator.h b/sdk/include/opentelemetry/sdk/_metrics/aggregator/exact_aggregator.h index cb4e52e71b..44ea717a0b 100644 --- a/sdk/include/opentelemetry/sdk/_metrics/aggregator/exact_aggregator.h +++ b/sdk/include/opentelemetry/sdk/_metrics/aggregator/exact_aggregator.h @@ -13,8 +13,6 @@ # include # include -namespace metrics_api = opentelemetry::metrics; - OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { @@ -37,7 +35,7 @@ template class ExactAggregator : public Aggregator { public: - ExactAggregator(metrics_api::InstrumentKind kind, bool quant_estimation = false) + ExactAggregator(opentelemetry::metrics::InstrumentKind kind, bool quant_estimation = false) { static_assert(std::is_arithmetic::value, "Not an arithmetic type"); this->kind_ = kind; diff --git a/sdk/include/opentelemetry/sdk/_metrics/aggregator/gauge_aggregator.h b/sdk/include/opentelemetry/sdk/_metrics/aggregator/gauge_aggregator.h index e65702843c..96119386d4 100644 --- a/sdk/include/opentelemetry/sdk/_metrics/aggregator/gauge_aggregator.h +++ b/sdk/include/opentelemetry/sdk/_metrics/aggregator/gauge_aggregator.h @@ -13,8 +13,6 @@ # include # include -namespace metrics_api = opentelemetry::metrics; - OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { @@ -33,7 +31,7 @@ template class GaugeAggregator : public Aggregator { public: - explicit GaugeAggregator(metrics_api::InstrumentKind kind) + explicit GaugeAggregator(opentelemetry::metrics::InstrumentKind kind) { static_assert(std::is_arithmetic::value, "Not an arithmetic type"); this->kind_ = kind; diff --git a/sdk/include/opentelemetry/sdk/_metrics/aggregator/histogram_aggregator.h b/sdk/include/opentelemetry/sdk/_metrics/aggregator/histogram_aggregator.h index 31c501d96d..13e1e1244a 100644 --- a/sdk/include/opentelemetry/sdk/_metrics/aggregator/histogram_aggregator.h +++ b/sdk/include/opentelemetry/sdk/_metrics/aggregator/histogram_aggregator.h @@ -12,8 +12,6 @@ # include "opentelemetry/sdk/_metrics/aggregator/aggregator.h" # include "opentelemetry/version.h" -namespace metrics_api = opentelemetry::metrics; - OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { @@ -32,7 +30,7 @@ class HistogramAggregator final : public Aggregator * Sum is stored in values_[0] * Count is stored in position_[1] */ - HistogramAggregator(metrics_api::InstrumentKind kind, std::vector boundaries) + HistogramAggregator(opentelemetry::metrics::InstrumentKind kind, std::vector boundaries) { if (!std::is_sorted(boundaries.begin(), boundaries.end())) { diff --git a/sdk/include/opentelemetry/sdk/_metrics/aggregator/min_max_sum_count_aggregator.h b/sdk/include/opentelemetry/sdk/_metrics/aggregator/min_max_sum_count_aggregator.h index 55699b208f..60628b567e 100644 --- a/sdk/include/opentelemetry/sdk/_metrics/aggregator/min_max_sum_count_aggregator.h +++ b/sdk/include/opentelemetry/sdk/_metrics/aggregator/min_max_sum_count_aggregator.h @@ -12,8 +12,6 @@ # include # include -namespace metrics_api = opentelemetry::metrics; - OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { @@ -36,7 +34,7 @@ template class MinMaxSumCountAggregator : public Aggregator { public: - explicit MinMaxSumCountAggregator(metrics_api::InstrumentKind kind) + explicit MinMaxSumCountAggregator(opentelemetry::metrics::InstrumentKind kind) { static_assert(std::is_arithmetic::value, "Not an arithmetic type"); this->kind_ = kind; diff --git a/sdk/include/opentelemetry/sdk/_metrics/aggregator/sketch_aggregator.h b/sdk/include/opentelemetry/sdk/_metrics/aggregator/sketch_aggregator.h index 6fbd502240..3942c9550f 100644 --- a/sdk/include/opentelemetry/sdk/_metrics/aggregator/sketch_aggregator.h +++ b/sdk/include/opentelemetry/sdk/_metrics/aggregator/sketch_aggregator.h @@ -15,8 +15,6 @@ # include "opentelemetry/sdk/_metrics/aggregator/aggregator.h" # include "opentelemetry/version.h" -namespace metrics_api = opentelemetry::metrics; - OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { @@ -45,7 +43,9 @@ class SketchAggregator final : public Aggregator *@param error_bound, what is referred to as "alpha" in the DDSketch algorithm *@param max_buckets, the maximum number of indices in the raw value map */ - SketchAggregator(metrics_api::InstrumentKind kind, double error_bound, size_t max_buckets = 2048) + SketchAggregator(opentelemetry::metrics::InstrumentKind kind, + double error_bound, + size_t max_buckets = 2048) { this->kind_ = kind; diff --git a/sdk/include/opentelemetry/sdk/_metrics/async_instruments.h b/sdk/include/opentelemetry/sdk/_metrics/async_instruments.h index 09ff75bfb5..5213a4e2ea 100644 --- a/sdk/include/opentelemetry/sdk/_metrics/async_instruments.h +++ b/sdk/include/opentelemetry/sdk/_metrics/async_instruments.h @@ -15,8 +15,6 @@ # include "opentelemetry/sdk/_metrics/instrument.h" # include "opentelemetry/version.h" -namespace metrics_api = opentelemetry::metrics; - OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { @@ -29,7 +27,8 @@ namespace metrics # endif template -class ValueObserver : public AsynchronousInstrument, virtual public metrics_api::ValueObserver +class ValueObserver : public AsynchronousInstrument, + virtual public opentelemetry::metrics::ValueObserver { public: @@ -39,13 +38,13 @@ class ValueObserver : public AsynchronousInstrument, virtual public metrics_a nostd::string_view description, nostd::string_view unit, bool enabled, - void (*callback)(metrics_api::ObserverResult)) + void (*callback)(opentelemetry::metrics::ObserverResult)) : AsynchronousInstrument(name, description, unit, enabled, callback, - metrics_api::InstrumentKind::ValueObserver) + opentelemetry::metrics::InstrumentKind::ValueObserver) {} /* @@ -81,7 +80,7 @@ class ValueObserver : public AsynchronousInstrument, virtual public metrics_a */ virtual void run() override { - metrics_api::ObserverResult res(this); + opentelemetry::metrics::ObserverResult res(this); this->callback_(res); } @@ -104,7 +103,8 @@ class ValueObserver : public AsynchronousInstrument, virtual public metrics_a }; template -class SumObserver : public AsynchronousInstrument, virtual public metrics_api::SumObserver +class SumObserver : public AsynchronousInstrument, + virtual public opentelemetry::metrics::SumObserver { public: @@ -114,13 +114,13 @@ class SumObserver : public AsynchronousInstrument, virtual public metrics_api nostd::string_view description, nostd::string_view unit, bool enabled, - void (*callback)(metrics_api::ObserverResult)) + void (*callback)(opentelemetry::metrics::ObserverResult)) : AsynchronousInstrument(name, description, unit, enabled, callback, - metrics_api::InstrumentKind::SumObserver) + opentelemetry::metrics::InstrumentKind::SumObserver) {} /* @@ -178,7 +178,7 @@ class SumObserver : public AsynchronousInstrument, virtual public metrics_api */ virtual void run() override { - metrics_api::ObserverResult res(this); + opentelemetry::metrics::ObserverResult res(this); this->callback_(res); } @@ -202,7 +202,7 @@ class SumObserver : public AsynchronousInstrument, virtual public metrics_api template class UpDownSumObserver : public AsynchronousInstrument, - virtual public metrics_api::UpDownSumObserver + virtual public opentelemetry::metrics::UpDownSumObserver { public: @@ -212,13 +212,13 @@ class UpDownSumObserver : public AsynchronousInstrument, nostd::string_view description, nostd::string_view unit, bool enabled, - void (*callback)(metrics_api::ObserverResult)) + void (*callback)(opentelemetry::metrics::ObserverResult)) : AsynchronousInstrument(name, description, unit, enabled, callback, - metrics_api::InstrumentKind::UpDownSumObserver) + opentelemetry::metrics::InstrumentKind::UpDownSumObserver) {} /* @@ -254,7 +254,7 @@ class UpDownSumObserver : public AsynchronousInstrument, */ virtual void run() override { - metrics_api::ObserverResult res(this); + opentelemetry::metrics::ObserverResult res(this); this->callback_(res); } diff --git a/sdk/include/opentelemetry/sdk/_metrics/controller.h b/sdk/include/opentelemetry/sdk/_metrics/controller.h index f0cb1fc841..72b53eda5d 100644 --- a/sdk/include/opentelemetry/sdk/_metrics/controller.h +++ b/sdk/include/opentelemetry/sdk/_metrics/controller.h @@ -17,8 +17,6 @@ # include "opentelemetry/sdk/_metrics/record.h" # include "opentelemetry/version.h" -namespace metrics_api = opentelemetry::metrics; - OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { @@ -29,7 +27,7 @@ class PushController { public: - PushController(nostd::shared_ptr meter, + PushController(nostd::shared_ptr meter, nostd::unique_ptr exporter, nostd::shared_ptr processor, double period, @@ -130,7 +128,7 @@ class PushController this->mu_.unlock(); } - nostd::shared_ptr meter_; + nostd::shared_ptr meter_; nostd::unique_ptr exporter_; nostd::shared_ptr processor_; std::thread runner_; diff --git a/sdk/include/opentelemetry/sdk/_metrics/instrument.h b/sdk/include/opentelemetry/sdk/_metrics/instrument.h index b69b550fdc..51111be5e2 100644 --- a/sdk/include/opentelemetry/sdk/_metrics/instrument.h +++ b/sdk/include/opentelemetry/sdk/_metrics/instrument.h @@ -16,8 +16,6 @@ # include "opentelemetry/sdk/_metrics/record.h" # include "opentelemetry/version.h" -namespace metrics_api = opentelemetry::metrics; - OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { @@ -29,7 +27,7 @@ namespace metrics # pragma warning(disable : 4250) // inheriting methods via dominance # endif -class Instrument : virtual public metrics_api::Instrument +class Instrument : virtual public opentelemetry::metrics::Instrument { public: @@ -39,7 +37,7 @@ class Instrument : virtual public metrics_api::Instrument nostd::string_view description, nostd::string_view unit, bool enabled, - metrics_api::InstrumentKind kind) + opentelemetry::metrics::InstrumentKind kind) : name_(name), description_(description), unit_(unit), enabled_(enabled), kind_(kind) {} @@ -55,7 +53,7 @@ class Instrument : virtual public metrics_api::Instrument // Return the insrument's units of measurement virtual nostd::string_view GetUnits() override { return unit_; } - virtual metrics_api::InstrumentKind GetKind() override { return this->kind_; } + virtual opentelemetry::metrics::InstrumentKind GetKind() override { return this->kind_; } protected: std::string name_; @@ -63,12 +61,13 @@ class Instrument : virtual public metrics_api::Instrument std::string unit_; bool enabled_; std::mutex mu_; - metrics_api::InstrumentKind kind_; + opentelemetry::metrics::InstrumentKind kind_; }; template -class BoundSynchronousInstrument : public Instrument, - virtual public metrics_api::BoundSynchronousInstrument +class BoundSynchronousInstrument + : public Instrument, + virtual public opentelemetry::metrics::BoundSynchronousInstrument { public: @@ -78,7 +77,7 @@ class BoundSynchronousInstrument : public Instrument, nostd::string_view description, nostd::string_view unit, bool enabled, - metrics_api::InstrumentKind kind, + opentelemetry::metrics::InstrumentKind kind, std::shared_ptr> agg) : Instrument(name, description, unit, enabled, kind), agg_(agg) { @@ -157,7 +156,7 @@ class BoundSynchronousInstrument : public Instrument, template class SynchronousInstrument : public Instrument, - virtual public metrics_api::SynchronousInstrument + virtual public opentelemetry::metrics::SynchronousInstrument { public: @@ -167,7 +166,7 @@ class SynchronousInstrument : public Instrument, nostd::string_view description, nostd::string_view unit, bool enabled, - metrics_api::InstrumentKind kind) + opentelemetry::metrics::InstrumentKind kind) : Instrument(name, description, unit, enabled, kind) {} @@ -181,7 +180,7 @@ class SynchronousInstrument : public Instrument, * @param labels the set of labels, as key-value pairs * @return a Bound Instrument */ - virtual nostd::shared_ptr> bind( + virtual nostd::shared_ptr> bind( const opentelemetry::common::KeyValueIterable &labels) override { return nostd::shared_ptr>(); @@ -203,7 +202,7 @@ class SynchronousInstrument : public Instrument, template class AsynchronousInstrument : public Instrument, - virtual public metrics_api::AsynchronousInstrument + virtual public opentelemetry::metrics::AsynchronousInstrument { public: @@ -213,8 +212,8 @@ class AsynchronousInstrument : public Instrument, nostd::string_view description, nostd::string_view unit, bool enabled, - void (*callback)(metrics_api::ObserverResult), - metrics_api::InstrumentKind kind) + void (*callback)(opentelemetry::metrics::ObserverResult), + opentelemetry::metrics::InstrumentKind kind) : Instrument(name, description, unit, enabled, kind) { this->callback_ = callback; diff --git a/sdk/include/opentelemetry/sdk/_metrics/meter.h b/sdk/include/opentelemetry/sdk/_metrics/meter.h index a045ab93b1..a91a3ed2bb 100644 --- a/sdk/include/opentelemetry/sdk/_metrics/meter.h +++ b/sdk/include/opentelemetry/sdk/_metrics/meter.h @@ -19,8 +19,7 @@ namespace sdk { namespace metrics { -namespace metrics_api = opentelemetry::metrics; -class Meter : public metrics_api::Meter +class Meter : public opentelemetry::metrics::Meter { public: explicit Meter(std::string library_name, std::string library_version = "") @@ -39,25 +38,29 @@ class Meter : public metrics_api::Meter * @return a shared pointer to the created Counter. * @throws invalid_argument exception if name is null or does not conform to OTel syntax. */ - nostd::shared_ptr> NewShortCounter(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) override; - - nostd::shared_ptr> NewIntCounter(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) override; - - nostd::shared_ptr> NewFloatCounter(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) override; - - nostd::shared_ptr> NewDoubleCounter(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) override; + nostd::shared_ptr> NewShortCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override; + + nostd::shared_ptr> NewIntCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override; + + nostd::shared_ptr> NewFloatCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override; + + nostd::shared_ptr> NewDoubleCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override; /** * Creates an UpDownCounter with the passed characteristics and returns a shared_ptr to that @@ -70,25 +73,25 @@ class Meter : public metrics_api::Meter * @return a shared pointer to the created UpDownCounter. * @throws invalid_argument exception if name is null or does not conform to OTel syntax. */ - nostd::shared_ptr> NewShortUpDownCounter( + nostd::shared_ptr> NewShortUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override; - nostd::shared_ptr> NewIntUpDownCounter( + nostd::shared_ptr> NewIntUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override; - nostd::shared_ptr> NewFloatUpDownCounter( + nostd::shared_ptr> NewFloatUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override; - nostd::shared_ptr> NewDoubleUpDownCounter( + nostd::shared_ptr> NewDoubleUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, @@ -105,25 +108,25 @@ class Meter : public metrics_api::Meter * @return a shared pointer to the created DoubleValueRecorder. * @throws invalid_argument exception if name is null or does not conform to OTel syntax. */ - nostd::shared_ptr> NewShortValueRecorder( + nostd::shared_ptr> NewShortValueRecorder( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override; - nostd::shared_ptr> NewIntValueRecorder( + nostd::shared_ptr> NewIntValueRecorder( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override; - nostd::shared_ptr> NewFloatValueRecorder( + nostd::shared_ptr> NewFloatValueRecorder( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override; - nostd::shared_ptr> NewDoubleValueRecorder( + nostd::shared_ptr> NewDoubleValueRecorder( nostd::string_view name, nostd::string_view description, nostd::string_view unit, @@ -141,33 +144,33 @@ class Meter : public metrics_api::Meter * @return a shared pointer to the created SumObserver. * @throws invalid_argument exception if name is null or does not conform to OTel syntax. */ - nostd::shared_ptr> NewShortSumObserver( + nostd::shared_ptr> NewShortSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(metrics_api::ObserverResult)) override; + void (*callback)(opentelemetry::metrics::ObserverResult)) override; - nostd::shared_ptr> NewIntSumObserver( + nostd::shared_ptr> NewIntSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(metrics_api::ObserverResult)) override; + void (*callback)(opentelemetry::metrics::ObserverResult)) override; - nostd::shared_ptr> NewFloatSumObserver( + nostd::shared_ptr> NewFloatSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(metrics_api::ObserverResult)) override; + void (*callback)(opentelemetry::metrics::ObserverResult)) override; - nostd::shared_ptr> NewDoubleSumObserver( + nostd::shared_ptr> NewDoubleSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(metrics_api::ObserverResult)) override; + void (*callback)(opentelemetry::metrics::ObserverResult)) override; /** * Creates an UpDownSumObserver with the passed characteristics and returns a shared_ptr to @@ -181,33 +184,33 @@ class Meter : public metrics_api::Meter * @return a shared pointer to the created UpDownSumObserver. * @throws invalid_argument exception if name is null or does not conform to OTel syntax. */ - nostd::shared_ptr> NewShortUpDownSumObserver( + nostd::shared_ptr> NewShortUpDownSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(metrics_api::ObserverResult)) override; + void (*callback)(opentelemetry::metrics::ObserverResult)) override; - nostd::shared_ptr> NewIntUpDownSumObserver( + nostd::shared_ptr> NewIntUpDownSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(metrics_api::ObserverResult)) override; + void (*callback)(opentelemetry::metrics::ObserverResult)) override; - nostd::shared_ptr> NewFloatUpDownSumObserver( + nostd::shared_ptr> NewFloatUpDownSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(metrics_api::ObserverResult)) override; + void (*callback)(opentelemetry::metrics::ObserverResult)) override; - nostd::shared_ptr> NewDoubleUpDownSumObserver( + nostd::shared_ptr> NewDoubleUpDownSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(metrics_api::ObserverResult)) override; + void (*callback)(opentelemetry::metrics::ObserverResult)) override; /** * Creates a ValueObserver with the passed characteristics and returns a shared_ptr to that @@ -221,33 +224,33 @@ class Meter : public metrics_api::Meter * @return a shared pointer to the created ValueObserver. * @throws invalid_argument exception if name is null or does not conform to OTel syntax. */ - nostd::shared_ptr> NewShortValueObserver( + nostd::shared_ptr> NewShortValueObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(metrics_api::ObserverResult)) override; + void (*callback)(opentelemetry::metrics::ObserverResult)) override; - nostd::shared_ptr> NewIntValueObserver( + nostd::shared_ptr> NewIntValueObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(metrics_api::ObserverResult)) override; + void (*callback)(opentelemetry::metrics::ObserverResult)) override; - nostd::shared_ptr> NewFloatValueObserver( + nostd::shared_ptr> NewFloatValueObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(metrics_api::ObserverResult)) override; + void (*callback)(opentelemetry::metrics::ObserverResult)) override; - nostd::shared_ptr> NewDoubleValueObserver( + nostd::shared_ptr> NewDoubleValueObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(metrics_api::ObserverResult)) override; + void (*callback)(opentelemetry::metrics::ObserverResult)) override; /** * Utility method that allows users to atomically record measurements to a set of @@ -257,21 +260,24 @@ class Meter : public metrics_api::Meter * @param values a span of pairs where the first element of the pair is a metric instrument * to record to, and the second element is the value to update that instrument with. */ - void RecordShortBatch(const opentelemetry::common::KeyValueIterable &labels, - nostd::span *> instruments, - nostd::span values) noexcept override; + void RecordShortBatch( + const opentelemetry::common::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept override; void RecordIntBatch(const opentelemetry::common::KeyValueIterable &labels, - nostd::span *> instruments, + nostd::span *> instruments, nostd::span values) noexcept override; - void RecordFloatBatch(const opentelemetry::common::KeyValueIterable &labels, - nostd::span *> instruments, - nostd::span values) noexcept override; + void RecordFloatBatch( + const opentelemetry::common::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept override; - void RecordDoubleBatch(const opentelemetry::common::KeyValueIterable &labels, - nostd::span *> instruments, - nostd::span values) noexcept override; + void RecordDoubleBatch( + const opentelemetry::common::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept override; /** * An SDK-only function that checkpoints the aggregators of all instruments created from @@ -300,7 +306,8 @@ class Meter : public metrics_api::Meter template void CollectSingleSyncInstrument( typename std::map>>::iterator i, + std::shared_ptr>>::iterator + i, std::vector &records); /** @@ -320,8 +327,9 @@ class Meter : public metrics_api::Meter */ template void CollectSingleAsyncInstrument( - typename std::map>>::iterator i, + typename std::map< + std::string, + std::shared_ptr>>::iterator i, std::vector &records); /** @@ -351,18 +359,22 @@ class Meter : public metrics_api::Meter * Additionally, when creating a new instrument, the meter must check if an instrument of the same * name already exists. */ - std::map>> short_metrics_; - std::map>> int_metrics_; - std::map>> float_metrics_; - std::map>> + std::map>> + short_metrics_; + std::map>> + int_metrics_; + std::map>> + float_metrics_; + std::map>> double_metrics_; - std::map>> + std::map>> short_observers_; - std::map>> int_observers_; - std::map>> + std::map>> + int_observers_; + std::map>> float_observers_; - std::map>> + std::map>> double_observers_; std::unordered_set names_; diff --git a/sdk/include/opentelemetry/sdk/_metrics/processor.h b/sdk/include/opentelemetry/sdk/_metrics/processor.h index b37d63c5fa..dd6c421fb3 100644 --- a/sdk/include/opentelemetry/sdk/_metrics/processor.h +++ b/sdk/include/opentelemetry/sdk/_metrics/processor.h @@ -12,8 +12,6 @@ # include # include -namespace sdkmetrics = opentelemetry::sdk::metrics; - OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -26,11 +24,11 @@ class MetricsProcessor public: virtual ~MetricsProcessor() = default; - virtual std::vector CheckpointSelf() noexcept = 0; + virtual std::vector CheckpointSelf() noexcept = 0; virtual void FinishedCollection() noexcept = 0; - virtual void process(sdkmetrics::Record record) noexcept = 0; + virtual void process(opentelemetry::sdk::metrics::Record record) noexcept = 0; }; } // namespace metrics diff --git a/sdk/include/opentelemetry/sdk/_metrics/record.h b/sdk/include/opentelemetry/sdk/_metrics/record.h index 02d61b7116..a07c1595c8 100644 --- a/sdk/include/opentelemetry/sdk/_metrics/record.h +++ b/sdk/include/opentelemetry/sdk/_metrics/record.h @@ -11,8 +11,6 @@ OPENTELEMETRY_BEGIN_NAMESPACE -namespace metrics_api = opentelemetry::metrics; - namespace sdk { namespace metrics diff --git a/sdk/include/opentelemetry/sdk/_metrics/sync_instruments.h b/sdk/include/opentelemetry/sdk/_metrics/sync_instruments.h index 55890f44f0..46274571af 100644 --- a/sdk/include/opentelemetry/sdk/_metrics/sync_instruments.h +++ b/sdk/include/opentelemetry/sdk/_metrics/sync_instruments.h @@ -14,8 +14,6 @@ # include "opentelemetry/sdk/_metrics/aggregator/min_max_sum_count_aggregator.h" # include "opentelemetry/sdk/_metrics/instrument.h" -namespace metrics_api = opentelemetry::metrics; - OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { @@ -28,7 +26,8 @@ namespace metrics # endif template -class BoundCounter final : public BoundSynchronousInstrument, public metrics_api::BoundCounter +class BoundCounter final : public BoundSynchronousInstrument, + public opentelemetry::metrics::BoundCounter { public: @@ -43,9 +42,9 @@ class BoundCounter final : public BoundSynchronousInstrument, public metrics_ description, unit, enabled, - metrics_api::InstrumentKind::Counter, + opentelemetry::metrics::InstrumentKind::Counter, std::shared_ptr>(new CounterAggregator( - metrics_api::InstrumentKind::Counter))) // Aggregator is chosen here + opentelemetry::metrics::InstrumentKind::Counter))) // Aggregator is chosen here {} /* @@ -73,7 +72,7 @@ class BoundCounter final : public BoundSynchronousInstrument, public metrics_ }; template -class Counter final : public SynchronousInstrument, public metrics_api::Counter +class Counter final : public SynchronousInstrument, public opentelemetry::metrics::Counter { public: @@ -87,7 +86,7 @@ class Counter final : public SynchronousInstrument, public metrics_api::Count description, unit, enabled, - metrics_api::InstrumentKind::Counter) + opentelemetry::metrics::InstrumentKind::Counter) {} /* @@ -98,14 +97,14 @@ class Counter final : public SynchronousInstrument, public metrics_api::Count * @return a BoundCounter tied to the specified labels */ - virtual nostd::shared_ptr> bindCounter( + virtual nostd::shared_ptr> bindCounter( const opentelemetry::common::KeyValueIterable &labels) override { this->mu_.lock(); std::string labelset = KvToString(labels); if (boundInstruments_.find(labelset) == boundInstruments_.end()) { - auto sp1 = nostd::shared_ptr>( + auto sp1 = nostd::shared_ptr>( new BoundCounter(this->name_, this->description_, this->unit_, this->enabled_)); boundInstruments_[labelset] = sp1; this->mu_.unlock(); @@ -179,13 +178,13 @@ class Counter final : public SynchronousInstrument, public metrics_api::Count // A collection of the bound instruments created by this unbound instrument identified by their // labels. - std::unordered_map>> + std::unordered_map>> boundInstruments_; }; template class BoundUpDownCounter final : public BoundSynchronousInstrument, - virtual public metrics_api::BoundUpDownCounter + virtual public opentelemetry::metrics::BoundUpDownCounter { public: @@ -199,9 +198,9 @@ class BoundUpDownCounter final : public BoundSynchronousInstrument, description, unit, enabled, - metrics_api::InstrumentKind::UpDownCounter, + opentelemetry::metrics::InstrumentKind::UpDownCounter, std::shared_ptr>(new CounterAggregator( - metrics_api::InstrumentKind::UpDownCounter))) + opentelemetry::metrics::InstrumentKind::UpDownCounter))) {} /* @@ -215,7 +214,8 @@ class BoundUpDownCounter final : public BoundSynchronousInstrument, }; template -class UpDownCounter final : public SynchronousInstrument, public metrics_api::UpDownCounter +class UpDownCounter final : public SynchronousInstrument, + public opentelemetry::metrics::UpDownCounter { public: @@ -229,7 +229,7 @@ class UpDownCounter final : public SynchronousInstrument, public metrics_api: description, unit, enabled, - metrics_api::InstrumentKind::UpDownCounter) + opentelemetry::metrics::InstrumentKind::UpDownCounter) {} /* @@ -239,14 +239,14 @@ class UpDownCounter final : public SynchronousInstrument, public metrics_api: * @param labels the set of labels, as key-value pairs. * @return a BoundIntCounter tied to the specified labels */ - nostd::shared_ptr> bindUpDownCounter( + nostd::shared_ptr> bindUpDownCounter( const opentelemetry::common::KeyValueIterable &labels) override { this->mu_.lock(); std::string labelset = KvToString(labels); if (boundInstruments_.find(labelset) == boundInstruments_.end()) { - auto sp1 = nostd::shared_ptr>( + auto sp1 = nostd::shared_ptr>( new BoundUpDownCounter(this->name_, this->description_, this->unit_, this->enabled_)); boundInstruments_[labelset] = sp1; this->mu_.unlock(); @@ -307,13 +307,13 @@ class UpDownCounter final : public SynchronousInstrument, public metrics_api: add(val, labels); } - std::unordered_map>> + std::unordered_map>> boundInstruments_; }; template class BoundValueRecorder final : public BoundSynchronousInstrument, - public metrics_api::BoundValueRecorder + public opentelemetry::metrics::BoundValueRecorder { public: @@ -328,9 +328,9 @@ class BoundValueRecorder final : public BoundSynchronousInstrument, description, unit, enabled, - metrics_api::InstrumentKind::ValueRecorder, - std::shared_ptr>( - new MinMaxSumCountAggregator(metrics_api::InstrumentKind::ValueRecorder))) + opentelemetry::metrics::InstrumentKind::ValueRecorder, + std::shared_ptr>(new MinMaxSumCountAggregator( + opentelemetry::metrics::InstrumentKind::ValueRecorder))) {} /* @@ -344,7 +344,8 @@ class BoundValueRecorder final : public BoundSynchronousInstrument, }; template -class ValueRecorder final : public SynchronousInstrument, public metrics_api::ValueRecorder +class ValueRecorder final : public SynchronousInstrument, + public opentelemetry::metrics::ValueRecorder { public: @@ -358,7 +359,7 @@ class ValueRecorder final : public SynchronousInstrument, public metrics_api: description, unit, enabled, - metrics_api::InstrumentKind::ValueRecorder) + opentelemetry::metrics::InstrumentKind::ValueRecorder) {} /* @@ -368,14 +369,14 @@ class ValueRecorder final : public SynchronousInstrument, public metrics_api: * @param labels the set of labels, as key-value pairs. * @return a BoundIntCounter tied to the specified labels */ - nostd::shared_ptr> bindValueRecorder( + nostd::shared_ptr> bindValueRecorder( const opentelemetry::common::KeyValueIterable &labels) override { this->mu_.lock(); std::string labelset = KvToString(labels); if (boundInstruments_.find(labelset) == boundInstruments_.end()) { - auto sp1 = nostd::shared_ptr>( + auto sp1 = nostd::shared_ptr>( new BoundValueRecorder(this->name_, this->description_, this->unit_, this->enabled_)); boundInstruments_[labelset] = sp1; this->mu_.unlock(); @@ -436,7 +437,7 @@ class ValueRecorder final : public SynchronousInstrument, public metrics_api: record(value, labels); } - std::unordered_map>> + std::unordered_map>> boundInstruments_; }; diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index dd46c3ac6a..452ba924b4 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -20,8 +20,6 @@ namespace sdk { namespace trace { -namespace trace_api = opentelemetry::trace; - /** * A sampling Decision for a Span to be created. */ @@ -65,7 +63,7 @@ class Sampler * @param trace_id the TraceId for the new Span. This will be identical to that in * the parentContext, unless this is a root span. * @param name the name of the new Span. - * @param spanKind the trace_api::SpanKind of the Span. + * @param spanKind the opentelemetry::trace::SpanKind of the Span. * @param attributes list of AttributeValue with their keys. * @param links Collection of links that will be associated with the Span to be created. * @return sampling result whether span should be sampled or not. @@ -73,12 +71,12 @@ class Sampler */ virtual SamplingResult ShouldSample( - const trace_api::SpanContext &parent_context, - trace_api::TraceId trace_id, + const opentelemetry::trace::SpanContext &parent_context, + opentelemetry::trace::TraceId trace_id, nostd::string_view name, - trace_api::SpanKind span_kind, + opentelemetry::trace::SpanKind span_kind, const opentelemetry::common::KeyValueIterable &attributes, - const trace_api::SpanContextKeyValueIterable &links) noexcept = 0; + const opentelemetry::trace::SpanContextKeyValueIterable &links) noexcept = 0; /** * Returns the sampler name or short description with the configuration. diff --git a/sdk/include/opentelemetry/sdk/trace/samplers/always_off.h b/sdk/include/opentelemetry/sdk/trace/samplers/always_off.h index 96fb034c5d..2392b9b2fb 100644 --- a/sdk/include/opentelemetry/sdk/trace/samplers/always_off.h +++ b/sdk/include/opentelemetry/sdk/trace/samplers/always_off.h @@ -10,8 +10,6 @@ namespace sdk { namespace trace { -namespace trace_api = opentelemetry::trace; - /** * The always off sampler always returns DROP, effectively disabling * tracing functionality. @@ -23,12 +21,12 @@ class AlwaysOffSampler : public Sampler * @return Returns DROP always */ SamplingResult ShouldSample( - const trace_api::SpanContext &parent_context, - trace_api::TraceId /*trace_id*/, + const opentelemetry::trace::SpanContext &parent_context, + opentelemetry::trace::TraceId /*trace_id*/, nostd::string_view /*name*/, - trace_api::SpanKind /*span_kind*/, + opentelemetry::trace::SpanKind /*span_kind*/, const opentelemetry::common::KeyValueIterable & /*attributes*/, - const trace_api::SpanContextKeyValueIterable & /*links*/) noexcept override + const opentelemetry::trace::SpanContextKeyValueIterable & /*links*/) noexcept override { if (!parent_context.IsValid()) { diff --git a/sdk/include/opentelemetry/sdk/trace/samplers/always_on.h b/sdk/include/opentelemetry/sdk/trace/samplers/always_on.h index c2e63eb308..6c8583599d 100644 --- a/sdk/include/opentelemetry/sdk/trace/samplers/always_on.h +++ b/sdk/include/opentelemetry/sdk/trace/samplers/always_on.h @@ -10,8 +10,6 @@ namespace sdk { namespace trace { -namespace trace_api = opentelemetry::trace; - /** * The always on sampler is a default sampler which always return Decision::RECORD_AND_SAMPLE */ @@ -22,12 +20,12 @@ class AlwaysOnSampler : public Sampler * @return Always return Decision RECORD_AND_SAMPLE */ inline SamplingResult ShouldSample( - const trace_api::SpanContext &parent_context, - trace_api::TraceId /*trace_id*/, + const opentelemetry::trace::SpanContext &parent_context, + opentelemetry::trace::TraceId /*trace_id*/, nostd::string_view /*name*/, - trace_api::SpanKind /*span_kind*/, + opentelemetry::trace::SpanKind /*span_kind*/, const opentelemetry::common::KeyValueIterable & /*attributes*/, - const trace_api::SpanContextKeyValueIterable & /*links*/) noexcept override + const opentelemetry::trace::SpanContextKeyValueIterable & /*links*/) noexcept override { if (!parent_context.IsValid()) { diff --git a/sdk/include/opentelemetry/sdk/trace/samplers/parent.h b/sdk/include/opentelemetry/sdk/trace/samplers/parent.h index ad2be2e36e..c76a6c2a58 100644 --- a/sdk/include/opentelemetry/sdk/trace/samplers/parent.h +++ b/sdk/include/opentelemetry/sdk/trace/samplers/parent.h @@ -11,8 +11,6 @@ namespace sdk { namespace trace { -namespace trace_api = opentelemetry::trace; - /** * The ParentBased sampler is a composite sampler. ParentBased(delegateSampler) either respects * the parent span's sampling decision or delegates to delegateSampler for root spans. @@ -26,12 +24,12 @@ class ParentBasedSampler : public Sampler * @return Returns DROP always */ SamplingResult ShouldSample( - const trace_api::SpanContext &parent_context, - trace_api::TraceId trace_id, + const opentelemetry::trace::SpanContext &parent_context, + opentelemetry::trace::TraceId trace_id, nostd::string_view name, - trace_api::SpanKind span_kind, + opentelemetry::trace::SpanKind span_kind, const opentelemetry::common::KeyValueIterable &attributes, - const trace_api::SpanContextKeyValueIterable &links) noexcept override; + const opentelemetry::trace::SpanContextKeyValueIterable &links) noexcept override; /** * @return Description MUST be ParentBased{delegate_sampler_.getDescription()} diff --git a/sdk/include/opentelemetry/sdk/trace/samplers/trace_id_ratio.h b/sdk/include/opentelemetry/sdk/trace/samplers/trace_id_ratio.h index 52670249e1..407b480d62 100644 --- a/sdk/include/opentelemetry/sdk/trace/samplers/trace_id_ratio.h +++ b/sdk/include/opentelemetry/sdk/trace/samplers/trace_id_ratio.h @@ -10,7 +10,6 @@ namespace sdk { namespace trace { -namespace trace_api = opentelemetry::trace; /** * The TraceIdRatioBased sampler computes and returns a decision based on the * provided trace_id and the configured ratio. @@ -33,12 +32,12 @@ class TraceIdRatioBasedSampler : public Sampler * ratio to determine whether this trace should be sampled */ SamplingResult ShouldSample( - const trace_api::SpanContext & /*parent_context*/, - trace_api::TraceId trace_id, + const opentelemetry::trace::SpanContext & /*parent_context*/, + opentelemetry::trace::TraceId trace_id, nostd::string_view /*name*/, - trace_api::SpanKind /*span_kind*/, + opentelemetry::trace::SpanKind /*span_kind*/, const opentelemetry::common::KeyValueIterable & /*attributes*/, - const trace_api::SpanContextKeyValueIterable & /*links*/) noexcept override; + const opentelemetry::trace::SpanContextKeyValueIterable & /*links*/) noexcept override; /** * @return Description MUST be TraceIdRatioBasedSampler{0.000100} diff --git a/sdk/src/trace/samplers/parent.cc b/sdk/src/trace/samplers/parent.cc index 599798ca3c..3aa6b4a455 100644 --- a/sdk/src/trace/samplers/parent.cc +++ b/sdk/src/trace/samplers/parent.cc @@ -3,6 +3,8 @@ #include "opentelemetry/sdk/trace/samplers/parent.h" +namespace trace_api = opentelemetry::trace; + OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { diff --git a/sdk/src/trace/span.h b/sdk/src/trace/span.h index f57023c20a..f507afbefb 100644 --- a/sdk/src/trace/span.h +++ b/sdk/src/trace/span.h @@ -13,22 +13,20 @@ namespace sdk { namespace trace { -namespace trace_api = opentelemetry::trace; - -class Span final : public trace_api::Span +class Span final : public opentelemetry::trace::Span { public: Span(std::shared_ptr &&tracer, nostd::string_view name, const opentelemetry::common::KeyValueIterable &attributes, - const trace_api::SpanContextKeyValueIterable &links, - const trace_api::StartSpanOptions &options, - const trace_api::SpanContext &parent_span_context, - std::unique_ptr span_context) noexcept; + const opentelemetry::trace::SpanContextKeyValueIterable &links, + const opentelemetry::trace::StartSpanOptions &options, + const opentelemetry::trace::SpanContext &parent_span_context, + std::unique_ptr span_context) noexcept; ~Span() override; - // trace_api::Span + // trace::Span void SetAttribute(nostd::string_view key, const opentelemetry::common::AttributeValue &value) noexcept override; @@ -41,22 +39,26 @@ class Span final : public trace_api::Span opentelemetry::common::SystemTimestamp timestamp, const opentelemetry::common::KeyValueIterable &attributes) noexcept override; - void SetStatus(trace_api::StatusCode code, nostd::string_view description) noexcept override; + void SetStatus(opentelemetry::trace::StatusCode code, + nostd::string_view description) noexcept override; void UpdateName(nostd::string_view name) noexcept override; - void End(const trace_api::EndSpanOptions &options = {}) noexcept override; + void End(const opentelemetry::trace::EndSpanOptions &options = {}) noexcept override; bool IsRecording() const noexcept override; - trace_api::SpanContext GetContext() const noexcept override { return *span_context_.get(); } + opentelemetry::trace::SpanContext GetContext() const noexcept override + { + return *span_context_.get(); + } private: std::shared_ptr tracer_; mutable std::mutex mu_; std::unique_ptr recordable_; opentelemetry::common::SteadyTimestamp start_steady_time; - std::unique_ptr span_context_; + std::unique_ptr span_context_; bool has_ended_; }; } // namespace trace diff --git a/sdk/test/_metrics/ungrouped_processor_test.cc b/sdk/test/_metrics/ungrouped_processor_test.cc index 301b4739bd..934bfe23e6 100644 --- a/sdk/test/_metrics/ungrouped_processor_test.cc +++ b/sdk/test/_metrics/ungrouped_processor_test.cc @@ -7,7 +7,7 @@ # include "opentelemetry/nostd/shared_ptr.h" # include "opentelemetry/sdk/_metrics/aggregator/counter_aggregator.h" -namespace sdkmetrics = opentelemetry::sdk::metrics; +namespace metric_sdk = opentelemetry::sdk::metrics; namespace metrics_api = opentelemetry::metrics; namespace nostd = opentelemetry::nostd; @@ -15,14 +15,14 @@ namespace nostd = opentelemetry::nostd; call FinishedCollection and see the map reset */ TEST(UngroupedMetricsProcessor, UngroupedProcessorFinishedCollectionStateless) { - auto processor = std::unique_ptr( - new sdkmetrics::UngroupedMetricsProcessor(false)); + auto processor = std::unique_ptr( + new metric_sdk::UngroupedMetricsProcessor(false)); - auto aggregator = std::shared_ptr>( - new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); + auto aggregator = std::shared_ptr>( + new metric_sdk::CounterAggregator(metrics_api::InstrumentKind::Counter)); - auto aggregator2 = std::shared_ptr>( - new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); + auto aggregator2 = std::shared_ptr>( + new metric_sdk::CounterAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(5.5); aggregator->checkpoint(); @@ -30,14 +30,14 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorFinishedCollectionStateless) aggregator2->update(500.4); aggregator2->checkpoint(); - sdkmetrics::Record r("name", "description", "labels", aggregator); + metric_sdk::Record r("name", "description", "labels", aggregator); // Must have different (name, description, label, instrument) to map to - sdkmetrics::Record r2("name2", "description2", "labels2", aggregator2); + metric_sdk::Record r2("name2", "description2", "labels2", aggregator2); processor->process(r); processor->process(r2); - std::vector checkpoint = processor->CheckpointSelf(); + std::vector checkpoint = processor->CheckpointSelf(); ASSERT_EQ(checkpoint.size(), 2); processor->FinishedCollection(); @@ -50,14 +50,14 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorFinishedCollectionStateless) call FinishedCollection and see the map stay the same */ TEST(UngroupedMetricsProcessor, UngroupedProcessorFinishedCollectionStateful) { - auto processor = std::unique_ptr( - new sdkmetrics::UngroupedMetricsProcessor(true)); + auto processor = std::unique_ptr( + new metric_sdk::UngroupedMetricsProcessor(true)); - auto aggregator = std::shared_ptr>( - new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); + auto aggregator = std::shared_ptr>( + new metric_sdk::CounterAggregator(metrics_api::InstrumentKind::Counter)); - auto aggregator2 = std::shared_ptr>( - new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); + auto aggregator2 = std::shared_ptr>( + new metric_sdk::CounterAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(5.5); aggregator->checkpoint(); @@ -65,14 +65,14 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorFinishedCollectionStateful) aggregator2->update(500.4); aggregator2->checkpoint(); - sdkmetrics::Record r("name", "description", "labels", aggregator); + metric_sdk::Record r("name", "description", "labels", aggregator); // Must have different (name, description, label, instrument) to map to - sdkmetrics::Record r2("name2", "description2", "labels2", aggregator2); + metric_sdk::Record r2("name2", "description2", "labels2", aggregator2); processor->process(r); processor->process(r2); - std::vector checkpoint = processor->CheckpointSelf(); + std::vector checkpoint = processor->CheckpointSelf(); ASSERT_EQ(checkpoint.size(), 2); processor->FinishedCollection(); @@ -83,95 +83,95 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorFinishedCollectionStateful) // Test to make sure we keep information from record(short) that goes through process() TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStatelessShort) { - auto processor = std::unique_ptr( - new sdkmetrics::UngroupedMetricsProcessor(false)); + auto processor = std::unique_ptr( + new metric_sdk::UngroupedMetricsProcessor(false)); - auto aggregator = std::shared_ptr>( - new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); + auto aggregator = std::shared_ptr>( + new metric_sdk::CounterAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(4); aggregator->checkpoint(); - sdkmetrics::Record r("name", "description", "labels", aggregator); + metric_sdk::Record r("name", "description", "labels", aggregator); processor->process(r); - std::vector checkpoint = processor->CheckpointSelf(); + std::vector checkpoint = processor->CheckpointSelf(); ASSERT_EQ(checkpoint[0].GetName(), "name"); ASSERT_EQ(checkpoint[0].GetLabels(), "labels"); ASSERT_EQ(checkpoint[0].GetDescription(), "description"); ASSERT_EQ( - nostd::get>>(checkpoint[0].GetAggregator()), + nostd::get>>(checkpoint[0].GetAggregator()), aggregator); } // Test to make sure we keep information from record(int) that goes through process() TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStatelessInt) { - auto processor = std::unique_ptr( - new sdkmetrics::UngroupedMetricsProcessor(false)); + auto processor = std::unique_ptr( + new metric_sdk::UngroupedMetricsProcessor(false)); - auto aggregator = std::shared_ptr>( - new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); + auto aggregator = std::shared_ptr>( + new metric_sdk::CounterAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(5); aggregator->checkpoint(); - sdkmetrics::Record r("name", "description", "labels", aggregator); + metric_sdk::Record r("name", "description", "labels", aggregator); processor->process(r); - std::vector checkpoint = processor->CheckpointSelf(); + std::vector checkpoint = processor->CheckpointSelf(); ASSERT_EQ(checkpoint[0].GetName(), "name"); ASSERT_EQ(checkpoint[0].GetLabels(), "labels"); ASSERT_EQ(checkpoint[0].GetDescription(), "description"); - ASSERT_EQ(nostd::get>>(checkpoint[0].GetAggregator()), + ASSERT_EQ(nostd::get>>(checkpoint[0].GetAggregator()), aggregator); } // Test to make sure we keep information from record(float) that goes through process() TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStatelessFloat) { - auto processor = std::unique_ptr( - new sdkmetrics::UngroupedMetricsProcessor(false)); + auto processor = std::unique_ptr( + new metric_sdk::UngroupedMetricsProcessor(false)); - auto aggregator = std::shared_ptr>( - new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); + auto aggregator = std::shared_ptr>( + new metric_sdk::CounterAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(8.5); aggregator->checkpoint(); - sdkmetrics::Record r("name", "description", "labels", aggregator); + metric_sdk::Record r("name", "description", "labels", aggregator); processor->process(r); - std::vector checkpoint = processor->CheckpointSelf(); + std::vector checkpoint = processor->CheckpointSelf(); ASSERT_EQ(checkpoint[0].GetName(), "name"); ASSERT_EQ(checkpoint[0].GetLabels(), "labels"); ASSERT_EQ(checkpoint[0].GetDescription(), "description"); ASSERT_EQ( - nostd::get>>(checkpoint[0].GetAggregator()), + nostd::get>>(checkpoint[0].GetAggregator()), aggregator); } // Test to make sure we keep information from record(double) that goes through process() TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStatelessDouble) { - auto processor = std::unique_ptr( - new sdkmetrics::UngroupedMetricsProcessor(false)); + auto processor = std::unique_ptr( + new metric_sdk::UngroupedMetricsProcessor(false)); - auto aggregator = std::shared_ptr>( - new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); + auto aggregator = std::shared_ptr>( + new metric_sdk::CounterAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(5.5); aggregator->checkpoint(); - sdkmetrics::Record r("name", "description", "labels", aggregator); + metric_sdk::Record r("name", "description", "labels", aggregator); processor->process(r); - std::vector checkpoint = processor->CheckpointSelf(); + std::vector checkpoint = processor->CheckpointSelf(); ASSERT_EQ(checkpoint[0].GetName(), "name"); ASSERT_EQ(checkpoint[0].GetLabels(), "labels"); ASSERT_EQ(checkpoint[0].GetDescription(), "description"); ASSERT_EQ( - nostd::get>>(checkpoint[0].GetAggregator()), + nostd::get>>(checkpoint[0].GetAggregator()), aggregator); } @@ -183,29 +183,29 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateles */ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStatefulShort) { - auto processor = std::unique_ptr( - new sdkmetrics::UngroupedMetricsProcessor(true)); + auto processor = std::unique_ptr( + new metric_sdk::UngroupedMetricsProcessor(true)); - auto aggregator = std::shared_ptr>( - new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); + auto aggregator = std::shared_ptr>( + new metric_sdk::CounterAggregator(metrics_api::InstrumentKind::Counter)); - auto aggregator_test = std::shared_ptr>( - new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); + auto aggregator_test = std::shared_ptr>( + new metric_sdk::CounterAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(5); aggregator_test->update(5); aggregator->checkpoint(); - sdkmetrics::Record r("name", "description", "labels", aggregator); + metric_sdk::Record r("name", "description", "labels", aggregator); processor->process(r); - std::vector checkpoint = processor->CheckpointSelf(); + std::vector checkpoint = processor->CheckpointSelf(); ASSERT_EQ(checkpoint[0].GetName(), "name"); ASSERT_EQ(checkpoint[0].GetLabels(), "labels"); ASSERT_EQ(checkpoint[0].GetDescription(), "description"); ASSERT_EQ( - nostd::get>>(checkpoint[0].GetAggregator()) + nostd::get>>(checkpoint[0].GetAggregator()) ->get_checkpoint(), aggregator->get_checkpoint()); @@ -216,38 +216,38 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful processor->process(r); - std::vector checkpoint2 = processor->CheckpointSelf(); + std::vector checkpoint2 = processor->CheckpointSelf(); ASSERT_EQ(checkpoint2.size(), 1); ASSERT_EQ( - nostd::get>>(checkpoint[0].GetAggregator()) + nostd::get>>(checkpoint[0].GetAggregator()) ->get_checkpoint()[0], aggregator_test->get_checkpoint()[0]); } TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStatefulInt) { - auto processor = std::unique_ptr( - new sdkmetrics::UngroupedMetricsProcessor(true)); + auto processor = std::unique_ptr( + new metric_sdk::UngroupedMetricsProcessor(true)); - auto aggregator = std::shared_ptr>( - new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); + auto aggregator = std::shared_ptr>( + new metric_sdk::CounterAggregator(metrics_api::InstrumentKind::Counter)); - auto aggregator_test = std::shared_ptr>( - new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); + auto aggregator_test = std::shared_ptr>( + new metric_sdk::CounterAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(5); aggregator_test->update(5); aggregator->checkpoint(); - sdkmetrics::Record r("name", "description", "labels", aggregator); + metric_sdk::Record r("name", "description", "labels", aggregator); processor->process(r); - std::vector checkpoint = processor->CheckpointSelf(); + std::vector checkpoint = processor->CheckpointSelf(); ASSERT_EQ(checkpoint[0].GetName(), "name"); ASSERT_EQ(checkpoint[0].GetLabels(), "labels"); ASSERT_EQ(checkpoint[0].GetDescription(), "description"); - ASSERT_EQ(nostd::get>>(checkpoint[0].GetAggregator()) + ASSERT_EQ(nostd::get>>(checkpoint[0].GetAggregator()) ->get_checkpoint(), aggregator->get_checkpoint()); @@ -258,38 +258,38 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful processor->process(r); - std::vector checkpoint2 = processor->CheckpointSelf(); + std::vector checkpoint2 = processor->CheckpointSelf(); ASSERT_EQ(checkpoint2.size(), 1); - ASSERT_EQ(nostd::get>>(checkpoint[0].GetAggregator()) + ASSERT_EQ(nostd::get>>(checkpoint[0].GetAggregator()) ->get_checkpoint()[0], aggregator_test->get_checkpoint()[0]); } TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStatefulFloat) { - auto processor = std::unique_ptr( - new sdkmetrics::UngroupedMetricsProcessor(true)); + auto processor = std::unique_ptr( + new metric_sdk::UngroupedMetricsProcessor(true)); - auto aggregator = std::shared_ptr>( - new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); + auto aggregator = std::shared_ptr>( + new metric_sdk::CounterAggregator(metrics_api::InstrumentKind::Counter)); - auto aggregator_test = std::shared_ptr>( - new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); + auto aggregator_test = std::shared_ptr>( + new metric_sdk::CounterAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(5); aggregator_test->update(5); aggregator->checkpoint(); - sdkmetrics::Record r("name", "description", "labels", aggregator); + metric_sdk::Record r("name", "description", "labels", aggregator); processor->process(r); - std::vector checkpoint = processor->CheckpointSelf(); + std::vector checkpoint = processor->CheckpointSelf(); ASSERT_EQ(checkpoint[0].GetName(), "name"); ASSERT_EQ(checkpoint[0].GetLabels(), "labels"); ASSERT_EQ(checkpoint[0].GetDescription(), "description"); ASSERT_EQ( - nostd::get>>(checkpoint[0].GetAggregator()) + nostd::get>>(checkpoint[0].GetAggregator()) ->get_checkpoint(), aggregator->get_checkpoint()); @@ -300,39 +300,39 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful processor->process(r); - std::vector checkpoint2 = processor->CheckpointSelf(); + std::vector checkpoint2 = processor->CheckpointSelf(); ASSERT_EQ(checkpoint2.size(), 1); ASSERT_EQ( - nostd::get>>(checkpoint[0].GetAggregator()) + nostd::get>>(checkpoint[0].GetAggregator()) ->get_checkpoint()[0], aggregator_test->get_checkpoint()[0]); } TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStatefulDouble) { - auto processor = std::unique_ptr( - new sdkmetrics::UngroupedMetricsProcessor(true)); + auto processor = std::unique_ptr( + new metric_sdk::UngroupedMetricsProcessor(true)); - auto aggregator = std::shared_ptr>( - new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); + auto aggregator = std::shared_ptr>( + new metric_sdk::CounterAggregator(metrics_api::InstrumentKind::Counter)); - auto aggregator_test = std::shared_ptr>( - new sdkmetrics::CounterAggregator(metrics_api::InstrumentKind::Counter)); + auto aggregator_test = std::shared_ptr>( + new metric_sdk::CounterAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(5.5); aggregator_test->update(5.5); aggregator->checkpoint(); - sdkmetrics::Record r("name", "description", "labels", aggregator); + metric_sdk::Record r("name", "description", "labels", aggregator); processor->process(r); - std::vector checkpoint = processor->CheckpointSelf(); + std::vector checkpoint = processor->CheckpointSelf(); ASSERT_EQ(checkpoint[0].GetName(), "name"); ASSERT_EQ(checkpoint[0].GetLabels(), "labels"); ASSERT_EQ(checkpoint[0].GetDescription(), "description"); ASSERT_EQ( - nostd::get>>(checkpoint[0].GetAggregator()) + nostd::get>>(checkpoint[0].GetAggregator()) ->get_checkpoint(), aggregator->get_checkpoint()); @@ -343,24 +343,24 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful processor->process(r); - std::vector checkpoint2 = processor->CheckpointSelf(); + std::vector checkpoint2 = processor->CheckpointSelf(); ASSERT_EQ(checkpoint2.size(), 1); ASSERT_EQ( - nostd::get>>(checkpoint[0].GetAggregator()) + nostd::get>>(checkpoint[0].GetAggregator()) ->get_checkpoint()[0], aggregator_test->get_checkpoint()[0]); } TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStatefulMinMaxSumCount) { - auto processor = std::unique_ptr( - new sdkmetrics::UngroupedMetricsProcessor(true)); + auto processor = std::unique_ptr( + new metric_sdk::UngroupedMetricsProcessor(true)); - auto aggregator = std::shared_ptr>( - new sdkmetrics::MinMaxSumCountAggregator(metrics_api::InstrumentKind::Counter)); + auto aggregator = std::shared_ptr>( + new metric_sdk::MinMaxSumCountAggregator(metrics_api::InstrumentKind::Counter)); - auto aggregator2 = std::shared_ptr>( - new sdkmetrics::MinMaxSumCountAggregator(metrics_api::InstrumentKind::Counter)); + auto aggregator2 = std::shared_ptr>( + new metric_sdk::MinMaxSumCountAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(1.1); aggregator->update(2.2); @@ -368,16 +368,16 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful aggregator2->update(2.2); aggregator->checkpoint(); - sdkmetrics::Record r("name", "description", "labels", aggregator); + metric_sdk::Record r("name", "description", "labels", aggregator); processor->process(r); - std::vector checkpoint = processor->CheckpointSelf(); + std::vector checkpoint = processor->CheckpointSelf(); ASSERT_EQ(checkpoint[0].GetName(), "name"); ASSERT_EQ(checkpoint[0].GetLabels(), "labels"); ASSERT_EQ(checkpoint[0].GetDescription(), "description"); ASSERT_EQ( - nostd::get>>(checkpoint[0].GetAggregator()) + nostd::get>>(checkpoint[0].GetAggregator()) ->get_checkpoint(), aggregator->get_checkpoint()); @@ -388,36 +388,36 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful processor->process(r); - std::vector checkpoint2 = processor->CheckpointSelf(); + std::vector checkpoint2 = processor->CheckpointSelf(); ASSERT_EQ(checkpoint2.size(), 1); ASSERT_EQ( - nostd::get>>(checkpoint2[0].GetAggregator()) + nostd::get>>(checkpoint2[0].GetAggregator()) ->get_checkpoint(), aggregator2->get_checkpoint()); } TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStatefulGauge) { - auto processor = std::unique_ptr( - new sdkmetrics::UngroupedMetricsProcessor(true)); + auto processor = std::unique_ptr( + new metric_sdk::UngroupedMetricsProcessor(true)); - auto aggregator = std::shared_ptr>( - new sdkmetrics::GaugeAggregator(metrics_api::InstrumentKind::Counter)); + auto aggregator = std::shared_ptr>( + new metric_sdk::GaugeAggregator(metrics_api::InstrumentKind::Counter)); aggregator->update(1.1); aggregator->update(2.2); aggregator->checkpoint(); - sdkmetrics::Record r("name", "description", "labels", aggregator); + metric_sdk::Record r("name", "description", "labels", aggregator); processor->process(r); - std::vector checkpoint = processor->CheckpointSelf(); + std::vector checkpoint = processor->CheckpointSelf(); ASSERT_EQ(checkpoint[0].GetName(), "name"); ASSERT_EQ(checkpoint[0].GetLabels(), "labels"); ASSERT_EQ(checkpoint[0].GetDescription(), "description"); ASSERT_EQ( - nostd::get>>(checkpoint[0].GetAggregator()) + nostd::get>>(checkpoint[0].GetAggregator()) ->get_checkpoint(), aggregator->get_checkpoint()); @@ -426,24 +426,24 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful processor->process(r); - std::vector checkpoint2 = processor->CheckpointSelf(); + std::vector checkpoint2 = processor->CheckpointSelf(); ASSERT_EQ(checkpoint2.size(), 1); ASSERT_EQ( - nostd::get>>(checkpoint2[0].GetAggregator()) + nostd::get>>(checkpoint2[0].GetAggregator()) ->get_checkpoint(), aggregator->get_checkpoint()); } TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStatefulExact) { - auto processor = std::unique_ptr( - new sdkmetrics::UngroupedMetricsProcessor(true)); + auto processor = std::unique_ptr( + new metric_sdk::UngroupedMetricsProcessor(true)); - auto aggregator = std::shared_ptr>( - new sdkmetrics::ExactAggregator(metrics_api::InstrumentKind::Counter, false)); + auto aggregator = std::shared_ptr>( + new metric_sdk::ExactAggregator(metrics_api::InstrumentKind::Counter, false)); - auto aggregator2 = std::shared_ptr>( - new sdkmetrics::ExactAggregator(metrics_api::InstrumentKind::Counter, false)); + auto aggregator2 = std::shared_ptr>( + new metric_sdk::ExactAggregator(metrics_api::InstrumentKind::Counter, false)); aggregator->update(1.1); aggregator->update(2.2); @@ -451,16 +451,16 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful aggregator2->update(2.2); aggregator->checkpoint(); - sdkmetrics::Record r("name", "description", "labels", aggregator); + metric_sdk::Record r("name", "description", "labels", aggregator); processor->process(r); - std::vector checkpoint = processor->CheckpointSelf(); + std::vector checkpoint = processor->CheckpointSelf(); ASSERT_EQ(checkpoint[0].GetName(), "name"); ASSERT_EQ(checkpoint[0].GetLabels(), "labels"); ASSERT_EQ(checkpoint[0].GetDescription(), "description"); ASSERT_EQ( - nostd::get>>(checkpoint[0].GetAggregator()) + nostd::get>>(checkpoint[0].GetAggregator()) ->get_checkpoint(), aggregator->get_checkpoint()); @@ -471,26 +471,26 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful processor->process(r); - std::vector checkpoint2 = processor->CheckpointSelf(); + std::vector checkpoint2 = processor->CheckpointSelf(); ASSERT_EQ(checkpoint2.size(), 1); ASSERT_EQ( - nostd::get>>(checkpoint2[0].GetAggregator()) + nostd::get>>(checkpoint2[0].GetAggregator()) ->get_checkpoint(), aggregator2->get_checkpoint()); } TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStatefulHistogram) { - auto processor = std::unique_ptr( - new sdkmetrics::UngroupedMetricsProcessor(true)); + auto processor = std::unique_ptr( + new metric_sdk::UngroupedMetricsProcessor(true)); std::vector boundaries{10, 20, 30, 40, 50}; - auto aggregator = std::shared_ptr>( - new sdkmetrics::HistogramAggregator(metrics_api::InstrumentKind::Counter, boundaries)); + auto aggregator = std::shared_ptr>( + new metric_sdk::HistogramAggregator(metrics_api::InstrumentKind::Counter, boundaries)); - auto aggregator2 = std::shared_ptr>( - new sdkmetrics::HistogramAggregator(metrics_api::InstrumentKind::Counter, boundaries)); + auto aggregator2 = std::shared_ptr>( + new metric_sdk::HistogramAggregator(metrics_api::InstrumentKind::Counter, boundaries)); for (int i = 0; i < 60; i++) { @@ -499,18 +499,18 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful } aggregator->checkpoint(); - sdkmetrics::Record r("name", "description", "labels", aggregator); + metric_sdk::Record r("name", "description", "labels", aggregator); processor->process(r); - std::vector checkpoint = processor->CheckpointSelf(); + std::vector checkpoint = processor->CheckpointSelf(); ASSERT_EQ(checkpoint[0].GetName(), "name"); ASSERT_EQ(checkpoint[0].GetLabels(), "labels"); ASSERT_EQ(checkpoint[0].GetDescription(), "description"); - ASSERT_EQ(nostd::get>>(checkpoint[0].GetAggregator()) + ASSERT_EQ(nostd::get>>(checkpoint[0].GetAggregator()) ->get_boundaries(), aggregator->get_boundaries()); - ASSERT_EQ(nostd::get>>(checkpoint[0].GetAggregator()) + ASSERT_EQ(nostd::get>>(checkpoint[0].GetAggregator()) ->get_counts(), aggregator->get_counts()); @@ -524,33 +524,33 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful processor->process(r); - std::vector checkpoint2 = processor->CheckpointSelf(); + std::vector checkpoint2 = processor->CheckpointSelf(); ASSERT_EQ(checkpoint2.size(), 1); ASSERT_EQ(checkpoint2[0].GetName(), "name"); ASSERT_EQ(checkpoint2[0].GetLabels(), "labels"); ASSERT_EQ(checkpoint2[0].GetDescription(), "description"); - ASSERT_EQ(nostd::get>>(checkpoint2[0].GetAggregator()) + ASSERT_EQ(nostd::get>>(checkpoint2[0].GetAggregator()) ->get_boundaries(), aggregator->get_boundaries()); - ASSERT_EQ(nostd::get>>(checkpoint2[0].GetAggregator()) + ASSERT_EQ(nostd::get>>(checkpoint2[0].GetAggregator()) ->get_counts(), aggregator2->get_counts()); - ASSERT_EQ(nostd::get>>(checkpoint2[0].GetAggregator()) + ASSERT_EQ(nostd::get>>(checkpoint2[0].GetAggregator()) ->get_checkpoint(), aggregator2->get_checkpoint()); } TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStatefulSketch) { - auto processor = std::unique_ptr( - new sdkmetrics::UngroupedMetricsProcessor(true)); + auto processor = std::unique_ptr( + new metric_sdk::UngroupedMetricsProcessor(true)); - auto aggregator = std::shared_ptr>( - new sdkmetrics::SketchAggregator(metrics_api::InstrumentKind::Counter, .00005)); + auto aggregator = std::shared_ptr>( + new metric_sdk::SketchAggregator(metrics_api::InstrumentKind::Counter, .00005)); - auto test_aggregator = std::shared_ptr>( - new sdkmetrics::SketchAggregator(metrics_api::InstrumentKind::Counter, .00005)); + auto test_aggregator = std::shared_ptr>( + new metric_sdk::SketchAggregator(metrics_api::InstrumentKind::Counter, .00005)); for (int i = 0; i < 60; i++) { @@ -559,18 +559,18 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful } aggregator->checkpoint(); - sdkmetrics::Record r("name", "description", "labels", aggregator); + metric_sdk::Record r("name", "description", "labels", aggregator); processor->process(r); - std::vector checkpoint = processor->CheckpointSelf(); + std::vector checkpoint = processor->CheckpointSelf(); ASSERT_EQ(checkpoint[0].GetName(), "name"); ASSERT_EQ(checkpoint[0].GetLabels(), "labels"); ASSERT_EQ(checkpoint[0].GetDescription(), "description"); - ASSERT_EQ(nostd::get>>(checkpoint[0].GetAggregator()) + ASSERT_EQ(nostd::get>>(checkpoint[0].GetAggregator()) ->get_boundaries(), aggregator->get_boundaries()); - ASSERT_EQ(nostd::get>>(checkpoint[0].GetAggregator()) + ASSERT_EQ(nostd::get>>(checkpoint[0].GetAggregator()) ->get_counts(), aggregator->get_counts()); @@ -584,17 +584,17 @@ TEST(UngroupedMetricsProcessor, UngroupedProcessorKeepsRecordInformationStateful processor->process(r); - std::vector checkpoint2 = processor->CheckpointSelf(); + std::vector checkpoint2 = processor->CheckpointSelf(); ASSERT_EQ(checkpoint2[0].GetName(), "name"); ASSERT_EQ(checkpoint2[0].GetLabels(), "labels"); ASSERT_EQ(checkpoint2[0].GetDescription(), "description"); - ASSERT_EQ(nostd::get>>(checkpoint2[0].GetAggregator()) + ASSERT_EQ(nostd::get>>(checkpoint2[0].GetAggregator()) ->get_boundaries(), test_aggregator->get_boundaries()); - ASSERT_EQ(nostd::get>>(checkpoint2[0].GetAggregator()) + ASSERT_EQ(nostd::get>>(checkpoint2[0].GetAggregator()) ->get_counts(), test_aggregator->get_counts()); - ASSERT_EQ(nostd::get>>(checkpoint2[0].GetAggregator()) + ASSERT_EQ(nostd::get>>(checkpoint2[0].GetAggregator()) ->get_checkpoint(), test_aggregator->get_checkpoint()); } diff --git a/sdk/test/trace/always_on_sampler_test.cc b/sdk/test/trace/always_on_sampler_test.cc index 28ad4cfdfc..c483f9b8be 100644 --- a/sdk/test/trace/always_on_sampler_test.cc +++ b/sdk/test/trace/always_on_sampler_test.cc @@ -11,6 +11,7 @@ using namespace opentelemetry::sdk::trace; using namespace opentelemetry::nostd; using opentelemetry::trace::SpanContext; +namespace trace_api = opentelemetry::trace; TEST(AlwaysOnSampler, ShouldSample) { From 23d99c393ed9e25063321f152d4fe34f4cb40925 Mon Sep 17 00:00:00 2001 From: PaurushGarg Date: Sun, 7 Nov 2021 22:08:27 -0800 Subject: [PATCH 13/16] Fixing the review comments on consistent namespace of sdk and namespace aliases in header files --- .vscode/settings.json | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index e9ddeba5ba..0000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "files.associations": { - "typeinfo": "cpp", - "__locale": "cpp", - "memory": "cpp" - } -} \ No newline at end of file From 04bfe70f339bfee903ccfca7ddf9ad8808042f49 Mon Sep 17 00:00:00 2001 From: PaurushGarg Date: Sun, 7 Nov 2021 23:12:16 -0800 Subject: [PATCH 14/16] Removed errors --- .../opentelemetry/trace/span_context.h | 21 +- exporters/ostream/src/metrics_exporter.cc | 12 +- .../sdk/_metrics/aggregator/aggregator.h | 7 +- .../sdk/_metrics/ungrouped_processor.h | 199 ++++++++++-------- sdk/src/_metrics/meter.cc | 3 + sdk/src/_metrics/ungrouped_processor.cc | 58 ++--- 6 files changed, 168 insertions(+), 132 deletions(-) diff --git a/api/include/opentelemetry/trace/span_context.h b/api/include/opentelemetry/trace/span_context.h index da4ce37ce6..569a3c1e71 100644 --- a/api/include/opentelemetry/trace/span_context.h +++ b/api/include/opentelemetry/trace/span_context.h @@ -29,7 +29,7 @@ class SpanContext final SpanContext(bool sampled_flag, bool is_remote) : trace_id_(), span_id_(), - trace_flags_(trace::TraceFlags((uint8_t)sampled_flag)), + trace_flags_(opentelemetry::trace::TraceFlags((uint8_t)sampled_flag)), is_remote_(is_remote), trace_state_(TraceState::GetDefault()) {} @@ -52,16 +52,19 @@ class SpanContext final bool IsValid() const noexcept { return trace_id_.IsValid() && span_id_.IsValid(); } // @returns the trace_flags associated with this span_context - const trace::TraceFlags &trace_flags() const noexcept { return trace_flags_; } + const opentelemetry::trace::TraceFlags &trace_flags() const noexcept { return trace_flags_; } // @returns the trace_id associated with this span_context - const trace::TraceId &trace_id() const noexcept { return trace_id_; } + const opentelemetry::trace::TraceId &trace_id() const noexcept { return trace_id_; } // @returns the span_id associated with this span_context - const trace::SpanId &span_id() const noexcept { return span_id_; } + const opentelemetry::trace::SpanId &span_id() const noexcept { return span_id_; } // @returns the trace_state associated with this span_context - const nostd::shared_ptr trace_state() const noexcept { return trace_state_; } + const nostd::shared_ptr trace_state() const noexcept + { + return trace_state_; + } /* * @param that SpanContext for comparing. @@ -83,11 +86,11 @@ class SpanContext final bool IsSampled() const noexcept { return trace_flags_.IsSampled(); } private: - trace::TraceId trace_id_; - trace::SpanId span_id_; - trace::TraceFlags trace_flags_; + opentelemetry::trace::TraceId trace_id_; + opentelemetry::trace::SpanId span_id_; + opentelemetry::trace::TraceFlags trace_flags_; bool is_remote_; - nostd::shared_ptr trace_state_; + nostd::shared_ptr trace_state_; }; } // namespace trace OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/ostream/src/metrics_exporter.cc b/exporters/ostream/src/metrics_exporter.cc index c310b7c856..4f4bbfd065 100644 --- a/exporters/ostream/src/metrics_exporter.cc +++ b/exporters/ostream/src/metrics_exporter.cc @@ -28,19 +28,23 @@ sdk::common::ExportResult OStreamMetricsExporter::Export( * Unpack the AggregatorVariant from the record so we can pass the data type to * PrintAggregatorVariant to unpack the Aggregator from the variant. */ - if (nostd::holds_alternative>>(aggregator)) + if (nostd::holds_alternative>>( + aggregator)) { PrintAggregatorVariant(aggregator); } - else if (nostd::holds_alternative>>(aggregator)) + else if (nostd::holds_alternative< + std::shared_ptr>>(aggregator)) { PrintAggregatorVariant(aggregator); } - else if (nostd::holds_alternative>>(aggregator)) + else if (nostd::holds_alternative< + std::shared_ptr>>(aggregator)) { PrintAggregatorVariant(aggregator); } - else if (nostd::holds_alternative>>(aggregator)) + else if (nostd::holds_alternative< + std::shared_ptr>>(aggregator)) { PrintAggregatorVariant(aggregator); } diff --git a/sdk/include/opentelemetry/sdk/_metrics/aggregator/aggregator.h b/sdk/include/opentelemetry/sdk/_metrics/aggregator/aggregator.h index 897a7f86a0..f6821d7319 100644 --- a/sdk/include/opentelemetry/sdk/_metrics/aggregator/aggregator.h +++ b/sdk/include/opentelemetry/sdk/_metrics/aggregator/aggregator.h @@ -89,10 +89,7 @@ class Aggregator * @param none * @return the InstrumentKind of the aggregator's owner */ - virtual opentelemetry::opentelemetry::metrics::InstrumentKind get_instrument_kind() final - { - return kind_; - } + virtual opentelemetry::metrics::InstrumentKind get_instrument_kind() final { return kind_; } /** * Returns the type of this aggregator @@ -147,7 +144,7 @@ class Aggregator protected: std::vector values_; std::vector checkpoint_; - opentelemetry::opentelemetry::metrics::InstrumentKind kind_; + opentelemetry::metrics::InstrumentKind kind_; std::mutex mu_; AggregatorKind agg_kind_; bool updated_; diff --git a/sdk/include/opentelemetry/sdk/_metrics/ungrouped_processor.h b/sdk/include/opentelemetry/sdk/_metrics/ungrouped_processor.h index 2a12be4270..5894144c7f 100644 --- a/sdk/include/opentelemetry/sdk/_metrics/ungrouped_processor.h +++ b/sdk/include/opentelemetry/sdk/_metrics/ungrouped_processor.h @@ -28,13 +28,13 @@ struct KeyStruct std::string name; std::string description; std::string labels; - metrics_api::InstrumentKind ins_kind; + opentelemetry::metrics::InstrumentKind ins_kind; // constructor KeyStruct(std::string name, std::string description, std::string labels, - metrics_api::InstrumentKind ins_kind) + opentelemetry::metrics::InstrumentKind ins_kind) { this->name = name; this->description = description; @@ -68,44 +68,51 @@ class UngroupedMetricsProcessor : public MetricsProcessor public: explicit UngroupedMetricsProcessor(bool stateful); - std::vector CheckpointSelf() noexcept override; + std::vector CheckpointSelf() noexcept override; virtual void FinishedCollection() noexcept override; - virtual void process(sdkmetrics::Record record) noexcept override; + virtual void process(opentelemetry::sdk::metrics::Record record) noexcept override; private: bool stateful_; - std::unordered_map batch_map_; + std::unordered_map + batch_map_; /** * get_instrument returns the instrument from the passed in AggregatorVariant. We have to * unpack the variant then get the instrument from the Aggreagtor. */ - metrics_api::InstrumentKind get_instrument(sdkmetrics::AggregatorVariant aggregator) + opentelemetry::metrics::InstrumentKind get_instrument( + opentelemetry::sdk::metrics::AggregatorVariant aggregator) { - if (nostd::holds_alternative>>(aggregator)) + if (nostd::holds_alternative>>( + aggregator)) { - return nostd::get>>(aggregator) + return nostd::get>>(aggregator) ->get_instrument_kind(); } - else if (nostd::holds_alternative>>(aggregator)) + else if (nostd::holds_alternative< + std::shared_ptr>>(aggregator)) { - return nostd::get>>(aggregator) + return nostd::get>>(aggregator) ->get_instrument_kind(); } - else if (nostd::holds_alternative>>(aggregator)) + else if (nostd::holds_alternative< + std::shared_ptr>>(aggregator)) { - return nostd::get>>(aggregator) + return nostd::get>>(aggregator) ->get_instrument_kind(); } - else if (nostd::holds_alternative>>(aggregator)) + else if (nostd::holds_alternative< + std::shared_ptr>>(aggregator)) { - return nostd::get>>(aggregator) + return nostd::get>>( + aggregator) ->get_instrument_kind(); } - return metrics_api::InstrumentKind::Counter; + return opentelemetry::metrics::InstrumentKind::Counter; } /** @@ -114,41 +121,44 @@ class UngroupedMetricsProcessor : public MetricsProcessor * additional constructor values */ template - std::shared_ptr> aggregator_copy( - std::shared_ptr> aggregator) + std::shared_ptr> aggregator_copy( + std::shared_ptr> aggregator) { auto ins_kind = aggregator->get_instrument_kind(); auto agg_kind = aggregator->get_aggregator_kind(); switch (agg_kind) { - case sdkmetrics::AggregatorKind::Counter: - return std::shared_ptr>( - new sdkmetrics::CounterAggregator(ins_kind)); + case opentelemetry::sdk::metrics::AggregatorKind::Counter: + return std::shared_ptr>( + new opentelemetry::sdk::metrics::CounterAggregator(ins_kind)); - case sdkmetrics::AggregatorKind::MinMaxSumCount: - return std::shared_ptr>( - new sdkmetrics::MinMaxSumCountAggregator(ins_kind)); + case opentelemetry::sdk::metrics::AggregatorKind::MinMaxSumCount: + return std::shared_ptr>( + new opentelemetry::sdk::metrics::MinMaxSumCountAggregator(ins_kind)); - case sdkmetrics::AggregatorKind::Gauge: - return std::shared_ptr>( - new sdkmetrics::GaugeAggregator(ins_kind)); + case opentelemetry::sdk::metrics::AggregatorKind::Gauge: + return std::shared_ptr>( + new opentelemetry::sdk::metrics::GaugeAggregator(ins_kind)); - case sdkmetrics::AggregatorKind::Sketch: - return std::shared_ptr>(new sdkmetrics::SketchAggregator( - ins_kind, aggregator->get_error_bound(), aggregator->get_max_buckets())); + case opentelemetry::sdk::metrics::AggregatorKind::Sketch: + return std::shared_ptr>( + new opentelemetry::sdk::metrics::SketchAggregator( + ins_kind, aggregator->get_error_bound(), aggregator->get_max_buckets())); - case sdkmetrics::AggregatorKind::Histogram: - return std::shared_ptr>( - new sdkmetrics::HistogramAggregator(ins_kind, aggregator->get_boundaries())); + case opentelemetry::sdk::metrics::AggregatorKind::Histogram: + return std::shared_ptr>( + new opentelemetry::sdk::metrics::HistogramAggregator(ins_kind, + aggregator->get_boundaries())); - case sdkmetrics::AggregatorKind::Exact: - return std::shared_ptr>( - new sdkmetrics::ExactAggregator(ins_kind, aggregator->get_quant_estimation())); + case opentelemetry::sdk::metrics::AggregatorKind::Exact: + return std::shared_ptr>( + new opentelemetry::sdk::metrics::ExactAggregator( + ins_kind, aggregator->get_quant_estimation())); default: - return std::shared_ptr>( - new sdkmetrics::CounterAggregator(ins_kind)); + return std::shared_ptr>( + new opentelemetry::sdk::metrics::CounterAggregator(ins_kind)); } }; @@ -158,37 +168,38 @@ class UngroupedMetricsProcessor : public MetricsProcessor * pipeline. */ template - std::shared_ptr> aggregator_for(metrics_api::InstrumentKind ins_kind) + std::shared_ptr> aggregator_for( + opentelemetry::metrics::InstrumentKind ins_kind) { switch (ins_kind) { - case metrics_api::InstrumentKind::Counter: - return std::shared_ptr>( - new sdkmetrics::CounterAggregator(ins_kind)); + case opentelemetry::metrics::InstrumentKind::Counter: + return std::shared_ptr>( + new opentelemetry::sdk::metrics::CounterAggregator(ins_kind)); - case metrics_api::InstrumentKind::UpDownCounter: - return std::shared_ptr>( - new sdkmetrics::CounterAggregator(ins_kind)); + case opentelemetry::metrics::InstrumentKind::UpDownCounter: + return std::shared_ptr>( + new opentelemetry::sdk::metrics::CounterAggregator(ins_kind)); - case metrics_api::InstrumentKind::ValueRecorder: - return std::shared_ptr>( - new sdkmetrics::MinMaxSumCountAggregator(ins_kind)); + case opentelemetry::metrics::InstrumentKind::ValueRecorder: + return std::shared_ptr>( + new opentelemetry::sdk::metrics::MinMaxSumCountAggregator(ins_kind)); - case metrics_api::InstrumentKind::SumObserver: - return std::shared_ptr>( - new sdkmetrics::CounterAggregator(ins_kind)); + case opentelemetry::metrics::InstrumentKind::SumObserver: + return std::shared_ptr>( + new opentelemetry::sdk::metrics::CounterAggregator(ins_kind)); - case metrics_api::InstrumentKind::UpDownSumObserver: - return std::shared_ptr>( - new sdkmetrics::CounterAggregator(ins_kind)); + case opentelemetry::metrics::InstrumentKind::UpDownSumObserver: + return std::shared_ptr>( + new opentelemetry::sdk::metrics::CounterAggregator(ins_kind)); - case metrics_api::InstrumentKind::ValueObserver: - return std::shared_ptr>( - new sdkmetrics::MinMaxSumCountAggregator(ins_kind)); + case opentelemetry::metrics::InstrumentKind::ValueObserver: + return std::shared_ptr>( + new opentelemetry::sdk::metrics::MinMaxSumCountAggregator(ins_kind)); default: - return std::shared_ptr>( - new sdkmetrics::CounterAggregator(ins_kind)); + return std::shared_ptr>( + new opentelemetry::sdk::metrics::CounterAggregator(ins_kind)); } }; @@ -199,82 +210,90 @@ class UngroupedMetricsProcessor : public MetricsProcessor * pointer and merge them together. */ template - void merge_aggregators(std::shared_ptr> batch_agg, - std::shared_ptr> record_agg) + void merge_aggregators(std::shared_ptr> batch_agg, + std::shared_ptr> record_agg) { auto agg_kind = batch_agg->get_aggregator_kind(); - if (agg_kind == sdkmetrics::AggregatorKind::Counter) + if (agg_kind == opentelemetry::sdk::metrics::AggregatorKind::Counter) { - std::shared_ptr> temp_batch_agg_counter = - std::dynamic_pointer_cast>(batch_agg); + std::shared_ptr> temp_batch_agg_counter = + std::dynamic_pointer_cast>(batch_agg); - std::shared_ptr> temp_record_agg_counter = - std::dynamic_pointer_cast>(record_agg); + std::shared_ptr> temp_record_agg_counter = + std::dynamic_pointer_cast>(record_agg); auto temp_batch_agg_raw_counter = temp_batch_agg_counter.get(); auto temp_record_agg_raw_counter = temp_record_agg_counter.get(); temp_batch_agg_raw_counter->merge(*temp_record_agg_raw_counter); } - else if (agg_kind == sdkmetrics::AggregatorKind::MinMaxSumCount) + else if (agg_kind == opentelemetry::sdk::metrics::AggregatorKind::MinMaxSumCount) { - std::shared_ptr> temp_batch_agg_mmsc = - std::dynamic_pointer_cast>(batch_agg); + std::shared_ptr> + temp_batch_agg_mmsc = + std::dynamic_pointer_cast>( + batch_agg); - std::shared_ptr> temp_record_agg_mmsc = - std::dynamic_pointer_cast>(record_agg); + std::shared_ptr> + temp_record_agg_mmsc = + std::dynamic_pointer_cast>( + record_agg); auto temp_batch_agg_raw_mmsc = temp_batch_agg_mmsc.get(); auto temp_record_agg_raw_mmsc = temp_record_agg_mmsc.get(); temp_batch_agg_raw_mmsc->merge(*temp_record_agg_raw_mmsc); } - else if (agg_kind == sdkmetrics::AggregatorKind::Gauge) + else if (agg_kind == opentelemetry::sdk::metrics::AggregatorKind::Gauge) { - std::shared_ptr> temp_batch_agg_gauge = - std::dynamic_pointer_cast>(batch_agg); + std::shared_ptr> temp_batch_agg_gauge = + std::dynamic_pointer_cast>(batch_agg); - std::shared_ptr> temp_record_agg_gauge = - std::dynamic_pointer_cast>(record_agg); + std::shared_ptr> temp_record_agg_gauge = + std::dynamic_pointer_cast>(record_agg); auto temp_batch_agg_raw_gauge = temp_batch_agg_gauge.get(); auto temp_record_agg_raw_gauge = temp_record_agg_gauge.get(); temp_batch_agg_raw_gauge->merge(*temp_record_agg_raw_gauge); } - else if (agg_kind == sdkmetrics::AggregatorKind::Sketch) + else if (agg_kind == opentelemetry::sdk::metrics::AggregatorKind::Sketch) { - std::shared_ptr> temp_batch_agg_sketch = - std::dynamic_pointer_cast>(batch_agg); + std::shared_ptr> temp_batch_agg_sketch = + std::dynamic_pointer_cast>(batch_agg); - std::shared_ptr> temp_record_agg_sketch = - std::dynamic_pointer_cast>(record_agg); + std::shared_ptr> temp_record_agg_sketch = + std::dynamic_pointer_cast>(record_agg); auto temp_batch_agg_raw_sketch = temp_batch_agg_sketch.get(); auto temp_record_agg_raw_sketch = temp_record_agg_sketch.get(); temp_batch_agg_raw_sketch->merge(*temp_record_agg_raw_sketch); } - else if (agg_kind == sdkmetrics::AggregatorKind::Histogram) + else if (agg_kind == opentelemetry::sdk::metrics::AggregatorKind::Histogram) { - std::shared_ptr> temp_batch_agg_histogram = - std::dynamic_pointer_cast>(batch_agg); + std::shared_ptr> + temp_batch_agg_histogram = + std::dynamic_pointer_cast>( + batch_agg); - std::shared_ptr> temp_record_agg_histogram = - std::dynamic_pointer_cast>(record_agg); + std::shared_ptr> + temp_record_agg_histogram = + std::dynamic_pointer_cast>( + record_agg); auto temp_batch_agg_raw_histogram = temp_batch_agg_histogram.get(); auto temp_record_agg_raw_histogram = temp_record_agg_histogram.get(); temp_batch_agg_raw_histogram->merge(*temp_record_agg_raw_histogram); } - else if (agg_kind == sdkmetrics::AggregatorKind::Exact) + else if (agg_kind == opentelemetry::sdk::metrics::AggregatorKind::Exact) { - std::shared_ptr> temp_batch_agg_exact = - std::dynamic_pointer_cast>(batch_agg); + std::shared_ptr> temp_batch_agg_exact = + std::dynamic_pointer_cast>(batch_agg); - std::shared_ptr> temp_record_agg_exact = - std::dynamic_pointer_cast>(record_agg); + std::shared_ptr> temp_record_agg_exact = + std::dynamic_pointer_cast>(record_agg); auto temp_batch_agg_raw_exact = temp_batch_agg_exact.get(); auto temp_record_agg_raw_exact = temp_record_agg_exact.get(); diff --git a/sdk/src/_metrics/meter.cc b/sdk/src/_metrics/meter.cc index be5d094022..5207865b9c 100644 --- a/sdk/src/_metrics/meter.cc +++ b/sdk/src/_metrics/meter.cc @@ -3,6 +3,9 @@ #ifdef ENABLE_METRICS_PREVIEW # include "opentelemetry/sdk/_metrics/meter.h" + +namespace metrics_api = opentelemetry::metrics; + OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { diff --git a/sdk/src/_metrics/ungrouped_processor.cc b/sdk/src/_metrics/ungrouped_processor.cc index 6d3598b59c..b3d1a94ebf 100644 --- a/sdk/src/_metrics/ungrouped_processor.cc +++ b/sdk/src/_metrics/ungrouped_processor.cc @@ -21,15 +21,16 @@ UngroupedMetricsProcessor::UngroupedMetricsProcessor(bool stateful) * CheckpointSelf will return a vector of records to be exported. This function will go through *aggregators that have been sent through process() and return them as a vector of records. **/ -std::vector UngroupedMetricsProcessor::CheckpointSelf() noexcept +std::vector +UngroupedMetricsProcessor::CheckpointSelf() noexcept { - std::vector metric_records; + std::vector metric_records; for (auto iter : batch_map_) { // Create a record from the held KeyStruct values and add to the Checkpoint KeyStruct key = iter.first; - sdkmetrics::Record r{key.name, key.description, key.labels, iter.second}; + opentelemetry::sdk::metrics::Record r{key.name, key.description, key.labels, iter.second}; metric_records.push_back(r); } @@ -49,7 +50,7 @@ void UngroupedMetricsProcessor::FinishedCollection() noexcept } } -void UngroupedMetricsProcessor::process(sdkmetrics::Record record) noexcept +void UngroupedMetricsProcessor::process(opentelemetry::sdk::metrics::Record record) noexcept { auto aggregator = record.GetAggregator(); std::string label = record.GetLabels(); @@ -66,39 +67,43 @@ void UngroupedMetricsProcessor::process(sdkmetrics::Record record) noexcept { auto batch_value = batch_map_[batch_key]; - if (nostd::holds_alternative>>(aggregator)) + if (nostd::holds_alternative>>( + aggregator)) { auto batch_value_reference_short = - nostd::get>>(batch_value); + nostd::get>>(batch_value); auto aggregator_reference_short = - nostd::get>>(aggregator); + nostd::get>>(aggregator); merge_aggregators(batch_value_reference_short, aggregator_reference_short); } - else if (nostd::holds_alternative>>(aggregator)) + else if (nostd::holds_alternative< + std::shared_ptr>>(aggregator)) { auto batch_value_reference_int = - nostd::get>>(batch_value); + nostd::get>>(batch_value); auto aggregator_reference_int = - nostd::get>>(aggregator); + nostd::get>>(aggregator); merge_aggregators(batch_value_reference_int, aggregator_reference_int); } - else if (nostd::holds_alternative>>(aggregator)) + else if (nostd::holds_alternative< + std::shared_ptr>>(aggregator)) { auto batch_value_reference_float = - nostd::get>>(batch_value); + nostd::get>>(batch_value); auto aggregator_reference_float = - nostd::get>>(aggregator); + nostd::get>>(aggregator); merge_aggregators(batch_value_reference_float, aggregator_reference_float); } - else if (nostd::holds_alternative>>(aggregator)) + else if (nostd::holds_alternative< + std::shared_ptr>>(aggregator)) { auto batch_value_reference_double = - nostd::get>>(batch_value); + nostd::get>>(batch_value); auto aggregator_reference_double = - nostd::get>>(aggregator); + nostd::get>>(aggregator); merge_aggregators(batch_value_reference_double, aggregator_reference_double); } @@ -111,39 +116,44 @@ void UngroupedMetricsProcessor::process(sdkmetrics::Record record) noexcept **/ if (stateful_) { - if (nostd::holds_alternative>>(aggregator)) + if (nostd::holds_alternative>>( + aggregator)) { auto record_agg_short = - nostd::get>>(aggregator); + nostd::get>>(aggregator); auto aggregator_short = aggregator_copy(record_agg_short); merge_aggregators(aggregator_short, record_agg_short); batch_map_[batch_key] = aggregator_short; } - else if (nostd::holds_alternative>>(aggregator)) + else if (nostd::holds_alternative< + std::shared_ptr>>(aggregator)) { - auto record_agg_int = nostd::get>>(aggregator); + auto record_agg_int = + nostd::get>>(aggregator); auto aggregator_int = aggregator_copy(record_agg_int); merge_aggregators(aggregator_int, record_agg_int); batch_map_[batch_key] = aggregator_int; } - else if (nostd::holds_alternative>>(aggregator)) + else if (nostd::holds_alternative< + std::shared_ptr>>(aggregator)) { auto record_agg_float = - nostd::get>>(aggregator); + nostd::get>>(aggregator); auto aggregator_float = aggregator_copy(record_agg_float); merge_aggregators(aggregator_float, record_agg_float); batch_map_[batch_key] = aggregator_float; } - else if (nostd::holds_alternative>>(aggregator)) + else if (nostd::holds_alternative< + std::shared_ptr>>(aggregator)) { auto record_agg_double = - nostd::get>>(aggregator); + nostd::get>>(aggregator); auto aggregator_double = aggregator_copy(record_agg_double); merge_aggregators(aggregator_double, record_agg_double); From 27e7d8be1b94fa5e39f564eec5bb405fee95d980 Mon Sep 17 00:00:00 2001 From: PaurushGarg Date: Sat, 13 Nov 2021 11:52:33 -0800 Subject: [PATCH 15/16] Fixing the errors --- .../opentelemetry/exporters/etw/etw_tracer.h | 2 +- .../prometheus/src/prometheus_collector.cc | 2 ++ .../src/prometheus_exporter_utils.cc | 1 + .../test/prometheus_collector_test.cc | 1 + exporters/zipkin/src/zipkin_exporter.cc | 2 ++ ext/test/w3c_tracecontext_test/main.cc | 18 +++++++++--------- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h b/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h index 0efbf66745..a946e70a6f 100644 --- a/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h +++ b/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h @@ -402,7 +402,7 @@ class Tracer : public opentelemetry::trace::Tracer nostd::string_view name, Properties &evt, const opentelemetry::trace::SpanContextKeyValueIterable &links, - const opentelemetry::opentelemetry::trace::StartSpanOptions &options = {}) noexcept + const opentelemetry::trace::StartSpanOptions &options = {}) noexcept { const auto &cfg = GetConfiguration(tracerProvider_); diff --git a/exporters/prometheus/src/prometheus_collector.cc b/exporters/prometheus/src/prometheus_collector.cc index ca0daced3c..53b7913dea 100644 --- a/exporters/prometheus/src/prometheus_collector.cc +++ b/exporters/prometheus/src/prometheus_collector.cc @@ -6,6 +6,8 @@ # include "opentelemetry/exporters/prometheus/prometheus_collector.h" +namespace metric_sdk = opentelemetry::sdk::metrics; + OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { diff --git a/exporters/prometheus/src/prometheus_exporter_utils.cc b/exporters/prometheus/src/prometheus_exporter_utils.cc index fcc4615c6b..5eec9e3e86 100644 --- a/exporters/prometheus/src/prometheus_exporter_utils.cc +++ b/exporters/prometheus/src/prometheus_exporter_utils.cc @@ -12,6 +12,7 @@ # include "prometheus/metric_type.h" namespace prometheus_client = ::prometheus; +namespace metric_sdk = opentelemetry::sdk::metrics; OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/exporters/prometheus/test/prometheus_collector_test.cc b/exporters/prometheus/test/prometheus_collector_test.cc index 355dfe2b45..d1aff1b0f4 100644 --- a/exporters/prometheus/test/prometheus_collector_test.cc +++ b/exporters/prometheus/test/prometheus_collector_test.cc @@ -21,6 +21,7 @@ using opentelemetry::exporter::prometheus::PrometheusCollector; namespace metric_api = opentelemetry::metrics; +namespace metric_sdk = opentelemetry::sdk::metrics; OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/exporters/zipkin/src/zipkin_exporter.cc b/exporters/zipkin/src/zipkin_exporter.cc index 8fffcf67ae..457bfa4b35 100644 --- a/exporters/zipkin/src/zipkin_exporter.cc +++ b/exporters/zipkin/src/zipkin_exporter.cc @@ -7,6 +7,8 @@ #include "opentelemetry/ext/http/common/url_parser.h" #include "opentelemetry/sdk_config.h" +namespace http_client = opentelemetry::ext::http::client; + OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { diff --git a/ext/test/w3c_tracecontext_test/main.cc b/ext/test/w3c_tracecontext_test/main.cc index a9a334d613..79aa4c9169 100644 --- a/ext/test/w3c_tracecontext_test/main.cc +++ b/ext/test/w3c_tracecontext_test/main.cc @@ -18,6 +18,8 @@ namespace trace_api = opentelemetry::trace; namespace http_client = opentelemetry::ext::http::client; namespace curl = opentelemetry::ext::http::client::curl; namespace context = opentelemetry::context; +namespace nostd = opentelemetry::nostd; +namespace trace_sdk = opentelemetry::sdk::trace; namespace { @@ -46,15 +48,15 @@ class TextMapCarrierTest : public context::propagation::TextMapCarrier void initTracer() { - auto exporter = std::unique_ptr( + auto exporter = std::unique_ptr( new opentelemetry::exporter::trace::OStreamSpanExporter); - auto processor = std::unique_ptr( - new sdktrace::SimpleSpanProcessor(std::move(exporter))); - std::vector> processors; + auto processor = std::unique_ptr( + new trace_sdk::SimpleSpanProcessor(std::move(exporter))); + std::vector> processors; processors.push_back(std::move(processor)); - auto context = std::make_shared(std::move(processors)); + auto context = std::make_shared(std::move(processors)); auto provider = - nostd::shared_ptr(new sdktrace::TracerProvider(context)); + nostd::shared_ptr(new trace_sdk::TracerProvider(context)); // Set the global trace provider trace_api::Provider::SetTracerProvider(provider); } @@ -87,9 +89,7 @@ struct Uri class NoopEventHandler : public http_client::EventHandler { public: - void OnEvent(http_client::SessionState state, - opentelemetry::nostd::string_view reason) noexcept override - {} + void OnEvent(http_client::SessionState state, nostd::string_view reason) noexcept override {} void OnConnecting(const http_client::SSLCertificate &) noexcept override {} From 13a7259fd945fe41c862237638cbbac6cbeb178e Mon Sep 17 00:00:00 2001 From: PaurushGarg Date: Sun, 14 Nov 2021 21:51:05 -0800 Subject: [PATCH 16/16] Removing Errors --- exporters/jaeger/src/jaeger_exporter.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/exporters/jaeger/src/jaeger_exporter.cc b/exporters/jaeger/src/jaeger_exporter.cc index 2bf181c54a..6d1291130c 100644 --- a/exporters/jaeger/src/jaeger_exporter.cc +++ b/exporters/jaeger/src/jaeger_exporter.cc @@ -11,6 +11,9 @@ #include +namespace sdk_common = opentelemetry::sdk::common; +namespace trace_sdk = opentelemetry::sdk::trace; + OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter {