Traces
A trace follows one request through your services. It’s made of spans, one per unit of work: the Function’s handler, the DynamoDB query it makes, the call to another service. Spans share a trace ID, so the whole request can be read back together.
AWS keeps spans in one of two places, chosen once for the whole account and region. By default they go to X-Ray’s own store. With Transaction Search on, every span is written to the aws/spans log group in CloudWatch Logs instead, where it’s searchable like any log, and a share of them, 1% by default, is also indexed as trace summaries. OpenTelemetry traces only go to the second: CloudWatch refuses them while the account is on X-Ray.
Turn it on from your runtime
Section titled “Turn it on from your runtime”AWS.CloudWatch.Telemetry with traces: true turns Transaction Search on when it’s off. It never turns it off: it’s one setting for the whole account, and other stacks may send traces too.
Effect.provide(AWS.CloudWatch.Telemetry({ traces: true }));Or declare it once for the account
Section titled “Or declare it once for the account”Declare it yourself to set how much is indexed, or to put the account back the way it was when the stack is destroyed. Creating it records the current destination and indexing percentage, and destroying it restores both:
yield* AWS.XRay.TransactionSearch("TransactionSearch", { indexingPercentage: 5 });Pass transactionSearch: false to the runtime’s layer when the account’s Transaction Search is declared like this, or managed outside Alchemy.
Every span from every service in the account now goes to CloudWatch Logs, and it’s billed as log ingestion. The first 1% indexed is free; a higher percentage costs more. See CloudWatch pricing.
Trace Lambda itself
Section titled “Trace Lambda itself”Your code’s spans cover your code. To also record Lambda’s own work around it, like cold starts and the time before your handler runs, turn on active tracing:
{ main: import.meta.url, tracing: "Active" }Lambda then samples requests and records them as X-Ray traces, which follow the account’s destination like any other span.
Read the spans
Section titled “Read the spans”With Transaction Search on, each span is a JSON log event in aws/spans, with its trace ID, name, timing and attributes. Search them in CloudWatch’s Transaction Search console, or query the log group with Logs Insights like any log group.