The ASGI middleware can be used to instrument any ASGI-compatible web framework to attach request data for your events.
import sentry_sdk from sentry_sdk.integrations.asgi import SentryAsgiMiddleware from myapp import asgi_app sentry_sdk.init( dsn="https://examplePublicKey@o0.ingest.sentry.io/0", # Set traces_sample_rate to 1.0 to capture 100% # of transactions for performance monitoring. # We recommend adjusting this value in production, traces_sample_rate=1.0, ) asgi_app = SentryAsgiMiddleware(asgi_app)
The middleware supports both ASGI 2 and ASGI 3 transparently.
Request data is attached to all events: HTTP method, URL, headers. Sentry excludes raw bodies and multipart file uploads. Sentry also excludes personally identifiable information (such as user ids, usernames, cookies, authorization headers, IP addresses) unless you set
Each request has a separate scope. Changes to the scope within a view, for example setting a tag, will only apply to events sent as part of the request being handled.
The ASGI middleware does not behave like a regular integration. It is not initialized through an extra parameter to
initand is not attached to a client. When capturing or supplementing events, it just uses the currently active hub.