Enable trace delivery
Prerequisites
Turn on Transaction Search. Spans are stored in the aws/spans log group of CloudWatch Transaction Search. Turn on Transaction Search once for your account in each Region where you use traces. For instructions on turning on Transaction Search, see Enable Transaction Search in the Amazon CloudWatch User Guide.
Grant permissions. To enable trace delivery, the user or role that calls PutDeliverySource (or turns on Tracing in the console) must have the context:AllowVendedLogDeliveryForResource permission for the Agent Context, in addition to the permissions required to deliver to AWS X-Ray. Callers of the operations don’t need this permission. For more information, including example IAM policies, see Logging that requires additional permissions [V2] in the Amazon CloudWatch Logs User Guide.
The following example policy grants the permission for an Agent Context:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "context:AllowVendedLogDeliveryForResource", "Resource": "arn:aws:context:us-east-1:111122223333:agent-context/ac-1234567890abcdef" } ] }
Enable trace delivery using the console
-
Open the AWS Context console and choose your Agent Context.
-
On the Integration tab, turn on Tracing. AWS Context creates the trace delivery for the Agent Context.
Enable trace delivery using the CloudWatch Logs API
To enable trace delivery using the CloudWatch Logs API, follow these steps:
-
Get the Amazon Resource Name (ARN) of your Agent Context. Call the
GetAgentContextAPI. An Agent Context ARN has the following format:arn:aws:context:region:account-id:agent-context/agent-context-id. -
Call
PutDeliverySource. Use the PutDeliverySource API to create a delivery source for the Agent Context. Pass the Agent Context ARN as theresourceArnand specifyTRACESas thelogType.{ "name": "my-agent-context-traces", "resourceArn": "arn:aws:context:us-east-1:111122223333:agent-context/ac-1234567890abcdef", "logType": "TRACES" } -
Call
PutDeliveryDestination. Use the PutDeliveryDestination API with adeliveryDestinationTypeofXRAY. X-Ray is a managed destination, so you do not specify a destination resource ARN. Note the ARN that the response returns.{ "name": "my-xray-destination", "deliveryDestinationType": "XRAY" } -
Call
CreateDelivery. Use the CreateDelivery API to link the delivery source to the X-Ray delivery destination.{ "deliverySourceName": "my-agent-context-traces", "deliveryDestinationArn": "arn:aws:logs:us-east-1:111122223333:delivery-destination:my-xray-destination" }
View traces
After you enable trace delivery, call one of the operations to generate spans. Then view the spans in either of these places:
-
The X-Ray trace map and trace details in the CloudWatch console, to see each span inside your agent’s trace.
-
Transaction Search, or CloudWatch Logs Insights on the
aws/spanslog group, to search and count spans by their fields. For examples, see Example queries.