Where the Trace Breaks - Carrying Trace Context Through Queues, Event Buses, and Workflows on AWS
First Published:
Last Updated:
For each asynchronous boundary on AWS, this article sorts out whether trace context continues, becomes a link, breaks, or is not described on the pages. It covers SQS, SNS, EventBridge (Custom event bus - classic and the new Custom event bus that launched in September 2026), Step Functions, asynchronous Lambda invocations and destinations, and Lambda event source mappings. For each boundary, it details the mechanisms used to carry context (such as HTTP headers like
X-Amzn-Trace-Id, SQS's AWSTraceHeader, API arguments like TraceHeader and traceHeader, and Lambda environment variables like _X_AMZN_TRACE_ID). Finally, it addresses propagation when migrating to OpenTelemetry and discusses limitations on trace size.Where the documentation alone does not settle the behavior, this article fills the gap with records from a demo run in us-east-1. It is based on documents read on December 3, 2026 (during re:Invent 2026) and on records from a demo run in the same period. It does not cover instrumentation procedures, pricing, or Transaction Search configuration.
Related articles on this site:
- AWS Observability Architecture Guide - End-to-End Tracing, Metrics, and Logs with CloudWatch, X-Ray, Application Signals, and OpenTelemetry
- OpenTelemetry-Native Observability on AWS - OTLP Ingestion, PromQL, and the X-Ray SDK Transition
- Event-Driven Serverless Architecture on AWS - Building Resilient Workflows with API Gateway, Lambda, EventBridge, Step Functions, and DynamoDB
- What Happens to a Failed Asynchronous Lambda Invocation - Caller Retries, the Internal Queue, and Where a Discarded Event Goes
Table of Contents
- 1. Scope and Assumptions
- 2. What Breaks at a Boundary
- 3. SQS and Lambda
- 4. SNS and EventBridge
- 5. Step Functions and Lambda
- 6. A Table by Boundary
- 7. When You Switch to OpenTelemetry
- 8. What the Demo Confirmed
- 9. Frequently Asked Questions About Trace Propagation
- 10. Summary
- 11. References
1. Scope and Assumptions
This chapter first sets out the intended audience, the scope, the materials read, the statement labels, and the terms used. The conclusions come first, in eight points.- The context of a trace consists of three elements: the trace ID, the parent segment ID, and the sampling decision. At asynchronous boundaries, the mechanism for carrying these three elements varies depending on the boundary (see Chapter 2).
- The SQS page says that the trace can continue with the same trace ID from a sender instrumented with the X-Ray SDK to the consumer. The same page also says that for Lambda consumers, the trace is automatically linked to the upstream trace. Consumers other than Lambda read
AWSTraceHeaderand restore the context themselves (see Chapter 3). - EventBridge's Custom event bus - classic carries the header only when the
PutEventsrequest passes the trace context. The header is not in the body of the event that reaches the target, and events replayed from an archive do not include it either (see Chapter 4). - On the new Custom event bus, the pages name a trace field for only two targets:
MessageSystemAttributesfor SQS targets andTraceHeaderfor Step Functions targets. In both cases, the user writes the value (see Chapter 4). - The Step Functions documentation states that if execution is initiated from Lambda or the SDK, the application must explicitly pass a
traceHeader. The Lambda pages say that asynchronous Lambda invocations and destinations are automatically linked to the upstream trace (see Chapter 5). - The documentation indicates that for Lambda event source mappings, MSK, self-managed Apache Kafka, Amazon MQ, and DocumentDB do not support X-Ray tracing. The documentation consulted did not contain information regarding Kinesis and DynamoDB Streams propagation (see Chapter 5).
- The documentation states that OpenTelemetry's default propagation uses the W3C Trace Context, and that for AWS services, the X-Ray propagator is used. Segments are limited to 64 KB, and traces have limits of 500 KB and 100 KB (see Chapter 7).
- In the us-east-1 demo, AWS SDK calls inside Lambda alone, without the X-Ray SDK, kept the same trace across EventBridge classic, Step Functions, SNS subscriptions to Lambda, asynchronous Lambda invocations, and Lambda targets on the new Custom event bus. The Lambda functions downstream of SQS ended up in separate traces, connected by links (see Chapter 8).
1.1 Target Audience
This article is for readers who run event-driven applications on AWS and have seen, in the X-Ray or CloudWatch trace views, a trace switch to a different trace partway through, or show nothing past a certain point. The article assumes basic knowledge of X-Ray traces, segments, and sampling, and of SQS, SNS, EventBridge, Step Functions, and Lambda.1.2 What This Article Covers and What It Does Not
This article covers how AWS services handle trace context at boundaries. It keeps what the pages say separate from what the demo observed.The following topics are covered elsewhere on this site:
- Configuring code to include context within message bodies using OpenTelemetry, and retrieving it: Section 3.4 of AWS Observability Architecture Guide. Section 10.1 of the same article covers the symptoms and causes when a trace breaks partway.
- Migrating from the X-Ray SDK to OpenTelemetry: Chapter 10 of OpenTelemetry-Native Observability on AWS.
- Designing a system to include correlation IDs in business events: Section 10.1 of Event-Driven Serverless Architecture on AWS.
- Definitions of terms such as X-Ray trace ID and W3C Trace Context: AWS Observability Glossary.
- What is delivered to destinations and DLQ (Dead Letter Queue) when an asynchronous invocation fails: Chapter 6 of What Happens to a Failed Asynchronous Lambda Invocation.
- Architectures for propagating OpenTelemetry context across asynchronous stages in LLM (Large Language Model) applications: Section 3.3 of LLMOps Observability and Evaluation Architecture on AWS.
- Limitations of reading per-request context from environment variables in AWS Lambda Managed Instances: Section 6.6 of AWS Lambda Managed Instances.
This article does not cover pricing, the steps to enable Transaction Search and the change in billing, which of X-Ray and OpenTelemetry is better, or how to use instrumentation libraries.
1.3 Checked Date and Reviewed Materials
The checked date is December 3, 2026. This date falls during the re:Invent 2026 conference (November 30 – December 4, 2026), and the pages reviewed for this article may change during the conference period.The materials reviewed included the developer guides and API references for X-Ray, EventBridge, SQS, SNS, Step Functions, Lambda, and CloudWatch, as well as the X-Ray limits page in the AWS General Reference, the AWS CLI reference, and AWS What's New.
Two name changes are relevant to this article.
First, there is EventBridge. On September 24, 2026, a new Custom event bus launched. AWS What's New states that existing buses have been renamed to "Custom event bus - classic," and that existing APIs remain unchanged. The X-Ray page in the EventBridge user guide explicitly states that this page applies to the "Custom Event Bus - Classic" (Section 4.4). This article calls the existing bus the classic bus and the new one the new Custom event bus.
Second, there is Lambda. The Lambda developer guide uses the terms "Event Functions" for functions triggered by events, and "Web Functions" for functions that respond to HTTP requests. The title of the X-Ray page also uses the term "Event Function." When this article refers to Lambda functions, it refers to Event Functions unless otherwise specified.
The X-Ray SDK and X-Ray Daemon entered maintenance mode on February 25, 2026. The support table in the X-Ray developer guide lists the end date of maintenance mode as N/A and recommends migrating to OpenTelemetry (Stated). The demo in this article does not use the X-Ray SDK, and relies only on what the services propagate and on an uninstrumented AWS SDK. Chapter 10 of OpenTelemetry-Native Observability on AWS (Section 1.2) covers migration in detail.
1.4 Statement Labels
This article puts one of the following four labels on each statement.| Label | Meaning |
|---|---|
| Stated | Found in AWS documentation (Developer Guide, API Reference, General Reference, CLI Reference, What's New). |
| Not stated | Not found within the documents reviewed for this article. This does not constitute proof of non-existence, nor does it indicate that the information is not propagated. |
| Inference | Derived from the content of the documents or the source code of the AWS SDK. |
| Observed | Observed in the Chapter 8 demo (us-east-1, December 2026). It does not necessarily apply to other Regions, other periods, or other configurations. |
Please do not read Not stated as meaning that the context is not propagated. This article puts Not stated only on what it could not find even after searching with different terms, and says that context is not propagated only when a page says so.
1.5 Usage of Terms
This article sorts what happens at a boundary into four categories.| Term | Meaning |
|---|---|
| Continues | The segment following the boundary has the same trace ID as the segment preceding it. In the X-Ray interface, this is displayed as a parent-child relationship within a single trace. |
| Linked | The segment following the boundary belongs to a different trace, and the two traces are connected by a link. In the X-Ray interface, this link is represented by a dashed edge (see Section 3.4). |
| Breaks | The segment following the boundary belongs to a different trace, and there is no connection to the previous trace. This article uses it when a page says the context is not carried, not traced, or not supported. |
| Not stated | The pages this article read do not say which of the three above applies. |
In addition, the following terms are used:
- Trace context: A combination of the trace ID, the ID of the parent segment, and the sampling decision. In the X-Ray format, this is represented as a single string within a trace header (see Section 2.1).
- Boundary: A point where a request is passed asynchronously from one service to another. This refers to sending to a queue, publishing to a topic, sending
PutEventsto an event bus, starting a workflow, making asynchronous calls to Lambda, or invoking a function through an event source mapping. - Carrier: The location that carries the trace context across a boundary. This can include HTTP headers, message system attributes, API arguments, or Lambda environment variables (see Section 2.2).
2. What Breaks at a Boundary
This chapter looks at what trace context is made of, what carries it, and how continuing differs from being linked.2.1 Contents of the Trace Header
The X-Ray developer guide provides the following example of a trace header (Stated).X-Amzn-Trace-Id: Root=1-5759e988-bd862e3fe1be46a994272793;Parent=53995c3f42cd8ad8;Sampled=1;Lineage=25:a87bd80c:1
The
Root field contains the trace ID. The 8 hexadecimal digits after 1- are the time the request started, and the subsequent 24 digits are a random number. Parent is the ID of the parent segment; it decides which segment the segment past the boundary becomes a child of. The Sampled field indicates the sampling decision; a value of 1 means it is recorded, while 0 means it is not.About
Lineage, the page says the following (Stated).
Lineage may be appended to the trace header by Lambda and other AWS services as part of their processing mechanisms, and should not be directly used.
AWS services such as Lambda may add
Lineage for their own processing; users should not use it directly. This article reads the field as being used by the recursive loop detection covered in Section 5.6 (Inference, Section 8.5).Context breaking at a boundary means that the service past the boundary cannot receive the three fields (
Root, Parent, and Sampled). When it cannot, the service past the boundary starts a trace with a new Root. Because Sampled does not arrive either, the sampling decision is made again past the boundary.2.2 Carriers
This article sorts the carriers of trace context that the AWS pages describe into four kinds. Each is a field that the pages name (Stated).| Carrier | Form | Pages that describe it |
|---|---|---|
X-Amzn-Trace-Id | HTTP header. Attached to requests that call AWS service APIs. | X-Ray (Tracing header), SQS, EventBridge, Step Functions |
AWSTraceHeader | System attribute of SQS messages. Remains on the queue along with the message. | SQS (SendMessage), X-Ray |
TraceHeader / traceHeader | API argument. TraceHeader in EventBridge's PutEventsRequestEntry, traceHeader in Step Functions' StartExecution and StartSyncExecution, and TraceHeader for Step Functions targets on the new Custom event bus. | EventBridge, Step Functions |
_X_AMZN_TRACE_ID | Environment variable within the Lambda execution environment. Contains the trace header for each invocation. | Lambda |
HTTP headers and API arguments carry the context for one call only. The HTTP headers themselves are not retained in messages that remain on queues or in archived events. Only fields associated with the message, such as SQS system attributes, remain alongside the message (Inference). In the Chapter 8 demo, SQS kept the value of the sending HTTP header in
AWSTraceHeader (Observed).When the same request has both an HTTP header and an API field, which one is used differs by service (Stated).
| Service | Behavior when both are present |
|---|---|
| SQS | The message system attribute (AWSTraceHeader) takes precedence over the HTTP header. |
| EventBridge (classic) | The TraceHeader in PutEventsRequestEntry takes precedence over the HTTP header. |
| Step Functions | The HTTP header takes precedence over the traceHeader in the request body. |
In SQS and EventBridge the API field wins; in Step Functions the header wins. Fields that look alike take precedence in opposite directions.
2.3 Continuing Versus Being Linked
When the trace continues, the segment past the boundary has the same trace ID and is part of a single trace. The X-Ray interface shows the whole chain, from sender to consumer, on a single timeline.When the trace is linked, the segment past the boundary belongs to a different trace with a different trace ID. X-Ray connects these upstream and downstream traces using links. The X-Ray pages describe this form for SQS and Lambda (see Section 3.2). There is a limit to the number of links (see Section 3.4).
The difference matters in practice in the following cases.
- When searching by trace ID: If the trace continues, the entire chain appears under a single trace ID. If it is linked, the downstream trace will have a different trace ID, and you can trace the connection from the upstream trace.
- When reaching the maximum size limit for a trace: If the trace continues, the segments past the boundary count toward the same trace's size. If it is linked, the trace is split at the boundary (Inference).
- Sampling: If the trace continues, the upstream
Sampleddecision also applies downstream.
3. SQS and Lambda
This chapter addressesAWSTraceHeader for SQS, the two statements on the SQS page, consumers other than Lambda, and link limits.3.1 AWSTraceHeader and HTTP Headers
The SQS SendMessage API reference describes message system attributes as follows (Stated).Currently, the only supported message system attribute isAWSTraceHeader. Its type must beStringand its value must be a correctly formatted AWS X-Ray trace header string.
SQS only supports one system attribute:
AWSTraceHeader. Its value must be a string formatted as an X-Ray trace header. The same reference also states that the size of system attributes is not included in the overall message size. The X-Ray page says that the trace header counts toward neither the message size nor the message attribute limit (Stated).There are two ways for a sender to pass the trace header to SQS. The X-Ray page describes them as follows (Stated).
- Default HTTP Header: When using the AWS SDK with SQS, the X-Ray SDK automatically adds the trace header as an HTTP header. The default header is
X-Amzn-Trace-Idand applies to all messages included in aSendMessageorSendMessageBatchrequest. AWSTraceHeaderSystem Attribute: This can be used even when automatic instrumentation by the X-Ray SDK is not available. If both are configured, the system attribute takes precedence over the HTTP header.
If a sender that does not use the X-Ray SDK sets
AWSTraceHeader itself, Python code can look like the following. Inside Lambda, the trace header for the current invocation is in _X_AMZN_TRACE_ID. In the Chapter 8 demo, the HTTP header that the AWS SDK adds inside Lambda (Section 5.6) was enough on its own: the messages the consumer received carried AWSTraceHeader (Observed). The code below is needed for a sender outside Lambda, or when you want to set the value explicitly (Inference).import os
import boto3
sqs = boto3.client("sqs")
def send_with_trace(queue_url, body):
kwargs = {"QueueUrl": queue_url, "MessageBody": body}
header = os.environ.get("_X_AMZN_TRACE_ID")
if header:
# The value must be a complete X-Ray trace header string (Root=...;Parent=...;Sampled=...).
kwargs["MessageSystemAttributes"] = {
"AWSTraceHeader": {"DataType": "String", "StringValue": header}
}
return sqs.send_message(**kwargs)
_X_AMZN_TRACE_ID may include Lineage. The pages this article read do not say whether the value may be passed with Lineage included (Not stated). The demo passed it in that form (Chapter 8).3.2 Two Statements on the SQS Page
The SQS page in the X-Ray developer guide describes what happens past the boundary in two ways. The first statement reads as follows (Stated).If a service traces requests by using the X-Ray SDK, Amazon SQS can send the tracing header and continue to propagate the original trace from the sender to the consumer with a consistent trace ID.
When the sender is a service that traces requests with the X-Ray SDK, SQS sends the trace header and can continue the original trace from sender to consumer with the same trace ID.
The next paragraph on the same page says the following about Lambda consumers (Stated).
Traces from upstream message producers are automatically linked to traces from downstream Lambda consumer nodes, creating an end-to-end view of the application.
The upstream sender's trace is automatically linked to the downstream Lambda consumer's trace.
The X-Ray page in the Lambda developer guide also states that traces from upstream producers, such as SQS, are automatically linked to traces from downstream Lambda functions (Stated).
The first statement describes a trace that continues, while the second describes a trace that is linked to another trace. The two statements cover the kind of consumer and the sender's instrumentation separately, and the page does not say which one applies to which combination (Not stated). This article therefore does not describe the SQS-to-Lambda boundary as one that continues a single trace. Going by the page text, it is a link; Chapter 8 reports which one the demo produced.
3.3 Consumers Other Than Lambda
The same page says the following about consumers that are not Lambda (Stated).If you are using a Lambda downstream consumer, trace context propagation is automatic. To continue context propagation with other Amazon SQS consumers, you must manually instrument the handoff to the receiver component.
Consumers reading queues on EC2, ECS, or on-premises hosts must manually instrument context passing. The page outlines three steps. First, receive messages by specifying the
AWSTraceHeader attribute with the ReceiveMessage call. Second, extract the trace header from the attribute. Third, restore the trace ID from the header. The page's example, using the X-Ray SDK for Java, demonstrates setting received header values such as Root, Parent, and Sampled directly into the consumer's segment (Stated).This example places the consumer's segment inside the sender's trace, so the trace continues rather than being linked (Inference). The
ReceiveMessage API reference describes MessageSystemAttributeNames as the list of attributes returned along with the message (Stated). As in the page's example, name AWSTraceHeader explicitly to receive it.3.4 Link Limits
The X-Ray page describes the link limits as follows (Stated).Each trace segment can be linked to up to 20 traces, while a trace can include a maximum of 100 links.
A single segment can be linked to a maximum of 20 traces, and a trace can contain a maximum of 100 links. The page goes on to say that adding links can push the trace document past its size limit, and the trace can then be incomplete. As an example, it gives a Lambda function with tracing turned on that sends many SQS messages in one invocation (Stated).
In the CloudWatch console's Trace Map, links are displayed as dashed lines connecting SQS nodes to downstream Lambda consumer nodes (Stated).
4. SNS and EventBridge
This chapter covers SNS propagation and the differences between the EventBridge classic bus and the new Custom event bus.4.1 SNS
The SNS page in the X-Ray developer guide says the following (Stated).If you publish to an Amazon SNS topic from a service that’s already instrumented with X-Ray, Amazon SNS passes the trace context from publisher to subscribers.
If you publish from a service instrumented with X-Ray, SNS will pass the context from the publisher to the subscriber. The X-Ray developer guide, listing services that integrate with X-Ray, includes an entry for SNS, stating that if the publisher traces its client with the X-Ray SDK, subscribers can extract the trace header and continue the original trace using the same trace ID (Stated). The SNS developer guide also states that if you call the SNS API from a service that is already traced, SNS will pass the trace, even if X-Ray tracing is not turned on for that API (Stated).
When active tracing is enabled on a topic, SNS sends segment data for each subscriber to X-Ray. The subscriptions that the SNS developer guide lists for active tracing are Amazon Data Firehose, Lambda, SQS, and HTTP/S. The guide also states that when active tracing is enabled, the topic reads the trace ID, sends the data based on the trace ID, and forwards the trace ID to downstream services (Stated).
However, the pages this article read do not say, for each subscription type, whether the downstream continues the same trace or is linked (Not stated). Nor do they say whether the SQS page's link statement (Section 3.2) applies on the path from SNS through SQS to Lambda (Not stated). Chapter 8 gives the demo results.
There are two cautions for SNS (Stated).
- Topics with a large number of subscribers may reach the maximum trace size, and not everything may be traced.
- When configuring active tracing through the console, SNS will attempt to configure the necessary permissions. When configuring it through the CLI, you must configure the permissions yourself in the X-Ray resource policy.
4.2 EventBridge Classic: Only When PutEvents Passes the Context
The X-Ray page in the EventBridge user guide says the following about the classic bus (Stated).
EventBridge can pass a trace header for an event only if the event came from a PutEvents request that passed the trace context.
EventBridge can only pass a trace header for an event if the event originates from a
PutEvents request that includes the trace context. The page continues, stating that events originating from third-party partners, scheduled events, or AWS services will not be traced by X-Ray and will not appear in the service map (Stated).So you cannot describe EventBridge as a whole as a service that propagates traces. It only does so when a
PutEvents request includes the context, and events from partners, schedules, and AWS services are not traced.There are two ways to pass context with
PutEvents (Stated).- Default HTTP header: The X-Ray SDK automatically adds the trace header as an HTTP header named
X-Amzn-Trace-Idfor all targets. TraceHeadersystem attribute:TraceHeaderis an attribute of thePutEventsRequestEntrythat EventBridge reserves for transporting the X-Ray trace header to the target. If you usePutEventsRequestEntry, it takes precedence over the HTTP trace header.
The
TraceHeader is not factored into the event's size (Stated). X-Ray validates the trace header and discards any that are invalid. However, the event itself is still processed (Stated). Even if the header format is incorrect, the event is still delivered, and only the context is lost (Inference).In the Chapter 8 demo, without passing
TraceHeader, the HTTP header that the AWS SDK adds inside Lambda (Section 5.6) was enough for the target Lambda function to continue the same trace (Observed). If you explicitly pass a TraceHeader without using the X-Ray SDK, it would take the following form:import json
import os
import boto3
events = boto3.client("events")
def put_with_trace(bus_name, detail):
entry = {
"EventBusName": bus_name,
"Source": "example.app",
"DetailType": "order-created",
"Detail": json.dumps(detail),
}
header = os.environ.get("_X_AMZN_TRACE_ID")
if header:
# TraceHeader overrides the X-Amzn-Trace-Id HTTP header for this entry.
entry["TraceHeader"] = header
return events.put_events(Entries=[entry])
4.3 The Target's Event Body, Archives, and the DLQ
On what is passed to the target, the same page puts two statements side by side. The first reads as follows (Stated).EventBridge passes the original trace header to the target so that target services can track, analyze, and debug.
It is followed by this sentence in an Important box (Stated).
The trace header is not available on the event that's delivered to the invocation target.
EventBridge forwards the original trace header to the target service, but the trace header is not present in the body of the event delivered to the target. If the target's Lambda function searches the event JSON for the trace header, it will not find it. A header on the call to the target service and a header in the event body are two different things (Inference).
About archives and replay, the page says the following (Stated).
If you have an event archive, the trace header isn't available on archived events. If you replay archived events, the trace header isn't included.
Archived events do not include the trace header, nor is it included when replaying archived events. The target of a replayed event has no connection to the original trace (Inference).
Concerning the DLQ, the page states that the trace header is included in the
SendMessage request that sends the event to the DLQ. When reading from the DLQ using ReceiveMessage, the trace header is present as an SQS message attribute, but not in the body of the event message (Stated). The page does not say which message attribute name holds it (Not stated).4.4 The New Custom Event Bus
The new Custom event bus, launched on September 24, 2026, has a different API from the classic bus. The AWS CLI handles it withaws eventsv2 (Stated, CLI reference). In the AWS SDK for Python, it is the eventbridgev2 client (checked in the botocore 1.44.18 service model).The EventBridge X-Ray page says the following about the new bus in a Note at the top (Stated).
A Custom Event Bus subscriber propagates a trace header to Step Functions targets throughStepFunctionsParameters.TraceHeaderand to Amazon SQS targets throughMessageSystemAttributes; see Targets for a Custom Event Bus subscriber.
The X-Ray page specifically mentions two fields that carry the trace header to targets on the new bus:
StepFunctionsParameters.TraceHeader for Step Functions targets and MessageSystemAttributes for SQS targets. The individual target pages describe these two fields as follows (Stated).| Target | Field | What the page says |
|---|---|---|
| SQS | MessageSystemAttributes | System attributes, such as the AWS X-Ray trace header |
| Step Functions | TraceHeader | The AWS X-Ray trace header to propagate |
Both are parameters for the Subscriber. The Subscriber is a resource that defines the conditions for the events it receives and a single target to which events are sent (Stated). The user writes each field's value, either as a fixed string or as a JSONata expression that extracts a value from the event. The pages for Lambda, SNS, and HTTP endpoint targets do not mention a field for tracing (Not stated).
The new bus's
PutEvents fields are Source, DetailType, Detail, Resources, Time, and SystemMetadata. The field equivalent to the TraceHeader in the classic bus does not appear in the CLI reference syntax (Stated, syntax). Furthermore, the SystemMetadata table also lacks a trace field. The word "trace" does not appear on the new bus's observability page or on the page about migrating from the classic bus either (Not stated).In short, the new bus's pages provide two fields on the target side for a value. They do not say where that value should come from (Not stated). Nor do they say whether the new bus carries the
X-Amzn-Trace-Id HTTP header of the PutEvents call to the target (Not stated).The demo tried having the publisher put its own trace header into the event's
detail and pulling it out into the SQS target's MessageSystemAttributes with a JSONata expression. The AWS SAM template looked like this:V2SubscriberSqsAttr:
Type: AWS::EventsV2::Subscriber
Properties:
# ...bus, filter, and delivery role omitted...
Target:
TargetArn: !GetAtt QV2Attr.Arn
SqsParameters:
MessageSystemAttributes:
AWSTraceHeader:
DataType: String
# The publisher copies its own trace header into detail.traceHeader.
StringValue: '{% $events.Data.detail.traceHeader %}'
This form is not a procedure the page gives; this article put it together from the field descriptions (Inference). In the Chapter 8 demo, a Subscriber that did not write this field also got
AWSTraceHeader with the same value, and the Lambda target, which has no such field, continued the same trace (Observed, Section 8.5).5. Step Functions and Lambda
This chapter covers the Step FunctionstraceHeader, Lambda Active and PassThrough, asynchronous invocations and destinations, event source mappings, and the newly named Lambda function types.5.1 The Step Functions traceHeader
The Step Functions developer guide describes how to connect a workflow to an upstream service as follows (Stated).To integrate the execution of Step Functions workflows, such as Express, Synchronous, and Standard workflows, with an upstream service you need to set thetraceHeader. This is automatically done for you if you are using a HTTP API in API Gateway. However, if you're using a Lambda function and/or an SDK, you need to set thetraceHeaderon theStartExecutionorStartSyncExecutionAPI calls yourself.
If you start from an HTTP API in API Gateway, it is automatic. If you start from a Lambda function or an SDK, you need to manually set the
traceHeader for StartExecution or StartSyncExecution. To ensure the same trace ID is used, format it as Root={TRACE_ID};Sampled={1 or 0} (Stated).The
StartExecution API reference, on the other hand, describes traceHeader as follows (Stated).For X-Ray traces, all AWS services use theX-Amzn-Trace-Idheader from the HTTP request. Using the header is the preferred mechanism to identify a trace.StartExecutionandStartSyncExecutionAPI operations can also usetraceHeaderfrom the body of the request payload. If both sources are provided, Step Functions will use the header value (preferred) over the value in the request body.
To identify the trace, the HTTP header comes first and the body's
traceHeader second. The length of the traceHeader can range from 0 to 256 characters, and its pattern is \p{ASCII}* (Stated).The developer guide states that if calling from Lambda, you should configure it yourself, while the API reference states that if HTTP headers are present, they should be used. If the AWS SDK within Lambda adds HTTP headers (as described in Section 5.6), it may be possible to continue tracing without passing the
traceHeader. The pages do not say which one happens (Not stated). The demo tried both, and in an Express workflow the trace continued without traceHeader (Observed, Section 8.5).If you provide the
traceHeader yourself, take Root and Sampled from _X_AMZN_TRACE_ID and put them in the page's format.import json
import os
import boto3
sfn = boto3.client("stepfunctions")
def start_with_trace(state_machine_arn, payload):
kwargs = {"stateMachineArn": state_machine_arn, "input": json.dumps(payload)}
header = os.environ.get("_X_AMZN_TRACE_ID", "")
parts = dict(p.split("=", 1) for p in header.split(";") if "=" in p)
if "Root" in parts:
# The documented format is Root={TRACE_ID};Sampled={1 or 0}.
kwargs["traceHeader"] = "Root=%s;Sampled=%s" % (parts["Root"], parts.get("Sampled", "0"))
return sfn.start_execution(**kwargs)
5.2 Step Functions Limits and Distributed Map
The Step Functions developer guide states that, in addition to the X-Ray limits, state machines have a minimum trace size guarantee of 100 KiB. Sending more than 100 KiB of trace data to X-Ray can freeze the trace (Stated).About Distributed Map, the page says the following (Stated).
Step Functions doesn't support X-Ray tracing for the child workflow executions started by a Distributed Map state because it's easy to exceed the Trace document size limit for such executions.
Child workflow executions started by a Distributed Map state are not supported for X-Ray tracing. This is because it is easy to exceed the limit for the trace document size.
5.3 Lambda Active and PassThrough
Lambda's tracing modes areActive and PassThrough. With Active, Lambda creates segments for each invocation and sends them to X-Ray. With PassThrough, it simply passes the context downstream (Stated).If
Active is not turned on, the default is PassThrough. The page describes PassThrough as follows (Stated).
In PassThrough mode, Lambda forwards the X-Ray tracing header to downstream services, but does not send traces automatically. This is true even if the tracing header contains a decision to sample the request. If the upstream service does not provide an X-Ray tracing header, Lambda generates a header and makes the decision not to sample.
A
PassThrough function forwards the upstream header downstream, but does not send its own trace, even if the header contains a sampling decision. If the upstream service does not provide a header, Lambda creates a header and includes a decision not to sample. So past a PassThrough function, the trace continues the upstream trace if there is one, and is a new trace with Sampled=0 if there is none (Inference).The sampling rate for
Active mode is one request per second plus 5% of additional requests, and cannot be modified on a per-function basis (Stated). If the upstream service includes a sampling decision in the header, Lambda follows that decision (Stated).5.4 Asynchronous Invocation and Destinations
The Lambda developer guide page on capturing records of asynchronous invocations says the following about destinations (Stated).When you activate X-Ray tracing for a function or a service that invokes a function, Lambda adds an X-Ray header to the request and passes the header to the destination service. Traces from upstream services are automatically linked to traces from downstream Lambda Event Functions and destination services, creating an end-to-end view of the entire application.
In an asynchronous invocation, Lambda adds an X-Ray header to the request and passes it to the destination service. Upstream traces are automatically linked to the traces of the downstream function and destination service. The page's word is "linked," not "continues." In the Chapter 8 demo, the function invoked asynchronously continued the same trace as the origin, and no link was returned (Observed, Section 8.5).
5.5 Event Source Mappings
The Lambda X-Ray page says the following about event source mappings (Stated).X-Ray tracing is currently not supported for Lambda Event Functions with Amazon Managed Streaming for Apache Kafka (Amazon MSK), self-managed Apache Kafka, Amazon MQ with ActiveMQ and RabbitMQ, or Amazon DocumentDB event source mappings.
Event source mappings for MSK, self-managed Apache Kafka, Amazon MQ (ActiveMQ and RabbitMQ), and DocumentDB are not supported for X-Ray tracing.
Whether event source mappings for Kinesis Data Streams and DynamoDB Streams carry the context is not described on the pages this article read (Not stated). These two are not listed among the unsupported services. They also do not appear on the list of AWS services that integrate with X-Ray in the X-Ray developer guide. After searching six times with different terms, this article places the two under not stated. It does not say they are unsupported.
For the SQS event source mapping, the pages describe a link, as covered in Section 3.2.
5.6 Headers the AWS SDK Adds Inside Lambda
The page on Lambda recursive loop detection describes the mechanism as follows (Stated).To detect recursive loops, Lambda uses AWS X-Ray tracing headers.
Events that Lambda receives from supported services carry metadata. When a function uses a supported version of the AWS SDK to write that event to another service, the SDK updates the metadata. The page states that enabling active tracing in X-Ray is not required for this functionality. The table of minimum SDK versions lists boto3 1.24.46 for Python (Stated).
The source of the AWS SDK for Python (botocore) has a step that, inside the Lambda execution environment, adds the value of
_X_AMZN_TRACE_ID as an X-Amzn-Trace-Id HTTP header when that variable is set and the request has no X-Amzn-Trace-Id yet (Inference, from the SDK source). This means that even in Lambda functions that do not include the X-Ray SDK, if the function calls AWS services like SQS or Step Functions, HTTP headers may be added. The pages do not say whether the SQS page's Default HTTP Header and the header precedence in the Step Functions API reference (Section 5.1) also apply in this case (Not stated). The demo's *-sdk cases tested this combination: for SQS, the sender's Root was in AWSTraceHeader, and for EventBridge classic and Step Functions, the trace continued (Observed, Section 8.5).5.7 Web Functions and Managed Instances
The page on monitoring Lambda Web Functions says the following (Stated).Lambda does not add a trace header to requests that do not include one, and Web Functions do not create Lambda service segments.
If a request has an
X-Amzn-Trace-Id header, Web Functions pass it to the function as is. If the header is not present, Lambda will not add a header and will not create Lambda service segments. The page says the header is added by the caller, so the value should be treated as client input (Stated). A Web Functions trace connects to the upstream only when the caller adds the header, and the trace data is sent from the code directly to X-Ray (Inference).The pages describing the Java, Node.js, .NET, and Rust runtimes for Lambda Managed Instances state that Managed Instances do not support the
_X_AMZN_TRACE_ID environment variable. You read the trace ID from the context passed to the handler, and with the AWS SDK the trace ID is propagated automatically (Stated). The Node.js and .NET pages call reading from the context concurrency-safe (Stated). The Python runtime page states that with Python you can read the trace ID from the _X_AMZN_TRACE_ID environment variable on Managed Instances as well, and that concurrent requests are processed one at a time, each in a separate process (Stated). This article reads this as follows: in the other four runtimes, a single process handles multiple requests at the same time, so a per-request value cannot live in an environment variable (Inference).The code examples in Sections 3.1, 4.2, and 5.1 are written in Python, so they can read the trace ID as written on Managed Instances. When you write them in another language, read the trace ID from the context instead (Inference).
6. A Table by Boundary
This chapter consolidates the descriptions of pages from Chapters 2 through 5 into a single table, organized by boundary. The In this demo column holds the results of the Chapter 8 demo.6.1 Figure 1: What Carries the Context at Each Boundary

6.2 Table 1: What the Pages Say, by Boundary
| # | Boundary | Carrier | What the pages say | Category | In this demo |
|---|---|---|---|---|---|
| 1 | Sender → SQS | X-Amzn-Trace-Id, AWSTraceHeader | If both exist, AWSTraceHeader takes precedence. Value is in X-Ray format. | — | Even with no argument (SDK header only), the AWSTraceHeader the consumer received contained the sender's Root. |
| 2 | SQS → Lambda (event source mapping) | AWSTraceHeader | A statement that an X-Ray SDK sender can continue with the same trace ID, and a statement that Lambda consumers are linked automatically | Linked (the page has two statements) | A separate trace; X-Ray returned the two traces as links to each other. |
| 3 | SQS → Consumer other than Lambda | AWSTraceHeader | Read using ReceiveMessage and manually restore context. | Continues if the consumer restores it. | — |
| 4 | SNS → Subscription (Firehose, Lambda, SQS, HTTP/S) | Not stated | Context is passed from the publisher to the subscriber. Handling per subscription type is not described | Continues (not stated per type) | The Lambda subscription stayed in the same trace. The Lambda behind an SQS subscription was in a separate trace, linked. |
| 5 | PutEvents → EventBridge classic → Target | X-Amzn-Trace-Id, TraceHeader | Only when PutEvents passes context. TraceHeader takes precedence. | Continues (conditionally) | Same trace with no argument (SDK header only) and with TraceHeader. New trace with neither header nor argument. |
| 6 | Partner, Schedule, AWS Service Events | — | X-Ray does not track. | Breaks | — |
| 7 | Body of events reaching EventBridge classic target | — | No trace headers in the body. | Not in the body | No trace keys in the body. |
| 8 | EventBridge classic archive → replay | — | Not included in either archive or replay. | Breaks | Replayed events were in a new trace; no link. |
| 9 | EventBridge classic → DLQ | SQS message attributes | Attributes are included; not in the body. | Attributes remain. | — |
| 10 | New Custom event bus → SQS target | MessageSystemAttributes (written by the user) | Only describes the field; does not say where the value comes from. | Not stated | Both the Subscriber that wrote the field and the one that wrote nothing got the publisher's header in AWSTraceHeader. The consumer was in a separate trace, linked. |
| 11 | New Custom event bus → Step Functions target | TraceHeader (written by the user) | Only describes the field. | Not stated | — |
| 12 | New Custom event bus → Lambda, SNS, HTTP target | — | No trace fields. | Not stated | The Lambda target was in the same trace as the publisher. (SNS and HTTP are untested.) |
| 13 | API Gateway HTTP API → Step Functions | X-Amzn-Trace-Id | Automatic. | Continues | — |
| 14 | Lambda, SDK → Step Functions | traceHeader, X-Amzn-Trace-Id | User must pass traceHeader. If both exist, the header takes precedence. | Continues (when passed) | Same trace if traceHeader is not present (only SDK headers). A new trace is created if there are no headers or arguments. |
| 15 | Step Functions Distributed Map → Child Execution | — | X-Ray tracing is not supported. | Breaks | — |
| 16 | Lambda Asynchronous Invocation → Function → Destination | X-Ray headers | Automatically linked. | Linked | The function is on the same trace. No link. The AWSTraceHeader of the destination SQS includes the Root from the origin. |
| 17 | Lambda (PassThrough) → Downstream | _X_AMZN_TRACE_ID | Passes the upstream header. If there is no upstream, creates a header with a decision not to sample. | Continues if there is an upstream (not recorded). New trace if there is none. | With an upstream, the same Root as the upstream with Sampled=1; without one, a new Root with Sampled=0. In neither case was the function's segment in X-Ray. |
| 18 | MSK, Self-Managed Kafka, Amazon MQ, DocumentDB → Lambda | — | X-Ray tracing is not supported. | Breaks | — |
| 19 | Kinesis, DynamoDB Streams → Lambda | — | Not described on the pages this article read. | Not stated | — |
| 20 | Caller → Lambda Web Functions | X-Amzn-Trace-Id (only when the caller adds it) | Lambda does not add headers and does not create service segments. | Depends on the caller. | — |
| 21 | Inside Lambda Managed Instances → AWS SDK call | Context trace ID | Environment variables cannot be used (except for Python). Automatically propagated if using the AWS SDK. | Continues (if using SDK) | — |
The Category column is what this article assigned from the page text, using the four terms in Section 1.5. Rows that fit none of the four (the sender-side field, the event body, the DLQ, and the row decided by the caller) get a short description instead. Rows where a page says
linked are linked, rows where a page says the context is not carried are breaks, and rows the pages do not describe are not stated.There are three points to note when reading the table:
- Even in continues rows, a request that sampling does not record does not appear in a trace. Sampling for Lambda
Activecannot be changed per function (see Section 5.3). - Even in breaks rows, if you put your own correlation ID in business events, you can still join the logs. Correlation ID design is left to Event-Driven Serverless Architecture on AWS (see Section 1.2).
- A not stated row does not mean the context is not propagated. The demo results are one record from that environment and period (Chapter 8).
7. When You Switch to OpenTelemetry
This chapter describes how the handling of boundaries changes when you switch from the X-Ray SDK to OpenTelemetry for instrumentation. The configuration code is left to the articles listed in Section 1.2.7.1 W3C Trace Context and the X-Ray Propagator
The X-Ray developer guide page on migrating to OpenTelemetry lists W3C Trace Context (default), X-Ray trace headers, and other custom formats as header formats supported by OpenTelemetry. It then says the following (Stated).You can configure OpenTelemetry to use one or more header formats. For example, use the X-Ray Propagator to send trace context to AWS services that support X-Ray tracing.
By default, OpenTelemetry carries context in the W3C Trace Context
traceparent header. The page says that to send context to AWS services, you configure the X-Ray propagator. Every carrier described on the AWS pages this article read uses the X-Ray format (Section 2.2, Inference).The SQS
AWSTraceHeader must be a string in the X-Ray trace header format (Section 3.1, Stated). So if a sender instrumented with OpenTelemetry puts a value in AWSTraceHeader, it has to convert the W3C traceparent string to the X-Ray format rather than putting the traceparent string in as is (Inference).7.2 W3C Trace IDs and X-Ray Trace IDs
X-Ray accepts trace IDs generated by systems that adhere to the W3C Trace Context, such as OpenTelemetry. The X-Ray developer guide, on the page describing how to send trace data to X-Ray, states that you reformat a W3C trace ID into the X-Ray trace ID format when you send it to X-Ray, and gives the following example (Stated).For example, W3C trace ID4efaaf4d1e8720b39541901950019ee5should be formatted as1-4efaaf4d-1e8720b39541901950019ee5when sending to X-Ray. X-Ray trace IDs include the original request time stamp in Unix epoch time, but this isn't required when sending W3C trace IDs in X-Ray format.
Split the 32-digit W3C trace ID into the first 8 digits and the remaining 24, and put the format version
1- in front. In an X-Ray trace ID, the second field holds the original request time in Unix epoch. The page says that when you send a W3C trace ID in X-Ray format, the first 8 digits do not have to be a time.7.3 Trace Size Limits
Traces that span boundaries grow in size as segments are added. The X-Ray limits in the AWS General Reference are as follows (Stated).| Item | Value |
|---|---|
| Segment document size | 64 Kilobytes |
| Trace document size (dynamic upper limit) | 500 Kilobytes |
| Trace document size (lower limit) | 100 Kilobytes |
Other size limits described on the pages this article read are as follows (Stated).
- SQS and Lambda links: 20 from one segment, and 100 in one trace (Section 3.4).
- Step Functions state machine traces: A minimum guaranteed size of 100 KiB (Section 5.2).
- SNS: Topics with a large number of subscriptions may reach the limit (Section 4.1).
- CloudWatch Transaction Search: According to the CloudWatch user guide, Transaction Search captures all spans as structured logs, allowing users to view large traces containing up to 10,000 spans.
Transaction Search is a CloudWatch feature that you turn on for the account. This article does not cover its configuration, and the demo ran in an account without Transaction Search turned on.
8. What the Demo Confirmed
This chapter checks, with a demo run in us-east-1, the boundaries that the page text alone does not settle. The results here are one record from this environment at this time, and carry the Observed label.8.1 Setup
The demo is a single AWS SAM stack. All Lambda functions used the Python 3.14 runtime on arm64 withActive tracing turned on, except the one that tests PassThrough. The functions included neither the X-Ray SDK nor OpenTelemetry; they called AWS only through the AWS SDK for Python (boto3) in the runtime. Only the function that publishes to the new Custom event bus was deployed with a version of boto3 that includes the eventbridgev2 client.The origin function,
ingress, was invoked from the AWS CLI. ingress then called one service across the boundary. v2 (the function that publishes to the new bus) and pt-direct (the PassThrough function) were each invoked directly from the CLI. Every downstream function logged a single line of JSON containing the received _X_AMZN_TRACE_ID, the SQS AWSTraceHeader, and any trace-like keys in the event body.| Name | Boundary | What changed |
|---|---|---|
sqs-sdk, sqs-attr, sqs-none | Lambda → SQS → Lambda | No arguments (only SDK header) / Pass AWSTraceHeader / No header, no arguments |
eb-sdk, eb-param, eb-none | Lambda → EventBridge classic → Lambda | No arguments / Pass TraceHeader / No header, no arguments |
sfn-via-eb | Lambda → EventBridge classic → Step Functions Express → Lambda | — |
sfn-sdk, sfn-param, sfn-none | Lambda → Step Functions Express → Lambda | No arguments / Pass traceHeader / No header, no arguments |
sns | Lambda → SNS → Lambda, SNS → SQS → Lambda | Active tracing on for the topic |
async | Lambda → Asynchronous invocation → Lambda → destination (SQS) | — |
pt-sync, pt-direct | Lambda (PassThrough) | Upstream Lambda is Active / No upstream (directly from CLI) |
v2 | Lambda → New Custom event bus → 2 SQS queues and Lambda | Subscriber that sets AWSTraceHeader with a JSONata expression / Subscriber that sets nothing / Lambda target |
| Replay | EventBridge classic archive → Replay → Lambda | Replay eb-* events |
For the no-header, no-argument cases,
_X_AMZN_TRACE_ID was removed from the environment only for the duration of the call. As noted in Section 5.6, the AWS SDK uses this environment variable to add HTTP headers, so removing it prevents those headers from being added (Inference).The scenarios ran 2 seconds apart, in three rounds. Because Lambda sampling is one request per second plus 5% (as described in Section 5.3), there may be invocations that are not recorded, even with the intervals.
8.2 How the Records Were Taken
The results were read from three sources.- A single line of JSON from the logs of each function (containing
_X_AMZN_TRACE_IDwith values ofRootandSampled, the receivedAWSTraceHeader, and trace-like keys in the body). - The
AWSTraceHeaderfrom messages received by the destination SQS queue. - The response from X-Ray's
BatchGetTracesfor all trace IDs recorded, including theoriginof each segment and thelinkswithin each segment's document.
In this article, trace IDs keep only the leading
1-xxxxxxxx- and the last four digits. Account IDs are masked.8.3 Table 2: Trace IDs at Each Boundary
Table 2 is the first record. The second and third records showed the same pattern for every scenario (Observed).Sampled was 1 everywhere except pt-direct.| Scenario | Origin trace | Downstream trace | Same trace? | X-Ray links | AWSTraceHeader received downstream |
|---|---|---|---|---|---|
sqs-sdk | 1-6b10de79-…b81f | 1-6b10de7a-…fd33 | Different | Linked to each other | Origin's Root |
sqs-attr | 1-6b10de7d-…2a1b | 1-6b10de7d-…7f76 | Different | Linked to each other | Origin's Root |
sqs-none | 1-6b10de80-…9dda | 1-6b10de80-…d254 | Different | None | None |
eb-sdk | 1-6b10de83-…66c2 | 1-6b10de83-…66c2 | Same | — | — |
eb-param | 1-6b10de86-…2c40 | 1-6b10de86-…2c40 | Same | — | — |
eb-none | 1-6b10de89-…23d4 | 1-6b10de89-…d745 | Different | None | — |
Replay (eb-*) | — | 1-6b10dfc9-…623b and others, 5 in total | Different | None | — |
sfn-via-eb | 1-6b10de8c-…9a65 | 1-6b10de8c-…9a65 | Same | — | — |
sfn-sdk | 1-6b10de8f-…82a0 | 1-6b10de8f-…82a0 | Same | — | — |
sfn-param | 1-6b10de92-…3d9a | 1-6b10de92-…3d9a | Same | — | — |
sfn-none | 1-6b10de95-…64f7 | 1-6b10de95-…c134 | Different | None | — |
sns (Lambda subscription) | 1-6b10de98-…7ac8 | 1-6b10de98-…7ac8 | Same | — | — |
sns (SQS subscription → Lambda) | 1-6b10de98-…7ac8 | 1-6b10de98-…12aa | Different | Linked to each other | Origin's Root |
async | 1-6b10de9b-…cd76 | 1-6b10de9b-…cd76 | Same | None | (In the destination SQS) origin's Root |
pt-sync | 1-6b10de9e-…57fc | 1-6b10de9e-…57fc | Same Root | — | — |
pt-direct | (Directly from CLI) | 1-6b10dea2-…1ff5 (Sampled=0) | — | — | — |
v2 (Lambda target) | 1-6b10dea4-…ac4b | 1-6b10dea4-…ac4b | Same | — | — |
v2 (SQS, Subscriber that writes the field) | 1-6b10dea4-…ac4b | 1-6b10dea7-…4c9b | Different | Linked to each other | Origin's Root |
v2 (SQS, Subscriber that writes nothing) | 1-6b10dea4-…ac4b | 1-6b10dea7-…2406 | Different | Linked to each other | Origin's Root |
The Same trace? column shows whether the
Root of the downstream function's _X_AMZN_TRACE_ID matches the origin. The X-Ray links column is the links in the segment documents that BatchGetTraces returned. In Same rows, the single trace that X-Ray returned contained the segments of both the origin function and the downstream function. For rows related to Step Functions, the state machine's segments were also in the same trace.8.4 Figure 2: Trace IDs Observed on the Demo Paths

8.5 Checking the Results Against the Pages
SQS → Lambda (Section 3.2): In all three runs, the downstream Lambda was in a separate trace, and X-Ray returned the two traces as links to each other (Observed). Of the SQS page's two statements, this matches the one about linking for Lambda consumers. Insqs-sdk, AWSTraceHeader was not passed, yet the messages the consumer received had AWSTraceHeader, and its Root and Parent matched the sender's _X_AMZN_TRACE_ID (Observed). The page's Default HTTP Header has the X-Ray SDK as its subject, but in this demo the HTTP header of the AWS SDK without the X-Ray SDK (Section 5.6) did the same job (Inference). The statement that a sender instrumented with the X-Ray SDK can continue with the same trace ID was not tested in this demo.EventBridge classic (Sections 4.2 and 4.3): Even without passing
TraceHeader, the target Lambda function continued the same trace. In calls with _X_AMZN_TRACE_ID removed, the target was in a new trace, with no link. In all cases, the body of the event received by the target did not contain any tracing keys (Observed). This aligns with two statements on the page: that the header is passed only when PutEvents passes the context, and that the body of the event received by the target has no header. The traces returned by X-Ray did not include any EventBridge nodes.Archive and replay (Section 4.3): The target of every replayed event was in a new trace, with no link. This held even for original events that had been sent with
TraceHeader (Observed). This matches the page statement that replay does not include the header. Of the nine eb-* events, five were replayed. The replay step started replaying as soon as the archive's event count was no longer zero, so some events may not yet have been in the archive (Inference).Step Functions (Sections 5.1 and 5.6): Even in
sfn-sdk, which does not pass traceHeader, the state machine and the downstream Lambda continued the same trace as the origin. In sfn-none, with _X_AMZN_TRACE_ID removed, a new trace began (Observed). The developer guide states that if calling from Lambda, you should configure it yourself, but in this demo (an Express workflow), the HTTP header that the AWS SDK adds was enough for the trace to continue. This matches the API reference statement that the header takes precedence over the body. Similarly, sfn-via-eb, which was started from an EventBridge classic rule, also continued the same trace.SNS (Section 4.1): The Lambda subscription continued the same trace. With the SQS subscription, the origin's trace contained the SNS topic and SQS queue nodes, and the Lambda beyond the queue was in a separate trace, linked (Observed). When SNS leads to SQS, the result took the same form as the SQS → Lambda boundary (Section 3.2).
Asynchronous invocation and destinations (Section 5.4): The function invoked asynchronously continued the same trace as the origin, with no link. The
AWSTraceHeader in the destination's SQS message also had the same Root as the origin (Observed). The page says the traces are linked automatically, but in this demo the function step was not a link; it was inside the same trace. The destination queue was read from the CLI, so there is no trace beyond it.PassThrough (Section 5.3):
pt-sync, invoked synchronously from an Active function, received the same Root and Sampled=1 as the upstream, and its Parent was also the upstream header's value. The pt-direct function, invoked directly from the CLI, received a new Root with Sampled=0 (Observed). In both cases, the PassThrough function's segment was not visible in X-Ray, and BatchGetTraces returned no traces for pt-direct. This matches the page statement that PassThrough does not send traces and, with no upstream, creates a header with a decision not to sample.New Custom event bus (Section 4.4): The Lambda target, which has no trace field, continued the same trace as the publisher. For the SQS targets, both the Subscriber that wrote
MessageSystemAttributes and the one that wrote nothing got, in AWSTraceHeader, the same string as the publisher's _X_AMZN_TRACE_ID (identical down to Root, Parent, and Lineage), and the consumers were in a separate trace, linked (Observed). The publisher's PutEvents entries have no trace field, so the new bus can be read as having carried the HTTP header of the PutEvents call (Inference). The value written in the field and the value the bus inserted were the same, so this demo cannot tell whether the field value takes precedence over the bus value. The traces that X-Ray returned had no EventBridge nodes.Lineage (Section 2.1): The SQS AWSTraceHeader carried the sender's Lineage as is. In the downstream functions' _X_AMZN_TRACE_ID, the first number of Lineage went from 1 to 2 (Observed). This can be read as the count that recursive loop detection uses, but the page says not to use Lineage directly (Section 2.1).8.6 Where These Results Do Not Generalize
These results are one record under the following conditions.- The Region was us-east-1, and the date of execution was December 3, 2026.
- The Lambda runtime was Python 3.14, arm64. The origin function used boto3 1.42.97 from the runtime, and the function that published to the new bus used boto3 1.44.18. No AWS SDK for another language was tested, nor any SDK older than the minimum version in Section 5.6.
- Neither the X-Ray SDK nor OpenTelemetry was used. How a sender instrumented with the X-Ray SDK behaves is outside the scope of this demo.
- Only Express workflows (Step Functions), standard queues (SQS), and standard topics (SNS) were tested.
- Apart from
pt-direct, no call went unrecorded by Lambda sampling. That is because calls were spaced 2 seconds apart; under heavy load, unrecorded requests will occur (Inference). - The demo ran in an account where Transaction Search was turned off.
- Behavior that the AWS pages do not describe can change without notice. In particular, two things are observations, not page statements: that a boundary the pages call a link continued the same trace (Lambda asynchronous invocation), and that the new bus carried the context to a target that has no field for it.
9. Frequently Asked Questions About Trace Propagation
Q1. Does a single trace continue from SQS to Lambda?The pages say it two ways. The X-Ray SQS page says that if a service instrumented with the X-Ray SDK is the sender, the original trace can continue to the consumer with the same trace ID. The same page and the Lambda page say that the upstream sender's trace is automatically linked to the downstream Lambda consumer's trace. This article does not describe this boundary as a single trace continuing. In this demo, all three runs produced a separate trace, and X-Ray returned the two traces as links to each other (Section 8.5).
Q2. Does EventBridge propagate traces?
The classic bus passes the trace header to the target only when the
PutEvents request passed the trace context. Events from partners, schedules, and AWS services are not traced. The event body that reaches the target has no header, and archives and replays do not include it either. On the new Custom event bus, the user writes values in MessageSystemAttributes for SQS targets and TraceHeader for Step Functions targets. The pages do not say where the values come from. In this demo, an SQS Subscriber that did not write the field also got AWSTraceHeader, and the Lambda target continued the same trace (Section 8.5).Q3. When a Lambda function initiates a Step Functions execution, does the trace continue?
The Step Functions developer guide states that if you start from a Lambda function or the SDK, you must manually set the
traceHeader. The format is Root={TRACE_ID};Sampled={1 or 0}. The API reference states that if both the HTTP header X-Amzn-Trace-Id and the body's traceHeader are present, Step Functions uses the header. The pages do not say whether the trace continues when the AWS SDK inside Lambda adds the header. In this demo (an Express workflow and Python boto3), the trace continued without traceHeader, and removing _X_AMZN_TRACE_ID gave a new trace (Section 8.5).Q4. Do event source mappings for Kinesis or DynamoDB Streams support X-Ray tracing?
The pages this article read describe neither. The Lambda X-Ray page names four as unsupported: MSK, self-managed Apache Kafka, Amazon MQ (ActiveMQ and RabbitMQ), and DocumentDB. Kinesis and DynamoDB Streams appear neither in that list nor in the list of services that integrate with X-Ray. This article places the two under not stated, not under unsupported.
Q5. What should a sender instrumented with OpenTelemetry put into SQS's
AWSTraceHeader?The
SendMessage API reference states that the value for AWSTraceHeader must be a correctly formatted X-Ray trace header string. OpenTelemetry's default propagation is W3C Trace Context, so this article reads it as needing conversion to the X-Ray format. The X-Ray page says to use the X-Ray propagator to send context to AWS services. To put a W3C trace ID in X-Ray format, add 1- in front and split it into 8 and 24 digits.Q6. What happens when traces become too large?
An X-Ray segment document is limited to 64 KB, and a trace document to 500 KB (dynamic upper limit) and 100 KB (lower limit). SQS and Lambda links are limited to 20 links per segment and 100 links per trace. Exceeding them can leave the trace incomplete. Step Functions state machines have a guaranteed minimum trace size of 100 KiB, and going past it can freeze the trace. Child executions in Distributed Map do not support X-Ray tracing for this reason. An SNS topic with many subscriptions may also not be traced in full.
10. Summary
- Trace context is three things: the trace ID, the parent segment ID, and the sampling decision. What carries it differs by boundary. HTTP headers and API arguments carry it for one call only, while SQS system attributes stay with the message.
- When multiple carriers are present, both SQS and EventBridge classic prioritize the API field, while Step Functions prioritizes HTTP headers.
- The SQS page has two statements: the trace can continue with the same trace ID from an X-Ray SDK sender, and it is automatically linked for Lambda consumers. Consumers other than Lambda read
AWSTraceHeaderand restore the context themselves. - EventBridge classic passes the header only when
PutEventspassed the context. The target's event body, archives, and replays have no header. On the new Custom event bus, the user writes the value in the fields of SQS and Step Functions targets. - According to the developer guide, Step Functions requires developers to manually pass the
traceHeaderwhen starting from Lambda or the SDK. The Lambda pages say that asynchronous Lambda invocations and destinations are automatically linked. - Event source mappings for MSK, self-managed Kafka, Amazon MQ, and DocumentDB do not support X-Ray. Kinesis and DynamoDB Streams are not stated on the pages.
- In OpenTelemetry, the X-Ray propagator sends context to AWS services. SQS requires
AWSTraceHeaderto be in X-Ray format. - In the us-east-1 demo, AWS SDK calls without the X-Ray SDK kept the same trace through EventBridge classic, Step Functions, SNS subscriptions to Lambda, asynchronous Lambda invocations, and Lambda targets on the new Custom event bus. Lambda functions downstream of SQS were linked, while replays and invocations without context created new traces.
- This article is based on documents read on December 3, 2026, and a us-east-1 demo from the same period. That falls during re:Invent 2026, and the pages may change.
11. References
- AWS X-Ray concepts - AWS X-Ray
- Sending trace data to AWS X-Ray - AWS X-Ray
- Amazon SQS and AWS X-Ray - AWS X-Ray
- Tracing event-driven applications - AWS X-Ray
- Amazon SNS and AWS X-Ray - AWS X-Ray
- Migrating from X-Ray instrumentation to OpenTelemetry instrumentation - AWS X-Ray
- X-Ray SDK and Daemon Support timeline - AWS X-Ray
- Integrating AWS X-Ray with other AWS services - AWS X-Ray
- AWS X-Ray endpoints and quotas - AWS General Reference
- SendMessage - Amazon Simple Queue Service
- ReceiveMessage - Amazon Simple Queue Service
- Active tracing in Amazon SNS - Amazon Simple Notification Service
- Amazon EventBridge integration with AWS X-Ray - Amazon EventBridge
- Amazon SQS queue target - Amazon EventBridge
- Step Functions state machine target - Amazon EventBridge
- Observability for the Custom Event Bus: metrics, logs, and CloudTrail - Amazon EventBridge
- Migrating from Custom Event Bus - Classic to the Custom Event Bus - Amazon EventBridge
- put-events - AWS CLI Command Reference
- Amazon EventBridge relaunches event buses for enterprise scale - AWS What's New
- Trace Step Functions request data in AWS X-Ray - AWS Step Functions
- StartExecution - AWS Step Functions
- Visualize Lambda Event Function invocations using AWS X-Ray - AWS Lambda
- Capturing records of Lambda asynchronous invocations - AWS Lambda
- Use Lambda recursive loop detection to prevent infinite loops - AWS Lambda
- Monitoring Lambda Web Functions - AWS Lambda
- Node.js runtime for Lambda Managed Instances - AWS Lambda
- Java runtime for Lambda Managed Instances - AWS Lambda
- .NET runtime for Lambda Managed Instances - AWS Lambda
- Rust support for Lambda Managed Instances - AWS Lambda
- Python runtime for Lambda Managed Instances - AWS Lambda
- Transaction Search - Amazon CloudWatch
References:
Tech Blog with curated related content
Written by Hidekazu Konishi