Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove include_trace_context #2194

Merged
merged 2 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions api/include/opentelemetry/logs/logger_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,16 @@ 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<Logger> GetLogger(
nostd::string_view logger_name,
nostd::string_view library_name,
nostd::string_view library_version,
nostd::string_view schema_url,
bool include_trace_context,
std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>> 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<const std::pair<nostd::string_view, common::AttributeValue>>{
attributes.begin(), attributes.end()});
}
Expand All @@ -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<T>(attributes));
}
};
Expand Down
1 change: 0 additions & 1 deletion api/include/opentelemetry/logs/noop.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
1 change: 0 additions & 1 deletion api/test/logs/logger_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Logger>(new TestLogger());
Expand Down
1 change: 0 additions & 1 deletion api/test/logs/provider_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Logger>(nullptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<opentelemetry::logs::Logger>{
Expand Down
4 changes: 2 additions & 2 deletions exporters/ostream/test/ostream_log_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, opentelemetry::v1::common::AttributeValue> attributes;
attributes["service.name"] = "unit_test_service";
Expand Down
8 changes: 4 additions & 4 deletions exporters/otlp/test/otlp_http_log_record_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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<const char *>(trace_id_bin), sizeof(trace_id_bin));
Expand Down Expand Up @@ -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<const char *>(trace_id_bin), sizeof(trace_id_bin));
Expand Down
5 changes: 1 addition & 4 deletions sdk/include/opentelemetry/sdk/logs/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ class Logger final : public opentelemetry::logs::Logger
opentelemetry::nostd::string_view name,
std::shared_ptr<LoggerContext> context,
std::unique_ptr<instrumentationscope::InstrumentationScope> instrumentation_scope =
instrumentationscope::InstrumentationScope::Create(""),
bool include_trace_context = true) noexcept;
instrumentationscope::InstrumentationScope::Create("")) noexcept;

/**
* Returns the name of this logger.
Expand Down Expand Up @@ -67,8 +66,6 @@ class Logger final : public opentelemetry::logs::Logger
// logger-context.
std::unique_ptr<instrumentationscope::InstrumentationScope> instrumentation_scope_;
std::shared_ptr<LoggerContext> context_;

bool include_trace_context_;
};

} // namespace logs
Expand Down
1 change: 0 additions & 1 deletion sdk/include/opentelemetry/sdk/logs/logger_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
14 changes: 6 additions & 8 deletions sdk/src/logs/logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<LoggerContext> context,
std::unique_ptr<instrumentationscope::InstrumentationScope> instrumentation_scope,
bool include_trace_context) noexcept
Logger::Logger(
nostd::string_view name,
std::shared_ptr<LoggerContext> context,
std::unique_ptr<instrumentationscope::InstrumentationScope> 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
Expand All @@ -43,8 +42,7 @@ nostd::unique_ptr<opentelemetry::logs::LogRecord> 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(
Expand Down
3 changes: 1 addition & 2 deletions sdk/src/logs/logger_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ nostd::shared_ptr<opentelemetry::logs::Logger> 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
Expand Down Expand Up @@ -105,7 +104,7 @@ nostd::shared_ptr<opentelemetry::logs::Logger> LoggerProvider::GetLogger(
}

loggers_.push_back(std::shared_ptr<opentelemetry::sdk::logs::Logger>(
new Logger(logger_name, context_, std::move(lib), include_trace_context)));
new Logger(logger_name, context_, std::move(lib))));
return nostd::shared_ptr<opentelemetry::logs::Logger>{loggers_.back()};
}

Expand Down
4 changes: 1 addition & 3 deletions sdk/test/logs/log_record_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<opentelemetry::logs::Logger>(new TestBodyLogger());
Expand All @@ -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<TestBodyLogger *>(logger.get());

Expand Down
4 changes: 2 additions & 2 deletions sdk/test/logs/logger_provider_sdk_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ TEST(LoggerProviderSDK, LoggerProviderLoggerArguments)
auto sdk_logger2 = static_cast<opentelemetry::sdk::logs::Logger *>(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<opentelemetry::sdk::logs::Logger *>(logger3.get());
Expand All @@ -89,7 +89,7 @@ TEST(LoggerProviderSDK, LoggerProviderLoggerArguments)

std::unordered_map<std::string, std::string> 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<opentelemetry::sdk::logs::Logger *>(logger4.get());

EXPECT_EQ(sdk_logger4->GetInstrumentationScope().GetAttributes().size(), 1);
Expand Down
6 changes: 3 additions & 3 deletions sdk/test/logs/logger_sdk_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,13 @@ TEST(LoggerSDK, LogToAProcessor)
// Create an API LoggerProvider and logger
auto api_lp = std::shared_ptr<logs_api::LoggerProvider>(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<LoggerProvider *>(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<opentelemetry::trace::Span> include_span;
Expand Down Expand Up @@ -261,7 +261,7 @@ TEST(LoggerSDK, EventLog)
// Create an API LoggerProvider and logger
auto api_lp = std::shared_ptr<logs_api::LoggerProvider>(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<logs_api::EventLoggerProvider>(new EventLoggerProvider());
auto event_logger = api_elp->CreateEventLogger(logger, "otel-cpp.event_domain");
Expand Down