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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
import java.io.Closeable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -168,6 +170,20 @@
public SdkTracerProvider unobfuscate() {
return delegate;
}

// currently not public as experimental
void updateTracerConfigurations() {
// and delegate method is experimental so also not public
// It would be: delegate.updateTracerConfigurations();
try {
Method method = SdkTracerProvider.class.getDeclaredMethod("updateTracerConfigurations");
method.setAccessible(true);
method.invoke(delegate);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new IllegalStateException(

Check warning on line 183 in sdk/all/src/main/java/io/opentelemetry/sdk/OpenTelemetrySdk.java

View check run for this annotation

Codecov / codecov/patch

sdk/all/src/main/java/io/opentelemetry/sdk/OpenTelemetrySdk.java#L179-L183

Added lines #L179 - L183 were not covered by tests
"Error calling SdkTracerProvider.updateTracerConfigurations(): ", e);
}
}

Check warning on line 186 in sdk/all/src/main/java/io/opentelemetry/sdk/OpenTelemetrySdk.java

View check run for this annotation

Codecov / codecov/patch

sdk/all/src/main/java/io/opentelemetry/sdk/OpenTelemetrySdk.java#L185-L186

Added lines #L185 - L186 were not covered by tests
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@

private final TracerSharedState sharedState;
private final InstrumentationScopeInfo instrumentationScopeInfo;

// TODO: add dedicated API for updating scope config.
@SuppressWarnings("FieldCanBeFinal") // For now, allow updating reflectively.
// deliberately not volatile because of performance concerns
// - which means its eventually consistent
private boolean tracerEnabled;
trask marked this conversation as resolved.
Show resolved Hide resolved

SdkTracer(
Expand Down Expand Up @@ -54,6 +53,11 @@
return instrumentationScopeInfo;
}

// currently not public as experimental
void updateTracerConfig(TracerConfig tracerConfig) {
this.tracerEnabled = tracerConfig.isEnabled();
}

Check warning on line 59 in sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkTracer.java

View check run for this annotation

Codecov / codecov/patch

sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkTracer.java#L58-L59

Added lines #L58 - L59 were not covered by tests

@Override
public boolean isEnabled() {
return tracerEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@
return sharedState.getSampler();
}

// currently not public as experimental
void updateTracerConfigurations() {
this.tracerSdkComponentRegistry
.getComponents()
.forEach(

Check warning on line 107 in sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkTracerProvider.java

View check run for this annotation

Codecov / codecov/patch

sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkTracerProvider.java#L105-L107

Added lines #L105 - L107 were not covered by tests
sdkTracer ->
sdkTracer.updateTracerConfig(
getTracerConfig(sdkTracer.getInstrumentationScopeInfo())));
}

Check warning on line 111 in sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkTracerProvider.java

View check run for this annotation

Codecov / codecov/patch

sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkTracerProvider.java#L109-L111

Added lines #L109 - L111 were not covered by tests

/**
* Attempts to stop all the activity for {@link Tracer}s created by this provider. Calls {@link
* SpanProcessor#shutdown()} for all registered {@link SpanProcessor}s.
Expand Down
Loading