diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 746dc134f3..360d01ffa8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -518,6 +518,23 @@ jobs: - name: run otprotocol test run: ./ci/do_ci.ps1 cmake.exporter.otprotocol.test + windows-build-dll: + name: CMake -> exporter proto (Build as DLL) + runs-on: windows-2019 + steps: + - uses: actions/checkout@v3 + with: + submodules: 'recursive' + - name: setup + run: | + ./ci/setup_windows_cmake.ps1 + ./ci/setup_windows_ci_environment.ps1 + ./ci/install_windows_protobuf.ps1 + - name: run cmake test (DLL build) + run: ./ci/do_ci.ps1 cmake.dll.test + - name: run otprotocol test (DLL build) + run: ./ci/do_ci.ps1 cmake.exporter.otprotocol.dll.test + windows_with_async_export: name: CMake (With async export) -> exporter proto runs-on: windows-2019 diff --git a/.gitignore b/.gitignore index b4a8233bb8..354d7462c4 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ *.so *.dylib *.dll +*.pdb # Fortran module files *.mod diff --git a/CHANGELOG.md b/CHANGELOG.md index 0611bc191d..0ecbc24737 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ Increment the: * Convert Prometheus Exporter to Pull MetricReader [#1953](https://github.com/open-telemetry/opentelemetry-cpp/pull/1953) * Upgrade prometheus-cpp to v1.1.0 [#1954](https://github.com/open-telemetry/opentelemetry-cpp/pull/1954) +* [BUILD] Build OpenTelemetry SDK and exporters into DLL + [#1932](https://github.com/open-telemetry/opentelemetry-cpp/pull/1932) * [CI] Enforce copyright check in CI [#1965](https://github.com/open-telemetry/opentelemetry-cpp/pull/1965) * [SEMANTIC CONVENTIONS] Upgrade to version 1.18.0 [#1974](https://github.com/open-telemetry/opentelemetry-cpp/pull/1974) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9df8f5cafc..a11ba3878c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -521,6 +521,17 @@ endif() include(CMakePackageConfigHelpers) +if(DEFINED OPENTELEMETRY_BUILD_DLL) + if(NOT MSVC) + message(WARNING "Build DLL is supposed to work with MSVC!") + endif() + if(WITH_STL) + message( + WARNING "Build DLL with C++ STL could cause binary incompatibility!") + endif() + add_definitions(-DOPENTELEMETRY_BUILD_EXPORT_DLL) +endif() + include_directories(api/include) add_subdirectory(api) diff --git a/INSTALL.md b/INSTALL.md index f4a0615350..31cc42dd59 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -264,10 +264,8 @@ cc_library( ## Building shared libs for Windows -Windows DLL build is not supported. There are some constraints on how C++ DLLs -work on Windows, specifically we can't safely allocate memory in one DLL and -free it in another. For now, OpenTelemetry C++ targets need to be statically -linked into the Windows applications. +Windows DLL build is supported under **preview**. Please check the +[doc](./docs/build-as-dll.md) for more details. ## Generatring binary packages diff --git a/api/include/opentelemetry/baggage/baggage.h b/api/include/opentelemetry/baggage/baggage.h index 899e4970a6..66a77ed941 100644 --- a/api/include/opentelemetry/baggage/baggage.h +++ b/api/include/opentelemetry/baggage/baggage.h @@ -16,7 +16,7 @@ OPENTELEMETRY_BEGIN_NAMESPACE namespace baggage { -class Baggage +class OPENTELEMETRY_EXPORT Baggage { public: static constexpr size_t kMaxKeyValuePairs = 180; diff --git a/api/include/opentelemetry/common/macros.h b/api/include/opentelemetry/common/macros.h index 0f8e57ccc0..323e5cdc04 100644 --- a/api/include/opentelemetry/common/macros.h +++ b/api/include/opentelemetry/common/macros.h @@ -175,3 +175,28 @@ point. # define OPENTELEMETRY_API_SINGLETON #endif + +/* clang-format on */ +// +// The if/elif order matters here. If both OPENTELEMETRY_BUILD_IMPORT_DLL and +// OPENTELEMETRY_BUILD_EXPORT_DLL are defined, the former takes precedence. +// +// TODO: consider define OPENTELEMETRY_EXPORT for cygwin/gcc, see below link. +// https://gcc.gnu.org/wiki/Visibility#How_to_use_the_new_C.2B-.2B-_visibility_support +// +#if defined(_MSC_VER) && defined(OPENTELEMETRY_BUILD_IMPORT_DLL) + +# define OPENTELEMETRY_EXPORT __declspec(dllimport) + +#elif defined(_MSC_VER) && defined(OPENTELEMETRY_BUILD_EXPORT_DLL) + +# define OPENTELEMETRY_EXPORT __declspec(dllexport) + +#else + +// +// build OpenTelemetry as static library or not on Windows. +// +# define OPENTELEMETRY_EXPORT + +#endif diff --git a/api/include/opentelemetry/context/propagation/global_propagator.h b/api/include/opentelemetry/context/propagation/global_propagator.h index 6d26b84019..460764a74d 100644 --- a/api/include/opentelemetry/context/propagation/global_propagator.h +++ b/api/include/opentelemetry/context/propagation/global_propagator.h @@ -22,7 +22,7 @@ namespace propagation /* Stores the singleton TextMapPropagator */ -class GlobalTextMapPropagator +class OPENTELEMETRY_EXPORT GlobalTextMapPropagator { public: static nostd::shared_ptr GetGlobalPropagator() noexcept diff --git a/api/include/opentelemetry/context/runtime_context.h b/api/include/opentelemetry/context/runtime_context.h index 6d59d9cc44..bec96a9af4 100644 --- a/api/include/opentelemetry/context/runtime_context.h +++ b/api/include/opentelemetry/context/runtime_context.h @@ -37,7 +37,7 @@ class Token * this class and passing an initialized RuntimeContextStorage object to * RuntimeContext::SetRuntimeContextStorage. */ -class RuntimeContextStorage +class OPENTELEMETRY_EXPORT RuntimeContextStorage { public: /** @@ -78,7 +78,7 @@ static RuntimeContextStorage *GetDefaultStorage() noexcept; // Provides a wrapper for propagating the context object globally. // // By default, a thread-local runtime context storage is used. -class RuntimeContext +class OPENTELEMETRY_EXPORT RuntimeContext { public: // Return the current context. diff --git a/api/include/opentelemetry/logs/logger.h b/api/include/opentelemetry/logs/logger.h index e62fbe1156..1220219449 100644 --- a/api/include/opentelemetry/logs/logger.h +++ b/api/include/opentelemetry/logs/logger.h @@ -323,4 +323,4 @@ class Logger } // namespace logs OPENTELEMETRY_END_NAMESPACE -#endif +#endif // end of ENABLE_LOGS_PREVIEW diff --git a/api/include/opentelemetry/logs/logger_provider.h b/api/include/opentelemetry/logs/logger_provider.h index 7fb56f4964..7979ab202a 100644 --- a/api/include/opentelemetry/logs/logger_provider.h +++ b/api/include/opentelemetry/logs/logger_provider.h @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once + #ifdef ENABLE_LOGS_PREVIEW # include "opentelemetry/common/key_value_iterable.h" @@ -16,7 +17,7 @@ namespace logs /** * Creates new Logger instances. */ -class LoggerProvider +class OPENTELEMETRY_EXPORT LoggerProvider { public: virtual ~LoggerProvider() = default; @@ -68,4 +69,5 @@ class LoggerProvider }; } // namespace logs OPENTELEMETRY_END_NAMESPACE -#endif + +#endif // ENABLE_LOGS_PREVIEW diff --git a/api/include/opentelemetry/trace/noop.h b/api/include/opentelemetry/trace/noop.h index 5532aacbe6..8a9b13b7a1 100644 --- a/api/include/opentelemetry/trace/noop.h +++ b/api/include/opentelemetry/trace/noop.h @@ -27,7 +27,7 @@ namespace trace /** * No-op implementation of Span. This class should not be used directly. */ -class NoopSpan final : public Span +class OPENTELEMETRY_EXPORT NoopSpan final : public Span { public: explicit NoopSpan(const std::shared_ptr &tracer) noexcept @@ -76,7 +76,8 @@ class NoopSpan final : public Span /** * No-op implementation of Tracer. */ -class NoopTracer final : public Tracer, public std::enable_shared_from_this +class OPENTELEMETRY_EXPORT NoopTracer final : public Tracer, + public std::enable_shared_from_this { public: // Tracer @@ -101,7 +102,7 @@ class NoopTracer final : public Tracer, public std::enable_shared_from_this(new TestLogger()); + return nostd::shared_ptr(new TestLogger()); } }; diff --git a/ci/do_ci.ps1 b/ci/do_ci.ps1 index 72094d3edb..e2143088f0 100644 --- a/ci/do_ci.ps1 +++ b/ci/do_ci.ps1 @@ -51,6 +51,33 @@ switch ($action) { exit $exit } } + "cmake.dll.test" { + cd "$BUILD_DIR" + cmake $SRC_DIR ` + -DVCPKG_TARGET_TRIPLET=x64-windows ` + -DOPENTELEMETRY_BUILD_DLL=1 ` + "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake" + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + cmake --build . + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + ctest -C Debug + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + $env:PATH = "$BUILD_DIR\ext\src\dll\Debug;$env:PATH" + examples\simple\Debug\example_simple.exe + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + } "cmake.maintainer.test" { cd "$BUILD_DIR" cmake $SRC_DIR ` @@ -116,6 +143,28 @@ switch ($action) { exit $exit } } + "cmake.exporter.otprotocol.dll.test" { + cd "$BUILD_DIR" + cmake $SRC_DIR ` + -DVCPKG_TARGET_TRIPLET=x64-windows ` + -DOPENTELEMETRY_BUILD_DLL=1 ` + -DWITH_OTPROTCOL=ON ` + "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake" + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + cmake --build . + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + ctest -C Debug + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + } "cmake.exporter.otprotocol.with_async_export.test" { cd "$BUILD_DIR" cmake $SRC_DIR ` diff --git a/docs/build-as-dll.md b/docs/build-as-dll.md new file mode 100644 index 0000000000..9a53639834 --- /dev/null +++ b/docs/build-as-dll.md @@ -0,0 +1,11 @@ +# Design of building OpenTelemetry C++ SDK and exporters as DLL + +**NOTE**: the current build produces a single DLL which includes API, SDK and +exporters. This **MAY** change in future. + +OpenTelemetry C++ can be built into single DLL named opentelemetry_cpp.dll on +Windows, with CMake flag `OPENTELEMETRY_BUILD_DLL` set to `ON`. + +To instrument an application based on the DLL, please define macro +`OPENTELEMETRY_BUILD_IMPORT_DLL` before including any OpenTelemetry API header +files in the application source files. diff --git a/examples/common/foo_library/CMakeLists.txt b/examples/common/foo_library/CMakeLists.txt index 61aadeff6e..cceb200596 100644 --- a/examples/common/foo_library/CMakeLists.txt +++ b/examples/common/foo_library/CMakeLists.txt @@ -1,6 +1,10 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 +if(DEFINED OPENTELEMETRY_BUILD_DLL) + add_definitions(-DOPENTELEMETRY_BUILD_IMPORT_DLL) +endif() + add_library(common_foo_library foo_library.h foo_library.cc) target_link_libraries(common_foo_library PUBLIC ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) diff --git a/examples/common/logs_foo_library/CMakeLists.txt b/examples/common/logs_foo_library/CMakeLists.txt index d030e2a3ad..45fe112f4e 100644 --- a/examples/common/logs_foo_library/CMakeLists.txt +++ b/examples/common/logs_foo_library/CMakeLists.txt @@ -1,6 +1,10 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 +if(DEFINED OPENTELEMETRY_BUILD_DLL) + add_definitions(-DOPENTELEMETRY_BUILD_IMPORT_DLL) +endif() + add_library(common_logs_foo_library foo_library.h foo_library.cc) target_link_libraries(common_logs_foo_library PUBLIC ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) diff --git a/examples/otlp/CMakeLists.txt b/examples/otlp/CMakeLists.txt index bcf387a108..a9263a38b5 100644 --- a/examples/otlp/CMakeLists.txt +++ b/examples/otlp/CMakeLists.txt @@ -1,43 +1,69 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 +if(DEFINED OPENTELEMETRY_BUILD_DLL) + add_definitions(-DOPENTELEMETRY_BUILD_IMPORT_DLL) +endif() + include_directories( ${CMAKE_BINARY_DIR}/generated/third_party/opentelemetry-proto ${CMAKE_SOURCE_DIR}/exporters/otlp/include) if(WITH_OTLP_GRPC) add_executable(example_otlp_grpc grpc_main.cc) - target_link_libraries( - example_otlp_grpc ${CMAKE_THREAD_LIBS_INIT} common_foo_library - opentelemetry_trace opentelemetry_exporter_otlp_grpc) + + target_link_libraries(example_otlp_grpc ${CMAKE_THREAD_LIBS_INIT} + common_foo_library) + + if(DEFINED OPENTELEMETRY_BUILD_DLL) + target_link_libraries(example_otlp_grpc opentelemetry_cpp) + else() + target_link_libraries(example_otlp_grpc opentelemetry_trace + opentelemetry_exporter_otlp_grpc) + endif() if(WITH_LOGS_PREVIEW) add_executable(example_otlp_grpc_log grpc_log_main.cc) - target_link_libraries( - example_otlp_grpc_log - ${CMAKE_THREAD_LIBS_INIT} - common_logs_foo_library - opentelemetry_trace - opentelemetry_logs - opentelemetry_exporter_otlp_grpc - opentelemetry_exporter_otlp_grpc_log) + + target_link_libraries(example_otlp_grpc_log ${CMAKE_THREAD_LIBS_INIT} + common_logs_foo_library) + if(DEFINED OPENTELEMETRY_BUILD_DLL) + target_link_libraries(example_otlp_grpc_log opentelemetry_cpp) + else() + target_link_libraries( + example_otlp_grpc_log opentelemetry_trace opentelemetry_logs + opentelemetry_exporter_otlp_grpc opentelemetry_exporter_otlp_grpc_log) + endif() endif() endif() if(WITH_OTLP_HTTP) add_executable(example_otlp_http http_main.cc) - target_link_libraries( - example_otlp_http ${CMAKE_THREAD_LIBS_INIT} common_foo_library - opentelemetry_trace opentelemetry_exporter_otlp_http) + + target_link_libraries(example_otlp_http ${CMAKE_THREAD_LIBS_INIT} + common_foo_library) + if(DEFINED OPENTELEMETRY_BUILD_DLL) + target_link_libraries(example_otlp_http opentelemetry_cpp + opentelemetry_common) + else() + target_link_libraries(example_otlp_http opentelemetry_trace + opentelemetry_exporter_otlp_http) + endif() + if(WITH_LOGS_PREVIEW) add_executable(example_otlp_http_log http_log_main.cc) - target_link_libraries( - example_otlp_http_log - ${CMAKE_THREAD_LIBS_INIT} - common_logs_foo_library - opentelemetry_trace - opentelemetry_logs - opentelemetry_exporter_otlp_http - opentelemetry_exporter_otlp_http_log) + target_link_libraries(example_otlp_http_log ${CMAKE_THREAD_LIBS_INIT} + common_logs_foo_library) + + if(DEFINED OPENTELEMETRY_BUILD_DLL) + target_link_libraries(example_otlp_http_log opentelemetry_cpp + opentelemetry_common) + else() + target_link_libraries( + example_otlp_http_log common_logs_foo_library opentelemetry_trace + opentelemetry_logs opentelemetry_exporter_otlp_http + opentelemetry_exporter_otlp_http_log) + endif() + endif() endif() diff --git a/examples/simple/CMakeLists.txt b/examples/simple/CMakeLists.txt index 3bcc8b4f2c..d4fb19c4db 100644 --- a/examples/simple/CMakeLists.txt +++ b/examples/simple/CMakeLists.txt @@ -1,9 +1,19 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 +if(DEFINED OPENTELEMETRY_BUILD_DLL) + add_definitions(-DOPENTELEMETRY_BUILD_IMPORT_DLL) +endif() + include_directories(${CMAKE_SOURCE_DIR}/exporters/ostream/include) add_executable(example_simple main.cc) -target_link_libraries( - example_simple ${CMAKE_THREAD_LIBS_INIT} common_foo_library - opentelemetry_trace opentelemetry_exporter_ostream_span) +target_link_libraries(example_simple ${CMAKE_THREAD_LIBS_INIT} + common_foo_library) + +if(DEFINED OPENTELEMETRY_BUILD_DLL) + target_link_libraries(example_simple opentelemetry_cpp) +else() + target_link_libraries(example_simple opentelemetry_trace + opentelemetry_exporter_ostream_span) +endif() diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter_factory.h b/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter_factory.h index c7216410b9..79ba3b06d4 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter_factory.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter_factory.h @@ -25,7 +25,7 @@ namespace trace /** * Factory class for OStreamSpanExporter. */ -class OStreamSpanExporterFactory +class OPENTELEMETRY_EXPORT OStreamSpanExporterFactory { public: /** 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 e258917df9..518cf8b82c 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 @@ -17,7 +17,7 @@ namespace otlp /** * Factory class for OtlpGrpcExporter. */ -class OtlpGrpcExporterFactory +class OPENTELEMETRY_EXPORT OtlpGrpcExporterFactory { public: /** 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 84e5aa1e96..a6fa8e50d6 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 @@ -17,7 +17,7 @@ namespace otlp /** * Factory class for OtlpGrpcLogRecordExporter. */ -class OtlpGrpcLogRecordExporterFactory +class OPENTELEMETRY_EXPORT OtlpGrpcLogRecordExporterFactory { public: /** diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_factory.h index e3deaca1ba..5316528365 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_factory.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_factory.h @@ -17,7 +17,7 @@ namespace otlp /** * Factory class for OtlpHttpExporter. */ -class OtlpHttpExporterFactory +class OPENTELEMETRY_EXPORT OtlpHttpExporterFactory { public: /** diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h index d2ea095245..152a394574 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h @@ -18,7 +18,7 @@ namespace otlp /** * Factory class for OtlpHttpLogRecordExporter. */ -class OtlpHttpLogRecordExporterFactory +class OPENTELEMETRY_EXPORT OtlpHttpLogRecordExporterFactory { public: /** diff --git a/ext/src/CMakeLists.txt b/ext/src/CMakeLists.txt index 84f30dd906..bc1f614eb9 100644 --- a/ext/src/CMakeLists.txt +++ b/ext/src/CMakeLists.txt @@ -8,3 +8,7 @@ endif() if(WITH_HTTP_CLIENT_CURL) add_subdirectory(http/client/curl) endif() + +if(MSVC AND DEFINED OPENTELEMETRY_BUILD_DLL) + add_subdirectory(dll) +endif() diff --git a/ext/src/dll/CMakeLists.txt b/ext/src/dll/CMakeLists.txt new file mode 100644 index 0000000000..7f34fab142 --- /dev/null +++ b/ext/src/dll/CMakeLists.txt @@ -0,0 +1,53 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +set(OPENTELEMETRY_EXPORT_DEF + "${CMAKE_CURRENT_BINARY_DIR}/opentelemetry_cpp.def") + +add_library(opentelemetry_cpp SHARED dllmain.cc ${OPENTELEMETRY_EXPORT_DEF}) + +target_link_libraries( + opentelemetry_cpp PRIVATE opentelemetry_trace + opentelemetry_exporter_ostream_span) + +if(WITH_OTLP_GRPC) + add_compile_definitions(WITH_OTLP_GRPC) + target_link_libraries(opentelemetry_cpp + PRIVATE opentelemetry_exporter_otlp_grpc) +endif() + +if(WITH_OTLP_HTTP) + add_compile_definitions(WITH_OTLP_HTTP) + target_link_libraries(opentelemetry_cpp + PRIVATE opentelemetry_exporter_otlp_http) +endif() + +if(WITH_LOGS_PREVIEW) + if(WITH_OTLP_GRPC) + target_link_libraries( + opentelemetry_cpp PRIVATE opentelemetry_logs + opentelemetry_exporter_otlp_grpc_log) + endif() + + if(WITH_OTLP_HTTP) + target_link_libraries( + opentelemetry_cpp PRIVATE opentelemetry_logs + opentelemetry_exporter_otlp_http_log) + endif() +endif() + +add_custom_command( + OUTPUT ${OPENTELEMETRY_EXPORT_DEF} + COMMAND + ${CMAKE_CXX_COMPILER} + "-D$,;-D>" /EP + ${CMAKE_CURRENT_SOURCE_DIR}/opentelemetry_cpp.src > + ${OPENTELEMETRY_EXPORT_DEF} + COMMAND_EXPAND_LISTS VERBATIM) + +install( + TARGETS opentelemetry_cpp + EXPORT "${PROJECT_NAME}-target" + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/ext/src/dll/dllmain.cc b/ext/src/dll/dllmain.cc new file mode 100644 index 0000000000..3dc5bc5c11 --- /dev/null +++ b/ext/src/dll/dllmain.cc @@ -0,0 +1,20 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include + +// Include API header files here for exporting +#include + +#if defined(ENABLE_LOGS_PREVIEW) +# include +#endif // ENABLE_LOGS_PREVIEW + +extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) +{ + UNREFERENCED_PARAMETER(hInstance); + UNREFERENCED_PARAMETER(dwReason); + UNREFERENCED_PARAMETER(lpReserved); + + return TRUE; +} diff --git a/ext/src/dll/opentelemetry_cpp.src b/ext/src/dll/opentelemetry_cpp.src new file mode 100644 index 0000000000..9f5ee76ba3 --- /dev/null +++ b/ext/src/dll/opentelemetry_cpp.src @@ -0,0 +1,39 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// clang-format off +LIBRARY opentelemetry_cpp +EXPORTS + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::trace::OStreamSpanExporterFactory::Create(void) + ?Create@OStreamSpanExporterFactory@trace@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VSpanExporter@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanExporter@trace@sdk@v1@opentelemetry@@@std@@@std@@XZ + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::trace::SimpleSpanProcessorFactory::Create(class std::unique_ptr > && __ptr64) + ?Create@SimpleSpanProcessorFactory@trace@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VSpanProcessor@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanProcessor@trace@sdk@v1@opentelemetry@@@std@@@std@@$$QEAV?$unique_ptr@VSpanExporter@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanExporter@trace@sdk@v1@opentelemetry@@@std@@@7@@Z + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::trace::TracerProviderFactory::Create(class std::unique_ptr >) + ?Create@TracerProviderFactory@trace@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VTracerProvider@trace@v1@opentelemetry@@U?$default_delete@VTracerProvider@trace@v1@opentelemetry@@@std@@@std@@V?$unique_ptr@VSpanProcessor@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanProcessor@trace@sdk@v1@opentelemetry@@@std@@@7@@Z +#if defined(WITH_OTLP_GRPC) + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpGrpcExporterOptions const & __ptr64) + ?Create@OtlpGrpcExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VSpanExporter@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanExporter@trace@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpGrpcExporterOptions@2345@@Z +#endif // defined(WITH_OTLP_GRPC) +#if defined(WITH_OTLP_HTTP) + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpHttpExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpHttpExporterOptions const & __ptr64) + ?Create@OtlpHttpExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VSpanExporter@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanExporter@trace@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpHttpExporterOptions@2345@@Z +#endif // defined(WITH_OTLP_HTTP) +#if defined(ENABLE_LOGS_PREVIEW) + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::logs::LoggerProviderFactory::Create(class std::unique_ptr > && __ptr64) + ?Create@LoggerProviderFactory@logs@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VLoggerProvider@logs@v1@opentelemetry@@U?$default_delete@VLoggerProvider@logs@v1@opentelemetry@@@std@@@std@@$$QEAV?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@7@@Z + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::logs::BatchLogRecordProcessorFactory::Create(class std::unique_ptr > && __ptr64,struct opentelemetry::v1::sdk::logs::BatchLogRecordProcessorOptions const & __ptr64) + ?Create@BatchLogRecordProcessorFactory@logs@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@std@@$$QEAV?$unique_ptr@VLogRecordExporter@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordExporter@logs@sdk@v1@opentelemetry@@@std@@@7@AEBUBatchLogRecordProcessorOptions@2345@@Z + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::logs::SimpleLogRecordProcessorFactory::Create(class std::unique_ptr > && __ptr64) + ?Create@SimpleLogRecordProcessorFactory@logs@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@std@@$$QEAV?$unique_ptr@VLogRecordExporter@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordExporter@logs@sdk@v1@opentelemetry@@@std@@@7@@Z + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::logs::MultiLogRecordProcessorFactory::Create(class std::vector >,class std::allocator > > > && __ptr64) + ?Create@MultiLogRecordProcessorFactory@logs@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@std@@$$QEAV?$vector@V?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@std@@V?$allocator@V?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@std@@@2@@7@@Z +#if defined(WITH_OTLP_GRPC) + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcLogRecordExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpGrpcExporterOptions const & __ptr64) + ?Create@OtlpGrpcLogRecordExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VLogRecordExporter@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordExporter@logs@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpGrpcExporterOptions@2345@@Z +#endif // defined(WITH_OTLP_GRPC) +#if defined(WITH_OTLP_HTTP) + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpHttpLogRecordExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpHttpLogRecordExporterOptions const & __ptr64) + ?Create@OtlpHttpLogRecordExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VLogRecordExporter@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordExporter@logs@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpHttpLogRecordExporterOptions@2345@@Z +#endif // defined(WITH_OTLP_HTTP) +#endif // defined(ENABLE_LOGS_PREVIEW) +// clang-format on diff --git a/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor_factory.h b/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor_factory.h index ea26fcd1ec..55adc68f72 100644 --- a/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor_factory.h +++ b/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor_factory.h @@ -21,7 +21,7 @@ namespace logs /** * Factory class for BatchLogRecordProcessor. */ -class BatchLogRecordProcessorFactory +class OPENTELEMETRY_EXPORT BatchLogRecordProcessorFactory { public: /** diff --git a/sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h b/sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h index e103fce8be..0795129df3 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h +++ b/sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h @@ -24,7 +24,7 @@ namespace logs /** * Factory class for LoggerProvider. */ -class LoggerProviderFactory +class OPENTELEMETRY_EXPORT LoggerProviderFactory { public: /** diff --git a/sdk/include/opentelemetry/sdk/logs/multi_log_record_processor_factory.h b/sdk/include/opentelemetry/sdk/logs/multi_log_record_processor_factory.h index 0e8b9a5878..c91cad52ff 100644 --- a/sdk/include/opentelemetry/sdk/logs/multi_log_record_processor_factory.h +++ b/sdk/include/opentelemetry/sdk/logs/multi_log_record_processor_factory.h @@ -19,7 +19,7 @@ namespace logs /** * Factory class for MultiLogRecordProcessor. */ -class MultiLogRecordProcessorFactory +class OPENTELEMETRY_EXPORT MultiLogRecordProcessorFactory { public: static std::unique_ptr Create( diff --git a/sdk/include/opentelemetry/sdk/logs/simple_log_record_processor_factory.h b/sdk/include/opentelemetry/sdk/logs/simple_log_record_processor_factory.h index a71ba05684..aec65349c5 100644 --- a/sdk/include/opentelemetry/sdk/logs/simple_log_record_processor_factory.h +++ b/sdk/include/opentelemetry/sdk/logs/simple_log_record_processor_factory.h @@ -19,7 +19,7 @@ namespace logs /** * Factory class for SimpleLogRecordProcessor. */ -class SimpleLogRecordProcessorFactory +class OPENTELEMETRY_EXPORT SimpleLogRecordProcessorFactory { public: /** diff --git a/sdk/include/opentelemetry/sdk/trace/batch_span_processor_factory.h b/sdk/include/opentelemetry/sdk/trace/batch_span_processor_factory.h index 67f45917cf..6e66d2d2b9 100644 --- a/sdk/include/opentelemetry/sdk/trace/batch_span_processor_factory.h +++ b/sdk/include/opentelemetry/sdk/trace/batch_span_processor_factory.h @@ -19,7 +19,7 @@ namespace trace /** * Factory class for BatchSpanProcessor. */ -class BatchSpanProcessorFactory +class OPENTELEMETRY_EXPORT BatchSpanProcessorFactory { public: /** diff --git a/sdk/include/opentelemetry/sdk/trace/exporter.h b/sdk/include/opentelemetry/sdk/trace/exporter.h index 5826b5f454..3f9bce9b84 100644 --- a/sdk/include/opentelemetry/sdk/trace/exporter.h +++ b/sdk/include/opentelemetry/sdk/trace/exporter.h @@ -17,7 +17,7 @@ namespace trace * SpanExporter defines the interface that protocol-specific span exporters must * implement. */ -class SpanExporter +class OPENTELEMETRY_EXPORT SpanExporter { public: virtual ~SpanExporter() = default; diff --git a/sdk/include/opentelemetry/sdk/trace/processor.h b/sdk/include/opentelemetry/sdk/trace/processor.h index 17ac0e59a0..f87b893837 100644 --- a/sdk/include/opentelemetry/sdk/trace/processor.h +++ b/sdk/include/opentelemetry/sdk/trace/processor.h @@ -18,7 +18,7 @@ namespace trace * Built-in span processors are responsible for batching and conversion of * spans to exportable representation and passing batches to exporters. */ -class SpanProcessor +class OPENTELEMETRY_EXPORT SpanProcessor { public: virtual ~SpanProcessor() = default; diff --git a/sdk/include/opentelemetry/sdk/trace/simple_processor_factory.h b/sdk/include/opentelemetry/sdk/trace/simple_processor_factory.h index 152b64b90c..efa3078a38 100644 --- a/sdk/include/opentelemetry/sdk/trace/simple_processor_factory.h +++ b/sdk/include/opentelemetry/sdk/trace/simple_processor_factory.h @@ -17,7 +17,7 @@ namespace trace /** * Factory class for SimpleSpanProcessor. */ -class SimpleSpanProcessorFactory +class OPENTELEMETRY_EXPORT SimpleSpanProcessorFactory { public: /** diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_context.h b/sdk/include/opentelemetry/sdk/trace/tracer_context.h index 572f60cafe..573af20b7d 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_context.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_context.h @@ -40,6 +40,8 @@ class TracerContext std::unique_ptr id_generator = std::unique_ptr(new RandomIdGenerator())) noexcept; + virtual ~TracerContext() = default; + /** * Attaches a span processor to list of configured processors to this tracer context. * Processor once attached can't be removed. diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_context_factory.h b/sdk/include/opentelemetry/sdk/trace/tracer_context_factory.h index eb88707328..b03ae297fc 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_context_factory.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_context_factory.h @@ -17,7 +17,7 @@ namespace trace /** * Factory class for TracerContext. */ -class TracerContextFactory +class OPENTELEMETRY_EXPORT TracerContextFactory { public: /** diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_provider_factory.h b/sdk/include/opentelemetry/sdk/trace/tracer_provider_factory.h index 0c493eb8e2..14458b2409 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_provider_factory.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_provider_factory.h @@ -19,7 +19,7 @@ namespace trace * Factory class for TracerProvider. * See @ref TracerProvider. */ -class TracerProviderFactory +class OPENTELEMETRY_EXPORT TracerProviderFactory { public: /* Serie of builders with a single processor. */ diff --git a/sdk/test/trace/batch_span_processor_test.cc b/sdk/test/trace/batch_span_processor_test.cc index 744d80775d..e9150d1ff1 100644 --- a/sdk/test/trace/batch_span_processor_test.cc +++ b/sdk/test/trace/batch_span_processor_test.cc @@ -108,10 +108,10 @@ TEST_F(BatchSpanProcessorTestPeer, TestShutdown) std::shared_ptr>> spans_received( new std::vector>); - auto batch_processor = - std::shared_ptr(new sdk::trace::BatchSpanProcessor( - std::unique_ptr(new MockSpanExporter(spans_received, is_shutdown)), - sdk::trace::BatchSpanProcessorOptions())); + auto batch_processor = std::shared_ptr( + new sdk::trace::BatchSpanProcessor(std::unique_ptr( + new MockSpanExporter(spans_received, is_shutdown)), + sdk::trace::BatchSpanProcessorOptions())); const int num_spans = 3; auto test_spans = GetTestSpans(batch_processor, num_spans); @@ -140,10 +140,10 @@ TEST_F(BatchSpanProcessorTestPeer, TestForceFlush) std::shared_ptr>> spans_received( new std::vector>); - auto batch_processor = - std::shared_ptr(new sdk::trace::BatchSpanProcessor( - std::unique_ptr(new MockSpanExporter(spans_received, is_shutdown)), - sdk::trace::BatchSpanProcessorOptions())); + auto batch_processor = std::shared_ptr( + new sdk::trace::BatchSpanProcessor(std::unique_ptr( + new MockSpanExporter(spans_received, is_shutdown)), + sdk::trace::BatchSpanProcessorOptions())); const int num_spans = 2048; auto test_spans = GetTestSpans(batch_processor, num_spans); @@ -215,10 +215,10 @@ TEST_F(BatchSpanProcessorTestPeer, TestManySpansLoss) const int max_queue_size = 4096; - auto batch_processor = - std::shared_ptr(new sdk::trace::BatchSpanProcessor( - std::unique_ptr(new MockSpanExporter(spans_received, is_shutdown)), - sdk::trace::BatchSpanProcessorOptions())); + auto batch_processor = std::shared_ptr( + new sdk::trace::BatchSpanProcessor(std::unique_ptr( + new MockSpanExporter(spans_received, is_shutdown)), + sdk::trace::BatchSpanProcessorOptions())); auto test_spans = GetTestSpans(batch_processor, max_queue_size); @@ -265,10 +265,10 @@ TEST_F(BatchSpanProcessorTestPeer, TestManySpansLossLess) const int num_spans = 2048; - auto batch_processor = - std::shared_ptr(new sdk::trace::BatchSpanProcessor( - std::unique_ptr(new MockSpanExporter(spans_received, is_shutdown)), - sdk::trace::BatchSpanProcessorOptions())); + auto batch_processor = std::shared_ptr( + new sdk::trace::BatchSpanProcessor(std::unique_ptr( + new MockSpanExporter(spans_received, is_shutdown)), + sdk::trace::BatchSpanProcessorOptions())); auto test_spans = GetTestSpans(batch_processor, num_spans); @@ -305,7 +305,7 @@ TEST_F(BatchSpanProcessorTestPeer, TestScheduleDelayMillis) auto batch_processor = std::shared_ptr(new sdk::trace::BatchSpanProcessor( - std::unique_ptr( + std::unique_ptr( new MockSpanExporter(spans_received, is_shutdown, is_export_completed, export_delay)), options)); diff --git a/sdk/test/trace/simple_processor_test.cc b/sdk/test/trace/simple_processor_test.cc index e65fd3b29a..f32485e7d0 100644 --- a/sdk/test/trace/simple_processor_test.cc +++ b/sdk/test/trace/simple_processor_test.cc @@ -17,9 +17,9 @@ using opentelemetry::trace::SpanContext; TEST(SimpleProcessor, ToInMemorySpanExporter) { - std::unique_ptr exporter(new InMemorySpanExporter()); + InMemorySpanExporter *exporter = new InMemorySpanExporter(); std::shared_ptr span_data = exporter->GetData(); - SimpleSpanProcessor processor(std::move(exporter)); + SimpleSpanProcessor processor(std::unique_ptr{exporter}); auto recordable = processor.MakeRecordable(); @@ -63,9 +63,9 @@ class RecordShutdownExporter final : public SpanExporter TEST(SimpleSpanProcessor, ShutdownCalledOnce) { - int shutdowns = 0; - std::unique_ptr exporter(new RecordShutdownExporter(&shutdowns)); - SimpleSpanProcessor processor(std::move(exporter)); + int shutdowns = 0; + RecordShutdownExporter *exporter = new RecordShutdownExporter(&shutdowns); + SimpleSpanProcessor processor(std::unique_ptr{exporter}); EXPECT_EQ(0, shutdowns); processor.Shutdown(); EXPECT_EQ(1, shutdowns); diff --git a/sdk/test/trace/tracer_test.cc b/sdk/test/trace/tracer_test.cc index 399c3c6d9f..f92c0f6e93 100644 --- a/sdk/test/trace/tracer_test.cc +++ b/sdk/test/trace/tracer_test.cc @@ -114,9 +114,9 @@ std::shared_ptr initTracer( TEST(Tracer, ToInMemorySpanExporter) { - std::unique_ptr exporter(new InMemorySpanExporter()); + InMemorySpanExporter *exporter = new InMemorySpanExporter(); std::shared_ptr span_data = exporter->GetData(); - auto tracer = initTracer(std::move(exporter)); + auto tracer = initTracer(std::unique_ptr{exporter}); auto span_first = tracer->StartSpan("span 1"); auto scope_first = tracer->WithActiveSpan(span_first); @@ -149,9 +149,9 @@ TEST(Tracer, ToInMemorySpanExporter) TEST(Tracer, StartSpanSampleOn) { - std::unique_ptr exporter(new InMemorySpanExporter()); + InMemorySpanExporter *exporter = new InMemorySpanExporter(); std::shared_ptr span_data = exporter->GetData(); - auto tracer_on = initTracer(std::move(exporter)); + auto tracer_on = initTracer(std::unique_ptr{exporter}); tracer_on->StartSpan("span 1")->End(); @@ -165,9 +165,9 @@ TEST(Tracer, StartSpanSampleOn) TEST(Tracer, StartSpanSampleOff) { - std::unique_ptr exporter(new InMemorySpanExporter()); + InMemorySpanExporter *exporter = new InMemorySpanExporter(); std::shared_ptr span_data = exporter->GetData(); - auto tracer_off = initTracer(std::move(exporter), new AlwaysOffSampler()); + auto tracer_off = initTracer(std::unique_ptr{exporter}, new AlwaysOffSampler()); // This span will not be recorded. auto span = tracer_off->StartSpan("span 2"); @@ -185,10 +185,11 @@ TEST(Tracer, StartSpanSampleOff) TEST(Tracer, StartSpanCustomIdGenerator) { - IdGenerator *id_generator = new MockIdGenerator(); - std::unique_ptr exporter(new InMemorySpanExporter()); + IdGenerator *id_generator = new MockIdGenerator(); + InMemorySpanExporter *exporter = new InMemorySpanExporter(); std::shared_ptr span_data = exporter->GetData(); - auto tracer = initTracer(std::move(exporter), new AlwaysOnSampler(), id_generator); + auto tracer = + initTracer(std::unique_ptr{exporter}, new AlwaysOnSampler(), id_generator); tracer->StartSpan("span 1")->End(); auto spans = span_data->GetSpans(); @@ -200,9 +201,9 @@ TEST(Tracer, StartSpanCustomIdGenerator) TEST(Tracer, StartSpanWithOptionsTime) { - std::unique_ptr exporter(new InMemorySpanExporter()); + InMemorySpanExporter *exporter = new InMemorySpanExporter(); std::shared_ptr span_data = exporter->GetData(); - auto tracer = initTracer(std::move(exporter)); + auto tracer = initTracer(std::unique_ptr{exporter}); opentelemetry::trace::StartSpanOptions start; start.start_system_time = SystemTimestamp(std::chrono::nanoseconds(300)); @@ -223,9 +224,9 @@ TEST(Tracer, StartSpanWithOptionsTime) TEST(Tracer, StartSpanWithAttributes) { - std::unique_ptr exporter(new InMemorySpanExporter()); + InMemorySpanExporter *exporter = new InMemorySpanExporter(); std::shared_ptr span_data = exporter->GetData(); - auto tracer = initTracer(std::move(exporter)); + auto tracer = initTracer(std::unique_ptr{exporter}); // Start a span with all supported scalar attribute types. tracer @@ -303,9 +304,9 @@ TEST(Tracer, StartSpanWithAttributes) TEST(Tracer, StartSpanWithAttributesCopy) { - std::unique_ptr exporter(new InMemorySpanExporter()); + InMemorySpanExporter *exporter = new InMemorySpanExporter(); std::shared_ptr span_data = exporter->GetData(); - auto tracer = initTracer(std::move(exporter)); + auto tracer = initTracer(std::unique_ptr{exporter}); { std::unique_ptr> numbers(new std::vector); @@ -371,9 +372,9 @@ TEST(Tracer, GetSampler) TEST(Tracer, SpanSetAttribute) { - std::unique_ptr exporter(new InMemorySpanExporter()); + InMemorySpanExporter *exporter = new InMemorySpanExporter(); std::shared_ptr span_data = exporter->GetData(); - auto tracer = initTracer(std::move(exporter)); + auto tracer = initTracer(std::unique_ptr{exporter}); auto span = tracer->StartSpan("span 1"); @@ -389,9 +390,9 @@ TEST(Tracer, SpanSetAttribute) TEST(Tracer, TestAfterEnd) { - std::unique_ptr exporter(new InMemorySpanExporter()); + InMemorySpanExporter *exporter = new InMemorySpanExporter(); std::shared_ptr span_data = exporter->GetData(); - auto tracer = initTracer(std::move(exporter)); + auto tracer = initTracer(std::unique_ptr{exporter}); auto span = tracer->StartSpan("span 1"); span->SetAttribute("abc", 3.1); @@ -417,9 +418,9 @@ TEST(Tracer, TestAfterEnd) TEST(Tracer, SpanSetEvents) { - std::unique_ptr exporter(new InMemorySpanExporter()); + InMemorySpanExporter *exporter = new InMemorySpanExporter(); std::shared_ptr span_data = exporter->GetData(); - auto tracer = initTracer(std::move(exporter)); + auto tracer = initTracer(std::unique_ptr{exporter}); auto span = tracer->StartSpan("span 1"); span->AddEvent("event 1"); @@ -442,9 +443,9 @@ TEST(Tracer, SpanSetEvents) TEST(Tracer, SpanSetLinks) { - std::unique_ptr exporter(new InMemorySpanExporter()); + InMemorySpanExporter *exporter = new InMemorySpanExporter(); std::shared_ptr span_data = exporter->GetData(); - auto tracer = initTracer(std::move(exporter)); + auto tracer = initTracer(std::unique_ptr{exporter}); { @@ -519,9 +520,9 @@ TEST(Tracer, SpanSetLinks) TEST(Tracer, TestAlwaysOnSampler) { - std::unique_ptr exporter(new InMemorySpanExporter()); + InMemorySpanExporter *exporter = new InMemorySpanExporter(); std::shared_ptr span_data = exporter->GetData(); - auto tracer_on = initTracer(std::move(exporter)); + auto tracer_on = initTracer(std::unique_ptr{exporter}); // Testing AlwaysOn sampler. // Create two spans for each tracer. Check the exported result. @@ -538,9 +539,9 @@ TEST(Tracer, TestAlwaysOnSampler) TEST(Tracer, TestAlwaysOffSampler) { - std::unique_ptr exporter(new InMemorySpanExporter()); + InMemorySpanExporter *exporter = new InMemorySpanExporter(); std::shared_ptr span_data = exporter->GetData(); - auto tracer_off = initTracer(std::move(exporter), new AlwaysOffSampler()); + auto tracer_off = initTracer(std::unique_ptr{exporter}, new AlwaysOffSampler()); auto span_off_1 = tracer_off->StartSpan("span 1"); auto span_off_2 = tracer_off->StartSpan("span 2"); @@ -557,10 +558,10 @@ TEST(Tracer, TestParentBasedSampler) { // Current ShouldSample always pass an empty ParentContext, // so this sampler will work as an AlwaysOnSampler. - std::unique_ptr exporter(new InMemorySpanExporter()); + InMemorySpanExporter *exporter = new InMemorySpanExporter(); std::shared_ptr span_data_parent_on = exporter->GetData(); - auto tracer_parent_on = - initTracer(std::move(exporter), new ParentBasedSampler(std::make_shared())); + auto tracer_parent_on = initTracer(std::unique_ptr{exporter}, + new ParentBasedSampler(std::make_shared())); auto span_parent_on_1 = tracer_parent_on->StartSpan("span 1"); auto span_parent_on_2 = tracer_parent_on->StartSpan("span 2"); @@ -577,10 +578,10 @@ TEST(Tracer, TestParentBasedSampler) // Current ShouldSample always pass an empty ParentContext, // so this sampler will work as an AlwaysOnSampler. - std::unique_ptr exporter2(new InMemorySpanExporter()); + InMemorySpanExporter *exporter2 = new InMemorySpanExporter(); std::shared_ptr span_data_parent_off = exporter2->GetData(); auto tracer_parent_off = - initTracer(std::move(exporter2), + initTracer(std::unique_ptr{exporter2}, // Add this to avoid different results for old and new version of clang-format new ParentBasedSampler(std::make_shared())); @@ -596,9 +597,9 @@ TEST(Tracer, TestParentBasedSampler) TEST(Tracer, WithActiveSpan) { - std::unique_ptr exporter(new InMemorySpanExporter()); + InMemorySpanExporter *exporter = new InMemorySpanExporter(); std::shared_ptr span_data = exporter->GetData(); - auto tracer = initTracer(std::move(exporter)); + auto tracer = initTracer(std::unique_ptr{exporter}); auto spans = span_data.get()->GetSpans(); ASSERT_EQ(0, spans.size()); @@ -631,9 +632,9 @@ TEST(Tracer, WithActiveSpan) TEST(Tracer, ExpectParent) { - std::unique_ptr exporter(new InMemorySpanExporter()); + InMemorySpanExporter *exporter = new InMemorySpanExporter(); std::shared_ptr span_data = exporter->GetData(); - auto tracer = initTracer(std::move(exporter)); + auto tracer = initTracer(std::unique_ptr{exporter}); auto spans = span_data.get()->GetSpans(); ASSERT_EQ(0, spans.size()); @@ -666,9 +667,9 @@ TEST(Tracer, ExpectParent) TEST(Tracer, ExpectParentAsContext) { - std::unique_ptr exporter(new InMemorySpanExporter()); + InMemorySpanExporter *exporter = new InMemorySpanExporter(); std::shared_ptr span_data = exporter->GetData(); - auto tracer = initTracer(std::move(exporter)); + auto tracer = initTracer(std::unique_ptr{exporter}); auto spans = span_data.get()->GetSpans(); ASSERT_EQ(0, spans.size()); @@ -704,9 +705,9 @@ TEST(Tracer, ExpectParentAsContext) TEST(Tracer, ValidTraceIdToSampler) { - std::unique_ptr exporter(new InMemorySpanExporter()); + InMemorySpanExporter *exporter = new InMemorySpanExporter(); std::shared_ptr span_data = exporter->GetData(); - auto tracer = initTracer(std::move(exporter), new MockSampler()); + auto tracer = initTracer(std::unique_ptr{exporter}); auto span = tracer->StartSpan("span 1"); // sampler was fed with valid trace_id, so span shouldn't be NoOp Span. @@ -716,9 +717,9 @@ TEST(Tracer, ValidTraceIdToSampler) TEST(Tracer, SpanCleanupWithScope) { - std::unique_ptr exporter(new InMemorySpanExporter()); + InMemorySpanExporter *exporter = new InMemorySpanExporter(); std::shared_ptr span_data = exporter->GetData(); - auto tracer = initTracer(std::move(exporter)); + auto tracer = initTracer(std::unique_ptr{exporter}, new MockSampler()); { auto span0 = tracer->StartSpan("Span0"); auto span1 = tracer->StartSpan("span1");