wrap_bedrock is currently in beta.
Installation
The bedrock extra installs boto3>=1.34.0. For async support install aioboto3 separately — wrap_bedrock detects it at runtime and instruments async methods automatically without making it a hard dependency.
Setup
Converse API (recommended)
Span name: "bedrock-converse", SpanKind: LLM
The Converse API is provider-agnostic — the same call shape works across Claude, Mistral, Llama, Titan and other Bedrock-hosted foundation models. Prefer Converse over InvokeModel for new integrations.
What gets traced
- Input: top-level
system blocks hoisted into the messages list as a role="system" entry, followed by the messages array. Text-only content blocks are flattened into a single string; mixed-block content (images, tool use/results) round-trips as structured JSON.
- Output: assistant
content text blocks joined together
- Model:
modelId from the request kwargs
- Token usage (see mapping table below)
- Model parameters:
temperature, topP, maxTokens, stopSequences from inferenceConfig, plus guardrailConfig, additionalModelRequestFields, toolConfig
reasoningContent blocks (when models emit them) are stored in span metadata as reasoning_summary
Streaming
The wrapper preserves the {"stream": ..., "ResponseMetadata": ...} response shape — only the inner iterator is replaced with a tracing-aware reducer. User code accesses response["stream"] exactly as before. Time-to-first-token is captured on the first contentBlockDelta; final token usage is read from the trailing metadata event.
InvokeModel API (legacy fallback)
Span name: "bedrock-invoke-model" (or "bedrock-invoke-model-stream"), SpanKind: LLM
InvokeModel bodies are provider-specific JSON; the wrapper parses the body on a best-effort basis and recognises:
- Anthropic Claude on Bedrock —
{"messages": [...], "system": "..."}, output content blocks, usage as input_tokens / output_tokens
- Mistral on Bedrock —
{"messages": [...]}
- Amazon Titan —
{"inputText": "..."}, output via results[0].outputText, usage via inputTextTokenCount + results[0].tokenCount
- Cohere / Meta Llama —
{"prompt": "..."} and provider-specific generation fields
Unknown body shapes still produce an LLM span containing the serialised request body as input.
Async (aioboto3)
aioboto3 is supported but not required. When wrap_bedrock is given an aioboto3 client (its module path starts with aioboto3 / aiobotocore, or its methods are coroutine functions), the wrapper installs async-shaped patches for converse, converse_stream, invoke_model, and invoke_model_with_response_stream.
Token usage mapping