Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit netty exception capture to netty spans #3809

Merged
merged 5 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
import io.opentelemetry.instrumentation.netty.v4_1.AttributeKeys;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge;
import io.opentelemetry.javaagent.instrumentation.netty.v4_1.client.NettyHttpClientTracer;
import io.opentelemetry.javaagent.instrumentation.netty.v4_1.server.NettyHttpServerTracer;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
Expand Down Expand Up @@ -46,15 +44,14 @@ public static class InvokeExceptionCaughtAdvice {
public static void onEnter(
@Advice.This ChannelHandlerContext channelContext,
@Advice.Argument(0) Throwable throwable) {
if (throwable != null) {
if (channelContext.channel().hasAttr(AttributeKeys.CLIENT_CONTEXT)) {
Attribute<Context> clientContextAttr =
channelContext.channel().attr(AttributeKeys.CLIENT_CONTEXT);
NettyHttpClientTracer.tracer().endExceptionally(clientContextAttr.get(), throwable);
} else {
NettyHttpServerTracer.tracer()
.onException(Java8BytecodeBridge.currentContext(), throwable);
}
if (channelContext.channel().hasAttr(AttributeKeys.CLIENT_CONTEXT)) {
Attribute<Context> clientContextAttr =
channelContext.channel().attr(AttributeKeys.CLIENT_CONTEXT);
NettyHttpClientTracer.tracer().endExceptionally(clientContextAttr.get(), throwable);
} else if (channelContext.channel().hasAttr(AttributeKeys.SERVER_CONTEXT)) {
trask marked this conversation as resolved.
Show resolved Hide resolved
Attribute<Context> clientContextAttr =
channelContext.channel().attr(AttributeKeys.SERVER_CONTEXT);
NettyHttpClientTracer.tracer().onException(clientContextAttr.get(), throwable);
trask marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ protected int responseStatus(HttpResponse httpResponse) {

@Override
protected void attachServerContext(Context context, Channel channel) {
channel.attr(AttributeKeys.SERVER_SPAN).set(context);
channel.attr(AttributeKeys.SERVER_CONTEXT).set(context);
}

@Override
public Context getServerContext(Channel channel) {
return channel.attr(AttributeKeys.SERVER_SPAN).get();
return channel.attr(AttributeKeys.SERVER_CONTEXT).get();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public final class AttributeKeys {
// this is the context that has the server span
//
// note: this attribute key is also used by ratpack instrumentation
public static final AttributeKey<Context> SERVER_SPAN =
public static final AttributeKey<Context> SERVER_CONTEXT =
AttributeKey.valueOf(AttributeKeys.class, "server-span");

public static final AttributeKey<Context> CLIENT_CONTEXT =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public final class TracingHandler implements Handler {
@Override
public void handle(Context ctx) {
Attribute<io.opentelemetry.context.Context> spanAttribute =
ctx.getDirectChannelAccess().getChannel().attr(AttributeKeys.SERVER_SPAN);
ctx.getDirectChannelAccess().getChannel().attr(AttributeKeys.SERVER_CONTEXT);
io.opentelemetry.context.Context serverSpanContext = spanAttribute.get();

// Must use context from channel, as executor instrumentation is not accurate - Ratpack
Expand Down