{"library":"opentelemetry-contrib-instrumentations","title":"OpenTelemetry Contrib Instrumentation Packages","description":"The `opentelemetry-contrib-instrumentations` library is a metapackage that conveniently installs a collection of community-maintained OpenTelemetry Python instrumentation packages. These instrumentations automatically capture telemetry data (traces, metrics, logs) from various third-party frameworks, databases, and HTTP clients without requiring manual code changes to the instrumented libraries themselves. The project is actively developed and follows a frequent release cadence, often aligning with the core OpenTelemetry Python SDK, typically on a monthly or bi-monthly schedule, with `b` (beta) versions being common.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install opentelemetry-contrib-instrumentations opentelemetry-sdk opentelemetry-exporter-otlp opentelemetry-distro"],"cli":null},"imports":["from opentelemetry.instrumentation.requests import RequestsInstrumentor","from opentelemetry.sdk.resources import Resource\nfrom opentelemetry.sdk.trace import TracerProvider\nfrom opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor\nfrom opentelemetry.instrumentation.distro import OpenTelemetryDistro\n\ndef configure_opentelemetry(service_name: str):\n    resource = Resource.create({\"service.name\": service_name})\n    tracer_provider = TracerProvider(resource=resource)\n    span_processor = SimpleSpanProcessor(ConsoleSpanExporter())\n    tracer_provider.add_span_processor(span_processor)\n    \n    # Set the global tracer provider\n    from opentelemetry import trace\n    trace.set_tracer_provider(tracer_provider)\n\n    # Instrument all installed contrib instrumentations\n    distro = OpenTelemetryDistro()\n    distro.instrument()\n    # Or, to instrument specific packages:\n    # from opentelemetry.instrumentation.requests import RequestsInstrumentor\n    # RequestsInstrumentor().instrument()"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nimport requests\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.requests import RequestsInstrumentor\n\n# Configure OpenTelemetry SDK\nresource = Resource.create({\"service.name\": os.environ.get('OTEL_SERVICE_NAME', 'my-python-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 the requests library\nRequestsInstrumentor().instrument()\n\n# Make an HTTP request that will be traced\ndef make_request():\n    print(\"Making an HTTP request...\")\n    response = requests.get(\"https://www.example.com\")\n    print(f\"Request completed with status: {response.status_code}\")\n\nif __name__ == \"__main__\":\n    make_request()\n\n# To run this, install:\n# pip install opentelemetry-sdk opentelemetry-exporter-console opentelemetry-instrumentation-requests requests","lang":"python","description":"This quickstart demonstrates how to set up the OpenTelemetry SDK with a console exporter and then enable automatic tracing for the `requests` library. It initializes a `TracerProvider`, configures a `SimpleSpanProcessor` with a `ConsoleSpanExporter` to print traces to the console, and then uses `RequestsInstrumentor().instrument()` to automatically trace HTTP requests made with the `requests` library. Run the script and observe the trace output in the console. For a more comprehensive automatic instrumentation, you can also use `opentelemetry-distro` which automatically instruments all compatible installed libraries.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}