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

Use traceparent from SQS MessageAttribute so that the transaction in Lambda to be a child of SQS Message Sender #4242

Open
deokgonkim opened this issue Sep 20, 2024 · 0 comments

Comments

@deokgonkim
Copy link

Is your feature request related to a problem? Please describe.
I have an API Server(nestjs) that sends messages to AWS SQS.
A Lambda retrieves messages from the SQS queue and processes them.

I would like these two transactions to be appear as related in the Service Map
Currently, I can see that the SQS Sender and SQS Receiver are linked via Span links

But I would prefer the Lambda function to be shown as a the child of API Server.

Describe the solution you'd like
I have reviewed the source code of lib/lambda.js

if (
(triggerType === TRIGGER_API_GATEWAY || triggerType === TRIGGER_ELB) &&
event.headers
) {
// https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
// says "Header names are lowercased." However, that isn't the case for
// payload format version 1.0. We need lowercased headers for processing.
if (!event.requestContext.http) {
// 1.0
event.normedHeaders = lowerCaseObjectKeys(event.headers);
} else {
event.normedHeaders = event.headers;
}
traceparent =
event.normedHeaders.traceparent ||
event.normedHeaders['elastic-apm-traceparent'];
tracestate = event.normedHeaders.tracestate;
}
// Start the transaction and set some possibly trigger-specific data.
const trans = agent.startTransaction(context.functionName, type, {
childOf: traceparent,
tracestate,
});
switch (triggerType) {
case TRIGGER_API_GATEWAY:
setApiGatewayData(agent, trans, event, context, gFaasId, isColdStart);
break;
case TRIGGER_ELB:
setElbData(agent, trans, event, context, gFaasId, isColdStart);
break;
case TRIGGER_SQS:
setSqsData(agent, trans, event, context, gFaasId, isColdStart);
break;

I noticed that only API Gateway and ELB trigger types are register as childOf the traceparent.

It would be ideal to use the traceparent injected into SQS Message Attribute to achieve this behavior.

Describe alternatives you've considered
I tried using agent.startTransaction API, but this left the messaging RECEIVED blabla transaction dangling.

Additional context
Is there any specific reason why SQS Message exchanges are linked only via span links rather than using parent-child transaction relationships?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant