Skip to content

Commit

Permalink
Propagate channelInactive to next handler
Browse files Browse the repository at this point in the history
  • Loading branch information
amarziali committed Nov 7, 2024
1 parent e91eeda commit 8da33a7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,17 @@ public void channelRead(final ChannelHandlerContext ctx, final Object msg) {

@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
final AgentSpan span = ctx.channel().attr(SPAN_ATTRIBUTE_KEY).getAndRemove();
if (span != null && span.phasedFinish()) {
// at this point we can just publish this span to avoid loosing the rest of the trace
span.publish();
try {
super.channelInactive(ctx);
} finally {
try {
final AgentSpan span = ctx.channel().attr(SPAN_ATTRIBUTE_KEY).getAndRemove();
if (span != null && span.phasedFinish()) {
// at this point we can just publish this span to avoid loosing the rest of the trace
span.publish();
}
} catch (final Throwable ignored) {
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,17 @@ public void channelRead(final ChannelHandlerContext ctx, final Object msg) {

@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
final AgentSpan span = ctx.channel().attr(SPAN_ATTRIBUTE_KEY).getAndRemove();
if (span != null && span.phasedFinish()) {
// at this point we can just publish this span to avoid loosing the rest of the trace
span.publish();
try {
super.channelInactive(ctx);
} finally {
try {
final AgentSpan span = ctx.channel().attr(SPAN_ATTRIBUTE_KEY).getAndRemove();
if (span != null && span.phasedFinish()) {
// at this point we can just publish this span to avoid loosing the rest of the trace
span.publish();
}
} catch (final Throwable ignored) {
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ class SpringWebfluxHttp11Test extends AgentTestRunner {
[ "message":"The subscription was cancelled", "event":"cancelled"])
traceParent = clientSpan(it, span(0), "netty.client.request", "netty-client", "GET", URI.create(url), null)
}
trace(1) {
trace(2) {
span {
resourceName "GET /very-delayed"
operationName "netty.request"
Expand All @@ -695,6 +695,18 @@ class SpringWebfluxHttp11Test extends AgentTestRunner {
defaultTags(true)
}
}
span {
resourceName "TestController.getVeryDelayedMono"
operationName "TestController.getVeryDelayedMono"
spanType DDSpanTypes.HTTP_SERVER
childOfPrevious()
tags {
"$Tags.COMPONENT" "spring-webflux-controller"
"$Tags.SPAN_KIND" Tags.SPAN_KIND_SERVER
"handler.type" TestController.getName()
defaultTags()
}
}
}
}
}
Expand Down

0 comments on commit 8da33a7

Please sign in to comment.