Timing-asgi is an ASGI middleware designed to automatically instrument ASGI endpoints and emit timing metrics. Developed by GRID, it's particularly useful for integrating with statsd-based cloud monitoring services like Datadog. The library currently supports ASGI3 and is actively maintained, with version 0.3.2 being the latest release.
pip install timing-asgiVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to integrate `timing-asgi` with a Starlette application. It defines a custom `TimingClient` that prints the collected metrics to the console. The `TimingMiddleware` is added to the Starlette application, configured with the custom client and a `StarletteScopeToName` metric namer to generate meaningful metric names based on the Starlette routes.
Ensure your ASGI server and application framework are ASGI3 compliant. If not, downgrade to `timing-asgi==0.1.2`.
Currently, there is no direct fix within `timing-asgi` for lifespan event instrumentation. Consider external tools or custom instrumentation for application startup/shutdown timings.
Adhere strictly to the `TimingClient` interface by implementing the `timing` method as specified in the base class.
Explicitly pass an appropriate `metric_namer` to `TimingMiddleware`. For Starlette, use `StarletteScopeToName(prefix="your_app_name", starlette_app=app)`.
pip install timing-asgi
app.add_middleware(TimingMiddleware, recorder=DatadogRecorder(client=statsd_client), channel=StarletteInfo())
statsd_client = statsd.StatsClient(host='localhost', port=8125) recorder=DatadogRecorder(client=statsd_client)
No dependency data recorded yet.