Review Serverless function X-Ray tracing

Choose tracing suited to incident analysis.

Description

Lambda’s Active mode sends trace segments for sampled invocations. A function can inherit its tracing setting from the provider.

Potential impact

In PassThrough mode, Lambda forwards trace context. To see where the function spends time, enable active tracing.

Remediation

Set tracing: Active on the function, or remove its PassThrough override to inherit active tracing from the provider. Grant a custom execution role permission to write to X-Ray and check for a sampled invocation.

Examples

For this Framework 4 example, supply a Node.js 22 handler.hello, the SNS topic ARN in failureTopicArn, and the execution role ARN in lambdaRoleArn.

Before

yaml
service: service
frameworkVersion: '4'
provider:
  name: aws
  runtime: nodejs22.x

functions:
  hello:
    handler: handler.hello
    onError: ${param:failureTopicArn}
    tags:
      foo: bar
    role: ${param:lambdaRoleArn}
    tracing: PassThrough

After

yaml
service: service
frameworkVersion: '4'
provider:
  name: aws
  runtime: nodejs22.x

functions:
  hello:
    handler: handler.hello
    onError: ${param:failureTopicArn}
    tags:
      foo: bar
    role: ${param:lambdaRoleArn}
    tracing: Active

References