Update aws-java-sdk-1.11.0 to new agent api
This commit is contained in:
parent
887633f086
commit
09cdc177cf
|
@ -12,7 +12,7 @@ import com.amazonaws.Request;
|
||||||
import com.amazonaws.handlers.RequestHandler2;
|
import com.amazonaws.handlers.RequestHandler2;
|
||||||
import com.google.auto.service.AutoService;
|
import com.google.auto.service.AutoService;
|
||||||
import datadog.trace.agent.tooling.Instrumenter;
|
import datadog.trace.agent.tooling.Instrumenter;
|
||||||
import io.opentracing.Scope;
|
import datadog.trace.instrumentation.api.AgentScope;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import net.bytebuddy.asm.Advice;
|
import net.bytebuddy.asm.Advice;
|
||||||
import net.bytebuddy.description.method.MethodDescription;
|
import net.bytebuddy.description.method.MethodDescription;
|
||||||
|
@ -60,7 +60,7 @@ public class AWSHttpClientInstrumentation extends Instrumenter.Default {
|
||||||
@Advice.Argument(value = 0, optional = true) final Request<?> request,
|
@Advice.Argument(value = 0, optional = true) final Request<?> request,
|
||||||
@Advice.Thrown final Throwable throwable) {
|
@Advice.Thrown final Throwable throwable) {
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
final Scope scope = request.getHandlerContext(TracingRequestHandler.SCOPE_CONTEXT_KEY);
|
final AgentScope scope = request.getHandlerContext(TracingRequestHandler.SCOPE_CONTEXT_KEY);
|
||||||
if (scope != null) {
|
if (scope != null) {
|
||||||
request.addHandlerContext(TracingRequestHandler.SCOPE_CONTEXT_KEY, null);
|
request.addHandlerContext(TracingRequestHandler.SCOPE_CONTEXT_KEY, null);
|
||||||
DECORATE.onError(scope.span(), throwable);
|
DECORATE.onError(scope.span(), throwable);
|
||||||
|
@ -96,7 +96,8 @@ public class AWSHttpClientInstrumentation extends Instrumenter.Default {
|
||||||
@Advice.FieldValue("request") final Request<?> request,
|
@Advice.FieldValue("request") final Request<?> request,
|
||||||
@Advice.Thrown final Throwable throwable) {
|
@Advice.Thrown final Throwable throwable) {
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
final Scope scope = request.getHandlerContext(TracingRequestHandler.SCOPE_CONTEXT_KEY);
|
final AgentScope scope =
|
||||||
|
request.getHandlerContext(TracingRequestHandler.SCOPE_CONTEXT_KEY);
|
||||||
if (scope != null) {
|
if (scope != null) {
|
||||||
request.addHandlerContext(TracingRequestHandler.SCOPE_CONTEXT_KEY, null);
|
request.addHandlerContext(TracingRequestHandler.SCOPE_CONTEXT_KEY, null);
|
||||||
DECORATE.onError(scope.span(), throwable);
|
DECORATE.onError(scope.span(), throwable);
|
||||||
|
|
|
@ -5,7 +5,7 @@ import com.amazonaws.Request;
|
||||||
import com.amazonaws.Response;
|
import com.amazonaws.Response;
|
||||||
import datadog.trace.agent.decorator.HttpClientDecorator;
|
import datadog.trace.agent.decorator.HttpClientDecorator;
|
||||||
import datadog.trace.api.DDTags;
|
import datadog.trace.api.DDTags;
|
||||||
import io.opentracing.Span;
|
import datadog.trace.instrumentation.api.AgentSpan;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -20,7 +20,7 @@ public class AwsSdkClientDecorator extends HttpClientDecorator<Request, Response
|
||||||
private final Map<Class, String> operationNames = new ConcurrentHashMap<>();
|
private final Map<Class, String> operationNames = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Span onRequest(final Span span, final Request request) {
|
public AgentSpan onRequest(final AgentSpan span, final Request request) {
|
||||||
// Call super first because we override the resource name below.
|
// Call super first because we override the resource name below.
|
||||||
super.onRequest(span, request);
|
super.onRequest(span, request);
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ public class AwsSdkClientDecorator extends HttpClientDecorator<Request, Response
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Span onResponse(final Span span, final Response response) {
|
public AgentSpan onResponse(final AgentSpan span, final Response response) {
|
||||||
if (response.getAwsResponse() instanceof AmazonWebServiceResponse) {
|
if (response.getAwsResponse() instanceof AmazonWebServiceResponse) {
|
||||||
final AmazonWebServiceResponse awsResp = (AmazonWebServiceResponse) response.getAwsResponse();
|
final AmazonWebServiceResponse awsResp = (AmazonWebServiceResponse) response.getAwsResponse();
|
||||||
span.setTag("aws.requestId", awsResp.getRequestId());
|
span.setTag("aws.requestId", awsResp.getRequestId());
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package datadog.trace.instrumentation.aws.v0;
|
package datadog.trace.instrumentation.aws.v0;
|
||||||
|
|
||||||
|
import static datadog.trace.instrumentation.api.AgentTracer.activateSpan;
|
||||||
|
import static datadog.trace.instrumentation.api.AgentTracer.startSpan;
|
||||||
import static datadog.trace.instrumentation.aws.v0.AwsSdkClientDecorator.DECORATE;
|
import static datadog.trace.instrumentation.aws.v0.AwsSdkClientDecorator.DECORATE;
|
||||||
|
|
||||||
import com.amazonaws.AmazonWebServiceRequest;
|
import com.amazonaws.AmazonWebServiceRequest;
|
||||||
|
@ -7,8 +9,8 @@ import com.amazonaws.Request;
|
||||||
import com.amazonaws.Response;
|
import com.amazonaws.Response;
|
||||||
import com.amazonaws.handlers.HandlerContextKey;
|
import com.amazonaws.handlers.HandlerContextKey;
|
||||||
import com.amazonaws.handlers.RequestHandler2;
|
import com.amazonaws.handlers.RequestHandler2;
|
||||||
import io.opentracing.Scope;
|
import datadog.trace.instrumentation.api.AgentScope;
|
||||||
import io.opentracing.util.GlobalTracer;
|
import datadog.trace.instrumentation.api.AgentSpan;
|
||||||
|
|
||||||
/** Tracing Request Handler */
|
/** Tracing Request Handler */
|
||||||
public class TracingRequestHandler extends RequestHandler2 {
|
public class TracingRequestHandler extends RequestHandler2 {
|
||||||
|
@ -16,7 +18,7 @@ public class TracingRequestHandler extends RequestHandler2 {
|
||||||
|
|
||||||
// Note: aws1.x sdk doesn't have any truly async clients so we can store scope in request context
|
// Note: aws1.x sdk doesn't have any truly async clients so we can store scope in request context
|
||||||
// safely.
|
// safely.
|
||||||
public static final HandlerContextKey<Scope> SCOPE_CONTEXT_KEY =
|
public static final HandlerContextKey<AgentScope> SCOPE_CONTEXT_KEY =
|
||||||
new HandlerContextKey<>("DatadogScope");
|
new HandlerContextKey<>("DatadogScope");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -26,15 +28,15 @@ public class TracingRequestHandler extends RequestHandler2 {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforeRequest(final Request<?> request) {
|
public void beforeRequest(final Request<?> request) {
|
||||||
final Scope scope = GlobalTracer.get().buildSpan("aws.command").startActive(true);
|
final AgentSpan span = startSpan("aws.command");
|
||||||
DECORATE.afterStart(scope.span());
|
DECORATE.afterStart(span);
|
||||||
DECORATE.onRequest(scope.span(), request);
|
DECORATE.onRequest(span, request);
|
||||||
request.addHandlerContext(SCOPE_CONTEXT_KEY, scope);
|
request.addHandlerContext(SCOPE_CONTEXT_KEY, activateSpan(span, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterResponse(final Request<?> request, final Response<?> response) {
|
public void afterResponse(final Request<?> request, final Response<?> response) {
|
||||||
final Scope scope = request.getHandlerContext(SCOPE_CONTEXT_KEY);
|
final AgentScope scope = request.getHandlerContext(SCOPE_CONTEXT_KEY);
|
||||||
if (scope != null) {
|
if (scope != null) {
|
||||||
request.addHandlerContext(SCOPE_CONTEXT_KEY, null);
|
request.addHandlerContext(SCOPE_CONTEXT_KEY, null);
|
||||||
DECORATE.onResponse(scope.span(), response);
|
DECORATE.onResponse(scope.span(), response);
|
||||||
|
@ -45,7 +47,7 @@ public class TracingRequestHandler extends RequestHandler2 {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterError(final Request<?> request, final Response<?> response, final Exception e) {
|
public void afterError(final Request<?> request, final Response<?> response, final Exception e) {
|
||||||
final Scope scope = request.getHandlerContext(SCOPE_CONTEXT_KEY);
|
final AgentScope scope = request.getHandlerContext(SCOPE_CONTEXT_KEY);
|
||||||
if (scope != null) {
|
if (scope != null) {
|
||||||
request.addHandlerContext(SCOPE_CONTEXT_KEY, null);
|
request.addHandlerContext(SCOPE_CONTEXT_KEY, null);
|
||||||
DECORATE.onError(scope.span(), e);
|
DECORATE.onError(scope.span(), e);
|
||||||
|
|
Loading…
Reference in New Issue