{"id":446,"library":"opentelemetry-instrumentation-requests","title":"OpenTelemetry Requests Instrumentation","description":"Provides tracing capabilities for HTTP requests made using the 'requests' library. Current version: 0.61b0. Release cadence: beta releases with incremental improvements.","status":"active","version":"0.61b0","language":"python","source_language":"en","source_url":"https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/requests","tags":["OpenTelemetry","requests","instrumentation","tracing"],"install":[{"cmd":"pip install opentelemetry-instrumentation-requests","lang":"bash","label":"Install OpenTelemetry Requests Instrumentation"}],"dependencies":[{"reason":"Required for HTTP request instrumentation","package":"requests"}],"imports":[{"note":"Ensure correct import path to access the RequestsInstrumentor class.","symbol":"RequestsInstrumentor","correct":"from opentelemetry.instrumentation.requests import RequestsInstrumentor"}],"quickstart":{"code":"import os\nfrom opentelemetry.instrumentation.requests import RequestsInstrumentor\nfrom opentelemetry import trace\nfrom opentelemetry.sdk.trace import TracerProvider\nfrom opentelemetry.sdk.trace.export import BatchSpanProcessor\nfrom opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter\nfrom opentelemetry.sdk.resources import Resource, SERVICE_NAME\n\n# Set up the OpenTelemetry SDK\nresource = Resource.create({SERVICE_NAME: 'my-service'})\nprovider = TracerProvider(resource=resource)\nprovider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter()))\nprovider.register()\n\n# Instrument the 'requests' library\nRequestsInstrumentor().instrument()\n\n# Make an HTTP request\nimport requests\nresponse = requests.get('https://api.example.com')\nprint(response.status_code)","lang":"python","description":"This script sets up OpenTelemetry tracing, instruments the 'requests' library, and makes an HTTP GET request to 'https://api.example.com'."},"warnings":[{"fix":"Ensure 'RequestsInstrumentor().instrument()' is called before importing 'requests'.","message":"Instrumenting after importing 'requests' may result in incomplete tracing due to module caching.","severity":"breaking","affected_versions":"all"},{"fix":"Verify the environment variable is set with the correct regex patterns to exclude desired URLs.","message":"Setting 'OTEL_PYTHON_REQUESTS_EXCLUDED_URLS' to exclude certain URLs may not work if the environment variable is not set correctly.","severity":"gotcha","affected_versions":"all"},{"fix":"Install the 'requests' package using pip: 'pip install requests'.","message":"The 'requests' package is a direct dependency of opentelemetry-instrumentation-requests and must be installed.","severity":"breaking","affected_versions":"all"},{"fix":"Install the 'requests' library using `pip install requests`.","message":"The 'requests' library is a required dependency for 'opentelemetry-instrumentation-requests' and must be installed. The absence of 'requests' will cause a `ModuleNotFoundError`.","severity":"breaking","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-12T13:52:27.923Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Ensure that `opentelemetry-api`, `opentelemetry-sdk`, and `opentelemetry-instrumentation-requests` are installed in your active Python environment using pip: `pip install opentelemetry-api opentelemetry-sdk opentelemetry-instrumentation-requests`.","cause":"The core OpenTelemetry SDK or the `opentelemetry-instrumentation-requests` package itself is not installed in the Python environment where the application is running, or there's an issue with Python's namespace package resolution.","error":"ModuleNotFoundError: No module named 'opentelemetry'"},{"fix":"Before making any `requests` calls, initialize the OpenTelemetry SDK with a `TracerProvider`, a `SpanProcessor`, and an `Exporter`. Then, call `RequestsInstrumentor().instrument()` to enable tracing:\n\n```python\nfrom opentelemetry import trace\nfrom opentelemetry.sdk.trace import TracerProvider\nfrom opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor\nfrom opentelemetry.instrumentation.requests import RequestsInstrumentor\nimport requests\n\n# Configure the SDK\nprovider = TracerProvider()\nprocessor = SimpleSpanProcessor(ConsoleSpanExporter()) # Or a different exporter like OTLPSpanExporter\nprovider.add_span_processor(processor)\ntrace.set_tracer_provider(provider)\n\n# Instrument the requests library\nRequestsInstrumentor().instrument()\n\n# Now, requests will be traced\nresponse = requests.get(\"http://example.com\")\n```","cause":"HTTP requests made by the `requests` library are not being traced because the `RequestsInstrumentor` has not been properly initialized or the OpenTelemetry SDK (TracerProvider, SpanProcessor, Exporter) is not configured correctly before the requests are made.","error":"opentelemetry-instrumentation-requests no traces"},{"fix":"Install the `opentelemetry-exporter-otlp` package with the necessary gRPC or HTTP dependencies. For gRPC, use: `pip install 'opentelemetry-exporter-otlp[grpc]'`. For HTTP, use: `pip install 'opentelemetry-exporter-otlp[http]'`. Also, ensure that relevant environment variables like `OTEL_TRACES_EXPORTER` and `OTEL_METRICS_EXPORTER` are correctly set (e.g., `OTEL_TRACES_EXPORTER=otlp`, and `OTEL_METRICS_EXPORTER=none` if not collecting metrics).","cause":"This error typically occurs when using the `opentelemetry-instrument` CLI for auto-instrumentation, and the OpenTelemetry OTLP exporter package for gRPC (or HTTP) is not installed with its required dependencies.","error":"RuntimeError: Requested component 'otlp_proto_grpc' not found"}],"ecosystem":"pypi","meta_description":null,"install_score":0,"install_tag":"stale","quickstart_score":0,"quickstart_tag":"stale","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}