Skip to content

[SDK] Support TracerConfigurator updates#4065

Open
dbarker wants to merge 16 commits into
open-telemetry:mainfrom
dbarker:feature_tracer_configurator_updates
Open

[SDK] Support TracerConfigurator updates#4065
dbarker wants to merge 16 commits into
open-telemetry:mainfrom
dbarker:feature_tracer_configurator_updates

Conversation

@dbarker
Copy link
Copy Markdown
Member

@dbarker dbarker commented May 7, 2026

Add support for updating the TracerConfigurator at runtime and provide an example.

The TracerProvider configuration includes the TracerConfigurator. SDKs may support updating the TracerConfigurator and resulting TracerConfig objects at runtime provided it is applied to previously created tracers. This feature allows dynamic enabling of tracers to turn tracing on or off without restarting the application.

https://opentelemetry.io/docs/specs/otel/trace/sdk/#configuration

The TracerProvider MAY provide methods to update the configuration. If configuration is updated (e.g., adding a SpanProcessor), the updated configuration MUST also apply to all already returned Tracers (i.e. it MUST NOT matter whether a Tracer was obtained from the TracerProvider before or after the configuration change).

Changes

  • Add SDK TracerProvider::UpdateTracerConfigurator method and tests
  • Add mutex for the SDK Tracer::tracer_config_ that will support dynamic updates including growth beyond the enabled bool.
  • Add example showing runtime changes to the tracer configurator to enable/disable tracers.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

❌ Patch coverage is 82.60870% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.95%. Comparing base (b706b56) to head (57c8c3e).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
sdk/src/trace/tracer_context.cc 60.00% 2 Missing ⚠️
sdk/src/trace/tracer_provider.cc 80.00% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4065      +/-   ##
==========================================
- Coverage   82.01%   81.95%   -0.05%     
==========================================
  Files         385      385              
  Lines       16031    16089      +58     
==========================================
+ Hits        13146    13184      +38     
- Misses       2885     2905      +20     
Files with missing lines Coverage Δ
...etry/sdk/instrumentationscope/scope_configurator.h 100.00% <ø> (ø)
sdk/include/opentelemetry/sdk/trace/tracer.h 100.00% <ø> (ø)
...k/include/opentelemetry/sdk/trace/tracer_context.h 100.00% <ø> (ø)
sdk/src/trace/tracer.cc 87.35% <100.00%> (+1.24%) ⬆️
sdk/src/trace/tracer_context.cc 80.65% <60.00%> (-3.97%) ⬇️
sdk/src/trace/tracer_provider.cc 87.94% <80.00%> (-1.65%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dbarker dbarker marked this pull request as ready for review May 7, 2026 22:53
@dbarker dbarker requested a review from a team as a code owner May 7, 2026 22:53
Comment thread sdk/src/trace/tracer_provider.cc Outdated
Comment thread sdk/src/trace/tracer.cc Outdated
Comment thread sdk/src/trace/tracer_provider.cc
Comment thread sdk/src/trace/tracer_provider.cc
Comment on lines +125 to +127
#if OPENTELEMETRY_ABI_VERSION_NO < 2
std::atomic<bool> is_enabled_;
#endif
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, the check on ABI_VERSION can be removed, this is in the SDK.

Second, the initialization MUST use {value}, see PR #2244:

[SDK] Valgrind errors on std::atomic variables (#2244)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, the check on ABI_VERSION can be removed, this is in the SDK.

Thanks. This sdk::trace::Tracer::is_enabled_ atomic was added for only ABIv1 since the API Tracer::enabled_ exists only for ABIv2. I think we should keep it guarded here in the SDK Tracer since it is redundant with the API Tracer boolean in ABIv2. When the project moves to ABIv2 as the default and ABIv1 is deprecated this SDK Tracer::is_enabled_ atomic should be removed. Does that sound reasonable?

Second, the initialization MUST use {value}

Good catch. I'll default initialize it in the header. CI is may not be warning on this since it is set in the constructor member initializer list.

Comment thread sdk/src/trace/tracer.cc
Comment on lines +222 to +226
#if OPENTELEMETRY_ABI_VERSION_NO >= 2
UpdateEnabled(enabled);
#else
is_enabled_.store(enabled, std::memory_order_relaxed);
#endif
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so UpdateEnabled() is a method that exists only in the API, starting with ABI version 2.

How about, in ABI version 1, defining the very same method with the same implementation, only in the SDK, instead of implementing a different attribute name (is_enabled) and type (std::atomic) ?

This code then becomes:

UpdateEnabled(enabled);

in all cases.

Likewise, define method Enabled() and member enabled_ in the SDK in ABI v1.

Basically, the pattern is the opposite of ForceFlushWithMicroseconds() which was demoted from the API to the SDK.

Here Enabled() can be in the SDK in ABI v1, promoted to the API in ABI v2.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I'll try this way.

Copy link
Copy Markdown
Member

@marcalff marcalff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See suggestion for Enabled().

Comment on lines +13 to +19
// The example simulates a debugging workflow where only the tracer configuration is changed at
// runtime through the provider:
//
// Stage 1 – Start with all tracing disabled (low-overhead production default).
// Stage 2 – An issue is reported. Enable only the user library traces to get an initial signal.
// Stage 3 – The issue involves external libraries too. Enable all traces for full visibility.
// Stage 4 – Investigation complete. Disable all tracing again.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very nice.

Could you paste the test output in a comment, for reviewers ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants