Registry /
observability / openinference-instrumentation-bedrock
Install & Compatibility
Where this runs
tested against v0.1.41 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.950s · 58.2MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 4.9s · import 0.861s · 59MB
57MB installed
● package 57MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
BedrockInstrumentor
✓ from openinference.instrumentation.bedrock import BedrockInstrumentor
This quickstart demonstrates how to set up `openinference-instrumentation-bedrock` to automatically trace calls to AWS Bedrock. It configures a basic OpenTelemetry `TracerProvider` with a `ConsoleSpanExporter` to print traces to the console, instruments the `boto3` Bedrock client, and then makes a sample `invoke_model` call. Ensure your AWS credentials (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION_NAME) are set as environment variables or configured in your AWS setup for `boto3` to work correctly. [1, 3, 4, 13]
import os
import boto3
from opentelemetry import trace
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor, ConsoleSpanExporter
from openinference.instrumentation.bedrock import BedrockInstrumentor
# 1. Configure OpenTelemetry Tracer Provider
resource = Resource.create({"service.name": "my-bedrock-app"})
tracer_provider = TracerProvider(resource=resource)
tracer_provider.add_span_processor(
SimpleSpanProcessor(ConsoleSpanExporter())
)
trace.set_tracer_provider(tracer_provider)
# 2. Instrument the Bedrock client
BedrockInstrumentor().instrument()
# 3. Create a boto3 client (must be after instrumentation)
# Ensure AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION_NAME are set in environment
# or configure boto3 credentials separately.
bedrock_runtime = boto3.client(
service_name='bedrock-runtime',
region_name=os.environ.get('AWS_REGION_NAME', 'us-east-1'),
aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', 'YOUR_AWS_ACCESS_KEY_ID'),
aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', 'YOUR_AWS_SECRET_ACCESS_KEY')
)
# 4. Invoke a Bedrock model
model_id = "anthropic.claude-instant-v1"
content_type = "application/json"
accept_type = "application/json"
body = {
"prompt": "Human: What is the capital of France? Assistant:",
"max_tokens_to_sample": 100,
"temperature": 0.5,
}
try:
response = bedrock_runtime.invoke_model(
body=str(body),
modelId=model_id,
contentType=content_type,
accept=accept_type
)
response_body = response['body'].read().decode('utf-8')
print(f"Model Response: {response_body}")
except Exception as e:
print(f"Error invoking model: {e}")
print("Please ensure your AWS credentials are configured and Bedrock access is granted.")
# Spans will be printed to console by ConsoleSpanExporter
Debug
Known issues
gotchaTracing of LLM-specific metadata (prompts, responses, token usage) is not fully supported for asynchronous Bedrock calls made with `aioboto3`. While spans might be generated, they often lack rich LLM attributes. [8]fixUse synchronous `boto3` for Bedrock interactions if complete LLM metadata tracing is critical, or manually instrument `aioboto3` calls by setting OpenInference semantic attributes directly within custom OpenTelemetry spans. [8]
affects: All versions up to 0.1.34
gotchaWhen using Meta models (e.g., Llama 3) on Amazon Bedrock, outputs might not be traced when using the `invoke_model` API. It is recommended to use the `converse` API for these models to ensure full tracing. [4, 13]fixPrefer the `boto3` Bedrock `converse` API over `invoke_model` for Meta models when comprehensive tracing is required. Ensure `botocore` version is >= 1.34.116 for `converse` API support. [3, 4, 13]
affects: All versions up to 0.1.34
gotchaThe `BedrockInstrumentor().instrument()` call must occur *before* any `boto3.client('bedrock-runtime')` instances are created. Clients initialized prior to instrumentation will not be traced. [4, 13]fixEnsure `BedrockInstrumentor().instrument()` is called early in your application's lifecycle, preferably immediately after configuring your OpenTelemetry `TracerProvider` and before initializing any `boto3` Bedrock clients.
affects: All versions up to 0.1.34
Upgrade
Version history
0.1.41latest on PyPI · released Jun 3, 2026
Audit
Dependencies
boto3requiredRequired for interacting with AWS Bedrock services.
botocorerequiredSpecific versions (e.g., >=1.34.116) are required for certain Bedrock APIs like 'converse'.
opentelemetry-apirequiredCore OpenTelemetry API for tracing (installed as a dependency).
opentelemetry-sdkrequiredOpenTelemetry SDK for trace management (installed as a dependency).