{"id":2154,"library":"opentelemetry-instrumentation-bedrock","title":"OpenTelemetry Bedrock Instrumentation","description":"The `opentelemetry-instrumentation-bedrock` library provides automatic instrumentation for AWS Bedrock API calls made using Boto3. It captures telemetry data such as prompts, completions, and embeddings, enabling observability into Large Language Model (LLM) applications within the OpenTelemetry ecosystem. This library is part of the broader OpenLLMetry project and is currently at version 0.58.0, with a frequent release cadence.","status":"active","version":"0.58.0","language":"en","source_language":"en","source_url":"https://github.com/traceloop/openllmetry/tree/main/packages/opentelemetry-instrumentation-bedrock","tags":["opentelemetry","observability","aws","bedrock","llm","ai","instrumentation","tracing"],"install":[{"cmd":"pip install opentelemetry-instrumentation-bedrock boto3","lang":"bash","label":"Install library and AWS Boto3"}],"dependencies":[{"reason":"Required for interacting with AWS Bedrock services, which this instrumentation intercepts.","package":"boto3"},{"reason":"Core OpenTelemetry SDK components are necessary for processing and exporting telemetry data.","package":"opentelemetry-sdk"},{"reason":"Core OpenTelemetry API for creating traces, metrics, and logs.","package":"opentelemetry-api"}],"imports":[{"symbol":"BedrockInstrumentor","correct":"from opentelemetry.instrumentation.bedrock import BedrockInstrumentor"}],"quickstart":{"code":"import os\nimport boto3\nfrom opentelemetry import trace\nfrom opentelemetry.sdk.resources import Resource\nfrom opentelemetry.sdk.trace import TracerProvider\nfrom opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor\nfrom opentelemetry.instrumentation.bedrock import BedrockInstrumentor\n\n# Configure OpenTelemetry SDK\nresource = Resource.create({\"service.name\": \"bedrock-app\"})\ntracer_provider = TracerProvider(resource=resource)\nspan_processor = SimpleSpanProcessor(ConsoleSpanExporter())\ntracer_provider.add_span_processor(span_processor)\ntrace.set_tracer_provider(tracer_provider)\n\n# Instrument Bedrock\nBedrockInstrumentor().instrument()\n\n# Ensure AWS credentials are set up (e.g., via environment variables or AWS CLI config)\n# For a runnable example, ensure AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION are set or mock boto3.\n# For this quickstart, we'll use os.environ.get for region, assuming credentials are in place.\naws_region = os.environ.get('AWS_REGION', 'us-east-1')\n\ndef invoke_bedrock_model():\n    try:\n        bedrock_runtime = boto3.client(\n            service_name='bedrock-runtime',\n            region_name=aws_region\n        )\n        \n        model_id = 'amazon.titan-text-express-v1'\n        body = {\n            'inputText': 'Explain the importance of OpenTelemetry.',\n            'textGenerationConfig': {\n                'maxTokenCount': 50,\n                'stopSequences': [],\n                'temperature': 0.7,\n                'topP': 0.9\n            }\n        }\n\n        response = bedrock_runtime.invoke_model(\n            body=json.dumps(body),\n            modelId=model_id,\n            accept='application/json',\n            contentType='application/json'\n        )\n\n        response_body = json.loads(response.get('body').read())\n        print(f\"Bedrock Model Response: {response_body['results'][0]['outputText'].strip()}\")\n    except Exception as e:\n        print(f\"Error invoking Bedrock model: {e}\")\n\nimport json\ninvoke_bedrock_model()\n","lang":"python","description":"This quickstart demonstrates how to set up the OpenTelemetry SDK with a console exporter, instrument the Bedrock client, and then invoke a Bedrock model. The instrumentation automatically creates spans for the Bedrock interaction, which are then printed to the console by the `ConsoleSpanExporter`."},"warnings":[{"fix":"Review existing dashboards, alerts, and querying logic that rely on OpenTelemetry span attributes. Update them to use the new semantic convention attribute names. For a transition period, you might use the `OTEL_SEMCONV_STABILITY_OPT_IN=gen_ai_latest_experimental` environment variable to explicitly enable the latest experimental conventions or facilitate dual emission, though direct adaptation is recommended for stable setups. Consult the OpenTelemetry semantic conventions documentation for specific changes.","message":"The OpenTelemetry Generative AI (GenAI) semantic conventions have undergone significant changes, particularly in attribute naming and structure. Recent versions of `opentelemetry-instrumentation-bedrock` (e.g., 0.53.4, 0.54.0, 0.55.0, 0.57.0) reflect these updates to conform to the latest OTel GenAI semantic conventions (e.g., 0.5.0).","severity":"breaking","affected_versions":">=0.53.0"},{"fix":"To disable logging of this content, set the environment variable `TRACELOOP_TRACE_CONTENT` to `false`.","message":"By default, this instrumentation logs prompts, completions, and embeddings to span attributes, which can contain sensitive user data. This is done to provide rich observability, but may pose privacy concerns.","severity":"gotcha","affected_versions":"All"},{"fix":"Check the AWS SDK documentation for `boto3` and `botocore` for version requirements related to specific Bedrock functionalities you are using. Upgrade `boto3` and `botocore` if necessary: `pip install --upgrade boto3 botocore`.","message":"Ensure your `boto3` and `botocore` library versions are compatible with the specific AWS Bedrock features you intend to use. Older versions might not support newer Bedrock APIs (e.g., `botocore >= 1.34.116` is required for the `converse` API).","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}