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

Message handler

Open atshaw43 opened this issue 2 years ago • 7 comments

Problem Adding Message Handler for messaging systems. These new handlers will create a span for the user and add span links and set the messaging attributes.

Testing Unit tests

atshaw43 avatar Apr 21 '23 07:04 atshaw43

@atshaw43 we already have aws lambda instrumentation in https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/aws-lambda/aws-lambda-events-2.2/library

laurit avatar Apr 21 '23 08:04 laurit

@atshaw43 we already have aws lambda instrumentation in https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/aws-lambda/aws-lambda-events-2.2/library

Those are Lambda specific because of the Context variable. This is for non-Lambda cases such as EC2.

This is for batching messages, while those classes are for for-loop cases. One message at a time.

atshaw43 avatar Apr 21 '23 16:04 atshaw43

@laurit Bump

atshaw43 avatar Apr 25 '23 17:04 atshaw43

@atshaw43 Firstly the module name message-handler doesn't seem appropriate as the code seems to deal only with aws messages. Perhaps it should be named aws-something-something or even be moved to aws-sdk module. Secondly instrumentations in this repository must use instrumenter api. The provided documentation does not do a good job illustrating why this code should be used. Also I believe aws-sdk instrumentation already creates spans for sqs, can this code be used together with aws-sdk instrumentation?

laurit avatar Apr 26 '23 09:04 laurit

Firstly the module name message-handler doesn't seem appropriate as the code seems to deal only with aws messages.

I think this is only sort of true. The code is in many places generic, and I think with a few small adjustments, the interface could be fit for any messages. But at the moment, I agree that it is too AWS-specific.

Note that there is also very similar functionality in the AWS Lambda instrumentation, that could be used as inspiration and generalized: https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/aws-lambda/aws-lambda-events-2.2/library/src/main/java/io/opentelemetry/instrumentation/awslambdaevents/v2_2/TracingSqsMessageHandler.java (maybe even in a way that the AWS Lambda instrumentation could re-use code from this new proposed message handler module)

Oberon00 avatar Apr 26 '23 11:04 Oberon00

@atshaw43 Firstly the module name message-handler doesn't seem appropriate as the code seems to deal only with aws messages. Perhaps it should be named aws-something-something or even be moved to aws-sdk module. Secondly instrumentations in this repository must use instrumenter api. The provided documentation does not do a good job illustrating why this code should be used. Also I believe aws-sdk instrumentation already creates spans for sqs, can this code be used together with aws-sdk instrumentation?

@laurit Thanks for the feedback. I have moved the x-ray specific code to the SqsMessageHandler.

atshaw43 avatar May 31 '23 17:05 atshaw43

I updated the PR so the MessageHandler focuses on process spans. I had originally tried to have it handle receive and process spans, but that is not feasible. I will open a separate PR for auto-instrumentation for SQS receive message nodes.

atshaw43 avatar Jul 21 '23 18:07 atshaw43

This PR has been labeled as stale due to lack of activity. It will be automatically closed if there is no further activity over the next 14 days.

github-actions[bot] avatar Oct 03 '25 00:10 github-actions[bot]