Skip to content

Commit 2ee59a9

Browse files
Fixed Error handling for trace interceptors. (#9097)
Fixed `Error` handling for trace interceptors.
1 parent c01b987 commit 2ee59a9

File tree

5 files changed

+25
-9
lines changed

5 files changed

+25
-9
lines changed

dd-smoke-tests/opentracing/src/main/java/datadog/smoketest/opentracing/ApiVerification.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@
88
public final class ApiVerification {
99
private ApiVerification() {}
1010

11-
public static void verifyInterceptors(Tracer otTracer) {
11+
public static void verifyInterceptors(Tracer otTracer, boolean throwError) {
1212
TraceInterceptor interceptor =
1313
new TraceInterceptor() {
1414
@Override
1515
public Collection<? extends MutableSpan> onTraceComplete(
1616
Collection<? extends MutableSpan> trace) {
17+
// Emulates situation when user code will throw an Error.
18+
if (throwError) {
19+
throw new AssertionError();
20+
}
21+
1722
return trace;
1823
}
1924

@@ -23,6 +28,6 @@ public int priority() {
2328
}
2429
};
2530

26-
((datadog.trace.api.Tracer) otTracer).addTraceInterceptor(interceptor);
31+
otTracer.addTraceInterceptor(interceptor);
2732
}
2833
}

dd-smoke-tests/opentracing/src/main/java/datadog/smoketest/opentracing/OTWithAgentApplication.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ public class OTWithAgentApplication {
1212
public static void main(final String[] args) throws InterruptedException {
1313
final Tracer tracer = GlobalTracer.get();
1414

15-
ApiVerification.verifyInterceptors(datadog.trace.api.GlobalTracer.get());
15+
boolean throwError = args != null && args.length > 0 && Boolean.parseBoolean(args[0]);
16+
ApiVerification.verifyInterceptors(datadog.trace.api.GlobalTracer.get(), throwError);
1617

1718
final Span span = tracer.buildSpan("someOperation").start();
18-
try (final Scope scope = tracer.activateSpan(span)) {
19+
try (final Scope ignored = tracer.activateSpan(span)) {
1920
span.setTag(DDTags.SERVICE_NAME, "someService");
2021
// Verify that the returned object is wrapped correctly.
2122
Span root = (Span) ((MutableSpan) tracer.activeSpan()).getLocalRootSpan();

dd-smoke-tests/opentracing/src/main/java/datadog/smoketest/opentracing/OTWithoutAgentApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static void main(final String[] args) throws InterruptedException {
1313
// register the same tracer with the Datadog API
1414
datadog.trace.api.GlobalTracer.registerIfAbsent(tracer);
1515

16-
ApiVerification.verifyInterceptors(tracer);
16+
ApiVerification.verifyInterceptors(tracer, false);
1717

1818
final Span span = tracer.buildSpan("someOperation").start();
1919
try (final Scope scope = tracer.activateSpan(span)) {

dd-smoke-tests/opentracing/src/test/groovy/datadog/smoketest/OpenTracingSmokeTest.groovy

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import static java.util.concurrent.TimeUnit.SECONDS
99
abstract class OpenTracingSmokeTest extends AbstractSmokeTest {
1010
// Estimate for the amount of time instrumentation, plus request, plus some extra
1111
public static final int TIMEOUT_SECS = 30
12-
// Timeout for individual requests
13-
public static final int REQUEST_TIMEOUT = 5
1412

1513
List<String> baseCommand() {
1614
List<String> command = new ArrayList<>()
@@ -53,3 +51,15 @@ class OTWithAgentTest extends OpenTracingSmokeTest {
5351
processBuilder.directory(new File(buildDirectory))
5452
}
5553
}
54+
55+
class OTWithAgentAssertionErrorTest extends OpenTracingSmokeTest {
56+
@Override
57+
ProcessBuilder createProcessBuilder() {
58+
List<String> command = baseCommand()
59+
command.add(OTWithAgentApplication.name)
60+
command.add("true")
61+
62+
ProcessBuilder processBuilder = new ProcessBuilder(command)
63+
processBuilder.directory(new File(buildDirectory))
64+
}
65+
}

dd-trace-core/src/main/java/datadog/trace/core/CoreTracer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,9 +1040,9 @@ private List<DDSpan> interceptCompleteTrace(List<DDSpan> trace) {
10401040
try {
10411041
// If one TraceInterceptor throws an exception, then continue with the next one
10421042
interceptedTrace = interceptor.onTraceComplete(interceptedTrace);
1043-
} catch (Exception e) {
1043+
} catch (Throwable e) {
10441044
String interceptorName = interceptor.getClass().getName();
1045-
rlLog.warn("Exception in TraceInterceptor {}", interceptorName, e);
1045+
rlLog.warn("Throwable raised in TraceInterceptor {}", interceptorName, e);
10461046
}
10471047
}
10481048
trace = new ArrayList<>(interceptedTrace.size());

0 commit comments

Comments
 (0)