Learn how to instrument AWS Bedrock calls with the LangWatch Python SDK using OpenInference.
boto3
library, allows you to leverage powerful foundation models. By using the OpenInference Bedrock instrumentor, you can automatically capture OpenTelemetry traces for your Bedrock API calls. LangWatch, being an OpenTelemetry-compatible observability platform, can seamlessly ingest these traces, providing insights into your LLM interactions.
This guide explains how to configure your Python application to send Bedrock traces to LangWatch.
boto3
to interact with AWS Bedrock, and the OpenInference instrumentation library for Bedrock.
openinference-instrumentation-bedrock
will install necessary OpenTelemetry packages. Ensure your boto3
and botocore
versions are compatible with the Bedrock features you intend to use (e.g., botocore >= 1.34.116
for the converse
API).
langwatch.setup()
at the beginning of your application. This configures the global OpenTelemetry SDK to export traces to LangWatch.BedrockInstrumentor
and call its instrument()
method. This will patch boto3
to automatically create spans for Bedrock client calls.langwatch.setup()
: Initializes the global OpenTelemetry environment configured for LangWatch. This must be called before any instrumented code is run.BedrockInstrumentor().instrument()
: This call patches the boto3
library. Any subsequent Bedrock calls made using a boto3.client("bedrock-runtime")
will automatically generate OpenTelemetry spans.@langwatch.trace()
: Creates a parent trace in LangWatch. The automated Bedrock spans generated by OpenInference will be nested under this parent trace if the Bedrock calls are made within the decorated function. This provides a clear hierarchy for your operations.invoke_model
and converse
APIs. The converse
API requires botocore
version 1.34.116
or newer.