Enable transaction search
You can enhance Lambda observability by using transaction search, which enables the capture of all trace spans for Lambda function invocation
without sampling. This feature allows you to collect 100% of the spans for your functions, unaffected by the sampled
flag in trace context propagation.
This ensures that there is no additional impact to downstream dependent services. By enabling transaction search on Lambda, you gain complete visibility into your function
performance and you can troubleshoot rarely occurring issues. To get started, see Transaction Search.
Enabling Transaction Search in the console
The following procedure describes how to enable Transaction Search in the console.
To enable Transaction Search in the CloudWatch console
-
Open the CloudWatch console at https://console.amazonaws.cn/cloudwatch/
. -
From the navigation pane, under Application Signals, choose Transaction Search.
-
Choose Enable Transaction Search.
-
Select the box to ingest spans as structured logs, and enter a percentage of spans to be indexed. You can index spans at 1% for free and change the percentage later based on your requirements.
Enabling Transaction Search using an API
The following procedure describes how to enable Transaction Search using an API.
Step 1. Create a policy that grants access to ingest spans in CloudWatch Logs
When using the Amazon CLI or SDK to enable Transaction Search, you must configure permissions using a resource-based policy with PutResourcePolicy
.
Example policy
The following example policy allows X-Ray to send traces to CloudWatch Logs
{ "Version": "2012-10-17", "Statement": [ { "Sid": "TransactionSearchXRayAccess", "Effect": "Allow", "Principal": { "Service": "xray.amazonaws.com" }, "Action": "logs:PutLogEvents", "Resource": [ "arn:partition:logs:region:account-id:log-group:aws/spans:*", "arn:partition:logs:region:account-id:log-group:/aws/application-signals/data:*" ], "Condition": { "ArnLike": { "aws:SourceArn": "arn:partition:xray:region:account-id:*" }, "StringEquals": { "aws:SourceAccount": "account-id" } } } ] }
Example command
The following example shows how to format your Amazon CLI command with PutResourcePolicy
.
aws logs put-resource-policy --policy-name MyResourcePolicy --policy-document '{ "Version": "2012-10-17", "Statement": [ { "Sid": "TransactionSearchXRayAccess", "Effect": "Allow", "Principal": { "Service": "xray.amazonaws.com" }, "Action": "logs:PutLogEvents", "Resource": [ "arn:partition:logs:region:account-id:log-group:aws/spans:*", "arn:partition:logs:region:account-id:log-group:/aws/application-signals/data:*" ], "Condition": { "ArnLike": { "aws:SourceArn": "arn:partition:logs:region:account-id:*" }, "StringEquals": { "aws:SourceAccount": "account-id" } } } ]}'
Step 2. Configure the destination of trace segments
Configure the ingestion of spans with UpdateTraceSegmentDestination
.
Example command
The following example shows how to format your Amazon CLI command with UpdateTraceSegmentDestination
.
aws xray update-trace-segment-destination --destination CloudWatchLogs
Step 3. Configure the amount of spans to index
Configure your desired sampling percentage with UpdateIndexingRule
Example command
The following example shows how to format your Amazon CLI command with UpdateIndexingRule
.
aws xray update-indexing-rule --name "Default" --rule '{"Probabilistic": {"DesiredSamplingPercentage": number}}'
Note
After you enable Transaction Search, it can take ten minutes for spans to become available for search and analysis.
Step 4. Verify spans are available for search and analysis
To verify spans are available for search and analysis, use GetTraceSegmentDestination
.
Example commands
The following example shows how to format your Amazon CLI command with GetTraceSegmentDestination
.
aws xray get-trace-segment-destination
Example response
The following example shows the response you can expect when Transaction Search is active.
{ "Destination": "CloudWatchLogs", "Status": "ACTIVE" }