ASGI¶
If the ASGI framework doesn't have a dedicated OpenTelemetry package, you can use the OpenTelemetry ASGI middleware.
Установка¶
You need to install the opentelemetry-instrumentation-asgi пакет:
pip install opentelemetry-instrumentation-asgi
Usage¶
Below We have a minimal example using Uvicorn Ты можешь справиться с ним python main.py:
main.py
import logfire
from opentelemetry.instrumentation.asgi import OpenTelemetryMiddleware
logfire.configure()
async def app(scope, receive, send):
assert scope["type"] == "http"
await send(
{
"type": "http.response.start",
"status": 200,
"headers": [(b"content-type", b"text/plain"), (b"content-length", b"13")],
}
)
await send({"type": "http.response.body", "body": b"Hello, world!"})
app = OpenTelemetryMiddleware(app)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app)
Вы можете прочитать больше о OpenTelemetry ASGI middleware here.
Capturing request and response headers¶
本文总阅读量次