Registry / observability / opentelemetry-instrumentation-asyncclick

opentelemetry-instrumentation-asyncclick

JSON →
library0.63b1pypypiunverified

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.

pip install opentelemetry-instrumentation-asyncclick asyncclick opentelemetry-sdk
INSTALL
IMPORT
SIG · OPENTELEMETRY-INST
O
opentelemetry-instrumentation-asyncclick
observabilitypythonv0.63b1
Install
2.8s avg
Import
420ms
Disk
23MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.63b1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.340s · 24.6MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.8s · import 0.331s · 25MB
23MB installed
● package 23MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AsyncClickInstrumentor
from opentelemetry.instrumentation.asyncclick import AsyncClickInstrumentor

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.

import asyncio from opentelemetry import trace from opentelemetry.sdk.resources import Resource from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor from opentelemetry.instrumentation.asyncclick import AsyncClickInstrumentor import asyncclick as click # Configure OpenTelemetry SDK resource = Resource.create({"service.name": "asyncclick-app"}) tracer_provider = TracerProvider(resource=resource) span_processor = SimpleSpanProcessor(ConsoleSpanExporter()) tracer_provider.add_span_processor(span_processor) trace.set_tracer_provider(tracer_provider) # Enable asyncclick instrumentation AsyncClickInstrumentor().instrument() # Define an async click command @click.group() async def cli(): "A simple async Click CLI." pass @cli.command() @click.option('--name', default='World', help='Name to greet.') async def hello(name): "Greets the given name." current_span = trace.get_current_span() current_span.set_attribute("greeting.name", name) click.echo(f"Hello, {name}!") await asyncio.sleep(0.05) click.echo("Greeting complete.") @cli.command() async def goodbye(): "Says goodbye." click.echo("Goodbye!") await asyncio.sleep(0.01) async def main(): # Simulate running a command, e.g., 'python your_app.py hello --name Alice' # In a real scenario, click.Group.main() would handle argv parsing. # For this example, we'll manually invoke the command. ctx = click.Context(cli, info_name='cli') await cli.invoke(ctx) # You can also simulate calling specific commands directly # await hello.callback(name="Bob") # await goodbye.callback() if __name__ == '__main__': # This part typically handles the command line invocation # For demonstration, we'll run the 'hello' command as if it was passed via argv # Note: asyncclick.main() internally uses asyncio.run() or anyio.run() # We are directly running an async function, so manually setup invocation. # This mimics `cli(['hello', '--name', 'OpenTelemetry'])` but for async context async def _run_cli_command(): ctx = click.Context(cli, obj={}, auto_envvar_prefix='OTEL') await cli.invoke(ctx) await hello.invoke(ctx, name='OpenTelemetry') await goodbye.invoke(ctx) asyncio.run(_run_cli_command()) # Ensure all spans are exported before exiting tracer_provider.shutdown()
Debug
Known issues
betaThis instrumentation package is currently in beta. This means its API and functionality might change in future releases, potentially introducing breaking changes or incomplete features. It is generally not recommended for production environments where stability is critical.
fix
Monitor release notes for `opentelemetry-python-contrib` for updates and breaking changes. Consider stability implications for production use.
affects: 0.x.x
gotchaThe `opentelemetry-instrumentation-asyncclick` package only provides instrumentation for `asyncclick`. It does not automatically install `asyncclick` itself. You must explicitly install `asyncclick` (or `click` if using the standard one) for your application to function.
fix
Ensure `asyncclick` is installed alongside the instrumentation: `pip install opentelemetry-instrumentation-asyncclick asyncclick`.
affects: All
gotchaThis instrumentation provides manual instrumentation. If you are looking for zero-code automatic instrumentation, you would typically use `opentelemetry-instrument` CLI, which detects and instruments supported libraries at runtime. However, for `asyncclick`, explicit `instrument()` call is typically required.
fix
To use this package, call `AsyncClickInstrumentor().instrument()` programmatically in your application's entry point before `asyncclick` commands are run. For other common libraries, consider `opentelemetry-bootstrap -a install` and `opentelemetry-instrument python your_app.py`.
affects: All
Upgrade
Version history
0.63b1latest on PyPI · released May 21, 2026
Audit
Dependencies
asyncclickrequiredThis is the library being instrumented; it must be installed for the instrumentation to function.
opentelemetry-apirequiredCore OpenTelemetry API for defining and creating telemetry data.
opentelemetry-sdkrequiredOpenTelemetry SDK for processing and exporting telemetry data.
opentelemetry-semantic-conventionsrequiredProvides standard attribute names for consistent telemetry.
wraptrequiredUsed by OpenTelemetry instrumentations for monkey-patching.
Agent activity
13 hits · last 30 days
node
10
OpenAI (training)
2
Resources
opentelemetry-instrumentation-asyncclick — pip install opentelemetry-instrumentation-asyncclick · libregistry