{"library":"opentelemetry-instrumentation-asyncclick","title":"Async Click Instrumentation for OpenTelemetry","description":"This library provides OpenTelemetry tracing for applications built with `asyncclick`, an asynchronous fork of the `click` library. It's part of the `opentelemetry-python-contrib` project, which maintains a monthly release cadence, and the instrumentation itself is currently in beta status, indicating potential for API changes.","language":"python","status":"active","last_verified":"Mon May 18","install":{"commands":["pip install opentelemetry-instrumentation-asyncclick asyncclick opentelemetry-sdk"],"cli":null},"imports":["from opentelemetry.instrumentation.asyncclick import AsyncClickInstrumentor"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import asyncio\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.asyncclick import AsyncClickInstrumentor\nimport asyncclick as click\n\n# Configure OpenTelemetry SDK\nresource = Resource.create({\"service.name\": \"asyncclick-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# Enable asyncclick instrumentation\nAsyncClickInstrumentor().instrument()\n\n# Define an async click command\n@click.group()\nasync def cli():\n    \"A simple async Click CLI.\"\n    pass\n\n@cli.command()\n@click.option('--name', default='World', help='Name to greet.')\nasync def hello(name):\n    \"Greets the given name.\"\n    current_span = trace.get_current_span()\n    current_span.set_attribute(\"greeting.name\", name)\n    click.echo(f\"Hello, {name}!\")\n    await asyncio.sleep(0.05)\n    click.echo(\"Greeting complete.\")\n\n@cli.command()\nasync def goodbye():\n    \"Says goodbye.\"\n    click.echo(\"Goodbye!\")\n    await asyncio.sleep(0.01)\n\nasync def main():\n    # Simulate running a command, e.g., 'python your_app.py hello --name Alice'\n    # In a real scenario, click.Group.main() would handle argv parsing.\n    # For this example, we'll manually invoke the command.\n    ctx = click.Context(cli, info_name='cli')\n    await cli.invoke(ctx)\n    \n    # You can also simulate calling specific commands directly\n    # await hello.callback(name=\"Bob\")\n    # await goodbye.callback()\n\nif __name__ == '__main__':\n    # This part typically handles the command line invocation\n    # For demonstration, we'll run the 'hello' command as if it was passed via argv\n    # Note: asyncclick.main() internally uses asyncio.run() or anyio.run()\n    # We are directly running an async function, so manually setup invocation.\n    \n    # This mimics `cli(['hello', '--name', 'OpenTelemetry'])` but for async context\n    async def _run_cli_command():\n        ctx = click.Context(cli, obj={}, auto_envvar_prefix='OTEL')\n        await cli.invoke(ctx)\n        await hello.invoke(ctx, name='OpenTelemetry')\n        await goodbye.invoke(ctx)\n\n    asyncio.run(_run_cli_command())\n\n    # Ensure all spans are exported before exiting\n    tracer_provider.shutdown()\n","lang":"python","description":"This quickstart demonstrates how to set up the OpenTelemetry SDK with a console exporter, enable the `asyncclick` instrumentation, and define a simple asynchronous Click CLI application. When executed, it will print traces for the `hello` and `goodbye` commands to the console, showcasing how command invocations are captured as spans. The `AsyncClickInstrumentor().instrument()` call should be made early in your application lifecycle, before `asyncclick` commands are invoked.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-18","installed_version":"0.62b1","pypi_latest":"0.62b1","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":2.9,"avg_import_s":0.42,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"opentelemetry-instrumentation-asyncclick","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"24.6M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"opentelemetry-instrumentation-asyncclick","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":3,"import_time_s":null,"mem_mb":null,"disk_size":"25M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"opentelemetry-instrumentation-asyncclick","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.45,"mem_mb":10.1,"disk_size":"27.3M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"opentelemetry-instrumentation-asyncclick","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.9,"import_time_s":0.42,"mem_mb":10.1,"disk_size":"28M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"opentelemetry-instrumentation-asyncclick","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.64,"mem_mb":12.3,"disk_size":"19.0M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"opentelemetry-instrumentation-asyncclick","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.4,"import_time_s":0.65,"mem_mb":12.3,"disk_size":"20M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"opentelemetry-instrumentation-asyncclick","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.27,"mem_mb":8.1,"disk_size":"18.7M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"opentelemetry-instrumentation-asyncclick","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.5,"import_time_s":0.27,"mem_mb":8.1,"disk_size":"19M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"opentelemetry-instrumentation-asyncclick","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.31,"mem_mb":10,"disk_size":"25.9M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"opentelemetry-instrumentation-asyncclick","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":3.6,"import_time_s":0.31,"mem_mb":10,"disk_size":"26M"}]}}