跳转到主要内容

OpenTelemetry asyncio 仪表盘

项目描述

pypi

AsyncioInstrumentor: 跟踪由 Asyncio 库发出的请求

opentelemetry-instrumentation-asyncio 软件包允许跟踪 asyncio 应用程序。它还包括协程和未来的持续时间及计数的度量。即使协程没有被跟踪,也会生成度量。

设置您想要跟踪的协程的名称。

export OTEL_PYTHON_ASYNCIO_COROUTINE_NAMES_TO_TRACE=coro_name,coro_name2,coro_name3

如果您想跟踪使用 asyncio 的 to_thread 函数执行的特定阻塞函数,请在 OTEL_PYTHON_ASYNCIO_TO_THREAD_FUNCTION_NAMES_TO_TRACE 中设置函数的名称。

export OTEL_PYTHON_ASYNCIO_TO_THREAD_FUNCTION_NAMES_TO_TRACE=func_name,func_name2,func_name3

您可以通过 OTEL_PYTHON_ASYNCIO_FUTURE_TRACE_ENABLED 启用未来的跟踪

export OTEL_PYTHON_ASYNCIO_FUTURE_TRACE_ENABLED=true

运行已配置的应用程序

1. 协程

# export OTEL_PYTHON_ASYNCIO_COROUTINE_NAMES_TO_TRACE=sleep

import asyncio
from opentelemetry.instrumentation.asyncio import AsyncioInstrumentor

AsyncioInstrumentor().instrument()

async def main():
    await asyncio.create_task(asyncio.sleep(0.1))

asyncio.run(main())

2. 未来

# export OTEL_PYTHON_ASYNCIO_FUTURE_TRACE_ENABLED=true

loop = asyncio.get_event_loop()

future = asyncio.Future()
future.set_result(1)
task = asyncio.ensure_future(future)
loop.run_until_complete(task)

3. to_thread

# export OTEL_PYTHON_ASYNCIO_TO_THREAD_FUNCTION_NAMES_TO_TRACE=func

import asyncio
from opentelemetry.instrumentation.asyncio import AsyncioInstrumentor

AsyncioInstrumentor().instrument()

async def main():
    await asyncio.to_thread(func)

def func():
    pass

asyncio.run(main())

asyncio 度量类型

  • asyncio.process.duration (秒) - asyncio 进程的持续时间

  • asyncio.process.count (计数) - asyncio 进程的数量

API

安装

pip install opentelemetry-instrumentation-asyncio

参考

项目详情


下载文件

下载适用于您平台文件的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码分发

opentelemetry_instrumentation_asyncio-0.48b0.tar.gz (12.6 kB 查看哈希值)

上传时间 源代码

构建分发

由以下机构支持