opentelemetry-go-contrib icon indicating copy to clipboard operation
opentelemetry-go-contrib copied to clipboard

Instrumentation for SNS/ SQS

Open febinrejoe opened this issue 3 years ago • 5 comments

Problem Statement

This could be more of a question rather than a feature request. I was wondering if we have a way to instrument Go for SNS/ SQS transactions. To give some background, I have a Go service (Service A) which talks to another service (Service B) via SQS and I would like to do tracing across these services. Any help with this will be greatly appreciated.

febinrejoe avatar Jan 28 '22 16:01 febinrejoe

Would the AWS client instrumentation work?

MrAlias avatar Jan 28 '22 16:01 MrAlias

I think that might trace the interaction with the SNS/SQS service, but it sounds like what's needed here is context propagation in messages carried by those services. Is that correct?

If so, there are a few options. You could use the propagation API to inject trace context data into the messages at the producer and extract it at the consumer. This could also be done using message attributes instead of the message body.

The second option would be to create a middleware for the AWS SDK v2 that could identify SQS requests/responses and handle the propagation automatically. Not quite sure how this would hand back an extracted span context to a consumer, but it might be an avenue worth exploring if you're using the v2 SDK.

The third approach would be to wrap the SDK client, similar to the Sarama instrumentation.

Aneurysm9 avatar Jan 28 '22 17:01 Aneurysm9

Thanks @Aneurysm9, I will need message propagation as well. I will look into the options provided.

febinrejoe avatar Jan 28 '22 22:01 febinrejoe

I have a very similar use-case to yours, @febinrejoe . Any advancement in your solution? Thank you!

mtcherni95 avatar Nov 17 '22 14:11 mtcherni95

I am currently sketching this carrier to perform context propagation across SQS messages using message attributes.

// ContextFromSqsMessageAttributes gets a tracing context from SQS message attributes.
// `sqsMessage` is incoming, received SQS message (possibly) carring trace information in the message attributes.
// Use ContextFromSqsMessageAttributes right after receiving an SQS message.
func ContextFromSqsMessageAttributes(sqsMessage *types.Message) context.Context

// InjectIntoSqsMessageAttributes inserts tracing from context into the SQS message attributes.
// `ctx` holds current context with trace information.
// `sqsMessage` is outgoing SQS message that will be set to carry trace information.
// Use InjectIntoSqsMessageAttributes right before sending out the SQS message.
func InjectIntoSqsMessageAttributes(ctx context.Context, sqsMessage *types.Message)

https://pkg.go.dev/github.com/udhos/opentelemetry-trace-sqs@main/otelsqs

It might be useful to some.

udhos avatar Jun 25 '23 06:06 udhos