Refactor Instrumenters into InstrumentationModules - N, O, P (#1575)
This commit is contained in:
parent
ef58ec1770
commit
7f36dd1617
|
@ -12,7 +12,6 @@ import static net.bytebuddy.matcher.ElementMatchers.isMethod;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.api.trace.Span.Kind;
|
||||
import io.opentelemetry.context.Context;
|
||||
|
@ -20,8 +19,7 @@ import io.opentelemetry.context.Scope;
|
|||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.netty.v3_8.client.NettyHttpClientTracer;
|
||||
import io.opentelemetry.javaagent.tooling.Instrumenter;
|
||||
import java.util.Collections;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
|
@ -30,14 +28,7 @@ import net.bytebuddy.matcher.ElementMatcher;
|
|||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelFuture;
|
||||
|
||||
@AutoService(Instrumenter.class)
|
||||
public class ChannelFutureListenerInstrumentation extends Instrumenter.Default {
|
||||
|
||||
public ChannelFutureListenerInstrumentation() {
|
||||
super(
|
||||
NettyChannelPipelineInstrumentation.INSTRUMENTATION_NAME,
|
||||
NettyChannelPipelineInstrumentation.ADDITIONAL_INSTRUMENTATION_NAMES);
|
||||
}
|
||||
final class ChannelFutureListenerInstrumentation implements TypeInstrumentation {
|
||||
|
||||
@Override
|
||||
public ElementMatcher<ClassLoader> classLoaderMatcher() {
|
||||
|
@ -50,19 +41,6 @@ public class ChannelFutureListenerInstrumentation extends Instrumenter.Default {
|
|||
return implementsInterface(named("org.jboss.netty.channel.ChannelFutureListener"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
packageName + ".AbstractNettyAdvice",
|
||||
packageName + ".ChannelTraceContext",
|
||||
packageName + ".ChannelTraceContext$Factory",
|
||||
packageName + ".client.NettyHttpClientTracer",
|
||||
packageName + ".client.NettyResponseInjectAdapter",
|
||||
packageName + ".server.NettyHttpServerTracer",
|
||||
packageName + ".server.NettyRequestExtractAdapter"
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
|
||||
return singletonMap(
|
||||
|
@ -72,12 +50,6 @@ public class ChannelFutureListenerInstrumentation extends Instrumenter.Default {
|
|||
ChannelFutureListenerInstrumentation.class.getName() + "$OperationCompleteAdvice");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> contextStore() {
|
||||
return Collections.singletonMap(
|
||||
"org.jboss.netty.channel.Channel", packageName + ".ChannelTraceContext");
|
||||
}
|
||||
|
||||
public static class OperationCompleteAdvice extends AbstractNettyAdvice {
|
||||
@Advice.OnMethodEnter
|
||||
public static Scope activateScope(@Advice.Argument(0) ChannelFuture future) {
|
||||
|
|
|
@ -11,14 +11,12 @@ import static net.bytebuddy.matcher.ElementMatchers.isMethod;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.returns;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge;
|
||||
import io.opentelemetry.javaagent.tooling.Instrumenter;
|
||||
import java.util.Collections;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
|
@ -27,13 +25,7 @@ import net.bytebuddy.description.type.TypeDescription;
|
|||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
import org.jboss.netty.channel.Channel;
|
||||
|
||||
@AutoService(Instrumenter.class)
|
||||
public class NettyChannelInstrumentation extends Instrumenter.Default {
|
||||
public NettyChannelInstrumentation() {
|
||||
super(
|
||||
NettyChannelPipelineInstrumentation.INSTRUMENTATION_NAME,
|
||||
NettyChannelPipelineInstrumentation.ADDITIONAL_INSTRUMENTATION_NAMES);
|
||||
}
|
||||
final class NettyChannelInstrumentation implements TypeInstrumentation {
|
||||
|
||||
@Override
|
||||
public ElementMatcher<ClassLoader> classLoaderMatcher() {
|
||||
|
@ -46,17 +38,6 @@ public class NettyChannelInstrumentation extends Instrumenter.Default {
|
|||
return implementsInterface(named("org.jboss.netty.channel.Channel"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
packageName + ".server.NettyHttpServerTracer",
|
||||
packageName + ".server.NettyRequestExtractAdapter",
|
||||
packageName + ".AbstractNettyAdvice",
|
||||
packageName + ".ChannelTraceContext",
|
||||
packageName + ".ChannelTraceContext$Factory",
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
|
||||
Map<ElementMatcher<? super MethodDescription>, String> transformers = new HashMap<>();
|
||||
|
@ -68,12 +49,6 @@ public class NettyChannelInstrumentation extends Instrumenter.Default {
|
|||
return transformers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> contextStore() {
|
||||
return Collections.singletonMap(
|
||||
"org.jboss.netty.channel.Channel", ChannelTraceContext.class.getName());
|
||||
}
|
||||
|
||||
public static class ChannelConnectAdvice extends AbstractNettyAdvice {
|
||||
@Advice.OnMethodEnter
|
||||
public static void addConnectContinuation(@Advice.This Channel channel) {
|
||||
|
|
|
@ -12,7 +12,6 @@ import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.CallDepthThreadLocalMap;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext;
|
||||
|
@ -22,8 +21,7 @@ import io.opentelemetry.javaagent.instrumentation.netty.v3_8.client.HttpClientTr
|
|||
import io.opentelemetry.javaagent.instrumentation.netty.v3_8.server.HttpServerRequestTracingHandler;
|
||||
import io.opentelemetry.javaagent.instrumentation.netty.v3_8.server.HttpServerResponseTracingHandler;
|
||||
import io.opentelemetry.javaagent.instrumentation.netty.v3_8.server.HttpServerTracingHandler;
|
||||
import io.opentelemetry.javaagent.tooling.Instrumenter;
|
||||
import java.util.Collections;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
|
@ -40,15 +38,7 @@ import org.jboss.netty.handler.codec.http.HttpResponseDecoder;
|
|||
import org.jboss.netty.handler.codec.http.HttpResponseEncoder;
|
||||
import org.jboss.netty.handler.codec.http.HttpServerCodec;
|
||||
|
||||
@AutoService(Instrumenter.class)
|
||||
public class NettyChannelPipelineInstrumentation extends Instrumenter.Default {
|
||||
|
||||
static final String INSTRUMENTATION_NAME = "netty";
|
||||
static final String[] ADDITIONAL_INSTRUMENTATION_NAMES = {"netty-3.8"};
|
||||
|
||||
public NettyChannelPipelineInstrumentation() {
|
||||
super(INSTRUMENTATION_NAME, ADDITIONAL_INSTRUMENTATION_NAMES);
|
||||
}
|
||||
final class NettyChannelPipelineInstrumentation implements TypeInstrumentation {
|
||||
|
||||
@Override
|
||||
public ElementMatcher<ClassLoader> classLoaderMatcher() {
|
||||
|
@ -61,30 +51,6 @@ public class NettyChannelPipelineInstrumentation extends Instrumenter.Default {
|
|||
return implementsInterface(named("org.jboss.netty.channel.ChannelPipeline"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
packageName + ".AbstractNettyAdvice",
|
||||
packageName + ".ChannelTraceContext",
|
||||
packageName + ".ChannelTraceContext$Factory",
|
||||
NettyChannelPipelineInstrumentation.class.getName() + "$ChannelPipelineAdviceUtil",
|
||||
// Util
|
||||
packageName + ".util.CombinedSimpleChannelHandler",
|
||||
// client helpers
|
||||
packageName + ".client.NettyHttpClientTracer",
|
||||
packageName + ".client.NettyResponseInjectAdapter",
|
||||
packageName + ".client.HttpClientRequestTracingHandler",
|
||||
packageName + ".client.HttpClientResponseTracingHandler",
|
||||
packageName + ".client.HttpClientTracingHandler",
|
||||
// server helpers
|
||||
packageName + ".server.NettyHttpServerTracer",
|
||||
packageName + ".server.NettyRequestExtractAdapter",
|
||||
packageName + ".server.HttpServerRequestTracingHandler",
|
||||
packageName + ".server.HttpServerResponseTracingHandler",
|
||||
packageName + ".server.HttpServerTracingHandler"
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
|
||||
Map<ElementMatcher<? super MethodDescription>, String> transformers = new HashMap<>();
|
||||
|
@ -101,12 +67,6 @@ public class NettyChannelPipelineInstrumentation extends Instrumenter.Default {
|
|||
return transformers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> contextStore() {
|
||||
return Collections.singletonMap(
|
||||
"org.jboss.netty.channel.Channel", ChannelTraceContext.class.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* When certain handlers are added to the pipeline, we want to add our corresponding tracing
|
||||
* handlers. If those handlers are later removed, we may want to remove our handlers. That is not
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.javaagent.instrumentation.netty.v3_8;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.opentelemetry.javaagent.tooling.InstrumentationModule;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@AutoService(InstrumentationModule.class)
|
||||
public class NettyInstrumentationModule extends InstrumentationModule {
|
||||
public NettyInstrumentationModule() {
|
||||
super("netty", "netty-3.8");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
packageName + ".ChannelTraceContext",
|
||||
packageName + ".ChannelTraceContext$Factory",
|
||||
NettyChannelPipelineInstrumentation.class.getName() + "$ChannelPipelineAdviceUtil",
|
||||
// Util
|
||||
packageName + ".util.CombinedSimpleChannelHandler",
|
||||
// client helpers
|
||||
packageName + ".client.NettyHttpClientTracer",
|
||||
packageName + ".client.NettyResponseInjectAdapter",
|
||||
packageName + ".client.HttpClientRequestTracingHandler",
|
||||
packageName + ".client.HttpClientResponseTracingHandler",
|
||||
packageName + ".client.HttpClientTracingHandler",
|
||||
// server helpers
|
||||
packageName + ".server.NettyHttpServerTracer",
|
||||
packageName + ".server.NettyRequestExtractAdapter",
|
||||
packageName + ".server.HttpServerRequestTracingHandler",
|
||||
packageName + ".server.HttpServerResponseTracingHandler",
|
||||
packageName + ".server.HttpServerTracingHandler"
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TypeInstrumentation> typeInstrumentations() {
|
||||
return asList(
|
||||
new ChannelFutureListenerInstrumentation(),
|
||||
new NettyChannelInstrumentation(),
|
||||
new NettyChannelPipelineInstrumentation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> contextStore() {
|
||||
return Collections.singletonMap(
|
||||
"org.jboss.netty.channel.Channel", ChannelTraceContext.class.getName());
|
||||
}
|
||||
}
|
|
@ -12,28 +12,20 @@ import static net.bytebuddy.matcher.ElementMatchers.isMethod;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.api.trace.Span.Kind;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.javaagent.instrumentation.netty.v4_0.client.NettyHttpClientTracer;
|
||||
import io.opentelemetry.javaagent.tooling.Instrumenter;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
@AutoService(Instrumenter.class)
|
||||
public class ChannelFutureListenerInstrumentation extends Instrumenter.Default {
|
||||
|
||||
public ChannelFutureListenerInstrumentation() {
|
||||
super(
|
||||
NettyChannelPipelineInstrumentation.INSTRUMENTATION_NAME,
|
||||
NettyChannelPipelineInstrumentation.ADDITIONAL_INSTRUMENTATION_NAMES);
|
||||
}
|
||||
final class ChannelFutureListenerInstrumentation implements TypeInstrumentation {
|
||||
|
||||
@Override
|
||||
public ElementMatcher<ClassLoader> classLoaderMatcher() {
|
||||
|
@ -46,26 +38,6 @@ public class ChannelFutureListenerInstrumentation extends Instrumenter.Default {
|
|||
return implementsInterface(named("io.netty.channel.ChannelFutureListener"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
packageName + ".AttributeKeys",
|
||||
packageName + ".AttributeKeys$1",
|
||||
// client helpers
|
||||
packageName + ".client.NettyHttpClientTracer",
|
||||
packageName + ".client.NettyResponseInjectAdapter",
|
||||
packageName + ".client.HttpClientRequestTracingHandler",
|
||||
packageName + ".client.HttpClientResponseTracingHandler",
|
||||
packageName + ".client.HttpClientTracingHandler",
|
||||
// server helpers
|
||||
packageName + ".server.NettyHttpServerTracer",
|
||||
packageName + ".server.NettyRequestExtractAdapter",
|
||||
packageName + ".server.HttpServerRequestTracingHandler",
|
||||
packageName + ".server.HttpServerResponseTracingHandler",
|
||||
packageName + ".server.HttpServerTracingHandler"
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
|
||||
return singletonMap(
|
||||
|
|
|
@ -13,7 +13,6 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.returns;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.handler.codec.http.HttpClientCodec;
|
||||
|
@ -32,7 +31,7 @@ import io.opentelemetry.javaagent.instrumentation.netty.v4_0.client.HttpClientTr
|
|||
import io.opentelemetry.javaagent.instrumentation.netty.v4_0.server.HttpServerRequestTracingHandler;
|
||||
import io.opentelemetry.javaagent.instrumentation.netty.v4_0.server.HttpServerResponseTracingHandler;
|
||||
import io.opentelemetry.javaagent.instrumentation.netty.v4_0.server.HttpServerTracingHandler;
|
||||
import io.opentelemetry.javaagent.tooling.Instrumenter;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
|
@ -40,15 +39,7 @@ import net.bytebuddy.description.method.MethodDescription;
|
|||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
@AutoService(Instrumenter.class)
|
||||
public class NettyChannelPipelineInstrumentation extends Instrumenter.Default {
|
||||
|
||||
static final String INSTRUMENTATION_NAME = "netty";
|
||||
static final String[] ADDITIONAL_INSTRUMENTATION_NAMES = {"netty-4.0"};
|
||||
|
||||
public NettyChannelPipelineInstrumentation() {
|
||||
super(INSTRUMENTATION_NAME, ADDITIONAL_INSTRUMENTATION_NAMES);
|
||||
}
|
||||
final class NettyChannelPipelineInstrumentation implements TypeInstrumentation {
|
||||
|
||||
@Override
|
||||
public ElementMatcher<ClassLoader> classLoaderMatcher() {
|
||||
|
@ -61,26 +52,6 @@ public class NettyChannelPipelineInstrumentation extends Instrumenter.Default {
|
|||
return implementsInterface(named("io.netty.channel.ChannelPipeline"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
packageName + ".AttributeKeys",
|
||||
packageName + ".AttributeKeys$1",
|
||||
// client helpers
|
||||
packageName + ".client.NettyHttpClientTracer",
|
||||
packageName + ".client.NettyResponseInjectAdapter",
|
||||
packageName + ".client.HttpClientRequestTracingHandler",
|
||||
packageName + ".client.HttpClientResponseTracingHandler",
|
||||
packageName + ".client.HttpClientTracingHandler",
|
||||
// server helpers
|
||||
packageName + ".server.NettyHttpServerTracer",
|
||||
packageName + ".server.NettyRequestExtractAdapter",
|
||||
packageName + ".server.HttpServerRequestTracingHandler",
|
||||
packageName + ".server.HttpServerResponseTracingHandler",
|
||||
packageName + ".server.HttpServerTracingHandler"
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
|
||||
Map<ElementMatcher<? super MethodDescription>, String> transformers = new HashMap<>();
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.javaagent.instrumentation.netty.v4_0;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.opentelemetry.javaagent.tooling.InstrumentationModule;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.List;
|
||||
|
||||
@AutoService(InstrumentationModule.class)
|
||||
public class NettyInstrumentationModule extends InstrumentationModule {
|
||||
public NettyInstrumentationModule() {
|
||||
super("netty", "netty-4.0");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
packageName + ".AttributeKeys",
|
||||
packageName + ".AttributeKeys$1",
|
||||
// client helpers
|
||||
packageName + ".client.NettyHttpClientTracer",
|
||||
packageName + ".client.NettyResponseInjectAdapter",
|
||||
packageName + ".client.HttpClientRequestTracingHandler",
|
||||
packageName + ".client.HttpClientResponseTracingHandler",
|
||||
packageName + ".client.HttpClientTracingHandler",
|
||||
// server helpers
|
||||
packageName + ".server.NettyHttpServerTracer",
|
||||
packageName + ".server.NettyRequestExtractAdapter",
|
||||
packageName + ".server.HttpServerRequestTracingHandler",
|
||||
packageName + ".server.HttpServerResponseTracingHandler",
|
||||
packageName + ".server.HttpServerTracingHandler"
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TypeInstrumentation> typeInstrumentations() {
|
||||
return asList(
|
||||
new ChannelFutureListenerInstrumentation(), new NettyChannelPipelineInstrumentation());
|
||||
}
|
||||
}
|
|
@ -12,28 +12,20 @@ import static net.bytebuddy.matcher.ElementMatchers.isMethod;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.api.trace.Span.Kind;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.javaagent.instrumentation.netty.v4_1.client.NettyHttpClientTracer;
|
||||
import io.opentelemetry.javaagent.tooling.Instrumenter;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
@AutoService(Instrumenter.class)
|
||||
public class ChannelFutureListenerInstrumentation extends Instrumenter.Default {
|
||||
|
||||
public ChannelFutureListenerInstrumentation() {
|
||||
super(
|
||||
NettyChannelPipelineInstrumentation.INSTRUMENTATION_NAME,
|
||||
NettyChannelPipelineInstrumentation.ADDITIONAL_INSTRUMENTATION_NAMES);
|
||||
}
|
||||
final class ChannelFutureListenerInstrumentation implements TypeInstrumentation {
|
||||
|
||||
@Override
|
||||
public ElementMatcher<ClassLoader> classLoaderMatcher() {
|
||||
|
@ -46,26 +38,6 @@ public class ChannelFutureListenerInstrumentation extends Instrumenter.Default {
|
|||
return implementsInterface(named("io.netty.channel.ChannelFutureListener"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
packageName + ".AttributeKeys",
|
||||
packageName + ".AttributeKeys$1",
|
||||
// client helpers
|
||||
packageName + ".client.NettyHttpClientTracer",
|
||||
packageName + ".client.NettyResponseInjectAdapter",
|
||||
packageName + ".client.HttpClientRequestTracingHandler",
|
||||
packageName + ".client.HttpClientResponseTracingHandler",
|
||||
packageName + ".client.HttpClientTracingHandler",
|
||||
// server helpers
|
||||
packageName + ".server.NettyHttpServerTracer",
|
||||
packageName + ".server.NettyRequestExtractAdapter",
|
||||
packageName + ".server.HttpServerRequestTracingHandler",
|
||||
packageName + ".server.HttpServerResponseTracingHandler",
|
||||
packageName + ".server.HttpServerTracingHandler"
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
|
||||
return singletonMap(
|
||||
|
|
|
@ -13,7 +13,6 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.returns;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.handler.codec.http.HttpClientCodec;
|
||||
|
@ -32,7 +31,7 @@ import io.opentelemetry.javaagent.instrumentation.netty.v4_1.client.HttpClientTr
|
|||
import io.opentelemetry.javaagent.instrumentation.netty.v4_1.server.HttpServerRequestTracingHandler;
|
||||
import io.opentelemetry.javaagent.instrumentation.netty.v4_1.server.HttpServerResponseTracingHandler;
|
||||
import io.opentelemetry.javaagent.instrumentation.netty.v4_1.server.HttpServerTracingHandler;
|
||||
import io.opentelemetry.javaagent.tooling.Instrumenter;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
|
@ -40,15 +39,7 @@ import net.bytebuddy.description.method.MethodDescription;
|
|||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
@AutoService(Instrumenter.class)
|
||||
public class NettyChannelPipelineInstrumentation extends Instrumenter.Default {
|
||||
|
||||
static final String INSTRUMENTATION_NAME = "netty";
|
||||
static final String[] ADDITIONAL_INSTRUMENTATION_NAMES = {"netty-4.1"};
|
||||
|
||||
public NettyChannelPipelineInstrumentation() {
|
||||
super(INSTRUMENTATION_NAME, ADDITIONAL_INSTRUMENTATION_NAMES);
|
||||
}
|
||||
final class NettyChannelPipelineInstrumentation implements TypeInstrumentation {
|
||||
|
||||
@Override
|
||||
public ElementMatcher<ClassLoader> classLoaderMatcher() {
|
||||
|
@ -61,26 +52,6 @@ public class NettyChannelPipelineInstrumentation extends Instrumenter.Default {
|
|||
return implementsInterface(named("io.netty.channel.ChannelPipeline"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
packageName + ".AttributeKeys",
|
||||
packageName + ".AttributeKeys$1",
|
||||
// client helpers
|
||||
packageName + ".client.NettyHttpClientTracer",
|
||||
packageName + ".client.NettyResponseInjectAdapter",
|
||||
packageName + ".client.HttpClientRequestTracingHandler",
|
||||
packageName + ".client.HttpClientResponseTracingHandler",
|
||||
packageName + ".client.HttpClientTracingHandler",
|
||||
// server helpers
|
||||
packageName + ".server.NettyHttpServerTracer",
|
||||
packageName + ".server.NettyRequestExtractAdapter",
|
||||
packageName + ".server.HttpServerRequestTracingHandler",
|
||||
packageName + ".server.HttpServerResponseTracingHandler",
|
||||
packageName + ".server.HttpServerTracingHandler"
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
|
||||
Map<ElementMatcher<? super MethodDescription>, String> transformers = new HashMap<>();
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.javaagent.instrumentation.netty.v4_1;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.opentelemetry.javaagent.tooling.InstrumentationModule;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.List;
|
||||
|
||||
@AutoService(InstrumentationModule.class)
|
||||
public class NettyInstrumentationModule extends InstrumentationModule {
|
||||
public NettyInstrumentationModule() {
|
||||
super("netty", "netty-4.1");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
packageName + ".AttributeKeys",
|
||||
packageName + ".AttributeKeys$1",
|
||||
// client helpers
|
||||
packageName + ".client.NettyHttpClientTracer",
|
||||
packageName + ".client.NettyResponseInjectAdapter",
|
||||
packageName + ".client.HttpClientRequestTracingHandler",
|
||||
packageName + ".client.HttpClientResponseTracingHandler",
|
||||
packageName + ".client.HttpClientTracingHandler",
|
||||
// server helpers
|
||||
packageName + ".server.NettyHttpServerTracer",
|
||||
packageName + ".server.NettyRequestExtractAdapter",
|
||||
packageName + ".server.HttpServerRequestTracingHandler",
|
||||
packageName + ".server.HttpServerResponseTracingHandler",
|
||||
packageName + ".server.HttpServerTracingHandler"
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TypeInstrumentation> typeInstrumentations() {
|
||||
return asList(
|
||||
new ChannelFutureListenerInstrumentation(), new NettyChannelPipelineInstrumentation());
|
||||
}
|
||||
}
|
|
@ -5,31 +5,29 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.okhttp.v2_2;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import com.squareup.okhttp.Interceptor;
|
||||
import com.squareup.okhttp.OkHttpClient;
|
||||
import io.opentelemetry.javaagent.tooling.Instrumenter;
|
||||
import io.opentelemetry.javaagent.tooling.InstrumentationModule;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
@AutoService(Instrumenter.class)
|
||||
public class OkHttp2Instrumentation extends Instrumenter.Default {
|
||||
public OkHttp2Instrumentation() {
|
||||
@AutoService(InstrumentationModule.class)
|
||||
public class OkHttp2InstrumentationModule extends InstrumentationModule {
|
||||
public OkHttp2InstrumentationModule() {
|
||||
super("okhttp", "okhttp-2");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElementMatcher<? super TypeDescription> typeMatcher() {
|
||||
return named("com.squareup.okhttp.OkHttpClient");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
|
@ -39,10 +37,22 @@ public class OkHttp2Instrumentation extends Instrumenter.Default {
|
|||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TypeInstrumentation> typeInstrumentations() {
|
||||
return singletonList(new OkHttpClientInstrumentation());
|
||||
}
|
||||
|
||||
private static final class OkHttpClientInstrumentation implements TypeInstrumentation {
|
||||
@Override
|
||||
public ElementMatcher<? super TypeDescription> typeMatcher() {
|
||||
return named("com.squareup.okhttp.OkHttpClient");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
|
||||
return Collections.singletonMap(
|
||||
isConstructor(), OkHttp2Instrumentation.class.getName() + "$OkHttp2ClientAdvice");
|
||||
isConstructor(), OkHttp2InstrumentationModule.class.getName() + "$OkHttp2ClientAdvice");
|
||||
}
|
||||
}
|
||||
|
||||
public static class OkHttp2ClientAdvice {
|
|
@ -5,13 +5,16 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.okhttp.v3_0;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.opentelemetry.javaagent.tooling.Instrumenter;
|
||||
import io.opentelemetry.javaagent.tooling.InstrumentationModule;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
|
@ -20,18 +23,13 @@ import net.bytebuddy.matcher.ElementMatcher;
|
|||
import okhttp3.Interceptor;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
@AutoService(Instrumenter.class)
|
||||
public class OkHttp3Instrumentation extends Instrumenter.Default {
|
||||
@AutoService(InstrumentationModule.class)
|
||||
public class OkHttp3InstrumentationModule extends InstrumentationModule {
|
||||
|
||||
public OkHttp3Instrumentation() {
|
||||
public OkHttp3InstrumentationModule() {
|
||||
super("okhttp", "okhttp-3");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElementMatcher<TypeDescription> typeMatcher() {
|
||||
return named("okhttp3.OkHttpClient");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
|
@ -41,11 +39,23 @@ public class OkHttp3Instrumentation extends Instrumenter.Default {
|
|||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TypeInstrumentation> typeInstrumentations() {
|
||||
return singletonList(new OkHttpClientInstrumentation());
|
||||
}
|
||||
|
||||
private static final class OkHttpClientInstrumentation implements TypeInstrumentation {
|
||||
@Override
|
||||
public ElementMatcher<TypeDescription> typeMatcher() {
|
||||
return named("okhttp3.OkHttpClient");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
|
||||
return singletonMap(
|
||||
isConstructor().and(takesArgument(0, named("okhttp3.OkHttpClient$Builder"))),
|
||||
OkHttp3Instrumentation.class.getName() + "$OkHttp3Advice");
|
||||
OkHttp3InstrumentationModule.class.getName() + "$OkHttp3Advice");
|
||||
}
|
||||
}
|
||||
|
||||
public static class OkHttp3Advice {
|
|
@ -12,9 +12,8 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||
|
||||
import application.io.opentelemetry.context.Context;
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.opentelemetry.api.baggage.Baggage;
|
||||
import io.opentelemetry.javaagent.tooling.Instrumenter;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
|
@ -25,8 +24,7 @@ import net.bytebuddy.matcher.ElementMatcher;
|
|||
// TODO: Actually bridge correlation context. We currently just stub out withBaggage
|
||||
// to have minimum functionality with SDK shim implementations.
|
||||
// https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/973
|
||||
@AutoService(Instrumenter.class)
|
||||
public class BaggageUtilsInstrumentation extends AbstractInstrumentation {
|
||||
final class BaggageUtilsInstrumentation implements TypeInstrumentation {
|
||||
@Override
|
||||
public ElementMatcher<? super TypeDescription> typeMatcher() {
|
||||
return named("application.io.opentelemetry.api.baggage.BaggageUtils");
|
||||
|
|
|
@ -11,9 +11,8 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
|
||||
import application.io.opentelemetry.context.Context;
|
||||
import application.io.opentelemetry.context.ContextStorage;
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.opentelemetry.javaagent.instrumentation.opentelemetryapi.context.AgentContextStorage;
|
||||
import io.opentelemetry.javaagent.tooling.Instrumenter;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
|
@ -27,8 +26,7 @@ import net.bytebuddy.matcher.ElementMatcher;
|
|||
* sure there is no dependency on a system property or possibility of a user overriding this since
|
||||
* it's required for instrumentation in the agent to work properly.
|
||||
*/
|
||||
@AutoService(Instrumenter.class)
|
||||
public class ContextInstrumentation extends AbstractInstrumentation {
|
||||
final class ContextInstrumentation implements TypeInstrumentation {
|
||||
|
||||
@Override
|
||||
public ElementMatcher<? super TypeDescription> typeMatcher() {
|
||||
|
|
|
@ -10,9 +10,8 @@ import static net.bytebuddy.matcher.ElementMatchers.isStatic;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
||||
import application.io.opentelemetry.context.ContextStorage;
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.opentelemetry.javaagent.instrumentation.opentelemetryapi.context.AgentContextStorage;
|
||||
import io.opentelemetry.javaagent.tooling.Instrumenter;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
|
@ -26,8 +25,7 @@ import net.bytebuddy.matcher.ElementMatcher;
|
|||
* sure there is no dependency on a system property or possibility of a user overriding this since
|
||||
* it's required for instrumentation in the agent to work properly.
|
||||
*/
|
||||
@AutoService(Instrumenter.class)
|
||||
public class ContextStorageInstrumentation extends AbstractInstrumentation {
|
||||
final class ContextStorageInstrumentation implements TypeInstrumentation {
|
||||
|
||||
@Override
|
||||
public ElementMatcher<? super TypeDescription> typeMatcher() {
|
||||
|
|
|
@ -5,10 +5,16 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.opentelemetryapi;
|
||||
|
||||
import io.opentelemetry.javaagent.tooling.Instrumenter;
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public abstract class AbstractInstrumentation extends Instrumenter.Default {
|
||||
public AbstractInstrumentation() {
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.opentelemetry.javaagent.tooling.InstrumentationModule;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.List;
|
||||
|
||||
@AutoService(InstrumentationModule.class)
|
||||
public class OpenTelemetryApiInstrumentationModule extends InstrumentationModule {
|
||||
public OpenTelemetryApiInstrumentationModule() {
|
||||
super("opentelemetry-api");
|
||||
}
|
||||
|
||||
|
@ -80,4 +86,14 @@ public abstract class AbstractInstrumentation extends Instrumenter.Default {
|
|||
packageName + ".LabelBridging"
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TypeInstrumentation> typeInstrumentations() {
|
||||
return asList(
|
||||
new BaggageUtilsInstrumentation(),
|
||||
new ContextInstrumentation(),
|
||||
new ContextStorageInstrumentation(),
|
||||
new OpenTelemetryInstrumentation(),
|
||||
new SpanInstrumentation());
|
||||
}
|
||||
}
|
|
@ -12,11 +12,10 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
|||
|
||||
import application.io.opentelemetry.api.metrics.MeterProvider;
|
||||
import application.io.opentelemetry.context.propagation.ContextPropagators;
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.opentelemetry.javaagent.instrumentation.opentelemetryapi.context.propagation.ApplicationContextPropagators;
|
||||
import io.opentelemetry.javaagent.instrumentation.opentelemetryapi.metrics.ApplicationMeterProvider;
|
||||
import io.opentelemetry.javaagent.instrumentation.opentelemetryapi.trace.ApplicationTracerProvider;
|
||||
import io.opentelemetry.javaagent.tooling.Instrumenter;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
|
@ -24,8 +23,7 @@ import net.bytebuddy.description.method.MethodDescription;
|
|||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
@AutoService(Instrumenter.class)
|
||||
public class OpenTelemetryApiInstrumentation extends AbstractInstrumentation {
|
||||
final class OpenTelemetryInstrumentation implements TypeInstrumentation {
|
||||
|
||||
@Override
|
||||
public ElementMatcher<? super TypeDescription> typeMatcher() {
|
||||
|
@ -37,13 +35,13 @@ public class OpenTelemetryApiInstrumentation extends AbstractInstrumentation {
|
|||
Map<ElementMatcher<? super MethodDescription>, String> transformers = new HashMap<>();
|
||||
transformers.put(
|
||||
isMethod().and(isPublic()).and(named("getGlobalTracerProvider")).and(takesArguments(0)),
|
||||
OpenTelemetryApiInstrumentation.class.getName() + "$GetTracerProviderAdvice");
|
||||
OpenTelemetryInstrumentation.class.getName() + "$GetTracerProviderAdvice");
|
||||
transformers.put(
|
||||
isMethod().and(isPublic()).and(named("getGlobalMeterProvider")).and(takesArguments(0)),
|
||||
OpenTelemetryApiInstrumentation.class.getName() + "$GetMeterProviderAdvice");
|
||||
OpenTelemetryInstrumentation.class.getName() + "$GetMeterProviderAdvice");
|
||||
transformers.put(
|
||||
isMethod().and(isPublic()).and(named("getGlobalPropagators")).and(takesArguments(0)),
|
||||
OpenTelemetryApiInstrumentation.class.getName() + "$GetPropagatorsAdvice");
|
||||
OpenTelemetryInstrumentation.class.getName() + "$GetPropagatorsAdvice");
|
||||
return transformers;
|
||||
}
|
||||
|
|
@ -11,9 +11,8 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
|
||||
import application.io.opentelemetry.api.trace.Span;
|
||||
import application.io.opentelemetry.api.trace.SpanContext;
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.opentelemetry.javaagent.instrumentation.opentelemetryapi.trace.Bridging;
|
||||
import io.opentelemetry.javaagent.tooling.Instrumenter;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
|
@ -21,8 +20,7 @@ import net.bytebuddy.description.method.MethodDescription;
|
|||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
@AutoService(Instrumenter.class)
|
||||
public class SpanInstrumentation extends AbstractInstrumentation {
|
||||
final class SpanInstrumentation implements TypeInstrumentation {
|
||||
@Override
|
||||
public ElementMatcher<? super TypeDescription> typeMatcher() {
|
||||
return named("application.io.opentelemetry.api.trace.PropagatedSpan");
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.javaagent.instrumentation.opentelemetryapi.anotations;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.isDeclaredBy;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.none;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.config.Config;
|
||||
import io.opentelemetry.instrumentation.api.config.MethodsConfigurationParser;
|
||||
import io.opentelemetry.javaagent.tooling.Instrumenter;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import net.bytebuddy.description.ByteCodeElement;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
import net.bytebuddy.matcher.ElementMatchers;
|
||||
|
||||
public abstract class AbstractTraceAnnotationInstrumentation extends Instrumenter.Default {
|
||||
private static final String TRACE_ANNOTATED_METHODS_EXCLUDE_CONFIG =
|
||||
"otel.trace.annotated.methods.exclude";
|
||||
|
||||
public AbstractTraceAnnotationInstrumentation(
|
||||
String instrumentationName, String... additionalNames) {
|
||||
super(instrumentationName, additionalNames);
|
||||
}
|
||||
|
||||
/*
|
||||
Returns a matcher for all methods that should be excluded from auto-instrumentation by
|
||||
annotation-based advices.
|
||||
*/
|
||||
ElementMatcher.Junction<MethodDescription> configureExcludedMethods() {
|
||||
ElementMatcher.Junction<MethodDescription> result = none();
|
||||
|
||||
Map<String, Set<String>> excludedMethods =
|
||||
MethodsConfigurationParser.parse(
|
||||
Config.get().getProperty(TRACE_ANNOTATED_METHODS_EXCLUDE_CONFIG));
|
||||
for (Map.Entry<String, Set<String>> entry : excludedMethods.entrySet()) {
|
||||
String className = entry.getKey();
|
||||
ElementMatcher.Junction<ByteCodeElement> classMather =
|
||||
isDeclaredBy(ElementMatchers.<TypeDescription>named(className));
|
||||
|
||||
ElementMatcher.Junction<MethodDescription> excludedMethodsMatcher = none();
|
||||
for (String methodName : entry.getValue()) {
|
||||
excludedMethodsMatcher = excludedMethodsMatcher.or(ElementMatchers.named(methodName));
|
||||
}
|
||||
|
||||
result = result.or(classMather.and(excludedMethodsMatcher));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@ import net.bytebuddy.asm.Advice;
|
|||
/**
|
||||
* Instrumentation for methods annotated with {@link WithSpan} annotation.
|
||||
*
|
||||
* @see WithSpanAnnotationInstrumentation
|
||||
* @see WithSpanAnnotationInstrumentationModule
|
||||
*/
|
||||
public class WithSpanAdvice {
|
||||
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.javaagent.instrumentation.opentelemetryapi.anotations;
|
||||
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.declaresMethod;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.isAnnotatedWith;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.not;
|
||||
|
||||
import application.io.opentelemetry.extension.auto.annotations.WithSpan;
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.opentelemetry.javaagent.tooling.Instrumenter;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.description.annotation.AnnotationSource;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
/** Instrumentation for methods annotated with {@link WithSpan} annotation. */
|
||||
@AutoService(Instrumenter.class)
|
||||
public final class WithSpanAnnotationInstrumentation
|
||||
extends AbstractTraceAnnotationInstrumentation {
|
||||
|
||||
private final ElementMatcher.Junction<AnnotationSource> annotatedMethodMatcher;
|
||||
/*
|
||||
This matcher matches all methods that should be excluded from transformation
|
||||
*/
|
||||
private final ElementMatcher.Junction<MethodDescription> excludedMethodsMatcher;
|
||||
|
||||
public WithSpanAnnotationInstrumentation() {
|
||||
super("trace", "with-span-annotation");
|
||||
annotatedMethodMatcher =
|
||||
isAnnotatedWith(named("application.io.opentelemetry.extension.auto.annotations.WithSpan"));
|
||||
excludedMethodsMatcher = configureExcludedMethods();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElementMatcher<TypeDescription> typeMatcher() {
|
||||
return declaresMethod(annotatedMethodMatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
packageName + ".TraceAnnotationTracer",
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
|
||||
return singletonMap(
|
||||
annotatedMethodMatcher.and(not(excludedMethodsMatcher)), packageName + ".WithSpanAdvice");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.javaagent.instrumentation.opentelemetryapi.anotations;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.declaresMethod;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.isAnnotatedWith;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.isDeclaredBy;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.none;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.not;
|
||||
|
||||
import application.io.opentelemetry.extension.auto.annotations.WithSpan;
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.opentelemetry.instrumentation.api.config.Config;
|
||||
import io.opentelemetry.instrumentation.api.config.MethodsConfigurationParser;
|
||||
import io.opentelemetry.javaagent.tooling.InstrumentationModule;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import net.bytebuddy.description.ByteCodeElement;
|
||||
import net.bytebuddy.description.annotation.AnnotationSource;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
import net.bytebuddy.matcher.ElementMatchers;
|
||||
|
||||
/** Instrumentation for methods annotated with {@link WithSpan} annotation. */
|
||||
@AutoService(InstrumentationModule.class)
|
||||
public final class WithSpanAnnotationInstrumentationModule extends InstrumentationModule {
|
||||
|
||||
private static final String TRACE_ANNOTATED_METHODS_EXCLUDE_CONFIG =
|
||||
"otel.trace.annotated.methods.exclude";
|
||||
|
||||
public WithSpanAnnotationInstrumentationModule() {
|
||||
super("trace", "with-span-annotation");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
packageName + ".TraceAnnotationTracer",
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TypeInstrumentation> typeInstrumentations() {
|
||||
return singletonList(new AnnotatedMethodInstrumentation());
|
||||
}
|
||||
|
||||
private static final class AnnotatedMethodInstrumentation implements TypeInstrumentation {
|
||||
private final ElementMatcher.Junction<AnnotationSource> annotatedMethodMatcher;
|
||||
/** This matcher matches all methods that should be excluded from transformation */
|
||||
private final ElementMatcher.Junction<MethodDescription> excludedMethodsMatcher;
|
||||
|
||||
AnnotatedMethodInstrumentation() {
|
||||
annotatedMethodMatcher =
|
||||
isAnnotatedWith(
|
||||
named("application.io.opentelemetry.extension.auto.annotations.WithSpan"));
|
||||
excludedMethodsMatcher = configureExcludedMethods();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElementMatcher<TypeDescription> typeMatcher() {
|
||||
return declaresMethod(annotatedMethodMatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
|
||||
return singletonMap(
|
||||
annotatedMethodMatcher.and(not(excludedMethodsMatcher)), WithSpanAdvice.class.getName());
|
||||
}
|
||||
|
||||
/*
|
||||
Returns a matcher for all methods that should be excluded from auto-instrumentation by
|
||||
annotation-based advices.
|
||||
*/
|
||||
static ElementMatcher.Junction<MethodDescription> configureExcludedMethods() {
|
||||
ElementMatcher.Junction<MethodDescription> result = none();
|
||||
|
||||
Map<String, Set<String>> excludedMethods =
|
||||
MethodsConfigurationParser.parse(
|
||||
Config.get().getProperty(TRACE_ANNOTATED_METHODS_EXCLUDE_CONFIG));
|
||||
for (Map.Entry<String, Set<String>> entry : excludedMethods.entrySet()) {
|
||||
String className = entry.getKey();
|
||||
ElementMatcher.Junction<ByteCodeElement> classMather =
|
||||
isDeclaredBy(ElementMatchers.named(className));
|
||||
|
||||
ElementMatcher.Junction<MethodDescription> excludedMethodsMatcher = none();
|
||||
for (String methodName : entry.getValue()) {
|
||||
excludedMethodsMatcher = excludedMethodsMatcher.or(ElementMatchers.named(methodName));
|
||||
}
|
||||
|
||||
result = result.or(classMather.and(excludedMethodsMatcher));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@
|
|||
package io.opentelemetry.javaagent.instrumentation.oshi;
|
||||
|
||||
import static io.opentelemetry.javaagent.tooling.ClassLoaderMatcher.hasClassesNamed;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.isStatic;
|
||||
|
@ -13,31 +14,23 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.opentelemetry.instrumentation.oshi.SystemMetrics;
|
||||
import io.opentelemetry.javaagent.tooling.Instrumenter;
|
||||
import io.opentelemetry.javaagent.tooling.InstrumentationModule;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
@AutoService(Instrumenter.class)
|
||||
public class OshiInstrumentation extends Instrumenter.Default {
|
||||
@AutoService(InstrumentationModule.class)
|
||||
public class OshiInstrumentationModule extends InstrumentationModule {
|
||||
|
||||
public OshiInstrumentation() {
|
||||
public OshiInstrumentationModule() {
|
||||
super("oshi");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElementMatcher<ClassLoader> classLoaderMatcher() {
|
||||
return hasClassesNamed("oshi.SystemInfo");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElementMatcher<? super TypeDescription> typeMatcher() {
|
||||
return named("oshi.SystemInfo");
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String[] helperClassNames() {
|
||||
return new String[] {
|
||||
|
@ -52,11 +45,28 @@ public class OshiInstrumentation extends Instrumenter.Default {
|
|||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TypeInstrumentation> typeInstrumentations() {
|
||||
return singletonList(new SystemInfoInstrumentation());
|
||||
}
|
||||
|
||||
private static final class SystemInfoInstrumentation implements TypeInstrumentation {
|
||||
@Override
|
||||
public ElementMatcher<ClassLoader> classLoaderMatcher() {
|
||||
return hasClassesNamed("oshi.SystemInfo");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElementMatcher<? super TypeDescription> typeMatcher() {
|
||||
return named("oshi.SystemInfo");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
|
||||
return Collections.singletonMap(
|
||||
isMethod().and(isPublic()).and(isStatic()).and(named("getCurrentPlatformEnum")),
|
||||
OshiInstrumentation.class.getName() + "$OshiInstrumentationAdvice");
|
||||
OshiInstrumentationModule.class.getName() + "$OshiInstrumentationAdvice");
|
||||
}
|
||||
}
|
||||
|
||||
public static class OshiInstrumentationAdvice {
|
|
@ -6,27 +6,49 @@
|
|||
package io.opentelemetry.javaagent.instrumentation.playws.v1_0;
|
||||
|
||||
import static io.opentelemetry.javaagent.instrumentation.playws.PlayWSClientTracer.tracer;
|
||||
import static java.util.Collections.singletonList;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge;
|
||||
import io.opentelemetry.javaagent.instrumentation.playws.BasePlayWSClientInstrumentation;
|
||||
import io.opentelemetry.javaagent.tooling.Instrumenter;
|
||||
import io.opentelemetry.javaagent.instrumentation.playws.AsyncHttpClientInstrumentation;
|
||||
import io.opentelemetry.javaagent.tooling.InstrumentationModule;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.List;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import play.shaded.ahc.org.asynchttpclient.AsyncHandler;
|
||||
import play.shaded.ahc.org.asynchttpclient.Request;
|
||||
import play.shaded.ahc.org.asynchttpclient.handler.StreamedAsyncHandler;
|
||||
import play.shaded.ahc.org.asynchttpclient.ws.WebSocketUpgradeHandler;
|
||||
|
||||
@AutoService(Instrumenter.class)
|
||||
public class PlayWSClientInstrumentation extends BasePlayWSClientInstrumentation {
|
||||
@AutoService(InstrumentationModule.class)
|
||||
public class PlayWsInstrumentationModule extends InstrumentationModule {
|
||||
public PlayWsInstrumentationModule() {
|
||||
super("play-ws");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
"io.opentelemetry.javaagent.instrumentation.playws.PlayWSClientTracer",
|
||||
"io.opentelemetry.javaagent.instrumentation.playws.HeadersInjectAdapter",
|
||||
packageName + ".AsyncHandlerWrapper",
|
||||
packageName + ".StreamedAsyncHandlerWrapper"
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TypeInstrumentation> typeInstrumentations() {
|
||||
return singletonList(new AsyncHttpClientInstrumentation(ClientAdvice.class.getName()));
|
||||
}
|
||||
|
||||
public static class ClientAdvice {
|
||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static void methodEnter(
|
||||
@Advice.Argument(0) Request request,
|
||||
@Advice.Argument(value = 1, readOnly = false) AsyncHandler asyncHandler,
|
||||
@Advice.Argument(value = 1, readOnly = false) AsyncHandler<?> asyncHandler,
|
||||
@Advice.Local("otelSpan") Span span,
|
||||
@Advice.Local("otelScope") Scope scope) {
|
||||
Context parentContext = Java8BytecodeBridge.currentContext();
|
||||
|
@ -37,7 +59,7 @@ public class PlayWSClientInstrumentation extends BasePlayWSClientInstrumentation
|
|||
if (asyncHandler instanceof StreamedAsyncHandler) {
|
||||
asyncHandler =
|
||||
new StreamedAsyncHandlerWrapper(
|
||||
(StreamedAsyncHandler) asyncHandler, span, parentContext);
|
||||
(StreamedAsyncHandler<?>) asyncHandler, span, parentContext);
|
||||
} else if (!(asyncHandler instanceof WebSocketUpgradeHandler)) {
|
||||
// websocket upgrade handlers aren't supported
|
||||
asyncHandler = new AsyncHandlerWrapper(asyncHandler, span, parentContext);
|
|
@ -6,25 +6,47 @@
|
|||
package io.opentelemetry.javaagent.instrumentation.playws.v2_0;
|
||||
|
||||
import static io.opentelemetry.javaagent.instrumentation.playws.PlayWSClientTracer.tracer;
|
||||
import static java.util.Collections.singletonList;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.javaagent.instrumentation.playws.BasePlayWSClientInstrumentation;
|
||||
import io.opentelemetry.javaagent.tooling.Instrumenter;
|
||||
import io.opentelemetry.javaagent.instrumentation.playws.AsyncHttpClientInstrumentation;
|
||||
import io.opentelemetry.javaagent.tooling.InstrumentationModule;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.List;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import play.shaded.ahc.org.asynchttpclient.AsyncHandler;
|
||||
import play.shaded.ahc.org.asynchttpclient.Request;
|
||||
import play.shaded.ahc.org.asynchttpclient.handler.StreamedAsyncHandler;
|
||||
import play.shaded.ahc.org.asynchttpclient.ws.WebSocketUpgradeHandler;
|
||||
|
||||
@AutoService(Instrumenter.class)
|
||||
public class PlayWSClientInstrumentation extends BasePlayWSClientInstrumentation {
|
||||
@AutoService(InstrumentationModule.class)
|
||||
public class PlayWsInstrumentationModule extends InstrumentationModule {
|
||||
public PlayWsInstrumentationModule() {
|
||||
super("play-ws");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
"io.opentelemetry.javaagent.instrumentation.playws.PlayWSClientTracer",
|
||||
"io.opentelemetry.javaagent.instrumentation.playws.HeadersInjectAdapter",
|
||||
packageName + ".AsyncHandlerWrapper",
|
||||
packageName + ".StreamedAsyncHandlerWrapper"
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TypeInstrumentation> typeInstrumentations() {
|
||||
return singletonList(new AsyncHttpClientInstrumentation(ClientAdvice.class.getName()));
|
||||
}
|
||||
|
||||
public static class ClientAdvice {
|
||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static void methodEnter(
|
||||
@Advice.Argument(0) Request request,
|
||||
@Advice.Argument(value = 1, readOnly = false) AsyncHandler asyncHandler,
|
||||
@Advice.Argument(value = 1, readOnly = false) AsyncHandler<?> asyncHandler,
|
||||
@Advice.Local("otelSpan") Span span) {
|
||||
|
||||
span = tracer().startSpan(request);
|
||||
|
@ -33,7 +55,8 @@ public class PlayWSClientInstrumentation extends BasePlayWSClientInstrumentation
|
|||
scope.close();
|
||||
|
||||
if (asyncHandler instanceof StreamedAsyncHandler) {
|
||||
asyncHandler = new StreamedAsyncHandlerWrapper((StreamedAsyncHandler) asyncHandler, span);
|
||||
asyncHandler =
|
||||
new StreamedAsyncHandlerWrapper((StreamedAsyncHandler<?>) asyncHandler, span);
|
||||
} else if (!(asyncHandler instanceof WebSocketUpgradeHandler)) {
|
||||
// websocket upgrade handlers aren't supported
|
||||
asyncHandler = new AsyncHandlerWrapper(asyncHandler, span);
|
|
@ -6,25 +6,47 @@
|
|||
package io.opentelemetry.javaagent.instrumentation.playws.v2_1;
|
||||
|
||||
import static io.opentelemetry.javaagent.instrumentation.playws.PlayWSClientTracer.tracer;
|
||||
import static java.util.Collections.singletonList;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.javaagent.instrumentation.playws.BasePlayWSClientInstrumentation;
|
||||
import io.opentelemetry.javaagent.tooling.Instrumenter;
|
||||
import io.opentelemetry.javaagent.instrumentation.playws.AsyncHttpClientInstrumentation;
|
||||
import io.opentelemetry.javaagent.tooling.InstrumentationModule;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.List;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import play.shaded.ahc.org.asynchttpclient.AsyncHandler;
|
||||
import play.shaded.ahc.org.asynchttpclient.Request;
|
||||
import play.shaded.ahc.org.asynchttpclient.handler.StreamedAsyncHandler;
|
||||
import play.shaded.ahc.org.asynchttpclient.ws.WebSocketUpgradeHandler;
|
||||
|
||||
@AutoService(Instrumenter.class)
|
||||
public class PlayWSClientInstrumentation extends BasePlayWSClientInstrumentation {
|
||||
@AutoService(InstrumentationModule.class)
|
||||
public class PlayWsInstrumentationModule extends InstrumentationModule {
|
||||
public PlayWsInstrumentationModule() {
|
||||
super("play-ws");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
"io.opentelemetry.javaagent.instrumentation.playws.PlayWSClientTracer",
|
||||
"io.opentelemetry.javaagent.instrumentation.playws.HeadersInjectAdapter",
|
||||
packageName + ".AsyncHandlerWrapper",
|
||||
packageName + ".StreamedAsyncHandlerWrapper"
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TypeInstrumentation> typeInstrumentations() {
|
||||
return singletonList(new AsyncHttpClientInstrumentation(ClientAdvice.class.getName()));
|
||||
}
|
||||
|
||||
public static class ClientAdvice {
|
||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static void methodEnter(
|
||||
@Advice.Argument(0) Request request,
|
||||
@Advice.Argument(value = 1, readOnly = false) AsyncHandler asyncHandler,
|
||||
@Advice.Argument(value = 1, readOnly = false) AsyncHandler<?> asyncHandler,
|
||||
@Advice.Local("otelSpan") Span span) {
|
||||
|
||||
span = tracer().startSpan(request);
|
||||
|
@ -33,7 +55,8 @@ public class PlayWSClientInstrumentation extends BasePlayWSClientInstrumentation
|
|||
scope.close();
|
||||
|
||||
if (asyncHandler instanceof StreamedAsyncHandler) {
|
||||
asyncHandler = new StreamedAsyncHandlerWrapper((StreamedAsyncHandler) asyncHandler, span);
|
||||
asyncHandler =
|
||||
new StreamedAsyncHandlerWrapper((StreamedAsyncHandler<?>) asyncHandler, span);
|
||||
} else if (!(asyncHandler instanceof WebSocketUpgradeHandler)) {
|
||||
// websocket upgrade handlers aren't supported
|
||||
asyncHandler = new AsyncHandlerWrapper(asyncHandler, span);
|
|
@ -15,15 +15,17 @@ import static net.bytebuddy.matcher.ElementMatchers.not;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||
|
||||
import io.opentelemetry.javaagent.tooling.Instrumenter;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
public abstract class BasePlayWSClientInstrumentation extends Instrumenter.Default {
|
||||
public BasePlayWSClientInstrumentation() {
|
||||
super("play-ws");
|
||||
public class AsyncHttpClientInstrumentation implements TypeInstrumentation {
|
||||
private final String adviceName;
|
||||
|
||||
public AsyncHttpClientInstrumentation(String adviceName) {
|
||||
this.adviceName = adviceName;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -50,16 +52,6 @@ public abstract class BasePlayWSClientInstrumentation extends Instrumenter.Defau
|
|||
.and(takesArguments(2))
|
||||
.and(takesArgument(0, named("play.shaded.ahc.org.asynchttpclient.Request")))
|
||||
.and(takesArgument(1, named("play.shaded.ahc.org.asynchttpclient.AsyncHandler"))),
|
||||
getClass().getName() + "$ClientAdvice");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
"io.opentelemetry.javaagent.instrumentation.playws.PlayWSClientTracer",
|
||||
"io.opentelemetry.javaagent.instrumentation.playws.HeadersInjectAdapter",
|
||||
packageName + ".AsyncHandlerWrapper",
|
||||
packageName + ".StreamedAsyncHandlerWrapper"
|
||||
};
|
||||
adviceName);
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.javaagent.instrumentation.play.v2_3;
|
||||
|
||||
import static io.opentelemetry.javaagent.tooling.ClassLoaderMatcher.hasClassesNamed;
|
||||
import static io.opentelemetry.javaagent.tooling.bytebuddy.matcher.AgentElementMatchers.implementsInterface;
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.returns;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.opentelemetry.javaagent.tooling.Instrumenter;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
@AutoService(Instrumenter.class)
|
||||
public final class PlayInstrumentation extends Instrumenter.Default {
|
||||
|
||||
public PlayInstrumentation() {
|
||||
super("play", "play-action");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElementMatcher<ClassLoader> classLoaderMatcher() {
|
||||
// Optimization for expensive typeMatcher.
|
||||
return hasClassesNamed("play.api.mvc.Action");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElementMatcher<TypeDescription> typeMatcher() {
|
||||
return implementsInterface(named("play.api.mvc.Action"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {packageName + ".PlayTracer", packageName + ".RequestCompleteCallback"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
|
||||
return singletonMap(
|
||||
named("apply")
|
||||
.and(takesArgument(0, named("play.api.mvc.Request")))
|
||||
.and(returns(named("scala.concurrent.Future"))),
|
||||
packageName + ".PlayAdvice");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.javaagent.instrumentation.play.v2_3;
|
||||
|
||||
import static io.opentelemetry.javaagent.tooling.ClassLoaderMatcher.hasClassesNamed;
|
||||
import static io.opentelemetry.javaagent.tooling.bytebuddy.matcher.AgentElementMatchers.implementsInterface;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.returns;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.opentelemetry.javaagent.tooling.InstrumentationModule;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
@AutoService(InstrumentationModule.class)
|
||||
public final class PlayInstrumentationModule extends InstrumentationModule {
|
||||
|
||||
public PlayInstrumentationModule() {
|
||||
super("play", "play-action");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {packageName + ".PlayTracer", packageName + ".RequestCompleteCallback"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TypeInstrumentation> typeInstrumentations() {
|
||||
return singletonList(new ActionInstrumentation());
|
||||
}
|
||||
|
||||
private static final class ActionInstrumentation implements TypeInstrumentation {
|
||||
@Override
|
||||
public ElementMatcher<ClassLoader> classLoaderMatcher() {
|
||||
// Optimization for expensive typeMatcher.
|
||||
return hasClassesNamed("play.api.mvc.Action");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElementMatcher<TypeDescription> typeMatcher() {
|
||||
return implementsInterface(named("play.api.mvc.Action"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
|
||||
return singletonMap(
|
||||
named("apply")
|
||||
.and(takesArgument(0, named("play.api.mvc.Request")))
|
||||
.and(returns(named("scala.concurrent.Future"))),
|
||||
PlayAdvice.class.getName());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.javaagent.instrumentation.play.v2_4;
|
||||
|
||||
import static io.opentelemetry.javaagent.tooling.ClassLoaderMatcher.hasClassesNamed;
|
||||
import static io.opentelemetry.javaagent.tooling.bytebuddy.matcher.AgentElementMatchers.implementsInterface;
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.returns;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.opentelemetry.javaagent.tooling.Instrumenter;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
@AutoService(Instrumenter.class)
|
||||
public final class PlayInstrumentation extends Instrumenter.Default {
|
||||
|
||||
public PlayInstrumentation() {
|
||||
super("play");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElementMatcher<ClassLoader> classLoaderMatcher() {
|
||||
// Optimization for expensive typeMatcher.
|
||||
return hasClassesNamed("play.api.mvc.Action");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElementMatcher<TypeDescription> typeMatcher() {
|
||||
return implementsInterface(named("play.api.mvc.Action"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {packageName + ".PlayTracer", packageName + ".RequestCompleteCallback"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
|
||||
return singletonMap(
|
||||
named("apply")
|
||||
.and(takesArgument(0, named("play.api.mvc.Request")))
|
||||
.and(returns(named("scala.concurrent.Future"))),
|
||||
packageName + ".PlayAdvice");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.javaagent.instrumentation.play.v2_4;
|
||||
|
||||
import static io.opentelemetry.javaagent.tooling.ClassLoaderMatcher.hasClassesNamed;
|
||||
import static io.opentelemetry.javaagent.tooling.bytebuddy.matcher.AgentElementMatchers.implementsInterface;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.returns;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.opentelemetry.javaagent.tooling.InstrumentationModule;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
@AutoService(InstrumentationModule.class)
|
||||
public final class PlayInstrumentationModule extends InstrumentationModule {
|
||||
|
||||
public PlayInstrumentationModule() {
|
||||
super("play");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {packageName + ".PlayTracer", packageName + ".RequestCompleteCallback"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TypeInstrumentation> typeInstrumentations() {
|
||||
return singletonList(new ActionInstrumentation());
|
||||
}
|
||||
|
||||
private static final class ActionInstrumentation implements TypeInstrumentation {
|
||||
@Override
|
||||
public ElementMatcher<ClassLoader> classLoaderMatcher() {
|
||||
// Optimization for expensive typeMatcher.
|
||||
return hasClassesNamed("play.api.mvc.Action");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElementMatcher<TypeDescription> typeMatcher() {
|
||||
return implementsInterface(named("play.api.mvc.Action"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
|
||||
return singletonMap(
|
||||
named("apply")
|
||||
.and(takesArgument(0, named("play.api.mvc.Request")))
|
||||
.and(returns(named("scala.concurrent.Future"))),
|
||||
PlayAdvice.class.getName());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.javaagent.instrumentation.play.v2_6;
|
||||
|
||||
import static io.opentelemetry.javaagent.tooling.ClassLoaderMatcher.hasClassesNamed;
|
||||
import static io.opentelemetry.javaagent.tooling.bytebuddy.matcher.AgentElementMatchers.implementsInterface;
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.returns;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.opentelemetry.javaagent.tooling.Instrumenter;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
@AutoService(Instrumenter.class)
|
||||
public final class PlayInstrumentation extends Instrumenter.Default {
|
||||
|
||||
public PlayInstrumentation() {
|
||||
super("play");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElementMatcher<ClassLoader> classLoaderMatcher() {
|
||||
// Optimization for expensive typeMatcher.
|
||||
return hasClassesNamed("play.api.mvc.Action");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElementMatcher<TypeDescription> typeMatcher() {
|
||||
return implementsInterface(named("play.api.mvc.Action"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {packageName + ".PlayTracer", packageName + ".RequestCompleteCallback"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
|
||||
return singletonMap(
|
||||
named("apply")
|
||||
.and(takesArgument(0, named("play.api.mvc.Request")))
|
||||
.and(returns(named("scala.concurrent.Future"))),
|
||||
packageName + ".PlayAdvice");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.javaagent.instrumentation.play.v2_6;
|
||||
|
||||
import static io.opentelemetry.javaagent.tooling.ClassLoaderMatcher.hasClassesNamed;
|
||||
import static io.opentelemetry.javaagent.tooling.bytebuddy.matcher.AgentElementMatchers.implementsInterface;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.returns;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.opentelemetry.javaagent.tooling.InstrumentationModule;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
@AutoService(InstrumentationModule.class)
|
||||
public final class PlayInstrumentationModule extends InstrumentationModule {
|
||||
|
||||
public PlayInstrumentationModule() {
|
||||
super("play");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {packageName + ".PlayTracer", packageName + ".RequestCompleteCallback"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TypeInstrumentation> typeInstrumentations() {
|
||||
return singletonList(new ActionInstrumentation());
|
||||
}
|
||||
|
||||
private static final class ActionInstrumentation implements TypeInstrumentation {
|
||||
@Override
|
||||
public ElementMatcher<ClassLoader> classLoaderMatcher() {
|
||||
// Optimization for expensive typeMatcher.
|
||||
return hasClassesNamed("play.api.mvc.Action");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElementMatcher<TypeDescription> typeMatcher() {
|
||||
return implementsInterface(named("play.api.mvc.Action"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
|
||||
return singletonMap(
|
||||
named("apply")
|
||||
.and(takesArgument(0, named("play.api.mvc.Request")))
|
||||
.and(returns(named("scala.concurrent.Future"))),
|
||||
PlayAdvice.class.getName());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue