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.
import{Code,Function,Runtime,Tracing}from'@aws-cdk/aws-lambda';exportclassMyStackextendscdk.Stack{constructor(scope:cdk.Construct,id:string,props?:cdk.StackProps){super(scope,id,props);constmyFunction=newFunction(scope,'MyFunction',{code:Code.fromAsset('src/hello/'),handler:'main.handler',runtime:Runtime.PYTHON_3_8,// Enable active tracingtracing:Tracing.ACTIVE,});}}
1 2 3 4 5 6 7 8 910111213141516
{"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 91011
Resources:MyFunction:Type:AWS::Serverless::FunctionProperties:# Required propertiesCodeUri:.Runtime:python3.8Handler:main.handler# Enable active tracingTracing:Active
12345678
provider:tracing:# Enable active tracing for Lambda functionslambda:truefunctions:hello:handler:handler.hello
1 2 3 4 5 6 7 8 91011
resource"aws_lambda_function""this"{function_name="my-function"runtime="python3.8"handler="main.handler"filename="function.zip" # Enable active tracingtracing_config{mode="Active"}}