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

Add experimental updateTracerConfigurations for dynamically updateable on/off instrumentation #6899

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jackshirazi
Copy link
Contributor

This enables dynamic config - it's all that is needed at the experimental level. For the complete solution it would be a TracerProvider.updateTracerConfigurations() interface method addition.

A usage example is https://github.com/elastic/elastic-otel-java/blob/main/custom/src/main/java/co/elastic/otel/config/DynamicInstrumentation.java

Essentially, the configuration is set with an updatable ScopeConfigurator (see below fragment), then that can be updated at any time with eg GlobalOpenTelemetry.getTracerProvider().updateTracerConfigurations()

  public void customize(AutoConfigurationCustomizer autoConfiguration) {
    autoConfiguration.addTracerProviderCustomizer(
        (providerBuilder, properties) -> {
          providerBuilder.setTracerConfigurator(
              UpdatableConfigurator.INSTANCE);
          return providerBuilder;
        });
  }

  public static class UpdatableConfigurator implements ScopeConfigurator<TracerConfig> {
    public static final UpdatableConfigurator INSTANCE = new UpdatableConfigurator();
    private final ConcurrentMap<String, TracerConfig> map = new ConcurrentHashMap<>();

    private UpdatableConfigurator() {}

    @Override
    public TracerConfig apply(InstrumentationScopeInfo scopeInfo) {
      return map.getOrDefault(scopeInfo.getName(), TracerConfig.defaultConfig());
    }

    public void put(InstrumentationScopeInfo scope, TracerConfig tracerConfig) {
      map.put(scope.getName(), tracerConfig);
    }
  }

I haven't added implementations for DefaultTracerProvider and ExtendedDefaultTracerProvider nor tests, because I feel this is fine for the experimental stage, but those could be added easily

@jackshirazi jackshirazi requested a review from a team as a code owner November 21, 2024 16:30
Copy link

codecov bot commented Nov 21, 2024

Codecov Report

Attention: Patch coverage is 0% with 15 lines in your changes missing coverage. Please review.

Project coverage is 90.24%. Comparing base (7d74ada) to head (6f68542).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...in/java/io/opentelemetry/sdk/OpenTelemetrySdk.java 0.00% 7 Missing ⚠️
.../io/opentelemetry/sdk/trace/SdkTracerProvider.java 0.00% 6 Missing ⚠️
...ain/java/io/opentelemetry/sdk/trace/SdkTracer.java 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #6899      +/-   ##
============================================
- Coverage     90.30%   90.24%   -0.06%     
- Complexity     6594     6595       +1     
============================================
  Files           729      729              
  Lines         19784    19799      +15     
  Branches       1945     1945              
============================================
+ Hits          17866    17868       +2     
- Misses         1325     1340      +15     
+ Partials        593      591       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

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.

2 participants