Skip to content

Commit c414c21

Browse files
committed
try
1 parent 7fb2e30 commit c414c21

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterBuilder.java

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
public final class InstrumenterBuilder<REQUEST, RESPONSE> {
5252

5353
private static final Logger logger = Logger.getLogger(InstrumenterBuilder.class.getName());
54-
private static final boolean supportsDeclarativeConfig = supportsDeclarativeConfig();
5554

5655
final OpenTelemetry openTelemetry;
5756
final String instrumentationName;
@@ -75,20 +74,6 @@ public final class InstrumenterBuilder<REQUEST, RESPONSE> {
7574
boolean propagateOperationListenersToOnEnd = false;
7675
boolean enabled = true;
7776

78-
private static boolean supportsDeclarativeConfig() {
79-
try {
80-
Class.forName("io.opentelemetry.api.incubator.ExtendedOpenTelemetry");
81-
return true;
82-
} catch (ClassNotFoundException e) {
83-
// The incubator module is not available.
84-
// This only happens in OpenTelemetry API instrumentation tests, where an older version of
85-
// OpenTelemetry API is used that does not have ExtendedOpenTelemetry.
86-
// Having the incubator module without ExtendedOpenTelemetry class should still return false
87-
// for those tests to avoid a ClassNotFoundException.
88-
return false;
89-
}
90-
}
91-
9277
static {
9378
Experimental.internalAddOperationListenerAttributesExtractor(
9479
(builder, operationListenerAttributesExtractor) ->
@@ -403,10 +388,13 @@ private String getSpanSuppressionStrategy() {
403388
instrumentationConfig.getStructured("java", empty()).getStructured("common", empty());
404389
}
405390
}
406-
return commonConfig.getString(
407-
"span_suppression_strategy/development",
391+
String experimentalOverride =
408392
ConfigPropertiesUtil.getString(
409-
"otel.instrumentation.experimental.span-suppression-strategy"));
393+
"otel.instrumentation.experimental.span-suppression-strategy");
394+
String result =
395+
commonConfig.getString(
396+
"span_suppression_strategy/development", experimentalOverride == null ? "" : experimentalOverride);
397+
return result.isEmpty() ? null : result;
410398
}
411399

412400
private Set<SpanKey> getSpanKeysFromAttributesExtractors() {

testing-common/src/main/java/io/opentelemetry/instrumentation/testing/InstrumentationTestRunner.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@
5252
*/
5353
public abstract class InstrumentationTestRunner {
5454

55-
private final TestInstrumenters testInstrumenters;
55+
private final OpenTelemetry openTelemetry;
56+
// Lazy initialized so that test runners can load without triggering Instrumenter construction
57+
// in the OpenTelemetry API bridging tests where some of the newer OpenTelemetry APIs used by
58+
// Instrumenter are absent.
59+
@Nullable private TestInstrumenters testInstrumenters;
5660
protected Map<InstrumentationScopeInfo, Map<String, MetricData>> metricsByScope = new HashMap<>();
5761
protected Set<InstrumentationScopeInfo> instrumentationScopes = new HashSet<>();
5862

@@ -65,7 +69,7 @@ public abstract class InstrumentationTestRunner {
6569
tracesByScope = new HashMap<>();
6670

6771
protected InstrumentationTestRunner(OpenTelemetry openTelemetry) {
68-
testInstrumenters = new TestInstrumenters(openTelemetry);
72+
this.openTelemetry = openTelemetry;
6973
}
7074

7175
public abstract void beforeTestClass();
@@ -285,7 +289,7 @@ public final <E extends Exception> void runWithSpan(String spanName, ThrowingRun
285289
*/
286290
public final <T, E extends Throwable> T runWithSpan(
287291
String spanName, ThrowingSupplier<T, E> callback) throws E {
288-
return testInstrumenters.runWithSpan(spanName, callback);
292+
return getTestInstrumenters().runWithSpan(spanName, callback);
289293
}
290294

291295
/**
@@ -308,7 +312,7 @@ public final <E extends Throwable> void runWithHttpClientSpan(
308312
*/
309313
public final <T, E extends Throwable> T runWithHttpClientSpan(
310314
String spanName, ThrowingSupplier<T, E> callback) throws E {
311-
return testInstrumenters.runWithHttpClientSpan(spanName, callback);
315+
return getTestInstrumenters().runWithHttpClientSpan(spanName, callback);
312316
}
313317

314318
/**
@@ -330,13 +334,20 @@ public final <E extends Throwable> void runWithHttpServerSpan(ThrowingRunnable<E
330334
*/
331335
public final <T, E extends Throwable> T runWithHttpServerSpan(ThrowingSupplier<T, E> callback)
332336
throws E {
333-
return testInstrumenters.runWithHttpServerSpan(callback);
337+
return getTestInstrumenters().runWithHttpServerSpan(callback);
334338
}
335339

336340
/** Runs the provided {@code callback} inside the scope of a non-recording span. */
337341
public final <T, E extends Throwable> T runWithNonRecordingSpan(ThrowingSupplier<T, E> callback)
338342
throws E {
339-
return testInstrumenters.runWithNonRecordingSpan(callback);
343+
return getTestInstrumenters().runWithNonRecordingSpan(callback);
344+
}
345+
346+
private TestInstrumenters getTestInstrumenters() {
347+
if (testInstrumenters == null) {
348+
testInstrumenters = new TestInstrumenters(openTelemetry);
349+
}
350+
return testInstrumenters;
340351
}
341352

342353
private static void awaitUntilAsserted(Runnable runnable) {

0 commit comments

Comments
 (0)