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

Fix JMS context propagation problems #2702

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -77,9 +77,7 @@ public static void onEnter(
MessageDestination messageDestination =
tracer().extractDestination(message, defaultDestination);
context = tracer().startProducerSpan(messageDestination, message);
// TODO: why are we propagating context only in this advice class? the other one does not
// inject current span context into JMS message
scope = tracer().startProducerScope(context, message);
scope = context.makeCurrent();
}

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
import static io.opentelemetry.javaagent.instrumentation.jms.MessageExtractAdapter.GETTER;
import static io.opentelemetry.javaagent.instrumentation.jms.MessageInjectAdapter.SETTER;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.instrumentation.api.tracer.BaseTracer;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -43,12 +41,7 @@ public Context startConsumerSpan(
MessageDestination destination, String operation, Message message, long startTime) {
Context parentContext = Context.root();
if (message != null && "process".equals(operation)) {
// TODO use BaseTracer.extract() which has context leak detection
// (and fix the context leak that it is currently detecting when running Jms2Test)
parentContext =
GlobalOpenTelemetry.getPropagators()
.getTextMapPropagator()
.extract(Context.root(), message, GETTER);
parentContext = extract(message, GETTER);
}

SpanBuilder spanBuilder =
Expand All @@ -64,12 +57,9 @@ public Context startProducerSpan(MessageDestination destination, Message message
Context parentContext = Context.current();
SpanBuilder span = spanBuilder(parentContext, spanName(destination, "send"), PRODUCER);
afterStart(span, destination, message);
return parentContext.with(span.startSpan());
}

public Scope startProducerScope(Context context, Message message) {
Context context = parentContext.with(span.startSpan());
inject(context, message, SETTER);
return context.makeCurrent();
return context;
}

public String spanName(MessageDestination destination, String operation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ protected Boolean computeValue(Class<?> taskClass) {
return false;
}

// OrderedExecutor$1 is a worker class that processes tasks submitted to OrderedExecutor
mateuszrzeszutek marked this conversation as resolved.
Show resolved Hide resolved
if (taskClass
.getName()
.equals("org.hornetq.utils.OrderedExecutorFactory$OrderedExecutor$1")) {
return false;
}

Class<?> enclosingClass = taskClass.getEnclosingClass();
if (enclosingClass != null) {
// Avoid context leak on jetty. Runnable submitted from SelectChannelEndPoint is used to
Expand Down