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

[question] How to instrument SQS lambdas properly? #2300

Open
Dreamescaper opened this issue Nov 5, 2024 · 4 comments
Open

[question] How to instrument SQS lambdas properly? #2300

Dreamescaper opened this issue Nov 5, 2024 · 4 comments
Labels
comp:instrumentation.awslambda Things related to OpenTelemetry.Instrumentation.AWSLambda enhancement New feature or request

Comments

@Dreamescaper
Copy link

Dreamescaper commented Nov 5, 2024

Component

OpenTelemetry.Instrumentation.AWSLambda

Question details

SQSEvent might contains multiple messages. How to handle them properly?

I can see that ExtractParentContext supports SQSEvent.SQSMessage input. So does it make sense to wrap each message processing, like this?

foreach (var message in sqsEvent.Records)
{
	await AWSLambdaWrapper.TraceAsync(tracerProvider, (message, context) => HandleAsync(...), message, lambdaContext);
}

Or maybe wrap both SQSEvent and SQSEvent.SQSMessage?

await AWSLambdaWrapper.TraceAsync(tracerProvider, async (sqsEvent, lambdaContext) =>
{
    foreach (var message in sqsEvent.Records)
    {
        await AWSLambdaWrapper.TraceAsync(tracerProvider, (message, context) => HandleAsync(...), message, lambdaContext);
    }
}, sqsEvent, lambdaContext);
@Dreamescaper Dreamescaper added the enhancement New feature or request label Nov 5, 2024
@github-actions github-actions bot added the comp:instrumentation.awslambda Things related to OpenTelemetry.Instrumentation.AWSLambda label Nov 5, 2024
Copy link
Contributor

github-actions bot commented Nov 5, 2024

Tagging component owner(s).

@srprash @ppittle @muhammad-othman @rypdal @Oberon00

@Dreamescaper Dreamescaper changed the title [question] How to instument SQS lambdas properly? [question] How to instrument SQS lambdas properly? Nov 5, 2024
@Oberon00
Copy link
Member

Oberon00 commented Nov 5, 2024

In the docs for Dynatrace we recommend calling TraceAsync only with the actual event object, not the messages: https://docs.dynatrace.com/docs/shortlink/aws-lambda-otel-dotnet#sqs-sns-in

After all, there is only one Lambda invocation, so calling TraceAsync multiple times seems semantically wrong. I think what would be needed would be an additional API that creates the right spans to represent that we are now processing a message but not invoking the Lambda again. Related new issue seems to be #2244 (though the SDK defines a different message type than Lambda libraries). Otherwise I'd recommend following the OTel messaging semantic conventions yourself. https://github.com/open-telemetry/semantic-conventions/blob/main/docs/messaging/README.md

@xactlance
Copy link

xactlance commented Nov 7, 2024

@Oberon00 But isn't each record it's own message with it's own MessageAttributes and thus it's own traceparent and tracestate? I personally do the second approach:

foreach (var message in sqsEvent.Records)
{
     await AWSLambdaWrapper.TraceAsync(tracerProvider, (message, context) => HandleAsync(...), message, lambdaContext);
}

I would love to know if this is wrong.

@Oberon00
Copy link
Member

Oberon00 commented Nov 8, 2024

I'm not 100% sure but won't it get the faas.trigger, etc. activity tags? That way, it would mean it was a separate Lambda invocation which it wasn't. So the faas attributes would need to be skipped at least

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:instrumentation.awslambda Things related to OpenTelemetry.Instrumentation.AWSLambda enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants