Skip to content

Commit

Permalink
add test for SdkTracerProviderUtil.setScopeConfigurator
Browse files Browse the repository at this point in the history
  • Loading branch information
jackshirazi committed Jan 23, 2025
1 parent 01a26f6 commit 16a8248
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private SdkTracerProviderUtil() {}

/** Reflectively set the {@link ScopeConfigurator} to the {@link SdkTracerProvider}. */
public static void setScopeConfigurator(
SdkTracerProviderBuilder sdkTracerProvider,
SdkTracerProvider sdkTracerProvider,
ScopeConfigurator<TracerConfig> scopeConfigurator) {
try {
Method method =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.internal.ScopeConfigurator;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.trace.internal.SdkTracerProviderUtil;
import io.opentelemetry.sdk.trace.internal.TracerConfig;
import io.opentelemetry.sdk.trace.samplers.Sampler;
import java.util.function.Supplier;
Expand Down Expand Up @@ -187,7 +188,16 @@ void propagatesInstrumentationScopeInfoToTracer() {
}

@Test
void propagatesEnablementToTracer() {
void propagatesEnablementToTracerDirectly() {
propagatesEnablementToTracer(true);
}

@Test
void propagatesEnablementToTracerByUtil() {
propagatesEnablementToTracer(false);
}

void propagatesEnablementToTracer(boolean directly) {
SdkTracer tracer = (SdkTracer) tracerFactory.get("test");
boolean isEnabled = tracer.isEnabled();
ScopeConfigurator<TracerConfig> flipConfigurator =
Expand All @@ -198,7 +208,11 @@ public TracerConfig apply(InstrumentationScopeInfo scopeInfo) {
}
};
// all in the same thread, so should see enablement change immediately
tracerFactory.setScopeConfigurator(flipConfigurator);
if (directly) {
tracerFactory.setScopeConfigurator(flipConfigurator);
} else {
SdkTracerProviderUtil.setScopeConfigurator(tracerFactory, flipConfigurator);
}
assertThat(tracer.isEnabled()).isEqualTo(!isEnabled);
}

Expand Down

0 comments on commit 16a8248

Please sign in to comment.