opentelemetry-java-instrumentation icon indicating copy to clipboard operation
opentelemetry-java-instrumentation copied to clipboard

Couldn't get Producer span in rocketmq SendMessageHook

Open wang007 opened this issue 1 year ago • 8 comments

Describe the bug

I want to add message body to Producer Span but Couldn't get Producer span in rocketmq SendMessageHook.

image

This seems to be the result of not calling Context.attch()

image

my code image

Steps to reproduce

ignore

Expected behavior

ignore

Actual behavior

ignore

Javaagent or library instrumentation version

1.32.0

Environment

JDK: 1.8 OS: mac

Additional context

No response

wang007 avatar Mar 12 '24 12:03 wang007

cc @aaron-ai

trask avatar Mar 12 '24 14:03 trask

@wang007 Could you provide me with more details about the motivation? Usually, we don't need to record the message body in span.

aaron-ai avatar Mar 13 '24 04:03 aaron-ai

As you can see from the first image above, I've mounted a sendmessage hook image

  1. I want to customize some properties to the producer span, but I can't do that right now.
  2. The ability to customize should be given to the user

wang007 avatar Mar 13 '24 06:03 wang007

@wang007 The situation you mentioned occurs because the advice for sendMessageHook does not execute the context.makeCurrent() method to replace the current thread's context after starting a span. This may imply that the designers do not intend for others to retrieve context information via the OTel SDK at the time point of sending messages, nor to modify the span.

In fact, for the 4.x version of the rocketmq-client, the org.apache.rocketmq.client.producer.DefaultMQProducer#getDefaultMQProducerImpl() method has been deprecated. Perhaps we should not obtain this object and register hook components at runtime.

Cirilla-zmh avatar May 08 '24 12:05 Cirilla-zmh

If you're keen on capturing the body information of a message, there might be two approaches:

  1. Within the opentelemetry-java-instrumentation project, extract the body in io.opentelemetry.instrumentation.rocketmqclient.v4_8.TracingSendMessageHookImpl#sendMessageBefore() and inject it into an attribute. Incidentally, is there any plan from OTel to consistently log this attribute across all messaging-type instrumentations as features? @trask If so, I might be interested in contributing.
  2. Use the OTel SDK in your application code to create a span and record the message.body within this newly created span.

I hope my answer can be of help to you.

Cirilla-zmh avatar May 08 '24 13:05 Cirilla-zmh

I'm using the second solution, but I need to create an extra span. The issue is raised because other third-party components can get the current span content.

If you think that's how it's designed, close the issue.

thx @Cirilla-zmh

wang007 avatar May 17 '24 02:05 wang007

The issue is raised because other third-party components can get the current span content. If you think that's how it's designed, close the issue.

I believe the body of the message carries significant information, and it might be worth considering logging this information. We could implement it as a configurable feature.

I would be happy to contribute to this. But before doing so, I would like to know if contributions of this kind are welcome. @trask @aaron-ai @steverao

Cirilla-zmh avatar May 20 '24 11:05 Cirilla-zmh

I believe the body of the message carries significant information, and it might be worth considering logging this information. We could implement it as a configurable feature.

I would be happy to contribute to this. But before doing so, I would like to know if contributions of this kind are welcome. @trask @aaron-ai @steverao

yes, I believe capturing message bodies would be accepted as an opt-in feature, similar to capturing request/response bodies in https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/8778

trask avatar May 20 '24 16:05 trask