ASGI Middlewareedit

This functionality is in technical preview and may be changed or removed in a future release. Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features.

Incorporating Elastic APM into your ASGI-based project only requires a few easy steps.

Several ASGI frameworks are supported natively. Please check Supported Technologies for more information


Install the Elastic APM agent using pip:

$ pip install elastic-apm

or add elastic-apm to your project’s requirements.txt file.


To set up the agent, you need to initialize it with appropriate settings.

The settings are configured either via environment variables, or as initialization arguments.

You can find a list of all available settings in the Configuration page.

To set up the APM agent, wrap your ASGI app with the ASGITracingMiddleware:

from elasticapm.contrib.asgi import ASGITracingMiddleware

app = MyGenericASGIApp()  # depending on framework

app = ASGITracingMiddleware(app)

Make sure to call elasticapm.set_transaction_name() with an appropriate transaction name in all your routes.

Currently, the agent doesn’t support automatic capturing of exceptions. You can follow progress on this issue on Github.

Supported Python versionsedit

A list of supported Python versions can be found on our Supported Technologies page.

Elastic APM only supports asyncio when using Python 3.7+