Fix route handling when local root span wasn't created by instrumentation api (#13588)
This commit is contained in:
parent
f048a91770
commit
389b153990
|
@ -190,7 +190,8 @@ public class Instrumenter<REQUEST, RESPONSE> {
|
|||
context = contextCustomizer.onStart(context, request, attributes);
|
||||
}
|
||||
|
||||
boolean localRoot = LocalRootSpan.isLocalRoot(context);
|
||||
boolean localRoot = LocalRootSpan.isLocalRoot(parentContext);
|
||||
boolean hasLocalRoot = LocalRootSpan.fromContextOrNull(context) != null;
|
||||
|
||||
spanBuilder.setAllAttributes(attributes);
|
||||
Span span = spanBuilder.setParent(context).startSpan();
|
||||
|
@ -216,9 +217,9 @@ public class Instrumenter<REQUEST, RESPONSE> {
|
|||
|
||||
if (localRoot) {
|
||||
context = LocalRootSpan.store(context, span);
|
||||
if (spanKind == SpanKind.SERVER) {
|
||||
HttpRouteState.updateSpan(context, span);
|
||||
}
|
||||
}
|
||||
if (!hasLocalRoot && spanKind == SpanKind.SERVER) {
|
||||
HttpRouteState.updateSpan(context, span);
|
||||
}
|
||||
|
||||
return spanSuppressor.storeInContext(context, spanKind, span);
|
||||
|
|
|
@ -27,7 +27,7 @@ public final class HttpRouteState implements ImplicitContextKeyed {
|
|||
|
||||
public static void updateSpan(Context context, Span span) {
|
||||
HttpRouteState state = fromContextOrNull(context);
|
||||
if (state != null) {
|
||||
if (state != null && state.span == null) {
|
||||
state.span = span;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ class HttpServerRouteTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void noLocalRootSpan() {
|
||||
void nonInstrumenerParentLocalRootSpan() {
|
||||
Span parentSpan =
|
||||
testing.getOpenTelemetry().getTracer("test").spanBuilder("parent").startSpan();
|
||||
parentSpan.end();
|
||||
|
@ -56,10 +56,11 @@ class HttpServerRouteTest {
|
|||
|
||||
instrumenter.end(context, "test", null, null);
|
||||
|
||||
assertNull(HttpServerRoute.get(context));
|
||||
assertEquals("/get/:id", HttpServerRoute.get(context));
|
||||
assertThat(testing.getSpans())
|
||||
.satisfiesExactly(
|
||||
span -> assertThat(span).hasName("parent"), span -> assertThat(span).hasName("test"));
|
||||
span -> assertThat(span).hasName("parent"),
|
||||
span -> assertThat(span).hasName("HTTP /get/:id"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue