-
Notifications
You must be signed in to change notification settings - Fork 440
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
[SDK] Better control of threads executed by opentelemetry-cpp #3175
base: main
Are you sure you want to change the base?
[SDK] Better control of threads executed by opentelemetry-cpp #3175
Conversation
✅ Deploy Preview for opentelemetry-cpp-api-docs canceled.
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3175 +/- ##
==========================================
- Coverage 88.16% 87.48% -0.68%
==========================================
Files 198 198
Lines 6224 6298 +74
==========================================
+ Hits 5487 5509 +22
- Misses 737 789 +52
|
Do you think we can implement a worker pool to share threads among multiple exporters and processors? Since most of them simply wait for a timeout, there is no need to create a separate thread for each component. |
For some applications, running in a multi threaded environment, it is critical to control how a thread executes in finer details. For example, I have:
When the exporter uses CURL to post to the endpoint, it makes a TCP/IP connection. (a), (b) and (c) do need to use different TCP/IP stacks, or different named networks, to connect to their respective endpoints. This is achieved by calling Having dedicated threads (as currently) makes this easier. If execution of each exporter was to be multiplexed and executed in the same worker thread, the context will need to change for each exporter, calling setns() many more time, and introducing more complexity to counter the effect of a pool worker thread, so it won't help but instead get in the way. setns() is just an example, there can be other use cases, like binding to a CPU, etc. Overall, the need is for the main application to inject arbitrary code in the opentelemetry-cpp execution code path, for opentelemetry threads. |
Could please also add this instrumentation for OTLP file exporters? |
Sure, implemented. Every place where opentelemetry-cpp starts a new |
An example of using this feature, to set thread names to the operating system on Linux:
In order, threads are:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM and thanks.
Fixes #3174
Changes
This feature provides a way for applications, when configuring the SDK and exporters,
to participate in the execution path of internal opentelemetry-cpp threads.
The opentelemetry-cpp library provides the following:
ThreadInstrumentation
interface,BatchSpanProcessorRuntimeOptions
PeriodicExportingMetricReaderRuntimeOptions
BatchLogRecordProcessorRuntimeOptions
OtlpHttpExporterRuntimeOptions
OtlpHttpMetricExporterRuntimeOptions
OtlpHttpLogRecordExporterRuntimeOptions
ThreadInstrumentation parameters
, to optionally configure the CURLHttpClient
OtlpFileExporterRuntimeOptions
OtlpFileMetricExporterRuntimeOptions
OtlpFileLogRecordExporterRuntimeOptions
OtlpFileClientRuntimeOptions
Using the optional runtime options structures,
an application can subclass the
ThreadInstrumentation
interface,and be notified of specific events of interest during the execution of an internal opentelemetry-cpp thread.
This allows an application to call, for example:
pthread_setaffinity_np()
, see related Add BatchSpanProcessor option to set CPU affinity on the worker thread #1822setns()
, to control the network namespace used by HTTP CURL connectionspthread_setname_np()
, for better observability from the operating systemSee the documentation for
ThreadInstrumentation
for details.A new example program,
example_otlp_instrumented_http
, shows how to use the feature,and add application logic in the thread execution code path.
For significant contributions please make sure you have completed the following items:
CHANGELOG.md
updated for non-trivial changes