Technology
Amazon Bedrock AgentCore
Dash0 integrates with Amazon Bedrock AgentCore to trace agents end to end across Runtime, Gateway, Memory, and Lambda tools, and to collect AgentCore CloudWatch metrics.
Overview
Overview
Amazon Bedrock AgentCore runs AI agents on AWS. AgentCore Runtime hosts the agent, AgentCore Gateway exposes tools to it over the Model Context Protocol (MCP), and AgentCore Memory stores conversation history and what the agent learns about each user.
With this integration, a request to your agent shows up in Dash0 as one trace. The trace contains the agent's model calls and tool calls from OpenTelemetry, plus the spans AWS records inside Gateway, Memory, and the Lambda functions behind your tools. Gateway, Memory, and Lambda logs from CloudWatch Logs add the details of each request. The AgentCore CloudWatch metrics add invocations, latency, and errors across all your agents, and the tokens AgentCore Memory uses.
Use Cases
- Trace each agent request end to end, from the model call through the Gateway to the tool's Lambda function.
- Find which tool call failed and whether the time went to the model, the Gateway, or the tool.
- Read the Gateway's request logs next to the spans of the same trace.
- Monitor invocations, latency, and errors per agent, per Gateway tool, and per Memory operation.
- Track the tokens AgentCore Memory spends on extracting long-term memories.
Setup
Overview
Telemetry for Amazon Bedrock AgentCore reaches Dash0 through four independent paths:
- Agent telemetry: Your agent's spans, logs, and metrics, sent with the OpenTelemetry SDK over OTLP.
- AgentCore spans: What AWS records inside AgentCore Gateway, AgentCore Memory, and Lambda tool targets, forwarded from CloudWatch Transaction Search.
- AgentCore logs: The application logs of AgentCore Gateway and AgentCore Memory, and the logs of your Lambda tool targets, forwarded from CloudWatch Logs.
- AgentCore metrics: The
AWS/Bedrock-AgentCoreCloudWatch namespace, scraped by the Dash0 AWS integration.
You can start with any of them. Paths 1 and 2 together give you one trace per agent request, and path 3 adds the matching logs. The dashboard uses path 4.
A complete, deployable example is available in the AgentCore Dash0 observability sample.
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.
- For AgentCore metrics, your AWS account connected through the AWS integration.
Send Agent Telemetry
AgentCore Runtime configures the AWS Distro for OpenTelemetry (ADOT) by default, which sends telemetry to CloudWatch. To send it to Dash0, turn that off and use the standard OpenTelemetry exporter environment variables.
Set the Environment Variables
Set these variables in environmentVariables when you create or update the agent runtime:
DISABLE_ADOT_OBSERVABILITY=true
OTEL_EXPORTER_OTLP_ENDPOINT={{endpoint_otlp_http}}
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
OTEL_EXPORTER_OTLP_HEADERS=Authorization=Bearer%20{{token}},Dash0-Dataset=<dataset>
OTEL_SERVICE_NAME=<service-name>The %20 encodes the space between Bearer and the token.
Configure the OpenTelemetry SDK
Add opentelemetry-sdk and opentelemetry-exporter-otlp-proto-http to your agent's dependencies. Then configure the SDK at the top of your entry point, before you import the agent framework. The exporter reads the endpoint and headers from the environment:
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)Configure a MeterProvider and a LoggerProvider the same way to send metrics and logs. Wrap each invocation in one span inside your @app.entrypoint handler, so the model calls, tool calls, and Memory calls of a request share one trace.
Add AgentCore Spans
AgentCore records spans for Gateway and Memory through AWS X-Ray, and stores them with CloudWatch Transaction Search in the aws/spans log group.
Enable Transaction Search and Tracing
- Enable CloudWatch Transaction Search in the region of your agent. See Enable CloudWatch Transaction Search.
- In the AgentCore console, open each Memory and Gateway your agent uses. On the Configuration tab, in the Tracing pane, choose Edit, turn tracing on, and choose Save.
- For Lambda tool targets, turn on active tracing:
aws lambda update-function-configuration \
--function-name <function-name> \
--tracing-config Mode=ActivePass the Trace Context
AgentCore records Gateway and Memory spans only for requests that carry a sampled trace context. Without it, no spans appear, even with tracing turned on. Build the X-Amzn-Trace-Id and traceparent headers from the current OpenTelemetry span:
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"Add the X-Ray header to every Memory request made with boto3:
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)Pass both headers when you open the Gateway MCP connection, here with the MCP Proxy for AWS client 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},
)
)Forward the Spans to Dash0
Forward the aws/spans log group to Dash0 as described in the Amazon CloudWatch Transaction Search setup. The log group holds the spans of every traced service in the account and region. To forward only your agent's spans, use a subscription filter pattern that matches a string in your resource names, such as "travel".
Add AgentCore Logs
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
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 Logs to Dash0
Forward the Gateway and Memory log groups, and the /aws/lambda/<function-name> log group of each Lambda tool target, to Dash0 as described in the AWS CloudWatch Logs setup. You can subscribe all of them 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.
Collect AgentCore Metrics
- In Dash0, go to Settings → Integrations and open your AWS integration.
- Select the Metrics tab and find the Bedrock-AgentCore namespace.
- On its card, click Turn on.
- Click Save.
Metrics appear in Dash0 a few minutes after AWS publishes them, under the aws.bedrock-agentcore. prefix, for example aws.bedrock-agentcore.invocations.
Verification
Invoke your agent a few times, then open a recent trace of your agent's service in Dash0. With all paths set up, the trace contains spans from:
- Your agent: The invocation,
chat, andexecute_toolspans. - The Gateway: One
AgentCore.Gateway.InvokeToolspan per tool call, plus authorization and routing spans. The service name is the Gateway ID. - Memory:
RetrieveMemoryRecords,CreateEvent, andListEventsspans. The service name is the Memory ID. - Lambda: The tool function's spans, when active tracing is on.
With logs forwarded, the trace's logs include the Gateway's request logs.
In the Metrics Explorer, search for aws.bedrock-agentcore to see the scraped metrics.
