Less ambiguous name, also doesn't collide with netty class
This commit is contained in:
parent
eb99b410c5
commit
9297ff39f4
|
@ -54,8 +54,8 @@ public class ChannelFutureListenerInstrumentation extends Instrumenter.Default {
|
|||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
packageName + ".ChannelState",
|
||||
packageName + ".ChannelState$Factory",
|
||||
packageName + ".ChannelTraceContext",
|
||||
packageName + ".ChannelTraceContext$Factory",
|
||||
packageName + ".server.NettyHttpServerDecorator",
|
||||
packageName + ".server.NettyRequestExtractAdapter"
|
||||
};
|
||||
|
@ -73,7 +73,7 @@ public class ChannelFutureListenerInstrumentation extends Instrumenter.Default {
|
|||
@Override
|
||||
public Map<String, String> contextStore() {
|
||||
return Collections.singletonMap(
|
||||
"org.jboss.netty.channel.Channel", ChannelState.class.getName());
|
||||
"org.jboss.netty.channel.Channel", ChannelTraceContext.class.getName());
|
||||
}
|
||||
|
||||
public static class OperationCompleteAdvice {
|
||||
|
@ -89,12 +89,12 @@ public class ChannelFutureListenerInstrumentation extends Instrumenter.Default {
|
|||
return null;
|
||||
}
|
||||
|
||||
final ContextStore<Channel, ChannelState> contextStore =
|
||||
InstrumentationContext.get(Channel.class, ChannelState.class);
|
||||
final ContextStore<Channel, ChannelTraceContext> contextStore =
|
||||
InstrumentationContext.get(Channel.class, ChannelTraceContext.class);
|
||||
|
||||
final TraceScope.Continuation continuation =
|
||||
contextStore
|
||||
.putIfAbsent(future.getChannel(), ChannelState.Factory.INSTANCE)
|
||||
.putIfAbsent(future.getChannel(), ChannelTraceContext.Factory.INSTANCE)
|
||||
.getConnectionContinuationAndRemove();
|
||||
if (continuation == null) {
|
||||
return null;
|
||||
|
|
|
@ -6,13 +6,13 @@ import datadog.trace.context.TraceScope;
|
|||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ChannelState {
|
||||
public static class Factory implements ContextStore.Factory<ChannelState> {
|
||||
public class ChannelTraceContext {
|
||||
public static class Factory implements ContextStore.Factory<ChannelTraceContext> {
|
||||
public static final Factory INSTANCE = new Factory();
|
||||
|
||||
@Override
|
||||
public ChannelState create() {
|
||||
return new ChannelState();
|
||||
public ChannelTraceContext create() {
|
||||
return new ChannelTraceContext();
|
||||
}
|
||||
}
|
||||
|
|
@ -46,7 +46,9 @@ public class NettyChannelInstrumentation extends Instrumenter.Default {
|
|||
|
||||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {packageName + ".ChannelState", packageName + ".ChannelState$Factory"};
|
||||
return new String[] {
|
||||
packageName + ".ChannelTraceContext", packageName + ".ChannelTraceContext$Factory"
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -63,7 +65,7 @@ public class NettyChannelInstrumentation extends Instrumenter.Default {
|
|||
@Override
|
||||
public Map<String, String> contextStore() {
|
||||
return Collections.singletonMap(
|
||||
"org.jboss.netty.channel.Channel", ChannelState.class.getName());
|
||||
"org.jboss.netty.channel.Channel", ChannelTraceContext.class.getName());
|
||||
}
|
||||
|
||||
public static class ChannelConnectAdvice {
|
||||
|
@ -73,11 +75,11 @@ public class NettyChannelInstrumentation extends Instrumenter.Default {
|
|||
if (scope != null) {
|
||||
final TraceScope.Continuation continuation = scope.capture();
|
||||
if (continuation != null) {
|
||||
final ContextStore<Channel, ChannelState> contextStore =
|
||||
InstrumentationContext.get(Channel.class, ChannelState.class);
|
||||
final ContextStore<Channel, ChannelTraceContext> contextStore =
|
||||
InstrumentationContext.get(Channel.class, ChannelTraceContext.class);
|
||||
|
||||
if (!contextStore
|
||||
.putIfAbsent(channel, ChannelState.Factory.INSTANCE)
|
||||
.putIfAbsent(channel, ChannelTraceContext.Factory.INSTANCE)
|
||||
.compareAndSet(null, continuation)) {
|
||||
continuation.close();
|
||||
}
|
||||
|
|
|
@ -63,8 +63,8 @@ public class NettyChannelPipelineInstrumentation extends Instrumenter.Default {
|
|||
@Override
|
||||
public String[] helperClassNames() {
|
||||
return new String[] {
|
||||
packageName + ".ChannelState",
|
||||
packageName + ".ChannelState$Factory",
|
||||
packageName + ".ChannelTraceContext",
|
||||
packageName + ".ChannelTraceContext$Factory",
|
||||
NettyChannelPipelineInstrumentation.class.getName() + "$ChannelPipelineAdviceUtil",
|
||||
// Util
|
||||
packageName + ".util.CombinedSimpleChannelHandler",
|
||||
|
@ -102,7 +102,7 @@ public class NettyChannelPipelineInstrumentation extends Instrumenter.Default {
|
|||
@Override
|
||||
public Map<String, String> contextStore() {
|
||||
return Collections.singletonMap(
|
||||
"org.jboss.netty.channel.Channel", ChannelState.class.getName());
|
||||
"org.jboss.netty.channel.Channel", ChannelTraceContext.class.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,7 +112,7 @@ public class NettyChannelPipelineInstrumentation extends Instrumenter.Default {
|
|||
*/
|
||||
public static class ChannelPipelineAdviceUtil {
|
||||
public static void wrapHandler(
|
||||
final ContextStore<Channel, ChannelState> contextStore,
|
||||
final ContextStore<Channel, ChannelTraceContext> contextStore,
|
||||
final ChannelPipeline pipeline,
|
||||
final ChannelHandler handler) {
|
||||
try {
|
||||
|
@ -173,8 +173,8 @@ public class NettyChannelPipelineInstrumentation extends Instrumenter.Default {
|
|||
return;
|
||||
}
|
||||
|
||||
final ContextStore<Channel, ChannelState> contextStore =
|
||||
InstrumentationContext.get(Channel.class, ChannelState.class);
|
||||
final ContextStore<Channel, ChannelTraceContext> contextStore =
|
||||
InstrumentationContext.get(Channel.class, ChannelTraceContext.class);
|
||||
|
||||
ChannelPipelineAdviceUtil.wrapHandler(contextStore, pipeline, handler);
|
||||
}
|
||||
|
@ -203,8 +203,8 @@ public class NettyChannelPipelineInstrumentation extends Instrumenter.Default {
|
|||
return;
|
||||
}
|
||||
|
||||
final ContextStore<Channel, ChannelState> contextStore =
|
||||
InstrumentationContext.get(Channel.class, ChannelState.class);
|
||||
final ContextStore<Channel, ChannelTraceContext> contextStore =
|
||||
InstrumentationContext.get(Channel.class, ChannelTraceContext.class);
|
||||
|
||||
ChannelPipelineAdviceUtil.wrapHandler(contextStore, pipeline, handler);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import datadog.trace.bootstrap.ContextStore;
|
|||
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
|
||||
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
|
||||
import datadog.trace.context.TraceScope;
|
||||
import datadog.trace.instrumentation.netty39.ChannelState;
|
||||
import datadog.trace.instrumentation.netty39.ChannelTraceContext;
|
||||
import java.net.InetSocketAddress;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jboss.netty.channel.Channel;
|
||||
|
@ -23,9 +23,10 @@ import org.jboss.netty.handler.codec.http.HttpRequest;
|
|||
@Slf4j
|
||||
public class HttpClientRequestTracingHandler extends SimpleChannelDownstreamHandler {
|
||||
|
||||
private final ContextStore<Channel, ChannelState> contextStore;
|
||||
private final ContextStore<Channel, ChannelTraceContext> contextStore;
|
||||
|
||||
public HttpClientRequestTracingHandler(final ContextStore<Channel, ChannelState> contextStore) {
|
||||
public HttpClientRequestTracingHandler(
|
||||
final ContextStore<Channel, ChannelTraceContext> contextStore) {
|
||||
this.contextStore = contextStore;
|
||||
}
|
||||
|
||||
|
@ -37,19 +38,19 @@ public class HttpClientRequestTracingHandler extends SimpleChannelDownstreamHand
|
|||
return;
|
||||
}
|
||||
|
||||
final ChannelState channelState =
|
||||
contextStore.putIfAbsent(ctx.getChannel(), ChannelState.Factory.INSTANCE);
|
||||
final ChannelTraceContext channelTraceContext =
|
||||
contextStore.putIfAbsent(ctx.getChannel(), ChannelTraceContext.Factory.INSTANCE);
|
||||
|
||||
TraceScope parentScope = null;
|
||||
final TraceScope.Continuation continuation = channelState.getConnectionContinuation();
|
||||
final TraceScope.Continuation continuation = channelTraceContext.getConnectionContinuation();
|
||||
if (continuation != null) {
|
||||
parentScope = continuation.activate();
|
||||
channelState.setConnectionContinuation(null);
|
||||
channelTraceContext.setConnectionContinuation(null);
|
||||
}
|
||||
|
||||
final HttpRequest request = (HttpRequest) msg.getMessage();
|
||||
|
||||
channelState.setClientParentSpan(activeSpan());
|
||||
channelTraceContext.setClientParentSpan(activeSpan());
|
||||
|
||||
final AgentSpan span = startSpan("netty.client.request");
|
||||
try (final AgentScope scope = activateSpan(span, false)) {
|
||||
|
@ -62,7 +63,7 @@ public class HttpClientRequestTracingHandler extends SimpleChannelDownstreamHand
|
|||
propagate().inject(span, request.headers(), SETTER);
|
||||
}
|
||||
|
||||
channelState.setClientSpan(span);
|
||||
channelTraceContext.setClientSpan(span);
|
||||
|
||||
try {
|
||||
ctx.sendDownstream(msg);
|
||||
|
|
|
@ -7,7 +7,7 @@ import static datadog.trace.instrumentation.netty39.client.NettyHttpClientDecora
|
|||
import datadog.trace.bootstrap.ContextStore;
|
||||
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
|
||||
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
|
||||
import datadog.trace.instrumentation.netty39.ChannelState;
|
||||
import datadog.trace.instrumentation.netty39.ChannelTraceContext;
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
import org.jboss.netty.channel.MessageEvent;
|
||||
|
@ -16,24 +16,25 @@ import org.jboss.netty.handler.codec.http.HttpResponse;
|
|||
|
||||
public class HttpClientResponseTracingHandler extends SimpleChannelUpstreamHandler {
|
||||
|
||||
private final ContextStore<Channel, ChannelState> contextStore;
|
||||
private final ContextStore<Channel, ChannelTraceContext> contextStore;
|
||||
|
||||
public HttpClientResponseTracingHandler(final ContextStore<Channel, ChannelState> contextStore) {
|
||||
public HttpClientResponseTracingHandler(
|
||||
final ContextStore<Channel, ChannelTraceContext> contextStore) {
|
||||
this.contextStore = contextStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageReceived(final ChannelHandlerContext ctx, final MessageEvent msg)
|
||||
throws Exception {
|
||||
final ChannelState channelState =
|
||||
contextStore.putIfAbsent(ctx.getChannel(), ChannelState.Factory.INSTANCE);
|
||||
final ChannelTraceContext channelTraceContext =
|
||||
contextStore.putIfAbsent(ctx.getChannel(), ChannelTraceContext.Factory.INSTANCE);
|
||||
|
||||
AgentSpan parent = channelState.getClientParentSpan();
|
||||
AgentSpan parent = channelTraceContext.getClientParentSpan();
|
||||
if (parent == null) {
|
||||
parent = noopSpan();
|
||||
channelState.setClientParentSpan(noopSpan());
|
||||
channelTraceContext.setClientParentSpan(noopSpan());
|
||||
}
|
||||
final AgentSpan span = channelState.getClientSpan();
|
||||
final AgentSpan span = channelTraceContext.getClientSpan();
|
||||
|
||||
final boolean finishSpan = msg.getMessage() instanceof HttpResponse;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package datadog.trace.instrumentation.netty39.client;
|
||||
|
||||
import datadog.trace.bootstrap.ContextStore;
|
||||
import datadog.trace.instrumentation.netty39.ChannelState;
|
||||
import datadog.trace.instrumentation.netty39.ChannelTraceContext;
|
||||
import datadog.trace.instrumentation.netty39.util.CombinedSimpleChannelHandler;
|
||||
import org.jboss.netty.channel.Channel;
|
||||
|
||||
|
@ -9,7 +9,7 @@ public class HttpClientTracingHandler
|
|||
extends CombinedSimpleChannelHandler<
|
||||
HttpClientResponseTracingHandler, HttpClientRequestTracingHandler> {
|
||||
|
||||
public HttpClientTracingHandler(final ContextStore<Channel, ChannelState> contextStore) {
|
||||
public HttpClientTracingHandler(final ContextStore<Channel, ChannelTraceContext> contextStore) {
|
||||
super(
|
||||
new HttpClientResponseTracingHandler(contextStore),
|
||||
new HttpClientRequestTracingHandler(contextStore));
|
||||
|
|
|
@ -10,7 +10,7 @@ import datadog.trace.bootstrap.ContextStore;
|
|||
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
|
||||
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
|
||||
import datadog.trace.bootstrap.instrumentation.api.AgentSpan.Context;
|
||||
import datadog.trace.instrumentation.netty39.ChannelState;
|
||||
import datadog.trace.instrumentation.netty39.ChannelTraceContext;
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
import org.jboss.netty.channel.MessageEvent;
|
||||
|
@ -19,20 +19,21 @@ import org.jboss.netty.handler.codec.http.HttpRequest;
|
|||
|
||||
public class HttpServerRequestTracingHandler extends SimpleChannelUpstreamHandler {
|
||||
|
||||
private final ContextStore<Channel, ChannelState> contextStore;
|
||||
private final ContextStore<Channel, ChannelTraceContext> contextStore;
|
||||
|
||||
public HttpServerRequestTracingHandler(final ContextStore<Channel, ChannelState> contextStore) {
|
||||
public HttpServerRequestTracingHandler(
|
||||
final ContextStore<Channel, ChannelTraceContext> contextStore) {
|
||||
this.contextStore = contextStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageReceived(final ChannelHandlerContext ctx, final MessageEvent msg)
|
||||
throws Exception {
|
||||
final ChannelState channelState =
|
||||
contextStore.putIfAbsent(ctx.getChannel(), ChannelState.Factory.INSTANCE);
|
||||
final ChannelTraceContext channelTraceContext =
|
||||
contextStore.putIfAbsent(ctx.getChannel(), ChannelTraceContext.Factory.INSTANCE);
|
||||
|
||||
if (!(msg.getMessage() instanceof HttpRequest)) {
|
||||
final AgentSpan span = channelState.getServerSpan();
|
||||
final AgentSpan span = channelTraceContext.getServerSpan();
|
||||
if (span == null) {
|
||||
ctx.sendUpstream(msg); // superclass does not throw
|
||||
} else {
|
||||
|
@ -56,7 +57,7 @@ public class HttpServerRequestTracingHandler extends SimpleChannelUpstreamHandle
|
|||
|
||||
scope.setAsyncPropagation(true);
|
||||
|
||||
channelState.setServerSpan(span);
|
||||
channelTraceContext.setServerSpan(span);
|
||||
|
||||
try {
|
||||
ctx.sendUpstream(msg);
|
||||
|
|
|
@ -5,7 +5,7 @@ import static datadog.trace.instrumentation.netty39.server.NettyHttpServerDecora
|
|||
import datadog.trace.bootstrap.ContextStore;
|
||||
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
|
||||
import datadog.trace.bootstrap.instrumentation.api.Tags;
|
||||
import datadog.trace.instrumentation.netty39.ChannelState;
|
||||
import datadog.trace.instrumentation.netty39.ChannelTraceContext;
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
import org.jboss.netty.channel.MessageEvent;
|
||||
|
@ -14,19 +14,20 @@ import org.jboss.netty.handler.codec.http.HttpResponse;
|
|||
|
||||
public class HttpServerResponseTracingHandler extends SimpleChannelDownstreamHandler {
|
||||
|
||||
private final ContextStore<Channel, ChannelState> contextStore;
|
||||
private final ContextStore<Channel, ChannelTraceContext> contextStore;
|
||||
|
||||
public HttpServerResponseTracingHandler(final ContextStore<Channel, ChannelState> contextStore) {
|
||||
public HttpServerResponseTracingHandler(
|
||||
final ContextStore<Channel, ChannelTraceContext> contextStore) {
|
||||
this.contextStore = contextStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeRequested(final ChannelHandlerContext ctx, final MessageEvent msg)
|
||||
throws Exception {
|
||||
final ChannelState channelState =
|
||||
contextStore.putIfAbsent(ctx.getChannel(), ChannelState.Factory.INSTANCE);
|
||||
final ChannelTraceContext channelTraceContext =
|
||||
contextStore.putIfAbsent(ctx.getChannel(), ChannelTraceContext.Factory.INSTANCE);
|
||||
|
||||
final AgentSpan span = channelState.getServerSpan();
|
||||
final AgentSpan span = channelTraceContext.getServerSpan();
|
||||
if (span == null || !(msg.getMessage() instanceof HttpResponse)) {
|
||||
ctx.sendDownstream(msg);
|
||||
return;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package datadog.trace.instrumentation.netty39.server;
|
||||
|
||||
import datadog.trace.bootstrap.ContextStore;
|
||||
import datadog.trace.instrumentation.netty39.ChannelState;
|
||||
import datadog.trace.instrumentation.netty39.ChannelTraceContext;
|
||||
import datadog.trace.instrumentation.netty39.util.CombinedSimpleChannelHandler;
|
||||
import org.jboss.netty.channel.Channel;
|
||||
|
||||
|
@ -9,7 +9,7 @@ public class HttpServerTracingHandler
|
|||
extends CombinedSimpleChannelHandler<
|
||||
HttpServerRequestTracingHandler, HttpServerResponseTracingHandler> {
|
||||
|
||||
public HttpServerTracingHandler(final ContextStore<Channel, ChannelState> contextStore) {
|
||||
public HttpServerTracingHandler(final ContextStore<Channel, ChannelTraceContext> contextStore) {
|
||||
super(
|
||||
new HttpServerRequestTracingHandler(contextStore),
|
||||
new HttpServerResponseTracingHandler(contextStore));
|
||||
|
|
Loading…
Reference in New Issue