googleJavaFormat

This commit is contained in:
dougqh 2019-09-23 15:29:15 -04:00
parent 6b5acc8386
commit 8a89547004
1 changed files with 14 additions and 17 deletions

View File

@ -1,15 +1,20 @@
package datadog.trace.instrumentation.springdata; package datadog.trace.instrumentation.springdata;
import static datadog.trace.instrumentation.springdata.SpringDataDecorator.DECORATOR;
import static net.bytebuddy.matcher.ElementMatchers.*;
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 io.opentracing.Scope;
import io.opentracing.Span; import io.opentracing.Span;
import io.opentracing.util.GlobalTracer; import io.opentracing.util.GlobalTracer;
import java.lang.reflect.Method;
import java.util.Collections;
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;
import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher; import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.utility.JavaModule;
import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation; import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.framework.ProxyFactory; import org.springframework.aop.framework.ProxyFactory;
@ -17,14 +22,6 @@ import org.springframework.data.repository.Repository;
import org.springframework.data.repository.core.support.RepositoryFactorySupport; import org.springframework.data.repository.core.support.RepositoryFactorySupport;
import org.springframework.data.repository.core.support.RepositoryProxyPostProcessor; import org.springframework.data.repository.core.support.RepositoryProxyPostProcessor;
import java.lang.reflect.Method;
import java.security.ProtectionDomain;
import java.util.Collections;
import java.util.Map;
import static datadog.trace.instrumentation.springdata.SpringDataDecorator.DECORATOR;
import static net.bytebuddy.matcher.ElementMatchers.*;
@AutoService(Instrumenter.class) @AutoService(Instrumenter.class)
public final class SpringRepositoryInstrumentation extends Instrumenter.Default { public final class SpringRepositoryInstrumentation extends Instrumenter.Default {
@ -50,22 +47,22 @@ public final class SpringRepositoryInstrumentation extends Instrumenter.Default
@Override @Override
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() { public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
return Collections.singletonMap( return Collections.singletonMap(
isConstructor(), isConstructor(), RepositoryFactorySupportAdvice.class.getName());
RepositoryFactorySupportAdvice.class.getName());
} }
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 RepositoryFactorySupport repositoryFactorySupport) {
repositoryFactorySupport.addRepositoryProxyPostProcessor( repositoryFactorySupport.addRepositoryProxyPostProcessor(
InterceptingRepositoryProxyPostProcessor.INSTANCE); InterceptingRepositoryProxyPostProcessor.INSTANCE);
} }
} }
public static final class InterceptingRepositoryProxyPostProcessor implements RepositoryProxyPostProcessor { public static final class InterceptingRepositoryProxyPostProcessor
implements RepositoryProxyPostProcessor {
public static final RepositoryProxyPostProcessor INSTANCE = public static final RepositoryProxyPostProcessor INSTANCE =
new InterceptingRepositoryProxyPostProcessor(); new InterceptingRepositoryProxyPostProcessor();
@Override @Override
public void postProcess(ProxyFactory factory) { public void postProcess(ProxyFactory factory) {
@ -86,7 +83,7 @@ public final class SpringRepositoryInstrumentation extends Instrumenter.Default
boolean isRepositoryOp = Repository.class.isAssignableFrom(clazz); boolean isRepositoryOp = Repository.class.isAssignableFrom(clazz);
// non-Repository methods including Object methods will also flow through // non-Repository methods including Object methods will also flow through
// this interceptor. Don't create spans for those. // this interceptor. Don't create spans for those.
if ( !isRepositoryOp ) { if (!isRepositoryOp) {
return methodInvocation.proceed(); return methodInvocation.proceed();
} }
@ -98,7 +95,7 @@ public final class SpringRepositoryInstrumentation extends Instrumenter.Default
Object result = null; Object result = null;
try { try {
result = methodInvocation.proceed(); result = methodInvocation.proceed();
} catch ( Throwable t ) { } catch (Throwable t) {
DECORATOR.onError(scope, t); DECORATOR.onError(scope, t);
} finally { } finally {
DECORATOR.beforeFinish(scope); DECORATOR.beforeFinish(scope);