{"library":"opentelemetry-instrumentation-openai-agents","title":"OpenTelemetry OpenAI Agents Instrumentation","description":"This library provides official OpenTelemetry instrumentation for the `openai-agents` SDK, converting the rich trace data emitted by the Agents runtime into the GenAI semantic conventions, enriching spans with request/response payload metadata, and recording duration/token usage metrics. It is currently at version `0.58.0` and maintains an active development pace with frequent updates, often related to compliance with evolving OpenTelemetry Generative AI semantic conventions.","language":"python","status":"active","last_verified":"Fri May 15","install":{"commands":["pip install opentelemetry-instrumentation-openai-agents openai-agents opentelemetry-sdk"],"cli":null},"imports":["from opentelemetry.instrumentation.openai_agents import OpenAIAgentsInstrumentor"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom agents import Agent, Runner, function_tool\nfrom opentelemetry import trace\nfrom opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter\nfrom opentelemetry.instrumentation.openai_agents import OpenAIAgentsInstrumentor\nfrom opentelemetry.sdk.trace import TracerProvider\nfrom opentelemetry.sdk.trace.export import BatchSpanProcessor\n\ndef configure_otel() -> None:\n    # Configure an OpenTelemetry TracerProvider\n    provider = TracerProvider()\n    processor = BatchSpanProcessor(OTLPSpanExporter())\n    provider.add_span_processor(processor)\n    trace.set_tracer_provider(provider)\n\n    # Instrument OpenAI Agents\n    OpenAIAgentsInstrumentor().instrument(tracer_provider=provider)\n\n@function_tool\ndef get_weather(city: str) -> str:\n    \"\"\"Provides the weather for a given city.\"\"\"\n    return f\"The forecast for {city} is sunny with pleasant temperatures.\"\n\nif __name__ == \"__main__\":\n    # Ensure OTLP collector is running, e.g., with Docker:\n    # docker run -d -p 4317:4317 -p 4318:4318 otel/opentelemetry-collector-contrib\n\n    # Configure OpenTelemetry\n    configure_otel()\n\n    # Example OpenAI Agent usage\n    assistant = Agent(\n        name=\"Travel Concierge\",\n        instructions=\"You are a concise travel concierge.\",\n        tools=[get_weather],\n    )\n\n    print(\"Running agent...\")\n    # Provide dummy API key if required by 'openai-agents', though it might be configured via env vars.\n    # For real use, ensure OpenAI API key is set via environment variable, e.g., OPENAI_API_KEY\n    os.environ['OPENAI_API_KEY'] = os.environ.get('OPENAI_API_KEY', 'sk-dummy-key-for-example')\n\n    result = Runner.run_sync(assistant, \"I'm visiting Barcelona this weekend. How should I pack?\")\n    print(f\"Agent final output: {result.final_output}\")\n    print(\"Traces should now be visible in your configured OpenTelemetry backend.\")\n","lang":"python","description":"This quickstart demonstrates how to set up the OpenTelemetry Python SDK with an OTLP exporter and then enable instrumentation for OpenAI Agents. After running this code, traces generated by the agent's operations will be sent to the configured OpenTelemetry collector. Make sure an OpenTelemetry collector is running and accessible.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-15","installed_version":"0.50.1","pypi_latest":"0.60.0","is_stale":true,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":9.4,"avg_import_s":0.39,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"opentelemetry-instrumentation-openai-agents","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.33,"mem_mb":9.3,"disk_size":"93.1M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"opentelemetry-instrumentation-openai-agents","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":11.3,"import_time_s":0.24,"mem_mb":9.3,"disk_size":"92M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"opentelemetry-instrumentation-openai-agents","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.49,"mem_mb":10.6,"disk_size":"102.0M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"opentelemetry-instrumentation-openai-agents","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":10.1,"import_time_s":0.43,"mem_mb":10.6,"disk_size":"101M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"opentelemetry-instrumentation-openai-agents","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.69,"mem_mb":12.8,"disk_size":"92.1M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"opentelemetry-instrumentation-openai-agents","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":8.3,"import_time_s":0.64,"mem_mb":12.8,"disk_size":"91M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"opentelemetry-instrumentation-openai-agents","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.29,"mem_mb":7.9,"disk_size":"92.0M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"opentelemetry-instrumentation-openai-agents","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":8.4,"import_time_s":0.29,"mem_mb":7.9,"disk_size":"91M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"opentelemetry-instrumentation-openai-agents","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.3,"mem_mb":8.5,"disk_size":"61.9M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"opentelemetry-instrumentation-openai-agents","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":9,"import_time_s":0.24,"mem_mb":8.5,"disk_size":"61M"}]}}