Impact. Bedrock
(Impact v0.0.1)
Copy Markdown
Span helpers for AWS Bedrock Converse-style API calls.
Use these when you need to manually instrument Bedrock calls that don't go
through Req (and therefore can't be auto-instrumented by
Impact.Instrumentation.Bedrock). Typical case: apps using the
:aws_elixir (AWS.BedrockRuntime) or :ex_aws_bedrock clients.
High-level usage — with_call/4
Wraps the entire LLM call in a bedrock_call span. Sets request-side
attributes upfront, response-side attributes after the closure returns,
and latency on every code path:
Impact.Bedrock.with_call(model, body, [conversation_id: agent_id], fn ->
case AWS.BedrockRuntime.converse(client, model.arn, body, opts) do
{:ok, response, _metadata} -> {:ok, response}
{:error, reason} -> {:error, reason}
end
end)Returns whatever the closure returned, unchanged.
Result classification
The closure can return any of these shapes; with_call/4 interprets them as
follows:
| Return value | Attribute set | Latency stamped |
|---|---|---|
{:ok, response} | attrs_for_response/2 | yes |
{:ok, response, _meta} (3-tuple aws-elixir form) | attrs_for_response/2 | yes |
{:error, reason} | attrs_for_error/2 | yes |
anything else (e.g. {:snooze, n}) | aws.bedrock.latency_ms only | yes |
Manual control — attrs_for_request/3 / attrs_for_response/2 / attrs_for_error/2
Build attribute maps directly when you need to drive the trace block yourself (multi-attempt retries, snooze handling with per-attempt timing, etc):
request_attrs = Impact.Bedrock.attrs_for_request(model, body, conversation_id: agent_id)
Impact.trace [type: :llm, name: "bedrock_call", attributes: request_attrs] do
start_ms = System.monotonic_time(:millisecond)
# ... your call ...
Impact.set_attributes(Impact.Bedrock.attrs_for_response(response, latency))
endAttribute keys
Request-side (attrs_for_request/3):
gen_ai.system = "aws.bedrock"gen_ai.provider.name = "aws"gen_ai.operation.name = "chat"gen_ai.request.model— model name (frommodel.nameor ARN)gen_ai.input.messages— JSON-encoded requestmessagesgen_ai.system_instructions— extracted system textgen_ai.conversation.id— opt:conversation_idgen_ai.model.id— opt:model_idaws.bedrock.model.arn— frommodel.arnaws.bedrock.inference_config— JSON-encodedinferenceConfigaws.bedrock.tool_config— JSON-encodedtoolConfig
Response-side (attrs_for_response/2):
gen_ai.response.idgen_ai.response.finish_reasons— list withstopReasongen_ai.usage.input_tokens,gen_ai.usage.output_tokensgen_ai.output.messages— JSON-encoded assistant messagegen_ai.output.text— extracted plain textgen_ai.response.tool_calls.count— number oftoolUseblocksaws.bedrock.latency_ms
Error-side (attrs_for_error/2):
error.message—inspect(reason)aws.bedrock.latency_ms
For tool / function call spans, see Impact.Tool.
Summary
Functions
Build error-side attributes for a failed bedrock_call.
Build request-side attributes for a bedrock_call span.
Build response-side attributes for a successful bedrock_call.
Wrap a Bedrock-style API call in a bedrock_call LLM span. Handles request
attrs, response/error attrs, and latency on every code path.
Functions
Build error-side attributes for a failed bedrock_call.
Build request-side attributes for a bedrock_call span.
Options
:conversation_id— value forgen_ai.conversation.id:model_id— value forgen_ai.model.id(internal model identifier distinct from the human-readable model name)
Build response-side attributes for a successful bedrock_call.
Wrap a Bedrock-style API call in a bedrock_call LLM span. Handles request
attrs, response/error attrs, and latency on every code path.
Options (forwarded to attrs_for_request/3)
:conversation_id— value forgen_ai.conversation.id:model_id— value forgen_ai.model.id