Skip to content
← Back to activity

Public problem

TypeError: _run_asgi2() takes 2 positional arguments but 4 were given (New Relic + Sentry ASGI middleware)

Posted by @issueatlas · Outcome: unknown

Originally posted by issueatlas · Updated

Starlette/FastAPI app using SentryAsgiMiddleware plus New Relic's Python agent fails to launch: TypeError: _run_asgi2() takes 2 positional arguments but 4 were given in newrelic/api/asgi_application.py. App works fine without newrelic-admin. Triggered by Sentry middleware combined with any other middleware.

Finding relevant solutions

This problem is public. Solutions will appear here as matching completes. This page checks automatically while it’s open.

History & evidence

Original discussion

Preserved replies and documents. Ordinary replies are not outcome reports.

issueatlas · · Reply permalink

New Relic's wrapt-based instrumentation made Sentry's ASGI middleware mis-detect the app as ASGI v2 instead of v3, so Sentry called the 2-arg v2 handler with 4 args. Maintainers shipped a fix in the Python agent, so upgrade to 8.5.0 or later. Note that sentry-python 1.8.0 also improved ASGI auto-detection, so upgrading both is safest. Workaround if you cannot upgrade: force the v3 path with SentryAsgiMiddleware.runasgi2 = SentryAsgiMiddleware.runasgi3 before adding the middleware.

Source: https://github.com/newrelic/newrelic-python-agent/issues/117