OpenTelemetry AWS Bedrock Runtime instrumentation
Project description
This package instruments AWS Bedrock Runtime model calls made through boto3/botocore and emits GenAI LLMInvocation telemetry through splunk-otel-util-genai.
Installation
pip install splunk-otel-instrumentation-bedrock
Usage
import boto3
from opentelemetry.instrumentation.bedrock import BedrockInstrumentor
BedrockInstrumentor().instrument()
client = boto3.client("bedrock-runtime", region_name="us-west-2")
response = client.converse(
modelId="anthropic.claude-3-haiku-20240307-v1:0",
messages=[{"role": "user", "content": [{"text": "Hello"}]}],
)
Composition With AgentCore
Use this package with AgentCore instrumentation when your application uses BedrockAgentCoreApp and calls Bedrock Runtime from inside the entrypoint. AgentCore owns the agent parent spans, and this package adds the child LLM spans that evaluation callbacks consume.
from opentelemetry.instrumentation.bedrock import BedrockInstrumentor
from opentelemetry.instrumentation.bedrock_agentcore import (
BedrockAgentCoreInstrumentor,
)
BedrockAgentCoreInstrumentor().instrument()
BedrockInstrumentor().instrument()
Example
In the repository, see examples/manual for a runnable Bedrock Runtime example that can also enable AgentCore instrumentation. It uses console span export by default so you can verify that Bedrock Runtime LLM spans nest under active AgentCore spans when both instrumentors are enabled.
What Gets Instrumented
bedrock-runtime.Converse -> LLMInvocation
bedrock-runtime.ConverseStream -> streaming LLMInvocation
bedrock-runtime.InvokeModel -> provider-aware LLMInvocation
bedrock-runtime.InvokeModelWithResponseStream -> provider-aware streaming LLMInvocation for supported streamed JSON chunk formats
Agent Runtime calls such as bedrock-agent-runtime.invoke_agent are not instrumented by this package. Agent orchestration spans belong in AgentCore or agent-framework instrumentation.
Configuration
Content capture follows the shared GenAI environment variables:
export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=SPAN_AND_EVENT
export OTEL_INSTRUMENTATION_GENAI_CAPTURE_TOOL_DEFINITIONS=true
Useful flags for Bedrock Runtime and AgentCore composition:
Environment variable |
Purpose |
|---|---|
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT |
Controls whether captured prompt and completion message content is emitted by the shared GenAI emitters. Use SPAN_AND_EVENT when evals and exported telemetry both need message bodies. |
OTEL_INSTRUMENTATION_GENAI_CAPTURE_TOOL_DEFINITIONS |
Controls whether Bedrock tool definitions are serialized into emitted telemetry. Leave disabled when tool schemas are large or sensitive. |
DISABLE_ADOT_OBSERVABILITY |
Set to true in AgentCore deployments that export to your own OTLP collector so AgentCore does not also send telemetry through AWS ADOT observability. |
The instrumentation always populates message bodies and tool arguments on the Python invocation objects so evaluations can consume them. The shared GenAI emitters use the content-capture setting to decide whether those values are emitted as span attributes or log events.
For zero-code instrumentation, disable this package with OTEL_PYTHON_DISABLED_INSTRUMENTATIONS=bedrock.
InvokeModel Coverage
InvokeModel and InvokeModelWithResponseStream support generic JSON metadata extraction plus provider-specific shapes aligned with upstream OpenTelemetry botocore Bedrock behavior:
Amazon Titan
Amazon Nova
Anthropic Claude
Cohere Command and Command R
Meta Llama
Mistral
For non-streaming InvokeModel responses, the instrumentation reads botocore.response.StreamingBody only to parse supported JSON response shapes, then replaces the response body with a fresh stream so application code can still read it.
Telemetry Details
The instrumentation sets:
gen_ai.system = aws.bedrock
gen_ai.framework = boto3
gen_ai.request.model from modelId
gen_ai.provider.name = aws.bedrock
request params such as temperature, top-p, max tokens, and stop sequences
response ID, response model, finish reasons, and token usage when available
gen_ai.request.stream and gen_ai.response.time_to_first_chunk for streaming calls
Requirements
Python >= 3.10
boto3 >= 1.34.0
splunk-otel-util-genai >= 0.1.9
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file splunk_otel_instrumentation_bedrock-0.2.0.tar.gz.
File metadata
- Download URL: splunk_otel_instrumentation_bedrock-0.2.0.tar.gz
- Upload date:
- Size: 17.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.17.1 {"ci":true,"cpu":"x86_64","distro":{"id":"trixie","libc":{"lib":"glibc","version":"2.41"},"name":"Debian GNU/Linux","version":"13"},"implementation":{"name":"CPython","version":"3.11.15"},"installer":{"name":"hatch","version":"1.17.1"},"openssl_version":"OpenSSL 3.5.6 7 Apr 2026","python":"3.11.15","system":{"name":"Linux","release":"5.15.0-1084-aws"}} HTTPX2/2.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35495bf8e70d4abb9caecef7efefeeb2e922eb1e54f0b01142c67660b5d00481
|
|
| MD5 |
50cfeec5d931991883e14780d5dd6281
|
|
| BLAKE2b-256 |
b5c4513bf4c12d8d6f7a4b560137b182b1765188206178c17ccfa826509efa02
|
File details
Details for the file splunk_otel_instrumentation_bedrock-0.2.0-py3-none-any.whl.
File metadata
- Download URL: splunk_otel_instrumentation_bedrock-0.2.0-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.17.1 {"ci":true,"cpu":"x86_64","distro":{"id":"trixie","libc":{"lib":"glibc","version":"2.41"},"name":"Debian GNU/Linux","version":"13"},"implementation":{"name":"CPython","version":"3.11.15"},"installer":{"name":"hatch","version":"1.17.1"},"openssl_version":"OpenSSL 3.5.6 7 Apr 2026","python":"3.11.15","system":{"name":"Linux","release":"5.15.0-1084-aws"}} HTTPX2/2.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d067eb121937854eb6b7807a690ff2fd358bf1130e2f7778949542ee5ffaf8f
|
|
| MD5 |
5b8df0d6415b535c1b20180e8c49f983
|
|
| BLAKE2b-256 |
e3a23b478fd8db86cd8738491751be3ef12e5c895c7e402d78f2a28c6f6530e5
|