Update spring-data-1.9 to new agent api
This commit is contained in:
parent
9b14f7198f
commit
7775c1e132
|
@ -4,7 +4,7 @@ package datadog.trace.instrumentation.springdata;
|
||||||
|
|
||||||
import datadog.trace.agent.decorator.ClientDecorator;
|
import datadog.trace.agent.decorator.ClientDecorator;
|
||||||
import datadog.trace.api.DDTags;
|
import datadog.trace.api.DDTags;
|
||||||
import io.opentracing.Span;
|
import datadog.trace.instrumentation.api.AgentSpan;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
public final class SpringDataDecorator extends ClientDecorator {
|
public final class SpringDataDecorator extends ClientDecorator {
|
||||||
|
@ -32,7 +32,7 @@ public final class SpringDataDecorator extends ClientDecorator {
|
||||||
return "spring-data";
|
return "spring-data";
|
||||||
}
|
}
|
||||||
|
|
||||||
public Span onOperation(final Span span, final Method method) {
|
public AgentSpan onOperation(final AgentSpan span, final Method method) {
|
||||||
assert span != null;
|
assert span != null;
|
||||||
assert method != null;
|
assert method != null;
|
||||||
|
|
||||||
|
|
|
@ -2,15 +2,18 @@
|
||||||
|
|
||||||
package datadog.trace.instrumentation.springdata;
|
package datadog.trace.instrumentation.springdata;
|
||||||
|
|
||||||
|
import static datadog.trace.instrumentation.api.AgentTracer.activateSpan;
|
||||||
|
import static datadog.trace.instrumentation.api.AgentTracer.startSpan;
|
||||||
import static datadog.trace.instrumentation.springdata.SpringDataDecorator.DECORATOR;
|
import static datadog.trace.instrumentation.springdata.SpringDataDecorator.DECORATOR;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.*;
|
import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
|
||||||
|
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
|
||||||
|
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||||
|
import static net.bytebuddy.matcher.ElementMatchers.not;
|
||||||
|
|
||||||
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 datadog.trace.context.TraceScope;
|
import datadog.trace.instrumentation.api.AgentScope;
|
||||||
import io.opentracing.Scope;
|
import datadog.trace.instrumentation.api.AgentSpan;
|
||||||
import io.opentracing.Span;
|
|
||||||
import io.opentracing.util.GlobalTracer;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -57,7 +60,7 @@ public final class SpringRepositoryInstrumentation extends Instrumenter.Default
|
||||||
public static class RepositoryFactorySupportAdvice {
|
public static class RepositoryFactorySupportAdvice {
|
||||||
@Advice.OnMethodExit(suppress = Throwable.class)
|
@Advice.OnMethodExit(suppress = Throwable.class)
|
||||||
public static void onConstruction(
|
public static void onConstruction(
|
||||||
@Advice.This RepositoryFactorySupport repositoryFactorySupport) {
|
@Advice.This final RepositoryFactorySupport repositoryFactorySupport) {
|
||||||
repositoryFactorySupport.addRepositoryProxyPostProcessor(
|
repositoryFactorySupport.addRepositoryProxyPostProcessor(
|
||||||
InterceptingRepositoryProxyPostProcessor.INSTANCE);
|
InterceptingRepositoryProxyPostProcessor.INSTANCE);
|
||||||
}
|
}
|
||||||
|
@ -92,26 +95,24 @@ public final class SpringRepositoryInstrumentation extends Instrumenter.Default
|
||||||
final Method invokedMethod = methodInvocation.getMethod();
|
final Method invokedMethod = methodInvocation.getMethod();
|
||||||
final Class<?> clazz = invokedMethod.getDeclaringClass();
|
final Class<?> clazz = invokedMethod.getDeclaringClass();
|
||||||
|
|
||||||
boolean isRepositoryOp = Repository.class.isAssignableFrom(clazz);
|
final boolean isRepositoryOp = Repository.class.isAssignableFrom(clazz);
|
||||||
// Since this interceptor is the outer most interceptor, non-Repository methods
|
// Since this interceptor is the outer most interceptor, non-Repository methods
|
||||||
// including Object methods will also flow through here. Don't create spans for those.
|
// including Object methods will also flow through here. Don't create spans for those.
|
||||||
if (!isRepositoryOp) {
|
if (!isRepositoryOp) {
|
||||||
return methodInvocation.proceed();
|
return methodInvocation.proceed();
|
||||||
}
|
}
|
||||||
|
|
||||||
final Scope scope = GlobalTracer.get().buildSpan("repository.operation").startActive(true);
|
final AgentSpan span = startSpan("repository.operation");
|
||||||
if (scope instanceof TraceScope) {
|
|
||||||
((TraceScope) scope).setAsyncPropagation(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
final Span span = scope.span();
|
|
||||||
DECORATOR.afterStart(span);
|
DECORATOR.afterStart(span);
|
||||||
DECORATOR.onOperation(span, invokedMethod);
|
DECORATOR.onOperation(span, invokedMethod);
|
||||||
|
|
||||||
|
final AgentScope scope = activateSpan(span, true);
|
||||||
|
scope.setAsyncPropagation(true);
|
||||||
|
|
||||||
Object result = null;
|
Object result = null;
|
||||||
try {
|
try {
|
||||||
result = methodInvocation.proceed();
|
result = methodInvocation.proceed();
|
||||||
} catch (Throwable t) {
|
} catch (final Throwable t) {
|
||||||
DECORATOR.onError(scope, t);
|
DECORATOR.onError(scope, t);
|
||||||
throw t;
|
throw t;
|
||||||
} finally {
|
} finally {
|
||||||
|
|
Loading…
Reference in New Issue