Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build OpenTelemetry C++ SDK and exporter into DLL #1932

Merged
merged 53 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
dbd818d
Initial changeset
ThomsonTan Jan 13, 2023
468c189
Build logs into DLL
ThomsonTan Jan 19, 2023
011d96e
Merge branch 'main' into Build_DLL
ThomsonTan Jan 19, 2023
435e88b
Revert changing library to object
ThomsonTan Jan 19, 2023
27d8a5c
Add TracerProviderFactory to export
ThomsonTan Jan 19, 2023
52ab127
Fix clang-format
ThomsonTan Jan 19, 2023
db962d0
Rename OPENTELEMETRY_API to OPENTELEMETRY_EXPORT
ThomsonTan Jan 19, 2023
3178916
Add preprocess on the DLL DEF file
ThomsonTan Jan 20, 2023
01c8dd2
Disable clang format for export def file
ThomsonTan Jan 21, 2023
1572f17
Fix more format
ThomsonTan Jan 21, 2023
f8ee55a
Change line format for clang-format
ThomsonTan Jan 21, 2023
16b2011
Merge branch 'main' into Build_DLL
ThomsonTan Jan 24, 2023
d61520d
Export more classes from SDK
ThomsonTan Jan 24, 2023
1ad93bd
Add default_delete for std::unique_ptr exposed to users
ThomsonTan Jan 25, 2023
0af8403
Fix cmake format
ThomsonTan Jan 25, 2023
aa09118
More cmake-format
ThomsonTan Jan 25, 2023
767a4f1
Change newline to unix style in markdown
ThomsonTan Jan 25, 2023
d14227f
Add DLL build to CI
ThomsonTan Jan 25, 2023
9295d6b
Honor OTLP build option from CMake
ThomsonTan Jan 25, 2023
86bb52c
Add deleter for GetLogger which returns nostd::shared_ptr
ThomsonTan Jan 27, 2023
321359d
More format
ThomsonTan Jan 27, 2023
e79a554
Run cmake-format
ThomsonTan Jan 27, 2023
5c3c5e5
Export OTLP symbols based on build flags
ThomsonTan Jan 27, 2023
1c54eb6
Merge branch 'main' into Build_DLL
ThomsonTan Jan 27, 2023
1fc1467
Address feedback about creating temprory unique_ptr
ThomsonTan Jan 30, 2023
eebe85b
Merge branch 'main' into Build_DLL
ThomsonTan Jan 30, 2023
6cda6e5
Add comment with undecorated symbols for exported decorated symbols f…
ThomsonTan Jan 30, 2023
44ca55a
Remove SystemTimestamp from export list
ThomsonTan Jan 31, 2023
91bfd07
Fix cmake format
ThomsonTan Jan 31, 2023
20cceb7
Update doc to trigger new build
ThomsonTan Jan 31, 2023
fcb7f22
Emit error when WITH_STL is enabled for DLL build
ThomsonTan Jan 31, 2023
d1cab2c
Merge branch 'main' into Build_DLL
ThomsonTan Jan 31, 2023
7f1cfd7
Merge branch 'main' into Build_DLL
ThomsonTan Jan 31, 2023
b3c4029
Update message
ThomsonTan Feb 2, 2023
1a8d6eb
Run example with opentelemetry DLL under sanitizer
ThomsonTan Feb 3, 2023
bcc3909
Fix CI task name
ThomsonTan Feb 3, 2023
86ea207
Fix the sanitize task name
ThomsonTan Feb 3, 2023
4b1c991
Remove default_delete and address sanitizer
ThomsonTan Feb 4, 2023
9312aef
Revert experiment change to macros.h
ThomsonTan Feb 4, 2023
2260a1b
Merge branch 'main' into Build_DLL
ThomsonTan Feb 4, 2023
8bd4fab
Remove extra end curly brace
ThomsonTan Feb 4, 2023
36e1ece
Update export symbol name for LoggerProvider::Create
ThomsonTan Feb 4, 2023
e98815f
Format cmake
ThomsonTan Feb 4, 2023
594f289
Run example to catch runtime error like memory allocation inconsistency
ThomsonTan Feb 4, 2023
ecddf7c
Add DLL path to environment for loading
ThomsonTan Feb 4, 2023
f6ab0fc
Merge branch 'main' into Build_DLL
ThomsonTan Feb 6, 2023
059e2e6
Merge branch 'main' into Build_DLL
ThomsonTan Feb 7, 2023
c23051f
Move changelog to unrelease section
ThomsonTan Feb 7, 2023
bacc3b6
Address feedback on missing copyright
ThomsonTan Feb 8, 2023
e4965a9
Merge branch 'main' into Build_DLL
ThomsonTan Feb 8, 2023
0b858a6
Add missing export
ThomsonTan Feb 10, 2023
5ecbf16
Merge branch 'main' into Build_DLL
ThomsonTan Feb 10, 2023
bca6227
Merge branch 'main' into Build_DLL
ThomsonTan Feb 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*.so
*.dylib
*.dll
*.pdb

# Fortran module files
*.mod
Expand Down
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,13 @@ endif()

include(CMakePackageConfigHelpers)

if(DEFINED OPENTELEMETRY_BUILD_DLL)
owent marked this conversation as resolved.
Show resolved Hide resolved
if(NOT MSVC)
message(WARNING "Build DLL is supposed to work with MSVC")
endif()
add_definitions(-DOPENTELEMETRY_BUILD_EXPORT_DLL)
marcalff marked this conversation as resolved.
Show resolved Hide resolved
endif()

include_directories(api/include)

add_subdirectory(api)
Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/baggage/baggage.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ OPENTELEMETRY_BEGIN_NAMESPACE
namespace baggage
{

class Baggage
class OPENTELEMETRY_API Baggage
{
public:
static constexpr size_t kMaxKeyValuePairs = 180;
Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/common/key_value_iterable.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace common
/**
* Supports internal iteration over a collection of key-value pairs.
*/
class KeyValueIterable
class OPENTELEMETRY_API KeyValueIterable
{
public:
virtual ~KeyValueIterable() = default;
Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/common/key_value_iterable_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct is_key_value_iterable
* 'non-standard' type to one of the standard types.
*/
template <class T>
class KeyValueIterableView final : public KeyValueIterable
class OPENTELEMETRY_API KeyValueIterableView final : public KeyValueIterable
{

public:
Expand Down
4 changes: 2 additions & 2 deletions api/include/opentelemetry/common/kv_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct KeyValueStringTokenizerOptions
};

// Tokenizer for key-value headers
class KeyValueStringTokenizer
class OPENTELEMETRY_API KeyValueStringTokenizer
{
public:
KeyValueStringTokenizer(
Expand Down Expand Up @@ -134,7 +134,7 @@ class KeyValueStringTokenizer
};

// Class to store fixed size array of key-value pairs of string type
class KeyValueProperties
class OPENTELEMETRY_API KeyValueProperties
{
// Class to store key-value pairs of string types
public:
Expand Down
21 changes: 21 additions & 0 deletions api/include/opentelemetry/common/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,24 @@ point.
# define OPENTELEMETRY_API_SINGLETON

#endif

//
// The if/elif order matters here. If both OPENTELEMETRY_BUILD_IMPORT_DLL and
// OPENTELEMETRY_BUILD_EXPORT_DLL are defined, the former takes precedence.
marcalff marked this conversation as resolved.
Show resolved Hide resolved
//
#if defined(_MSC_VER) && defined(OPENTELEMETRY_BUILD_IMPORT_DLL)
ThomsonTan marked this conversation as resolved.
Show resolved Hide resolved
owent marked this conversation as resolved.
Show resolved Hide resolved

# define OPENTELEMETRY_API __declspec(dllimport)

#elif defined(_MSC_VER) && defined(OPENTELEMETRY_BUILD_EXPORT_DLL)

# define OPENTELEMETRY_API __declspec(dllexport)

#else

//
// build OpenTelemetry as static library or not on Windows.
//
# define OPENTELEMETRY_API

#endif
2 changes: 1 addition & 1 deletion api/include/opentelemetry/common/timestamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace common
*
* This is used for marking the beginning and end of an operation.
*/
class SystemTimestamp
class OPENTELEMETRY_API SystemTimestamp
{
public:
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace propagation

/* Stores the singleton TextMapPropagator */

class GlobalTextMapPropagator
class OPENTELEMETRY_API GlobalTextMapPropagator
{
public:
static nostd::shared_ptr<TextMapPropagator> GetGlobalPropagator() noexcept
Expand Down
4 changes: 2 additions & 2 deletions api/include/opentelemetry/context/runtime_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Token
* this class and passing an initialized RuntimeContextStorage object to
* RuntimeContext::SetRuntimeContextStorage.
*/
class RuntimeContextStorage
class OPENTELEMETRY_API RuntimeContextStorage
{
public:
/**
Expand Down Expand Up @@ -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_API RuntimeContext
{
public:
// Return the current context.
Expand Down
7 changes: 4 additions & 3 deletions api/include/opentelemetry/trace/noop.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_API NoopSpan final : public Span
{
public:
explicit NoopSpan(const std::shared_ptr<Tracer> &tracer) noexcept
Expand Down Expand Up @@ -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<NoopTracer>
class OPENTELEMETRY_API NoopTracer final : public Tracer,
public std::enable_shared_from_this<NoopTracer>
{
public:
// Tracer
Expand All @@ -101,7 +102,7 @@ class NoopTracer final : public Tracer, public std::enable_shared_from_this<Noop
/**
* No-op implementation of a TracerProvider.
*/
class NoopTracerProvider final : public opentelemetry::trace::TracerProvider
class OPENTELEMETRY_API NoopTracerProvider final : public opentelemetry::trace::TracerProvider
{
public:
NoopTracerProvider() noexcept
Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/trace/provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace trace
/**
* Stores the singleton global TracerProvider.
*/
class Provider
class OPENTELEMETRY_API Provider
{
public:
/**
Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/trace/trace_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace trace
* For more information, see the W3C Trace Context specification:
* https://www.w3.org/TR/trace-context
*/
class TraceState
class OPENTELEMETRY_API TraceState
{
public:
static constexpr int kKeyMaxSize = 256;
Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/trace/tracer_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace trace
/**
* Creates new Tracer instances.
*/
class TracerProvider
class OPENTELEMETRY_API TracerProvider
{
public:
virtual ~TracerProvider() = default;
Expand Down
4 changes: 4 additions & 0 deletions examples/common/foo_library/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if(DEFINED OPENTELEMETRY_BUILD_DLL)
add_definitions(-DOPENTELEMETRY_BUILD_IMPORT_DLL)
endif()
marcalff marked this conversation as resolved.
Show resolved Hide resolved

add_library(common_foo_library foo_library.h foo_library.cc)
target_link_libraries(common_foo_library PUBLIC ${CMAKE_THREAD_LIBS_INIT}
opentelemetry_api)
4 changes: 4 additions & 0 deletions examples/common/logs_foo_library/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
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)
70 changes: 48 additions & 22 deletions examples/otlp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
marcalff marked this conversation as resolved.
Show resolved Hide resolved
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()

Expand Down
16 changes: 13 additions & 3 deletions examples/simple/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
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()
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace trace
/**
* Factory class for OStreamSpanExporter.
*/
class OStreamSpanExporterFactory
class OPENTELEMETRY_API OStreamSpanExporterFactory
{
public:
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace otlp
/**
* Factory class for OtlpGrpcExporter.
*/
class OtlpGrpcExporterFactory
class OPENTELEMETRY_API OtlpGrpcExporterFactory
{
public:
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace otlp
/**
* Factory class for OtlpGrpcLogRecordExporter.
*/
class OtlpGrpcLogRecordExporterFactory
class OPENTELEMETRY_API OtlpGrpcLogRecordExporterFactory
{
public:
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace otlp
/**
* Factory class for OtlpHttpExporter.
*/
class OtlpHttpExporterFactory
class OPENTELEMETRY_API OtlpHttpExporterFactory
{
public:
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace otlp
/**
* Factory class for OtlpHttpLogRecordExporter.
*/
class OtlpHttpLogRecordExporterFactory
class OPENTELEMETRY_API OtlpHttpLogRecordExporterFactory
{
public:
/**
Expand Down
4 changes: 4 additions & 0 deletions ext/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
21 changes: 21 additions & 0 deletions ext/src/dll/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

add_library(opentelemetry_cpp SHARED dllmain.cc opentelemetry_cpp.def)

target_link_libraries(
opentelemetry_cpp
PRIVATE opentelemetry_trace
opentelemetry_exporter_ostream_span
opentelemetry_exporter_otlp_grpc
opentelemetry_exporter_otlp_http
opentelemetry_exporter_otlp_http_log
opentelemetry_logs
opentelemetry_exporter_otlp_grpc_log)

install(
TARGETS opentelemetry_cpp
EXPORT "${PROJECT_NAME}-target"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
Loading