From 773a172ddbf692bd98e2352f9f6dbf807d2c5a78 Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Tue, 13 Jun 2023 01:16:06 +0800 Subject: [PATCH] Remove include_trace_context (#2194) --- CHANGELOG.md | 3 +++ api/include/opentelemetry/logs/logger_provider.h | 7 ++----- api/include/opentelemetry/logs/noop.h | 1 - api/test/logs/logger_test.cc | 1 - api/test/logs/provider_test.cc | 1 - .../opentelemetry/exporters/etw/etw_logger.h | 2 -- exporters/ostream/test/ostream_log_test.cc | 4 ++-- .../test/otlp_grpc_log_record_exporter_test.cc | 2 +- .../test/otlp_http_log_record_exporter_test.cc | 8 ++++---- sdk/include/opentelemetry/sdk/logs/logger.h | 5 +---- .../opentelemetry/sdk/logs/logger_provider.h | 1 - sdk/src/logs/logger.cc | 14 ++++++-------- sdk/src/logs/logger_provider.cc | 3 +-- sdk/test/logs/log_record_test.cc | 4 +--- sdk/test/logs/logger_provider_sdk_test.cc | 4 ++-- sdk/test/logs/logger_sdk_test.cc | 6 +++--- 16 files changed, 26 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a58e5ad3ca..3330790d2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,9 @@ Increment the: ## [Unreleased] +* [API] Remove include_trace_context + [#2194](https://github.com/open-telemetry/opentelemetry-cpp/pull/2194) + ## [1.9.1] 2023-05-26 * [DEPRECATION] Drop C++11 support diff --git a/api/include/opentelemetry/logs/logger_provider.h b/api/include/opentelemetry/logs/logger_provider.h index 89723725b8..e2a72bcc54 100644 --- a/api/include/opentelemetry/logs/logger_provider.h +++ b/api/include/opentelemetry/logs/logger_provider.h @@ -43,7 +43,6 @@ class OPENTELEMETRY_EXPORT LoggerProvider nostd::string_view library_name = "", nostd::string_view library_version = "", nostd::string_view schema_url = "", - bool include_trace_context = true, const common::KeyValueIterable &attributes = common::NoopKeyValueIterable()) = 0; nostd::shared_ptr GetLogger( @@ -51,10 +50,9 @@ class OPENTELEMETRY_EXPORT LoggerProvider nostd::string_view library_name, nostd::string_view library_version, nostd::string_view schema_url, - bool include_trace_context, std::initializer_list> attributes) { - return GetLogger(logger_name, library_name, library_version, schema_url, include_trace_context, + return GetLogger(logger_name, library_name, library_version, schema_url, nostd::span>{ attributes.begin(), attributes.end()}); } @@ -65,10 +63,9 @@ class OPENTELEMETRY_EXPORT LoggerProvider nostd::string_view library_name, nostd::string_view library_version, nostd::string_view schema_url, - bool include_trace_context, const T &attributes) { - return GetLogger(logger_name, library_name, library_version, schema_url, include_trace_context, + return GetLogger(logger_name, library_name, library_version, schema_url, common::KeyValueIterableView(attributes)); } }; diff --git a/api/include/opentelemetry/logs/noop.h b/api/include/opentelemetry/logs/noop.h index ed4ba64bc7..5303b2e77f 100644 --- a/api/include/opentelemetry/logs/noop.h +++ b/api/include/opentelemetry/logs/noop.h @@ -54,7 +54,6 @@ class NoopLoggerProvider final : public LoggerProvider nostd::string_view /* library_name */, nostd::string_view /* library_version */, nostd::string_view /* schema_url */, - bool /* include_trace_context */, const common::KeyValueIterable & /* attributes */) override { return logger_; diff --git a/api/test/logs/logger_test.cc b/api/test/logs/logger_test.cc index ccdcd990c5..789ffd1259 100644 --- a/api/test/logs/logger_test.cc +++ b/api/test/logs/logger_test.cc @@ -202,7 +202,6 @@ class TestProvider : public LoggerProvider nostd::string_view /* library_name */, nostd::string_view /* library_version */, nostd::string_view /* schema_url */, - bool /* include_trace_context */, const common::KeyValueIterable & /* attributes */) override { return nostd::shared_ptr(new TestLogger()); diff --git a/api/test/logs/provider_test.cc b/api/test/logs/provider_test.cc index 0d607f1d01..27af9b0c43 100644 --- a/api/test/logs/provider_test.cc +++ b/api/test/logs/provider_test.cc @@ -24,7 +24,6 @@ class TestProvider : public LoggerProvider nostd::string_view /* library_name */, nostd::string_view /* library_version */, nostd::string_view /* schema_url */, - bool /* include_trace_context */, const opentelemetry::common::KeyValueIterable & /* attributes */) override { return shared_ptr(nullptr); diff --git a/exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h b/exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h index ccf332b599..8040032597 100644 --- a/exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h +++ b/exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h @@ -359,13 +359,11 @@ class LoggerProvider : public opentelemetry::logs::LoggerProvider nostd::string_view library_name, nostd::string_view version = "", nostd::string_view schema_url = "", - bool include_trace_context = true, const common::KeyValueIterable &attributes = common::NoopKeyValueIterable()) override { UNREFERENCED_PARAMETER(library_name); UNREFERENCED_PARAMETER(version); UNREFERENCED_PARAMETER(schema_url); - UNREFERENCED_PARAMETER(include_trace_context); UNREFERENCED_PARAMETER(attributes); ETWProvider::EventFormat evtFmt = config_.encoding; return nostd::shared_ptr{ diff --git a/exporters/ostream/test/ostream_log_test.cc b/exporters/ostream/test/ostream_log_test.cc index 30cf64c5eb..82bc91a747 100644 --- a/exporters/ostream/test/ostream_log_test.cc +++ b/exporters/ostream/test/ostream_log_test.cc @@ -377,7 +377,7 @@ TEST(OStreamLogRecordExporter, IntegrationTest) logs_api::Provider::SetLoggerProvider(provider); const std::string schema_url{"https://opentelemetry.io/schemas/1.11.0"}; auto logger = logs_api::Provider::GetLoggerProvider()->GetLogger( - "Logger", "opentelelemtry_library", OPENTELEMETRY_SDK_VERSION, schema_url, true, + "Logger", "opentelelemtry_library", OPENTELEMETRY_SDK_VERSION, schema_url, {{"scope.attr.key", 123}}); // Back up cout's streambuf @@ -449,7 +449,7 @@ TEST(OStreamLogRecordExporter, IntegrationTestWithEventId) logs_api::Provider::SetLoggerProvider(provider); const std::string schema_url{"https://opentelemetry.io/schemas/1.11.0"}; auto logger = logs_api::Provider::GetLoggerProvider()->GetLogger( - "Logger", "opentelelemtry_library", OPENTELEMETRY_SDK_VERSION, schema_url, true, + "Logger", "opentelelemtry_library", OPENTELEMETRY_SDK_VERSION, schema_url, {{"scope.attr.key", 123}}); // Back up cout's streambuf diff --git a/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc b/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc index a0455adb70..f2962a0b0c 100644 --- a/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc @@ -170,7 +170,7 @@ TEST_F(OtlpGrpcLogRecordExporterTestPeer, ExportIntegrationTest) auto trace_span = tracer->StartSpan("test_log"); opentelemetry::trace::Scope trace_scope{trace_span}; - auto logger = provider->GetLogger("test", "opentelelemtry_library", "", schema_url, true, + auto logger = provider->GetLogger("test", "opentelelemtry_library", "", schema_url, {{"scope_key1", "scope_value"}, {"scope_key2", 2}}); std::unordered_map attributes; attributes["service.name"] = "unit_test_service"; diff --git a/exporters/otlp/test/otlp_http_log_record_exporter_test.cc b/exporters/otlp/test/otlp_http_log_record_exporter_test.cc index aba1c9c503..7720b6e5d8 100644 --- a/exporters/otlp/test/otlp_http_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_log_record_exporter_test.cc @@ -143,7 +143,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test opentelemetry::trace::SpanId span_id{span_id_bin}; const std::string schema_url{"https://opentelemetry.io/schemas/1.2.0"}; - auto logger = provider->GetLogger("test", "opentelelemtry_library", "", schema_url, true, + auto logger = provider->GetLogger("test", "opentelelemtry_library", "", schema_url, {{"scope_key1", "scope_value"}, {"scope_key2", 2}}); trace_id.ToLowerBase16(MakeSpan(trace_id_hex)); @@ -260,7 +260,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test opentelemetry::trace::SpanId span_id{span_id_bin}; const std::string schema_url{"https://opentelemetry.io/schemas/1.2.0"}; - auto logger = provider->GetLogger("test", "opentelelemtry_library", "1.2.0", schema_url, true, + auto logger = provider->GetLogger("test", "opentelelemtry_library", "1.2.0", schema_url, {{"scope_key1", "scope_value"}, {"scope_key2", 2}}); trace_id.ToLowerBase16(MakeSpan(trace_id_hex)); @@ -385,7 +385,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test opentelemetry::trace::SpanId span_id{span_id_bin}; const std::string schema_url{"https://opentelemetry.io/schemas/1.2.0"}; - auto logger = provider->GetLogger("test", "opentelelemtry_library", "1.2.0", schema_url, true, + auto logger = provider->GetLogger("test", "opentelelemtry_library", "1.2.0", schema_url, {{"scope_key1", "scope_value"}, {"scope_key2", 2}}); report_trace_id.assign(reinterpret_cast(trace_id_bin), sizeof(trace_id_bin)); @@ -498,7 +498,7 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test opentelemetry::trace::SpanId span_id{span_id_bin}; const std::string schema_url{"https://opentelemetry.io/schemas/1.2.0"}; - auto logger = provider->GetLogger("test", "opentelelemtry_library", "", schema_url, true, + auto logger = provider->GetLogger("test", "opentelelemtry_library", "", schema_url, {{"scope_key1", "scope_value"}, {"scope_key2", 2}}); report_trace_id.assign(reinterpret_cast(trace_id_bin), sizeof(trace_id_bin)); diff --git a/sdk/include/opentelemetry/sdk/logs/logger.h b/sdk/include/opentelemetry/sdk/logs/logger.h index ece83a8b57..d290df98c3 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger.h +++ b/sdk/include/opentelemetry/sdk/logs/logger.h @@ -33,8 +33,7 @@ class Logger final : public opentelemetry::logs::Logger opentelemetry::nostd::string_view name, std::shared_ptr context, std::unique_ptr instrumentation_scope = - instrumentationscope::InstrumentationScope::Create(""), - bool include_trace_context = true) noexcept; + instrumentationscope::InstrumentationScope::Create("")) noexcept; /** * Returns the name of this logger. @@ -67,8 +66,6 @@ class Logger final : public opentelemetry::logs::Logger // logger-context. std::unique_ptr instrumentation_scope_; std::shared_ptr context_; - - bool include_trace_context_; }; } // namespace logs diff --git a/sdk/include/opentelemetry/sdk/logs/logger_provider.h b/sdk/include/opentelemetry/sdk/logs/logger_provider.h index a52c1a7220..a5190c7a30 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger_provider.h +++ b/sdk/include/opentelemetry/sdk/logs/logger_provider.h @@ -78,7 +78,6 @@ class LoggerProvider final : public opentelemetry::logs::LoggerProvider nostd::string_view library_name, nostd::string_view library_version = "", nostd::string_view schema_url = "", - bool include_trace_context = true, const opentelemetry::common::KeyValueIterable &attributes = opentelemetry::common::NoopKeyValueIterable()) noexcept override; diff --git a/sdk/src/logs/logger.cc b/sdk/src/logs/logger.cc index 190bfe6f5a..4c76b198bb 100644 --- a/sdk/src/logs/logger.cc +++ b/sdk/src/logs/logger.cc @@ -16,14 +16,13 @@ namespace trace_api = opentelemetry::trace; namespace nostd = opentelemetry::nostd; namespace common = opentelemetry::common; -Logger::Logger(nostd::string_view name, - std::shared_ptr context, - std::unique_ptr instrumentation_scope, - bool include_trace_context) noexcept +Logger::Logger( + nostd::string_view name, + std::shared_ptr context, + std::unique_ptr instrumentation_scope) noexcept : logger_name_(std::string(name)), instrumentation_scope_(std::move(instrumentation_scope)), - context_(context), - include_trace_context_(include_trace_context) + context_(context) {} const nostd::string_view Logger::GetName() noexcept @@ -43,8 +42,7 @@ nostd::unique_ptr Logger::CreateLogRecord() noex recordable->SetObservedTimestamp(std::chrono::system_clock::now()); - if (include_trace_context_ && - opentelemetry::context::RuntimeContext::GetCurrent().HasKey(opentelemetry::trace::kSpanKey)) + if (opentelemetry::context::RuntimeContext::GetCurrent().HasKey(opentelemetry::trace::kSpanKey)) { opentelemetry::context::ContextValue context_value = opentelemetry::context::RuntimeContext::GetCurrent().GetValue( diff --git a/sdk/src/logs/logger_provider.cc b/sdk/src/logs/logger_provider.cc index 2f75a09247..66948b1744 100644 --- a/sdk/src/logs/logger_provider.cc +++ b/sdk/src/logs/logger_provider.cc @@ -61,7 +61,6 @@ nostd::shared_ptr LoggerProvider::GetLogger( nostd::string_view library_name, nostd::string_view library_version, nostd::string_view schema_url, - bool include_trace_context, const opentelemetry::common::KeyValueIterable &attributes) noexcept { // Ensure only one thread can read/write from the map of loggers @@ -105,7 +104,7 @@ nostd::shared_ptr LoggerProvider::GetLogger( } loggers_.push_back(std::shared_ptr( - new Logger(logger_name, context_, std::move(lib), include_trace_context))); + new Logger(logger_name, context_, std::move(lib)))); return nostd::shared_ptr{loggers_.back()}; } diff --git a/sdk/test/logs/log_record_test.cc b/sdk/test/logs/log_record_test.cc index 204827bfb0..cce81d9910 100644 --- a/sdk/test/logs/log_record_test.cc +++ b/sdk/test/logs/log_record_test.cc @@ -118,7 +118,6 @@ class TestBodyProvider : public opentelemetry::logs::LoggerProvider nostd::string_view /* library_name */, nostd::string_view /* library_version */, nostd::string_view /* schema_url */, - bool /* include_trace_context */, const opentelemetry::common::KeyValueIterable & /* attributes */) override { return nostd::shared_ptr(new TestBodyLogger()); @@ -132,8 +131,7 @@ TEST(LogBody, BodyConversation) // Check that the implementation was pushed by calling TestLogger's GetName() nostd::string_view schema_url{"https://opentelemetry.io/schemas/1.11.0"}; - auto logger = - lp.GetLogger("TestBodyProvider", "opentelelemtry_library", "", schema_url, false, {}); + auto logger = lp.GetLogger("TestBodyProvider", "opentelelemtry_library", "", schema_url, {}); auto real_logger = static_cast(logger.get()); diff --git a/sdk/test/logs/logger_provider_sdk_test.cc b/sdk/test/logs/logger_provider_sdk_test.cc index ae606876b3..510f02b4df 100644 --- a/sdk/test/logs/logger_provider_sdk_test.cc +++ b/sdk/test/logs/logger_provider_sdk_test.cc @@ -75,7 +75,7 @@ TEST(LoggerProviderSDK, LoggerProviderLoggerArguments) auto sdk_logger2 = static_cast(logger2.get()); ASSERT_EQ(sdk_logger2->GetInstrumentationScope(), sdk_logger1->GetInstrumentationScope()); - auto logger3 = lp->GetLogger("logger3", "opentelelemtry_library", "", schema_url, true, + auto logger3 = lp->GetLogger("logger3", "opentelelemtry_library", "", schema_url, {{"scope_key1", "scope_value"}, {"scope_key2", 2}}); auto sdk_logger3 = static_cast(logger3.get()); @@ -89,7 +89,7 @@ TEST(LoggerProviderSDK, LoggerProviderLoggerArguments) std::unordered_map scope_attributes = {{"scope_key", "scope_value"}}; auto logger4 = - lp->GetLogger("logger4", "opentelelemtry_library", "", schema_url, true, scope_attributes); + lp->GetLogger("logger4", "opentelelemtry_library", "", schema_url, scope_attributes); auto sdk_logger4 = static_cast(logger4.get()); EXPECT_EQ(sdk_logger4->GetInstrumentationScope().GetAttributes().size(), 1); diff --git a/sdk/test/logs/logger_sdk_test.cc b/sdk/test/logs/logger_sdk_test.cc index 78189ed8db..0e5050a973 100644 --- a/sdk/test/logs/logger_sdk_test.cc +++ b/sdk/test/logs/logger_sdk_test.cc @@ -200,13 +200,13 @@ TEST(LoggerSDK, LogToAProcessor) // Create an API LoggerProvider and logger auto api_lp = std::shared_ptr(new LoggerProvider()); const std::string schema_url{"https://opentelemetry.io/schemas/1.11.0"}; - auto logger = api_lp->GetLogger("logger", "opentelelemtry_library", "", schema_url, true); + auto logger = api_lp->GetLogger("logger", "opentelelemtry_library", "", schema_url); // Cast the API LoggerProvider to an SDK Logger Provider and assert that it is still the same // LoggerProvider by checking that getting a logger with the same name as the previously defined // logger is the same instance auto lp = static_cast(api_lp.get()); - auto logger2 = lp->GetLogger("logger", "opentelelemtry_library", "", schema_url, true); + auto logger2 = lp->GetLogger("logger", "opentelelemtry_library", "", schema_url); ASSERT_EQ(logger, logger2); nostd::shared_ptr include_span; @@ -261,7 +261,7 @@ TEST(LoggerSDK, EventLog) // Create an API LoggerProvider and logger auto api_lp = std::shared_ptr(new LoggerProvider()); const std::string schema_url{"https://opentelemetry.io/schemas/1.11.0"}; - auto logger = api_lp->GetLogger("logger", "opentelelemtry_library", "", schema_url, false); + auto logger = api_lp->GetLogger("logger", "opentelelemtry_library", "", schema_url); auto api_elp = std::shared_ptr(new EventLoggerProvider()); auto event_logger = api_elp->CreateEventLogger(logger, "otel-cpp.event_domain");