OpenTelemetry Boto Instrumentation
This library provides instrumentation for the `boto` (AWS SDK v2) Python library, allowing it to emit traces and metrics compatible with OpenTelemetry. It helps monitor interactions with AWS services made using `boto`. The current version is `0.61b0`, and it's released as part of the `opentelemetry-python-contrib` project, with frequent beta releases.
Warnings
- gotcha This instrumentation is for the `boto` library (AWS SDK v2) only. It will NOT instrument `boto3` (AWS SDK v3). For `boto3`, use `opentelemetry-instrumentation-botocore` instead.
- gotcha The library is currently in a beta release (`0.61b0`). APIs and behavior may not be stable and could change in future releases without adhering to strict semantic versioning.
- gotcha You must explicitly call `BotoInstrumentor().instrument()` after configuring your OpenTelemetry `TracerProvider` for the instrumentation to become active.
- gotcha The `boto` library itself must be installed separately. `opentelemetry-instrumentation-boto` does not automatically install `boto` as a dependency.
Install
-
pip install opentelemetry-instrumentation-boto
Imports
- BotoInstrumentor
from opentelemetry.instrumentation.boto import BotoInstrumentor
Quickstart
import os
import boto
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor
from opentelemetry.instrumentation.boto import BotoInstrumentor
# Configure OpenTelemetry TracerProvider
provider = TracerProvider()
processor = SimpleSpanProcessor(ConsoleSpanExporter())
provider.add_span_processor(processor)
trace.set_tracer_provider(provider)
# Instrument boto
BotoInstrumentor().instrument()
# Example boto usage (requires AWS credentials or configuration)
# For a real application, ensure AWS credentials are set up via env vars, ~/.aws/credentials, etc.
# Using dummy credentials for a non-functional example to demonstrate instrumentation.
# DO NOT use real credentials in quickstart.
os.environ['AWS_ACCESS_KEY_ID'] = os.environ.get('AWS_ACCESS_KEY_ID', 'DUMMY_KEY_ID')
os.environ['AWS_SECRET_ACCESS_KEY'] = os.environ.get('AWS_SECRET_ACCESS_KEY', 'DUMMY_SECRET_KEY')
print('Attempting to create S3 connection (may fail without real credentials, but traces will appear if instrumentation works):')
try:
conn = boto.connect_s3(is_secure=False, port=8000, host='localhost') # Use a dummy host to avoid actual calls
# Attempt to list buckets, this will likely fail but trigger instrumentation
conn.get_all_buckets()
print('S3 buckets retrieved (this might be an empty list or error out gracefully)')
except Exception as e:
print(f'S3 operation failed: {e}')
finally:
# Explicitly shutdown the provider to ensure all spans are exported
provider.shutdown()