Skip to content

Commit

Permalink
End netty client span before callbacks (#7737)
Browse files Browse the repository at this point in the history
  • Loading branch information
trask authored Feb 6, 2023
1 parent e7820f8 commit b9918ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
requestAttr.remove();
}

if (msg instanceof FullHttpResponse) {
instrumenter().end(context, request, (HttpResponse) msg, null);
} else if (msg instanceof LastHttpContent) {
HttpResponse response = ctx.channel().attr(AttributeKeys.CLIENT_RESPONSE).getAndRemove();
instrumenter().end(context, request, response, null);
}

// We want the callback in the scope of the parent, not the client span
if (parentContext != null) {
try (Scope ignored = parentContext.makeCurrent()) {
Expand All @@ -58,12 +65,5 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
} else {
super.channelRead(ctx, msg);
}

if (msg instanceof FullHttpResponse) {
instrumenter().end(context, request, (HttpResponse) msg, null);
} else if (msg instanceof LastHttpContent) {
HttpResponse response = ctx.channel().attr(AttributeKeys.CLIENT_RESPONSE).getAndRemove();
instrumenter().end(context, request, response, null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
requestAttr.set(null);
}

if (msg instanceof FullHttpResponse) {
instrumenter.end(context, request, (HttpResponse) msg, null);
} else if (msg instanceof LastHttpContent) {
instrumenter.end(context, request, ctx.channel().attr(HTTP_RESPONSE).getAndSet(null), null);
}

// We want the callback in the scope of the parent, not the client span
if (parentContext != null) {
try (Scope ignored = parentContext.makeCurrent()) {
Expand All @@ -74,11 +80,5 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
} else {
super.channelRead(ctx, msg);
}

if (msg instanceof FullHttpResponse) {
instrumenter.end(context, request, (HttpResponse) msg, null);
} else if (msg instanceof LastHttpContent) {
instrumenter.end(context, request, ctx.channel().attr(HTTP_RESPONSE).getAndSet(null), null);
}
}
}

0 comments on commit b9918ab

Please sign in to comment.