Add scopes to http server response (DataDog/dd-trace-java#1408)
MODIFY
instrumentation/netty/netty-3.8/src/main/java/io/opentelemetry/auto/instrumentation/netty/v3_8/server/HttpServerResponseTracingHandler.java
instrumentation/netty/netty-3.8/src/main/java/io/opentelemetry/auto/instrumentation/netty/v3_8/server/HttpServerResponseTracingHandler.java
*/
package io.opentelemetry.auto.instrumentation.netty.v3_8.server;
+import static io.opentelemetry.auto.instrumentation.netty.v3_8.server.NettyHttpServerDecorator.DECORATE;
+import static io.opentelemetry.auto.instrumentation.netty.v3_8.server.NettyHttpServerDecorator.TRACER;
+
import io.opentelemetry.auto.bootstrap.ContextStore;
import io.opentelemetry.auto.instrumentation.api.Tags;
import io.opentelemetry.auto.instrumentation.netty.v3_8.ChannelTraceContext;
+import io.opentelemetry.context.Scope;
import io.opentelemetry.trace.Span;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
@@ -45,18 +49,20 @@ public class HttpServerResponseTracingHandler extends SimpleChannelDownstreamHan
return;
}
+ try (final Scope scope = TRACER.withSpan(span)) {
final HttpResponse response = (HttpResponse) msg.getMessage();
try {
ctx.sendDownstream(msg);
} catch (final Throwable throwable) {
- NettyHttpServerDecorator.DECORATE.onError(span, throwable);
+ DECORATE.onError(span, throwable);
span.setAttribute(Tags.HTTP_STATUS, 500);
span.end(); // Finish the span manually since finishSpanOnClose was false
throw throwable;
}
- NettyHttpServerDecorator.DECORATE.onResponse(span, response);
- NettyHttpServerDecorator.DECORATE.beforeFinish(span);
+ DECORATE.onResponse(span, response);
+ DECORATE.beforeFinish(span);
span.end(); // Finish the span manually since finishSpanOnClose was false
}
}
+}

MODIFY
instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/auto/instrumentation/netty/v4_0/server/HttpServerResponseTracingHandler.java
instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/auto/instrumentation/netty/v4_0/server/HttpServerResponseTracingHandler.java
package io.opentelemetry.auto.instrumentation.netty.v4_0.server;
import static io.opentelemetry.auto.instrumentation.netty.v4_0.server.NettyHttpServerDecorator.DECORATE;
+import static io.opentelemetry.auto.instrumentation.netty.v4_0.server.NettyHttpServerDecorator.TRACER;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
@@ -23,6 +24,7 @@ import io.netty.channel.ChannelPromise;
import io.netty.handler.codec.http.HttpResponse;
import io.opentelemetry.auto.instrumentation.api.Tags;
import io.opentelemetry.auto.instrumentation.netty.v4_0.AttributeKeys;
+import io.opentelemetry.context.Scope;
import io.opentelemetry.trace.Span;
public class HttpServerResponseTracingHandler extends ChannelOutboundHandlerAdapter {
@@ -35,6 +37,7 @@ public class HttpServerResponseTracingHandler extends ChannelOutboundHandlerAdap
return;
}
+ try (final Scope scope = TRACER.withSpan(span)) {
final HttpResponse response = (HttpResponse) msg;
try {
@@ -50,3 +53,4 @@ public class HttpServerResponseTracingHandler extends ChannelOutboundHandlerAdap
span.end(); // Finish the span manually since finishSpanOnClose was false
}
}
+}

MODIFY
instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/auto/instrumentation/netty/v4_1/server/HttpServerResponseTracingHandler.java
instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/auto/instrumentation/netty/v4_1/server/HttpServerResponseTracingHandler.java
package io.opentelemetry.auto.instrumentation.netty.v4_1.server;
import static io.opentelemetry.auto.instrumentation.netty.v4_1.server.NettyHttpServerDecorator.DECORATE;
+import static io.opentelemetry.auto.instrumentation.netty.v4_1.server.NettyHttpServerDecorator.TRACER;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
@@ -23,6 +24,7 @@ import io.netty.channel.ChannelPromise;
import io.netty.handler.codec.http.HttpResponse;
import io.opentelemetry.auto.instrumentation.api.Tags;
import io.opentelemetry.auto.instrumentation.netty.v4_1.AttributeKeys;
+import io.opentelemetry.context.Scope;
import io.opentelemetry.trace.Span;
public class HttpServerResponseTracingHandler extends ChannelOutboundHandlerAdapter {
@@ -35,6 +37,7 @@ public class HttpServerResponseTracingHandler extends ChannelOutboundHandlerAdap
return;
}
+ try (final Scope scope = TRACER.withSpan(span)) {
final HttpResponse response = (HttpResponse) msg;
try {
@@ -50,3 +53,4 @@ public class HttpServerResponseTracingHandler extends ChannelOutboundHandlerAdap
span.end(); // Finish the span manually since finishSpanOnClose was false
}
}
+}

Add scopes to http server response (DataDog/dd-trace-java#1408)