跳转至

Redis

logfire.instrument_redis() 方法将为 Redis 客户端执行的每个命令创建一个跨度。

安装

使用 redis extra 安装 logfire

pip install 'logfire[redis]'
rye add logfire -E redis
poetry add 'logfire[redis]'

用法

让我们看下面一个最小的例子:

main.py
import logfire
import redis


logfire.configure()
logfire.instrument_redis()

# This will report a span with the default settings
client = redis.StrictRedis(host="localhost", port=6379)
client.get("my-key")

# This will report a span with the default settings
async def main():
    client = redis.asyncio.Redis(host="localhost", port=6379)
    await client.get("my-key")

if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

logfire.instrument_redis() 的关键字参数被传递给 OpenTelemetry Redis Instrumentation 包的 RedisInstrumentor().instrument() 方法,请在此处阅读更多相关信息。


本文总阅读量