diff --git a/instrumentation/rocketmq/rocketmq-client/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmqclient/v4_8/TracingConsumeMessageHookImpl.java b/instrumentation/rocketmq/rocketmq-client/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmqclient/v4_8/TracingConsumeMessageHookImpl.java index a1e307019bc5..be6e328bdc37 100644 --- a/instrumentation/rocketmq/rocketmq-client/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmqclient/v4_8/TracingConsumeMessageHookImpl.java +++ b/instrumentation/rocketmq/rocketmq-client/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmqclient/v4_8/TracingConsumeMessageHookImpl.java @@ -34,6 +34,10 @@ public void consumeMessageBefore(ConsumeMessageContext context) { Context parentContext = Context.current(); Context newContext = instrumenter.start(parentContext, context.getMsgList()); + // it's safe to store the scope in the rocketMq message context, both before() and after() + // methods are always called from the same thread; see: + // - ConsumeMessageConcurrentlyService$ConsumeRequest#run() + // - ConsumeMessageOrderlyService$ConsumeRequest#run() if (newContext != parentContext) { contextAndScopeField.set( context, ContextAndScope.create(newContext, newContext.makeCurrent()));