Skip to content

Lambda Tracing

Level: Warning

Initial version: 0.1.3

cfn-lint: WS1000

tflint: aws_lambda_function_tracing_rule

AWS Lambda can emit traces to AWS X-Ray, which enables visualizing service maps for faster troubleshooting.

Why is this a warning?

You might use third party solutions for monitoring serverless applications. If this is the case, enabling tracing for your AWS Lambda functions might be optional. Refer to the documentation of your monitoring solutions to see if you should enable AWS X-Ray tracing or not.

Implementations

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
import { Code, Function, Runtime, Tracing } from '@aws-cdk/aws-lambda';

export class MyStack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const myFunction = new Function(
      scope, 'MyFunction',
      {
        code: Code.fromAsset('src/hello/'),
        handler: 'main.handler',
        runtime: Runtime.PYTHON_3_8,
        // Enable active tracing
        tracing: Tracing.ACTIVE,
      }
    );
  }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
{
  "Resources": {
    "MyFunction": {
      "Type": "AWS::Serverless::Function",
      "Properties": {
        // Required properties
        "CodeUri": ".",
        "Runtime": "python3.8",
        "Handler": "main.handler",

        // Enable active tracing
        "Tracing": "Active"
      }
    }
  }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
Resources:
  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      # Required properties
      CodeUri: .
      Runtime: python3.8
      Handler: main.handler

      # Enable active tracing
      Tracing: Active
1
2
3
4
5
6
7
8
provider:
  tracing:
    # Enable active tracing for Lambda functions
    lambda: true

functions:
  hello:
    handler: handler.hello
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
resource "aws_lambda_function" "this" {
  function_name = "my-function"
  runtime       = "python3.8"
  handler       = "main.handler"
  filename      = "function.zip"

  # Enable active tracing
  tracing_config {
    mode = "Active"
  }
}

See also