Skip to content

Commit d693e95

Browse files
authored
[SDK] Better control of threads executed by opentelemetry-cpp (open-telemetry#3175)
1 parent 0b712dd commit d693e95

File tree

67 files changed

+1720
-112
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1720
-112
lines changed

CHANGELOG.md

+60
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,66 @@ Increment the:
2727
* [EXPORTER] Fix throw in OtlpGrpcMetricExporter with shared grpc client
2828
[#3243](https://github.com/open-telemetry/opentelemetry-cpp/pull/3243)
2929

30+
* [SDK] Better control of threads executed by opentelemetry-cpp
31+
[#3175](https://github.com/open-telemetry/opentelemetry-cpp/pull/3175)
32+
33+
New features:
34+
35+
* [SDK] Better control of threads executed by opentelemetry-cpp
36+
[#3175](https://github.com/open-telemetry/opentelemetry-cpp/pull/3175)
37+
38+
* This feature provides a way for applications,
39+
when configuring the SDK and exporters,
40+
to participate in the execution path
41+
of internal opentelemetry-cpp threads.
42+
43+
* The opentelemetry-cpp library provides the following:
44+
45+
* a new ThreadInstrumentation interface,
46+
* new runtime options structures, to optionally configure the SDK:
47+
* BatchSpanProcessorRuntimeOptions
48+
* PeriodicExportingMetricReaderRuntimeOptions
49+
* BatchLogRecordProcessorRuntimeOptions
50+
* new runtime options structures,
51+
to optionally configure the OTLP HTTP exporters:
52+
* OtlpHttpExporterRuntimeOptions
53+
* OtlpHttpMetricExporterRuntimeOptions
54+
* OtlpHttpLogRecordExporterRuntimeOptions
55+
* new ThreadInstrumentation parameters,
56+
to optionally configure the CURL HttpClient
57+
* new runtime options structures,
58+
to optionally configure the OTLP FILE exporters:
59+
* OtlpFileExporterRuntimeOptions
60+
* OtlpFileMetricExporterRuntimeOptions
61+
* OtlpFileLogRecordExporterRuntimeOptions
62+
* new runtime options structure,
63+
to optionally configure the OTLP FILE client:
64+
* OtlpFileClientRuntimeOptions
65+
66+
* Using the optional runtime options structures,
67+
an application can subclass the ThreadInstrumentation interface,
68+
and be notified of specific events of interest during the execution
69+
of an internal opentelemetry-cpp thread.
70+
71+
* This allows an application to call, for example:
72+
73+
* pthread_setaffinity_np(), for better performances,
74+
* setns(), to control the network namespace used by HTTP CURL connections
75+
* pthread_setname_np(), for better observability from the operating system
76+
* many more specific apis, as needed
77+
78+
* See the documentation for ThreadInstrumentation for details.
79+
80+
* A new example program, example_otlp_instrumented_http,
81+
shows how to use the feature,
82+
and add application logic in the thread execution code path.
83+
84+
* Note that this feature is experimental,
85+
protected by a WITH_THREAD_INSTRUMENTATION_PREVIEW
86+
flag in CMake. Various runtime options structures,
87+
as well as the thread instrumentation interface,
88+
may change without notice before this feature is declared stable.
89+
3090
## [1.18 2024-11-25]
3191

3292
* [EXPORTER] Fix crash in ElasticsearchLogRecordExporter

CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ option(WITH_ASYNC_EXPORT_PREVIEW "Whether to enable async export" OFF)
300300
option(WITH_METRICS_EXEMPLAR_PREVIEW
301301
"Whether to enable exemplar within metrics" OFF)
302302

303+
# Experimental, so behind feature flag by default
304+
option(WITH_THREAD_INSTRUMENTATION_PREVIEW
305+
"Whether to enable thread instrumentation" OFF)
306+
303307
option(OPENTELEMETRY_SKIP_DYNAMIC_LOADING_TESTS
304308
"Whether to build test libraries that are always linked as shared libs"
305309
OFF)

api/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ if(WITH_METRICS_EXEMPLAR_PREVIEW)
126126
INTERFACE ENABLE_METRICS_EXEMPLAR_PREVIEW)
127127
endif()
128128

129+
if(WITH_THREAD_INSTRUMENTATION_PREVIEW)
130+
target_compile_definitions(opentelemetry_api
131+
INTERFACE ENABLE_THREAD_INSTRUMENTATION_PREVIEW)
132+
endif()
133+
129134
if(WITH_OTLP_HTTP_COMPRESSION)
130135
target_compile_definitions(opentelemetry_api
131136
INTERFACE ENABLE_OTLP_COMPRESSION_PREVIEW)

ci/do_ci.sh

+4
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ elif [[ "$1" == "cmake.maintainer.sync.test" ]]; then
131131
-DOTELCPP_MAINTAINER_MODE=ON \
132132
-DWITH_NO_DEPRECATED_CODE=ON \
133133
-DWITH_OTLP_HTTP_COMPRESSION=ON \
134+
-DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON \
134135
${IWYU} \
135136
"${SRC_DIR}"
136137
eval "$MAKE_COMMAND"
@@ -153,6 +154,7 @@ elif [[ "$1" == "cmake.maintainer.async.test" ]]; then
153154
-DOTELCPP_MAINTAINER_MODE=ON \
154155
-DWITH_NO_DEPRECATED_CODE=ON \
155156
-DWITH_OTLP_HTTP_COMPRESSION=ON \
157+
-DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON \
156158
${IWYU} \
157159
"${SRC_DIR}"
158160
eval "$MAKE_COMMAND"
@@ -176,6 +178,7 @@ elif [[ "$1" == "cmake.maintainer.cpp11.async.test" ]]; then
176178
-DOTELCPP_MAINTAINER_MODE=ON \
177179
-DWITH_NO_DEPRECATED_CODE=ON \
178180
-DWITH_OTLP_HTTP_COMPRESSION=ON \
181+
-DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON \
179182
"${SRC_DIR}"
180183
make -k -j $(nproc)
181184
make test
@@ -199,6 +202,7 @@ elif [[ "$1" == "cmake.maintainer.abiv2.test" ]]; then
199202
-DWITH_ABI_VERSION_1=OFF \
200203
-DWITH_ABI_VERSION_2=ON \
201204
-DWITH_OTLP_HTTP_COMPRESSION=ON \
205+
-DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON \
202206
${IWYU} \
203207
"${SRC_DIR}"
204208
eval "$MAKE_COMMAND"

examples/otlp/BUILD

+22
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,25 @@ cc_binary(
168168
"//sdk/src/metrics",
169169
],
170170
)
171+
172+
cc_binary(
173+
name = "example_otlp_instrumented_http",
174+
srcs = [
175+
"http_instrumented_main.cc",
176+
],
177+
tags = [
178+
"examples",
179+
"otlp",
180+
"otlp_http",
181+
],
182+
deps = [
183+
"//api",
184+
"//examples/common/logs_foo_library:common_logs_foo_library",
185+
"//examples/common/metrics_foo_library:common_metrics_foo_library",
186+
"//exporters/otlp:otlp_http_exporter",
187+
"//exporters/otlp:otlp_http_log_record_exporter",
188+
"//exporters/otlp:otlp_http_metric_exporter",
189+
"//sdk/src/metrics",
190+
"//sdk/src/trace",
191+
],
192+
)

examples/otlp/CMakeLists.txt

+23
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,29 @@ if(WITH_OTLP_HTTP)
9999
opentelemetry_exporter_otlp_http_log)
100100
endif()
101101

102+
# ALL, instrumented
103+
104+
add_executable(example_otlp_instrumented_http http_instrumented_main.cc)
105+
106+
# Note: common_logs_foo_library provide traces and logs
107+
target_link_libraries(
108+
example_otlp_instrumented_http ${CMAKE_THREAD_LIBS_INIT}
109+
common_metrics_foo_library common_logs_foo_library)
110+
111+
if(DEFINED OPENTELEMETRY_BUILD_DLL)
112+
target_link_libraries(example_otlp_instrumented_http opentelemetry_cpp
113+
opentelemetry_common)
114+
else()
115+
target_link_libraries(
116+
example_otlp_instrumented_http
117+
opentelemetry_trace
118+
opentelemetry_metrics
119+
opentelemetry_logs
120+
opentelemetry_exporter_otlp_http
121+
opentelemetry_exporter_otlp_http_metric
122+
opentelemetry_exporter_otlp_http_log)
123+
endif()
124+
102125
endif()
103126

104127
if(WITH_OTLP_FILE)

0 commit comments

Comments
 (0)