Skip to content

Commit

Permalink
Propagate client span context in doOnRequest (open-telemetry#6621)
Browse files Browse the repository at this point in the history
Copying the changes from Mike W. This fixes the problem where the jaxrs
and http client request spans are siblings instead of parent/child.

@mateuszrzeszutek please review

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
  • Loading branch information
2 people authored and LironKS committed Oct 31, 2022
1 parent 8922cd4 commit a6f9c7c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ public static void onEnter(
BiConsumer<? super HttpClientRequest, ? super Connection> callback) {

if (DecoratorFunctions.shouldDecorate(callback.getClass())) {
callback = new DecoratorFunctions.OnMessageDecorator<>(callback, PropagatedContext.PARENT);
// perform the callback with the client span active (instead of the parent) since this
// callback occurs after the connection is made
callback = new DecoratorFunctions.OnMessageDecorator<>(callback, PropagatedContext.CLIENT);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void shouldExposeContextToHttpClientCallbacks() throws InterruptedException {
span -> span.hasName("HTTP GET").hasKind(CLIENT).hasParent(parentSpan),
span -> span.hasName("test-http-server").hasKind(SERVER).hasParent(nettyClientSpan));

assertSameSpan(parentSpan, onRequestSpan);
assertSameSpan(nettyClientSpan, onRequestSpan);
assertSameSpan(nettyClientSpan, afterRequestSpan);
assertSameSpan(nettyClientSpan, onResponseSpan);
assertSameSpan(parentSpan, afterResponseSpan);
Expand Down

0 comments on commit a6f9c7c

Please sign in to comment.