Undertow: restore attached context only when it is for different trace (#10336)
This commit is contained in:
parent
4695b57d73
commit
20e3cd6ab8
|
@ -53,7 +53,7 @@ public class HandlerInstrumentation implements TypeInstrumentation {
|
||||||
@Advice.Local("otelScope") Scope scope) {
|
@Advice.Local("otelScope") Scope scope) {
|
||||||
Context attachedContext = helper().getServerContext(exchange);
|
Context attachedContext = helper().getServerContext(exchange);
|
||||||
if (attachedContext != null) {
|
if (attachedContext != null) {
|
||||||
if (!Java8BytecodeBridge.currentContext().equals(attachedContext)) {
|
if (!helper().sameTrace(Java8BytecodeBridge.currentContext(), attachedContext)) {
|
||||||
// request processing is dispatched to another thread
|
// request processing is dispatched to another thread
|
||||||
scope = attachedContext.makeCurrent();
|
scope = attachedContext.makeCurrent();
|
||||||
context = attachedContext;
|
context = attachedContext;
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
package io.opentelemetry.javaagent.instrumentation.undertow;
|
package io.opentelemetry.javaagent.instrumentation.undertow;
|
||||||
|
|
||||||
|
import io.opentelemetry.api.trace.Span;
|
||||||
import io.opentelemetry.context.Context;
|
import io.opentelemetry.context.Context;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
||||||
import io.opentelemetry.javaagent.bootstrap.servlet.AppServerBridge;
|
import io.opentelemetry.javaagent.bootstrap.servlet.AppServerBridge;
|
||||||
|
@ -85,4 +86,12 @@ public class UndertowHelper {
|
||||||
AttachmentKey.class, key -> AttachmentKey.create(Context.class));
|
AttachmentKey.class, key -> AttachmentKey.create(Context.class));
|
||||||
exchange.putAttachment(contextKey, context);
|
exchange.putAttachment(contextKey, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean sameTrace(Context currentContext, Context attachedContext) {
|
||||||
|
return sameTrace(Span.fromContext(currentContext), Span.fromContext(attachedContext));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean sameTrace(Span oneSpan, Span otherSpan) {
|
||||||
|
return oneSpan.getSpanContext().getTraceId().equals(otherSpan.getSpanContext().getTraceId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue