Skip to content

Commit

Permalink
add SdkTracerProviderUtil updator method
Browse files Browse the repository at this point in the history
  • Loading branch information
jackshirazi committed Jan 23, 2025
1 parent 79b639f commit 01a26f6
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.internal.ScopeConfigurator;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand All @@ -24,6 +25,22 @@ public final class SdkTracerProviderUtil {

private SdkTracerProviderUtil() {}

/** Reflectively set the {@link ScopeConfigurator} to the {@link SdkTracerProvider}. */
public static void setScopeConfigurator(
SdkTracerProviderBuilder sdkTracerProvider,
ScopeConfigurator<TracerConfig> scopeConfigurator) {
try {
Method method =
SdkTracerProvider.class.getDeclaredMethod(

Check warning on line 34 in sdk/trace/src/main/java/io/opentelemetry/sdk/trace/internal/SdkTracerProviderUtil.java

View check run for this annotation

Codecov / codecov/patch

sdk/trace/src/main/java/io/opentelemetry/sdk/trace/internal/SdkTracerProviderUtil.java#L33-L34

Added lines #L33 - L34 were not covered by tests
"setScopeConfigurator", ScopeConfigurator.class);
method.setAccessible(true);
method.invoke(sdkTracerProvider, scopeConfigurator);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new IllegalStateException(

Check warning on line 39 in sdk/trace/src/main/java/io/opentelemetry/sdk/trace/internal/SdkTracerProviderUtil.java

View check run for this annotation

Codecov / codecov/patch

sdk/trace/src/main/java/io/opentelemetry/sdk/trace/internal/SdkTracerProviderUtil.java#L36-L39

Added lines #L36 - L39 were not covered by tests
"Error calling setTracerConfigurator on SdkTracerProvider", e);
}
}

Check warning on line 42 in sdk/trace/src/main/java/io/opentelemetry/sdk/trace/internal/SdkTracerProviderUtil.java

View check run for this annotation

Codecov / codecov/patch

sdk/trace/src/main/java/io/opentelemetry/sdk/trace/internal/SdkTracerProviderUtil.java#L41-L42

Added lines #L41 - L42 were not covered by tests

/** Reflectively set the {@link ScopeConfigurator} to the {@link SdkTracerProviderBuilder}. */
public static void setTracerConfigurator(
SdkTracerProviderBuilder sdkTracerProviderBuilder,
Expand Down

0 comments on commit 01a26f6

Please sign in to comment.