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 2cb294e721..0bf750cd54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,62 @@ Increment the: * [EXT] `curl::HttpClient` use `curl_multi_handle` instead of creating a thread for every request and it's able to reuse connections now. ([#1317](https://github.com/open-telemetry/opentelemetry-cpp/pull/1317)) +## [1.4.0] 2022-05-17 + +* [API SDK] Upgrade proto to v0.17.0, update log data model ([#1383](https://github.com/open-telemetry/opentelemetry-cpp/pull/1383)) +* [BUILD] Alpine image ([#1382](https://github.com/open-telemetry/opentelemetry-cpp/pull/1382)) +* [LOGS SDK] Get span_id from context when Logger::Log received invalid span_id + ([#1398](https://github.com/open-telemetry/opentelemetry-cpp/pull/1398)) +* [METRICS SDK] Connect async storage with async instruments ([#1388](https://github.com/open-telemetry/opentelemetry-cpp/pull/1388)) +* [DOCS] Getting started document using ostream exporter ([#1394](https://github.com/open-telemetry/opentelemetry-cpp/pull/1394)) +* [BUILD] Fix missing link to nlohmann_json ([#1390](https://github.com/open-telemetry/opentelemetry-cpp/pull/1390)) +* [SDK] Fix sharing resource in batched exported spans ([#1386](https://github.com/open-telemetry/opentelemetry-cpp/pull/1386)) +* [PROTOCOL \& LOGS] Upgrade proto to v0.17.0, update log data model ([#1383](https://github.com/open-telemetry/opentelemetry-cpp/pull/1383)) +* [METRICS SDK] Remove un-necessary files. ([#1379](https://github.com/open-telemetry/opentelemetry-cpp/pull/1379)) +* [EXPORTER] Prometheus exporter meters and instrument name ([#1378](https://github.com/open-telemetry/opentelemetry-cpp/pull/1378)) +* [API] Add noexcept/const qualifier at missing places for Trace API. ([#1374](https://github.com/open-telemetry/opentelemetry-cpp/pull/1374)) +* [SDK] Fix empty tracestate header propagation ([#1373](https://github.com/open-telemetry/opentelemetry-cpp/pull/1373)) +* [METRICS SDK] Reuse temporal metric storage for sync storage ([#1369](https://github.com/open-telemetry/opentelemetry-cpp/pull/1369)) +* [SDK] Fix baggage propagation for empty/invalid baggage context ([#1367](https://github.com/open-telemetry/opentelemetry-cpp/pull/1367)) +* [BUILD] Export opentelemetry_otlp_recordable ([#1365](https://github.com/open-telemetry/opentelemetry-cpp/pull/1365)) +* [TESTS] Disable test on prometheus-cpp which not need ([#1363](https://github.com/open-telemetry/opentelemetry-cpp/pull/1363)) +* [METRICS] Fix class member initialization order ([#1360](https://github.com/open-telemetry/opentelemetry-cpp/pull/1360)) +* [METRICS SDK] Simplify SDK Configuration: Use View with default aggregation if + no matching View is configured + ([#1358](https://github.com/open-telemetry/opentelemetry-cpp/pull/1358)) +* [BUILD] Add missing include guard ([#1357](https://github.com/open-telemetry/opentelemetry-cpp/pull/1357)) +* [ETW EXPORTER] Fix scalar delete against array ([#1356](https://github.com/open-telemetry/opentelemetry-cpp/pull/1356)) +* [ETW EXPORTER] Conditional include for codecvt header ([#1355](https://github.com/open-telemetry/opentelemetry-cpp/pull/1355)) +* [BUILD] Use latest TraceLoggingDynamic.h ([#1354](https://github.com/open-telemetry/opentelemetry-cpp/pull/1354)) +* [SDK] Add explicit type cast in baggage UrlDecode ([#1353](https://github.com/open-telemetry/opentelemetry-cpp/pull/1353)) +* [METRICS SDK] Remove exporter registration to meter provider ([#1350](https://github.com/open-telemetry/opentelemetry-cpp/pull/1350)) +* [METRICS SDK] Fix output time in metrics OStream exporter ([#1346](https://github.com/open-telemetry/opentelemetry-cpp/pull/1346)) +* [BUILD] ostream metrics cmake ([#1344](https://github.com/open-telemetry/opentelemetry-cpp/pull/1344)) +* [BUILD] Link `opentelemetry_ext` with `opentelemetry_api` ([#1336](https://github.com/open-telemetry/opentelemetry-cpp/pull/1336)) +* [METRICS SDK] Enable metric collection for Async Instruments - Delta and + Cumulative + ([#1334](https://github.com/open-telemetry/opentelemetry-cpp/pull/1334)) +* [BUILD] Dependencies image as artifact ([#1333](https://github.com/open-telemetry/opentelemetry-cpp/pull/1333)) +* [EXAMPLE] Prometheus example ([#1332](https://github.com/open-telemetry/opentelemetry-cpp/pull/1332)) +* [METRICS EXPORTER] Prometheus exporter ([#1331](https://github.com/open-telemetry/opentelemetry-cpp/pull/1331)) +* [METRICS] Metrics histogram example ([#1330](https://github.com/open-telemetry/opentelemetry-cpp/pull/1330)) +* [TESTS] Replace deprecated googletest API ([#1327](https://github.com/open-telemetry/opentelemetry-cpp/pull/1327)) +* [BUILD] Fix Ninja path ([#1326](https://github.com/open-telemetry/opentelemetry-cpp/pull/1326)) +* [API] Update yield logic for ARM processor ([#1325](https://github.com/open-telemetry/opentelemetry-cpp/pull/1325)) +* [BUILD] Fix metrics compiler warnings ([#1328](https://github.com/open-telemetry/opentelemetry-cpp/pull/1328)) +* [METRICS SDK] Implement Merge and Diff operation for Histogram Aggregation ([#1303](https://github.com/open-telemetry/opentelemetry-cpp/pull/1303)) + +Notes: + +While opentelemetry-cpp Logs are still in experimental stage, +[#1383](https://github.com/open-telemetry/opentelemetry-cpp/pull/1383) updated +opentelemetry-proto to 0.17.0, which includes some breaking change in the +protocol, like +[this](https://github.com/open-telemetry/opentelemetry-proto/pull/373). This +makes `name` parameter for our log API unnecessary. However, this parameter is +marked deprecated instead of being removed in this release, and it will be +removed in future release. + ## [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 fc4e2b0a66..26387aee60 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/README.md b/README.md index 7dc77fc940..75231ac7cc 100644 --- a/README.md +++ b/README.md @@ -13,15 +13,15 @@ The C++ [OpenTelemetry](https://opentelemetry.io/) client. | Signal | Status | Project | | ------- | ---------------------- | ------------------------------------------------------------------------ | | Traces | Public Release | N/A | -| Metrics | Development [1] | N/A | +| Metrics | Alpha [1] | N/A | | Logs | Experimental [2] | N/A | -* [1]: The development of the metrics API and SDK based on new stable - specification is ongoing. The timelines would be available in release - milestone. The earlier implementation (based on old specification) can be - included in build by setting `ENABLE_METRICS_PREVIEW` preprocessor macro, - and is included under `*/_metrics/*` directory. This would be eventually - removed once the ongoing implemetation is stable. +* [1]: The metric collection pipeline is available for testing purpose. Not + ready for production. The earlier implementation (based on old + specification) can be included in build by setting + `ENABLE_METRICS_PREVIEW` preprocessor macro, and is included under + `*/_metrics/*` directory. This would be eventually removed once the + ongoing implemetation is stable. * [2]: The current Log Signal Implementation is Experimental, and will change as the current OpenTelemetry Log specification matures. The current implementation can be included in build by setting `ENABLE_LOGS_PREVIEW` 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/include/opentelemetry/metrics/meter.h b/api/include/opentelemetry/metrics/meter.h index 9f7f2d2b0a..6a19911390 100644 --- a/api/include/opentelemetry/metrics/meter.h +++ b/api/include/opentelemetry/metrics/meter.h @@ -56,17 +56,15 @@ class Meter * @param callback the function to be observed by the instrument. * @return a shared pointer to the created Observable Counter. */ - virtual nostd::shared_ptr> CreateLongObservableCounter( - nostd::string_view name, - void (*callback)(ObserverResult &), - nostd::string_view description = "", - nostd::string_view unit = "") noexcept = 0; + virtual void CreateLongObservableCounter(nostd::string_view name, + void (*callback)(ObserverResult &), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept = 0; - virtual nostd::shared_ptr> CreateDoubleObservableCounter( - nostd::string_view name, - void (*callback)(ObserverResult &), - nostd::string_view description = "", - nostd::string_view unit = "") noexcept = 0; + virtual void CreateDoubleObservableCounter(nostd::string_view name, + void (*callback)(ObserverResult &), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept = 0; /** * Creates a Histogram with the passed characteristics and returns a shared_ptr to that Histogram. @@ -96,17 +94,15 @@ class Meter * @param callback the function to be observed by the instrument. * @return a shared pointer to the created Observable Gauge. */ - virtual nostd::shared_ptr> CreateLongObservableGauge( - nostd::string_view name, - void (*callback)(ObserverResult &), - nostd::string_view description = "", - nostd::string_view unit = "") noexcept = 0; + virtual void CreateLongObservableGauge(nostd::string_view name, + void (*callback)(ObserverResult &), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept = 0; - virtual nostd::shared_ptr> CreateDoubleObservableGauge( - nostd::string_view name, - void (*callback)(ObserverResult &), - nostd::string_view description = "", - nostd::string_view unit = "") noexcept = 0; + virtual void CreateDoubleObservableGauge(nostd::string_view name, + void (*callback)(ObserverResult &), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept = 0; /** * Creates an UpDownCounter with the passed characteristics and returns a shared_ptr to that @@ -137,17 +133,15 @@ class Meter * @param callback the function to be observed by the instrument. * @return a shared pointer to the created Observable UpDownCounter. */ - virtual nostd::shared_ptr> CreateLongObservableUpDownCounter( - nostd::string_view name, - void (*callback)(ObserverResult &), - nostd::string_view description = "", - nostd::string_view unit = "") noexcept = 0; - - virtual nostd::shared_ptr> CreateDoubleObservableUpDownCounter( - nostd::string_view name, - void (*callback)(ObserverResult &), - nostd::string_view description = "", - nostd::string_view unit = "") noexcept = 0; + virtual void CreateLongObservableUpDownCounter(nostd::string_view name, + void (*callback)(ObserverResult &), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept = 0; + + virtual void CreateDoubleObservableUpDownCounter(nostd::string_view name, + void (*callback)(ObserverResult &), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept = 0; }; } // namespace metrics OPENTELEMETRY_END_NAMESPACE diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h index 3332384ee2..0fbda060b9 100644 --- a/api/include/opentelemetry/metrics/noop.h +++ b/api/include/opentelemetry/metrics/noop.h @@ -137,25 +137,17 @@ class NoopMeter final : public Meter return nostd::shared_ptr>{new NoopCounter(name, description, unit)}; } - nostd::shared_ptr> CreateLongObservableCounter( - nostd::string_view name, - void (*callback)(ObserverResult &), - nostd::string_view description = "", - nostd::string_view unit = "") noexcept override - { - return nostd::shared_ptr>{ - new NoopObservableCounter(name, callback, description, unit)}; - } + void CreateLongObservableCounter(nostd::string_view name, + void (*callback)(ObserverResult &), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override + {} - nostd::shared_ptr> CreateDoubleObservableCounter( - nostd::string_view name, - void (*callback)(ObserverResult &), - nostd::string_view description = "", - nostd::string_view unit = "") noexcept override - { - return nostd::shared_ptr>{ - new NoopObservableCounter(name, callback, description, unit)}; - } + void CreateDoubleObservableCounter(nostd::string_view name, + void (*callback)(ObserverResult &), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override + {} nostd::shared_ptr> CreateLongHistogram( nostd::string_view name, @@ -173,25 +165,17 @@ class NoopMeter final : public Meter return nostd::shared_ptr>{new NoopHistogram(name, description, unit)}; } - nostd::shared_ptr> CreateLongObservableGauge( - nostd::string_view name, - void (*callback)(ObserverResult &), - nostd::string_view description = "", - nostd::string_view unit = "") noexcept override - { - return nostd::shared_ptr>{ - new NoopObservableGauge(name, callback, description, unit)}; - } + void CreateLongObservableGauge(nostd::string_view name, + void (*callback)(ObserverResult &), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override + {} - nostd::shared_ptr> CreateDoubleObservableGauge( - nostd::string_view name, - void (*callback)(ObserverResult &), - nostd::string_view description = "", - nostd::string_view unit = "") noexcept override - { - return nostd::shared_ptr>{ - new NoopObservableGauge(name, callback, description, unit)}; - } + void CreateDoubleObservableGauge(nostd::string_view name, + void (*callback)(ObserverResult &), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override + {} nostd::shared_ptr> CreateLongUpDownCounter( nostd::string_view name, @@ -211,25 +195,17 @@ class NoopMeter final : public Meter new NoopUpDownCounter(name, description, unit)}; } - nostd::shared_ptr> CreateLongObservableUpDownCounter( - nostd::string_view name, - void (*callback)(ObserverResult &), - nostd::string_view description = "", - nostd::string_view unit = "") noexcept override - { - return nostd::shared_ptr>{ - new NoopObservableUpDownCounter(name, callback, description, unit)}; - } + void CreateLongObservableUpDownCounter(nostd::string_view name, + void (*callback)(ObserverResult &), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override + {} - nostd::shared_ptr> CreateDoubleObservableUpDownCounter( - nostd::string_view name, - void (*callback)(ObserverResult &), - nostd::string_view description = "", - nostd::string_view unit = "") noexcept override - { - return nostd::shared_ptr>{ - new NoopObservableUpDownCounter(name, callback, description, unit)}; - } + void CreateDoubleObservableUpDownCounter(nostd::string_view name, + void (*callback)(ObserverResult &), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override + {} }; /** diff --git a/api/include/opentelemetry/version.h b/api/include/opentelemetry/version.h index 1e01e242ed..849259d3ed 100644 --- a/api/include/opentelemetry/version.h +++ b/api/include/opentelemetry/version.h @@ -6,7 +6,7 @@ #include "opentelemetry/detail/preprocessor.h" #define OPENTELEMETRY_ABI_VERSION_NO 1 -#define OPENTELEMETRY_VERSION "1.3.0" +#define OPENTELEMETRY_VERSION "1.4.0" #define OPENTELEMETRY_ABI_VERSION OPENTELEMETRY_STRINGIFY(OPENTELEMETRY_ABI_VERSION_NO) // clang-format off 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 7b60632422..7663ccee40 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 --copt=-DENABLE_ASYNC_EXPORT" -$BAZEL_TEST_OPTIONS="$BAZEL_OPTIONS --test_output=errors" +$BAZEL_OPTIONS = "--copt=-DENABLE_METRICS_PREVIEW --copt=-DENABLE_LOGS_PREVIEW --copt=-DENABLE_ASYNC_EXPORT" +$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" { @@ -33,7 +33,7 @@ switch ($action) { cmake $SRC_DIR ` -DVCPKG_TARGET_TRIPLET=x64-windows ` -DWITH_ASYNC_EXPORT_PREVIEW=ON ` - "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR\scripts\buildsystems\vcpkg.cmake" + "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake" $exit = $LASTEXITCODE if ($exit -ne 0) { exit $exit @@ -55,7 +55,7 @@ switch ($action) { -DVCPKG_TARGET_TRIPLET=x64-windows ` -DWITH_ASYNC_EXPORT_PREVIEW=ON ` -DWITH_OTPROTCOL=ON ` - "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR\scripts\buildsystems\vcpkg.cmake" + "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake" $exit = $LASTEXITCODE if ($exit -ne 0) { exit $exit @@ -76,7 +76,7 @@ switch ($action) { cmake $SRC_DIR ` -DVCPKG_TARGET_TRIPLET=x64-windows ` -DWITH_ASYNC_EXPORT_PREVIEW=ON ` - "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR\scripts\buildsystems\vcpkg.cmake" + "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake" $exit = $LASTEXITCODE if ($exit -ne 0) { exit $exit @@ -86,14 +86,14 @@ 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 ` -DWITH_ASYNC_EXPORT_PREVIEW=ON ` - "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR\scripts\buildsystems\vcpkg.cmake" + "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake" $exit = $LASTEXITCODE if ($exit -ne 0) { exit $exit @@ -103,7 +103,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 5258dfe74e..47b556c342 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -66,7 +66,7 @@ if [[ "$1" != "bazel.nortti" ]]; then fi BAZEL_TEST_OPTIONS="$BAZEL_OPTIONS --test_output=errors" -BAZEL_OPTIONS_ASYNC="--copt=-DENABLE_METRICS_PREVIEW --copt=-DENABLE_LOGS_PREVIEW --copt=-DENABLE_TEST --copt=-DENABLE_ASYNC_EXPORT" +BAZEL_OPTIONS_ASYNC="$BAZEL_OPTIONS --copt=-DENABLE_ASYNC_EXPORT" BAZEL_TEST_OPTIONS_ASYNC="$BAZEL_OPTIONS_ASYNC --test_output=errors" # https://github.com/bazelbuild/bazel/issues/4341 @@ -241,8 +241,8 @@ elif [[ "$1" == "bazel.noexcept" ]]; then elif [[ "$1" == "bazel.nortti" ]]; then # there are some exceptions and error handling code from the Prometheus and Jaeger Clients # that make this test always fail. ignore Prometheus and Jaeger exporters in the noexcept here. - bazel $BAZEL_STARTUP_OPTIONS build --cxxopt=-fno-rtti --build_tag_filters=-jaeger $BAZEL_OPTIONS -- //... -//exporters/prometheus/... -//exporters/jaeger/... - bazel $BAZEL_STARTUP_OPTIONS test --cxxopt=-fno-rtti --build_tag_filters=-jaeger $BAZEL_TEST_OPTIONS -- //... -//exporters/prometheus/... -//exporters/jaeger/... + bazel $BAZEL_STARTUP_OPTIONS build --cxxopt=-fno-rtti --build_tag_filters=-jaeger $BAZEL_OPTIONS_ASYNC -- //... -//exporters/prometheus/... -//exporters/jaeger/... + bazel $BAZEL_STARTUP_OPTIONS test --cxxopt=-fno-rtti --build_tag_filters=-jaeger $BAZEL_TEST_OPTIONS_ASYNC -- //... -//exporters/prometheus/... -//exporters/jaeger/... exit 0 elif [[ "$1" == "bazel.asan" ]]; then bazel $BAZEL_STARTUP_OPTIONS test --config=asan $BAZEL_TEST_OPTIONS_ASYNC //... @@ -294,7 +294,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/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000000..118cac62f9 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,36 @@ +ARG BASE_IMAGE=ubuntu:latest +ARG GRPC_IMAGE=grpc-${BASE_IMAGE} +ARG THRIFT_IMAGE=thrift-${BASE_IMAGE} + +FROM ${GRPC_IMAGE} as grpc +FROM ${THRIFT_IMAGE} as thrift + +FROM base-${BASE_IMAGE}-dev AS otel-cpp + +ARG CORES=${nproc} +ARG OTEL_GIT_TAG=v1.3.0 + +COPY --from=grpc / /usr/local +COPY --from=thrift / /usr/local + +#install opentelemetry-cpp +RUN git clone --recurse-submodules -j ${CORES} --depth=1 \ + -b ${OTEL_GIT_TAG} https://github.com/open-telemetry/opentelemetry-cpp.git \ + && cd opentelemetry-cpp \ + && mkdir -p build && cd build \ + && cmake \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE \ + -DWITH_ZIPKIN=ON \ + -DWITH_JAEGER=ON \ + -DCMAKE_INSTALL_PREFIX=/opt/third_party/install \ + -DBUILD_TESTING=OFF \ + -DWITH_OTLP=ON \ + -DWITH_OTLP_GRPC=ON \ + -DBUILD_SHARED_LIBS=ON \ + .. \ + && cmake --build . -j ${CORES} --target install + +FROM scratch as final + +COPY --from=otel-cpp /opt/third_party/install / diff --git a/docker/Dockerfile.alpine.base b/docker/Dockerfile.alpine.base new file mode 100644 index 0000000000..2595efa70f --- /dev/null +++ b/docker/Dockerfile.alpine.base @@ -0,0 +1,15 @@ +ARG BASE_IMAGE=alpine:latest +ARG CORES=${nproc} + +FROM ${BASE_IMAGE} as final + +RUN apk update + +RUN apk add --update alpine-sdk \ + && apk add cmake openssl openssl-dev g++ \ + curl-dev git autoconf libtool linux-headers \ + boost-dev libevent-dev openssl-dev + +RUN mkdir -p /opt/third_party/install + +WORKDIR /opt diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000000..165667117c --- /dev/null +++ b/docker/README.md @@ -0,0 +1,24 @@ +# OpenTelemetry library builder + +**How to use this build script:** + +The build script `build.sh` can be used to build OpenTelemetry and +it's dependencies within the desired base image. +The final image only contains the necessary files in `/`. + +```sh +bash build.sh -b alpine -j ${nproc} -g v1.43.2 -o v1.3.0 -t 0.14.1 + +# copy to current dir +docker create -ti --name otel otel-cpp- bash +docker cp otel:/ ./ +docker rm -f otel + +docker create -ti --name grpc grpc- bash +docker cp grpc:/ ./ +docker rm -f grpc + +docker create -ti --name thrift thrift- bash +docker cp thrift:/ ./ +docker rm -f thrift +``` diff --git a/docker/build.sh b/docker/build.sh new file mode 100644 index 0000000000..53773b739f --- /dev/null +++ b/docker/build.sh @@ -0,0 +1,86 @@ +#!/bin/bash + +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +set -o errexit +set -o nounset +set -o pipefail + +Help() +{ + # Display Help + echo "Add description of the script functions here." + echo + echo "Syntax: scriptTemplate [-b|o|g|j]" + echo "options:" + echo "b Base image" + echo "o OpenTelemetry-cpp git tag" + echo "h Print Help." + echo "g gRPC git tag" + echo "t thrift version" + echo "j Parallel jobs" + echo + echo "how to use:" + echo + echo "docker create -ti --name otel otel-cpp- bash" + echo "docker cp otel:/ ./" + echo "docker rm -f otel" + echo + echo "or:" + echo + echo "COPY --from=otel-cpp- /usr" +} + +base_image=${base_image:="alpine"} +grpc_git_tag=${grpc_git_tag:="v1.43.2"} +thrift_version=${thrift_version:="0.14.1"} +otel_git_tag=${otel_git_tag:="v1.3.0"} +cores=${cores:=1} + +while getopts ":h:b:o:g:j:t:" option; do + case $option in + h) # display Help + Help + exit;; + b) # base image + base_image=$OPTARG + ;; + o) # OpenTelemetry-cpp git tag + otel_git_tag=$OPTARG + ;; + g) # gRPC git tag + grpc_git_tag=$OPTARG + ;; + t) # thrfit version + thrift_version=$OPTARG + ;; + j) # number of cores + cores=$OPTARG + ;; + \?) + Help + exit;; + esac +done + +docker build -t base-${base_image}-dev -f Dockerfile.${base_image}.base . + +pushd grpc/ +docker build --build-arg BASE_IMAGE=base-${base_image}-dev \ + --build-arg GRPC_GIT_TAG=${grpc_git_tag} \ + --build-arg CORES=${cores} \ + -t grpc-${base_image} -f Dockerfile . +popd + +pushd thrift/ +docker build --build-arg BASE_IMAGE=base-${base_image}-dev \ + --build-arg THRIFT_VERSION=${thrift_version} \ + --build-arg CORES=${cores} \ + -t thrift-${base_image} -f Dockerfile . +popd + +docker build --build-arg BASE_IMAGE=${base_image} \ + --build-arg CORES=${cores} \ + --build-arg OTEL_GIT_TAG=${otel_git_tag} \ + -t otel-cpp-${base_image} -f Dockerfile . diff --git a/docker/grpc/CMakeLists.txt b/docker/grpc/CMakeLists.txt new file mode 100644 index 0000000000..8cb69cc6c3 --- /dev/null +++ b/docker/grpc/CMakeLists.txt @@ -0,0 +1,84 @@ +cmake_minimum_required(VERSION 3.11 FATAL_ERROR) + +project( + dependencies + LANGUAGES CXX + VERSION 0.0.1) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_FLAGS "-O2") + +set(CMAKE_BUILD_TYPE + Release + CACHE STRING "Build type" FORCE) + +include(GNUInstallDirs) + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY + ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY + ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY + ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}) + +set(INSTALL_LIBDIR + ${CMAKE_INSTALL_LIBDIR} + CACHE PATH "directory for libraries") +set(INSTALL_BINDIR + ${CMAKE_INSTALL_BINDIR} + CACHE PATH "directory for executables") +set(INSTALL_INCLUDEDIR + ${CMAKE_INSTALL_INCLUDEDIR} + CACHE PATH "directory for header files") + +set(DEF_INSTALL_CMAKEDIR share/cmake/${PROJECT_NAME}) +set(INSTALL_CMAKEDIR + ${DEF_INSTALL_CMAKEDIR} + CACHE PATH "directory for CMake files") + +set_property(DIRECTORY PROPERTY EP_BASE ${CMAKE_BINARY_DIR}/subs) + +set(STAGED_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/stage) +message(STATUS "${PROJECT_NAME} staged install: ${STAGED_INSTALL_PREFIX}") + +find_package(OpenSSL REQUIRED) +message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}") +message("OpenSSL libraries: ${OPENSSL_LIBRARIES}") + +set(GRPC_GIT_TAG + "v1.45.2" + CACHE STRING "gRPC version") + +include(ExternalProject) +ExternalProject_Add( + grpc + GIT_REPOSITORY https://github.com/grpc/grpc.git + GIT_TAG ${GRPC_GIT_TAG} + GIT_SHALLOW 1 + UPDATE_COMMAND "" + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DgRPC_SSL_PROVIDER=package + -DOPENSSL_ROOT_DIR=OpenSSL + -DgRPC_BUILD_TESTS=OFF + -DBUILD_SHARED_LIBS=ON + -DgRPC_BUILD_GRPC_NODE_PLUGIN=OFF + -DgRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN=OFF + -DgRPC_BUILD_GRPC_PHP_PLUGIN=OFF + -DgRPC_BUILD_GRPC_PHP_PLUGIN=OFF + -DgRPC_BUILD_GRPC_PYTHON_PLUGIN=OFF + -DgRPC_BUILD_GRPC_RUBY_PLUGIN=OFF + CMAKE_CACHE_ARGS -DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS} + TEST_AFTER_INSTALL 0 + DOWNLOAD_NO_PROGRESS 1 + LOG_CONFIGURE 1 + LOG_BUILD 0 + LOG_INSTALL 1) + +install( + DIRECTORY ${STAGED_INSTALL_PREFIX}/ + DESTINATION . + USE_SOURCE_PERMISSIONS) diff --git a/docker/grpc/Dockerfile b/docker/grpc/Dockerfile new file mode 100644 index 0000000000..fee3082b2d --- /dev/null +++ b/docker/grpc/Dockerfile @@ -0,0 +1,21 @@ +ARG BASE_IMAGE=ubuntu:latest +FROM ${BASE_IMAGE} AS grpc + +ARG CORES=${nproc} +ARG GRPC_GIT_TAG=v1.45.2 + +RUN mkdir mkdir -p /opt/third_party/grpc + +WORKDIR /opt/third_party/grpc + +ADD CMakeLists.txt /opt/third_party/grpc + +RUN mkdir build \ + && cd build \ + && cmake -DCMAKE_INSTALL_PREFIX=/opt/third_party/install \ + -DGRPC_GIT_TAG=${GRPC_GIT_TAG} /opt/third_party/grpc \ + && cmake --build . -j ${CORES} --target install + +FROM scratch as final + +COPY --from=grpc /opt/third_party/install / diff --git a/docker/thrift/CMakeLists.txt b/docker/thrift/CMakeLists.txt new file mode 100644 index 0000000000..0028dc48c7 --- /dev/null +++ b/docker/thrift/CMakeLists.txt @@ -0,0 +1,87 @@ +cmake_minimum_required(VERSION 3.11 FATAL_ERROR) + +project( + dependencies + LANGUAGES CXX + VERSION 0.0.1) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_FLAGS "-O2") + +set(CMAKE_BUILD_TYPE + Release + CACHE STRING "Build type" FORCE) + +include(GNUInstallDirs) + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY + ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY + ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY + ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}) + +set(INSTALL_LIBDIR + ${CMAKE_INSTALL_LIBDIR} + CACHE PATH "directory for libraries") +set(INSTALL_BINDIR + ${CMAKE_INSTALL_BINDIR} + CACHE PATH "directory for executables") +set(INSTALL_INCLUDEDIR + ${CMAKE_INSTALL_INCLUDEDIR} + CACHE PATH "directory for header files") + +set(DEF_INSTALL_CMAKEDIR share/cmake/${PROJECT_NAME}) +set(INSTALL_CMAKEDIR + ${DEF_INSTALL_CMAKEDIR} + CACHE PATH "directory for CMake files") + +set_property(DIRECTORY PROPERTY EP_BASE ${CMAKE_BINARY_DIR}/subs) + +set(STAGED_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/stage) +message(STATUS "${PROJECT_NAME} staged install: ${STAGED_INSTALL_PREFIX}") + +find_package(OpenSSL REQUIRED) +message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}") +message("OpenSSL libraries: ${OPENSSL_LIBRARIES}") + +set(THRIFT_VERSION + "0.14.1" + CACHE STRING "thrift version") + +include(ExternalProject) +ExternalProject_Add( + thrift + URL https://github.com/apache/thrift/archive/refs/tags/v${THRIFT_VERSION}.tar.gz + UPDATE_COMMAND "" + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE + -DBUILD_COMPILER=OFF + -DBUILD_CPP=ON + -DBUILD_LIBRARIES=ON + -DBUILD_NODEJS=OFF + -DBUILD_PYTHON=OFF + -DBUILD_JAVASCRIPT=OFF + -DBUILD_C_GLIB=OFF + -DBUILD_JAVA=OFF + -DBUILD_TESTING=OFF + -DBUILD_TUTORIALS=OFF + -DWITH_STDTHREADS=ON + -DWITH_BOOSTTHREADS=OFF + -DWITH_BOOST_FUNCTIONAL=OFF + -DWITH_BOOST_SMART_PTR=OFF + CMAKE_CACHE_ARGS -DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS} + TEST_AFTER_INSTALL 0 + DOWNLOAD_NO_PROGRESS 1 + LOG_CONFIGURE 1 + LOG_BUILD 0 + LOG_INSTALL 1) + +install( + DIRECTORY ${STAGED_INSTALL_PREFIX}/ + DESTINATION . + USE_SOURCE_PERMISSIONS) diff --git a/docker/thrift/Dockerfile b/docker/thrift/Dockerfile new file mode 100644 index 0000000000..2c57199f3f --- /dev/null +++ b/docker/thrift/Dockerfile @@ -0,0 +1,21 @@ +ARG BASE_IMAGE=ubuntu:latest +FROM ${BASE_IMAGE} AS thrift + +ARG CORES=${nproc} +ARG THRIFT_VERSION=0.14.1 + +RUN mkdir mkdir -p /opt/third_party/thrift + +WORKDIR /opt/third_party/th + +ADD CMakeLists.txt /opt/third_party/thrift + +RUN mkdir build \ + && cd build \ + && cmake -DCMAKE_INSTALL_PREFIX=/opt/third_party/install \ + -DTHRIFT_VERSION=${THRIFT_VERSION} /opt/third_party/thrift \ + && cmake --build . -j ${CORES} --target install + +FROM scratch as final + +COPY --from=thrift /opt/third_party/install / diff --git a/docs/building-with-vcpkg.md b/docs/building-with-vcpkg.md index 7586486e88..aace95460c 100644 --- a/docs/building-with-vcpkg.md +++ b/docs/building-with-vcpkg.md @@ -13,7 +13,7 @@ source release of OpenTelemetry C++ SDK. The following command can be used to install the public open source release: ```console -vcpkg install opentelemetry +vcpkg install opentelemetry-cpp ``` That's it! The package should be compiled for the current OS. diff --git a/docs/public/conf.py b/docs/public/conf.py index 910cfc6346..ff95a16b3f 100644 --- a/docs/public/conf.py +++ b/docs/public/conf.py @@ -21,7 +21,7 @@ author = 'OpenTelemetry authors' # The full version, including alpha/beta/rc tags -release = '1.3.0' +release = '1.4.0' # Run sphinx on subprojects and copy output # ----------------------------------------- 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/examples/common/metrics_foo_library/foo_library.cc b/examples/common/metrics_foo_library/foo_library.cc index cd15adad5b..da8a99d91c 100644 --- a/examples/common/metrics_foo_library/foo_library.cc +++ b/examples/common/metrics_foo_library/foo_library.cc @@ -6,6 +6,8 @@ # include # include # include +# include +# include "opentelemetry/context/context.h" # include "opentelemetry/metrics/provider.h" namespace nostd = opentelemetry::nostd; @@ -23,6 +25,18 @@ std::map get_random_attr() return std::map{labels[rand() % (labels.size() - 1)], labels[rand() % (labels.size() - 1)]}; } + +class MeasurementFetcher +{ +public: + static void Fetcher(opentelemetry::metrics::ObserverResult &observer_result) + { + double val = (rand() % 700) + 1.1; + std::map labels = get_random_attr(); + auto labelkv = opentelemetry::common::KeyValueIterableView{labels}; + observer_result.Observe(val /*, labelkv*/); + } +}; } // namespace void foo_library::counter_example(const std::string &name) @@ -40,6 +54,18 @@ void foo_library::counter_example(const std::string &name) } } +void foo_library::observable_counter_example(const std::string &name) +{ + std::string counter_name = name + "_observable_counter"; + auto provider = metrics_api::Provider::GetMeterProvider(); + nostd::shared_ptr meter = provider->GetMeter(name, "1.2.0"); + meter->CreateDoubleObservableCounter(counter_name, MeasurementFetcher::Fetcher); + while (true) + { + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + } +} + void foo_library::histogram_example(const std::string &name) { std::string histogram_name = name + "_histogram"; diff --git a/examples/common/metrics_foo_library/foo_library.h b/examples/common/metrics_foo_library/foo_library.h index 73cd30d2d5..2f84bcc34f 100644 --- a/examples/common/metrics_foo_library/foo_library.h +++ b/examples/common/metrics_foo_library/foo_library.h @@ -10,5 +10,6 @@ class foo_library public: static void counter_example(const std::string &name); static void histogram_example(const std::string &name); + static void observable_counter_example(const std::string &name); }; #endif diff --git a/examples/metrics_simple/README.md b/examples/metrics_simple/README.md index 41d683c782..b2c5dc0a74 100644 --- a/examples/metrics_simple/README.md +++ b/examples/metrics_simple/README.md @@ -1,83 +1,72 @@ # Simple Metrics Example -In this example, the application in `main.cc` initializes the metrics pipeline -and shows 3 different ways of updating instrument values. Here are more detailed -explanations of each part. +This example initializes the metrics pipeline with 2 different instrument types. +Here are more detailed explanations of each part. -1: Initialize a MeterProvider. We will use this to obtain Meter objects in the -future. - -`auto provider = shared_ptr(new MeterProvider);` - -2: Set the MeterProvider as the default instance for the library. This ensures -that we will have access to the same MeterProvider across our application. - -`Provider::SetMeterProvider(provider);` - -3: Obtain a meter from this meter provider. Every Meter pointer returned by the -MeterProvider points to the same Meter. This means that the Meter will be able -to combine metrics captured from different functions without having to -constantly pass the Meter around the library. - -`shared_ptr meter = provider→GetMeter("Test");` - -4: Initialize an exporter and processor. In this case, we initialize an OStream -Exporter which will print to stdout by default. The Processor is an -UngroupedProcessor which doesn’t filter or group captured metrics in any way. -The false parameter indicates that this processor will send metric deltas rather -than metric cumulatives. +1: Initialize an exporter and a reader. In this case, we initialize an OStream +Exporter which will print to stdout by default. +The reader periodically collects metrics from the collector and exports them. ```cpp -unique_ptr exporter = unique_ptr(new OStreamMetricsExporter); -shared_ptr processor = shared_ptr(new UngroupedMetricsProcessor(false)); +std::unique_ptr exporter{new exportermetrics::OStreamMetricExporter}; +std::unique_ptr reader{ + new metric_sdk::PeriodicExportingMetricReader(std::move(exporter), options)}; ``` -5: Pass the meter, exporter, and processor into the controller. Since this is a -push controller, a collection interval parameter (in seconds) is also taken. At -each collection interval, the controller will request data from all of the -instruments in the code and export them. Start the controller to begin the -metrics pipeline. +2: Initialize a MeterProvider and add the reader. +We will use this to obtain Meter objects in the future. -`metrics_sdk::PushController controller(meter, std::move(exporter), processor, -5);` `controller.start();` +```cpp +auto provider = std::shared_ptr(new opentelemetry::metrics::MeterProvider()); +auto p = std::static_pointer_cast(provider); +p->AddMetricReader(std::move(reader)); +``` -6: Instrument code with synchronous and asynchronous instrument. These -instruments can be placed in areas of interest to collect metrics and are -created by the meter. Synchronous instruments are updated whenever the user -desires with a value and label set. Calling add on a counter instrument for -example will increase its value. Asynchronous instruments can be updated the -same way, but are intended to receive updates from a callback function. The -callback below observes a value of 1. The user never has to call this function -as it is automatically called by the controller. +3: Create and add a view to the provider. ```cpp -// Observer callback function -void SumObserverCallback(metrics_api::ObserverResult result){ - std::map labels = {{"key", "value"}}; - auto labelkv = common::KeyValueIterableView{labels}; - result.observe(1,labelkv); -} +std::unique_ptr instrument_selector{ + new metric_sdk::InstrumentSelector(metric_sdk::InstrumentType::kCounter, "name_counter")}; +std::unique_ptr meter_selector{ + new metric_sdk::MeterSelector(name, version, schema)}; +std::unique_ptr sum_view{ + new metric_sdk::View{name, "description", metric_sdk::AggregationType::kSum}}; +p->AddView(std::move(instrument_selector), std::move(meter_selector), std::move(sum_view)); +``` -// Create new instruments -auto ctr= meter->NewIntCounter("Counter","none", "none", true); -auto obs= meter->NewIntSumObserver("Counter","none", "none", true, &SumObserverCallback); +4: Then create a +[Counter](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#counter) +instrument from it. Every Meter pointer returned by the +MeterProvider points to the same Meter. This means that the Meter will be able +to combine metrics captured from different functions without having to +constantly pass the Meter around the library. +```cpp +nostd::shared_ptr meter = provider->GetMeter(name, "1.2.0"); +auto double_counter = meter->CreateDoubleCounter(counter_name); // Create a label set which annotates metric values std::map labels = {{"key", "value"}}; auto labelkv = common::KeyValueIterableView{labels}; - -// Capture data from instruments. Note that the asynchronous instrument is updates -// automatically though its callback at the collection interval. Additional measurments -// can be made through calls to its observe function. -ctr->add(5, labelkv); - +double_counter->Add(val, labelkv); ``` -7: Stop the controller once the program finished. This ensures that any metrics -inside the pipeline are properly exported. Otherwise, some metrics may be -destroyed in cleanup. +5: To use histogram instrument, a view with proper `InstrumentType` and `AggregationType` +has to be added to the provider. -`controller.stop();` +```cpp +std::unique_ptr histogram_instrument_selector{ + new metric_sdk::InstrumentSelector(metric_sdk::InstrumentType::kHistogram, "histogram_name")}; +std::unique_ptr histogram_meter_selector{ + new metric_sdk::MeterSelector(name, version, schema)}; +std::unique_ptr histogram_view{ + new metric_sdk::View{name, "description", metric_sdk::AggregationType::kHistogram}}; +p->AddView(std::move(histogram_instrument_selector), std::move(histogram_meter_selector), + std::move(histogram_view)); + +auto histogram_counter = meter->CreateDoubleHistogram("histogram_name"); +auto context = opentelemetry::context::Context{}; +histogram_counter->Record(val, labelkv, context); +``` See [CONTRIBUTING.md](../../CONTRIBUTING.md) for instructions on building and running the example. diff --git a/examples/metrics_simple/metrics_ostream.cc b/examples/metrics_simple/metrics_ostream.cc index ebb8b34b8a..585856f91f 100644 --- a/examples/metrics_simple/metrics_ostream.cc +++ b/examples/metrics_simple/metrics_ostream.cc @@ -54,6 +54,18 @@ void initMetrics(const std::string &name) new metric_sdk::View{name, "description", metric_sdk::AggregationType::kSum}}; p->AddView(std::move(instrument_selector), std::move(meter_selector), std::move(sum_view)); + // observable counter view + std::string observable_counter_name = name + "_observable_counter"; + std::unique_ptr observable_instrument_selector{ + new metric_sdk::InstrumentSelector(metric_sdk::InstrumentType::kObservableCounter, + observable_counter_name)}; + std::unique_ptr observable_meter_selector{ + new metric_sdk::MeterSelector(name, version, schema)}; + std::unique_ptr observable_sum_view{ + new metric_sdk::View{name, "description", metric_sdk::AggregationType::kSum}}; + p->AddView(std::move(observable_instrument_selector), std::move(observable_meter_selector), + std::move(observable_sum_view)); + // histogram view std::string histogram_name = name + "_histogram"; std::unique_ptr histogram_instrument_selector{ @@ -83,6 +95,10 @@ int main(int argc, char **argv) { foo_library::counter_example(name); } + else if (example_type == "observable_counter") + { + foo_library::observable_counter_example(name); + } else if (example_type == "histogram") { foo_library::histogram_example(name); @@ -90,8 +106,11 @@ int main(int argc, char **argv) else { std::thread counter_example{&foo_library::counter_example, name}; + std::thread observable_counter_example{&foo_library::observable_counter_example, name}; std::thread histogram_example{&foo_library::histogram_example, name}; + counter_example.join(); + observable_counter_example.join(); histogram_example.join(); } } diff --git a/examples/prometheus/README.md b/examples/prometheus/README.md new file mode 100644 index 0000000000..d7e284a0ec --- /dev/null +++ b/examples/prometheus/README.md @@ -0,0 +1,208 @@ +# Getting Started with Prometheus and Grafana + +- [Export metrics from the application](#export-metrics-from-the-application) + - [Check results in the browser](#check-results-in-the-browser) +- [Collect metrics using Prometheus](#collect-metrics-using-prometheus) + - [Configuration](#configuration) + - [Start Prometheus](#start-prometheus) + - [View results in Prometheus](#view-results-in-prometheus) +- [Explore metrics using Grafana](#explore-metrics-using-grafana) +- [Learn more](#learn-more) + +## Export metrics from the application + +It is highly recommended to go over the [ostream-metrics](../metrics_simple/README.md) +doc before following along this document. + +Run the application with: + +```sh +bazel run //examples/prometheus:prometheus_example +``` + +The main difference between the [ostream-metrics](../metrics_simple/README.md) +example with this one is that the line below is replaced: + +```cpp +std::unique_ptr exporter{ + new exportermetrics::OStreamMetricExporter}; + +``` + +with + +```cpp +std::unique_ptr exporter{ + new metrics_exporter::PrometheusExporter(opts)}; +``` + +OpenTelemetry `PrometheusExporter` will export +data via the endpoint defined by +`metrics_exporter::PrometheusExporterOptions::url`, +which is `http://localhost:9464/` by default. + +```mermaid +graph LR + +subgraph SDK + MeterProvider + MetricReader[PeriodicExportingMetricReader] + PrometheusExporter["PrometheusExporter
(http://localhost:9464/)"] +end + +subgraph API + Instrument["Meter(#quot;prometheus_metric_example#quot;, #quot;1.0#quot;)
Histogram(#quot;prometheus_metric_example_histogram#quot;)"] +end + +Instrument --> | Measurements | MeterProvider + +MeterProvider --> | Metrics | MetricReader --> | Pull | PrometheusExporter +``` + +Also, for our learning purpose, we use a while-loop to keep recoring random +values until the program stops. + +```cpp +while (true) +{ + double val = (rand() % 700) + 1.1; + std::map labels = get_random_attr(); + auto labelkv = opentelemetry::common::KeyValueIterableView{labels}; + histogram_counter->Record(val, labelkv, context); + std::this_thread::sleep_for(std::chrono::milliseconds(50)); +} +``` + +### Check results in the browser + +Start the application and keep it running. Now we should be able to see the +metrics at [http://localhost:9464/metrics](http://localhost:9464/metrics) from a +web browser: + +![Browser UI](https://user-images.githubusercontent.com/71217171/168492500-12bd1c99-33ab-4515-a294-17bc349b5d13.png) + +Now, we understand how we can configure `PrometheusExporter` to export metrics. +Next, we are going to learn about how to use Prometheus to collect the metrics. + +## Collect metrics using Prometheus + +Follow the [first steps](https://prometheus.io/docs/introduction/first_steps/) +to download the [latest release](https://prometheus.io/download/) of Prometheus. +It is also possible to use `prom/prometheus` docker image. + +### Configuration + +After downloading, extract it to a local location that's easy to +access. We will find the default Prometheus configuration YAML file in the +folder, named `prometheus.yml`. + +```yaml +global: + scrape_interval: 5s + scrape_timeout: 2s + evaluation_interval: 5s +alerting: + alertmanagers: + - follow_redirects: true + scheme: http + timeout: 5s + api_version: v2 + static_configs: + - targets: [localhost:9464] +scrape_configs: + - job_name: otel + static_configs: + - targets: ['localhost:9464'] +``` + +### Start Prometheus + +Follow the instructions from +[starting-prometheus](https://prometheus.io/docs/introduction/first_steps/#starting-prometheus) +to start the Prometheus server and verify it has been started successfully. + +Please note that we will need pass in `prometheus.yml` file as the argument +or mount as volume: + +```console +./prometheus --config.file=prometheus.yml +# OR: +docker run -p 9090:9090 -v $(pwd):/etc/prometheus --network="host" prom/prometheus +``` + +### View results in Prometheus + +To use the graphical interface for viewing our metrics with Prometheus, navigate +to [http://localhost:9090/graph](http://localhost:9090/graph), +and type `prometheus_metric_example_bucket` in the expression bar of the UI; +finally, click the execute button. + +We should be able to see the following chart from the browser: + +![Prometheus UI](https://user-images.githubusercontent.com/71217171/168492437-f9769db1-6f9e-49c6-8ef0-85f5e1188ba0.png) + +From the legend, we can see that the `instance` name and the `job` name are the +values we have set in `prometheus.yml`. + +Congratulations! + +Now we know how to configure Prometheus server and deploy OpenTelemetry +`PrometheusExporter` to export our metrics. Next, we are going to explore a tool +called Grafana, which has powerful visualizations for the metrics. + +## Explore metrics using Grafana + +[Install Grafana](https://grafana.com/docs/grafana/latest/installation/). + +Start the standalone Grafana server (`grafana-server.exe` or +`./bin/grafana-server`, depending on the operating system). Then, use the +browser to navigate to [http://localhost:3000/](http://localhost:3000/). +It is also possible to run `grafana/grafana` container: + +```sh +docker run -d -p 3000:3000 --network="host" grafana/grafana +``` + +Follow the instructions in the Grafana getting started +[doc](https://grafana.com/docs/grafana/latest/getting-started/getting-started/#step-2-log-in) +to log in. + +After successfully logging in, click on the Configuration icon +on the panel at the left hand side, and click on Prometheus. +Type in the default endpoint of Prometheus as suggested by the UI +as the value for the URI. + +```console +http://localhost:9090 +``` + +Then, click on the Explore icon on the left panel of +the website - we should be able to write some queries to explore our metrics +now! + +Feel free to find some handy PromQL +[here](https://promlabs.com/promql-cheat-sheet/). + +![Grafana +UI](https://user-images.githubusercontent.com/71217171/168492482-047a4429-4854-4b3c-a2dd-4d75362090d5.png) + +```mermaid +graph TD + +subgraph Prometheus + PrometheusScraper + PrometheusDatabase +end + +PrometheusExporter["PrometheusExporter
(listening at #quot;http://localhost:9464/#quot;)"] -->|HTTP GET| PrometheusScraper{{"Prometheus scraper
(polling #quot;http://localhost:9464/metrics#quot; every 5 seconds)"}} +PrometheusScraper --> PrometheusDatabase[("Prometheus TSDB (time series database)")] +PrometheusDatabase -->|http://localhost:9090/graph| PrometheusUI["Browser
(Prometheus Dashboard)"] +PrometheusDatabase -->|http://localhost:9090/api/| Grafana[Grafana Server] +Grafana -->|http://localhost:3000/dashboard| GrafanaUI["Browser
(Grafana Dashboard)"] +``` + +## Learn more + +- [What is Prometheus?](https://prometheus.io/docs/introduction/overview/) +- [Grafana support for + Prometheus](https://prometheus.io/docs/visualization/grafana/#creating-a-prometheus-graph) diff --git a/examples/prometheus/prometheus.yml b/examples/prometheus/prometheus.yml index 3f415d39dc..382854818d 100644 --- a/examples/prometheus/prometheus.yml +++ b/examples/prometheus/prometheus.yml @@ -9,8 +9,8 @@ alerting: timeout: 5s api_version: v2 static_configs: - - targets: [localhost:8080] + - targets: [localhost:9464] scrape_configs: - job_name: otel static_configs: - - targets: ['localhost:8080'] \ No newline at end of file + - targets: ['localhost:9464'] 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 52d42cc5c4..acd507980e 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/src/metric_exporter.cc b/exporters/ostream/src/metric_exporter.cc index bf97db04c2..18e73a310c 100644 --- a/exporters/ostream/src/metric_exporter.cc +++ b/exporters/ostream/src/metric_exporter.cc @@ -96,6 +96,7 @@ void OStreamMetricExporter::printInstrumentationInfoMetricData( { sout_ << "\n start time\t: " << timeToString(record.start_ts) << "\n end time\t: " << timeToString(record.end_ts) + << "\n name\t\t: " << record.instrument_descriptor.name_ << "\n description\t: " << record.instrument_descriptor.description_ << "\n unit\t\t: " << record.instrument_descriptor.unit_; 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/ostream/test/ostream_metric_test.cc b/exporters/ostream/test/ostream_metric_test.cc index 3618d93e7a..82c1be2bc7 100644 --- a/exporters/ostream/test/ostream_metric_test.cc +++ b/exporters/ostream/test/ostream_metric_test.cc @@ -70,6 +70,7 @@ TEST(OStreamMetricsExporter, ExportSumPointData) "\n version\t: 1.2.0" "\n start time\t: Thu Jan 1 00:00:00 1970" "\n end time\t: Thu Jan 1 00:00:00 1970" + "\n name\t\t: library_name" "\n description\t: description" "\n unit\t\t: unit" "\n type\t\t: SumPointData" @@ -128,6 +129,7 @@ TEST(OStreamMetricsExporter, ExportHistogramPointData) "\n version\t: 1.2.0" "\n start time\t: Thu Jan 1 00:00:00 1970" "\n end time\t: Thu Jan 1 00:00:00 1970" + "\n name\t\t: library_name" "\n description\t: description" "\n unit\t\t: unit" "\n type : HistogramPointData" @@ -190,6 +192,7 @@ TEST(OStreamMetricsExporter, ExportLastValuePointData) "\n version\t: 1.2.0" "\n start time\t: Thu Jan 1 00:00:00 1970" "\n end time\t: Thu Jan 1 00:00:00 1970" + "\n name\t\t: library_name" "\n description\t: description" "\n unit\t\t: unit" "\n type : LastValuePointData" @@ -244,6 +247,7 @@ TEST(OStreamMetricsExporter, ExportDropPointData) "\n version\t: 1.2.0" "\n start time\t: Thu Jan 1 00:00:00 1970" "\n end time\t: Thu Jan 1 00:00:00 1970" + "\n name\t\t: library_name" "\n description\t: description" "\n unit\t\t: unit" "\n}\n"; 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 bdeedf95e8..77106f3e47 100644 --- a/exporters/otlp/test/otlp_http_log_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_log_exporter_test.cc @@ -137,15 +137,13 @@ class OtlpHttpLogExporterTestPeer : public ::testing::Test std::shared_ptr 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 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"); @@ -159,7 +157,7 @@ class OtlpHttpLogExporterTestPeer : public ::testing::Test response.Finish(*callback.get()); }); - 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}, @@ -236,15 +234,13 @@ class OtlpHttpLogExporterTestPeer : public ::testing::Test std::shared_ptr 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 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"); @@ -263,7 +259,7 @@ class OtlpHttpLogExporterTestPeer : public ::testing::Test async_finish.detach(); }); - 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}, @@ -335,10 +331,9 @@ class OtlpHttpLogExporterTestPeer : public ::testing::Test 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; @@ -358,7 +353,7 @@ class OtlpHttpLogExporterTestPeer : public ::testing::Test response.Finish(*callback.get()); }); - 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}, @@ -431,10 +426,9 @@ class OtlpHttpLogExporterTestPeer : public ::testing::Test 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; @@ -458,7 +452,7 @@ class OtlpHttpLogExporterTestPeer : public ::testing::Test async_finish.detach(); }); - 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_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/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter.h b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter.h index 151244928f..59ef1a11ad 100644 --- a/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter.h +++ b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter.h @@ -28,10 +28,10 @@ namespace exporter namespace metrics { -inline const std::string GetOtlpDefaultHttpEndpoint() +inline const std::string GetPrometheusDefaultHttpEndpoint() { constexpr char kPrometheusEndpointEnv[] = "PROMETHEUS_EXPORTER_ENDPOINT"; - constexpr char kPrometheusEndpointDefault[] = "localhost:8080"; + constexpr char kPrometheusEndpointDefault[] = "localhost:9464"; auto endpoint = opentelemetry::sdk::common::GetEnvironmentVariable(kPrometheusEndpointEnv); return endpoint.size() ? endpoint : kPrometheusEndpointDefault; @@ -43,7 +43,7 @@ inline const std::string GetOtlpDefaultHttpEndpoint() struct PrometheusExporterOptions { // The endpoint the Prometheus backend can collect metrics from - std::string url = GetOtlpDefaultHttpEndpoint(); + std::string url = GetPrometheusDefaultHttpEndpoint(); }; class PrometheusExporter : public sdk::metrics::MetricExporter diff --git a/sdk/include/opentelemetry/sdk/common/global_log_handler.h b/sdk/include/opentelemetry/sdk/common/global_log_handler.h index 06bbd30f7d..612d21eca5 100644 --- a/sdk/include/opentelemetry/sdk/common/global_log_handler.h +++ b/sdk/include/opentelemetry/sdk/common/global_log_handler.h @@ -236,9 +236,9 @@ OPENTELEMETRY_END_NAMESPACE # define OTEL_INTERNAL_LOG_INFO_2_ARGS(message, attributes) \ OTEL_INTERNAL_LOG_DISPATCH(opentelemetry::sdk::common::internal_log::LogLevel::Info, message, \ attributes) -# define OTEL_INTERNAL_LOG_INFO_MACRO(...) \ - OTEL_INTERNAL_LOG_GET_3RD_ARG(__VA_ARGS__, OTEL_INTERNAL_LOG_ERROR_2_ARGS, \ - OTEL_INTERNAL_LOG_ERROR_1_ARGS) +# define OTEL_INTERNAL_LOG_INFO_MACRO(...) \ + OTEL_INTERNAL_LOG_GET_3RD_ARG(__VA_ARGS__, OTEL_INTERNAL_LOG_INFO_2_ARGS, \ + OTEL_INTERNAL_LOG_INFO_1_ARGS) # define OTEL_INTERNAL_LOG_INFO(...) OTEL_INTERNAL_LOG_INFO_MACRO(__VA_ARGS__)(__VA_ARGS__) #else # define OTEL_INTERNAL_LOG_INFO(...) 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/include/opentelemetry/sdk/metrics/meter.h b/sdk/include/opentelemetry/sdk/metrics/meter.h index 4a6ea26aeb..9d9595f660 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter.h @@ -8,6 +8,8 @@ # include "opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h" # include "opentelemetry/sdk/metrics/instruments.h" # include "opentelemetry/sdk/metrics/meter_context.h" +# include "opentelemetry/sdk/metrics/state/async_metric_storage.h" + # include "opentelemetry/sdk/resource/resource.h" # include "opentelemetry/version.h" @@ -40,18 +42,17 @@ class Meter final : public opentelemetry::metrics::Meter nostd::string_view description = "", nostd::string_view unit = "") noexcept override; - nostd::shared_ptr> CreateLongObservableCounter( + void CreateLongObservableCounter(nostd::string_view name, + void (*callback)(opentelemetry::metrics::ObserverResult &), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override; + + void CreateDoubleObservableCounter( nostd::string_view name, - void (*callback)(opentelemetry::metrics::ObserverResult &), + void (*callback)(opentelemetry::metrics::ObserverResult &), nostd::string_view description = "", nostd::string_view unit = "") noexcept override; - nostd::shared_ptr> - CreateDoubleObservableCounter(nostd::string_view name, - void (*callback)(opentelemetry::metrics::ObserverResult &), - nostd::string_view description = "", - nostd::string_view unit = "1") noexcept override; - nostd::shared_ptr> CreateLongHistogram( nostd::string_view name, nostd::string_view description = "", @@ -62,13 +63,12 @@ class Meter final : public opentelemetry::metrics::Meter nostd::string_view description = "", nostd::string_view unit = "") noexcept override; - nostd::shared_ptr> CreateLongObservableGauge( - nostd::string_view name, - void (*callback)(opentelemetry::metrics::ObserverResult &), - nostd::string_view description = "", - nostd::string_view unit = "") noexcept override; + void CreateLongObservableGauge(nostd::string_view name, + void (*callback)(opentelemetry::metrics::ObserverResult &), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override; - nostd::shared_ptr> CreateDoubleObservableGauge( + void CreateDoubleObservableGauge( nostd::string_view name, void (*callback)(opentelemetry::metrics::ObserverResult &), nostd::string_view description = "", @@ -84,15 +84,13 @@ class Meter final : public opentelemetry::metrics::Meter nostd::string_view description = "", nostd::string_view unit = "") noexcept override; - nostd::shared_ptr> - CreateLongObservableUpDownCounter( + void CreateLongObservableUpDownCounter( nostd::string_view name, void (*callback)(opentelemetry::metrics::ObserverResult &), nostd::string_view description = "", nostd::string_view unit = "") noexcept override; - nostd::shared_ptr> - CreateDoubleObservableUpDownCounter( + void CreateDoubleObservableUpDownCounter( nostd::string_view name, void (*callback)(opentelemetry::metrics::ObserverResult &), nostd::string_view description = "", @@ -116,6 +114,25 @@ class Meter final : public opentelemetry::metrics::Meter std::unique_ptr RegisterMetricStorage( InstrumentDescriptor &instrument_descriptor); + + template + void RegisterAsyncMetricStorage(InstrumentDescriptor &instrument_descriptor, + void (*callback)(opentelemetry::metrics::ObserverResult &)) + { + auto view_registry = meter_context_->GetViewRegistry(); + auto success = view_registry->FindViews( + instrument_descriptor, *instrumentation_library_, + [this, &instrument_descriptor, callback](const View &view) { + auto view_instr_desc = instrument_descriptor; + view_instr_desc.name_ = view.GetName(); + view_instr_desc.description_ = view.GetDescription(); + auto storage = std::shared_ptr>( + new AsyncMetricStorage(view_instr_desc, view.GetAggregationType(), callback, + &view.GetAttributesProcessor())); + storage_registry_[instrument_descriptor.name_] = storage; + return true; + }); + } }; } // namespace metrics } // namespace sdk diff --git a/sdk/include/opentelemetry/sdk/version/version.h b/sdk/include/opentelemetry/sdk/version/version.h index 155cba3f87..65c3c826ca 100644 --- a/sdk/include/opentelemetry/sdk/version/version.h +++ b/sdk/include/opentelemetry/sdk/version/version.h @@ -5,7 +5,7 @@ #include "opentelemetry/detail/preprocessor.h" -#define OPENTELEMETRY_SDK_VERSION "1.3.0" +#define OPENTELEMETRY_SDK_VERSION "1.4.0" #include "opentelemetry/version.h" diff --git a/sdk/src/logs/logger.cc b/sdk/src/logs/logger.cc index 0222b786bc..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()); @@ -99,7 +97,7 @@ void Logger::Log(opentelemetry::logs::Severity severity, } else if (span_context.span_id().IsValid()) { - recordable->SetSpanId(span_id); + recordable->SetSpanId(span_context.span_id()); } // TraceFlags 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/src/metrics/meter.cc b/sdk/src/metrics/meter.cc index ce638c22e6..30725bdccf 100644 --- a/sdk/src/metrics/meter.cc +++ b/sdk/src/metrics/meter.cc @@ -57,24 +57,28 @@ nostd::shared_ptr> Meter::CreateDoubleCounter( new DoubleCounter(instrument_descriptor, std::move(storage))}; } -nostd::shared_ptr> Meter::CreateLongObservableCounter( - nostd::string_view name, - void (*callback)(metrics::ObserverResult &), - nostd::string_view description, - nostd::string_view unit) noexcept +void Meter::CreateLongObservableCounter(nostd::string_view name, + void (*callback)(metrics::ObserverResult &), + nostd::string_view description, + nostd::string_view unit) noexcept { - return nostd::shared_ptr>{ - new LongObservableCounter(name, callback, description, unit)}; + InstrumentDescriptor instrument_descriptor = { + std::string{name.data(), name.size()}, std::string{description.data(), description.size()}, + std::string{unit.data(), unit.size()}, InstrumentType::kObservableCounter, + InstrumentValueType::kLong}; + RegisterAsyncMetricStorage(instrument_descriptor, callback); } -nostd::shared_ptr> Meter::CreateDoubleObservableCounter( - nostd::string_view name, - void (*callback)(metrics::ObserverResult &), - nostd::string_view description, - nostd::string_view unit) noexcept +void Meter::CreateDoubleObservableCounter(nostd::string_view name, + void (*callback)(metrics::ObserverResult &), + nostd::string_view description, + nostd::string_view unit) noexcept { - return nostd::shared_ptr>{ - new DoubleObservableCounter(name, callback, description, unit)}; + InstrumentDescriptor instrument_descriptor = { + std::string{name.data(), name.size()}, std::string{description.data(), description.size()}, + std::string{unit.data(), unit.size()}, InstrumentType::kObservableCounter, + InstrumentValueType::kDouble}; + RegisterAsyncMetricStorage(instrument_descriptor, callback); } nostd::shared_ptr> Meter::CreateLongHistogram( @@ -105,24 +109,28 @@ nostd::shared_ptr> Meter::CreateDoubleHistogram( new DoubleHistogram(instrument_descriptor, std::move(storage))}; } -nostd::shared_ptr> Meter::CreateLongObservableGauge( - nostd::string_view name, - void (*callback)(metrics::ObserverResult &), - nostd::string_view description, - nostd::string_view unit) noexcept +void Meter::CreateLongObservableGauge(nostd::string_view name, + void (*callback)(metrics::ObserverResult &), + nostd::string_view description, + nostd::string_view unit) noexcept { - return nostd::shared_ptr>{ - new LongObservableGauge(name, callback, description, unit)}; + InstrumentDescriptor instrument_descriptor = { + std::string{name.data(), name.size()}, std::string{description.data(), description.size()}, + std::string{unit.data(), unit.size()}, InstrumentType::kObservableGauge, + InstrumentValueType::kLong}; + RegisterAsyncMetricStorage(instrument_descriptor, callback); } -nostd::shared_ptr> Meter::CreateDoubleObservableGauge( - nostd::string_view name, - void (*callback)(metrics::ObserverResult &), - nostd::string_view description, - nostd::string_view unit) noexcept +void Meter::CreateDoubleObservableGauge(nostd::string_view name, + void (*callback)(metrics::ObserverResult &), + nostd::string_view description, + nostd::string_view unit) noexcept { - return nostd::shared_ptr>{ - new DoubleObservableGauge(name, callback, description, unit)}; + InstrumentDescriptor instrument_descriptor = { + std::string{name.data(), name.size()}, std::string{description.data(), description.size()}, + std::string{unit.data(), unit.size()}, InstrumentType::kObservableGauge, + InstrumentValueType::kDouble}; + RegisterAsyncMetricStorage(instrument_descriptor, callback); } nostd::shared_ptr> Meter::CreateLongUpDownCounter( @@ -153,24 +161,28 @@ nostd::shared_ptr> Meter::CreateDoubleUpDownCount new DoubleUpDownCounter(instrument_descriptor, std::move(storage))}; } -nostd::shared_ptr> Meter::CreateLongObservableUpDownCounter( - nostd::string_view name, - void (*callback)(metrics::ObserverResult &), - nostd::string_view description, - nostd::string_view unit) noexcept +void Meter::CreateLongObservableUpDownCounter(nostd::string_view name, + void (*callback)(metrics::ObserverResult &), + nostd::string_view description, + nostd::string_view unit) noexcept { - return nostd::shared_ptr>{ - new LongObservableUpDownCounter(name, callback, description, unit)}; + InstrumentDescriptor instrument_descriptor = { + std::string{name.data(), name.size()}, std::string{description.data(), description.size()}, + std::string{unit.data(), unit.size()}, InstrumentType::kObservableUpDownCounter, + InstrumentValueType::kLong}; + RegisterAsyncMetricStorage(instrument_descriptor, callback); } -nostd::shared_ptr> -Meter::CreateDoubleObservableUpDownCounter(nostd::string_view name, - void (*callback)(metrics::ObserverResult &), - nostd::string_view description, - nostd::string_view unit) noexcept +void Meter::CreateDoubleObservableUpDownCounter(nostd::string_view name, + void (*callback)(metrics::ObserverResult &), + nostd::string_view description, + nostd::string_view unit) noexcept { - return nostd::shared_ptr>{ - new DoubleObservableUpDownCounter(name, callback, description, unit)}; + InstrumentDescriptor instrument_descriptor = { + std::string{name.data(), name.size()}, std::string{description.data(), description.size()}, + std::string{unit.data(), unit.size()}, InstrumentType::kObservableUpDownCounter, + InstrumentValueType::kDouble}; + RegisterAsyncMetricStorage(instrument_descriptor, callback); } const sdk::instrumentationlibrary::InstrumentationLibrary *Meter::GetInstrumentationLibrary() diff --git a/sdk/src/trace/async_batch_span_processor.cc b/sdk/src/trace/async_batch_span_processor.cc index 4f7a7c957a..e28fe34e70 100644 --- a/sdk/src/trace/async_batch_span_processor.cc +++ b/sdk/src/trace/async_batch_span_processor.cc @@ -20,8 +20,8 @@ namespace trace AsyncBatchSpanProcessor::AsyncBatchSpanProcessor(std::unique_ptr &&exporter, const AsyncBatchSpanProcessorOptions &options) : BatchSpanProcessor(std::move(exporter), options), - max_export_async_(options.max_export_async), - export_data_storage_(std::make_shared()) + export_data_storage_(std::make_shared()), + max_export_async_(options.max_export_async) { export_data_storage_->export_ids_flag.resize(max_export_async_, true); for (size_t i = 1; i <= max_export_async_; i++) diff --git a/sdk/src/version/version.cc b/sdk/src/version/version.cc index a153196514..9303a305aa 100644 --- a/sdk/src/version/version.cc +++ b/sdk/src/version/version.cc @@ -9,7 +9,7 @@ namespace sdk namespace version { const int MAJOR_VERSION = 1; -const int MINOR_VERSION = 3; +const int MINOR_VERSION = 4; const int PATCH_VERSION = 0; const char *PRE_RELEASE = ""; const char *BUILD_METADATA = ""; diff --git a/sdk/test/common/global_log_handle_test.cc b/sdk/test/common/global_log_handle_test.cc index 9c24b0234e..a38bdc8728 100644 --- a/sdk/test/common/global_log_handle_test.cc +++ b/sdk/test/common/global_log_handle_test.cc @@ -24,6 +24,14 @@ class CustomLogHandler : public opentelemetry::sdk::common::internal_log::LogHan { EXPECT_EQ(0, strncmp(msg, "Error message", 13)); } + else if (level == opentelemetry::sdk::common::internal_log::LogLevel::Info) + { + EXPECT_EQ(0, strncmp(msg, "Info message", 12)); + } + else if (level == opentelemetry::sdk::common::internal_log::LogLevel::Warning) + { + EXPECT_EQ(0, strncmp(msg, "Warning message", 15)); + } ++count; } @@ -50,7 +58,9 @@ TEST(GlobalLogHandleTest, CustomLogHandler) opentelemetry::sdk::common::internal_log::LogLevel::Debug); OTEL_INTERNAL_LOG_ERROR("Error message"); OTEL_INTERNAL_LOG_DEBUG("Debug message. Headers:", attributes); - EXPECT_EQ(before_count + 3, static_cast(custom_log_handler.get())->count); + OTEL_INTERNAL_LOG_INFO("Info message"); + OTEL_INTERNAL_LOG_WARN("Warning message"); + EXPECT_EQ(before_count + 5, static_cast(custom_log_handler.get())->count); opentelemetry::sdk::common::internal_log::GlobalLogHandler::SetLogHandler(backup_log_handle); opentelemetry::sdk::common::internal_log::GlobalLogHandler::SetLogLevel(backup_log_level); diff --git a/sdk/test/logs/BUILD b/sdk/test/logs/BUILD index c8f051070f..f620eaf613 100644 --- a/sdk/test/logs/BUILD +++ b/sdk/test/logs/BUILD @@ -73,3 +73,18 @@ cc_test( "@com_google_googletest//:gtest_main", ], ) + +cc_test( + name = "async_batch_log_processor_test", + srcs = [ + "async_batch_log_processor_test.cc", + ], + tags = [ + "logs", + "test", + ], + deps = [ + "//sdk/src/logs", + "@com_google_googletest//:gtest_main", + ], +) diff --git a/sdk/test/logs/async_batch_log_processor_test.cc b/sdk/test/logs/async_batch_log_processor_test.cc index dba600b9a7..3c71ce743e 100644 --- a/sdk/test/logs/async_batch_log_processor_test.cc +++ b/sdk/test/logs/async_batch_log_processor_test.cc @@ -169,7 +169,7 @@ TEST_F(AsyncBatchLogProcessorTest, TestAsyncShutdown) 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)); } @@ -185,7 +185,7 @@ TEST_F(AsyncBatchLogProcessorTest, TestAsyncShutdown) // 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 @@ -216,7 +216,7 @@ TEST_F(AsyncBatchLogProcessorTest, TestAsyncShutdownNoCallback) 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)); } @@ -249,7 +249,7 @@ TEST_F(AsyncBatchLogProcessorTest, TestAsyncForceFlush) 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)); } @@ -258,14 +258,14 @@ TEST_F(AsyncBatchLogProcessorTest, TestAsyncForceFlush) 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)); } @@ -274,7 +274,7 @@ TEST_F(AsyncBatchLogProcessorTest, TestAsyncForceFlush) 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()); } } @@ -294,7 +294,7 @@ TEST_F(AsyncBatchLogProcessorTest, 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)); } @@ -318,7 +318,7 @@ TEST_F(AsyncBatchLogProcessorTest, 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)); } @@ -327,7 +327,7 @@ TEST_F(AsyncBatchLogProcessorTest, 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()); } } @@ -351,7 +351,7 @@ TEST_F(AsyncBatchLogProcessorTest, 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 @@ -367,7 +367,7 @@ TEST_F(AsyncBatchLogProcessorTest, 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/batch_log_processor_test.cc b/sdk/test/logs/batch_log_processor_test.cc index 5e4e0f852b..2379c11c0c 100644 --- a/sdk/test/logs/batch_log_processor_test.cc +++ b/sdk/test/logs/batch_log_processor_test.cc @@ -123,7 +123,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)); } @@ -139,7 +139,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 @@ -158,7 +158,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)); } @@ -167,14 +167,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)); } @@ -183,7 +183,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()); } } @@ -203,7 +203,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)); } @@ -227,7 +227,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)); } @@ -236,7 +236,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()); } } @@ -260,7 +260,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 @@ -276,7 +276,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 888ce51c7a..824bf62696 100644 --- a/sdk/test/logs/simple_log_processor_test.cc +++ b/sdk/test/logs/simple_log_processor_test.cc @@ -96,7 +96,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 @@ -107,7 +107,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