diff --git a/api/test/logs/logger_test.cc b/api/test/logs/logger_test.cc index 25fc61e7a1..92a17d4119 100644 --- a/api/test/logs/logger_test.cc +++ b/api/test/logs/logger_test.cc @@ -25,8 +25,9 @@ namespace trace = opentelemetry::trace; // Check that the default logger is a noop logger instance TEST(Logger, GetLoggerDefault) { - auto lp = Provider::GetLoggerProvider(); - auto logger = lp->GetLogger("TestLogger"); + auto lp = Provider::GetLoggerProvider(); + const std::string schema_url{"https://opentelemetry.io/schemas/1.2.0"}; + auto logger = lp->GetLogger("TestLogger", "", schema_url); auto name = logger->GetName(); EXPECT_NE(nullptr, logger); EXPECT_EQ(name, "noop logger"); @@ -95,7 +96,8 @@ TEST(Logger, PushLoggerImplementation) auto lp = Provider::GetLoggerProvider(); // Check that the implementation was pushed by calling TestLogger's GetName() - auto logger = lp->GetLogger("TestLogger"); + nostd::string_view schema_url{"https://opentelemetry.io/schemas/1.2.0"}; + auto logger = lp->GetLogger("TestLogger", "", schema_url); ASSERT_EQ("test logger", logger->GetName()); } #endif diff --git a/exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h b/exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h index 2f3a5af892..b847e8b85c 100644 --- a/exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h +++ b/exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h @@ -212,7 +212,7 @@ class LoggerProvider : public opentelemetry::logs::LoggerProvider } /** - * @brief Obtain ETW Logger. + * @brief Obtain ETW Tracer. * @param name ProviderId (instrumentation name) - Name or GUID * * @param version Library version @@ -223,7 +223,8 @@ class LoggerProvider : public opentelemetry::logs::LoggerProvider nostd::string_view version = "", nostd::string_view schema_url = "") override { - UNREFERENCED_PARAMETER(args); + UNREFERENCED_PARAMETER(version); + UNREFERENCED_PARAMETER(schema_url); ETWProvider::EventFormat evtFmt = config_.encoding; return nostd::shared_ptr{new (std::nothrow) etw::Logger(*this, name, evtFmt)}; diff --git a/exporters/etw/test/etw_logger_test.cc b/exporters/etw/test/etw_logger_test.cc index 419e4ad0da..e4cf53ee34 100644 --- a/exporters/etw/test/etw_logger_test.cc +++ b/exporters/etw/test/etw_logger_test.cc @@ -48,7 +48,8 @@ TEST(ETWLogger, LoggerCheckWithBody) std::string providerName = kGlobalProviderName; // supply unique instrumentation name here exporter::etw::LoggerProvider lp; - auto logger = lp.GetLogger(providerName); + const std::string schema_url{"https://opentelemetry.io/schemas/1.2.0"}; + auto logger = lp.GetLogger(providerName, "", schema_url); Properties attribs = {{"attrib1", 1}, {"attrib2", 2}}; EXPECT_NO_THROW( logger->Log(opentelemetry::logs::Severity::kDebug, "My Log", "This is test log body")); @@ -90,7 +91,8 @@ TEST(ETWLogger, LoggerCheckWithAttributes) std::string providerName = kGlobalProviderName; // supply unique instrumentation name here exporter::etw::LoggerProvider lp; - auto logger = lp.GetLogger(providerName); + const std::string schema_url{"https://opentelemetry.io/schemas/1.2.0"}; + auto logger = lp.GetLogger(providerName, "", schema_url); // Log attributes Properties attribs = {{"attrib1", 1}, {"attrib2", 2}}; EXPECT_NO_THROW(logger->Log(opentelemetry::logs::Severity::kDebug, "My Log", attribs)); diff --git a/sdk/include/opentelemetry/sdk/logs/recordable.h b/sdk/include/opentelemetry/sdk/logs/recordable.h index 89bb79da3e..d570d2aeee 100644 --- a/sdk/include/opentelemetry/sdk/logs/recordable.h +++ b/sdk/include/opentelemetry/sdk/logs/recordable.h @@ -19,7 +19,6 @@ # include "opentelemetry/version.h" # include -# include OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -101,10 +100,6 @@ class Recordable virtual void SetInstrumentationLibrary( const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary &instrumentation_library) noexcept = 0; - -private: - const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary - *instrumentation_library_ = nullptr; }; } // namespace logs } // namespace sdk diff --git a/sdk/test/logs/logger_provider_sdk_test.cc b/sdk/test/logs/logger_provider_sdk_test.cc index a16ce11fca..aec12ce690 100644 --- a/sdk/test/logs/logger_provider_sdk_test.cc +++ b/sdk/test/logs/logger_provider_sdk_test.cc @@ -39,12 +39,24 @@ TEST(LoggerProviderSDK, LoggerProviderGetLoggerSimple) ASSERT_NE(logger1, nullptr); ASSERT_NE(logger2, nullptr); + auto sdk_logger1 = static_cast(logger1.get()); + auto sdk_logger2 = static_cast(logger2.get()); + ASSERT_EQ(sdk_logger1->GetInstrumentationLibrary().GetName(), "logger1"); + ASSERT_EQ(sdk_logger1->GetInstrumentationLibrary().GetVersion(), ""); + ASSERT_EQ(sdk_logger1->GetInstrumentationLibrary().GetSchemaURL(), schema_url); + + ASSERT_EQ(sdk_logger2->GetInstrumentationLibrary().GetName(), "logger2"); + ASSERT_EQ(sdk_logger2->GetInstrumentationLibrary().GetVersion(), ""); + ASSERT_EQ(sdk_logger2->GetInstrumentationLibrary().GetSchemaURL(), schema_url); + // Check that two loggers with different names aren't the same instance ASSERT_NE(logger1, logger2); // Check that two loggers with the same name are the same instance auto logger3 = lp->GetLogger("logger1"); ASSERT_EQ(logger1, logger3); + auto sdk_logger3 = static_cast(logger3.get()); + ASSERT_EQ(sdk_logger3->GetInstrumentationLibrary(), sdk_logger1->GetInstrumentationLibrary()); } class DummyProcessor : public LogProcessor diff --git a/sdk/test/logs/logger_sdk_test.cc b/sdk/test/logs/logger_sdk_test.cc index 26632f1f91..0f95ad47f0 100644 --- a/sdk/test/logs/logger_sdk_test.cc +++ b/sdk/test/logs/logger_sdk_test.cc @@ -17,9 +17,14 @@ TEST(LoggerSDK, LogToNullProcessor) // even when there is no processor set // since it calls Processor::OnReceive() - auto lp = std::shared_ptr(new LoggerProvider()); - auto logger = lp->GetLogger("logger"); - + auto lp = std::shared_ptr(new LoggerProvider()); + const std::string schema_url{"https://opentelemetry.io/schemas/1.2.0"}; + auto logger = lp->GetLogger("logger", "", schema_url); + + auto sdk_logger = static_cast(logger.get()); + ASSERT_EQ(sdk_logger->GetInstrumentationLibrary().GetName(), "logger"); + ASSERT_EQ(sdk_logger->GetInstrumentationLibrary().GetVersion(), ""); + ASSERT_EQ(sdk_logger->GetInstrumentationLibrary().GetSchemaURL(), schema_url); // Log a sample log record to a nullptr processor logger->Debug("Test log"); } @@ -66,15 +71,20 @@ TEST(LoggerSDK, LogToAProcessor) { // Create an API LoggerProvider and logger auto api_lp = std::shared_ptr(new LoggerProvider()); - auto logger = api_lp->GetLogger("logger"); + const std::string schema_url{"https://opentelemetry.io/schemas/1.2.0"}; + auto logger = api_lp->GetLogger("logger", "", 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"); + auto logger2 = lp->GetLogger("logger", "", schema_url); ASSERT_EQ(logger, logger2); + auto sdk_logger = static_cast(logger.get()); + ASSERT_EQ(sdk_logger->GetInstrumentationLibrary().GetName(), "logger"); + ASSERT_EQ(sdk_logger->GetInstrumentationLibrary().GetVersion(), ""); + ASSERT_EQ(sdk_logger->GetInstrumentationLibrary().GetSchemaURL(), schema_url); // Set a processor for the LoggerProvider auto shared_recordable = std::shared_ptr(new LogRecord()); auto processor = std::shared_ptr(new MockProcessor(shared_recordable));