Skip to content

How is the trace ID set when invoking Bedrock AgentCore harness from a Step Function

0

I'm playing around with the new support for invoking a Bedrock AgentCore managed harness directly from Step Functions. I am setting the session ID for each invocation to Step Function 's "states.context.Execution.Name" so it seems like it should be unique. However for some reason every invocation seems to be sending traces with the same trace ID. So as I check the CloudWatch GenAI observability of each harness invocation, I get a single ever expanding trace that includes traces from all separate invocations. I haven't found any information online on how the trace ID is set. Does anyone know how the trace ID is set, and if it can be changed?

For reference the whole Step Function is triggered by EventBridge in response to an S3 file upload. Could it be that something needs to be enabled here to set up a fresh trace ID for each step function invocation?

2 Answers
2

In addition to the other answer .... , there is a architectural reason for this behavior. The Trace ID in "CloudWatch GenAI Observability" is not generated by Bedrock in isolation; it is inherited from the standard AWS X-Ray trace context (specifically the X-Amzn-Trace-Id header) passed by the calling service.

Because your execution chain starts upstream (S3 -> EventBridge -> Step Functions -> Bedrock), the trace context is being propagated through the events. If tracing is not explicitly configured to generate a new context per execution, downstream services like Bedrock will fall back to grouping invocations under an incomplete, default, or reused trace context.

To resolve this and force a unique Trace ID for every single Bedrock invocation, you must enable Active Tracing (AWS X-Ray) directly on your Step Functions State Machine.

When Active Tracing is enabled, Step Functions acts as the trace generator. It automatically creates a strictly unique X-Amzn-Trace-Id for every distinct state machine execution and propagates it to all supported AWS service integrations, including Amazon Bedrock. Bedrock's GenAI Observability will consume this inherited ID and correctly split the traces per execution.

You can verify the requirements and behavior for Step Functions trace propagation in the official AWS documentation here: https://docs.aws.amazon.com/step-functions/latest/dg/concepts-xray-tracing.html

EXPERT

answered a month ago

0

Based on the available documentation, the trace ID in Amazon Bedrock AgentCore is automatically generated by the system and is not directly configurable by users. The trace ID serves as a unique identifier for grouping related trace events together.

While you can access and use the runtime session ID in your agent code (either through context.session_id in the Bedrock AgentCore SDK or via the X-Amzn-Bedrock-AgentCore-Runtime-Session-Id HTTP header for custom runtime servers), the trace ID itself is a separate system-generated identifier that's managed internally.

The behavior you're experiencing - where multiple invocations appear to share the same trace ID - suggests that the trace ID may be tied to something other than the individual invocation or session. Unfortunately, the current documentation doesn't provide details on the specific logic used to generate or assign trace IDs, nor does it offer a way to manually set or override them.

For your use case where you want to track separate Step Functions invocations independently in CloudWatch GenAI observability, you might consider using the session ID you're already setting (based on the execution name) as a correlation mechanism in your own logging and monitoring, even though it won't change how traces are grouped in the native observability interface.

If you need more specific guidance on trace ID behavior or potential workarounds for your observability requirements, I'd recommend reaching out through the AWS Support Center at https://console.aws.amazon.com/support/ where the support team can investigate your specific setup and potentially provide more detailed information about trace ID assignment logic.
Sources
Troubleshoot AgentCore Runtime - Amazon Bedrock AgentCore

answered a month ago

EXPERT

reviewed a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.