Set Up Amazon Bedrock AgentCore Monitoring
This guide connects an agent on Amazon Bedrock AgentCore Runtime to Dash0 in five steps. Step 1 is enough to trace the agent itself. Steps 2 to 5 add the spans and logs AWS records inside AgentCore Gateway, Memory, and your Lambda tool targets, and the AgentCore CloudWatch metrics.
For a complete, deployable example, see the AgentCore Dash0 observability sample in the awslabs/agentcore-samples repository.
Prerequisites
- An agent deployed to AgentCore Runtime , written in Python with the OpenTelemetry SDK and an agent framework that emits spans, such as Strands Agents .
- A Dash0 auth token with ingest permission for the target dataset.
- The OTLP via HTTP endpoint for your Dash0 region, from Settings → Endpoints .
- For step 5, an AWS account connected to Dash0 through the AWS integration.
Step 1: Send Agent Telemetry to Dash0
AgentCore Runtime configures the AWS Distro for OpenTelemetry (ADOT) for your agent by default, which sends telemetry to CloudWatch. To send it to Dash0 instead, turn that off and configure the OpenTelemetry exporter with the standard environment variables.
Set these environment variables on your agent runtime:
| Variable | Value |
|---|---|
DISABLE_ADOT_OBSERVABILITY | true |
OTEL_EXPORTER_OTLP_ENDPOINT | Your Dash0 OTLP via HTTP endpoint, for example https://ingress.us-west-2.aws.dash0.com |
OTEL_EXPORTER_OTLP_PROTOCOL | http/protobuf |
OTEL_EXPORTER_OTLP_HEADERS | Authorization=Bearer%20<token>,Dash0-Dataset=<dataset> |
OTEL_SERVICE_NAME | The service name to show in Dash0, for example travel-agent |
The %20 encodes the space between Bearer and the token. Pass the variables in environmentVariables when you call CreateAgentRuntime or UpdateAgentRuntime.
Then set up the OpenTelemetry SDK at the top of your agent's entry point, before you import the agent framework. The exporters read the endpoint and headers from the environment, and Resource.create() reads OTEL_SERVICE_NAME:
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
provider = TracerProvider(resource=Resource.create())
provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter()))
trace.set_tracer_provider(provider)Add the opentelemetry-sdk and opentelemetry-exporter-otlp-proto-http packages to your agent's dependencies. Configure a MeterProvider and a LoggerProvider the same way to send metrics and logs. The sample linked above shows all three.
Wrap each invocation in one span, for example with tracer.start_as_current_span("invoke") inside your @app.entrypoint handler. Every model call, tool call, and Memory call of that invocation then belongs to the same trace.
Invoke your agent, then open Tracing in Dash0 and filter by your service name. Each invocation shows the agent run, its chat spans for model calls, and its execute_tool spans for tool calls.
Step 2: Turn On Tracing for Gateway and Memory
AgentCore records spans inside Gateway and Memory through AWS X-Ray. These spans show work your agent can't see, such as Gateway authorization, tool routing, and Memory retrieval.
Turn On CloudWatch Transaction Search
AgentCore requires CloudWatch Transaction Search , which stores X-Ray spans in the aws/spans log group. Transaction Search is a per-region setting for your whole AWS account.
Follow Enable CloudWatch Transaction Search in the AWS documentation. It takes up to 10 minutes before spans appear in aws/spans.
Turn On Tracing for Each Resource
In the AgentCore console , open each Memory and each Gateway your agent uses. On the Configuration tab, in the Tracing pane, choose Edit, turn tracing on, and choose Save. To do the same with an AWS SDK, create a TRACES delivery source for the resource and deliver it to an XRAY delivery destination, as shown in Configure CloudWatch resources using an AWS SDK .
Pass the Trace Context to Gateway and Memory
AgentCore records Gateway and Memory spans only for requests that carry a sampled trace context. Your agent must send it, or no spans appear even with tracing turned on.
The following helpers turn the current OpenTelemetry span into the X-Amzn-Trace-Id and traceparent headers:
from opentelemetry import trace
def xray_trace_header():
ctx = trace.get_current_span().get_span_context()
if not ctx.is_valid:
return None
trace_id = f"{ctx.trace_id:032x}"
return f"Root=1-{trace_id[:8]}-{trace_id[8:]};Parent={ctx.span_id:016x};Sampled=1"
def w3c_traceparent():
ctx = trace.get_current_span().get_span_context()
if not ctx.is_valid:
return None
return f"00-{ctx.trace_id:032x}-{ctx.span_id:016x}-01"For Memory calls made with boto3, add the header to every request of the bedrock-agentcore client before it's signed:
def add_trace_header(request, **kwargs):
header = xray_trace_header()
if header:
request.headers["X-Amzn-Trace-Id"] = header
memory_client.meta.events.register("before-sign.bedrock-agentcore.*", add_trace_header)For the Gateway, pass both headers when you open the MCP connection. This example uses the MCP Proxy for AWS client, which signs Gateway requests with AWS IAM credentials, inside the invocation span:
from mcp_proxy_for_aws.client import aws_iam_streamablehttp_client
from strands.tools.mcp import MCPClient
headers = {"X-Amzn-Trace-Id": xray_trace_header(), "traceparent": w3c_traceparent()}
gateway = MCPClient(
lambda: aws_iam_streamablehttp_client(
gateway_url,
aws_service="bedrock-agentcore",
aws_region=region,
headers={k: v for k, v in headers.items() if v},
)
)Trace Lambda Tool Targets
If a Gateway target is a Lambda function, turn on active tracing for that function. Lambda then records its own spans in aws/spans, under the same trace:
aws lambda update-function-configuration \
--function-name <function-name> \
--tracing-config Mode=ActiveThe function's execution role needs the AWSXRayDaemonWriteAccess managed policy, or equivalent permissions to write to X-Ray.
Step 3: Forward AgentCore Spans to Dash0
Spans in aws/spans reach Dash0 through a CloudWatch Logs subscription filter and an Amazon Data Firehose stream. Follow the AWS CloudWatch Transaction Search integration setup to create both.
The aws/spans log group holds the spans of every traced service in the AWS account and region. To forward only your agent's spans, set a filter pattern on the subscription filter. A text pattern such as "travel" matches every span whose JSON contains that string, for example in a resource ARN or service name. An empty pattern forwards everything.
In Dash0, the AgentCore spans appear under service names that AWS sets from the resource: the Gateway ID for Gateway spans, the Memory ID for Memory spans, and the function name for Lambda spans.
Step 4: Forward AgentCore Logs to Dash0
AgentCore Gateway writes a log for each request it handles, and AgentCore Memory writes logs for its memory extraction. Lambda tool targets write their logs to CloudWatch Logs. Gateway logs carry the trace ID of the request, so in the Dash0 trace view they appear as markers on the Gateway's spans.
Turn On Log Delivery for Gateway and Memory
AgentCore doesn't deliver Gateway and Memory logs until you add a log destination. In the AgentCore console , open each Memory and each Gateway your agent uses:
- Open the Configuration tab. For a Gateway, the panes are under Log deliveries and tracing.
- In the Log delivery pane, choose Add > To Amazon CloudWatch Logs.
- For Log type, select APPLICATION_LOGS.
- For Destination log group, enter a log group name that starts with
/aws/vendedlogs/, for example/aws/vendedlogs/bedrock-agentcore/<resource-id>. AWS creates log groups with this prefix for you. - Choose Add.
To do the same with an AWS SDK, create an APPLICATION_LOGS delivery source for the resource and deliver it to a CloudWatch Logs delivery destination, as shown in Configure CloudWatch resources using an AWS SDK .
Forward the Log Groups
Forward the Gateway and Memory log groups, and the /aws/lambda/<function-name> log group of each Lambda tool target, through a CloudWatch Logs subscription filter and an Amazon Data Firehose stream. Follow the AWS CloudWatch Logs integration setup to create both. You can subscribe all of the log groups to the same Firehose stream.
In Dash0, Gateway and Memory logs use the same service name as their spans: the Gateway ID or the Memory ID. Lambda logs carry the function name in faas.name.
Step 5: Collect AgentCore Metrics
AgentCore publishes metrics to the AWS/Bedrock-AgentCore CloudWatch namespace, such as invocations, latency, errors, sessions, and resource usage for Runtime, Gateway, and Memory. The Dash0 AWS integration scrapes them for you.
- Go to Settings → Integrations and open your AWS integration.
- Select the Metrics tab and find the Bedrock-AgentCore namespace with Search namespaces.
- On its card, click Turn on.
- Click Save.
For details on selecting namespaces and metrics, see Collect AWS CloudWatch Metrics.
Verify the Setup
Invoke your agent a few times, then open Tracing in Dash0 and open a recent trace of your agent's service. A trace with steps 1 to 3 complete contains spans from several services:
- Your agent: The invocation,
chat, andexecute_toolspans. - The Gateway:
AgentCore.Gateway.InvokeToolspans, one per tool call, plus authorization and routing spans. - Memory:
RetrieveMemoryRecords,CreateEvent, andListEventsspans. - Lambda: The tool function's spans, when active tracing is on.
With step 4 complete, the trace's logs include the Gateway's request logs. To see Memory and Lambda logs, open Logging and filter by the Memory ID or by faas.name.
If you see only your agent's spans, check the following:
- No Gateway or Memory spans in
aws/spans: Confirm that Transaction Search is on, that tracing is on for the resource, and that your agent sends the trace context headers from step 2. - Spans in
aws/spansbut not in Dash0: Check the Firehose stream's delivery metrics and the subscription filter pattern. - Separate traces for each Memory call: Wrap the whole invocation in one span, as described in the tip in step 1.
Further Reading
Last updated:
