Less ambiguous name, also doesn't collide with netty class

This commit is contained in:
Brian Devins-Suresh 2020-03-20 08:00:34 -04:00
parent eb99b410c5
commit 9297ff39f4
10 changed files with 63 additions and 57 deletions

View File

@ -54,8 +54,8 @@ public class ChannelFutureListenerInstrumentation extends Instrumenter.Default {
@Override @Override
public String[] helperClassNames() { public String[] helperClassNames() {
return new String[] { return new String[] {
packageName + ".ChannelState", packageName + ".ChannelTraceContext",
packageName + ".ChannelState$Factory", packageName + ".ChannelTraceContext$Factory",
packageName + ".server.NettyHttpServerDecorator", packageName + ".server.NettyHttpServerDecorator",
packageName + ".server.NettyRequestExtractAdapter" packageName + ".server.NettyRequestExtractAdapter"
}; };
@ -73,7 +73,7 @@ public class ChannelFutureListenerInstrumentation extends Instrumenter.Default {
@Override @Override
public Map<String, String> contextStore() { public Map<String, String> contextStore() {
return Collections.singletonMap( return Collections.singletonMap(
"org.jboss.netty.channel.Channel", ChannelState.class.getName()); "org.jboss.netty.channel.Channel", ChannelTraceContext.class.getName());
} }
public static class OperationCompleteAdvice { public static class OperationCompleteAdvice {
@ -89,12 +89,12 @@ public class ChannelFutureListenerInstrumentation extends Instrumenter.Default {
return null; return null;
} }
final ContextStore<Channel, ChannelState> contextStore = final ContextStore<Channel, ChannelTraceContext> contextStore =
InstrumentationContext.get(Channel.class, ChannelState.class); InstrumentationContext.get(Channel.class, ChannelTraceContext.class);
final TraceScope.Continuation continuation = final TraceScope.Continuation continuation =
contextStore contextStore
.putIfAbsent(future.getChannel(), ChannelState.Factory.INSTANCE) .putIfAbsent(future.getChannel(), ChannelTraceContext.Factory.INSTANCE)
.getConnectionContinuationAndRemove(); .getConnectionContinuationAndRemove();
if (continuation == null) { if (continuation == null) {
return null; return null;

View File

@ -6,13 +6,13 @@ import datadog.trace.context.TraceScope;
import lombok.Data; import lombok.Data;
@Data @Data
public class ChannelState { public class ChannelTraceContext {
public static class Factory implements ContextStore.Factory<ChannelState> { public static class Factory implements ContextStore.Factory<ChannelTraceContext> {
public static final Factory INSTANCE = new Factory(); public static final Factory INSTANCE = new Factory();
@Override @Override
public ChannelState create() { public ChannelTraceContext create() {
return new ChannelState(); return new ChannelTraceContext();
} }
} }

View File

@ -46,7 +46,9 @@ public class NettyChannelInstrumentation extends Instrumenter.Default {
@Override @Override
public String[] helperClassNames() { public String[] helperClassNames() {
return new String[] {packageName + ".ChannelState", packageName + ".ChannelState$Factory"}; return new String[] {
packageName + ".ChannelTraceContext", packageName + ".ChannelTraceContext$Factory"
};
} }
@Override @Override
@ -63,7 +65,7 @@ public class NettyChannelInstrumentation extends Instrumenter.Default {
@Override @Override
public Map<String, String> contextStore() { public Map<String, String> contextStore() {
return Collections.singletonMap( return Collections.singletonMap(
"org.jboss.netty.channel.Channel", ChannelState.class.getName()); "org.jboss.netty.channel.Channel", ChannelTraceContext.class.getName());
} }
public static class ChannelConnectAdvice { public static class ChannelConnectAdvice {
@ -73,11 +75,11 @@ public class NettyChannelInstrumentation extends Instrumenter.Default {
if (scope != null) { if (scope != null) {
final TraceScope.Continuation continuation = scope.capture(); final TraceScope.Continuation continuation = scope.capture();
if (continuation != null) { if (continuation != null) {
final ContextStore<Channel, ChannelState> contextStore = final ContextStore<Channel, ChannelTraceContext> contextStore =
InstrumentationContext.get(Channel.class, ChannelState.class); InstrumentationContext.get(Channel.class, ChannelTraceContext.class);
if (!contextStore if (!contextStore
.putIfAbsent(channel, ChannelState.Factory.INSTANCE) .putIfAbsent(channel, ChannelTraceContext.Factory.INSTANCE)
.compareAndSet(null, continuation)) { .compareAndSet(null, continuation)) {
continuation.close(); continuation.close();
} }

View File

@ -63,8 +63,8 @@ public class NettyChannelPipelineInstrumentation extends Instrumenter.Default {
@Override @Override
public String[] helperClassNames() { public String[] helperClassNames() {
return new String[] { return new String[] {
packageName + ".ChannelState", packageName + ".ChannelTraceContext",
packageName + ".ChannelState$Factory", packageName + ".ChannelTraceContext$Factory",
NettyChannelPipelineInstrumentation.class.getName() + "$ChannelPipelineAdviceUtil", NettyChannelPipelineInstrumentation.class.getName() + "$ChannelPipelineAdviceUtil",
// Util // Util
packageName + ".util.CombinedSimpleChannelHandler", packageName + ".util.CombinedSimpleChannelHandler",
@ -102,7 +102,7 @@ public class NettyChannelPipelineInstrumentation extends Instrumenter.Default {
@Override @Override
public Map<String, String> contextStore() { public Map<String, String> contextStore() {
return Collections.singletonMap( 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 class ChannelPipelineAdviceUtil {
public static void wrapHandler( public static void wrapHandler(
final ContextStore<Channel, ChannelState> contextStore, final ContextStore<Channel, ChannelTraceContext> contextStore,
final ChannelPipeline pipeline, final ChannelPipeline pipeline,
final ChannelHandler handler) { final ChannelHandler handler) {
try { try {
@ -173,8 +173,8 @@ public class NettyChannelPipelineInstrumentation extends Instrumenter.Default {
return; return;
} }
final ContextStore<Channel, ChannelState> contextStore = final ContextStore<Channel, ChannelTraceContext> contextStore =
InstrumentationContext.get(Channel.class, ChannelState.class); InstrumentationContext.get(Channel.class, ChannelTraceContext.class);
ChannelPipelineAdviceUtil.wrapHandler(contextStore, pipeline, handler); ChannelPipelineAdviceUtil.wrapHandler(contextStore, pipeline, handler);
} }
@ -203,8 +203,8 @@ public class NettyChannelPipelineInstrumentation extends Instrumenter.Default {
return; return;
} }
final ContextStore<Channel, ChannelState> contextStore = final ContextStore<Channel, ChannelTraceContext> contextStore =
InstrumentationContext.get(Channel.class, ChannelState.class); InstrumentationContext.get(Channel.class, ChannelTraceContext.class);
ChannelPipelineAdviceUtil.wrapHandler(contextStore, pipeline, handler); ChannelPipelineAdviceUtil.wrapHandler(contextStore, pipeline, handler);
} }

View File

@ -11,7 +11,7 @@ import datadog.trace.bootstrap.ContextStore;
import datadog.trace.bootstrap.instrumentation.api.AgentScope; import datadog.trace.bootstrap.instrumentation.api.AgentScope;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan; import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.context.TraceScope; import datadog.trace.context.TraceScope;
import datadog.trace.instrumentation.netty39.ChannelState; import datadog.trace.instrumentation.netty39.ChannelTraceContext;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.Channel;
@ -23,9 +23,10 @@ import org.jboss.netty.handler.codec.http.HttpRequest;
@Slf4j @Slf4j
public class HttpClientRequestTracingHandler extends SimpleChannelDownstreamHandler { 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; this.contextStore = contextStore;
} }
@ -37,19 +38,19 @@ public class HttpClientRequestTracingHandler extends SimpleChannelDownstreamHand
return; return;
} }
final ChannelState channelState = final ChannelTraceContext channelTraceContext =
contextStore.putIfAbsent(ctx.getChannel(), ChannelState.Factory.INSTANCE); contextStore.putIfAbsent(ctx.getChannel(), ChannelTraceContext.Factory.INSTANCE);
TraceScope parentScope = null; TraceScope parentScope = null;
final TraceScope.Continuation continuation = channelState.getConnectionContinuation(); final TraceScope.Continuation continuation = channelTraceContext.getConnectionContinuation();
if (continuation != null) { if (continuation != null) {
parentScope = continuation.activate(); parentScope = continuation.activate();
channelState.setConnectionContinuation(null); channelTraceContext.setConnectionContinuation(null);
} }
final HttpRequest request = (HttpRequest) msg.getMessage(); final HttpRequest request = (HttpRequest) msg.getMessage();
channelState.setClientParentSpan(activeSpan()); channelTraceContext.setClientParentSpan(activeSpan());
final AgentSpan span = startSpan("netty.client.request"); final AgentSpan span = startSpan("netty.client.request");
try (final AgentScope scope = activateSpan(span, false)) { try (final AgentScope scope = activateSpan(span, false)) {
@ -62,7 +63,7 @@ public class HttpClientRequestTracingHandler extends SimpleChannelDownstreamHand
propagate().inject(span, request.headers(), SETTER); propagate().inject(span, request.headers(), SETTER);
} }
channelState.setClientSpan(span); channelTraceContext.setClientSpan(span);
try { try {
ctx.sendDownstream(msg); ctx.sendDownstream(msg);

View File

@ -7,7 +7,7 @@ import static datadog.trace.instrumentation.netty39.client.NettyHttpClientDecora
import datadog.trace.bootstrap.ContextStore; import datadog.trace.bootstrap.ContextStore;
import datadog.trace.bootstrap.instrumentation.api.AgentScope; import datadog.trace.bootstrap.instrumentation.api.AgentScope;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan; 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.Channel;
import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.MessageEvent;
@ -16,24 +16,25 @@ import org.jboss.netty.handler.codec.http.HttpResponse;
public class HttpClientResponseTracingHandler extends SimpleChannelUpstreamHandler { 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; this.contextStore = contextStore;
} }
@Override @Override
public void messageReceived(final ChannelHandlerContext ctx, final MessageEvent msg) public void messageReceived(final ChannelHandlerContext ctx, final MessageEvent msg)
throws Exception { throws Exception {
final ChannelState channelState = final ChannelTraceContext channelTraceContext =
contextStore.putIfAbsent(ctx.getChannel(), ChannelState.Factory.INSTANCE); contextStore.putIfAbsent(ctx.getChannel(), ChannelTraceContext.Factory.INSTANCE);
AgentSpan parent = channelState.getClientParentSpan(); AgentSpan parent = channelTraceContext.getClientParentSpan();
if (parent == null) { if (parent == null) {
parent = noopSpan(); 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; final boolean finishSpan = msg.getMessage() instanceof HttpResponse;

View File

@ -1,7 +1,7 @@
package datadog.trace.instrumentation.netty39.client; package datadog.trace.instrumentation.netty39.client;
import datadog.trace.bootstrap.ContextStore; 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 datadog.trace.instrumentation.netty39.util.CombinedSimpleChannelHandler;
import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.Channel;
@ -9,7 +9,7 @@ public class HttpClientTracingHandler
extends CombinedSimpleChannelHandler< extends CombinedSimpleChannelHandler<
HttpClientResponseTracingHandler, HttpClientRequestTracingHandler> { HttpClientResponseTracingHandler, HttpClientRequestTracingHandler> {
public HttpClientTracingHandler(final ContextStore<Channel, ChannelState> contextStore) { public HttpClientTracingHandler(final ContextStore<Channel, ChannelTraceContext> contextStore) {
super( super(
new HttpClientResponseTracingHandler(contextStore), new HttpClientResponseTracingHandler(contextStore),
new HttpClientRequestTracingHandler(contextStore)); new HttpClientRequestTracingHandler(contextStore));

View File

@ -10,7 +10,7 @@ import datadog.trace.bootstrap.ContextStore;
import datadog.trace.bootstrap.instrumentation.api.AgentScope; import datadog.trace.bootstrap.instrumentation.api.AgentScope;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan; import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan.Context; 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.Channel;
import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.MessageEvent;
@ -19,20 +19,21 @@ import org.jboss.netty.handler.codec.http.HttpRequest;
public class HttpServerRequestTracingHandler extends SimpleChannelUpstreamHandler { 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; this.contextStore = contextStore;
} }
@Override @Override
public void messageReceived(final ChannelHandlerContext ctx, final MessageEvent msg) public void messageReceived(final ChannelHandlerContext ctx, final MessageEvent msg)
throws Exception { throws Exception {
final ChannelState channelState = final ChannelTraceContext channelTraceContext =
contextStore.putIfAbsent(ctx.getChannel(), ChannelState.Factory.INSTANCE); contextStore.putIfAbsent(ctx.getChannel(), ChannelTraceContext.Factory.INSTANCE);
if (!(msg.getMessage() instanceof HttpRequest)) { if (!(msg.getMessage() instanceof HttpRequest)) {
final AgentSpan span = channelState.getServerSpan(); final AgentSpan span = channelTraceContext.getServerSpan();
if (span == null) { if (span == null) {
ctx.sendUpstream(msg); // superclass does not throw ctx.sendUpstream(msg); // superclass does not throw
} else { } else {
@ -56,7 +57,7 @@ public class HttpServerRequestTracingHandler extends SimpleChannelUpstreamHandle
scope.setAsyncPropagation(true); scope.setAsyncPropagation(true);
channelState.setServerSpan(span); channelTraceContext.setServerSpan(span);
try { try {
ctx.sendUpstream(msg); ctx.sendUpstream(msg);

View File

@ -5,7 +5,7 @@ import static datadog.trace.instrumentation.netty39.server.NettyHttpServerDecora
import datadog.trace.bootstrap.ContextStore; import datadog.trace.bootstrap.ContextStore;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan; import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.api.Tags; 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.Channel;
import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.MessageEvent;
@ -14,19 +14,20 @@ import org.jboss.netty.handler.codec.http.HttpResponse;
public class HttpServerResponseTracingHandler extends SimpleChannelDownstreamHandler { 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; this.contextStore = contextStore;
} }
@Override @Override
public void writeRequested(final ChannelHandlerContext ctx, final MessageEvent msg) public void writeRequested(final ChannelHandlerContext ctx, final MessageEvent msg)
throws Exception { throws Exception {
final ChannelState channelState = final ChannelTraceContext channelTraceContext =
contextStore.putIfAbsent(ctx.getChannel(), ChannelState.Factory.INSTANCE); contextStore.putIfAbsent(ctx.getChannel(), ChannelTraceContext.Factory.INSTANCE);
final AgentSpan span = channelState.getServerSpan(); final AgentSpan span = channelTraceContext.getServerSpan();
if (span == null || !(msg.getMessage() instanceof HttpResponse)) { if (span == null || !(msg.getMessage() instanceof HttpResponse)) {
ctx.sendDownstream(msg); ctx.sendDownstream(msg);
return; return;

View File

@ -1,7 +1,7 @@
package datadog.trace.instrumentation.netty39.server; package datadog.trace.instrumentation.netty39.server;
import datadog.trace.bootstrap.ContextStore; 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 datadog.trace.instrumentation.netty39.util.CombinedSimpleChannelHandler;
import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.Channel;
@ -9,7 +9,7 @@ public class HttpServerTracingHandler
extends CombinedSimpleChannelHandler< extends CombinedSimpleChannelHandler<
HttpServerRequestTracingHandler, HttpServerResponseTracingHandler> { HttpServerRequestTracingHandler, HttpServerResponseTracingHandler> {
public HttpServerTracingHandler(final ContextStore<Channel, ChannelState> contextStore) { public HttpServerTracingHandler(final ContextStore<Channel, ChannelTraceContext> contextStore) {
super( super(
new HttpServerRequestTracingHandler(contextStore), new HttpServerRequestTracingHandler(contextStore),
new HttpServerResponseTracingHandler(contextStore)); new HttpServerResponseTracingHandler(contextStore));