Skip to content

Commit

Permalink
Guard against propagation errors leaking out through the interceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
mcculls committed Feb 8, 2023
1 parent d02c6e0 commit 31d570a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/** Tracing Request Handler */
public class TracingRequestHandler extends RequestHandler2 {
Expand All @@ -27,6 +29,8 @@ public class TracingRequestHandler extends RequestHandler2 {

private static final CharSequence AWS_HTTP = UTF8BytesString.create("aws.http");

private static final Logger log = LoggerFactory.getLogger(TracingRequestHandler.class);

@Override
public AmazonWebServiceRequest beforeMarshalling(final AmazonWebServiceRequest request) {
return request;
Expand All @@ -46,7 +50,11 @@ public void beforeRequest(final Request<?> request) {
}
request.addHandlerContext(SCOPE_CONTEXT_KEY, activateSpan(span));
if (Config.get().isAwsPropagationEnabled()) {
propagate().inject(span, request, DECORATE, TracePropagationStyle.XRAY);
try {
propagate().inject(span, request, DECORATE, TracePropagationStyle.XRAY);
} catch (Throwable e) {
log.warn("Unable to inject trace header", e);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import datadog.trace.api.TracePropagationStyle;
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.core.SdkRequest;
import software.amazon.awssdk.core.interceptor.Context;
import software.amazon.awssdk.core.interceptor.ExecutionAttribute;
Expand All @@ -25,6 +27,8 @@ public class TracingExecutionInterceptor implements ExecutionInterceptor {
public static final ExecutionAttribute<AgentSpan> SPAN_ATTRIBUTE =
new ExecutionAttribute<>("DatadogSpan");

private static final Logger log = LoggerFactory.getLogger(TracingExecutionInterceptor.class);

@Override
public void beforeExecution(
final Context.BeforeExecution context, final ExecutionAttributes executionAttributes) {
Expand All @@ -50,13 +54,16 @@ public void afterMarshalling(
public SdkHttpRequest modifyHttpRequest(
Context.ModifyHttpRequest context, ExecutionAttributes executionAttributes) {
if (Config.get().isAwsPropagationEnabled()) {
final AgentSpan span = executionAttributes.getAttribute(SPAN_ATTRIBUTE);
SdkHttpRequest.Builder requestBuilder = context.httpRequest().toBuilder();
propagate().inject(span, requestBuilder, DECORATE, TracePropagationStyle.XRAY);
return requestBuilder.build();
} else {
return context.httpRequest();
try {
final AgentSpan span = executionAttributes.getAttribute(SPAN_ATTRIBUTE);
SdkHttpRequest.Builder requestBuilder = context.httpRequest().toBuilder();
propagate().inject(span, requestBuilder, DECORATE, TracePropagationStyle.XRAY);
return requestBuilder.build();
} catch (Throwable e) {
log.warn("Unable to inject trace header", e);
}
}
return context.httpRequest();
}

@Override
Expand Down

0 comments on commit 31d570a

Please sign in to comment.