Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undertow: restore attached context only when it is for different trace #10336

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static void onEnter(
@Advice.Local("otelScope") Scope scope) {
Context attachedContext = helper().getServerContext(exchange);
if (attachedContext != null) {
if (!Java8BytecodeBridge.currentContext().equals(attachedContext)) {
if (!helper().sameTrace(Java8BytecodeBridge.currentContext(), attachedContext)) {
// request processing is dispatched to another thread
scope = attachedContext.makeCurrent();
context = attachedContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.javaagent.instrumentation.undertow;

import io.opentelemetry.api.trace.Span;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.javaagent.bootstrap.servlet.AppServerBridge;
Expand Down Expand Up @@ -85,4 +86,12 @@ private static void attachServerContext(Context context, HttpServerExchange exch
AttachmentKey.class, key -> AttachmentKey.create(Context.class));
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