Review Serverless function X-Ray tracing

Choose tracing suited to incident analysis.

Description

AWS X-Ray helps investigate Lambda latency and errors. Active enables active tracing, with different sampling behavior from PassThrough. A function that omits its setting can inherit provider tracing configuration.

Potential impact

Without needed trace data, locating latency or failures across services can take longer.

Remediation

When active tracing is needed, use function-level tracing: Active or shared provider tracing settings. Grant required X-Ray permissions to a custom execution role and verify trace collection.

Examples

The examples change PassThrough to Active. Separately provide a handler compatible with Framework 4 and Node.js 22, an SNS topic ARN as failureTopicArn, and an execution-role ARN with X-Ray permissions as 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