Skip to content

Opentelemetry instrumentation #35

@jomcgi

Description

@jomcgi

Would it be useful to flag this instrumentation package for asyncclick users?

Contrib repo with source code:
https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-asyncclick

PyPI:
https://pypi.org/project/opentelemetry-instrumentation-asyncclick/

pip install opentelemetry-instrumentation-asyncclick

Example usage:

import asyncio
import asyncclick
from opentelemetry.instrumentation.asyncclick import AsyncClickInstrumentor

AsyncClickInstrumentor().instrument()

@asyncclick.command()
async def hello():
    asyncclick.echo(f'Hello world!')

if __name__ == "__main__":
    asyncio.run(hello())

When this is configured with an exporter / receiver you get spans for each command with details like:

    span_attributes = {
        PROCESS_COMMAND_ARGS: sys.argv,
        PROCESS_EXECUTABLE_NAME: sys.argv[0],
        PROCESS_EXIT_CODE: 0,
        PROCESS_PID: os.getpid(),
    }

This can be useful for projects where you want to measure the latency of commands.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions