From 16a824816b8db34af4ccab22d4b28dbef94bc368 Mon Sep 17 00:00:00 2001 From: Jack Shirazi Date: Thu, 23 Jan 2025 15:12:27 +0000 Subject: [PATCH] add test for SdkTracerProviderUtil.setScopeConfigurator --- .../trace/internal/SdkTracerProviderUtil.java | 2 +- .../sdk/trace/SdkTracerProviderTest.java | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/internal/SdkTracerProviderUtil.java b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/internal/SdkTracerProviderUtil.java index e020a223027..b415ffd3ca8 100644 --- a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/internal/SdkTracerProviderUtil.java +++ b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/internal/SdkTracerProviderUtil.java @@ -27,7 +27,7 @@ private SdkTracerProviderUtil() {} /** Reflectively set the {@link ScopeConfigurator} to the {@link SdkTracerProvider}. */ public static void setScopeConfigurator( - SdkTracerProviderBuilder sdkTracerProvider, + SdkTracerProvider sdkTracerProvider, ScopeConfigurator scopeConfigurator) { try { Method method = diff --git a/sdk/trace/src/test/java/io/opentelemetry/sdk/trace/SdkTracerProviderTest.java b/sdk/trace/src/test/java/io/opentelemetry/sdk/trace/SdkTracerProviderTest.java index 53be991c1eb..1224401377b 100644 --- a/sdk/trace/src/test/java/io/opentelemetry/sdk/trace/SdkTracerProviderTest.java +++ b/sdk/trace/src/test/java/io/opentelemetry/sdk/trace/SdkTracerProviderTest.java @@ -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; @@ -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 flipConfigurator = @@ -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); }