diff --git a/.gitmodules b/.gitmodules index 5da651fd16..c422e39e27 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,34 +1,34 @@ [submodule "third_party/prometheus-cpp"] - path = third_party/prometheus-cpp - url = https://github.com/jupp0r/prometheus-cpp - branch = master +path = third_party/prometheus-cpp +url = https://github.com/jupp0r/prometheus-cpp +branch = master [submodule "tools/vcpkg"] - path = tools/vcpkg - url = https://github.com/Microsoft/vcpkg - branch = master +path = tools/vcpkg +url = https://github.com/Microsoft/vcpkg +branch = master [submodule "third_party/ms-gsl"] - path = third_party/ms-gsl - url = https://github.com/microsoft/GSL - branch = master +path = third_party/ms-gsl +url = https://github.com/microsoft/GSL +branch = main [submodule "third_party/googletest"] - path = third_party/googletest - url = https://github.com/google/googletest - branch = master +path = third_party/googletest +url = https://github.com/google/googletest +branch = main [submodule "third_party/benchmark"] - path = third_party/benchmark - url = https://github.com/google/benchmark - branch = master +path = third_party/benchmark +url = https://github.com/google/benchmark +branch = main [submodule "third_party/opentelemetry-proto"] - path = third_party/opentelemetry-proto - url = https://github.com/open-telemetry/opentelemetry-proto - branch = master +path = third_party/opentelemetry-proto +url = https://github.com/open-telemetry/opentelemetry-proto +branch = main [submodule "third_party/nlohmann-json"] - path = third_party/nlohmann-json - url = https://github.com/nlohmann/json - branch = master +path = third_party/nlohmann-json +url = https://github.com/nlohmann/json +branch = master diff --git a/CHANGELOG.md b/CHANGELOG.md index 425029d72f..9393523ddf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ Increment the: ## [Unreleased] +* [PROTOCOL \& LOGS] Upgrade proto to v0.17.0, update log data model ([#1383](https://github.com/open-telemetry/opentelemetry-cpp/pull/1383)) + ## [1.3.0] 2022-04-11 * [ETW EXPORTER] ETW provider handle cleanup ([#1322](https://github.com/open-telemetry/opentelemetry-cpp/pull/1322)) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9840aa19a6..6d2b274358 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -173,6 +173,11 @@ if(WIN32) option(WITH_ETW "Whether to include the ETW Exporter in the SDK" ON) endif(WIN32) +# Do not convert deprecated message to error +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang") + add_compile_options(-Wno-error=deprecated-declarations) +endif() + option( WITH_API_ONLY "Only build the API (use as a header-only library). Overrides WITH_EXAMPLES and all options to enable exporters" diff --git a/api/include/opentelemetry/common/macros.h b/api/include/opentelemetry/common/macros.h index 982e368ce3..204c1ed04e 100644 --- a/api/include/opentelemetry/common/macros.h +++ b/api/include/opentelemetry/common/macros.h @@ -7,6 +7,23 @@ #include "opentelemetry/version.h" +#if !defined(OPENTELEMETRY_LIKELY_IF) && defined(__cplusplus) +// GCC 9 has likely attribute but do not support declare it at the beginning of statement +# if defined(__has_cpp_attribute) && (defined(__clang__) || !defined(__GNUC__) || __GNUC__ > 9) +# if __has_cpp_attribute(likely) +# define OPENTELEMETRY_LIKELY_IF(...) \ + if (__VA_ARGS__) \ + [[likely]] +# endif +# endif +#endif +#if !defined(OPENTELEMETRY_LIKELY_IF) && (defined(__clang__) || defined(__GNUC__)) +# define OPENTELEMETRY_LIKELY_IF(...) if (__builtin_expect(!!(__VA_ARGS__), true)) +#endif +#ifndef OPENTELEMETRY_LIKELY_IF +# define OPENTELEMETRY_LIKELY_IF(...) if (__VA_ARGS__) +#endif + /// \brief Declare variable as maybe unused /// usage: /// OPENTELEMETRY_MAYBE_UNUSED int a; @@ -40,3 +57,35 @@ # endif # endif #endif + +#if defined(__cplusplus) && __cplusplus >= 201402L +# define OPENTELEMETRY_DEPRECATED [[deprecated]] +#elif defined(__clang__) +# define OPENTELEMETRY_DEPRECATED __attribute__((deprecated)) +#elif defined(__GNUC__) +# define OPENTELEMETRY_DEPRECATED __attribute__((deprecated)) +#elif defined(_MSC_VER) +# if _MSC_VER >= 1910 && defined(_MSVC_LANG) && _MSVC_LANG >= 201703L +# define OPENTELEMETRY_DEPRECATED [[deprecated]] +# else +# define OPENTELEMETRY_DEPRECATED __declspec(deprecated) +# endif +#else +# define OPENTELEMETRY_DEPRECATED +#endif + +#if defined(__cplusplus) && __cplusplus >= 201402L +# define OPENTELEMETRY_DEPRECATED_MESSAGE(msg) [[deprecated(msg)]] +#elif defined(__clang__) +# define OPENTELEMETRY_DEPRECATED_MESSAGE(msg) __attribute__((deprecated(msg))) +#elif defined(__GNUC__) +# define OPENTELEMETRY_DEPRECATED_MESSAGE(msg) __attribute__((deprecated(msg))) +#elif defined(_MSC_VER) +# if _MSC_VER >= 1910 && defined(_MSVC_LANG) && _MSVC_LANG >= 201703L +# define OPENTELEMETRY_DEPRECATED_MESSAGE(msg) [[deprecated(msg)]] +# else +# define OPENTELEMETRY_DEPRECATED_MESSAGE(msg) __declspec(deprecated(msg)) +# endif +#else +# define OPENTELEMETRY_DEPRECATED_MESSAGE(msg) +#endif diff --git a/api/include/opentelemetry/logs/logger.h b/api/include/opentelemetry/logs/logger.h index 91e882717f..32c3974a1f 100644 --- a/api/include/opentelemetry/logs/logger.h +++ b/api/include/opentelemetry/logs/logger.h @@ -11,6 +11,7 @@ # include "opentelemetry/common/attribute_value.h" # include "opentelemetry/common/key_value_iterable.h" # include "opentelemetry/common/key_value_iterable_view.h" +# include "opentelemetry/common/macros.h" # include "opentelemetry/common/timestamp.h" # include "opentelemetry/logs/severity.h" # include "opentelemetry/nostd/shared_ptr.h" @@ -41,7 +42,6 @@ class Logger * creates a log message with the specific parameters passed. * * @param severity the severity level of the log event. - * @param name the name of the log event. * @param message the string message of the log (perhaps support std::fmt or fmt-lib format). * @param attributes the attributes, stored as a 2D list of key/value pairs, that are associated * with the log event. @@ -57,7 +57,6 @@ class Logger * in order to create a log record. */ virtual void Log(Severity severity, - nostd::string_view name, nostd::string_view body, const common::KeyValueIterable &attributes, trace::TraceId trace_id, @@ -65,6 +64,34 @@ class Logger trace::TraceFlags trace_flags, common::SystemTimestamp timestamp) noexcept = 0; + /** + * Each of the following overloaded Log(...) methods + * creates a log message with the specific parameters passed. + * + * @param severity the severity level of the log event. + * @param name the name of the log event. + * @param message the string message of the log (perhaps support std::fmt or fmt-lib format). + * @param attributes the attributes, stored as a 2D list of key/value pairs, that are associated + * with the log event. + * @param trace_id the trace id associated with the log event. + * @param span_id the span id associate with the log event. + * @param trace_flags the trace flags associated with the log event. + * @param timestamp the timestamp the log record was created. + * @throws No exceptions under any circumstances. + */ + OPENTELEMETRY_DEPRECATED_MESSAGE("name will be removed in the future") + virtual void Log(Severity severity, + OPENTELEMETRY_MAYBE_UNUSED nostd::string_view name, + nostd::string_view body, + const common::KeyValueIterable &attributes, + trace::TraceId trace_id, + trace::SpanId span_id, + trace::TraceFlags trace_flags, + common::SystemTimestamp timestamp) noexcept + { + Log(severity, body, attributes, trace_id, span_id, trace_flags, timestamp); + } + /*** Overloaded methods for KeyValueIterables ***/ /** * The secondary base Log(...) method that all other Log(...) overloaded methods except the one @@ -72,6 +99,21 @@ class Logger */ template ::value> * = nullptr> + void Log(Severity severity, + nostd::string_view body, + const T &attributes, + trace::TraceId trace_id, + trace::SpanId span_id, + trace::TraceFlags trace_flags, + common::SystemTimestamp timestamp) noexcept + { + Log(severity, body, common::KeyValueIterableView(attributes), trace_id, span_id, trace_flags, + timestamp); + } + + template ::value> * = nullptr> + OPENTELEMETRY_DEPRECATED_MESSAGE("name will be removed in the future") void Log(Severity severity, nostd::string_view name, nostd::string_view body, @@ -85,6 +127,21 @@ class Logger trace_flags, timestamp); } + void Log(Severity severity, + nostd::string_view body, + std::initializer_list> attributes, + trace::TraceId trace_id, + trace::SpanId span_id, + trace::TraceFlags trace_flags, + common::SystemTimestamp timestamp) noexcept + { + return this->Log(severity, body, + nostd::span>{ + attributes.begin(), attributes.end()}, + trace_id, span_id, trace_flags, timestamp); + } + + OPENTELEMETRY_DEPRECATED_MESSAGE("name will be removed in the future") void Log(Severity severity, nostd::string_view name, nostd::string_view body, @@ -109,15 +166,10 @@ class Logger */ void Log(Severity severity, nostd::string_view message) noexcept { - this->Log(severity, "", message, {}, {}, {}, {}, std::chrono::system_clock::now()); + this->Log(severity, message, {}, {}, {}, {}, std::chrono::system_clock::now()); } - /** - * Writes a log. - * @param severity The severity of the log - * @param name The name of the log - * @param message The message to log - */ + OPENTELEMETRY_DEPRECATED_MESSAGE("name will be removed in the future") void Log(Severity severity, nostd::string_view name, nostd::string_view message) noexcept { this->Log(severity, name, message, {}, {}, {}, {}, std::chrono::system_clock::now()); @@ -132,20 +184,20 @@ class Logger nostd::enable_if_t::value> * = nullptr> void Log(Severity severity, const T &attributes) noexcept { - this->Log(severity, "", "", attributes, {}, {}, {}, std::chrono::system_clock::now()); + this->Log(severity, "", attributes, {}, {}, {}, std::chrono::system_clock::now()); } /** * Writes a log. * @param severity The severity of the log - * @param name The name of the log + * @param message The message to log * @param attributes The attributes of the log as a key/value object */ template ::value> * = nullptr> - void Log(Severity severity, nostd::string_view name, const T &attributes) noexcept + void Log(Severity severity, nostd::string_view message, const T &attributes) noexcept { - this->Log(severity, name, "", attributes, {}, {}, {}, std::chrono::system_clock::now()); + this->Log(severity, message, attributes, {}, {}, {}, std::chrono::system_clock::now()); } /** @@ -157,35 +209,46 @@ class Logger std::initializer_list> attributes) noexcept { - this->Log(severity, "", "", attributes, {}, {}, {}, std::chrono::system_clock::now()); + this->Log(severity, "", attributes, {}, {}, {}, std::chrono::system_clock::now()); } /** * Writes a log. * @param severity The severity of the log - * @param name The name of the log + * @param message The message to log * @param attributes The attributes of the log as an initializer list */ void Log(Severity severity, - nostd::string_view name, + nostd::string_view message, std::initializer_list> attributes) noexcept { - this->Log(severity, name, "", attributes, {}, {}, {}, std::chrono::system_clock::now()); + this->Log(severity, message, attributes, {}, {}, {}, std::chrono::system_clock::now()); } /** * Writes a log. * @param severity The severity of the log - * @param name The name of the log + * @param attributes The attributes, stored as a 2D list of key/value pairs, that are associated + * with the log event + */ + void Log(Severity severity, const common::KeyValueIterable &attributes) noexcept + { + this->Log(severity, "", attributes, {}, {}, {}, std::chrono::system_clock::now()); + } + + /** + * Writes a log. + * @param severity The severity of the log + * @param message The message to log * @param attributes The attributes, stored as a 2D list of key/value pairs, that are associated * with the log event */ void Log(Severity severity, - nostd::string_view name, - common::KeyValueIterable &attributes) noexcept + nostd::string_view message, + const common::KeyValueIterable &attributes) noexcept { - this->Log(severity, name, {}, attributes, {}, {}, {}, std::chrono::system_clock::now()); + this->Log(severity, message, attributes, {}, {}, {}, std::chrono::system_clock::now()); } /** Trace severity overloads **/ @@ -201,6 +264,7 @@ class Logger * @param name The name of the log * @param message The message to log */ + OPENTELEMETRY_DEPRECATED_MESSAGE("name will be removed in the future") void Trace(nostd::string_view name, nostd::string_view message) noexcept { this->Log(Severity::kTrace, name, message); @@ -219,14 +283,14 @@ class Logger /** * Writes a log with a severity of trace. - * @param name The name of the log + * @param message The message of the log * @param attributes The attributes of the log as a key/value object */ template ::value> * = nullptr> - void Trace(nostd::string_view name, const T &attributes) noexcept + void Trace(nostd::string_view message, const T &attributes) noexcept { - this->Log(Severity::kTrace, name, attributes); + this->Log(Severity::kTrace, message, attributes); } /** @@ -241,14 +305,14 @@ class Logger /** * Writes a log with a severity of trace. - * @param name The name of the log + * @param message The message of the log * @param attributes The attributes of the log as an initializer list */ - void Trace(nostd::string_view name, + void Trace(nostd::string_view message, std::initializer_list> attributes) noexcept { - this->Log(Severity::kTrace, name, attributes); + this->Log(Severity::kTrace, message, attributes); } /** Debug severity overloads **/ @@ -264,6 +328,7 @@ class Logger * @param name The name of the log * @param message The message to log */ + OPENTELEMETRY_DEPRECATED_MESSAGE("name will be removed in the future") void Debug(nostd::string_view name, nostd::string_view message) noexcept { this->Log(Severity::kDebug, name, message); @@ -282,14 +347,14 @@ class Logger /** * Writes a log with a severity of debug. - * @param name The name of the log + * @param message The message of the log * @param attributes The attributes of the log as a key/value object */ template ::value> * = nullptr> - void Debug(nostd::string_view name, const T &attributes) noexcept + void Debug(nostd::string_view message, const T &attributes) noexcept { - this->Log(Severity::kDebug, name, attributes); + this->Log(Severity::kDebug, message, attributes); } /** @@ -304,14 +369,14 @@ class Logger /** * Writes a log with a severity of debug. - * @param name The name of the log + * @param message The message of the log * @param attributes The attributes of the log as an initializer list */ - void Debug(nostd::string_view name, + void Debug(nostd::string_view message, std::initializer_list> attributes) noexcept { - this->Log(Severity::kDebug, name, attributes); + this->Log(Severity::kDebug, message, attributes); } /** Info severity overloads **/ @@ -327,6 +392,7 @@ class Logger * @param name The name of the log * @param message The message to log */ + OPENTELEMETRY_DEPRECATED_MESSAGE("name will be removed in the future") void Info(nostd::string_view name, nostd::string_view message) noexcept { this->Log(Severity::kInfo, name, message); @@ -345,14 +411,14 @@ class Logger /** * Writes a log with a severity of info. - * @param name The name of the log + * @param message The message of the log * @param attributes The attributes of the log as a key/value object */ template ::value> * = nullptr> - void Info(nostd::string_view name, const T &attributes) noexcept + void Info(nostd::string_view message, const T &attributes) noexcept { - this->Log(Severity::kInfo, name, attributes); + this->Log(Severity::kInfo, message, attributes); } /** @@ -367,14 +433,14 @@ class Logger /** * Writes a log with a severity of info. - * @param name The name of the log + * @param message The message of the log * @param attributes The attributes of the log as an initializer list */ - void Info(nostd::string_view name, + void Info(nostd::string_view message, std::initializer_list> attributes) noexcept { - this->Log(Severity::kInfo, name, attributes); + this->Log(Severity::kInfo, message, attributes); } /** Warn severity overloads **/ @@ -390,6 +456,7 @@ class Logger * @param name The name of the log * @param message The message to log */ + OPENTELEMETRY_DEPRECATED_MESSAGE("name will be removed in the future") void Warn(nostd::string_view name, nostd::string_view message) noexcept { this->Log(Severity::kWarn, name, message); @@ -408,14 +475,14 @@ class Logger /** * Writes a log with a severity of warn. - * @param name The name of the log + * @param message The message of the log * @param attributes The attributes of the log as a key/value object */ template ::value> * = nullptr> - void Warn(nostd::string_view name, const T &attributes) noexcept + void Warn(nostd::string_view message, const T &attributes) noexcept { - this->Log(Severity::kWarn, name, attributes); + this->Log(Severity::kWarn, message, attributes); } /** @@ -430,14 +497,14 @@ class Logger /** * Writes a log with a severity of warn. - * @param name The name of the log + * @param message The message of the log * @param attributes The attributes of the log as an initializer list */ - void Warn(nostd::string_view name, + void Warn(nostd::string_view message, std::initializer_list> attributes) noexcept { - this->Log(Severity::kWarn, name, attributes); + this->Log(Severity::kWarn, message, attributes); } /** Error severity overloads **/ @@ -453,6 +520,7 @@ class Logger * @param name The name of the log * @param message The message to log */ + OPENTELEMETRY_DEPRECATED_MESSAGE("name will be removed in the future") void Error(nostd::string_view name, nostd::string_view message) noexcept { this->Log(Severity::kError, name, message); @@ -471,14 +539,14 @@ class Logger /** * Writes a log with a severity of error. - * @param name The name of the log + * @param message The message of the log * @param attributes The attributes of the log as a key/value object */ template ::value> * = nullptr> - void Error(nostd::string_view name, const T &attributes) noexcept + void Error(nostd::string_view message, const T &attributes) noexcept { - this->Log(Severity::kError, name, attributes); + this->Log(Severity::kError, message, attributes); } /** @@ -493,14 +561,14 @@ class Logger /** * Writes a log with a severity of error. - * @param name The name of the log + * @param message The message of the log * @param attributes The attributes of the log as an initializer list */ - void Error(nostd::string_view name, + void Error(nostd::string_view message, std::initializer_list> attributes) noexcept { - this->Log(Severity::kError, name, attributes); + this->Log(Severity::kError, message, attributes); } /** Fatal severity overloads **/ @@ -516,6 +584,7 @@ class Logger * @param name The name of the log * @param message The message to log */ + OPENTELEMETRY_DEPRECATED_MESSAGE("name will be removed in the future") void Fatal(nostd::string_view name, nostd::string_view message) noexcept { this->Log(Severity::kFatal, name, message); @@ -534,14 +603,14 @@ class Logger /** * Writes a log with a severity of fatal. - * @param name The name of the log + * @param message The message of the log * @param attributes The attributes of the log as a key/value object */ template ::value> * = nullptr> - void Fatal(nostd::string_view name, const T &attributes) noexcept + void Fatal(nostd::string_view message, const T &attributes) noexcept { - this->Log(Severity::kFatal, name, attributes); + this->Log(Severity::kFatal, message, attributes); } /** @@ -556,16 +625,17 @@ class Logger /** * Writes a log with a severity of fatal. - * @param name The name of the log + * @param message The message of the log * @param attributes The attributes of the log as an initializer list */ - void Fatal(nostd::string_view name, + void Fatal(nostd::string_view message, std::initializer_list> attributes) noexcept { - this->Log(Severity::kFatal, name, attributes); + this->Log(Severity::kFatal, message, attributes); } }; } // namespace logs OPENTELEMETRY_END_NAMESPACE + #endif diff --git a/api/include/opentelemetry/logs/noop.h b/api/include/opentelemetry/logs/noop.h index 8186fb8c76..2816123fde 100644 --- a/api/include/opentelemetry/logs/noop.h +++ b/api/include/opentelemetry/logs/noop.h @@ -42,7 +42,6 @@ class NoopLogger final : public Logger const nostd::string_view GetName() noexcept override { return "noop logger"; } void Log(Severity severity, - nostd::string_view name, nostd::string_view body, const common::KeyValueIterable &attributes, trace::TraceId trace_id, diff --git a/api/test/logs/logger_test.cc b/api/test/logs/logger_test.cc index b2d2d1d60a..07480ef44c 100644 --- a/api/test/logs/logger_test.cc +++ b/api/test/logs/logger_test.cc @@ -26,7 +26,7 @@ namespace trace = opentelemetry::trace; TEST(Logger, GetLoggerDefault) { auto lp = Provider::GetLoggerProvider(); - const std::string schema_url{"https://opentelemetry.io/schemas/1.2.0"}; + const std::string schema_url{"https://opentelemetry.io/schemas/1.11.0"}; auto logger = lp->GetLogger("TestLogger", "", "opentelelemtry_library", "", schema_url); auto name = logger->GetName(); EXPECT_NE(nullptr, logger); @@ -41,7 +41,7 @@ TEST(Logger, GetNoopLoggerNameWithArgs) // GetLogger(name, list(args)) std::array sv{"string"}; span args{sv}; - const std::string schema_url{"https://opentelemetry.io/schemas/1.2.0"}; + const std::string schema_url{"https://opentelemetry.io/schemas/1.11.0"}; lp->GetLogger("NoopLoggerWithArgs", args, "opentelelemtry_library", "", schema_url); // GetLogger(name, string options) @@ -52,7 +52,7 @@ TEST(Logger, GetNoopLoggerNameWithArgs) TEST(Logger, LogMethodOverloads) { auto lp = Provider::GetLoggerProvider(); - const std::string schema_url{"https://opentelemetry.io/schemas/1.2.0"}; + const std::string schema_url{"https://opentelemetry.io/schemas/1.11.0"}; auto logger = lp->GetLogger("TestLogger", "", "opentelelemtry_library", "", schema_url); // Create a map to test the logs with @@ -60,19 +60,56 @@ TEST(Logger, LogMethodOverloads) // Log overloads logger->Log(Severity::kTrace, "Test log message"); - logger->Log(Severity::kInfo, "Logging a message", "Test log message"); + logger->Log(Severity::kInfo, "Test log message"); logger->Log(Severity::kDebug, m); logger->Log(Severity::kWarn, "Logging a map", m); logger->Log(Severity::kError, {{"key1", "value 1"}, {"key2", 2}}); logger->Log(Severity::kFatal, "Logging an initializer list", {{"key1", "value 1"}, {"key2", 2}}); + // Deprecated Log overloads + logger->Log(Severity::kTrace, "Log name", "Test log message"); + logger->Log(Severity::kWarn, "Log name", "Logging a map", m, {}, {}, {}, + std::chrono::system_clock::now()); + logger->Log(Severity::kError, "Log name", "Logging a map", {{"key1", "value 1"}, {"key2", 2}}, {}, + {}, {}, std::chrono::system_clock::now()); + logger->Trace("Log name", "Test log message"); + logger->Debug("Log name", "Test log message"); + logger->Info("Log name", "Test log message"); + logger->Warn("Log name", "Test log message"); + logger->Error("Log name", "Test log message"); + logger->Fatal("Log name", "Test log message"); + // Severity methods logger->Trace("Test log message"); - logger->Debug("Logging a message", "Test log message"); + logger->Trace("Test log message", m); + logger->Trace("Test log message", {{"key1", "value 1"}, {"key2", 2}}); + logger->Trace(m); + logger->Trace({{"key1", "value 1"}, {"key2", 2}}); + logger->Debug("Test log message"); + logger->Debug("Test log message", m); + logger->Debug("Test log message", {{"key1", "value 1"}, {"key2", 2}}); + logger->Debug(m); + logger->Debug({{"key1", "value 1"}, {"key2", 2}}); + logger->Info("Test log message"); + logger->Info("Test log message", m); + logger->Info("Test log message", {{"key1", "value 1"}, {"key2", 2}}); logger->Info(m); - logger->Warn("Logging a map", m); + logger->Info({{"key1", "value 1"}, {"key2", 2}}); + logger->Warn("Test log message"); + logger->Warn("Test log message", m); + logger->Warn("Test log message", {{"key1", "value 1"}, {"key2", 2}}); + logger->Warn(m); + logger->Warn({{"key1", "value 1"}, {"key2", 2}}); + logger->Error("Test log message"); + logger->Error("Test log message", m); + logger->Error("Test log message", {{"key1", "value 1"}, {"key2", 2}}); + logger->Error(m); logger->Error({{"key1", "value 1"}, {"key2", 2}}); - logger->Fatal("Logging an initializer list", {{"key1", "value 1"}, {"key2", 2}}); + logger->Fatal("Test log message"); + logger->Fatal("Test log message", m); + logger->Fatal("Test log message", {{"key1", "value 1"}, {"key2", 2}}); + logger->Fatal(m); + logger->Fatal({{"key1", "value 1"}, {"key2", 2}}); } // Define a basic Logger class @@ -81,7 +118,6 @@ class TestLogger : public Logger const nostd::string_view GetName() noexcept override { return "test logger"; } void Log(Severity severity, - string_view name, string_view body, const common::KeyValueIterable &attributes, trace::TraceId trace_id, @@ -122,7 +158,7 @@ TEST(Logger, PushLoggerImplementation) auto lp = Provider::GetLoggerProvider(); // Check that the implementation was pushed by calling TestLogger's GetName() - nostd::string_view schema_url{"https://opentelemetry.io/schemas/1.2.0"}; + nostd::string_view schema_url{"https://opentelemetry.io/schemas/1.11.0"}; auto logger = lp->GetLogger("TestLogger", "", "opentelelemtry_library", "", schema_url); ASSERT_EQ("test logger", logger->GetName()); } diff --git a/bazel/repository.bzl b/bazel/repository.bzl index f3f276e2a5..7d50e12d31 100644 --- a/bazel/repository.bzl +++ b/bazel/repository.bzl @@ -2,7 +2,7 @@ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") -_ALL_CONTENT = """\ +_ALL_CONTENT = """ filegroup( name = "all_srcs", srcs = glob(["**"]), @@ -74,10 +74,10 @@ def opentelemetry_cpp_deps(): http_archive, name = "com_github_opentelemetry_proto", build_file = "@io_opentelemetry_cpp//bazel:opentelemetry_proto.BUILD", - sha256 = "985367f8905e91018e636cbf0d83ab3f834b665c4f5899a27d10cae9657710e2", - strip_prefix = "opentelemetry-proto-0.11.0", + sha256 = "f269fbcb30e17b03caa1decd231ce826e59d7651c0f71c3b28eb5140b4bb5412", + strip_prefix = "opentelemetry-proto-0.17.0", urls = [ - "https://github.com/open-telemetry/opentelemetry-proto/archive/v0.11.0.tar.gz", + "https://github.com/open-telemetry/opentelemetry-proto/archive/v0.17.0.tar.gz", ], ) @@ -164,5 +164,5 @@ cc_library( visibility = ["//visibility:public"], ) """, - path = "vcpkg/installed/x64-windows/", + path = "tools/vcpkg/installed/x64-windows/", ) diff --git a/ci/do_ci.ps1 b/ci/do_ci.ps1 index ca7f8abf83..b32c9ff54b 100644 --- a/ci/do_ci.ps1 +++ b/ci/do_ci.ps1 @@ -3,22 +3,22 @@ trap { $host.SetShouldExit(1) } $action = $args[0] -$SRC_DIR=(Get-Item -Path ".\").FullName +$SRC_DIR = (Get-Item -Path ".\").FullName -$BAZEL_OPTIONS="--copt=-DENABLE_METRICS_PREVIEW --copt=-DENABLE_LOGS_PREVIEW" -$BAZEL_TEST_OPTIONS="$BAZEL_OPTIONS --test_output=errors" +$BAZEL_OPTIONS = "--copt=-DENABLE_METRICS_PREVIEW --copt=-DENABLE_LOGS_PREVIEW" +$BAZEL_TEST_OPTIONS = "$BAZEL_OPTIONS --test_output=errors" if (!(test-path build)) { mkdir build } -$BUILD_DIR="$SRC_DIR\build" +$BUILD_DIR = Join-Path "$SRC_DIR" "build" if (!(test-path plugin)) { mkdir plugin } -$PLUGIN_DIR="$SRC_DIR\plugin" +$PLUGIN_DIR = Join-Path "$SRC_DIR" "plugin" -$VCPKG_DIR="$SRC_DIR\vcpkg" +$VCPKG_DIR = Join-Path "$SRC_DIR" "tools" "vcpkg" switch ($action) { "bazel.build" { @@ -31,8 +31,8 @@ switch ($action) { "cmake.test" { cd "$BUILD_DIR" cmake $SRC_DIR ` - -DVCPKG_TARGET_TRIPLET=x64-windows ` - "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR\scripts\buildsystems\vcpkg.cmake" + -DVCPKG_TARGET_TRIPLET=x64-windows ` + "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake" $exit = $LASTEXITCODE if ($exit -ne 0) { exit $exit @@ -51,9 +51,9 @@ switch ($action) { "cmake.exporter.otprotocol.test" { cd "$BUILD_DIR" cmake $SRC_DIR ` - -DVCPKG_TARGET_TRIPLET=x64-windows ` - -DWITH_OTPROTCOL=ON ` - "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR\scripts\buildsystems\vcpkg.cmake" + -DVCPKG_TARGET_TRIPLET=x64-windows ` + -DWITH_OTPROTCOL=ON ` + "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake" $exit = $LASTEXITCODE if ($exit -ne 0) { exit $exit @@ -72,8 +72,8 @@ switch ($action) { "cmake.build_example_plugin" { cd "$BUILD_DIR" cmake $SRC_DIR ` - -DVCPKG_TARGET_TRIPLET=x64-windows ` - "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR\scripts\buildsystems\vcpkg.cmake" + -DVCPKG_TARGET_TRIPLET=x64-windows ` + "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake" $exit = $LASTEXITCODE if ($exit -ne 0) { exit $exit @@ -83,13 +83,13 @@ switch ($action) { if ($exit -ne 0) { exit $exit } - cp examples\plugin\plugin\Debug\example_plugin.dll ${PLUGIN_DIR} + cp examples/plugin/plugin/Debug/example_plugin.dll ${PLUGIN_DIR} } "cmake.test_example_plugin" { cd "$BUILD_DIR" cmake $SRC_DIR ` - -DVCPKG_TARGET_TRIPLET=x64-windows ` - "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR\scripts\buildsystems\vcpkg.cmake" + -DVCPKG_TARGET_TRIPLET=x64-windows ` + "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake" $exit = $LASTEXITCODE if ($exit -ne 0) { exit $exit @@ -99,7 +99,7 @@ switch ($action) { if ($exit -ne 0) { exit $exit } - cp examples\plugin\plugin\Debug\example_plugin.dll ${PLUGIN_DIR} + cp examples/plugin/plugin/Debug/example_plugin.dll ${PLUGIN_DIR} $config = New-TemporaryFile examples/plugin/load/Debug/load_plugin_example.exe ${PLUGIN_DIR}/example_plugin.dll $config $exit = $LASTEXITCODE diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 14749500ec..e11ca0d2ec 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -281,7 +281,7 @@ elif [[ "$1" == "third_party.tags" ]]; then echo "gRPC=v1.43.2" > third_party_release echo "thrift=0.14.1" >> third_party_release echo "abseil=20210324.0" >> third_party_release - git submodule status | sed 's:.*/::' | sed 's/ (/=/g' | sed 's/)//g' >> third_party_release + git submodule foreach --quiet 'echo "$name=$(git describe --tags HEAD)"' | sed 's:.*/::' >> third_party_release exit 0 fi diff --git a/ci/install_windows_protobuf.ps1 b/ci/install_windows_protobuf.ps1 index 979a9e5f4f..4e1b1b8f05 100644 --- a/ci/install_windows_protobuf.ps1 +++ b/ci/install_windows_protobuf.ps1 @@ -1,6 +1,6 @@ $ErrorActionPreference = "Stop" trap { $host.SetShouldExit(1) } -cd vcpkg +cd tools/vcpkg # Lock to specific version of Protobuf port file to avoid build break -./vcpkg install --overlay-ports="$PSScriptRoot\ports" protobuf:x64-windows +./vcpkg "--vcpkg-root=$PWD" install --overlay-ports="$PSScriptRoot\ports" protobuf:x64-windows diff --git a/ci/setup_thrift.ps1 b/ci/setup_thrift.ps1 index 62b0d25c97..a9be25262d 100644 --- a/ci/setup_thrift.ps1 +++ b/ci/setup_thrift.ps1 @@ -1,14 +1,13 @@ $ErrorActionPreference = "Stop" trap { $host.SetShouldExit(1) } -# TODO: consider moving this to .gitmodules -git clone --depth=1 -b 2020.04 https://github.com/Microsoft/vcpkg.git -Push-Location -Path vcpkg -$VCPKG_DIR=(Get-Item -Path ".\").FullName -setx VCPKG_DIR (Get-Item -Path ".\").FullName +git submodule update -f "tools/vcpkg" +Push-Location -Path "tools/vcpkg" +$VCPKG_DIR = (Get-Item -Path ".\").FullName +setx VCPKG_DIR "$VCPKG_DIR" ./bootstrap-vcpkg.bat # boost needed for thrift -./vcpkg install boost-predef[core]:x64-windows boost-locale[core]:x64-windows boost-numeric-conversion[core]:x64-windows boost-scope-exit[core]:x64-windows openssl:x64-windows +./vcpkg "--vcpkg-root=$VCPKG_DIR" install boost-predef[core]:x64-windows boost-locale[core]:x64-windows boost-numeric-conversion[core]:x64-windows boost-scope-exit[core]:x64-windows openssl:x64-windows Pop-Location \ No newline at end of file diff --git a/ci/setup_windows_ci_environment.ps1 b/ci/setup_windows_ci_environment.ps1 index e7cdfeda97..4a0e04459d 100755 --- a/ci/setup_windows_ci_environment.ps1 +++ b/ci/setup_windows_ci_environment.ps1 @@ -1,20 +1,19 @@ $ErrorActionPreference = "Stop" trap { $host.SetShouldExit(1) } -# TODO: consider moving this to .gitmodules -git clone https://github.com/Microsoft/vcpkg.git -Push-Location -Path vcpkg -$VCPKG_DIR=(Get-Item -Path ".\").FullName +git submodule update -f "tools/vcpkg" +Push-Location -Path "tools/vcpkg" +$VCPKG_DIR = (Get-Item -Path ".\").FullName ./bootstrap-vcpkg.bat ./vcpkg integrate install # Patched Google Benchmark can be shared between vs2017 and vs2019 compilers -./vcpkg install --overlay-ports="$PSScriptRoot\ports" benchmark:x64-windows +./vcpkg "--vcpkg-root=$VCPKG_DIR" install --overlay-ports="$PSScriptRoot\ports" benchmark:x64-windows # Google Test -./vcpkg install gtest:x64-windows +./vcpkg "--vcpkg-root=$VCPKG_DIR" install gtest:x64-windows # nlohmann-json -./vcpkg install nlohmann-json:x64-windows +./vcpkg "--vcpkg-root=$VCPKG_DIR" install nlohmann-json:x64-windows Pop-Location diff --git a/cmake/opentelemetry-proto.cmake b/cmake/opentelemetry-proto.cmake index 8d8f868baf..37d45da6c4 100644 --- a/cmake/opentelemetry-proto.cmake +++ b/cmake/opentelemetry-proto.cmake @@ -3,7 +3,7 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/opentelemetry-proto/.git) set(needs_proto_download FALSE) else() if("${opentelemetry-proto}" STREQUAL "") - set(opentelemetry-proto "main") + set(opentelemetry-proto "v0.17.0") endif() include(ExternalProject) ExternalProject_Add( @@ -153,8 +153,9 @@ if(WITH_OTLP_GRPC) ${METRICS_SERVICE_GRPC_PB_H_FILE} ${METRICS_SERVICE_GRPC_PB_CPP_FILE} COMMAND - ${PROTOBUF_PROTOC_EXECUTABLE} ARGS "--proto_path=${PROTO_PATH}" - ${PROTOBUF_INCLUDE_FLAGS} "--cpp_out=${GENERATED_PROTOBUF_PATH}" + ${PROTOBUF_PROTOC_EXECUTABLE} ARGS "--experimental_allow_proto3_optional" + "--proto_path=${PROTO_PATH}" ${PROTOBUF_INCLUDE_FLAGS} + "--cpp_out=${GENERATED_PROTOBUF_PATH}" "--grpc_out=generate_mock_code=true:${GENERATED_PROTOBUF_PATH}" --plugin=protoc-gen-grpc="${gRPC_CPP_PLUGIN_EXECUTABLE}" ${COMMON_PROTO} ${RESOURCE_PROTO} ${TRACE_PROTO} ${LOGS_PROTO} ${METRICS_PROTO} @@ -178,11 +179,11 @@ else() ${METRICS_SERVICE_PB_H_FILE} ${METRICS_SERVICE_PB_CPP_FILE} COMMAND - ${PROTOBUF_PROTOC_EXECUTABLE} ARGS "--proto_path=${PROTO_PATH}" - ${PROTOBUF_INCLUDE_FLAGS} "--cpp_out=${GENERATED_PROTOBUF_PATH}" - ${COMMON_PROTO} ${RESOURCE_PROTO} ${TRACE_PROTO} ${LOGS_PROTO} - ${METRICS_PROTO} ${TRACE_SERVICE_PROTO} ${LOGS_SERVICE_PROTO} - ${METRICS_SERVICE_PROTO}) + ${PROTOBUF_PROTOC_EXECUTABLE} ARGS "--experimental_allow_proto3_optional" + "--proto_path=${PROTO_PATH}" ${PROTOBUF_INCLUDE_FLAGS} + "--cpp_out=${GENERATED_PROTOBUF_PATH}" ${COMMON_PROTO} ${RESOURCE_PROTO} + ${TRACE_PROTO} ${LOGS_PROTO} ${METRICS_PROTO} ${TRACE_SERVICE_PROTO} + ${LOGS_SERVICE_PROTO} ${METRICS_SERVICE_PROTO}) endif() include_directories("${GENERATED_PROTOBUF_PATH}") diff --git a/examples/common/logs_foo_library/foo_library.cc b/examples/common/logs_foo_library/foo_library.cc index 2ae5ccfaf6..daba9191bc 100644 --- a/examples/common/logs_foo_library/foo_library.cc +++ b/examples/common/logs_foo_library/foo_library.cc @@ -32,7 +32,7 @@ void foo_library() auto scoped_span = trace::Scope(get_tracer()->StartSpan("foo_library")); auto ctx = span->GetContext(); auto logger = get_logger(); - logger->Log(opentelemetry::logs::Severity::kDebug, "name", "body", {}, ctx.trace_id(), - ctx.span_id(), ctx.trace_flags(), opentelemetry::common::SystemTimestamp()); + logger->Log(opentelemetry::logs::Severity::kDebug, "body", {}, ctx.trace_id(), ctx.span_id(), + ctx.trace_flags(), opentelemetry::common::SystemTimestamp()); } #endif diff --git a/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_recordable.h b/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_recordable.h index 5c223cd0d4..c38bf8769d 100755 --- a/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_recordable.h +++ b/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_recordable.h @@ -124,12 +124,6 @@ class ElasticSearchRecordable final : public sdk::logs::Recordable } } - /** - * Set name for this log - * @param name the name to set - */ - void SetName(nostd::string_view name) noexcept override { json_["name"] = name.data(); } - /** * Set body field for this log. * @param message the body to set @@ -214,6 +208,7 @@ class ElasticSearchRecordable final : public sdk::logs::Recordable const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary &instrumentation_library) noexcept { + json_["name"] = instrumentation_library.GetName(); instrumentation_library_ = &instrumentation_library; } diff --git a/exporters/elasticsearch/test/es_log_exporter_test.cc b/exporters/elasticsearch/test/es_log_exporter_test.cc index d32048e83d..943f9fa7ba 100644 --- a/exporters/elasticsearch/test/es_log_exporter_test.cc +++ b/exporters/elasticsearch/test/es_log_exporter_test.cc @@ -69,7 +69,6 @@ TEST(ElasticsearchLogsExporterTests, RecordableCreation) // Create a recordable auto record = exporter->MakeRecordable(); - record->SetName("Timeout Log"); record->SetSeverity(logs_api::Severity::kFatal); record->SetTimestamp(std::chrono::system_clock::now()); record->SetBody("Body of the log message"); diff --git a/exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h b/exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h index 84f6b6970f..bd2478224f 100644 --- a/exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h +++ b/exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h @@ -100,6 +100,30 @@ class Logger : public opentelemetry::logs::Logger provHandle(initProvHandle()) {} + void Log(opentelemetry::logs::Severity severity, + nostd::string_view body, + const common::KeyValueIterable &attributes, + opentelemetry::trace::TraceId trace_id, + opentelemetry::trace::SpanId span_id, + opentelemetry::trace::TraceFlags trace_flags, + common::SystemTimestamp timestamp) noexcept override + { + +# ifdef OPENTELEMETRY_RTTI_ENABLED + common::KeyValueIterable &attribs = const_cast(attributes); + Properties *evt = dynamic_cast(&attribs); + // Properties *res = dynamic_cast(&resr); + + if (evt != nullptr) + { + // Pass as a reference to original modifyable collection without creating a copy + return Log(severity, provId, body, *evt, trace_id, span_id, trace_flags, timestamp); + } +# endif + Properties evtCopy = attributes; + return Log(severity, provId, body, evtCopy, trace_id, span_id, trace_flags, timestamp); + } + void Log(opentelemetry::logs::Severity severity, nostd::string_view name, nostd::string_view body, @@ -163,7 +187,7 @@ class Logger : public opentelemetry::logs::Logger ActivityIdPtr = &ActivityId; } } - evt[ETW_FIELD_PAYLOAD_NAME] = std::string(name.data(), name.length()); + evt[ETW_FIELD_PAYLOAD_NAME] = std::string(name.data(), name.size()); std::chrono::system_clock::time_point ts = timestamp; int64_t tsMs = std::chrono::duration_cast(ts.time_since_epoch()).count(); diff --git a/exporters/etw/test/etw_logger_test.cc b/exporters/etw/test/etw_logger_test.cc index e4cf53ee34..99d5b3a9b8 100644 --- a/exporters/etw/test/etw_logger_test.cc +++ b/exporters/etw/test/etw_logger_test.cc @@ -51,8 +51,7 @@ TEST(ETWLogger, LoggerCheckWithBody) 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")); + EXPECT_NO_THROW(logger->Log(opentelemetry::logs::Severity::kDebug, "This is test log body")); } /** @@ -95,7 +94,7 @@ TEST(ETWLogger, LoggerCheckWithAttributes) 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)); + EXPECT_NO_THROW(logger->Log(opentelemetry::logs::Severity::kDebug, attribs)); } # endif // _WIN32 diff --git a/exporters/ostream/src/log_exporter.cc b/exporters/ostream/src/log_exporter.cc index ef103bb6b2..ba6997aa7e 100644 --- a/exporters/ostream/src/log_exporter.cc +++ b/exporters/ostream/src/log_exporter.cc @@ -159,8 +159,7 @@ sdk::common::ExportResult OStreamLogExporter::Export( sout_ << opentelemetry::logs::SeverityNumToText[severity_index] << "\n"; } - sout_ << " name : " << log_record->GetName() << "\n" - << " body : " << log_record->GetBody() << "\n" + sout_ << " body : " << log_record->GetBody() << "\n" << " resource : "; printMap(log_record->GetResource().GetAttributes(), sout_); diff --git a/exporters/ostream/test/ostream_log_test.cc b/exporters/ostream/test/ostream_log_test.cc index e5eaa7ef67..7fa51c18a9 100644 --- a/exporters/ostream/test/ostream_log_test.cc +++ b/exporters/ostream/test/ostream_log_test.cc @@ -79,7 +79,6 @@ TEST(OstreamLogExporter, DefaultLogRecordToCout) " timestamp : 0\n" " severity_num : 0\n" " severity_text : INVALID\n" - " name : \n" " body : \n", " resource : {", "{telemetry.sdk.version: " OPENTELEMETRY_VERSION "}", @@ -117,7 +116,6 @@ TEST(OStreamLogExporter, SimpleLogToCout) auto record = std::unique_ptr(new sdklogs::LogRecord()); record->SetTimestamp(now); record->SetSeverity(logs_api::Severity::kTrace); // kTrace has enum value of 1 - record->SetName("Name"); record->SetBody("Message"); // Log a record to cout @@ -133,7 +131,6 @@ TEST(OStreamLogExporter, SimpleLogToCout) "\n" " severity_num : 1\n" " severity_text : TRACE\n" - " name : Name\n" " body : Message\n", " resource : {", "{telemetry.sdk.version: " OPENTELEMETRY_VERSION "}", @@ -187,7 +184,6 @@ TEST(OStreamLogExporter, LogWithStringAttributesToCerr) " timestamp : 0\n" " severity_num : 0\n" " severity_text : INVALID\n" - " name : \n" " body : \n", " resource : {", "{telemetry.sdk.version: " OPENTELEMETRY_VERSION "}", @@ -249,7 +245,6 @@ TEST(OStreamLogExporter, LogWithVariantTypesToClog) " timestamp : 0\n" " severity_num : 0\n" " severity_text : INVALID\n" - " name : \n" " body : \n", " resource : {", "{service.name: unknown_service}", @@ -283,7 +278,7 @@ TEST(OStreamLogExporter, IntegrationTest) auto apiProvider = nostd::shared_ptr(sdkProvider); auto provider = nostd::shared_ptr(apiProvider); logs_api::Provider::SetLoggerProvider(provider); - const std::string schema_url{"https://opentelemetry.io/schemas/1.2.0"}; + const std::string schema_url{"https://opentelemetry.io/schemas/1.11.0"}; auto logger = logs_api::Provider::GetLoggerProvider()->GetLogger( "Logger", "", "opentelelemtry_library", "", schema_url); @@ -296,7 +291,7 @@ TEST(OStreamLogExporter, IntegrationTest) // Write a log to ostream exporter common::SystemTimestamp now(std::chrono::system_clock::now()); - logger->Log(logs_api::Severity::kDebug, "", "Hello", {}, {}, {}, {}, now); + logger->Log(logs_api::Severity::kDebug, "Hello", {}, {}, {}, {}, now); // Restore cout's original streambuf std::cout.rdbuf(original); @@ -309,7 +304,6 @@ TEST(OStreamLogExporter, IntegrationTest) "\n" " severity_num : 5\n" " severity_text : DEBUG\n" - " name : \n" " body : Hello\n", " resource : {", "{telemetry.sdk.version: " OPENTELEMETRY_VERSION "}", diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_log_recordable.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_log_recordable.h index b6d02bddcd..57ae94ea03 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_log_recordable.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_log_recordable.h @@ -49,12 +49,6 @@ class OtlpLogRecordable final : public opentelemetry::sdk::logs::Recordable */ void SetSeverity(opentelemetry::logs::Severity severity) noexcept override; - /** - * Set name for this log - * @param name the name to set - */ - void SetName(nostd::string_view name) noexcept override; - /** * Set body field for this log. * @param message the body to set @@ -67,6 +61,9 @@ class OtlpLogRecordable final : public opentelemetry::sdk::logs::Recordable */ void SetResource(const opentelemetry::sdk::resource::Resource &resource) noexcept override; + /** Returns the associated resource */ + const opentelemetry::sdk::resource::Resource &GetResource() const noexcept; + /** * Set an attribute of a log. * @param key the name of the attribute diff --git a/exporters/otlp/src/otlp_log_recordable.cc b/exporters/otlp/src/otlp_log_recordable.cc index e859981e9f..d38fe241fa 100644 --- a/exporters/otlp/src/otlp_log_recordable.cc +++ b/exporters/otlp/src/otlp_log_recordable.cc @@ -3,6 +3,8 @@ #ifdef ENABLE_LOGS_PREVIEW +# include "opentelemetry/common/macros.h" + # include "opentelemetry/exporters/otlp/otlp_log_recordable.h" # include "opentelemetry/exporters/otlp/otlp_recordable_utils.h" @@ -167,11 +169,6 @@ void OtlpLogRecordable::SetSeverity(opentelemetry::logs::Severity severity) noex } } -void OtlpLogRecordable::SetName(nostd::string_view name) noexcept -{ - log_record_.set_name(name.data(), name.size()); -} - void OtlpLogRecordable::SetBody(nostd::string_view message) noexcept { log_record_.mutable_body()->set_string_value(message.data(), message.size()); @@ -182,6 +179,13 @@ void OtlpLogRecordable::SetResource(const opentelemetry::sdk::resource::Resource resource_ = &resource; } +const opentelemetry::sdk::resource::Resource &OtlpLogRecordable::GetResource() const noexcept +{ + OPENTELEMETRY_LIKELY_IF(nullptr != resource_) { return *resource_; } + + return opentelemetry::sdk::resource::Resource::GetDefault(); +} + void OtlpLogRecordable::SetAttribute(nostd::string_view key, const opentelemetry::common::AttributeValue &value) noexcept { @@ -215,7 +219,14 @@ void OtlpLogRecordable::SetInstrumentationLibrary( const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary & OtlpLogRecordable::GetInstrumentationLibrary() const noexcept { - return *instrumentation_library_; + OPENTELEMETRY_LIKELY_IF(nullptr != instrumentation_library_) { return *instrumentation_library_; } + + static opentelemetry::nostd::unique_ptr< + opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary> + default_instrumentation = + opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary::Create( + "default", "1.0.0", "https://opentelemetry.io/schemas/1.11.0"); + return *default_instrumentation; } } // namespace otlp } // namespace exporter diff --git a/exporters/otlp/src/otlp_recordable_utils.cc b/exporters/otlp/src/otlp_recordable_utils.cc index b981448de1..bb3c846042 100644 --- a/exporters/otlp/src/otlp_recordable_utils.cc +++ b/exporters/otlp/src/otlp_recordable_utils.cc @@ -13,6 +13,9 @@ #include "opentelemetry/exporters/otlp/otlp_log_recordable.h" #include "opentelemetry/exporters/otlp/otlp_recordable.h" +#include +#include + namespace nostd = opentelemetry::nostd; OPENTELEMETRY_BEGIN_NAMESPACE @@ -21,6 +24,29 @@ namespace exporter namespace otlp { +namespace +{ +struct InstrumentationLibraryPointerHasher +{ + std::size_t operator()(const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary + *instrumentation) const noexcept + { + return instrumentation->HashCode(); + } +}; + +struct InstrumentationLibraryPointerEqual +{ + std::size_t operator()( + const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary *left, + const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary *right) + const noexcept + { + return *left == *right; + } +}; +} // namespace + // // See `attribute_value.h` for details. // @@ -285,26 +311,48 @@ void OtlpRecordableUtils::PopulateRequest( return; } + using logs_index_by_instrumentation_type = + std::unordered_map>, + InstrumentationLibraryPointerHasher, InstrumentationLibraryPointerEqual>; + std::unordered_map + logs_index_by_resource; + for (auto &recordable : logs) { - auto resource_logs = request->add_resource_logs(); - auto instrumentation_lib = resource_logs->add_instrumentation_library_logs(); - auto rec = std::unique_ptr(static_cast(recordable.release())); + auto instrumentation = &rec->GetInstrumentationLibrary(); + auto resource = &rec->GetResource(); + + logs_index_by_resource[resource][instrumentation].emplace_back(std::move(rec)); + } - // TODO schema url - *resource_logs->mutable_resource() = rec->ProtoResource(); + for (auto &input_resource_log : logs_index_by_resource) + { + auto output_resource_log = request->add_resource_logs(); + for (auto &input_scope_log : input_resource_log.second) + { + auto output_scope_log = output_resource_log->add_scope_logs(); + for (auto &input_log_record : input_scope_log.second) + { + if (!output_resource_log->has_resource()) + { + *output_resource_log->mutable_resource() = input_log_record->ProtoResource(); + output_resource_log->set_schema_url(input_resource_log.first->GetSchemaURL()); + } - // TODO schema url - // resource_logs->set_schema_url(rec->GetResourceSchemaURL()); + if (!output_scope_log->has_scope()) + { + output_scope_log->mutable_scope()->set_name(input_scope_log.first->GetName()); + output_scope_log->mutable_scope()->set_version(input_scope_log.first->GetVersion()); + output_scope_log->set_schema_url(input_scope_log.first->GetSchemaURL()); + } - *instrumentation_lib->add_logs() = std::move(rec->log_record()); - // TODO instrumentation_library - // *instrumentation_lib->mutable_instrumentation_library() = - // rec->GetProtoInstrumentationLibrary(); - // TODO schema data - // instrumentation_lib->set_schema_url(rec->GetInstrumentationLibrarySchemaURL()); + *output_scope_log->add_log_records() = std::move(input_log_record->log_record()); + } + } } } #endif diff --git a/exporters/otlp/test/otlp_grpc_log_exporter_test.cc b/exporters/otlp/test/otlp_grpc_log_exporter_test.cc index f5f621bf9f..b60aac61a4 100644 --- a/exporters/otlp/test/otlp_grpc_log_exporter_test.cc +++ b/exporters/otlp/test/otlp_grpc_log_exporter_test.cc @@ -58,9 +58,7 @@ TEST_F(OtlpGrpcLogExporterTestPeer, ShutdownTest) auto exporter = GetExporter(stub_interface); auto recordable_1 = exporter->MakeRecordable(); - recordable_1->SetName("Test log 1"); auto recordable_2 = exporter->MakeRecordable(); - recordable_2->SetName("Test log 2"); // exporter shuold not be shutdown by default nostd::span> batch_1(&recordable_1, 1); @@ -87,9 +85,7 @@ TEST_F(OtlpGrpcLogExporterTestPeer, ExportUnitTest) auto exporter = GetExporter(stub_interface); auto recordable_1 = exporter->MakeRecordable(); - recordable_1->SetName("Test logs 1"); auto recordable_2 = exporter->MakeRecordable(); - recordable_2->SetName("Test logs 2"); // Test successful RPC nostd::span> batch_1(&recordable_1, 1); @@ -137,9 +133,9 @@ TEST_F(OtlpGrpcLogExporterTestPeer, ExportIntegrationTest) '3', '2', '1', '0'}; opentelemetry::trace::SpanId span_id{span_id_bin}; - const std::string schema_url{"https://opentelemetry.io/schemas/1.2.0"}; + const std::string schema_url{"https://opentelemetry.io/schemas/1.11.0"}; auto logger = provider->GetLogger("test", "", "opentelelemtry_library", "", schema_url); - logger->Log(opentelemetry::logs::Severity::kInfo, "Log name", "Log message", + logger->Log(opentelemetry::logs::Severity::kInfo, "Log message", {{"service.name", "unit_test_service"}, {"tenant.id", "test_user"}, {"bool_value", true}, diff --git a/exporters/otlp/test/otlp_http_log_exporter_test.cc b/exporters/otlp/test/otlp_http_log_exporter_test.cc index ffd1a9a0f3..7e2c0808e2 100644 --- a/exporters/otlp/test/otlp_http_log_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_log_exporter_test.cc @@ -118,7 +118,7 @@ TEST_F(OtlpHttpLogExporterTestPeer, ExportJsonIntegrationTest) const std::string schema_url{"https://opentelemetry.io/schemas/1.2.0"}; auto logger = provider->GetLogger("test", "", "opentelelemtry_library", "", schema_url); - logger->Log(opentelemetry::logs::Severity::kInfo, "Log name", "Log message", + logger->Log(opentelemetry::logs::Severity::kInfo, "Log message", {{"service.name", "unit_test_service"}, {"tenant.id", "test_user"}, {"bool_value", true}, @@ -151,14 +151,13 @@ TEST_F(OtlpHttpLogExporterTestPeer, ExportJsonIntegrationTest) .WillOnce([&mock_session, report_trace_id, report_span_id](opentelemetry::ext::http::client::EventHandler &callback) { auto check_json = nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); - auto resource_logs = *check_json["resource_logs"].begin(); - auto instrumentation_library_span = *resource_logs["instrumentation_library_logs"].begin(); - auto log = *instrumentation_library_span["logs"].begin(); - auto received_trace_id = log["trace_id"].get(); - auto received_span_id = log["span_id"].get(); + auto resource_logs = *check_json["resource_logs"].begin(); + auto scope_logs = *resource_logs["scope_logs"].begin(); + auto log = *scope_logs["log_records"].begin(); + auto received_trace_id = log["trace_id"].get(); + auto received_span_id = log["span_id"].get(); EXPECT_EQ(received_trace_id, report_trace_id); EXPECT_EQ(received_span_id, report_span_id); - EXPECT_EQ("Log name", log["name"].get()); EXPECT_EQ("Log message", log["body"]["string_value"].get()); EXPECT_LE(15, log["attributes"].size()); auto custom_header = mock_session->GetRequest()->headers_.find("Custom-Header-Key"); @@ -205,7 +204,7 @@ TEST_F(OtlpHttpLogExporterTestPeer, ExportBinaryIntegrationTest) const std::string schema_url{"https://opentelemetry.io/schemas/1.2.0"}; auto logger = provider->GetLogger("test", "", "opentelelemtry_library", "", schema_url); - logger->Log(opentelemetry::logs::Severity::kInfo, "Log name", "Log message", + logger->Log(opentelemetry::logs::Severity::kInfo, "Log message", {{"service.name", "unit_test_service"}, {"tenant.id", "test_user"}, {"bool_value", true}, @@ -237,10 +236,9 @@ TEST_F(OtlpHttpLogExporterTestPeer, ExportBinaryIntegrationTest) opentelemetry::proto::collector::logs::v1::ExportLogsServiceRequest request_body; request_body.ParseFromArray(&mock_session->GetRequest()->body_[0], static_cast(mock_session->GetRequest()->body_.size())); - auto received_log = request_body.resource_logs(0).instrumentation_library_logs(0).logs(0); + auto &received_log = request_body.resource_logs(0).scope_logs(0).log_records(0); EXPECT_EQ(received_log.trace_id(), report_trace_id); EXPECT_EQ(received_log.span_id(), report_span_id); - EXPECT_EQ("Log name", received_log.name()); EXPECT_EQ("Log message", received_log.body().string_value()); EXPECT_LE(15, received_log.attributes_size()); bool check_service_name = false; diff --git a/exporters/otlp/test/otlp_log_recordable_test.cc b/exporters/otlp/test/otlp_log_recordable_test.cc index a4945d394b..bb48fd54e9 100644 --- a/exporters/otlp/test/otlp_log_recordable_test.cc +++ b/exporters/otlp/test/otlp_log_recordable_test.cc @@ -17,14 +17,6 @@ namespace otlp namespace resource = opentelemetry::sdk::resource; namespace proto = opentelemetry::proto; -TEST(OtlpLogRecordable, SetName) -{ - OtlpLogRecordable rec; - nostd::string_view name = "Test Log Name"; - rec.SetName(name); - EXPECT_EQ(rec.log_record().name(), name); -} - TEST(OtlpLogRecordable, SetTimestamp) { OtlpLogRecordable rec; diff --git a/exporters/otlp/test/otlp_recordable_test.cc b/exporters/otlp/test/otlp_recordable_test.cc index 1c5b8a6895..b46802d875 100644 --- a/exporters/otlp/test/otlp_recordable_test.cc +++ b/exporters/otlp/test/otlp_recordable_test.cc @@ -49,13 +49,6 @@ TEST(OtlpRecordable, SetIdentity) EXPECT_EQ(rec_invalid_parent.span().parent_span_id(), std::string{}); } -TEST(OtlpRecordable, SetName) -{ - OtlpRecordable rec; - nostd::string_view name = "Test Span"; - rec.SetName(name); - EXPECT_EQ(rec.span().name(), name); -} TEST(OtlpRecordable, SetSpanKind) { OtlpRecordable rec; @@ -77,7 +70,7 @@ TEST(OtlpRecordable, SetInstrumentationLibrary) TEST(OtlpRecordable, SetInstrumentationLibraryWithSchemaURL) { OtlpRecordable rec; - const std::string expected_schema_url{"https://opentelemetry.io/schemas/1.2.0"}; + const std::string expected_schema_url{"https://opentelemetry.io/schemas/1.11.0"}; auto inst_lib = trace_sdk::InstrumentationLibrary::Create("test", "v1", expected_schema_url); rec.SetInstrumentationLibrary(*inst_lib); EXPECT_EQ(expected_schema_url, rec.GetInstrumentationLibrarySchemaURL()); @@ -220,7 +213,7 @@ TEST(OtlpRecordable, SetResourceWithSchemaURL) OtlpRecordable rec; 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"; + const std::string expected_schema_url = "https://opentelemetry.io/schemas/1.11.0"; auto resource = resource::Resource::Create({{service_name_key, service_name}}, expected_schema_url); rec.SetResource(resource); diff --git a/sdk/include/opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h b/sdk/include/opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h index b288aa5b71..20f82a5d18 100644 --- a/sdk/include/opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h +++ b/sdk/include/opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h @@ -3,11 +3,13 @@ #pragma once -#include #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/unique_ptr.h" #include "opentelemetry/version.h" +#include +#include + OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -35,6 +37,8 @@ class InstrumentationLibrary new InstrumentationLibrary{name, version, schema_url}); } + std::size_t HashCode() const noexcept { return hash_code_; } + /** * Compare 2 instrumentation libraries. * @param other the instrumentation library to compare to. @@ -70,12 +74,20 @@ class InstrumentationLibrary nostd::string_view version, nostd::string_view schema_url = "") : name_(name), version_(version), schema_url_(schema_url) - {} + { + std::string hash_data; + hash_data.reserve(name_.size() + version_.size() + schema_url_.size()); + hash_data += name_; + hash_data += version_; + hash_data += schema_url_; + hash_code_ = std::hash{}(hash_data); + } private: std::string name_; std::string version_; std::string schema_url_; + std::size_t hash_code_; }; } // namespace instrumentationlibrary diff --git a/sdk/include/opentelemetry/sdk/logs/log_record.h b/sdk/include/opentelemetry/sdk/logs/log_record.h index 502a87a6f0..2a3a782893 100644 --- a/sdk/include/opentelemetry/sdk/logs/log_record.h +++ b/sdk/include/opentelemetry/sdk/logs/log_record.h @@ -31,7 +31,6 @@ class LogRecord final : public Recordable opentelemetry::logs::Severity severity_ = opentelemetry::logs::Severity::kInvalid; const opentelemetry::sdk::resource::Resource *resource_ = nullptr; common::AttributeMap attributes_map_; - std::string name_; std::string body_; // Currently a simple string, but should be changed to "Any" type opentelemetry::trace::TraceId trace_id_; opentelemetry::trace::SpanId span_id_; @@ -50,12 +49,6 @@ class LogRecord final : public Recordable severity_ = severity; } - /** - * Set name for this log - * @param name the name to set - */ - void SetName(nostd::string_view name) noexcept override { name_ = std::string(name); } - /** * Set body field for this log. * @param message the body to set @@ -127,12 +120,6 @@ class LogRecord final : public Recordable */ opentelemetry::logs::Severity GetSeverity() const noexcept { return severity_; } - /** - * Get the name of this log - * @return the name of this log - */ - std::string GetName() const noexcept { return name_; } - /** * Get the body of this log * @return the body of this log diff --git a/sdk/include/opentelemetry/sdk/logs/logger.h b/sdk/include/opentelemetry/sdk/logs/logger.h index 604eb0d8f9..4eeca2da11 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger.h +++ b/sdk/include/opentelemetry/sdk/logs/logger.h @@ -40,7 +40,6 @@ class Logger final : public opentelemetry::logs::Logger /** * Writes a log record into the processor. * @param severity the severity level of the log event. - * @param name the name of the log event. * @param message the string message of the log (perhaps support std::fmt or fmt-lib format). * with the log event. * @param attributes the attributes, stored as a 2D list of key/value pairs, that are associated @@ -51,7 +50,6 @@ class Logger final : public opentelemetry::logs::Logger * @param timestamp the timestamp the log record was created. * @throws No exceptions under any circumstances. */ void Log(opentelemetry::logs::Severity severity, - nostd::string_view name, nostd::string_view body, const opentelemetry::common::KeyValueIterable &attributes, opentelemetry::trace::TraceId trace_id, diff --git a/sdk/include/opentelemetry/sdk/logs/multi_recordable.h b/sdk/include/opentelemetry/sdk/logs/multi_recordable.h index 59c018d2d6..db3df96227 100644 --- a/sdk/include/opentelemetry/sdk/logs/multi_recordable.h +++ b/sdk/include/opentelemetry/sdk/logs/multi_recordable.h @@ -41,12 +41,6 @@ class MultiRecordable final : public Recordable */ void SetSeverity(opentelemetry::logs::Severity severity) noexcept override; - /** - * Set name for this log - * @param name the name to set - */ - void SetName(nostd::string_view name) noexcept override; - /** * Set body field for this log. * @param message the body to set diff --git a/sdk/include/opentelemetry/sdk/logs/recordable.h b/sdk/include/opentelemetry/sdk/logs/recordable.h index a858e67d62..4a32273732 100644 --- a/sdk/include/opentelemetry/sdk/logs/recordable.h +++ b/sdk/include/opentelemetry/sdk/logs/recordable.h @@ -45,12 +45,6 @@ class Recordable */ virtual void SetSeverity(opentelemetry::logs::Severity severity) noexcept = 0; - /** - * Set name for this log - * @param name the name to set - */ - virtual void SetName(nostd::string_view name) noexcept = 0; - /** * Set body field for this log. * @param message the body to set diff --git a/sdk/src/logs/logger.cc b/sdk/src/logs/logger.cc index fc690c6773..b8fdb15c38 100644 --- a/sdk/src/logs/logger.cc +++ b/sdk/src/logs/logger.cc @@ -36,7 +36,6 @@ const nostd::string_view Logger::GetName() noexcept * if the user does not specify them. */ void Logger::Log(opentelemetry::logs::Severity severity, - nostd::string_view name, nostd::string_view body, const common::KeyValueIterable &attributes, trace_api::TraceId trace_id, @@ -63,7 +62,6 @@ void Logger::Log(opentelemetry::logs::Severity severity, // Populate recordable fields recordable->SetTimestamp(timestamp); recordable->SetSeverity(severity); - recordable->SetName(name); recordable->SetBody(body); recordable->SetInstrumentationLibrary(GetInstrumentationLibrary()); diff --git a/sdk/src/logs/logger_provider.cc b/sdk/src/logs/logger_provider.cc index 3115b7fac8..089b8d0de0 100644 --- a/sdk/src/logs/logger_provider.cc +++ b/sdk/src/logs/logger_provider.cc @@ -88,9 +88,19 @@ nostd::shared_ptr LoggerProvider::GetLogger( } */ - // If no logger with that name exists yet, create it and add it to the map of loggers - auto lib = instrumentationlibrary::InstrumentationLibrary::Create(library_name, library_version, - schema_url); + // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#field-instrumentationscope + opentelemetry::nostd::unique_ptr lib; + if (library_name.empty()) + { + lib = instrumentationlibrary::InstrumentationLibrary::Create(logger_name, library_version, + schema_url); + } + else + { + lib = instrumentationlibrary::InstrumentationLibrary::Create(library_name, library_version, + schema_url); + } + loggers_.push_back(std::shared_ptr( new Logger(logger_name, context_, std::move(lib)))); return nostd::shared_ptr{loggers_.back()}; diff --git a/sdk/src/logs/multi_recordable.cc b/sdk/src/logs/multi_recordable.cc index b7bb92c627..4d615ec738 100644 --- a/sdk/src/logs/multi_recordable.cc +++ b/sdk/src/logs/multi_recordable.cc @@ -72,14 +72,6 @@ void MultiRecordable::SetSeverity(opentelemetry::logs::Severity severity) noexce } } -void MultiRecordable::SetName(nostd::string_view name) noexcept -{ - for (auto &recordable : recordables_) - { - recordable.second->SetName(name); - } -} - void MultiRecordable::SetBody(nostd::string_view message) noexcept { for (auto &recordable : recordables_) diff --git a/sdk/test/logs/batch_log_processor_test.cc b/sdk/test/logs/batch_log_processor_test.cc index df503cb2aa..63e44676c8 100644 --- a/sdk/test/logs/batch_log_processor_test.cc +++ b/sdk/test/logs/batch_log_processor_test.cc @@ -110,7 +110,7 @@ TEST_F(BatchLogProcessorTest, TestShutdown) for (int i = 0; i < num_logs; ++i) { auto log = batch_processor->MakeRecordable(); - log->SetName("Log" + std::to_string(i)); + log->SetBody("Log" + std::to_string(i)); batch_processor->OnReceive(std::move(log)); } @@ -126,7 +126,7 @@ TEST_F(BatchLogProcessorTest, TestShutdown) // Assume logs are received by exporter in same order as sent by processor for (int i = 0; i < num_logs; ++i) { - EXPECT_EQ("Log" + std::to_string(i), logs_received->at(i)->GetName()); + EXPECT_EQ("Log" + std::to_string(i), logs_received->at(i)->GetBody()); } // Also check that the processor is shut down at the end @@ -145,7 +145,7 @@ TEST_F(BatchLogProcessorTest, TestForceFlush) for (int i = 0; i < num_logs; ++i) { auto log = batch_processor->MakeRecordable(); - log->SetName("Log" + std::to_string(i)); + log->SetBody("Log" + std::to_string(i)); batch_processor->OnReceive(std::move(log)); } @@ -154,14 +154,14 @@ TEST_F(BatchLogProcessorTest, TestForceFlush) EXPECT_EQ(num_logs, logs_received->size()); for (int i = 0; i < num_logs; ++i) { - EXPECT_EQ("Log" + std::to_string(i), logs_received->at(i)->GetName()); + EXPECT_EQ("Log" + std::to_string(i), logs_received->at(i)->GetBody()); } // Create some more logs to make sure that the processor still works for (int i = 0; i < num_logs; ++i) { auto log = batch_processor->MakeRecordable(); - log->SetName("Log" + std::to_string(i)); + log->SetBody("Log" + std::to_string(i)); batch_processor->OnReceive(std::move(log)); } @@ -170,7 +170,7 @@ TEST_F(BatchLogProcessorTest, TestForceFlush) EXPECT_EQ(num_logs * 2, logs_received->size()); for (int i = 0; i < num_logs * 2; ++i) { - EXPECT_EQ("Log" + std::to_string(i % num_logs), logs_received->at(i)->GetName()); + EXPECT_EQ("Log" + std::to_string(i % num_logs), logs_received->at(i)->GetBody()); } } @@ -190,7 +190,7 @@ TEST_F(BatchLogProcessorTest, TestManyLogsLoss) for (int i = 0; i < max_queue_size; ++i) { auto log = batch_processor->MakeRecordable(); - log->SetName("Log" + std::to_string(i)); + log->SetBody("Log" + std::to_string(i)); batch_processor->OnReceive(std::move(log)); } @@ -214,7 +214,7 @@ TEST_F(BatchLogProcessorTest, TestManyLogsLossLess) for (int i = 0; i < num_logs; ++i) { auto log = batch_processor->MakeRecordable(); - log->SetName("Log" + std::to_string(i)); + log->SetBody("Log" + std::to_string(i)); batch_processor->OnReceive(std::move(log)); } @@ -223,7 +223,7 @@ TEST_F(BatchLogProcessorTest, TestManyLogsLossLess) EXPECT_EQ(num_logs, logs_received->size()); for (int i = 0; i < num_logs; ++i) { - EXPECT_EQ("Log" + std::to_string(i), logs_received->at(i)->GetName()); + EXPECT_EQ("Log" + std::to_string(i), logs_received->at(i)->GetBody()); } } @@ -247,7 +247,7 @@ TEST_F(BatchLogProcessorTest, TestScheduledDelayMillis) for (std::size_t i = 0; i < max_export_batch_size; ++i) { auto log = batch_processor->MakeRecordable(); - log->SetName("Log" + std::to_string(i)); + log->SetBody("Log" + std::to_string(i)); batch_processor->OnReceive(std::move(log)); } // Sleep for scheduled_delay_millis milliseconds @@ -263,7 +263,7 @@ TEST_F(BatchLogProcessorTest, TestScheduledDelayMillis) EXPECT_EQ(max_export_batch_size, logs_received->size()); for (size_t i = 0; i < max_export_batch_size; ++i) { - EXPECT_EQ("Log" + std::to_string(i), logs_received->at(i)->GetName()); + EXPECT_EQ("Log" + std::to_string(i), logs_received->at(i)->GetBody()); } } #endif diff --git a/sdk/test/logs/log_record_test.cc b/sdk/test/logs/log_record_test.cc index dda80cc1ee..89b07473a3 100644 --- a/sdk/test/logs/log_record_test.cc +++ b/sdk/test/logs/log_record_test.cc @@ -24,7 +24,6 @@ TEST(LogRecord, GetDefaultValues) LogRecord record; ASSERT_EQ(record.GetSeverity(), logs_api::Severity::kInvalid); - ASSERT_EQ(record.GetName(), ""); ASSERT_EQ(record.GetBody(), ""); ASSERT_NE(record.GetResource().GetAttributes().size(), 0); ASSERT_EQ(record.GetAttributes().size(), 0); @@ -46,7 +45,6 @@ TEST(LogRecord, SetAndGet) LogRecord record; auto resource = opentelemetry::sdk::resource::Resource::Create({{"res1", true}}); record.SetSeverity(logs_api::Severity::kInvalid); - record.SetName("Log name"); record.SetBody("Message"); record.SetResource(resource); record.SetAttribute("attr1", (int64_t)314159); @@ -57,7 +55,6 @@ TEST(LogRecord, SetAndGet) // Test that all fields match what was set ASSERT_EQ(record.GetSeverity(), logs_api::Severity::kInvalid); - ASSERT_EQ(record.GetName(), "Log name"); ASSERT_EQ(record.GetBody(), "Message"); ASSERT_TRUE(nostd::get(record.GetResource().GetAttributes().at("res1"))); ASSERT_EQ(nostd::get(record.GetAttributes().at("attr1")), 314159); diff --git a/sdk/test/logs/logger_provider_sdk_test.cc b/sdk/test/logs/logger_provider_sdk_test.cc index 5948a9dfd2..3e5e8dfb26 100644 --- a/sdk/test/logs/logger_provider_sdk_test.cc +++ b/sdk/test/logs/logger_provider_sdk_test.cc @@ -32,9 +32,9 @@ TEST(LoggerProviderSDK, LoggerProviderGetLoggerSimple) { auto lp = std::shared_ptr(new LoggerProvider()); - nostd::string_view schema_url{"https://opentelemetry.io/schemas/1.2.0"}; + nostd::string_view schema_url{"https://opentelemetry.io/schemas/1.11.0"}; auto logger1 = lp->GetLogger("logger1", "", "opentelelemtry_library", "", schema_url); - auto logger2 = lp->GetLogger("logger2", "", "opentelelemtry_library", "", schema_url); + auto logger2 = lp->GetLogger("logger2", "", "", "", schema_url); // Check that the logger is not nullptr ASSERT_NE(logger1, nullptr); @@ -46,7 +46,7 @@ TEST(LoggerProviderSDK, LoggerProviderGetLoggerSimple) ASSERT_EQ(sdk_logger1->GetInstrumentationLibrary().GetVersion(), ""); ASSERT_EQ(sdk_logger1->GetInstrumentationLibrary().GetSchemaURL(), schema_url); - ASSERT_EQ(sdk_logger2->GetInstrumentationLibrary().GetName(), "opentelelemtry_library"); + ASSERT_EQ(sdk_logger2->GetInstrumentationLibrary().GetName(), "logger2"); ASSERT_EQ(sdk_logger2->GetInstrumentationLibrary().GetVersion(), ""); ASSERT_EQ(sdk_logger2->GetInstrumentationLibrary().GetSchemaURL(), schema_url); @@ -67,7 +67,7 @@ TEST(LoggerProviderSDK, LoggerProviderLoggerArguments) // detail to this test auto lp = std::shared_ptr(new LoggerProvider()); - nostd::string_view schema_url{"https://opentelemetry.io/schemas/1.2.0"}; + nostd::string_view schema_url{"https://opentelemetry.io/schemas/1.11.0"}; auto logger1 = lp->GetLogger("logger1", "", "opentelelemtry_library", "", schema_url); // Check GetLogger(logger_name, args) diff --git a/sdk/test/logs/logger_sdk_test.cc b/sdk/test/logs/logger_sdk_test.cc index aad13f41e2..3747731f1f 100644 --- a/sdk/test/logs/logger_sdk_test.cc +++ b/sdk/test/logs/logger_sdk_test.cc @@ -18,7 +18,7 @@ TEST(LoggerSDK, LogToNullProcessor) // since it calls Processor::OnReceive() auto lp = std::shared_ptr(new LoggerProvider()); - const std::string schema_url{"https://opentelemetry.io/schemas/1.2.0"}; + const std::string schema_url{"https://opentelemetry.io/schemas/1.11.0"}; auto logger = lp->GetLogger("logger", "", "opentelelemtry_library", "", schema_url); auto sdk_logger = static_cast(logger.get()); @@ -54,7 +54,6 @@ class MockProcessor final : public LogProcessor // Copy over the received log record's severity, name, and body fields over to the recordable // passed in the constructor record_received_->SetSeverity(copy->GetSeverity()); - record_received_->SetName(copy->GetName()); record_received_->SetBody(copy->GetBody()); } bool ForceFlush(std::chrono::microseconds timeout = std::chrono::microseconds(0)) noexcept @@ -71,7 +70,7 @@ 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.2.0"}; + const std::string schema_url{"https://opentelemetry.io/schemas/1.11.0"}; 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 @@ -90,10 +89,9 @@ TEST(LoggerSDK, LogToAProcessor) lp->AddProcessor(std::unique_ptr(new MockProcessor(shared_recordable))); // Check that the recordable created by the Log() statement is set properly - logger->Log(logs_api::Severity::kWarn, "Log Name", "Log Message"); + logger->Log(logs_api::Severity::kWarn, "Log Message"); ASSERT_EQ(shared_recordable->GetSeverity(), logs_api::Severity::kWarn); - ASSERT_EQ(shared_recordable->GetName(), "Log Name"); ASSERT_EQ(shared_recordable->GetBody(), "Log Message"); } #endif diff --git a/sdk/test/logs/simple_log_processor_test.cc b/sdk/test/logs/simple_log_processor_test.cc index 0bb6ba2667..32c62a5083 100644 --- a/sdk/test/logs/simple_log_processor_test.cc +++ b/sdk/test/logs/simple_log_processor_test.cc @@ -85,7 +85,7 @@ TEST(SimpleLogProcessorTest, SendReceivedLogsToExporter) for (int i = 0; i < num_logs; i++) { auto recordable = processor.MakeRecordable(); - recordable->SetName("Log"); + recordable->SetBody("Log Body"); processor.OnReceive(std::move(recordable)); // Verify that the batch of 1 log record sent by processor matches what exporter received @@ -96,7 +96,7 @@ TEST(SimpleLogProcessorTest, SendReceivedLogsToExporter) EXPECT_EQ(logs_received->size(), num_logs); for (int i = 0; i < num_logs; i++) { - EXPECT_EQ("Log", logs_received->at(i)->GetName()); + EXPECT_EQ("Log Body", logs_received->at(i)->GetBody()); } } diff --git a/third_party/opentelemetry-proto b/third_party/opentelemetry-proto index b43e9b18b7..5c2fe5ddbd 160000 --- a/third_party/opentelemetry-proto +++ b/third_party/opentelemetry-proto @@ -1 +1 @@ -Subproject commit b43e9b18b76abf3ee040164b55b9c355217151f3 +Subproject commit 5c2fe5ddbd9fb9f3e08f31d20f7566a3ee3d8885 diff --git a/third_party_release b/third_party_release index c752efe629..964cbfb871 100644 --- a/third_party_release +++ b/third_party_release @@ -2,9 +2,9 @@ gRPC=v1.43.2 thrift=0.14.1 abseil=20210324.0 benchmark=v1.5.3 -googletest=release-1.8.0-2523-ga6dfd3ac -ms-gsl=v1.0.0-393-g6f45293 +googletest=release-1.10.0-459-ga6dfd3ac +ms-gsl=v3.1.0-67-g6f45293 nlohmann-json=v3.9.1 -opentelemetry-proto=v0.11.0 +opentelemetry-proto=v0.17.0 prometheus-cpp=v1.0.0 -vcpkg=2020.04-2702-g5568f110b +vcpkg=2022.04.12 diff --git a/tools/build-vcpkg.sh b/tools/build-vcpkg.sh index f7fb829ce2..f4acb009fe 100755 --- a/tools/build-vcpkg.sh +++ b/tools/build-vcpkg.sh @@ -1,23 +1,26 @@ #!/bin/bash export PATH=/usr/local/bin:$PATH -DIR="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" +DIR="$( + cd "$(dirname "$0")" >/dev/null 2>&1 + pwd -P +)" WORKSPACE_ROOT=$DIR/.. export VCPKG_ROOT=$WORKSPACE_ROOT/tools/vcpkg export PATH=$VCPKG_ROOT:$PATH -if [[ ! -f $DIR/vcpkg/vcpkg ]] ; then +if [[ ! -f $DIR/vcpkg/vcpkg ]]; then pushd $DIR/vcpkg ./bootstrap-vcpkg.sh popd fi -vcpkg install gtest -vcpkg install benchmark -vcpkg install ms-gsl -vcpkg install nlohmann-json -vcpkg install abseil -vcpkg install protobuf +vcpkg "--vcpkg-root=$VCPKG_ROOT" install gtest +vcpkg "--vcpkg-root=$VCPKG_ROOT" install benchmark +vcpkg "--vcpkg-root=$VCPKG_ROOT" install ms-gsl +vcpkg "--vcpkg-root=$VCPKG_ROOT" install nlohmann-json +vcpkg "--vcpkg-root=$VCPKG_ROOT" install abseil +vcpkg "--vcpkg-root=$VCPKG_ROOT" install protobuf cd $WORKSPACE_ROOT export USE_VCPKG=1 diff --git a/tools/setup-buildtools.cmd b/tools/setup-buildtools.cmd index 956c8ddfe4..fab61a520e 100644 --- a/tools/setup-buildtools.cmd +++ b/tools/setup-buildtools.cmd @@ -61,15 +61,15 @@ if %ERRORLEVEL% == 1 ( ) REM Install dependencies -vcpkg install gtest:%ARCH%-windows -vcpkg install --overlay-ports=%~dp0ports benchmark:%ARCH%-windows -vcpkg install --overlay-ports=%~dp0ports protobuf:%ARCH%-windows -vcpkg install ms-gsl:%ARCH%-windows -vcpkg install nlohmann-json:%ARCH%-windows -vcpkg install abseil:%ARCH%-windows -vcpkg install gRPC:%ARCH%-windows -vcpkg install prometheus-cpp:%ARCH%-windows -vcpkg install curl:%ARCH%-windows -vcpkg install thrift:%ARCH%-windows +vcpkg "--vcpkg-root=%VCPKG_ROOT%" install gtest:%ARCH%-windows +vcpkg "--vcpkg-root=%VCPKG_ROOT%" install --overlay-ports=%~dp0ports benchmark:%ARCH%-windows +vcpkg "--vcpkg-root=%VCPKG_ROOT%" install --overlay-ports=%~dp0ports protobuf:%ARCH%-windows +vcpkg "--vcpkg-root=%VCPKG_ROOT%" install ms-gsl:%ARCH%-windows +vcpkg "--vcpkg-root=%VCPKG_ROOT%" install nlohmann-json:%ARCH%-windows +vcpkg "--vcpkg-root=%VCPKG_ROOT%" install abseil:%ARCH%-windows +vcpkg "--vcpkg-root=%VCPKG_ROOT%" install gRPC:%ARCH%-windows +vcpkg "--vcpkg-root=%VCPKG_ROOT%" install prometheus-cpp:%ARCH%-windows +vcpkg "--vcpkg-root=%VCPKG_ROOT%" install curl:%ARCH%-windows +vcpkg "--vcpkg-root=%VCPKG_ROOT%" install thrift:%ARCH%-windows popd exit /b 0