Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fixed Error handling for trace interceptors.
  • Loading branch information
AlexeyKuznetsov-DD committed Jul 3, 2025
commit adbd0ad07393372413d37471baca4b21ea8804a1
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@
public final class ApiVerification {
private ApiVerification() {}

public static void verifyInterceptors(Tracer otTracer) {
public static void verifyInterceptors(Tracer otTracer, boolean throwError) {
TraceInterceptor interceptor =
new TraceInterceptor() {
@Override
public Collection<? extends MutableSpan> onTraceComplete(
Collection<? extends MutableSpan> trace) {
// Emulates situation when user code will throw an Error.
if (throwError) {
throw new AssertionError();
}

return trace;
}

Expand All @@ -23,6 +28,6 @@ public int priority() {
}
};

((datadog.trace.api.Tracer) otTracer).addTraceInterceptor(interceptor);
otTracer.addTraceInterceptor(interceptor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ public class OTWithAgentApplication {
public static void main(final String[] args) throws InterruptedException {
final Tracer tracer = GlobalTracer.get();

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

final Span span = tracer.buildSpan("someOperation").start();
try (final Scope scope = tracer.activateSpan(span)) {
try (final Scope ignored = tracer.activateSpan(span)) {
span.setTag(DDTags.SERVICE_NAME, "someService");
// Verify that the returned object is wrapped correctly.
Span root = (Span) ((MutableSpan) tracer.activeSpan()).getLocalRootSpan();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static void main(final String[] args) throws InterruptedException {
// register the same tracer with the Datadog API
datadog.trace.api.GlobalTracer.registerIfAbsent(tracer);

ApiVerification.verifyInterceptors(tracer);
ApiVerification.verifyInterceptors(tracer, false);

final Span span = tracer.buildSpan("someOperation").start();
try (final Scope scope = tracer.activateSpan(span)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import static java.util.concurrent.TimeUnit.SECONDS
abstract class OpenTracingSmokeTest extends AbstractSmokeTest {
// Estimate for the amount of time instrumentation, plus request, plus some extra
public static final int TIMEOUT_SECS = 30
// Timeout for individual requests
public static final int REQUEST_TIMEOUT = 5

List<String> baseCommand() {
List<String> command = new ArrayList<>()
Expand Down Expand Up @@ -53,3 +51,15 @@ class OTWithAgentTest extends OpenTracingSmokeTest {
processBuilder.directory(new File(buildDirectory))
}
}

class OTWithAgentAssertionErrorTest extends OpenTracingSmokeTest {
@Override
ProcessBuilder createProcessBuilder() {
List<String> command = baseCommand()
command.add(OTWithAgentApplication.name)
command.add("true")

ProcessBuilder processBuilder = new ProcessBuilder(command)
processBuilder.directory(new File(buildDirectory))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ private List<DDSpan> interceptCompleteTrace(List<DDSpan> trace) {
try {
// If one TraceInterceptor throws an exception, then continue with the next one
interceptedTrace = interceptor.onTraceComplete(interceptedTrace);
} catch (Exception e) {
} catch (Throwable e) {
String interceptorName = interceptor.getClass().getName();
rlLog.warn("Exception in TraceInterceptor {}", interceptorName, e);
}
Expand Down