From a5db7e593548fd0718241ba57e62c62bbca77357 Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Tue, 19 Nov 2024 06:32:36 +0800 Subject: [PATCH] [EXPORTER] Allow to share gRPC clients between OTLP exporters (#3041) --- CHANGELOG.md | 3 + CMakeLists.txt | 10 +- .../nostd/internal/absl/README.md | 4 +- .../nostd/internal/absl/base/config.h | 43 +-- .../absl/base/internal/inline_variable.h | 10 +- .../internal/absl/base/internal/invoke.h | 10 +- .../nostd/internal/absl/base/macros.h | 8 +- .../nostd/internal/absl/base/options.h | 50 ++-- .../nostd/internal/absl/meta/type_traits.h | 28 +- .../internal/absl/types/bad_variant_access.h | 14 +- .../internal/absl/types/internal/variant.h | 258 +++++++++--------- .../nostd/internal/absl/types/variant.h | 222 +++++++-------- .../nostd/internal/absl/utility/utility.h | 68 ++--- api/include/opentelemetry/nostd/variant.h | 11 +- cmake/opentelemetry-cpp-config.cmake.in | 9 +- cmake/opentelemetry-proto.cmake | 32 ++- cmake/patch-imported-config.cmake | 2 +- examples/grpc/CMakeLists.txt | 2 +- exporters/otlp/BUILD | 2 + exporters/otlp/CMakeLists.txt | 8 +- .../exporters/otlp/otlp_grpc_client.h | 55 +++- .../exporters/otlp/otlp_grpc_client_factory.h | 36 +++ .../exporters/otlp/otlp_grpc_exporter.h | 40 ++- .../otlp/otlp_grpc_exporter_factory.h | 10 + .../otlp/otlp_grpc_log_record_exporter.h | 43 ++- .../otlp_grpc_log_record_exporter_factory.h | 12 +- .../otlp/otlp_grpc_metric_exporter.h | 42 ++- .../otlp/otlp_grpc_metric_exporter_factory.h | 12 +- exporters/otlp/src/otlp_grpc_client.cc | 161 +++++++++-- .../otlp/src/otlp_grpc_client_factory.cc | 27 ++ exporters/otlp/src/otlp_grpc_exporter.cc | 108 ++++++-- .../otlp/src/otlp_grpc_exporter_factory.cc | 9 + .../otlp/src/otlp_grpc_log_record_exporter.cc | 113 ++++++-- .../otlp_grpc_log_record_exporter_factory.cc | 9 + .../otlp/src/otlp_grpc_metric_exporter.cc | 110 ++++++-- .../src/otlp_grpc_metric_exporter_factory.cc | 9 + .../test/otlp_grpc_exporter_factory_test.cc | 22 ++ ...p_grpc_log_record_exporter_factory_test.cc | 24 ++ .../otlp_grpc_log_record_exporter_test.cc | 132 +++++++++ .../otlp_grpc_metric_exporter_factory_test.cc | 24 ++ sdk/src/common/CMakeLists.txt | 2 +- 41 files changed, 1256 insertions(+), 538 deletions(-) create mode 100644 exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client_factory.h create mode 100644 exporters/otlp/src/otlp_grpc_client_factory.cc diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e3521797d..050dfa7551 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,9 @@ Increment the: * [SEMANTIC CONVENTIONS] Migration to weaver [#3105](https://github.com/open-telemetry/opentelemetry-cpp/pull/3105) +* [EXPORTER] Allow to share gRPC clients between OTLP exporters. + [#3041](https://github.com/open-telemetry/opentelemetry-cpp/pull/3041) + Important changes: * [API] Jaeger Propagator should not be deprecated diff --git a/CMakeLists.txt b/CMakeLists.txt index aa0ae9ef43..f9e017eed2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -389,14 +389,8 @@ if(WITH_OTLP_GRPC OR WITH_OTLP_HTTP OR WITH_OTLP_FILE) find_package(Protobuf) - if(Protobuf_VERSION AND Protobuf_VERSION VERSION_GREATER_EQUAL "3.22.0") - if(NOT WITH_ABSEIL) - message( - FATAL_ERROR - "Protobuf 3.22 or upper require abseil-cpp(Recommended version: 20230125 or upper)" - ) - endif() - endif() + # Protobuf 3.22 or upper require abseil-cpp, we can find it in + # opentelemetry-cpp-config.cmake if(WITH_OTLP_GRPC) find_package(gRPC) diff --git a/api/include/opentelemetry/nostd/internal/absl/README.md b/api/include/opentelemetry/nostd/internal/absl/README.md index 6a40855704..5dd661971f 100644 --- a/api/include/opentelemetry/nostd/internal/absl/README.md +++ b/api/include/opentelemetry/nostd/internal/absl/README.md @@ -1,4 +1,4 @@ # Notes on Abseil Variant implementation -This is a snapshot of Abseil Variant `absl::variant` from Abseil -`v2020-03-03#8`. +This is a snapshot of Abseil Variant +`absl::OTABSL_OPTION_NAMESPACE_NAME::variant` from Abseil `v2020-03-03#8`. diff --git a/api/include/opentelemetry/nostd/internal/absl/base/config.h b/api/include/opentelemetry/nostd/internal/absl/base/config.h index 3f78df3d98..e0836b9b3f 100644 --- a/api/include/opentelemetry/nostd/internal/absl/base/config.h +++ b/api/include/opentelemetry/nostd/internal/absl/base/config.h @@ -84,7 +84,7 @@ // namespace absl { // OTABSL_NAMESPACE_BEGIN // -// void Foo(); // absl::Foo(). +// void Foo(); // absl::OTABSL_OPTION_NAMESPACE_NAME::Foo(). // // OTABSL_NAMESPACE_END // } // namespace absl @@ -94,40 +94,32 @@ // not support forward declarations of its own types, nor does it support // user-provided specialization of Abseil templates. Code that violates these // rules may be broken without warning.) -#if !defined(OTABSL_OPTION_USE_INLINE_NAMESPACE) || \ - !defined(OTABSL_OPTION_INLINE_NAMESPACE_NAME) +#if !defined(OTABSL_OPTION_NAMESPACE_NAME) #error options.h is misconfigured. #endif -// Check that OTABSL_OPTION_INLINE_NAMESPACE_NAME is neither "head" nor "" -#if defined(__cplusplus) && OTABSL_OPTION_USE_INLINE_NAMESPACE == 1 +// Check that OTABSL_OPTION_NAMESPACE_NAME is neither "head" nor "" +#if defined(__cplusplus) #define OTABSL_INTERNAL_INLINE_NAMESPACE_STR \ - OTABSL_INTERNAL_TOKEN_STR(OTABSL_OPTION_INLINE_NAMESPACE_NAME) + OTABSL_INTERNAL_TOKEN_STR(OTABSL_OPTION_NAMESPACE_NAME) static_assert(OTABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != '\0', - "options.h misconfigured: OTABSL_OPTION_INLINE_NAMESPACE_NAME must " + "options.h misconfigured: OTABSL_OPTION_NAMESPACE_NAME must " "not be empty."); static_assert(OTABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' || OTABSL_INTERNAL_INLINE_NAMESPACE_STR[1] != 'e' || OTABSL_INTERNAL_INLINE_NAMESPACE_STR[2] != 'a' || OTABSL_INTERNAL_INLINE_NAMESPACE_STR[3] != 'd' || OTABSL_INTERNAL_INLINE_NAMESPACE_STR[4] != '\0', - "options.h misconfigured: OTABSL_OPTION_INLINE_NAMESPACE_NAME must " + "options.h misconfigured: OTABSL_OPTION_NAMESPACE_NAME must " "be changed to a new, unique identifier name."); #endif -#if OTABSL_OPTION_USE_INLINE_NAMESPACE == 0 -#define OTABSL_NAMESPACE_BEGIN -#define OTABSL_NAMESPACE_END -#elif OTABSL_OPTION_USE_INLINE_NAMESPACE == 1 -#define OTABSL_NAMESPACE_BEGIN \ - inline namespace OTABSL_OPTION_INLINE_NAMESPACE_NAME { + +#define OTABSL_NAMESPACE_BEGIN namespace OTABSL_OPTION_NAMESPACE_NAME { #define OTABSL_NAMESPACE_END } -#else -#error options.h is misconfigured. -#endif // ----------------------------------------------------------------------------- // Compiler Feature Checks @@ -217,7 +209,7 @@ static_assert(OTABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' || // OTABSL_HAVE_SOURCE_LOCATION_CURRENT // -// Indicates whether `absl::SourceLocation::current()` will return useful +// Indicates whether `absl::OTABSL_OPTION_NAMESPACE_NAME::SourceLocation::current()` will return useful // information in some contexts. #ifndef OTABSL_HAVE_SOURCE_LOCATION_CURRENT #if OTABSL_INTERNAL_HAS_KEYWORD(__builtin_LINE) && \ @@ -570,7 +562,7 @@ static_assert(OTABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' || // OTABSL_USES_STD_ANY // -// Indicates whether absl::any is an alias for std::any. +// Indicates whether absl::OTABSL_OPTION_NAMESPACE_NAME::any is an alias for std::any. #if !defined(OTABSL_OPTION_USE_STD_ANY) #error options.h is misconfigured. #elif OTABSL_OPTION_USE_STD_ANY == 0 || \ @@ -585,7 +577,7 @@ static_assert(OTABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' || // OTABSL_USES_STD_OPTIONAL // -// Indicates whether absl::optional is an alias for std::optional. +// Indicates whether absl::OTABSL_OPTION_NAMESPACE_NAME::optional is an alias for std::optional. #if !defined(OTABSL_OPTION_USE_STD_OPTIONAL) #error options.h is misconfigured. #elif OTABSL_OPTION_USE_STD_OPTIONAL == 0 || \ @@ -600,7 +592,7 @@ static_assert(OTABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' || // OTABSL_USES_STD_VARIANT // -// Indicates whether absl::variant is an alias for std::variant. +// Indicates whether absl::OTABSL_OPTION_NAMESPACE_NAME::variant is an alias for std::variant. #if !defined(OTABSL_OPTION_USE_STD_VARIANT) #error options.h is misconfigured. #elif OTABSL_OPTION_USE_STD_VARIANT == 0 || \ @@ -615,7 +607,7 @@ static_assert(OTABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' || // OTABSL_USES_STD_STRING_VIEW // -// Indicates whether absl::string_view is an alias for std::string_view. +// Indicates whether absl::OTABSL_OPTION_NAMESPACE_NAME::string_view is an alias for std::string_view. #if !defined(OTABSL_OPTION_USE_STD_STRING_VIEW) #error options.h is misconfigured. #elif OTABSL_OPTION_USE_STD_STRING_VIEW == 0 || \ @@ -650,15 +642,10 @@ static_assert(OTABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' || // the proper count to skip past the CCTZ fork namespace names. (This number // is one larger when there is an inline namespace name to skip.) #if defined(_MSC_VER) -#if OTABSL_OPTION_USE_INLINE_NAMESPACE == 0 -#define OTABSL_INTERNAL_MANGLED_NS "absl" -#define OTABSL_INTERNAL_MANGLED_BACKREFERENCE "5" -#else #define OTABSL_INTERNAL_MANGLED_NS \ - OTABSL_INTERNAL_TOKEN_STR(OTABSL_OPTION_INLINE_NAMESPACE_NAME) "@absl" + OTABSL_INTERNAL_TOKEN_STR(OTABSL_OPTION_NAMESPACE_NAME) "@absl" #define OTABSL_INTERNAL_MANGLED_BACKREFERENCE "6" #endif -#endif #undef OTABSL_INTERNAL_HAS_KEYWORD diff --git a/api/include/opentelemetry/nostd/internal/absl/base/internal/inline_variable.h b/api/include/opentelemetry/nostd/internal/absl/base/internal/inline_variable.h index 9d024a2d91..dd66e9f223 100644 --- a/api/include/opentelemetry/nostd/internal/absl/base/internal/inline_variable.h +++ b/api/include/opentelemetry/nostd/internal/absl/base/internal/inline_variable.h @@ -68,7 +68,7 @@ // types, etc.. #if defined(__clang__) #define OTABSL_INTERNAL_EXTERN_DECL(type, name) \ - extern const ::absl::OTABSL_OPTION_INLINE_NAMESPACE_NAME::internal::identity_t name; + extern const ::absl::OTABSL_OPTION_NAMESPACE_NAME::internal::identity_t name; #else // Otherwise, just define the macro to do nothing. #define OTABSL_INTERNAL_EXTERN_DECL(type, name) #endif // defined(__clang__) @@ -76,7 +76,7 @@ // See above comment at top of file for details. #define OTABSL_INTERNAL_INLINE_CONSTEXPR(type, name, init) \ OTABSL_INTERNAL_EXTERN_DECL(type, name) \ - inline constexpr ::absl::OTABSL_OPTION_INLINE_NAMESPACE_NAME::internal::identity_t name = init + inline constexpr ::absl::OTABSL_OPTION_NAMESPACE_NAME::internal::identity_t name = init #else @@ -89,14 +89,14 @@ #define OTABSL_INTERNAL_INLINE_CONSTEXPR(var_type, name, init) \ template \ struct AbslInternalInlineVariableHolder##name { \ - static constexpr ::absl::OTABSL_OPTION_INLINE_NAMESPACE_NAME::internal::identity_t kInstance = init; \ + static constexpr ::absl::OTABSL_OPTION_NAMESPACE_NAME::internal::identity_t kInstance = init; \ }; \ \ template \ - constexpr ::absl::OTABSL_OPTION_INLINE_NAMESPACE_NAME::internal::identity_t \ + constexpr ::absl::OTABSL_OPTION_NAMESPACE_NAME::internal::identity_t \ AbslInternalInlineVariableHolder##name::kInstance; \ \ - static constexpr const ::absl::OTABSL_OPTION_INLINE_NAMESPACE_NAME::internal::identity_t& \ + static constexpr const ::absl::OTABSL_OPTION_NAMESPACE_NAME::internal::identity_t& \ name = /* NOLINT */ \ AbslInternalInlineVariableHolder##name<>::kInstance; \ static_assert(sizeof(void (*)(decltype(name))) != 0, \ diff --git a/api/include/opentelemetry/nostd/internal/absl/base/internal/invoke.h b/api/include/opentelemetry/nostd/internal/absl/base/internal/invoke.h index 99c37ba24a..c37f43cfc8 100644 --- a/api/include/opentelemetry/nostd/internal/absl/base/internal/invoke.h +++ b/api/include/opentelemetry/nostd/internal/absl/base/internal/invoke.h @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. // -// absl::base_internal::Invoke(f, args...) is an implementation of +// absl::OTABSL_OPTION_NAMESPACE_NAME::base_internal::Invoke(f, args...) is an implementation of // INVOKE(f, args...) from section [func.require] of the C++ standard. // // [func.require] @@ -73,7 +73,7 @@ struct MemFunAndRef : StrippedAccept { template struct AcceptImpl : std::integral_constant::value && - absl::is_function::value> { + absl::OTABSL_OPTION_NAMESPACE_NAME::is_function::value> { }; template @@ -94,7 +94,7 @@ struct MemFunAndPtr : StrippedAccept { template struct AcceptImpl : std::integral_constant::value && - absl::is_function::value> { + absl::OTABSL_OPTION_NAMESPACE_NAME::is_function::value> { }; template @@ -116,7 +116,7 @@ struct DataMemAndRef : StrippedAccept { template struct AcceptImpl : std::integral_constant::value && - !absl::is_function::value> {}; + !absl::OTABSL_OPTION_NAMESPACE_NAME::is_function::value> {}; template static decltype(std::declval().*std::declval()) Invoke( @@ -134,7 +134,7 @@ struct DataMemAndPtr : StrippedAccept { template struct AcceptImpl : std::integral_constant::value && - !absl::is_function::value> {}; + !absl::OTABSL_OPTION_NAMESPACE_NAME::is_function::value> {}; template static decltype((*std::declval()).*std::declval()) Invoke( diff --git a/api/include/opentelemetry/nostd/internal/absl/base/macros.h b/api/include/opentelemetry/nostd/internal/absl/base/macros.h index 7b4f427d30..707c375ed1 100644 --- a/api/include/opentelemetry/nostd/internal/absl/base/macros.h +++ b/api/include/opentelemetry/nostd/internal/absl/base/macros.h @@ -41,7 +41,7 @@ // can be used in defining new arrays. If you use this macro on a pointer by // mistake, you will get a compile-time error. #define OTABSL_ARRAYSIZE(array) \ - (sizeof(::absl::macros_internal::ArraySizeHelper(array))) + (sizeof(::absl::OTABSL_OPTION_NAMESPACE_NAME::macros_internal::ArraySizeHelper(array))) namespace absl { OTABSL_NAMESPACE_BEGIN @@ -60,7 +60,7 @@ OTABSL_NAMESPACE_END // static storage duration, and that the constructor should do nothing to its // state. Use of this macro indicates to the reader that it is legal to // declare a static instance of the class, provided the constructor is given -// the absl::base_internal::kLinkerInitialized argument. +// the absl::OTABSL_OPTION_NAMESPACE_NAME::base_internal::kLinkerInitialized argument. // // Normally, it is unsafe to declare a static variable that has a constructor or // a destructor because invocation order is undefined. However, if the type can @@ -70,10 +70,10 @@ OTABSL_NAMESPACE_END // // Example: // // Declaration -// explicit MyClass(absl::base_internal:LinkerInitialized x) {} +// explicit MyClass(absl::OTABSL_OPTION_NAMESPACE_NAME::base_internal:LinkerInitialized x) {} // // // Invocation -// static MyClass my_global(absl::base_internal::kLinkerInitialized); +// static MyClass my_global(absl::OTABSL_OPTION_NAMESPACE_NAME::base_internal::kLinkerInitialized); namespace absl { OTABSL_NAMESPACE_BEGIN namespace base_internal { diff --git a/api/include/opentelemetry/nostd/internal/absl/base/options.h b/api/include/opentelemetry/nostd/internal/absl/base/options.h index 3632b74f64..26665b151e 100644 --- a/api/include/opentelemetry/nostd/internal/absl/base/options.h +++ b/api/include/opentelemetry/nostd/internal/absl/base/options.h @@ -79,7 +79,7 @@ // // OTABSL_OPTION_USE_STD_ANY // -// This option controls whether absl::any is implemented as an alias to +// This option controls whether absl::OTABSL_OPTION_NAMESPACE_NAME::any is implemented as an alias to // std::any, or as an independent implementation. // // A value of 0 means to use Abseil's implementation. This requires only C++11 @@ -93,19 +93,19 @@ // useful when you are building your entire program, including all of its // dependencies, from source. It should not be used otherwise -- for example, // if you are distributing Abseil in a binary package manager -- since in -// mode 2, absl::any will name a different type, with a different mangled name +// mode 2, absl::OTABSL_OPTION_NAMESPACE_NAME::any will name a different type, with a different mangled name // and binary layout, depending on the compiler flags passed by the end user. // For more info, see https://abseil.io/about/design/dropin-types. // // User code should not inspect this macro. To check in the preprocessor if -// absl::any is a typedef of std::any, use the feature macro OTABSL_USES_STD_ANY. +// absl::OTABSL_OPTION_NAMESPACE_NAME::any is a typedef of std::any, use the feature macro OTABSL_USES_STD_ANY. #define OTABSL_OPTION_USE_STD_ANY 0 // OTABSL_OPTION_USE_STD_OPTIONAL // -// This option controls whether absl::optional is implemented as an alias to +// This option controls whether absl::OTABSL_OPTION_NAMESPACE_NAME::optional is implemented as an alias to // std::optional, or as an independent implementation. // // A value of 0 means to use Abseil's implementation. This requires only C++11 @@ -118,13 +118,13 @@ // and use an alias only if a working std::optional is available. This option // is useful when you are building your program from source. It should not be // used otherwise -- for example, if you are distributing Abseil in a binary -// package manager -- since in mode 2, absl::optional will name a different +// package manager -- since in mode 2, absl::OTABSL_OPTION_NAMESPACE_NAME::optional will name a different // type, with a different mangled name and binary layout, depending on the // compiler flags passed by the end user. For more info, see // https://abseil.io/about/design/dropin-types. // User code should not inspect this macro. To check in the preprocessor if -// absl::optional is a typedef of std::optional, use the feature macro +// absl::OTABSL_OPTION_NAMESPACE_NAME::optional is a typedef of std::optional, use the feature macro // OTABSL_USES_STD_OPTIONAL. #define OTABSL_OPTION_USE_STD_OPTIONAL 0 @@ -132,7 +132,7 @@ // OTABSL_OPTION_USE_STD_STRING_VIEW // -// This option controls whether absl::string_view is implemented as an alias to +// This option controls whether absl::OTABSL_OPTION_NAMESPACE_NAME::string_view is implemented as an alias to // std::string_view, or as an independent implementation. // // A value of 0 means to use Abseil's implementation. This requires only C++11 @@ -145,20 +145,20 @@ // and use an alias only if a working std::string_view is available. This // option is useful when you are building your program from source. It should // not be used otherwise -- for example, if you are distributing Abseil in a -// binary package manager -- since in mode 2, absl::string_view will name a +// binary package manager -- since in mode 2, absl::OTABSL_OPTION_NAMESPACE_NAME::string_view will name a // different type, with a different mangled name and binary layout, depending on // the compiler flags passed by the end user. For more info, see // https://abseil.io/about/design/dropin-types. // // User code should not inspect this macro. To check in the preprocessor if -// absl::string_view is a typedef of std::string_view, use the feature macro +// absl::OTABSL_OPTION_NAMESPACE_NAME::string_view is a typedef of std::string_view, use the feature macro // OTABSL_USES_STD_STRING_VIEW. #define OTABSL_OPTION_USE_STD_STRING_VIEW 0 // OTABSL_OPTION_USE_STD_VARIANT // -// This option controls whether absl::variant is implemented as an alias to +// This option controls whether absl::OTABSL_OPTION_NAMESPACE_NAME::variant is implemented as an alias to // std::variant, or as an independent implementation. // // A value of 0 means to use Abseil's implementation. This requires only C++11 @@ -171,41 +171,23 @@ // and use an alias only if a working std::variant is available. This option // is useful when you are building your program from source. It should not be // used otherwise -- for example, if you are distributing Abseil in a binary -// package manager -- since in mode 2, absl::variant will name a different +// package manager -- since in mode 2, absl::OTABSL_OPTION_NAMESPACE_NAME::variant will name a different // type, with a different mangled name and binary layout, depending on the // compiler flags passed by the end user. For more info, see // https://abseil.io/about/design/dropin-types. // // User code should not inspect this macro. To check in the preprocessor if -// absl::variant is a typedef of std::variant, use the feature macro +// absl::OTABSL_OPTION_NAMESPACE_NAME::variant is a typedef of std::variant, use the feature macro // OTABSL_USES_STD_VARIANT. #define OTABSL_OPTION_USE_STD_VARIANT 0 -// OTABSL_OPTION_USE_INLINE_NAMESPACE -// OTABSL_OPTION_INLINE_NAMESPACE_NAME +// OTABSL_OPTION_NAMESPACE_NAME // -// These options controls whether all entities in the absl namespace are -// contained within an inner inline namespace. This does not affect the -// user-visible API of Abseil, but it changes the mangled names of all symbols. -// -// This can be useful as a version tag if you are distributing Abseil in -// precompiled form. This will prevent a binary library build of Abseil with -// one inline namespace being used with headers configured with a different -// inline namespace name. Binary packagers are reminded that Abseil does not -// guarantee any ABI stability in Abseil, so any update of Abseil or -// configuration change in such a binary package should be combined with a -// new, unique value for the inline namespace name. -// -// A value of 0 means not to use inline namespaces. -// -// A value of 1 means to use an inline namespace with the given name inside -// namespace absl. If this is set, OTABSL_OPTION_INLINE_NAMESPACE_NAME must also -// be changed to a new, unique identifier name. In particular "head" is not -// allowed. +// All codes in otabsl are under OTABSL_OPTION_NAMESPACE_NAME, we do not use inline namespace to avoid +// conlict with external Abseil. -#define OTABSL_OPTION_USE_INLINE_NAMESPACE 1 -#define OTABSL_OPTION_INLINE_NAMESPACE_NAME otel_v1 +#define OTABSL_OPTION_NAMESPACE_NAME otel_v1 #endif // OTABSL_BASE_OPTIONS_H_ diff --git a/api/include/opentelemetry/nostd/internal/absl/meta/type_traits.h b/api/include/opentelemetry/nostd/internal/absl/meta/type_traits.h index 7fba912312..dbd0348871 100644 --- a/api/include/opentelemetry/nostd/internal/absl/meta/type_traits.h +++ b/api/include/opentelemetry/nostd/internal/absl/meta/type_traits.h @@ -81,25 +81,25 @@ struct IsTriviallyMoveConstructibleObject : std::integral_constant< bool, std::is_move_constructible< type_traits_internal::SingleMemberUnion>::value && - absl::is_trivially_destructible::value> {}; + absl::OTABSL_OPTION_NAMESPACE_NAME::is_trivially_destructible::value> {}; template struct IsTriviallyCopyConstructibleObject : std::integral_constant< bool, std::is_copy_constructible< type_traits_internal::SingleMemberUnion>::value && - absl::is_trivially_destructible::value> {}; + absl::OTABSL_OPTION_NAMESPACE_NAME::is_trivially_destructible::value> {}; template struct IsTriviallyMoveAssignableReference : std::false_type {}; template struct IsTriviallyMoveAssignableReference - : absl::is_trivially_move_assignable::type {}; + : absl::OTABSL_OPTION_NAMESPACE_NAME::is_trivially_move_assignable::type {}; template struct IsTriviallyMoveAssignableReference - : absl::is_trivially_move_assignable::type {}; + : absl::OTABSL_OPTION_NAMESPACE_NAME::is_trivially_move_assignable::type {}; template struct VoidTImpl { @@ -191,7 +191,7 @@ struct is_move_assignable : type_traits_internal::is_detected< // This metafunction is designed to be a drop-in replacement for the C++17 // `std::void_t` metafunction. // -// NOTE: `absl::void_t` does not use the standard-specified implementation so +// NOTE: `absl::OTABSL_OPTION_NAMESPACE_NAME::void_t` does not use the standard-specified implementation so // that it can remain compatible with gcc < 5.1. This can introduce slightly // different behavior, such as when ordering partial specializations. template @@ -493,7 +493,7 @@ struct is_trivially_copy_assignable #else : std::integral_constant< bool, __has_trivial_assign(typename std::remove_reference::type) && - absl::is_copy_assignable::value> { + absl::OTABSL_OPTION_NAMESPACE_NAME::is_copy_assignable::value> { #endif #ifdef OTABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE private: @@ -537,8 +537,8 @@ class is_trivially_copyable_impl { std::is_copy_constructible::value || std::is_move_constructible::value; static constexpr bool kIsCopyOrMoveAssignable = - absl::is_copy_assignable::value || - absl::is_move_assignable::value; + absl::OTABSL_OPTION_NAMESPACE_NAME::is_copy_assignable::value || + absl::OTABSL_OPTION_NAMESPACE_NAME::is_move_assignable::value; public: static constexpr bool kValue = @@ -661,7 +661,7 @@ struct IsHashable : std::false_type {}; template struct IsHashable< Key, - absl::enable_if_t&>()(std::declval())), std::size_t>::value>> : std::true_type {}; #endif // !OTABSL_META_INTERNAL_STD_HASH_SFINAE_FRIENDLY_ @@ -687,7 +687,7 @@ struct AssertHashEnabledHelper { static_assert( std::is_copy_constructible>::value, "std::hash must be copy constructible when it is enabled"); - static_assert(absl::is_copy_assignable>::value, + static_assert(absl::OTABSL_OPTION_NAMESPACE_NAME::is_copy_assignable>::value, "std::hash must be copy assignable when it is enabled"); // is_destructible is unchecked as it's implied by each of the // is_constructible checks. @@ -717,7 +717,7 @@ namespace swap_internal { // Necessary for the traits. using std::swap; -// This declaration prevents global `swap` and `absl::swap` overloads from being +// This declaration prevents global `swap` and `absl::OTABSL_OPTION_NAMESPACE_NAME::swap` overloads from being // considered unless ADL picks them up. void swap(); @@ -736,7 +736,7 @@ using IsNothrowSwappableImpl = typename std::enable_if::type; // arguments of type `T`. template struct IsSwappable - : absl::type_traits_internal::is_detected {}; + : absl::OTABSL_OPTION_NAMESPACE_NAME::type_traits_internal::is_detected {}; // IsNothrowSwappable // @@ -744,13 +744,13 @@ struct IsSwappable // arguments of type `T` and is noexcept. template struct IsNothrowSwappable - : absl::type_traits_internal::is_detected {}; + : absl::OTABSL_OPTION_NAMESPACE_NAME::type_traits_internal::is_detected {}; // Swap() // // Performs the swap idiom from a namespace where valid candidates may only be // found in `std` or via ADL. -template ::value, int> = 0> +template ::value, int> = 0> void Swap(T& lhs, T& rhs) noexcept(IsNothrowSwappable::value) { swap(lhs, rhs); } diff --git a/api/include/opentelemetry/nostd/internal/absl/types/bad_variant_access.h b/api/include/opentelemetry/nostd/internal/absl/types/bad_variant_access.h index 81caa0d75c..89fe750dbd 100644 --- a/api/include/opentelemetry/nostd/internal/absl/types/bad_variant_access.h +++ b/api/include/opentelemetry/nostd/internal/absl/types/bad_variant_access.h @@ -16,7 +16,7 @@ // bad_variant_access.h // ----------------------------------------------------------------------------- // -// This header file defines the `absl::bad_variant_access` type. +// This header file defines the `absl::OTABSL_OPTION_NAMESPACE_NAME::bad_variant_access` type. #ifndef OTABSL_TYPES_BAD_VARIANT_ACCESS_H_ #define OTABSL_TYPES_BAD_VARIANT_ACCESS_H_ @@ -44,21 +44,21 @@ OTABSL_NAMESPACE_BEGIN // bad_variant_access // ----------------------------------------------------------------------------- // -// An `absl::bad_variant_access` type is an exception type that is thrown in +// An `absl::OTABSL_OPTION_NAMESPACE_NAME::bad_variant_access` type is an exception type that is thrown in // the following cases: // -// * Calling `absl::get(absl::variant) with an index or type that does not +// * Calling `absl::OTABSL_OPTION_NAMESPACE_NAME::get(absl::OTABSL_OPTION_NAMESPACE_NAME::variant) with an index or type that does not // match the currently selected alternative type -// * Calling `absl::visit on an `absl::variant` that is in the +// * Calling `absl::OTABSL_OPTION_NAMESPACE_NAME::visit on an `absl::OTABSL_OPTION_NAMESPACE_NAME::variant` that is in the // `variant::valueless_by_exception` state. // // Example: // -// absl::variant v; +// absl::OTABSL_OPTION_NAMESPACE_NAME::variant v; // v = 1; // try { -// absl::get(v); -// } catch(const absl::bad_variant_access& e) { +// absl::OTABSL_OPTION_NAMESPACE_NAME::get(v); +// } catch(const absl::OTABSL_OPTION_NAMESPACE_NAME::bad_variant_access& e) { // std::cout << "Bad variant access: " << e.what() << '\n'; // } class bad_variant_access : public std::exception { diff --git a/api/include/opentelemetry/nostd/internal/absl/types/internal/variant.h b/api/include/opentelemetry/nostd/internal/absl/types/internal/variant.h index ee42da7c93..fc73cf5328 100644 --- a/api/include/opentelemetry/nostd/internal/absl/types/internal/variant.h +++ b/api/include/opentelemetry/nostd/internal/absl/types/internal/variant.h @@ -136,24 +136,24 @@ struct VariantAccessResultImpl; template class Variantemplate, class... T> struct VariantAccessResultImpl&> { - using type = typename absl::variant_alternative>::type&; + using type = typename absl::OTABSL_OPTION_NAMESPACE_NAME::variant_alternative>::type&; }; template class Variantemplate, class... T> struct VariantAccessResultImpl&> { using type = - const typename absl::variant_alternative>::type&; + const typename absl::OTABSL_OPTION_NAMESPACE_NAME::variant_alternative>::type&; }; template class Variantemplate, class... T> struct VariantAccessResultImpl&&> { - using type = typename absl::variant_alternative>::type&&; + using type = typename absl::OTABSL_OPTION_NAMESPACE_NAME::variant_alternative>::type&&; }; template class Variantemplate, class... T> struct VariantAccessResultImpl&&> { using type = - const typename absl::variant_alternative>::type&&; + const typename absl::OTABSL_OPTION_NAMESPACE_NAME::variant_alternative>::type&&; }; template @@ -198,7 +198,7 @@ using AlwaysZero = SizeT<0>; template struct VisitIndicesResultImpl { - using type = absl::result_of_t...)>; + using type = absl::OTABSL_OPTION_NAMESPACE_NAME::result_of_t...)>; }; template @@ -214,7 +214,7 @@ constexpr ReturnType call_with_indices(FunctionObject&& function) { std::is_same()( SizeT()...))>::value, "Not all visitation overloads have the same return type."); - return absl::forward(function)(SizeT()...); + return absl::OTABSL_OPTION_NAMESPACE_NAME::forward(function)(SizeT()...); } template @@ -265,7 +265,7 @@ struct MakeVisitationMatrix> : MakeVisitationMatrixImpl, - absl::make_index_sequence, + absl::OTABSL_OPTION_NAMESPACE_NAME::make_index_sequence, index_sequence> {}; struct UnreachableSwitchCase { @@ -284,7 +284,7 @@ struct UnreachableSwitchCase { assert(false); // NOLINT // Hack to silence potential no return warning -- cause an infinite loop. - return Run(absl::forward(op)); + return Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); #endif // Checks for __builtin_unreachable } }; @@ -292,7 +292,7 @@ struct UnreachableSwitchCase { template struct ReachableSwitchCase { static VisitIndicesResultT Run(Op&& op) { - return absl::OTABSL_OPTION_INLINE_NAMESPACE_NAME::base_internal::Invoke(absl::forward(op), SizeT()); + return absl::OTABSL_OPTION_NAMESPACE_NAME::base_internal::Invoke(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op), SizeT()); } }; @@ -326,7 +326,7 @@ using PickCase = typename PickCaseImpl<(I < EndIndex)>::template Apply; template [[noreturn]] ReturnType TypedThrowBadVariantAccess() { - absl::variant_internal::ThrowBadVariantAccess(); + absl::OTABSL_OPTION_NAMESPACE_NAME::variant_internal::ThrowBadVariantAccess(); } // Given N variant sizes, determine the number of cases there would need to be @@ -357,74 +357,74 @@ struct VisitIndicesSwitch { static VisitIndicesResultT Run(Op&& op, std::size_t i) { switch (i) { case 0: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 1: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 2: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 3: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 4: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 5: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 6: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 7: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 8: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 9: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 10: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 11: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 12: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 13: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 14: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 15: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 16: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 17: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 18: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 19: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 20: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 21: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 22: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 23: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 24: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 25: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 26: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 27: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 28: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 29: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 30: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 31: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); case 32: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); default: OTABSL_ASSERT(i == variant_npos); - return absl::OTABSL_OPTION_INLINE_NAMESPACE_NAME::base_internal::Invoke(absl::forward(op), NPos()); + return absl::OTABSL_OPTION_NAMESPACE_NAME::base_internal::Invoke(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op), NPos()); } } }; @@ -437,7 +437,7 @@ struct VisitIndicesFallback { MakeVisitationMatrix, Op, index_sequence<(EndIndices + 1)...>, index_sequence<>>::Run(), - (indices + 1)...)(absl::forward(op)); + (indices + 1)...)(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)); } }; @@ -479,7 +479,7 @@ template struct VisitIndicesVariadicImpl; template -struct VisitIndicesVariadicImpl, EndIndices...> { +struct VisitIndicesVariadicImpl, EndIndices...> { // A type that can take an N-ary function object and converts it to a unary // function object that takes a single, flattened index, and "unflattens" it // into its individual dimensions when forwarding to the wrapped object. @@ -488,8 +488,8 @@ struct VisitIndicesVariadicImpl, EndIndices...> { template VisitIndicesResultT operator()( SizeT /*index*/) && { - return OTABSL_OPTION_INLINE_NAMESPACE_NAME::base_internal::Invoke( - absl::forward(op), + return absl::OTABSL_OPTION_NAMESPACE_NAME::base_internal::Invoke( + absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op), SizeT::value - std::size_t{1}>()...); } @@ -501,7 +501,7 @@ struct VisitIndicesVariadicImpl, EndIndices...> { static VisitIndicesResultT Run( Op&& op, SizeType... i) { return VisitIndicesSwitch::value>::Run( - FlattenedOp{absl::forward(op)}, + FlattenedOp{absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op)}, FlattenIndices<(EndIndices + std::size_t{1})...>::Run( (i + std::size_t{1})...)); } @@ -509,7 +509,7 @@ struct VisitIndicesVariadicImpl, EndIndices...> { template struct VisitIndicesVariadic - : VisitIndicesVariadicImpl, + : VisitIndicesVariadicImpl, EndIndices...> {}; // This implementation will flatten N-ary visit operations into a single switch @@ -522,14 +522,14 @@ struct VisitIndicesVariadic // size. template struct VisitIndices - : absl::conditional_t<(NumCasesOfSwitch::value <= + : absl::OTABSL_OPTION_NAMESPACE_NAME::conditional_t<(NumCasesOfSwitch::value <= MaxUnrolledVisitCases), VisitIndicesVariadic, VisitIndicesFallback> {}; template struct VisitIndices - : absl::conditional_t<(EndIndex <= MaxUnrolledVisitCases), + : absl::OTABSL_OPTION_NAMESPACE_NAME::conditional_t<(EndIndex <= MaxUnrolledVisitCases), VisitIndicesSwitch, VisitIndicesFallback> {}; @@ -577,7 +577,7 @@ struct VariantCoreAccess { template static void Destroy(VariantType& self) { // NOLINT Derived(self).destroy(); - self.index_ = absl::variant_npos; + self.index_ = absl::OTABSL_OPTION_NAMESPACE_NAME::variant_npos; } template @@ -587,7 +587,7 @@ struct VariantCoreAccess { template static void InitFrom(Variant& self, Variant&& other) { // NOLINT - VisitIndices::value>::Run( + VisitIndices::value>::Run( InitFromVisitor{&self, std::forward(other)}, other.index()); @@ -612,7 +612,7 @@ struct VariantCoreAccess { TypedThrowBadVariantAccess>(); } - return Access(absl::forward(self)); + return Access(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(self)); } // The implementation of the move-assignment operation for a variant. @@ -629,7 +629,7 @@ struct VariantCoreAccess { } } - void operator()(SizeT /*new_i*/) const { + void operator()(SizeT /*new_i*/) const { Destroy(*left); } @@ -650,7 +650,7 @@ struct VariantCoreAccess { template void operator()(SizeT /*new_i*/) const { using New = - typename absl::variant_alternative::type; + typename absl::OTABSL_OPTION_NAMESPACE_NAME::variant_alternative::type; if (left->index_ == NewIndex) { Access(*left) = Access(*right); @@ -662,7 +662,7 @@ struct VariantCoreAccess { } } - void operator()(SizeT /*new_i*/) const { + void operator()(SizeT /*new_i*/) const { Destroy(*left); } @@ -684,24 +684,24 @@ struct VariantCoreAccess { void operator()(SizeT /*old_i*/ ) const { - Access(*left) = absl::forward(other); + Access(*left) = absl::OTABSL_OPTION_NAMESPACE_NAME::forward(other); } template void operator()(SizeT /*old_i*/ ) const { using New = - typename absl::variant_alternative::type; + typename absl::OTABSL_OPTION_NAMESPACE_NAME::variant_alternative::type; if (std::is_nothrow_constructible::value || !std::is_nothrow_move_constructible::value) { left->template emplace( - absl::forward(other)); + absl::OTABSL_OPTION_NAMESPACE_NAME::forward(other)); } else { // the standard says "equivalent to // operator=(variant(std::forward(t)))", but we use `emplace` here // because the variant's move assignment operator could be deleted. left->template emplace( - New(absl::forward(other))); + New(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(other))); } } @@ -712,18 +712,18 @@ struct VariantCoreAccess { template static ConversionAssignVisitor MakeConversionAssignVisitor(Left* left, QualifiedNew&& qual) { - return {left, absl::forward(qual)}; + return {left, absl::OTABSL_OPTION_NAMESPACE_NAME::forward(qual)}; } // Backend for operations for `emplace()` which destructs `*self` then // construct a new alternative with `Args...`. template - static typename absl::variant_alternative::type& Replace( + static typename absl::OTABSL_OPTION_NAMESPACE_NAME::variant_alternative::type& Replace( Self* self, Args&&... args) { Destroy(*self); - using New = typename absl::variant_alternative::type; + using New = typename absl::OTABSL_OPTION_NAMESPACE_NAME::variant_alternative::type; New* const result = ::new (static_cast(&self->state_)) - New(absl::forward(args)...); + New(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(args)...); self->index_ = NewIndex; return *result; } @@ -738,7 +738,7 @@ struct VariantCoreAccess { Access(std::forward(right))); } - void operator()(SizeT /*new_i*/) const { + void operator()(SizeT /*new_i*/) const { // This space intentionally left blank. } LeftVariant* left; @@ -888,13 +888,13 @@ struct IndexOfConstructedType< template struct ContainsVariantNPos - : absl::negation, - absl::integer_sequence>> {}; + : absl::OTABSL_OPTION_NAMESPACE_NAME::negation, + absl::OTABSL_OPTION_NAMESPACE_NAME::integer_sequence>> {}; template using RawVisitResult = - absl::result_of_t...)>; + absl::OTABSL_OPTION_NAMESPACE_NAME::result_of_t...)>; // NOTE: The spec requires that all return-paths yield the same type and is not // SFINAE-friendly, so we can deduce the return type by examining the first @@ -905,7 +905,7 @@ using RawVisitResult = template struct VisitResultImpl { using type = - absl::result_of_t...)>; + absl::OTABSL_OPTION_NAMESPACE_NAME::result_of_t...)>; }; // Done in two steps intentionally so that we don't cause substitution to fail. @@ -919,7 +919,7 @@ struct PerformVisitation { template constexpr ReturnType operator()(SizeT... indices) const { return Run(typename ContainsVariantNPos::type{}, - absl::index_sequence_for(), indices...); + absl::OTABSL_OPTION_NAMESPACE_NAME::index_sequence_for(), indices...); } template @@ -927,19 +927,19 @@ struct PerformVisitation { index_sequence, SizeT...) const { static_assert( std::is_same...)>>::value, "All visitation overloads must have the same return type."); - return absl::OTABSL_OPTION_INLINE_NAMESPACE_NAME::base_internal::Invoke( - absl::forward(op), + return absl::OTABSL_OPTION_NAMESPACE_NAME::base_internal::Invoke( + absl::OTABSL_OPTION_NAMESPACE_NAME::forward(op), VariantCoreAccess::Access( - absl::forward(std::get(variant_tup)))...); + absl::OTABSL_OPTION_NAMESPACE_NAME::forward(std::get(variant_tup)))...); } template [[noreturn]] ReturnType Run(std::true_type /*has_valueless*/, index_sequence, SizeT...) const { - absl::variant_internal::ThrowBadVariantAccess(); + absl::OTABSL_OPTION_NAMESPACE_NAME::variant_internal::ThrowBadVariantAccess(); } // TODO(calabrese) Avoid using a tuple, which causes lots of instantiations @@ -981,11 +981,11 @@ union Union { template explicit constexpr Union(EmplaceTag<0>, P&&... args) - : head(absl::forward

(args)...) {} + : head(absl::OTABSL_OPTION_NAMESPACE_NAME::forward

(args)...) {} template explicit constexpr Union(EmplaceTag, P&&... args) - : tail(EmplaceTag{}, absl::forward

(args)...) {} + : tail(EmplaceTag{}, absl::OTABSL_OPTION_NAMESPACE_NAME::forward

(args)...) {} Head head; TailUnion tail; @@ -1013,11 +1013,11 @@ union DestructibleUnionImpl { template explicit constexpr DestructibleUnionImpl(EmplaceTag<0>, P&&... args) - : head(absl::forward

(args)...) {} + : head(absl::OTABSL_OPTION_NAMESPACE_NAME::forward

(args)...) {} template explicit constexpr DestructibleUnionImpl(EmplaceTag, P&&... args) - : tail(EmplaceTag{}, absl::forward

(args)...) {} + : tail(EmplaceTag{}, absl::OTABSL_OPTION_NAMESPACE_NAME::forward

(args)...) {} ~DestructibleUnionImpl() {} @@ -1030,7 +1030,7 @@ union DestructibleUnionImpl { // this resultant type. template using DestructibleUnion = - absl::conditional_t>::value, Union, + absl::OTABSL_OPTION_NAMESPACE_NAME::conditional_t>::value, Union, DestructibleUnionImpl>; // Deepest base, containing the actual union and the discriminator @@ -1040,7 +1040,7 @@ class VariantStateBase { using Variant = variant; template ::value, LazyH>> constexpr VariantStateBase() noexcept( std::is_nothrow_default_constructible::value) @@ -1048,7 +1048,7 @@ class VariantStateBase { template explicit constexpr VariantStateBase(EmplaceTag tag, P&&... args) - : state_(tag, absl::forward

(args)...), index_(I) {} + : state_(tag, absl::OTABSL_OPTION_NAMESPACE_NAME::forward

(args)...), index_(I) {} explicit constexpr VariantStateBase(NoopConstructorTag) : state_(NoopConstructorTag()), index_(variant_npos) {} @@ -1059,7 +1059,7 @@ class VariantStateBase { std::size_t index_; }; -using absl::OTABSL_OPTION_INLINE_NAMESPACE_NAME::internal::identity; +using absl::OTABSL_OPTION_NAMESPACE_NAME::internal::identity; // OverloadSet::Overload() is a unary function which is overloaded to // take any of the element types of the variant, by reference-to-const. @@ -1106,37 +1106,37 @@ using NotEqualResult = decltype(std::declval() != std::declval()); using type_traits_internal::is_detected_convertible; template -using RequireAllHaveEqualT = absl::enable_if_t< - absl::conjunction...>::value, +using RequireAllHaveEqualT = absl::OTABSL_OPTION_NAMESPACE_NAME::enable_if_t< + absl::OTABSL_OPTION_NAMESPACE_NAME::conjunction...>::value, bool>; template using RequireAllHaveNotEqualT = - absl::enable_if_t...>::value, bool>; template using RequireAllHaveLessThanT = - absl::enable_if_t...>::value, bool>; template using RequireAllHaveLessThanOrEqualT = - absl::enable_if_t...>::value, bool>; template using RequireAllHaveGreaterThanOrEqualT = - absl::enable_if_t...>::value, bool>; template using RequireAllHaveGreaterThanT = - absl::enable_if_t...>::value, bool>; @@ -1171,7 +1171,7 @@ struct VariantHelper> { template struct CanConvertFrom> - : public absl::conjunction...> {}; + : public absl::OTABSL_OPTION_NAMESPACE_NAME::conjunction...> {}; }; // A type with nontrivial copy ctor and trivial move ctor. @@ -1220,7 +1220,7 @@ class VariantCopyAssignBaseNontrivial; // Base that is dependent on whether or not the destructor can be trivial. template using VariantStateBaseDestructor = - absl::conditional_t>::value, + absl::OTABSL_OPTION_NAMESPACE_NAME::conditional_t>::value, VariantStateBase, VariantStateBaseDestructorNontrivial>; @@ -1232,44 +1232,44 @@ using VariantStateBaseDestructor = // So we have to use a different approach (i.e. `HasTrivialMoveConstructor`) to // work around the bug. template -using VariantMoveBase = absl::conditional_t< - absl::disjunction< - absl::negation...>>, - absl::conjunction...>>::value, +using VariantMoveBase = absl::OTABSL_OPTION_NAMESPACE_NAME::conditional_t< + absl::OTABSL_OPTION_NAMESPACE_NAME::disjunction< + absl::OTABSL_OPTION_NAMESPACE_NAME::negation...>>, + absl::OTABSL_OPTION_NAMESPACE_NAME::conjunction...>>::value, VariantStateBaseDestructor, VariantMoveBaseNontrivial>; // Base that is dependent on whether or not the copy-constructor can be trivial. template -using VariantCopyBase = absl::conditional_t< - absl::disjunction< - absl::negation...>>, +using VariantCopyBase = absl::OTABSL_OPTION_NAMESPACE_NAME::conditional_t< + absl::OTABSL_OPTION_NAMESPACE_NAME::disjunction< + absl::OTABSL_OPTION_NAMESPACE_NAME::negation...>>, std::is_copy_constructible>>::value, VariantMoveBase, VariantCopyBaseNontrivial>; // Base that is dependent on whether or not the move-assign can be trivial. template -using VariantMoveAssignBase = absl::conditional_t< - absl::disjunction< - absl::conjunction>, +using VariantMoveAssignBase = absl::OTABSL_OPTION_NAMESPACE_NAME::conditional_t< + absl::OTABSL_OPTION_NAMESPACE_NAME::disjunction< + absl::OTABSL_OPTION_NAMESPACE_NAME::conjunction>, std::is_move_constructible>, std::is_destructible>>, - absl::negation..., + absl::OTABSL_OPTION_NAMESPACE_NAME::negation..., // Note: We're not qualifying this with - // absl:: because it doesn't compile + // absl::OTABSL_OPTION_NAMESPACE_NAME:: because it doesn't compile // under MSVC. is_move_assignable...>>>::value, VariantCopyBase, VariantMoveAssignBaseNontrivial>; // Base that is dependent on whether or not the copy-assign can be trivial. template -using VariantCopyAssignBase = absl::conditional_t< - absl::disjunction< - absl::conjunction>, +using VariantCopyAssignBase = absl::OTABSL_OPTION_NAMESPACE_NAME::conditional_t< + absl::OTABSL_OPTION_NAMESPACE_NAME::disjunction< + absl::OTABSL_OPTION_NAMESPACE_NAME::conjunction>, std::is_copy_constructible>, std::is_destructible>>, - absl::negation..., + absl::OTABSL_OPTION_NAMESPACE_NAME::negation..., // Note: We're not qualifying this with - // absl:: because it doesn't compile + // absl::OTABSL_OPTION_NAMESPACE_NAME:: because it doesn't compile // under MSVC. is_copy_assignable...>>>::value, VariantMoveAssignBase, VariantCopyAssignBaseNontrivial>; @@ -1299,11 +1299,11 @@ class VariantStateBaseDestructorNontrivial : protected VariantStateBase { template void operator()(SizeT i) const { using Alternative = - typename absl::variant_alternative>::type; + typename absl::OTABSL_OPTION_NAMESPACE_NAME::variant_alternative>::type; variant_internal::AccessUnion(self->state_, i).~Alternative(); } - void operator()(SizeT /*i*/) const { + void operator()(SizeT /*i*/) const { // This space intentionally left blank } @@ -1331,12 +1331,12 @@ class VariantMoveBaseNontrivial : protected VariantStateBaseDestructor { template void operator()(SizeT i) const { using Alternative = - typename absl::variant_alternative>::type; + typename absl::OTABSL_OPTION_NAMESPACE_NAME::variant_alternative>::type; ::new (static_cast(&self->state_)) Alternative( - variant_internal::AccessUnion(absl::move(other->state_), i)); + variant_internal::AccessUnion(absl::OTABSL_OPTION_NAMESPACE_NAME::move(other->state_), i)); } - void operator()(SizeT /*i*/) const {} + void operator()(SizeT /*i*/) const {} VariantMoveBaseNontrivial* self; VariantMoveBaseNontrivial* other; @@ -1344,7 +1344,7 @@ class VariantMoveBaseNontrivial : protected VariantStateBaseDestructor { VariantMoveBaseNontrivial() = default; VariantMoveBaseNontrivial(VariantMoveBaseNontrivial&& other) noexcept( - absl::conjunction...>::value) + absl::OTABSL_OPTION_NAMESPACE_NAME::conjunction...>::value) : Base(NoopConstructorTag()) { VisitIndices::Run(Construct{this, &other}, other.index_); index_ = other.index_; @@ -1376,12 +1376,12 @@ class VariantCopyBaseNontrivial : protected VariantMoveBase { template void operator()(SizeT i) const { using Alternative = - typename absl::variant_alternative>::type; + typename absl::OTABSL_OPTION_NAMESPACE_NAME::variant_alternative>::type; ::new (static_cast(&self->state_)) Alternative(variant_internal::AccessUnion(other->state_, i)); } - void operator()(SizeT /*i*/) const {} + void operator()(SizeT /*i*/) const {} VariantCopyBaseNontrivial* self; const VariantCopyBaseNontrivial* other; @@ -1421,7 +1421,7 @@ class VariantMoveAssignBaseNontrivial : protected VariantCopyBase { VariantMoveAssignBaseNontrivial& operator=(VariantMoveAssignBaseNontrivial&& other) noexcept( - absl::conjunction..., + absl::OTABSL_OPTION_NAMESPACE_NAME::conjunction..., std::is_nothrow_move_assignable...>::value) { VisitIndices::Run( VariantCoreAccess::MakeMoveAssignVisitor(this, &other), other.index_); @@ -1471,7 +1471,7 @@ struct EqualsOp { const variant* v; const variant* w; - constexpr bool operator()(SizeT /*v_i*/) const { + constexpr bool operator()(SizeT /*v_i*/) const { return true; } @@ -1486,7 +1486,7 @@ struct NotEqualsOp { const variant* v; const variant* w; - constexpr bool operator()(SizeT /*v_i*/) const { + constexpr bool operator()(SizeT /*v_i*/) const { return false; } @@ -1501,7 +1501,7 @@ struct LessThanOp { const variant* v; const variant* w; - constexpr bool operator()(SizeT /*v_i*/) const { + constexpr bool operator()(SizeT /*v_i*/) const { return false; } @@ -1516,7 +1516,7 @@ struct GreaterThanOp { const variant* v; const variant* w; - constexpr bool operator()(SizeT /*v_i*/) const { + constexpr bool operator()(SizeT /*v_i*/) const { return false; } @@ -1531,7 +1531,7 @@ struct LessThanOrEqualsOp { const variant* v; const variant* w; - constexpr bool operator()(SizeT /*v_i*/) const { + constexpr bool operator()(SizeT /*v_i*/) const { return true; } @@ -1546,7 +1546,7 @@ struct GreaterThanOrEqualsOp { const variant* v; const variant* w; - constexpr bool operator()(SizeT /*v_i*/) const { + constexpr bool operator()(SizeT /*v_i*/) const { return true; } @@ -1584,7 +1584,7 @@ struct Swap { VariantCoreAccess::InitFrom(*v, std::move(tmp)); } - void operator()(SizeT /*w_i*/) const { + void operator()(SizeT /*w_i*/) const { if (!v->valueless_by_exception()) { generic_swap(); } @@ -1618,7 +1618,7 @@ struct VariantHashVisitor { template struct VariantHashBase...>::value>, Ts...> { using argument_type = Variant; diff --git a/api/include/opentelemetry/nostd/internal/absl/types/variant.h b/api/include/opentelemetry/nostd/internal/absl/types/variant.h index 2649a29ce3..cbce326c26 100644 --- a/api/include/opentelemetry/nostd/internal/absl/types/variant.h +++ b/api/include/opentelemetry/nostd/internal/absl/types/variant.h @@ -16,26 +16,26 @@ // variant.h // ----------------------------------------------------------------------------- // -// This header file defines an `absl::variant` type for holding a type-safe +// This header file defines an `absl::OTABSL_OPTION_NAMESPACE_NAME::variant` type for holding a type-safe // value of some prescribed set of types (noted as alternative types), and // associated functions for managing variants. // -// The `absl::variant` type is a form of type-safe union. An `absl::variant` +// The `absl::OTABSL_OPTION_NAMESPACE_NAME::variant` type is a form of type-safe union. An `absl::OTABSL_OPTION_NAMESPACE_NAME::variant` // should always hold a value of one of its alternative types (except in the // "valueless by exception state" -- see below). A default-constructed -// `absl::variant` will hold the value of its first alternative type, provided +// `absl::OTABSL_OPTION_NAMESPACE_NAME::variant` will hold the value of its first alternative type, provided // it is default-constructible. // -// In exceptional cases due to error, an `absl::variant` can hold no +// In exceptional cases due to error, an `absl::OTABSL_OPTION_NAMESPACE_NAME::variant` can hold no // value (known as a "valueless by exception" state), though this is not the // norm. // -// As with `absl::optional`, an `absl::variant` -- when it holds a value -- +// As with `absl::OTABSL_OPTION_NAMESPACE_NAME::optional`, an `absl::OTABSL_OPTION_NAMESPACE_NAME::variant` -- when it holds a value -- // allocates a value of that type directly within the `variant` itself; it // cannot hold a reference, array, or the type `void`; it can, however, hold a // pointer to externally managed memory. // -// `absl::variant` is a C++11 compatible version of the C++17 `std::variant` +// `absl::OTABSL_OPTION_NAMESPACE_NAME::variant` is a C++11 compatible version of the C++17 `std::variant` // abstraction and is designed to be a drop-in replacement for code compliant // with C++17. @@ -82,10 +82,10 @@ namespace absl { OTABSL_NAMESPACE_BEGIN // ----------------------------------------------------------------------------- -// absl::variant +// absl::OTABSL_OPTION_NAMESPACE_NAME::variant // ----------------------------------------------------------------------------- // -// An `absl::variant` type is a form of type-safe union. An `absl::variant` -- +// An `absl::OTABSL_OPTION_NAMESPACE_NAME::variant` type is a form of type-safe union. An `absl::OTABSL_OPTION_NAMESPACE_NAME::variant` -- // except in exceptional cases -- always holds a value of one of its alternative // types. // @@ -93,29 +93,29 @@ OTABSL_NAMESPACE_BEGIN // // // Construct a variant that holds either an integer or a std::string and // // assign it to a std::string. -// absl::variant v = std::string("abc"); +// absl::OTABSL_OPTION_NAMESPACE_NAME::variant v = std::string("abc"); // // // A default-constructed variant will hold a value-initialized value of // // the first alternative type. -// auto a = absl::variant(); // Holds an int of value '0'. +// auto a = absl::OTABSL_OPTION_NAMESPACE_NAME::variant(); // Holds an int of value '0'. // // // variants are assignable. // // // copy assignment -// auto v1 = absl::variant("abc"); -// auto v2 = absl::variant(10); +// auto v1 = absl::OTABSL_OPTION_NAMESPACE_NAME::variant("abc"); +// auto v2 = absl::OTABSL_OPTION_NAMESPACE_NAME::variant(10); // v2 = v1; // copy assign // // // move assignment -// auto v1 = absl::variant("abc"); -// v1 = absl::variant(10); +// auto v1 = absl::OTABSL_OPTION_NAMESPACE_NAME::variant("abc"); +// v1 = absl::OTABSL_OPTION_NAMESPACE_NAME::variant(10); // // // assignment through type conversion // a = 128; // variant contains int // a = "128"; // variant contains std::string // -// An `absl::variant` holding a value of one of its alternative types `T` holds -// an allocation of `T` directly within the variant itself. An `absl::variant` +// An `absl::OTABSL_OPTION_NAMESPACE_NAME::variant` holding a value of one of its alternative types `T` holds +// an allocation of `T` directly within the variant itself. An `absl::OTABSL_OPTION_NAMESPACE_NAME::variant` // is not allowed to allocate additional storage, such as dynamic memory, to // allocate the contained value. The contained value shall be allocated in a // region of the variant storage suitably aligned for all alternative types. @@ -124,8 +124,8 @@ class variant; // swap() // -// Swaps two `absl::variant` values. This function is equivalent to `v.swap(w)` -// where `v` and `w` are `absl::variant` types. +// Swaps two `absl::OTABSL_OPTION_NAMESPACE_NAME::variant` values. This function is equivalent to `v.swap(w)` +// where `v` and `w` are `absl::OTABSL_OPTION_NAMESPACE_NAME::variant` types. // // Note that this function requires all alternative types to be both swappable // and move-constructible, because any two variants may refer to either the same @@ -134,8 +134,8 @@ class variant; // template < typename... Ts, - absl::enable_if_t< - absl::conjunction..., + absl::OTABSL_OPTION_NAMESPACE_NAME::enable_if_t< + absl::OTABSL_OPTION_NAMESPACE_NAME::conjunction..., type_traits_internal::IsSwappable...>::value, int> = 0> void swap(variant& v, variant& w) noexcept(noexcept(v.swap(w))) { @@ -144,25 +144,25 @@ void swap(variant& v, variant& w) noexcept(noexcept(v.swap(w))) { // variant_size // -// Returns the number of alternative types available for a given `absl::variant` +// Returns the number of alternative types available for a given `absl::OTABSL_OPTION_NAMESPACE_NAME::variant` // type as a compile-time constant expression. As this is a class template, it // is not generally useful for accessing the number of alternative types of -// any given `absl::variant` instance. +// any given `absl::OTABSL_OPTION_NAMESPACE_NAME::variant` instance. // // Example: // -// auto a = absl::variant; +// auto a = absl::OTABSL_OPTION_NAMESPACE_NAME::variant; // constexpr int num_types = -// absl::variant_size>(); +// absl::OTABSL_OPTION_NAMESPACE_NAME::variant_size>(); // // // You can also use the member constant `value`. // constexpr int num_types = -// absl::variant_size>::value; +// absl::OTABSL_OPTION_NAMESPACE_NAME::variant_size>::value; // -// // `absl::variant_size` is more valuable for use in generic code: +// // `absl::OTABSL_OPTION_NAMESPACE_NAME::variant_size` is more valuable for use in generic code: // template // constexpr bool IsVariantMultivalue() { -// return absl::variant_size() > 1; +// return absl::OTABSL_OPTION_NAMESPACE_NAME::variant_size() > 1; // } // // Note that the set of cv-qualified specializations of `variant_size` are @@ -189,20 +189,20 @@ struct variant_size : variant_size::type {}; // variant_alternative // -// Returns the alternative type for a given `absl::variant` at the passed +// Returns the alternative type for a given `absl::OTABSL_OPTION_NAMESPACE_NAME::variant` at the passed // index value as a compile-time constant expression. As this is a class // template resulting in a type, it is not useful for access of the run-time -// value of any given `absl::variant` variable. +// value of any given `absl::OTABSL_OPTION_NAMESPACE_NAME::variant` variable. // // Example: // // // The type of the 0th alternative is "int". // using alternative_type_0 -// = absl::variant_alternative<0, absl::variant>::type; +// = absl::OTABSL_OPTION_NAMESPACE_NAME::variant_alternative<0, absl::OTABSL_OPTION_NAMESPACE_NAME::variant>::type; // // static_assert(std::is_same::value, ""); // -// // `absl::variant_alternative` is more valuable for use in generic code: +// // `absl::OTABSL_OPTION_NAMESPACE_NAME::variant_alternative` is more valuable for use in generic code: // template // constexpr bool IsFirstElementTrivial() { // return std::is_trivial_v::type>; @@ -244,7 +244,7 @@ struct variant_alternative { // Example: // // using alternative_type_0 -// = absl::variant_alternative_t<0, absl::variant>; +// = absl::OTABSL_OPTION_NAMESPACE_NAME::variant_alternative_t<0, absl::OTABSL_OPTION_NAMESPACE_NAME::variant>; // static_assert(std::is_same::value, ""); template using variant_alternative_t = typename variant_alternative::type; @@ -256,8 +256,8 @@ using variant_alternative_t = typename variant_alternative::type; // // Example: // -// absl::variant foo = 42; -// if (absl::holds_alternative(foo)) { +// absl::OTABSL_OPTION_NAMESPACE_NAME::variant foo = 42; +// if (absl::OTABSL_OPTION_NAMESPACE_NAME::holds_alternative(foo)) { // std::cout << "The variant holds an integer"; // } template @@ -278,22 +278,22 @@ constexpr bool holds_alternative(const variant& v) noexcept { // using a type that is not unique within the variant's set of alternative types // is a compile-time error. If the index of the alternative being specified is // different from the index of the alternative that is currently stored, throws -// `absl::bad_variant_access`. +// `absl::OTABSL_OPTION_NAMESPACE_NAME::bad_variant_access`. // // Example: // -// auto a = absl::variant; +// auto a = absl::OTABSL_OPTION_NAMESPACE_NAME::variant; // // // Get the value by type (if unique). -// int i = absl::get(a); +// int i = absl::OTABSL_OPTION_NAMESPACE_NAME::get(a); // -// auto b = absl::variant; +// auto b = absl::OTABSL_OPTION_NAMESPACE_NAME::variant; // // // Getting the value by a type that is not unique is ill-formed. -// int j = absl::get(b); // Compile Error! +// int j = absl::OTABSL_OPTION_NAMESPACE_NAME::get(b); // Compile Error! // // // Getting value by index not ambiguous and allowed. -// int k = absl::get<1>(b); +// int k = absl::OTABSL_OPTION_NAMESPACE_NAME::get<1>(b); // Overload for getting a variant's lvalue by type. template @@ -303,11 +303,11 @@ constexpr T& get(variant& v) { // NOLINT } // Overload for getting a variant's rvalue by type. -// Note: `absl::move()` is required to allow use of constexpr in C++11. +// Note: `absl::OTABSL_OPTION_NAMESPACE_NAME::move()` is required to allow use of constexpr in C++11. template constexpr T&& get(variant&& v) { return variant_internal::VariantCoreAccess::CheckedAccess< - variant_internal::IndexOf::value>(absl::move(v)); + variant_internal::IndexOf::value>(absl::OTABSL_OPTION_NAMESPACE_NAME::move(v)); } // Overload for getting a variant's const lvalue by type. @@ -318,11 +318,11 @@ constexpr const T& get(const variant& v) { } // Overload for getting a variant's const rvalue by type. -// Note: `absl::move()` is required to allow use of constexpr in C++11. +// Note: `absl::OTABSL_OPTION_NAMESPACE_NAME::move()` is required to allow use of constexpr in C++11. template constexpr const T&& get(const variant&& v) { return variant_internal::VariantCoreAccess::CheckedAccess< - variant_internal::IndexOf::value>(absl::move(v)); + variant_internal::IndexOf::value>(absl::OTABSL_OPTION_NAMESPACE_NAME::move(v)); } // Overload for getting a variant's lvalue by index. @@ -333,11 +333,11 @@ constexpr variant_alternative_t>& get( } // Overload for getting a variant's rvalue by index. -// Note: `absl::move()` is required to allow use of constexpr in C++11. +// Note: `absl::OTABSL_OPTION_NAMESPACE_NAME::move()` is required to allow use of constexpr in C++11. template constexpr variant_alternative_t>&& get( variant&& v) { - return variant_internal::VariantCoreAccess::CheckedAccess(absl::move(v)); + return variant_internal::VariantCoreAccess::CheckedAccess(absl::OTABSL_OPTION_NAMESPACE_NAME::move(v)); } // Overload for getting a variant's const lvalue by index. @@ -348,11 +348,11 @@ constexpr const variant_alternative_t>& get( } // Overload for getting a variant's const rvalue by index. -// Note: `absl::move()` is required to allow use of constexpr in C++11. +// Note: `absl::OTABSL_OPTION_NAMESPACE_NAME::move()` is required to allow use of constexpr in C++11. template constexpr const variant_alternative_t>&& get( const variant&& v) { - return variant_internal::VariantCoreAccess::CheckedAccess(absl::move(v)); + return variant_internal::VariantCoreAccess::CheckedAccess(absl::OTABSL_OPTION_NAMESPACE_NAME::move(v)); } // get_if() @@ -368,7 +368,7 @@ constexpr const variant_alternative_t>&& get( // Overload for getting a pointer to the value stored in the given variant by // index. template -constexpr absl::add_pointer_t>> +constexpr absl::OTABSL_OPTION_NAMESPACE_NAME::add_pointer_t>> get_if(variant* v) noexcept { return (v != nullptr && v->index() == I) ? std::addressof( @@ -379,7 +379,7 @@ get_if(variant* v) noexcept { // Overload for getting a pointer to the const value stored in the given // variant by index. template -constexpr absl::add_pointer_t>> +constexpr absl::OTABSL_OPTION_NAMESPACE_NAME::add_pointer_t>> get_if(const variant* v) noexcept { return (v != nullptr && v->index() == I) ? std::addressof( @@ -390,21 +390,21 @@ get_if(const variant* v) noexcept { // Overload for getting a pointer to the value stored in the given variant by // type. template -constexpr absl::add_pointer_t get_if(variant* v) noexcept { - return absl::get_if::value>(v); +constexpr absl::OTABSL_OPTION_NAMESPACE_NAME::add_pointer_t get_if(variant* v) noexcept { + return absl::OTABSL_OPTION_NAMESPACE_NAME::get_if::value>(v); } // Overload for getting a pointer to the const value stored in the given variant // by type. template -constexpr absl::add_pointer_t get_if( +constexpr absl::OTABSL_OPTION_NAMESPACE_NAME::add_pointer_t get_if( const variant* v) noexcept { - return absl::get_if::value>(v); + return absl::OTABSL_OPTION_NAMESPACE_NAME::get_if::value>(v); } // visit() // -// Calls a provided functor on a given set of variants. `absl::visit()` is +// Calls a provided functor on a given set of variants. `absl::OTABSL_OPTION_NAMESPACE_NAME::visit()` is // commonly used to conditionally inspect the state of a given variant (or set // of variants). // @@ -421,19 +421,19 @@ constexpr absl::add_pointer_t get_if( // } // }; // -// // Declare our variant, and call `absl::visit()` on it. +// // Declare our variant, and call `absl::OTABSL_OPTION_NAMESPACE_NAME::visit()` on it. // // Note that `GetVariant()` returns void in either case. -// absl::variant foo = std::string("foo"); +// absl::OTABSL_OPTION_NAMESPACE_NAME::variant foo = std::string("foo"); // GetVariant visitor; -// absl::visit(visitor, foo); // Prints `The variant's value is: foo' +// absl::OTABSL_OPTION_NAMESPACE_NAME::visit(visitor, foo); // Prints `The variant's value is: foo' template variant_internal::VisitResult visit(Visitor&& vis, Variants&&... vars) { return variant_internal:: - VisitIndices >::value...>::Run( + VisitIndices >::value...>::Run( variant_internal::PerformVisitation{ - std::forward_as_tuple(absl::forward(vars)...), - absl::forward(vis)}, + std::forward_as_tuple(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(vars)...), + absl::OTABSL_OPTION_NAMESPACE_NAME::forward(vis)}, vars.index()...); } @@ -443,7 +443,7 @@ variant_internal::VisitResult visit(Visitor&& vis, // which the first variant type is otherwise not default-constructible. struct monostate {}; -// `absl::monostate` Relational Operators +// `absl::OTABSL_OPTION_NAMESPACE_NAME::monostate` Relational Operators constexpr bool operator<(monostate, monostate) noexcept { return false; } constexpr bool operator>(monostate, monostate) noexcept { return false; } @@ -454,20 +454,20 @@ constexpr bool operator!=(monostate, monostate) noexcept { return false; } //------------------------------------------------------------------------------ -// `absl::variant` Template Definition +// `absl::OTABSL_OPTION_NAMESPACE_NAME::variant` Template Definition //------------------------------------------------------------------------------ template class variant : private variant_internal::VariantBase { - static_assert(absl::conjunction, + static_assert(absl::OTABSL_OPTION_NAMESPACE_NAME::conjunction, std::is_object...>::value, "Attempted to instantiate a variant containing a non-object " "type."); - // Intentionally not qualifying `negation` with `absl::` to work around a bug + // Intentionally not qualifying `negation` with `absl::OTABSL_OPTION_NAMESPACE_NAME::` to work around a bug // in MSVC 2015 with inline namespace and variadic template. - static_assert(absl::conjunction >, + static_assert(absl::OTABSL_OPTION_NAMESPACE_NAME::conjunction >, negation >...>::value, "Attempted to instantiate a variant containing an array type."); - static_assert(absl::conjunction, + static_assert(absl::OTABSL_OPTION_NAMESPACE_NAME::conjunction, std::is_nothrow_destructible...>::value, "Attempted to instantiate a variant containing a non-nothrow " "destructible type."); @@ -499,18 +499,18 @@ class variant : private variant_internal::VariantBase { // // NOTE: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0608r1.html // has been voted passed the design phase in the C++ standard meeting in Mar - // 2018. It will be implemented and integrated into `absl::variant`. + // 2018. It will be implemented and integrated into `absl::OTABSL_OPTION_NAMESPACE_NAME::variant`. template < class T, std::size_t I = std::enable_if< variant_internal::IsNeitherSelfNorInPlace>::value, + absl::OTABSL_OPTION_NAMESPACE_NAME::decay_t>::value, variant_internal::IndexOfConstructedType>::type::value, - class Tj = absl::variant_alternative_t, - absl::enable_if_t::value>* = + class Tj = absl::OTABSL_OPTION_NAMESPACE_NAME::variant_alternative_t, + absl::OTABSL_OPTION_NAMESPACE_NAME::enable_if_t::value>* = nullptr> constexpr variant(T&& t) noexcept(std::is_nothrow_constructible::value) - : Base(variant_internal::EmplaceTag(), absl::forward(t)) {} + : Base(variant_internal::EmplaceTag(), absl::OTABSL_OPTION_NAMESPACE_NAME::forward(t)) {} // Constructs a variant of an alternative type from the arguments through // direct-initialization. @@ -524,7 +524,7 @@ class variant : private variant_internal::VariantBase { constexpr explicit variant(in_place_type_t, Args&&... args) : Base(variant_internal::EmplaceTag< variant_internal::UnambiguousIndexOf::value>(), - absl::forward(args)...) {} + absl::OTABSL_OPTION_NAMESPACE_NAME::forward(args)...) {} // Constructs a variant of an alternative type from an initializer list // and other arguments through direct-initialization. @@ -539,7 +539,7 @@ class variant : private variant_internal::VariantBase { Args&&... args) : Base(variant_internal::EmplaceTag< variant_internal::UnambiguousIndexOf::value>(), - il, absl::forward(args)...) {} + il, absl::OTABSL_OPTION_NAMESPACE_NAME::forward(args)...) {} // Constructs a variant of an alternative type from a provided index, // through value-initialization using the provided forwarded arguments. @@ -548,7 +548,7 @@ class variant : private variant_internal::VariantBase { variant_internal::VariantAlternativeSfinaeT, Args...>::value>::type* = nullptr> constexpr explicit variant(in_place_index_t, Args&&... args) - : Base(variant_internal::EmplaceTag(), absl::forward(args)...) {} + : Base(variant_internal::EmplaceTag(), absl::OTABSL_OPTION_NAMESPACE_NAME::forward(args)...) {} // Constructs a variant of an alternative type from a provided index, // through value-initialization of an initializer list and the provided @@ -560,12 +560,12 @@ class variant : private variant_internal::VariantBase { constexpr explicit variant(in_place_index_t, std::initializer_list il, Args&&... args) : Base(variant_internal::EmplaceTag(), il, - absl::forward(args)...) {} + absl::OTABSL_OPTION_NAMESPACE_NAME::forward(args)...) {} // Destructors // Destroys the variant's currently contained value, provided that - // `absl::valueless_by_exception()` is false. + // `absl::OTABSL_OPTION_NAMESPACE_NAME::valueless_by_exception()` is false. ~variant() = default; // Assignment Operators @@ -580,13 +580,13 @@ class variant : private variant_internal::VariantBase { // // NOTE: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0608r1.html // has been voted passed the design phase in the C++ standard meeting in Mar - // 2018. It will be implemented and integrated into `absl::variant`. + // 2018. It will be implemented and integrated into `absl::OTABSL_OPTION_NAMESPACE_NAME::variant`. template < class T, std::size_t I = std::enable_if< - !std::is_same, variant>::value, + !std::is_same, variant>::value, variant_internal::IndexOfConstructedType>::type::value, - class Tj = absl::variant_alternative_t, + class Tj = absl::OTABSL_OPTION_NAMESPACE_NAME::variant_alternative_t, typename std::enable_if::value && std::is_constructible::value>::type* = nullptr> @@ -595,7 +595,7 @@ class variant : private variant_internal::VariantBase { std::is_nothrow_constructible::value) { variant_internal::VisitIndices::Run( variant_internal::VariantCoreAccess::MakeConversionAssignVisitor( - this, absl::forward(t)), + this, absl::OTABSL_OPTION_NAMESPACE_NAME::forward(t)), index()); return *this; @@ -606,89 +606,89 @@ class variant : private variant_internal::VariantBase { // Constructs a value of the given alternative type T within the variant. The // existing value of the variant is destroyed first (provided that - // `absl::valueless_by_exception()` is false). Requires that T is unambiguous + // `absl::OTABSL_OPTION_NAMESPACE_NAME::valueless_by_exception()` is false). Requires that T is unambiguous // in the variant. // // Example: // - // absl::variant, int, std::string> v; + // absl::OTABSL_OPTION_NAMESPACE_NAME::variant, int, std::string> v; // v.emplace(99); // v.emplace("abc"); template < class T, class... Args, typename std::enable_if::value, variant>, Args...>::value>::type* = nullptr> T& emplace(Args&&... args) { return variant_internal::VariantCoreAccess::Replace< variant_internal::UnambiguousIndexOf::value>( - this, absl::forward(args)...); + this, absl::OTABSL_OPTION_NAMESPACE_NAME::forward(args)...); } // Constructs a value of the given alternative type T within the variant using // an initializer list. The existing value of the variant is destroyed first - // (provided that `absl::valueless_by_exception()` is false). Requires that T + // (provided that `absl::OTABSL_OPTION_NAMESPACE_NAME::valueless_by_exception()` is false). Requires that T // is unambiguous in the variant. // // Example: // - // absl::variant, int, std::string> v; + // absl::OTABSL_OPTION_NAMESPACE_NAME::variant, int, std::string> v; // v.emplace>({0, 1, 2}); template < class T, class U, class... Args, typename std::enable_if::value, variant>, std::initializer_list&, Args...>::value>::type* = nullptr> T& emplace(std::initializer_list il, Args&&... args) { return variant_internal::VariantCoreAccess::Replace< variant_internal::UnambiguousIndexOf::value>( - this, il, absl::forward(args)...); + this, il, absl::OTABSL_OPTION_NAMESPACE_NAME::forward(args)...); } // Destroys the current value of the variant (provided that - // `absl::valueless_by_exception()` is false) and constructs a new value at + // `absl::OTABSL_OPTION_NAMESPACE_NAME::valueless_by_exception()` is false) and constructs a new value at // the given index. // // Example: // - // absl::variant, int, int> v; + // absl::OTABSL_OPTION_NAMESPACE_NAME::variant, int, int> v; // v.emplace<1>(99); // v.emplace<2>(98); // v.emplace(99); // Won't compile. 'int' isn't a unique type. template , + std::is_constructible, Args...>::value>::type* = nullptr> - absl::variant_alternative_t& emplace(Args&&... args) { + absl::OTABSL_OPTION_NAMESPACE_NAME::variant_alternative_t& emplace(Args&&... args) { return variant_internal::VariantCoreAccess::Replace( - this, absl::forward(args)...); + this, absl::OTABSL_OPTION_NAMESPACE_NAME::forward(args)...); } // Destroys the current value of the variant (provided that - // `absl::valueless_by_exception()` is false) and constructs a new value at + // `absl::OTABSL_OPTION_NAMESPACE_NAME::valueless_by_exception()` is false) and constructs a new value at // the given index using an initializer list and the provided arguments. // // Example: // - // absl::variant, int, int> v; + // absl::OTABSL_OPTION_NAMESPACE_NAME::variant, int, int> v; // v.emplace<0>({0, 1, 2}); template , + absl::OTABSL_OPTION_NAMESPACE_NAME::variant_alternative_t, std::initializer_list&, Args...>::value>::type* = nullptr> - absl::variant_alternative_t& emplace(std::initializer_list il, + absl::OTABSL_OPTION_NAMESPACE_NAME::variant_alternative_t& emplace(std::initializer_list il, Args&&... args) { return variant_internal::VariantCoreAccess::Replace( - this, il, absl::forward(args)...); + this, il, absl::OTABSL_OPTION_NAMESPACE_NAME::forward(args)...); } // variant::valueless_by_exception() // // Returns false if and only if the variant currently holds a valid value. constexpr bool valueless_by_exception() const noexcept { - return this->index_ == absl::variant_npos; + return this->index_ == absl::OTABSL_OPTION_NAMESPACE_NAME::variant_npos; } // variant::index() @@ -702,7 +702,7 @@ class variant : private variant_internal::VariantBase { // Swaps the values of two variant objects. // void swap(variant& rhs) noexcept( - absl::conjunction< + absl::OTABSL_OPTION_NAMESPACE_NAME::conjunction< std::is_nothrow_move_constructible, std::is_nothrow_move_constructible..., type_traits_internal::IsNothrowSwappable, @@ -810,14 +810,14 @@ namespace std { // hash() template <> // NOLINT -struct hash { - std::size_t operator()(absl::monostate) const { return 0; } +struct hash { + std::size_t operator()(absl::OTABSL_OPTION_NAMESPACE_NAME::monostate) const { return 0; } }; template // NOLINT -struct hash> - : absl::variant_internal::VariantHashBase, void, - absl::remove_const_t...> {}; +struct hash> + : absl::OTABSL_OPTION_NAMESPACE_NAME::variant_internal::VariantHashBase, void, + absl::OTABSL_OPTION_NAMESPACE_NAME::remove_const_t...> {}; } // namespace std @@ -841,22 +841,22 @@ struct ConversionVisitor { // ConvertVariantTo() // -// Helper functions to convert an `absl::variant` to a variant of another set of +// Helper functions to convert an `absl::OTABSL_OPTION_NAMESPACE_NAME::variant` to a variant of another set of // types, provided that the alternative type of the new variant type can be // converted from any type in the source variant. // // Example: // -// absl::variant InternalReq(const Req&); +// absl::OTABSL_OPTION_NAMESPACE_NAME::variant InternalReq(const Req&); // // // name1 and name2 are convertible to name -// absl::variant ExternalReq(const Req& req) { -// return absl::ConvertVariantTo>( +// absl::OTABSL_OPTION_NAMESPACE_NAME::variant ExternalReq(const Req& req) { +// return absl::OTABSL_OPTION_NAMESPACE_NAME::ConvertVariantTo>( // InternalReq(req)); // } template To ConvertVariantTo(Variant&& variant) { - return absl::visit(variant_internal::ConversionVisitor{}, + return absl::OTABSL_OPTION_NAMESPACE_NAME::visit(variant_internal::ConversionVisitor{}, std::forward(variant)); } diff --git a/api/include/opentelemetry/nostd/internal/absl/utility/utility.h b/api/include/opentelemetry/nostd/internal/absl/utility/utility.h index 8c15e2b8c1..62580cc5af 100644 --- a/api/include/opentelemetry/nostd/internal/absl/utility/utility.h +++ b/api/include/opentelemetry/nostd/internal/absl/utility/utility.h @@ -58,7 +58,7 @@ OTABSL_NAMESPACE_BEGIN // Class template representing a compile-time integer sequence. An instantiation // of `integer_sequence` has a sequence of integers encoded in its // type through its template arguments (which is a common need when -// working with C++11 variadic templates). `absl::integer_sequence` is designed +// working with C++11 variadic templates). `absl::OTABSL_OPTION_NAMESPACE_NAME::integer_sequence` is designed // to be a drop-in replacement for C++14's `std::integer_sequence`. // // Example: @@ -81,7 +81,7 @@ struct integer_sequence { // index_sequence // // A helper template for an `integer_sequence` of `size_t`, -// `absl::index_sequence` is designed to be a drop-in replacement for C++14's +// `absl::OTABSL_OPTION_NAMESPACE_NAME::index_sequence` is designed to be a drop-in replacement for C++14's // `std::index_sequence`. template using index_sequence = integer_sequence; @@ -169,7 +169,7 @@ using std::in_place; // in_place_t // // Tag type used to specify in-place construction, such as with -// `absl::optional`, designed to be a drop-in replacement for C++17's +// `absl::OTABSL_OPTION_NAMESPACE_NAME::optional`, designed to be a drop-in replacement for C++17's // `std::in_place_t`. struct in_place_t {}; @@ -185,7 +185,7 @@ using std::in_place_type_t; // in_place_type_t // // Tag type used for in-place construction when the type to construct needs to -// be specified, such as with `absl::any`, designed to be a drop-in replacement +// be specified, such as with `absl::OTABSL_OPTION_NAMESPACE_NAME::any`, designed to be a drop-in replacement // for C++17's `std::in_place_type_t`. template using in_place_type_t = void (*)(utility_internal::InPlaceTypeTag); @@ -202,7 +202,7 @@ using std::in_place_index_t; // in_place_index_t // // Tag type used for in-place construction when the type to construct needs to -// be specified, such as with `absl::any`, designed to be a drop-in replacement +// be specified, such as with `absl::OTABSL_OPTION_NAMESPACE_NAME::any`, designed to be a drop-in replacement // for C++17's `std::in_place_index_t`. template using in_place_index_t = void (*)(utility_internal::InPlaceIndexTag); @@ -218,8 +218,8 @@ void in_place_index(utility_internal::InPlaceIndexTag) {} // A constexpr version of `std::move()`, designed to be a drop-in replacement // for C++14's `std::move()`. template -constexpr absl::remove_reference_t&& move(T&& t) noexcept { - return static_cast&&>(t); +constexpr absl::OTABSL_OPTION_NAMESPACE_NAME::remove_reference_t&& move(T&& t) noexcept { + return static_cast&&>(t); } // forward() @@ -228,7 +228,7 @@ constexpr absl::remove_reference_t&& move(T&& t) noexcept { // for C++14's `std::forward()`. template constexpr T&& forward( - absl::remove_reference_t& t) noexcept { // NOLINT(runtime/references) + absl::OTABSL_OPTION_NAMESPACE_NAME::remove_reference_t& t) noexcept { // NOLINT(runtime/references) return static_cast(t); } @@ -236,12 +236,12 @@ namespace utility_internal { // Helper method for expanding tuple into a called method. template auto apply_helper(Functor&& functor, Tuple&& t, index_sequence) - -> decltype(absl::OTABSL_OPTION_INLINE_NAMESPACE_NAME::base_internal::Invoke( - absl::forward(functor), - std::get(absl::forward(t))...)) { - return absl::OTABSL_OPTION_INLINE_NAMESPACE_NAME::base_internal::Invoke( - absl::forward(functor), - std::get(absl::forward(t))...); + -> decltype(absl::OTABSL_OPTION_NAMESPACE_NAME::base_internal::Invoke( + absl::OTABSL_OPTION_NAMESPACE_NAME::forward(functor), + std::get(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(t))...)) { + return absl::OTABSL_OPTION_NAMESPACE_NAME::base_internal::Invoke( + absl::OTABSL_OPTION_NAMESPACE_NAME::forward(functor), + std::get(absl::OTABSL_OPTION_NAMESPACE_NAME::forward(t))...); } } // namespace utility_internal @@ -252,7 +252,7 @@ auto apply_helper(Functor&& functor, Tuple&& t, index_sequence) // Each element of the tuple corresponds to an argument of the call (in order). // Both the Callable argument and the tuple argument are perfect-forwarded. // For member-function Callables, the first tuple element acts as the `this` -// pointer. `absl::apply` is designed to be a drop-in replacement for C++17's +// pointer. `absl::OTABSL_OPTION_NAMESPACE_NAME::apply` is designed to be a drop-in replacement for C++17's // `std::apply`. Unlike C++17's `std::apply`, this is not currently `constexpr`. // // Example: @@ -269,57 +269,57 @@ auto apply_helper(Functor&& functor, Tuple&& t, index_sequence) // { // std::tuple tuple1(42, "bar"); // // Invokes the first user function on int, std::string. -// absl::apply(&user_function1, tuple1); +// absl::OTABSL_OPTION_NAMESPACE_NAME::apply(&user_function1, tuple1); // -// std::tuple> tuple2(absl::make_unique()); +// std::tuple> tuple2(absl::OTABSL_OPTION_NAMESPACE_NAME::make_unique()); // // Invokes the user function that takes ownership of the unique // // pointer. -// absl::apply(&user_function2, std::move(tuple2)); +// absl::OTABSL_OPTION_NAMESPACE_NAME::apply(&user_function2, std::move(tuple2)); // -// auto foo = absl::make_unique(); +// auto foo = absl::OTABSL_OPTION_NAMESPACE_NAME::make_unique(); // std::tuple tuple3(foo.get(), 42); // // Invokes the method Bar on foo with one argument, 42. -// absl::apply(&Foo::Bar, tuple3); +// absl::OTABSL_OPTION_NAMESPACE_NAME::apply(&Foo::Bar, tuple3); // // std::tuple tuple4(8, 9); // // Invokes a lambda. -// absl::apply(user_lambda, tuple4); +// absl::OTABSL_OPTION_NAMESPACE_NAME::apply(user_lambda, tuple4); // } template auto apply(Functor&& functor, Tuple&& t) -> decltype(utility_internal::apply_helper( - absl::forward(functor), absl::forward(t), - absl::make_index_sequence(functor), absl::OTABSL_OPTION_NAMESPACE_NAME::forward(t), + absl::OTABSL_OPTION_NAMESPACE_NAME::make_index_sequence::type>::value>{})) { return utility_internal::apply_helper( - absl::forward(functor), absl::forward(t), - absl::make_index_sequence(functor), absl::OTABSL_OPTION_NAMESPACE_NAME::forward(t), + absl::OTABSL_OPTION_NAMESPACE_NAME::make_index_sequence::type>::value>{}); } // exchange // // Replaces the value of `obj` with `new_value` and returns the old value of -// `obj`. `absl::exchange` is designed to be a drop-in replacement for C++14's +// `obj`. `absl::OTABSL_OPTION_NAMESPACE_NAME::exchange` is designed to be a drop-in replacement for C++14's // `std::exchange`. // // Example: // // Foo& operator=(Foo&& other) { -// ptr1_ = absl::exchange(other.ptr1_, nullptr); -// int1_ = absl::exchange(other.int1_, -1); +// ptr1_ = absl::OTABSL_OPTION_NAMESPACE_NAME::exchange(other.ptr1_, nullptr); +// int1_ = absl::OTABSL_OPTION_NAMESPACE_NAME::exchange(other.int1_, -1); // return *this; // } template T exchange(T& obj, U&& new_value) { - T old_value = absl::move(obj); - obj = absl::forward(new_value); + T old_value = absl::OTABSL_OPTION_NAMESPACE_NAME::move(obj); + obj = absl::OTABSL_OPTION_NAMESPACE_NAME::forward(new_value); return old_value; } namespace utility_internal { template -T make_from_tuple_impl(Tuple&& tup, absl::index_sequence) { +T make_from_tuple_impl(Tuple&& tup, absl::OTABSL_OPTION_NAMESPACE_NAME::index_sequence) { return T(std::get(std::forward(tup))...); } } // namespace utility_internal @@ -333,15 +333,15 @@ T make_from_tuple_impl(Tuple&& tup, absl::index_sequence) { // Example: // // std::tuple args("hello world", 5); -// auto s = absl::make_from_tuple(args); +// auto s = absl::OTABSL_OPTION_NAMESPACE_NAME::make_from_tuple(args); // assert(s == "hello"); // template constexpr T make_from_tuple(Tuple&& tup) { return utility_internal::make_from_tuple_impl( std::forward(tup), - absl::make_index_sequence< - std::tuple_size>::value>{}); + absl::OTABSL_OPTION_NAMESPACE_NAME::make_index_sequence< + std::tuple_size>::value>{}); } OTABSL_NAMESPACE_END diff --git a/api/include/opentelemetry/nostd/variant.h b/api/include/opentelemetry/nostd/variant.h index 6f3837c588..02df092d0f 100644 --- a/api/include/opentelemetry/nostd/variant.h +++ b/api/include/opentelemetry/nostd/variant.h @@ -66,7 +66,6 @@ namespace nostd { # ifdef HAVE_ABSEIL using absl::bad_variant_access; -# endif using absl::get; using absl::get_if; using absl::holds_alternative; @@ -75,6 +74,16 @@ using absl::variant; using absl::variant_alternative_t; using absl::variant_size; using absl::visit; +# else +using absl::OTABSL_OPTION_NAMESPACE_NAME::get; +using absl::OTABSL_OPTION_NAMESPACE_NAME::get_if; +using absl::OTABSL_OPTION_NAMESPACE_NAME::holds_alternative; +using absl::OTABSL_OPTION_NAMESPACE_NAME::monostate; +using absl::OTABSL_OPTION_NAMESPACE_NAME::variant; +using absl::OTABSL_OPTION_NAMESPACE_NAME::variant_alternative_t; +using absl::OTABSL_OPTION_NAMESPACE_NAME::variant_size; +using absl::OTABSL_OPTION_NAMESPACE_NAME::visit; +# endif } // namespace nostd OPENTELEMETRY_END_NAMESPACE diff --git a/cmake/opentelemetry-cpp-config.cmake.in b/cmake/opentelemetry-cpp-config.cmake.in index f5c6e5e722..6eead53d28 100644 --- a/cmake/opentelemetry-cpp-config.cmake.in +++ b/cmake/opentelemetry-cpp-config.cmake.in @@ -7,7 +7,6 @@ # # Find the native opentelemetry-cpp includes and library. # -# # Result Variables # ^^^^^^^^^^^^^^^^ # @@ -104,6 +103,14 @@ if (@WITH_HTTP_CLIENT_CURL@ AND NOT @BUILD_SHARED_LIBS@) endif() endif() +if(@WITH_ABSEIL@ OR @WITH_OTLP_GRPC@) + find_package(absl CONFIG) +elseif(OR @WITH_OTLP_HTTP@ OR @WITH_OTLP_FILE@) + if("@Protobuf_VERSION@" VERSION_GREATER_EQUAL "3.22.0") + find_package(absl CONFIG) + endif() +endif() + set_and_check(OPENTELEMETRY_CPP_INCLUDE_DIRS "@PACKAGE_INCLUDE_INSTALL_DIR@") set_and_check(OPENTELEMETRY_CPP_LIBRARY_DIRS "@PACKAGE_CMAKE_INSTALL_LIBDIR@") diff --git a/cmake/opentelemetry-proto.cmake b/cmake/opentelemetry-proto.cmake index fa6e185c13..7831075a27 100644 --- a/cmake/opentelemetry-proto.cmake +++ b/cmake/opentelemetry-proto.cmake @@ -328,15 +328,23 @@ add_library( set_target_version(opentelemetry_proto) # Disable include-what-you-use on generated code. -set_target_properties( - opentelemetry_proto - PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "" -) +set_target_properties(opentelemetry_proto PROPERTIES CXX_INCLUDE_WHAT_YOU_USE + "") -if(WITH_ABSEIL) +if(TARGET absl::bad_variant_access) target_link_libraries(opentelemetry_proto PUBLIC absl::bad_variant_access) endif() +if(NOT Protobuf_INCLUDE_DIRS AND TARGET protobuf::libprotobuf) + get_target_property(Protobuf_INCLUDE_DIRS protobuf::libprotobuf + INTERFACE_INCLUDE_DIRECTORIES) +endif() +if(Protobuf_INCLUDE_DIRS) + target_include_directories( + opentelemetry_proto BEFORE + PUBLIC "$") +endif() + if(WITH_OTLP_GRPC) add_library( opentelemetry_proto_grpc @@ -358,7 +366,7 @@ if(WITH_OTLP_GRPC) INTERFACE_INCLUDE_DIRECTORIES) if(GRPC_INCLUDE_DIRECTORY) target_include_directories( - opentelemetry_proto_grpc + opentelemetry_proto_grpc BEFORE PUBLIC "$") endif() endif() @@ -387,18 +395,14 @@ endif() if(TARGET protobuf::libprotobuf) target_link_libraries(opentelemetry_proto PUBLIC protobuf::libprotobuf) else() # cmake 3.8 or lower - target_include_directories(opentelemetry_proto - PUBLIC ${Protobuf_INCLUDE_DIRS}) target_link_libraries(opentelemetry_proto PUBLIC ${Protobuf_LIBRARIES}) endif() if(WITH_OTLP_GRPC) - if(WITH_ABSEIL) - find_package(absl CONFIG) - if(TARGET absl::synchronization) - target_link_libraries(opentelemetry_proto_grpc - PRIVATE absl::synchronization) - endif() + find_package(absl CONFIG) + if(TARGET absl::synchronization) + target_link_libraries(opentelemetry_proto_grpc + PRIVATE absl::synchronization) endif() endif() diff --git a/cmake/patch-imported-config.cmake b/cmake/patch-imported-config.cmake index a2d22ed398..25d6b2f78f 100644 --- a/cmake/patch-imported-config.cmake +++ b/cmake/patch-imported-config.cmake @@ -29,7 +29,7 @@ if(TARGET CURL::libcurl endif() # abseil targets -if(WITH_ABSEIL) +if(WITH_ABSEIL OR WITH_OTLP_GRPC) project_build_tools_patch_default_imported_config( absl::bad_variant_access absl::raw_logging_internal diff --git a/examples/grpc/CMakeLists.txt b/examples/grpc/CMakeLists.txt index 447f138a0f..21325663ab 100644 --- a/examples/grpc/CMakeLists.txt +++ b/examples/grpc/CMakeLists.txt @@ -39,7 +39,7 @@ else() target_link_libraries(example_grpc_proto PUBLIC gRPC::grpc++ ${Protobuf_LIBRARIES}) endif() -if(WITH_ABSEIL) +if(WITH_ABSEIL OR WITH_OTLP_GRPC) target_link_libraries(example_grpc_proto PUBLIC absl::bad_variant_access) endif() diff --git a/exporters/otlp/BUILD b/exporters/otlp/BUILD index a2dd8f8c65..eb3d23d579 100644 --- a/exporters/otlp/BUILD +++ b/exporters/otlp/BUILD @@ -42,11 +42,13 @@ cc_library( name = "otlp_grpc_client", srcs = [ "src/otlp_grpc_client.cc", + "src/otlp_grpc_client_factory.cc", "src/otlp_grpc_utils.cc", ], hdrs = [ "include/opentelemetry/exporters/otlp/otlp_environment.h", "include/opentelemetry/exporters/otlp/otlp_grpc_client.h", + "include/opentelemetry/exporters/otlp/otlp_grpc_client_factory.h", "include/opentelemetry/exporters/otlp/otlp_grpc_client_options.h", "include/opentelemetry/exporters/otlp/otlp_grpc_utils.h", "include/opentelemetry/exporters/otlp/protobuf_include_prefix.h", diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index 83b35f16a7..34da75b563 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -23,8 +23,10 @@ target_link_libraries(opentelemetry_otlp_recordable if(WITH_OTLP_GRPC) find_package(gRPC REQUIRED) - add_library(opentelemetry_exporter_otlp_grpc_client src/otlp_grpc_client.cc - src/otlp_grpc_utils.cc) + add_library( + opentelemetry_exporter_otlp_grpc_client + src/otlp_grpc_client.cc src/otlp_grpc_client_factory.cc + src/otlp_grpc_utils.cc) set_target_properties(opentelemetry_exporter_otlp_grpc_client PROPERTIES EXPORT_NAME otlp_grpc_client) set_target_version(opentelemetry_exporter_otlp_grpc_client) @@ -45,7 +47,7 @@ if(WITH_OTLP_GRPC) INTERFACE_INCLUDE_DIRECTORIES) if(GRPC_INCLUDE_DIRECTORY) target_include_directories( - opentelemetry_exporter_otlp_grpc_client + opentelemetry_exporter_otlp_grpc_client BEFORE PUBLIC "$") endif() target_include_directories( diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client.h index 89224403a4..3ded3a16eb 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client.h @@ -13,14 +13,18 @@ #include "opentelemetry/exporters/otlp/otlp_grpc_client_options.h" +// clang-format off #include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" +// clang-format on #include "google/protobuf/arena.h" #include "opentelemetry/proto/collector/logs/v1/logs_service.grpc.pb.h" #include "opentelemetry/proto/collector/metrics/v1/metrics_service.grpc.pb.h" #include "opentelemetry/proto/collector/trace/v1/trace_service.grpc.pb.h" +// clang-format off #include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" +// clang-format on OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -28,11 +32,25 @@ namespace exporter namespace otlp { +class OtlpGrpcClient; struct OtlpGrpcClientOptions; - -#ifdef ENABLE_ASYNC_EXPORT struct OtlpGrpcClientAsyncData; -#endif + +class OtlpGrpcClientReferenceGuard +{ +public: + OtlpGrpcClientReferenceGuard() noexcept; + ~OtlpGrpcClientReferenceGuard() noexcept; + + OtlpGrpcClientReferenceGuard(const OtlpGrpcClientReferenceGuard &) = delete; + OtlpGrpcClientReferenceGuard(OtlpGrpcClientReferenceGuard &&) = delete; + OtlpGrpcClientReferenceGuard &operator=(const OtlpGrpcClientReferenceGuard &) = delete; + OtlpGrpcClientReferenceGuard &operator=(OtlpGrpcClientReferenceGuard &&) = delete; + +private: + friend class OtlpGrpcClient; + std::atomic has_value_; +}; /** * The OTLP gRPC client contains utility functions of gRPC. @@ -40,7 +58,7 @@ struct OtlpGrpcClientAsyncData; class OtlpGrpcClient { public: - OtlpGrpcClient(); + OtlpGrpcClient(const OtlpGrpcClientOptions &options); ~OtlpGrpcClient(); @@ -58,20 +76,18 @@ class OtlpGrpcClient /** * Create trace service stub to communicate with the OpenTelemetry Collector. */ - static std::unique_ptr - MakeTraceServiceStub(const OtlpGrpcClientOptions &options); + std::unique_ptr MakeTraceServiceStub(); /** * Create metrics service stub to communicate with the OpenTelemetry Collector. */ - static std::unique_ptr - MakeMetricsServiceStub(const OtlpGrpcClientOptions &options); + std::unique_ptr + MakeMetricsServiceStub(); /** * Create logs service stub to communicate with the OpenTelemetry Collector. */ - static std::unique_ptr - MakeLogsServiceStub(const OtlpGrpcClientOptions &options); + std::unique_ptr MakeLogsServiceStub(); static grpc::Status DelegateExport( proto::collector::trace::v1::TraceService::StubInterface *stub, @@ -94,8 +110,18 @@ class OtlpGrpcClient proto::collector::logs::v1::ExportLogsServiceRequest &&request, proto::collector::logs::v1::ExportLogsServiceResponse *response); -#ifdef ENABLE_ASYNC_EXPORT + void AddReference(OtlpGrpcClientReferenceGuard &guard, + const OtlpGrpcClientOptions &options) noexcept; + /** + * Reomve reference fro a guard object + * + * @param guard guard object to remove reference from + * @return true if there is no more reference to this gRPC client + */ + bool RemoveReference(OtlpGrpcClientReferenceGuard &guard) noexcept; + +#ifdef ENABLE_ASYNC_EXPORT /** * Async export * @param options Options used to message to create gRPC context and stub(if necessary) @@ -155,6 +181,7 @@ class OtlpGrpcClient const proto::collector::logs::v1::ExportLogsServiceRequest &, proto::collector::logs::v1::ExportLogsServiceResponse *)> &&result_callback) noexcept; +#endif /** * Force flush the gRPC client. @@ -167,17 +194,19 @@ class OtlpGrpcClient * timeout is applied. * @return return the status of this operation */ - bool Shutdown(std::chrono::microseconds timeout = std::chrono::microseconds(0)) noexcept; + bool Shutdown(OtlpGrpcClientReferenceGuard &guard, + std::chrono::microseconds timeout = std::chrono::microseconds(0)) noexcept; std::shared_ptr MutableAsyncData(const OtlpGrpcClientOptions &options); + bool IsShutdown() const noexcept; + private: // Stores if this gRPC client had its Shutdown() method called std::atomic is_shutdown_; // Stores shared data between threads of this gRPC client std::shared_ptr async_data_; -#endif }; } // namespace otlp } // namespace exporter diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client_factory.h new file mode 100644 index 0000000000..ded0eadd8e --- /dev/null +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client_factory.h @@ -0,0 +1,36 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/exporters/otlp/otlp_grpc_client_options.h" +#include "opentelemetry/nostd/shared_ptr.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +class OtlpGrpcClientReferenceGuard; +class OtlpGrpcClient; + +/** + * Factory class for OtlpGrpcClient. + */ +class OPENTELEMETRY_EXPORT OtlpGrpcClientFactory +{ +public: + /** + * Create an OtlpGrpcClient using all default options. + */ + static std::shared_ptr Create(const OtlpGrpcClientOptions &options); + + static std::shared_ptr CreateReferenceGuard(); +}; + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter.h index 80346a253d..1022b0dc8f 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter.h @@ -6,12 +6,17 @@ #include #include +// clang-format off #include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" +// clang-format on #include "opentelemetry/proto/collector/trace/v1/trace_service.grpc.pb.h" +// clang-format off #include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" +// clang-format on +#include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/sdk/trace/exporter.h" #include "opentelemetry/exporters/otlp/otlp_environment.h" @@ -23,6 +28,8 @@ namespace exporter namespace otlp { +class OtlpGrpcClientReferenceGuard; + class OtlpGrpcClient; /** @@ -36,11 +43,22 @@ class OtlpGrpcExporter final : public opentelemetry::sdk::trace::SpanExporter */ OtlpGrpcExporter(); + /** + * Create an OtlpGrpcExporter using specified OtlpGrpcClient. + * + * @param options options to create exporter + * @param client the gRPC client to use + */ + OtlpGrpcExporter(const OtlpGrpcExporterOptions &options, + const std::shared_ptr &client); + /** * Create an OtlpGrpcExporter using the given options. */ explicit OtlpGrpcExporter(const OtlpGrpcExporterOptions &options); + ~OtlpGrpcExporter() override; + /** * Create a span recordable. * @return a newly initialized Recordable object @@ -71,20 +89,26 @@ class OtlpGrpcExporter final : public opentelemetry::sdk::trace::SpanExporter bool Shutdown( std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept override; + /** + * Get the Client object + * + * @return return binded gRPC client + */ + const std::shared_ptr &GetClient() const noexcept; + private: // The configuration options associated with this exporter. const OtlpGrpcExporterOptions options_; -#ifdef ENABLE_ASYNC_EXPORT std::shared_ptr client_; -#endif + std::shared_ptr client_reference_guard_; // For testing friend class OtlpGrpcExporterTestPeer; friend class OtlpGrpcLogRecordExporterTestPeer; // Store service stub internally. Useful for testing. - std::unique_ptr trace_service_stub_; + std::shared_ptr trace_service_stub_; /** * Create an OtlpGrpcExporter using the specified service stub. @@ -92,6 +116,16 @@ class OtlpGrpcExporter final : public opentelemetry::sdk::trace::SpanExporter * @param stub the service stub to be used for exporting */ OtlpGrpcExporter(std::unique_ptr stub); + + /** + * Create an OtlpGrpcExporter using the specified service stub and gRPC client. + * Only tests can call this constructor directly. + * @param stub the service stub to be used for exporting + * @param client the gRPC client to use + */ + OtlpGrpcExporter(std::unique_ptr stub, + const std::shared_ptr &client); + std::atomic is_shutdown_{false}; bool isShutdown() const noexcept; }; diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h index 518cf8b82c..24d19d5ced 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h @@ -6,6 +6,7 @@ #include #include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" +#include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/sdk/trace/exporter.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -14,6 +15,8 @@ namespace exporter namespace otlp { +class OtlpGrpcClient; + /** * Factory class for OtlpGrpcExporter. */ @@ -30,6 +33,13 @@ class OPENTELEMETRY_EXPORT OtlpGrpcExporterFactory */ static std::unique_ptr Create( const OtlpGrpcExporterOptions &options); + + /** + * Create an OtlpGrpcExporter using the given options and gRPC client. + */ + static std::unique_ptr Create( + const OtlpGrpcExporterOptions &options, + const std::shared_ptr &client); }; } // namespace otlp diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h index 72af90701f..da278ccd28 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h @@ -4,15 +4,18 @@ #pragma once // clang-format off - #include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" +// clang-format on + #include "opentelemetry/proto/collector/logs/v1/logs_service.grpc.pb.h" -#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" +// clang-format off +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // clang-format on #include "opentelemetry/exporters/otlp/otlp_environment.h" #include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h" +#include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/sdk/logs/exporter.h" #include @@ -23,6 +26,8 @@ namespace exporter namespace otlp { +class OtlpGrpcClientReferenceGuard; + class OtlpGrpcClient; /** @@ -36,12 +41,23 @@ class OtlpGrpcLogRecordExporter : public opentelemetry::sdk::logs::LogRecordExpo */ OtlpGrpcLogRecordExporter(); + /** + * Create an OtlpGrpcLogRecordExporter using specified OtlpGrpcClient. + * + * @param options options to create exporter + * @param client the gRPC client to use + */ + OtlpGrpcLogRecordExporter(const OtlpGrpcLogRecordExporterOptions &options, + const std::shared_ptr &client); + /** * Create an OtlpGrpcLogRecordExporter with user specified options. * @param options An object containing the user's configuration options. */ OtlpGrpcLogRecordExporter(const OtlpGrpcLogRecordExporterOptions &options); + ~OtlpGrpcLogRecordExporter() override; + /** * Creates a recordable that stores the data in protobuf. * @return a newly initialized Recordable object. @@ -72,19 +88,25 @@ class OtlpGrpcLogRecordExporter : public opentelemetry::sdk::logs::LogRecordExpo bool Shutdown( std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept override; + /** + * Get the Client object + * + * @return return binded gRPC client + */ + const std::shared_ptr &GetClient() const noexcept; + private: // Configuration options for the exporter const OtlpGrpcLogRecordExporterOptions options_; -#ifdef ENABLE_ASYNC_EXPORT std::shared_ptr client_; -#endif + std::shared_ptr client_reference_guard_; // For testing friend class OtlpGrpcLogRecordExporterTestPeer; // Store service stub internally. Useful for testing. - std::unique_ptr log_service_stub_; + std::shared_ptr log_service_stub_; /** * Create an OtlpGrpcLogRecordExporter using the specified service stub. @@ -93,6 +115,17 @@ class OtlpGrpcLogRecordExporter : public opentelemetry::sdk::logs::LogRecordExpo */ OtlpGrpcLogRecordExporter( std::unique_ptr stub); + + /** + * Create an OtlpGrpcLogRecordExporter using the specified service stub and gRPC client. + * Only tests can call this constructor directly. + * @param stub the service stub to be used for exporting + * @param client the gRPC client to use + */ + OtlpGrpcLogRecordExporter( + std::unique_ptr stub, + const std::shared_ptr &client); + std::atomic is_shutdown_{false}; bool isShutdown() const noexcept; }; diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h index 7a88615959..e69a20b452 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h @@ -4,6 +4,7 @@ #pragma once #include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h" +#include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/sdk/logs/exporter.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -12,6 +13,8 @@ namespace exporter namespace otlp { +class OtlpGrpcClient; + /** * Factory class for OtlpGrpcLogRecordExporter. */ @@ -24,10 +27,17 @@ class OPENTELEMETRY_EXPORT OtlpGrpcLogRecordExporterFactory static std::unique_ptr Create(); /** - * Create a OtlpGrpcLogRecordExporter. + * Create a OtlpGrpcLogRecordExporter using the given options. */ static std::unique_ptr Create( const OtlpGrpcLogRecordExporterOptions &options); + + /** + * Create a OtlpGrpcLogRecordExporter using the given options and gRPC client. + */ + static std::unique_ptr Create( + const OtlpGrpcLogRecordExporterOptions &options, + const std::shared_ptr &client); }; } // namespace otlp diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h index 3899e926f6..d3d857b3f0 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h @@ -4,15 +4,18 @@ #pragma once // clang-format off - #include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" +// clang-format on + #include "opentelemetry/proto/collector/metrics/v1/metrics_service.grpc.pb.h" -#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" +// clang-format off +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // clang-format on #include "opentelemetry/exporters/otlp/otlp_environment.h" #include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h" +#include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/sdk/metrics/push_metric_exporter.h" #include @@ -23,6 +26,7 @@ namespace exporter namespace otlp { +class OtlpGrpcClientReferenceGuard; class OtlpGrpcClient; /** @@ -36,11 +40,22 @@ class OtlpGrpcMetricExporter : public opentelemetry::sdk::metrics::PushMetricExp */ OtlpGrpcMetricExporter(); + /** + * Create an OtlpGrpcMetricExporter using specified OtlpGrpcClient. + * + * @param options options to create exporter + * @param client the gRPC client to use + */ + OtlpGrpcMetricExporter(const OtlpGrpcMetricExporterOptions &options, + const std::shared_ptr &client); + /** * Create an OtlpGrpcMetricExporter using the given options. */ explicit OtlpGrpcMetricExporter(const OtlpGrpcMetricExporterOptions &options); + ~OtlpGrpcMetricExporter() override; + /** * Get the AggregationTemporality for exporter * @@ -58,13 +73,19 @@ class OtlpGrpcMetricExporter : public opentelemetry::sdk::metrics::PushMetricExp bool Shutdown( std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept override; + /** + * Get the Client object + * + * @return return binded gRPC client + */ + const std::shared_ptr &GetClient() const noexcept; + private: // The configuration options associated with this exporter. const OtlpGrpcMetricExporterOptions options_; -#ifdef ENABLE_ASYNC_EXPORT std::shared_ptr client_; -#endif + std::shared_ptr client_reference_guard_; // Aggregation Temporality selector const sdk::metrics::AggregationTemporalitySelector aggregation_temporality_selector_; @@ -73,7 +94,7 @@ class OtlpGrpcMetricExporter : public opentelemetry::sdk::metrics::PushMetricExp friend class OtlpGrpcMetricExporterTestPeer; // Store service stub internally. Useful for testing. - std::unique_ptr + std::shared_ptr metrics_service_stub_; /** @@ -83,6 +104,17 @@ class OtlpGrpcMetricExporter : public opentelemetry::sdk::metrics::PushMetricExp */ OtlpGrpcMetricExporter( std::unique_ptr stub); + + /** + * Create an OtlpGrpcMetricExporter using the specified service stub and gRPC client. + * Only tests can call this constructor directly. + * @param stub the service stub to be used for exporting + * @param client the gRPC client to use + */ + OtlpGrpcMetricExporter( + std::unique_ptr stub, + const std::shared_ptr &client); + std::atomic is_shutdown_{false}; bool isShutdown() const noexcept; }; diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h index 11b185a384..5d405609b0 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h @@ -6,6 +6,7 @@ #include #include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h" +#include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/sdk/metrics/push_metric_exporter.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -14,6 +15,8 @@ namespace exporter namespace otlp { +class OtlpGrpcClient; + /** * Factory class for OtlpGrpcMetricExporter. */ @@ -26,10 +29,17 @@ class OPENTELEMETRY_EXPORT OtlpGrpcMetricExporterFactory static std::unique_ptr Create(); /** - * Create a OtlpGrpcMetricExporter. + * Create a OtlpGrpcMetricExporter using the given options. */ static std::unique_ptr Create( const OtlpGrpcMetricExporterOptions &options); + + /** + * Create a OtlpGrpcMetricExporter using the given options and gRPC client. + */ + static std::unique_ptr Create( + const OtlpGrpcMetricExporterOptions &options, + const std::shared_ptr &client); }; } // namespace otlp diff --git a/exporters/otlp/src/otlp_grpc_client.cc b/exporters/otlp/src/otlp_grpc_client.cc index 44d86004a9..04382c65e5 100644 --- a/exporters/otlp/src/otlp_grpc_client.cc +++ b/exporters/otlp/src/otlp_grpc_client.cc @@ -78,16 +78,20 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpGrpcAsyncCallData : public OtlpGrpcAsyncCal virtual ~OtlpGrpcAsyncCallData() {} }; } // namespace +#endif struct OtlpGrpcClientAsyncData { + std::chrono::system_clock::duration export_timeout = std::chrono::seconds{10}; // The best performance trade-off of gRPC is having numcpu's threads and one completion queue // per thread, but this exporter should not cost a lot resource and we don't want to create - // too many threads in the process. So we use one completion queue. - grpc::CompletionQueue cq; - + // too many threads in the process. So we use one completion queue and shared context. + std::shared_ptr channel; +#ifdef ENABLE_ASYNC_EXPORT + std::mutex running_calls_lock; + std::unordered_set> running_calls; // Running requests, this is used to limit the number of concurrent requests. std::atomic running_requests{0}; // Request counter is used to record ForceFlush. @@ -98,13 +102,16 @@ struct OtlpGrpcClientAsyncData // Condition variable and mutex to control the concurrency count of running requests. std::mutex session_waker_lock; std::condition_variable session_waker; +#endif + + // Reference count of OtlpGrpcClient + std::atomic reference_count{0}; // Do not use OtlpGrpcClientAsyncData() = default; here, some versions of GCC&Clang have BUGs // and may not initialize the member correctly. See also // https://stackoverflow.com/questions/53408962/try-to-understand-compiler-error-message-default-member-initializer-required-be OtlpGrpcClientAsyncData() {} }; -#endif namespace { @@ -199,6 +206,11 @@ static sdk::common::ExportResult InternalDelegateAsyncExport( ++async_data->start_request_counter; ++async_data->running_requests; + { + std::lock_guard lock{async_data->running_calls_lock}; + async_data->running_calls.insert( + std::static_pointer_cast(call_data)); + } // Some old toolchains can only use gRPC 1.33 and it's experimental. # if defined(GRPC_CPP_VERSION_MAJOR) && \ (GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039 @@ -208,6 +220,12 @@ static sdk::common::ExportResult InternalDelegateAsyncExport( # endif ->Export(call_data->grpc_context.get(), call_data->request, call_data->response, [call_data, async_data, export_data_name](::grpc::Status grpc_status) { + { + std::lock_guard lock{async_data->running_calls_lock}; + async_data->running_calls.erase( + std::static_pointer_cast(call_data)); + } + --async_data->running_requests; ++async_data->finished_request_counter; @@ -247,18 +265,38 @@ static sdk::common::ExportResult InternalDelegateAsyncExport( #endif } // namespace -OtlpGrpcClient::OtlpGrpcClient() -#ifdef ENABLE_ASYNC_EXPORT - : is_shutdown_(false) -#endif -{} +OtlpGrpcClientReferenceGuard::OtlpGrpcClientReferenceGuard() noexcept : has_value_{false} {} + +OtlpGrpcClientReferenceGuard::~OtlpGrpcClientReferenceGuard() noexcept {} + +OtlpGrpcClient::OtlpGrpcClient(const OtlpGrpcClientOptions &options) : is_shutdown_(false) +{ + std::shared_ptr async_data = MutableAsyncData(options); + async_data->channel = MakeChannel(options); +} OtlpGrpcClient::~OtlpGrpcClient() { -#ifdef ENABLE_ASYNC_EXPORT std::shared_ptr async_data; async_data.swap(async_data_); +#ifdef ENABLE_ASYNC_EXPORT + if (async_data) + { + std::unordered_set> running_calls; + { + std::lock_guard lock(async_data->running_calls_lock); + running_calls = async_data->running_calls; + } + for (auto &call_data : running_calls) + { + if (call_data && call_data->grpc_context) + { + call_data->grpc_context->TryCancel(); + } + } + } + while (async_data && async_data->running_requests.load(std::memory_order_acquire) > 0) { std::unique_lock lock{async_data->session_waker_lock}; @@ -357,21 +395,33 @@ std::unique_ptr OtlpGrpcClient::MakeClientContext( } std::unique_ptr -OtlpGrpcClient::MakeTraceServiceStub(const OtlpGrpcClientOptions &options) +OtlpGrpcClient::MakeTraceServiceStub() { - return proto::collector::trace::v1::TraceService::NewStub(MakeChannel(options)); + if (!async_data_ || !async_data_->channel) + { + return nullptr; + } + return proto::collector::trace::v1::TraceService::NewStub(async_data_->channel); } std::unique_ptr -OtlpGrpcClient::MakeMetricsServiceStub(const OtlpGrpcClientOptions &options) +OtlpGrpcClient::MakeMetricsServiceStub() { - return proto::collector::metrics::v1::MetricsService::NewStub(MakeChannel(options)); + if (!async_data_ || !async_data_->channel) + { + return nullptr; + } + return proto::collector::metrics::v1::MetricsService::NewStub(async_data_->channel); } std::unique_ptr -OtlpGrpcClient::MakeLogsServiceStub(const OtlpGrpcClientOptions &options) +OtlpGrpcClient::MakeLogsServiceStub() { - return proto::collector::logs::v1::LogsService::NewStub(MakeChannel(options)); + if (!async_data_ || !async_data_->channel) + { + return nullptr; + } + return proto::collector::logs::v1::LogsService::NewStub(async_data_->channel); } grpc::Status OtlpGrpcClient::DelegateExport( @@ -404,6 +454,35 @@ grpc::Status OtlpGrpcClient::DelegateExport( return stub->Export(context.get(), request, response); } +void OtlpGrpcClient::AddReference(OtlpGrpcClientReferenceGuard &guard, + const OtlpGrpcClientOptions &options) noexcept +{ + if (false == guard.has_value_.exchange(true, std::memory_order_acq_rel)) + { + MutableAsyncData(options)->reference_count.fetch_add(1, std::memory_order_acq_rel); + } +} + +bool OtlpGrpcClient::RemoveReference(OtlpGrpcClientReferenceGuard &guard) noexcept +{ + auto async_data = async_data_; + if (true == guard.has_value_.exchange(false, std::memory_order_acq_rel)) + { + if (async_data) + { + int64_t left = async_data->reference_count.fetch_sub(1, std::memory_order_acq_rel); + return left <= 1; + } + } + + if (async_data) + { + return async_data->reference_count.load(std::memory_order_acquire) <= 0; + } + + return true; +} + #ifdef ENABLE_ASYNC_EXPORT /** @@ -507,26 +586,37 @@ sdk::common::ExportResult OtlpGrpcClient::DelegateAsyncExport( "log(s)"); } +#endif + std::shared_ptr OtlpGrpcClient::MutableAsyncData( const OtlpGrpcClientOptions &options) { if (!async_data_) { - async_data_ = std::make_shared(); - async_data_->export_timeout = options.timeout; + async_data_ = std::make_shared(); + async_data_->export_timeout = options.timeout; +#ifdef ENABLE_ASYNC_EXPORT async_data_->max_concurrent_requests = options.max_concurrent_requests; +#endif } return async_data_; } -bool OtlpGrpcClient::ForceFlush(std::chrono::microseconds timeout) noexcept +bool OtlpGrpcClient::IsShutdown() const noexcept +{ + return is_shutdown_.load(std::memory_order_acquire); +} + +bool OtlpGrpcClient::ForceFlush( + OPENTELEMETRY_MAYBE_UNUSED std::chrono::microseconds timeout) noexcept { if (!async_data_) { return true; } +#ifdef ENABLE_ASYNC_EXPORT std::size_t request_counter = async_data_->start_request_counter.load(std::memory_order_acquire); if (request_counter <= async_data_->finished_request_counter.load(std::memory_order_acquire)) { @@ -565,21 +655,46 @@ bool OtlpGrpcClient::ForceFlush(std::chrono::microseconds timeout) noexcept } return timeout_steady > std::chrono::steady_clock::duration::zero(); +#else + return true; +#endif } -bool OtlpGrpcClient::Shutdown(std::chrono::microseconds timeout) noexcept +bool OtlpGrpcClient::Shutdown(OtlpGrpcClientReferenceGuard &guard, + OPENTELEMETRY_MAYBE_UNUSED std::chrono::microseconds timeout) noexcept { if (!async_data_) { return true; } + bool last_reference_removed = RemoveReference(guard); bool force_flush_result; - if (false == is_shutdown_.exchange(true, std::memory_order_acq_rel)) + if (last_reference_removed && false == is_shutdown_.exchange(true, std::memory_order_acq_rel)) { + OTEL_INTERNAL_LOG_DEBUG("[OTLP GRPC Client] DEBUG: OtlpGrpcClient start to shitdown"); force_flush_result = ForceFlush(timeout); - async_data_->cq.Shutdown(); +#ifdef ENABLE_ASYNC_EXPORT + std::unordered_set> running_calls; + { + std::lock_guard lock(async_data_->running_calls_lock); + running_calls = async_data_->running_calls; + } + if (!running_calls.empty()) + { + OTEL_INTERNAL_LOG_WARN( + "[OTLP GRPC Client] WARN: OtlpGrpcClient shutdown timeout, try to cancel " + << running_calls.size() << " running calls."); + } + for (auto &call_data : running_calls) + { + if (call_data && call_data->grpc_context) + { + call_data->grpc_context->TryCancel(); + } + } +#endif } else { @@ -589,8 +704,6 @@ bool OtlpGrpcClient::Shutdown(std::chrono::microseconds timeout) noexcept return force_flush_result; } -#endif - } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_grpc_client_factory.cc b/exporters/otlp/src/otlp_grpc_client_factory.cc new file mode 100644 index 0000000000..310593a77a --- /dev/null +++ b/exporters/otlp/src/otlp_grpc_client_factory.cc @@ -0,0 +1,27 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/otlp/otlp_grpc_client_factory.h" +#include + +#include "opentelemetry/exporters/otlp/otlp_grpc_client.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +std::shared_ptr OtlpGrpcClientFactory::Create(const OtlpGrpcClientOptions &options) +{ + return std::make_shared(options); +} + +std::shared_ptr OtlpGrpcClientFactory::CreateReferenceGuard() +{ + return std::make_shared(); +} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_grpc_exporter.cc b/exporters/otlp/src/otlp_grpc_exporter.cc index ed0fc74518..e4012c2ebf 100644 --- a/exporters/otlp/src/otlp_grpc_exporter.cc +++ b/exporters/otlp/src/otlp_grpc_exporter.cc @@ -12,6 +12,7 @@ #include "opentelemetry/exporters/otlp/otlp_recordable_utils.h" #include "opentelemetry/sdk_config.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_client_factory.h" #include "opentelemetry/exporters/otlp/otlp_grpc_utils.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -23,22 +24,53 @@ namespace otlp OtlpGrpcExporter::OtlpGrpcExporter() : OtlpGrpcExporter(OtlpGrpcExporterOptions()) {} -OtlpGrpcExporter::OtlpGrpcExporter(const OtlpGrpcExporterOptions &options) - : options_(options), -#ifdef ENABLE_ASYNC_EXPORT - client_(std::make_shared()), -#endif - trace_service_stub_(OtlpGrpcClient::MakeTraceServiceStub(options)) -{} +OtlpGrpcExporter::OtlpGrpcExporter(const OtlpGrpcExporterOptions &options) : options_(options) +{ + client_ = OtlpGrpcClientFactory::Create(options_); + client_reference_guard_ = OtlpGrpcClientFactory::CreateReferenceGuard(); + client_->AddReference(*client_reference_guard_, options_); + + trace_service_stub_ = client_->MakeTraceServiceStub(); +} OtlpGrpcExporter::OtlpGrpcExporter( std::unique_ptr stub) + : options_(OtlpGrpcExporterOptions()), trace_service_stub_(std::move(stub)) +{ + client_ = OtlpGrpcClientFactory::Create(options_); + client_reference_guard_ = OtlpGrpcClientFactory::CreateReferenceGuard(); + client_->AddReference(*client_reference_guard_, options_); +} + +OtlpGrpcExporter::OtlpGrpcExporter(const OtlpGrpcExporterOptions &options, + const std::shared_ptr &client) + : options_(options), + client_(client), + client_reference_guard_(OtlpGrpcClientFactory::CreateReferenceGuard()) +{ + client_->AddReference(*client_reference_guard_, options_); + + trace_service_stub_ = client_->MakeTraceServiceStub(); +} + +OtlpGrpcExporter::OtlpGrpcExporter( + std::unique_ptr stub, + const std::shared_ptr &client) : options_(OtlpGrpcExporterOptions()), -#ifdef ENABLE_ASYNC_EXPORT - client_(std::make_shared()), -#endif + client_(client), + client_reference_guard_(OtlpGrpcClientFactory::CreateReferenceGuard()), trace_service_stub_(std::move(stub)) -{} +{ + client_->AddReference(*client_reference_guard_, options_); +} + +OtlpGrpcExporter::~OtlpGrpcExporter() +{ + if (client_) + { + client_->RemoveReference(*client_reference_guard_); + } +} // ----------------------------- Exporter methods ------------------------------ @@ -50,12 +82,21 @@ std::unique_ptr OtlpGrpcExporter::MakeRecordable() noexc sdk::common::ExportResult OtlpGrpcExporter::Export( const nostd::span> &spans) noexcept { - if (isShutdown()) + std::shared_ptr client = client_; + if (isShutdown() || !client) { OTEL_INTERNAL_LOG_ERROR("[OTLP gRPC] Exporting " << spans.size() << " span(s) failed, exporter is shutdown"); return sdk::common::ExportResult::kFailure; } + + if (!trace_service_stub_) + { + OTEL_INTERNAL_LOG_ERROR("[OTLP gRPC] Exporting " + << spans.size() << " span(s) failed, service stub unavailable"); + return sdk::common::ExportResult::kFailure; + } + if (spans.empty()) { return sdk::common::ExportResult::kSuccess; @@ -82,13 +123,16 @@ sdk::common::ExportResult OtlpGrpcExporter::Export( #ifdef ENABLE_ASYNC_EXPORT if (options_.max_concurrent_requests > 1) { - return client_->DelegateAsyncExport( + return client->DelegateAsyncExport( options_, trace_service_stub_.get(), std::move(context), std::move(arena), std::move(*request), - [](opentelemetry::sdk::common::ExportResult result, - std::unique_ptr &&, - const proto::collector::trace::v1::ExportTraceServiceRequest &request, - proto::collector::trace::v1::ExportTraceServiceResponse *) { + // Capture the trace_service_stub_ to ensure it is not destroyed before the callback is + // called. + [trace_service_stub = trace_service_stub_]( + opentelemetry::sdk::common::ExportResult result, + std::unique_ptr &&, + const proto::collector::trace::v1::ExportTraceServiceRequest &request, + proto::collector::trace::v1::ExportTraceServiceResponse *) { if (result != opentelemetry::sdk::common::ExportResult::kSuccess) { OTEL_INTERNAL_LOG_ERROR("[OTLP TRACE GRPC Exporter] ERROR: Export " @@ -125,22 +169,27 @@ sdk::common::ExportResult OtlpGrpcExporter::Export( bool OtlpGrpcExporter::ForceFlush( OPENTELEMETRY_MAYBE_UNUSED std::chrono::microseconds timeout) noexcept { -#ifdef ENABLE_ASYNC_EXPORT - return client_->ForceFlush(timeout); -#else - return true; -#endif + // Maybe already shutdown, we need to keep thread-safety here. + std::shared_ptr client = client_; + if (!client) + { + return true; + } + return client->ForceFlush(timeout); } bool OtlpGrpcExporter::Shutdown( OPENTELEMETRY_MAYBE_UNUSED std::chrono::microseconds timeout) noexcept { is_shutdown_ = true; -#ifdef ENABLE_ASYNC_EXPORT - return client_->Shutdown(timeout); -#else - return true; -#endif + // Maybe already shutdown, we need to keep thread-safety here. + std::shared_ptr client; + client.swap(client_); + if (!client) + { + return true; + } + return client->Shutdown(*client_reference_guard_, timeout); } bool OtlpGrpcExporter::isShutdown() const noexcept @@ -148,6 +197,11 @@ bool OtlpGrpcExporter::isShutdown() const noexcept return is_shutdown_; } +const std::shared_ptr &OtlpGrpcExporter::GetClient() const noexcept +{ + return client_; +} + } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_grpc_exporter_factory.cc b/exporters/otlp/src/otlp_grpc_exporter_factory.cc index f8ee7e3594..5ed832a3cd 100644 --- a/exporters/otlp/src/otlp_grpc_exporter_factory.cc +++ b/exporters/otlp/src/otlp_grpc_exporter_factory.cc @@ -27,6 +27,15 @@ std::unique_ptr OtlpGrpcExporterFactory return exporter; } +std::unique_ptr OtlpGrpcExporterFactory::Create( + const OtlpGrpcExporterOptions &options, + const std::shared_ptr &client) +{ + std::unique_ptr exporter( + new OtlpGrpcExporter(options, client)); + return exporter; +} + } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_grpc_log_record_exporter.cc b/exporters/otlp/src/otlp_grpc_log_record_exporter.cc index 1069703f96..fe05be7b30 100644 --- a/exporters/otlp/src/otlp_grpc_log_record_exporter.cc +++ b/exporters/otlp/src/otlp_grpc_log_record_exporter.cc @@ -6,19 +6,20 @@ #include "opentelemetry/common/macros.h" #include "opentelemetry/exporters/otlp/otlp_grpc_client.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_client_factory.h" #include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h" #include "opentelemetry/exporters/otlp/otlp_log_recordable.h" #include "opentelemetry/exporters/otlp/otlp_recordable_utils.h" // clang-format off - #include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" +// clang-format on -#include "opentelemetry/proto/collector/logs/v1/logs_service.pb.h" #include "opentelemetry/proto/collector/logs/v1/logs_service.grpc.pb.h" +#include "opentelemetry/proto/collector/logs/v1/logs_service.pb.h" +// clang-format off #include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" - // clang-format on #include "opentelemetry/sdk/common/global_log_handler.h" @@ -36,21 +37,54 @@ OtlpGrpcLogRecordExporter::OtlpGrpcLogRecordExporter() OtlpGrpcLogRecordExporter::OtlpGrpcLogRecordExporter( const OtlpGrpcLogRecordExporterOptions &options) - : options_(options), -#ifdef ENABLE_ASYNC_EXPORT - client_(std::make_shared()), -#endif - log_service_stub_(OtlpGrpcClient::MakeLogsServiceStub(options)) -{} + : options_(options) +{ + client_ = OtlpGrpcClientFactory::Create(options_); + client_reference_guard_ = OtlpGrpcClientFactory::CreateReferenceGuard(); + client_->AddReference(*client_reference_guard_, options_); + + log_service_stub_ = client_->MakeLogsServiceStub(); +} OtlpGrpcLogRecordExporter::OtlpGrpcLogRecordExporter( std::unique_ptr stub) + : options_(OtlpGrpcLogRecordExporterOptions()), log_service_stub_(std::move(stub)) +{ + client_ = OtlpGrpcClientFactory::Create(options_); + client_reference_guard_ = OtlpGrpcClientFactory::CreateReferenceGuard(); + client_->AddReference(*client_reference_guard_, options_); +} + +OtlpGrpcLogRecordExporter::OtlpGrpcLogRecordExporter( + const OtlpGrpcLogRecordExporterOptions &options, + const std::shared_ptr &client) + : options_(options), + client_(client), + client_reference_guard_(OtlpGrpcClientFactory::CreateReferenceGuard()) +{ + client_->AddReference(*client_reference_guard_, options_); + + log_service_stub_ = client_->MakeLogsServiceStub(); +} + +OtlpGrpcLogRecordExporter::OtlpGrpcLogRecordExporter( + std::unique_ptr stub, + const std::shared_ptr &client) : options_(OtlpGrpcLogRecordExporterOptions()), -#ifdef ENABLE_ASYNC_EXPORT - client_(std::make_shared()), -#endif + client_(client), + client_reference_guard_(OtlpGrpcClientFactory::CreateReferenceGuard()), log_service_stub_(std::move(stub)) -{} +{ + client_->AddReference(*client_reference_guard_, options_); +} + +OtlpGrpcLogRecordExporter::~OtlpGrpcLogRecordExporter() +{ + if (client_) + { + client_->RemoveReference(*client_reference_guard_); + } +} // ----------------------------- Exporter methods ------------------------------ @@ -63,12 +97,20 @@ OtlpGrpcLogRecordExporter::MakeRecordable() noexcept opentelemetry::sdk::common::ExportResult OtlpGrpcLogRecordExporter::Export( const nostd::span> &logs) noexcept { - if (isShutdown()) + std::shared_ptr client = client_; + if (isShutdown() || !client) { OTEL_INTERNAL_LOG_ERROR("[OTLP gRPC log] Exporting " << logs.size() << " log(s) failed, exporter is shutdown"); return sdk::common::ExportResult::kFailure; } + if (!log_service_stub_) + { + OTEL_INTERNAL_LOG_ERROR("[OTLP gRPC] Exporting " << logs.size() + << " log(s) failed, service stub unavailable"); + return sdk::common::ExportResult::kFailure; + } + if (logs.empty()) { return sdk::common::ExportResult::kSuccess; @@ -95,13 +137,16 @@ opentelemetry::sdk::common::ExportResult OtlpGrpcLogRecordExporter::Export( #ifdef ENABLE_ASYNC_EXPORT if (options_.max_concurrent_requests > 1) { - return client_->DelegateAsyncExport( + return client->DelegateAsyncExport( options_, log_service_stub_.get(), std::move(context), std::move(arena), std::move(*request), - [](opentelemetry::sdk::common::ExportResult result, - std::unique_ptr &&, - const proto::collector::logs::v1::ExportLogsServiceRequest &request, - proto::collector::logs::v1::ExportLogsServiceResponse *) { + // Capture log_service_stub by value to ensure it is not destroyed before the callback is + // called. + [log_service_stub = log_service_stub_]( + opentelemetry::sdk::common::ExportResult result, + std::unique_ptr &&, + const proto::collector::logs::v1::ExportLogsServiceRequest &request, + proto::collector::logs::v1::ExportLogsServiceResponse *) { if (result != opentelemetry::sdk::common::ExportResult::kSuccess) { OTEL_INTERNAL_LOG_ERROR("[OTLP LOG GRPC Exporter] ERROR: Export " @@ -139,21 +184,26 @@ bool OtlpGrpcLogRecordExporter::Shutdown( OPENTELEMETRY_MAYBE_UNUSED std::chrono::microseconds timeout) noexcept { is_shutdown_ = true; -#ifdef ENABLE_ASYNC_EXPORT - return client_->Shutdown(timeout); -#else - return true; -#endif + // Maybe already shutdown, we need to keep thread-safety here. + std::shared_ptr client; + client.swap(client_); + if (!client) + { + return true; + } + return client->Shutdown(*client_reference_guard_, timeout); } bool OtlpGrpcLogRecordExporter::ForceFlush( OPENTELEMETRY_MAYBE_UNUSED std::chrono::microseconds timeout) noexcept { -#ifdef ENABLE_ASYNC_EXPORT - return client_->ForceFlush(timeout); -#else - return true; -#endif + // Maybe already shutdown, we need to keep thread-safety here. + std::shared_ptr client = client_; + if (!client) + { + return true; + } + return client->ForceFlush(timeout); } bool OtlpGrpcLogRecordExporter::isShutdown() const noexcept @@ -161,6 +211,11 @@ bool OtlpGrpcLogRecordExporter::isShutdown() const noexcept return is_shutdown_; } +const std::shared_ptr &OtlpGrpcLogRecordExporter::GetClient() const noexcept +{ + return client_; +} + } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_grpc_log_record_exporter_factory.cc b/exporters/otlp/src/otlp_grpc_log_record_exporter_factory.cc index 7229de569a..4b519e37e8 100644 --- a/exporters/otlp/src/otlp_grpc_log_record_exporter_factory.cc +++ b/exporters/otlp/src/otlp_grpc_log_record_exporter_factory.cc @@ -28,6 +28,15 @@ OtlpGrpcLogRecordExporterFactory::Create(const OtlpGrpcLogRecordExporterOptions return exporter; } +std::unique_ptr +OtlpGrpcLogRecordExporterFactory::Create(const OtlpGrpcLogRecordExporterOptions &options, + const std::shared_ptr &client) +{ + std::unique_ptr exporter( + new OtlpGrpcLogRecordExporter(options, client)); + return exporter; +} + } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_grpc_metric_exporter.cc b/exporters/otlp/src/otlp_grpc_metric_exporter.cc index 6a78149eaa..1723dd557a 100644 --- a/exporters/otlp/src/otlp_grpc_metric_exporter.cc +++ b/exporters/otlp/src/otlp_grpc_metric_exporter.cc @@ -6,6 +6,7 @@ #include "opentelemetry/common/macros.h" #include "opentelemetry/exporters/otlp/otlp_grpc_client.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_client_factory.h" #include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h" #include "opentelemetry/exporters/otlp/otlp_metric_utils.h" @@ -24,24 +25,57 @@ OtlpGrpcMetricExporter::OtlpGrpcMetricExporter() OtlpGrpcMetricExporter::OtlpGrpcMetricExporter(const OtlpGrpcMetricExporterOptions &options) : options_(options), -#ifdef ENABLE_ASYNC_EXPORT - client_(std::make_shared()), -#endif aggregation_temporality_selector_{ - OtlpMetricUtils::ChooseTemporalitySelector(options_.aggregation_temporality)}, - metrics_service_stub_(OtlpGrpcClient::MakeMetricsServiceStub(options)) -{} + OtlpMetricUtils::ChooseTemporalitySelector(options_.aggregation_temporality)} +{ + client_ = OtlpGrpcClientFactory::Create(options_); + client_reference_guard_ = OtlpGrpcClientFactory::CreateReferenceGuard(); + client_->AddReference(*client_reference_guard_, options_); + + metrics_service_stub_ = client_->MakeMetricsServiceStub(); +} OtlpGrpcMetricExporter::OtlpGrpcMetricExporter( std::unique_ptr stub) : options_(OtlpGrpcMetricExporterOptions()), -#ifdef ENABLE_ASYNC_EXPORT - client_(std::make_shared()), -#endif aggregation_temporality_selector_{ OtlpMetricUtils::ChooseTemporalitySelector(options_.aggregation_temporality)}, metrics_service_stub_(std::move(stub)) -{} +{ + client_ = OtlpGrpcClientFactory::Create(options_); + client_reference_guard_ = OtlpGrpcClientFactory::CreateReferenceGuard(); + client_->AddReference(*client_reference_guard_, options_); +} + +OtlpGrpcMetricExporter::OtlpGrpcMetricExporter(const OtlpGrpcMetricExporterOptions &options, + const std::shared_ptr &client) + : options_(options), + client_(client), + client_reference_guard_(OtlpGrpcClientFactory::CreateReferenceGuard()) +{ + client_->AddReference(*client_reference_guard_, options_); + + metrics_service_stub_ = client_->MakeMetricsServiceStub(); +} + +OtlpGrpcMetricExporter::OtlpGrpcMetricExporter( + std::unique_ptr stub, + const std::shared_ptr &client) + : options_(OtlpGrpcMetricExporterOptions()), + client_(client), + client_reference_guard_(OtlpGrpcClientFactory::CreateReferenceGuard()), + metrics_service_stub_(std::move(stub)) +{ + client_->AddReference(*client_reference_guard_, options_); +} + +OtlpGrpcMetricExporter::~OtlpGrpcMetricExporter() +{ + if (client_) + { + client_->RemoveReference(*client_reference_guard_); + } +} // ----------------------------- Exporter methods ------------------------------ @@ -54,14 +88,23 @@ sdk::metrics::AggregationTemporality OtlpGrpcMetricExporter::GetAggregationTempo opentelemetry::sdk::common::ExportResult OtlpGrpcMetricExporter::Export( const opentelemetry::sdk::metrics::ResourceMetrics &data) noexcept { - - if (isShutdown()) + std::shared_ptr client = client_; + if (isShutdown() || !client) { OTEL_INTERNAL_LOG_ERROR("[OTLP METRICS gRPC] Exporting " << data.scope_metric_data_.size() << " metric(s) failed, exporter is shutdown"); return sdk::common::ExportResult::kFailure; } + + if (!metrics_service_stub_) + { + OTEL_INTERNAL_LOG_ERROR("[OTLP gRPC] Exporting " + << data.scope_metric_data_.size() + << " metric(s) failed, service stub unavailable"); + return sdk::common::ExportResult::kFailure; + } + if (data.scope_metric_data_.empty()) { return sdk::common::ExportResult::kSuccess; @@ -88,13 +131,16 @@ opentelemetry::sdk::common::ExportResult OtlpGrpcMetricExporter::Export( #ifdef ENABLE_ASYNC_EXPORT if (options_.max_concurrent_requests > 1) { - return client_->DelegateAsyncExport( + return client->DelegateAsyncExport( options_, metrics_service_stub_.get(), std::move(context), std::move(arena), std::move(*request), - [](opentelemetry::sdk::common::ExportResult result, - std::unique_ptr &&, - const proto::collector::metrics::v1::ExportMetricsServiceRequest &request, - proto::collector::metrics::v1::ExportMetricsServiceResponse *) { + // Capture the metrics_service_stub_ to ensure it is not destroyed before the callback is + // called. + [metrics_service_stub = metrics_service_stub_]( + opentelemetry::sdk::common::ExportResult result, + std::unique_ptr &&, + const proto::collector::metrics::v1::ExportMetricsServiceRequest &request, + proto::collector::metrics::v1::ExportMetricsServiceResponse *) { if (result != opentelemetry::sdk::common::ExportResult::kSuccess) { OTEL_INTERNAL_LOG_ERROR("[OTLP METRIC GRPC Exporter] ERROR: Export " @@ -131,22 +177,27 @@ opentelemetry::sdk::common::ExportResult OtlpGrpcMetricExporter::Export( bool OtlpGrpcMetricExporter::ForceFlush( OPENTELEMETRY_MAYBE_UNUSED std::chrono::microseconds timeout) noexcept { -#ifdef ENABLE_ASYNC_EXPORT - return client_->ForceFlush(timeout); -#else - return true; -#endif + // Maybe already shutdown, we need to keep thread-safety here. + std::shared_ptr client = client_; + if (!client) + { + return true; + } + return client->ForceFlush(timeout); } bool OtlpGrpcMetricExporter::Shutdown( OPENTELEMETRY_MAYBE_UNUSED std::chrono::microseconds timeout) noexcept { is_shutdown_ = true; -#ifdef ENABLE_ASYNC_EXPORT - return client_->Shutdown(timeout); -#else - return true; -#endif + // Maybe already shutdown, we need to keep thread-safety here. + std::shared_ptr client; + client.swap(client_); + if (!client) + { + return true; + } + return client->Shutdown(*client_reference_guard_, timeout); } bool OtlpGrpcMetricExporter::isShutdown() const noexcept @@ -154,6 +205,11 @@ bool OtlpGrpcMetricExporter::isShutdown() const noexcept return is_shutdown_; } +const std::shared_ptr &OtlpGrpcMetricExporter::GetClient() const noexcept +{ + return client_; +} + } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_grpc_metric_exporter_factory.cc b/exporters/otlp/src/otlp_grpc_metric_exporter_factory.cc index c26035a8df..244d275722 100644 --- a/exporters/otlp/src/otlp_grpc_metric_exporter_factory.cc +++ b/exporters/otlp/src/otlp_grpc_metric_exporter_factory.cc @@ -28,6 +28,15 @@ OtlpGrpcMetricExporterFactory::Create(const OtlpGrpcMetricExporterOptions &optio return exporter; } +std::unique_ptr +OtlpGrpcMetricExporterFactory::Create(const OtlpGrpcMetricExporterOptions &options, + const std::shared_ptr &client) +{ + std::unique_ptr exporter( + new OtlpGrpcMetricExporter(options, client)); + return exporter; +} + } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/test/otlp_grpc_exporter_factory_test.cc b/exporters/otlp/test/otlp_grpc_exporter_factory_test.cc index c383cc85ed..a2fb62dab0 100644 --- a/exporters/otlp/test/otlp_grpc_exporter_factory_test.cc +++ b/exporters/otlp/test/otlp_grpc_exporter_factory_test.cc @@ -3,6 +3,7 @@ #include +#include "opentelemetry/exporters/otlp/otlp_grpc_client_factory.h" #include "opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h" #include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" @@ -14,6 +15,8 @@ # error "protobuf should not be included" #endif +#include "opentelemetry/exporters/otlp/otlp_grpc_exporter.h" + OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { @@ -31,6 +34,25 @@ TEST(OtlpGrpcExporterFactoryTest, BuildTest) EXPECT_TRUE(exporter != nullptr); } +TEST(OtlpGrpcExporterFactoryTest, ShareClient) +{ + OtlpGrpcExporterOptions opts; + opts.endpoint = "localhost:45454"; + + std::shared_ptr client = OtlpGrpcClientFactory::Create(opts); + std::unique_ptr exporter1 = + OtlpGrpcExporterFactory::Create(opts, client); + + std::unique_ptr exporter2 = + OtlpGrpcExporterFactory::Create(opts, client); + + EXPECT_TRUE(exporter1 != nullptr); + EXPECT_TRUE(exporter2 != nullptr); + + EXPECT_TRUE(static_cast(exporter1.get())->GetClient().get() == client.get()); + EXPECT_TRUE(static_cast(exporter2.get())->GetClient().get() == client.get()); +} + } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/test/otlp_grpc_log_record_exporter_factory_test.cc b/exporters/otlp/test/otlp_grpc_log_record_exporter_factory_test.cc index cb1d1849aa..0d0ab17d62 100644 --- a/exporters/otlp/test/otlp_grpc_log_record_exporter_factory_test.cc +++ b/exporters/otlp/test/otlp_grpc_log_record_exporter_factory_test.cc @@ -3,6 +3,7 @@ #include +#include "opentelemetry/exporters/otlp/otlp_grpc_client_factory.h" #include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h" #include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h" @@ -14,6 +15,8 @@ # error "protobuf should not be included" #endif +#include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h" + OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { @@ -31,6 +34,27 @@ TEST(OtlpGrpcLogRecordExporterFactoryTest, BuildTest) EXPECT_TRUE(exporter != nullptr); } +TEST(OtlpGrpcLogRecordExporterFactoryTest, ShareClient) +{ + OtlpGrpcLogRecordExporterOptions opts; + opts.endpoint = "localhost:45454"; + + std::shared_ptr client = OtlpGrpcClientFactory::Create(opts); + std::unique_ptr exporter1 = + OtlpGrpcLogRecordExporterFactory::Create(opts, client); + + std::unique_ptr exporter2 = + OtlpGrpcLogRecordExporterFactory::Create(opts, client); + + EXPECT_TRUE(exporter1 != nullptr); + EXPECT_TRUE(exporter2 != nullptr); + + EXPECT_TRUE(static_cast(exporter1.get())->GetClient().get() == + client.get()); + EXPECT_TRUE(static_cast(exporter2.get())->GetClient().get() == + client.get()); +} + } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc b/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc index 90827f576f..a2604de096 100644 --- a/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc @@ -3,15 +3,21 @@ #include +#include "opentelemetry/exporters/otlp/otlp_grpc_client.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_client_factory.h" #include "opentelemetry/exporters/otlp/otlp_grpc_exporter.h" #include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h" +// clang-format off #include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" +// clang-format on #include "opentelemetry/proto/collector/logs/v1/logs_service_mock.grpc.pb.h" #include "opentelemetry/proto/collector/trace/v1/trace_service_mock.grpc.pb.h" +// clang-format off #include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" +// clang-format on #include "opentelemetry/logs/provider.h" #include "opentelemetry/sdk/logs/batch_log_record_processor.h" @@ -188,6 +194,22 @@ class OtlpGrpcLogRecordExporterTestPeer : public ::testing::Test new OtlpGrpcExporter(std::move(stub_interface))); } + std::unique_ptr GetExporter( + std::unique_ptr &stub_interface, + const std::shared_ptr &client) + { + return std::unique_ptr( + new OtlpGrpcLogRecordExporter(std::move(stub_interface), std::move(client))); + } + + std::unique_ptr GetExporter( + std::unique_ptr &stub_interface, + const std::shared_ptr &client) + { + return std::unique_ptr( + new OtlpGrpcExporter(std::move(stub_interface), std::move(client))); + } + // Get the options associated with the given exporter. const OtlpGrpcLogRecordExporterOptions &GetOptions( std::unique_ptr &exporter) @@ -334,6 +356,116 @@ TEST_F(OtlpGrpcLogRecordExporterTestPeer, ExportIntegrationTest) trace_provider = opentelemetry::nostd::shared_ptr(); } +// Create spans, let processor call Export() and share client object between trace and logs +TEST_F(OtlpGrpcLogRecordExporterTestPeer, ShareClientTest) +{ + std::shared_ptr shared_client = + OtlpGrpcClientFactory::Create(OtlpGrpcLogRecordExporterOptions()); + + auto mock_stub = new OtlpMockLogsServiceStub(); + std::unique_ptr stub_interface(mock_stub); + + auto exporter = GetExporter(stub_interface, shared_client); + + bool attribute_storage_bool_value[] = {true, false, true}; + int32_t attribute_storage_int32_value[] = {1, 2}; + uint32_t attribute_storage_uint32_value[] = {3, 4}; + int64_t attribute_storage_int64_value[] = {5, 6}; + uint64_t attribute_storage_uint64_value[] = {7, 8}; + double attribute_storage_double_value[] = {3.2, 3.3}; + opentelemetry::nostd::string_view attribute_storage_string_value[] = {"vector", "string"}; + + auto provider = nostd::shared_ptr(new sdk::logs::LoggerProvider()); + provider->AddProcessor( + std::unique_ptr(new sdk::logs::BatchLogRecordProcessor( + std::move(exporter), 5, std::chrono::milliseconds(256), 1))); + + EXPECT_CALL(*mock_stub, Export(_, _, _)) + .Times(Exactly(1)) + .WillRepeatedly(Return(grpc::Status::OK)); + + uint8_t trace_id_bin[opentelemetry::trace::TraceId::kSize] = { + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; + opentelemetry::trace::TraceId trace_id{trace_id_bin}; + uint8_t span_id_bin[opentelemetry::trace::SpanId::kSize] = {'7', '6', '5', '4', + '3', '2', '1', '0'}; + opentelemetry::trace::SpanId span_id{span_id_bin}; + + auto trace_mock_stub = new OtlpMockTraceServiceStub(); + std::unique_ptr trace_stub_interface( + trace_mock_stub); + + auto trace_provider = opentelemetry::nostd::shared_ptr( + opentelemetry::sdk::trace::TracerProviderFactory::Create( + opentelemetry::sdk::trace::SimpleSpanProcessorFactory::Create( + GetExporter(trace_stub_interface, shared_client)))); + + // Trace and Logs should both receive datas when links static gRPC on ELF ABI. + EXPECT_CALL(*trace_mock_stub, Export(_, _, _)) + .Times(AtLeast(2)) + .WillRepeatedly(Return(grpc::Status::OK)); + + { + const std::string schema_url{"https://opentelemetry.io/schemas/1.11.0"}; + + auto tracer = trace_provider->GetTracer("opentelelemtry_library", "", schema_url); + auto copy_trace_provider = trace_provider; + opentelemetry::trace::Provider::SetTracerProvider(std::move(copy_trace_provider)); + auto trace_span = tracer->StartSpan("test_log"); + opentelemetry::trace::Scope trace_scope{trace_span}; + + auto logger = provider->GetLogger("test", "opentelelemtry_library", "", schema_url, + {{"scope_key1", "scope_value"}, {"scope_key2", 2}}); + std::unordered_map attributes; + attributes["service.name"] = "unit_test_service"; + attributes["tenant.id"] = "test_user"; + attributes["bool_value"] = true; + attributes["int32_value"] = static_cast(1); + attributes["uint32_value"] = static_cast(2); + attributes["int64_value"] = static_cast(0x1100000000LL); + attributes["uint64_value"] = static_cast(0x1200000000ULL); + attributes["double_value"] = static_cast(3.1); + attributes["vec_bool_value"] = attribute_storage_bool_value; + attributes["vec_int32_value"] = attribute_storage_int32_value; + attributes["vec_uint32_value"] = attribute_storage_uint32_value; + attributes["vec_int64_value"] = attribute_storage_int64_value; + attributes["vec_uint64_value"] = attribute_storage_uint64_value; + attributes["vec_double_value"] = attribute_storage_double_value; + attributes["vec_string_value"] = attribute_storage_string_value; + logger->EmitLogRecord(opentelemetry::logs::Severity::kInfo, "Log message", attributes, + trace_span->GetContext(), std::chrono::system_clock::now()); + } + + // Shudown logs, but tracer still works + provider->Shutdown(); + EXPECT_FALSE(shared_client->IsShutdown()); + + { + const std::string schema_url{"https://opentelemetry.io/schemas/1.11.0"}; + + auto tracer = trace_provider->GetTracer("opentelelemtry_library", "", schema_url); + auto trace_span = tracer->StartSpan("test_log"); + opentelemetry::trace::Scope trace_scope{trace_span}; + + auto logger = provider->GetLogger("test", "opentelelemtry_library", "", schema_url, + {{"scope_key1", "scope_value"}, {"scope_key2", 2}}); + std::unordered_map attributes; + attributes["service.name"] = "unit_test_service"; + attributes["tenant.id"] = "test_user"; + logger->EmitLogRecord(opentelemetry::logs::Severity::kInfo, "Log message", attributes, + trace_span->GetContext(), std::chrono::system_clock::now()); + } + + // All references are released, client should also be shutdown + trace_provider->Shutdown(); + EXPECT_TRUE(shared_client->IsShutdown()); + + opentelemetry::trace::Provider::SetTracerProvider( + opentelemetry::nostd::shared_ptr( + new opentelemetry::trace::NoopTracerProvider())); + trace_provider = opentelemetry::nostd::shared_ptr(); +} + } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/test/otlp_grpc_metric_exporter_factory_test.cc b/exporters/otlp/test/otlp_grpc_metric_exporter_factory_test.cc index b1d473e8da..ecad49bee1 100644 --- a/exporters/otlp/test/otlp_grpc_metric_exporter_factory_test.cc +++ b/exporters/otlp/test/otlp_grpc_metric_exporter_factory_test.cc @@ -3,6 +3,7 @@ #include +#include "opentelemetry/exporters/otlp/otlp_grpc_client_factory.h" #include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h" #include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h" @@ -14,6 +15,8 @@ # error "protobuf should not be included" #endif +#include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h" + OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { @@ -31,6 +34,27 @@ TEST(OtlpGrpcMetricExporterFactory, BuildTest) EXPECT_TRUE(exporter != nullptr); } +TEST(OtlpGrpcMetricExporterFactory, ShareClient) +{ + OtlpGrpcMetricExporterOptions opts; + opts.endpoint = "localhost:45454"; + + std::shared_ptr client = OtlpGrpcClientFactory::Create(opts); + std::unique_ptr exporter1 = + OtlpGrpcMetricExporterFactory::Create(opts, client); + + std::unique_ptr exporter2 = + OtlpGrpcMetricExporterFactory::Create(opts, client); + + EXPECT_TRUE(exporter1 != nullptr); + EXPECT_TRUE(exporter2 != nullptr); + + EXPECT_TRUE(static_cast(exporter1.get())->GetClient().get() == + client.get()); + EXPECT_TRUE(static_cast(exporter2.get())->GetClient().get() == + client.get()); +} + } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/common/CMakeLists.txt b/sdk/src/common/CMakeLists.txt index 664db38e17..16229e0820 100644 --- a/sdk/src/common/CMakeLists.txt +++ b/sdk/src/common/CMakeLists.txt @@ -17,7 +17,7 @@ target_link_libraries( opentelemetry_common PUBLIC opentelemetry_api opentelemetry_sdk Threads::Threads) -if(WITH_ABSEIL) +if(WITH_ABSEIL OR WITH_OTLP_GRPC) target_link_libraries(opentelemetry_common PUBLIC absl::strings) endif()