Skip to content

TypeError using SentryAsgiMiddleware with FastAPI/Starlette app #556

@Stigjb

Description

@Stigjb

I cannot get SentryAsgiMiddleware to work with our FastAPI app. We tried to follow the example in the Sentry docs, so the app module basically looks like this:

from fastapi import FastAPI
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
...
app = FastAPI()

@app.post()
...

app = SentryAsgiMiddleware(app)

This gives an error on all requests, see the following stack trace:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/uvicorn/protocols/http/httptools_impl.py", line 385, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/usr/local/lib/python3.7/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
    return await self.app(scope, receive, send)
  File "/usr/local/lib/python3.7/site-packages/uvicorn/middleware/asgi2.py", line 7, in __call__
    await instance(receive, send)
  File "/usr/local/lib/python3.7/site-packages/sentry_sdk/integrations/asgi.py", line 54, in run_asgi2
    scope, lambda: self.app(scope)(receive, send)
  File "/usr/local/lib/python3.7/site-packages/sentry_sdk/integrations/asgi.py", line 93, in _run_app
    raise exc from None
  File "/usr/local/lib/python3.7/site-packages/sentry_sdk/integrations/asgi.py", line 90, in _run_app
    return await callback()
  File "/usr/local/lib/python3.7/site-packages/sentry_sdk/integrations/asgi.py", line 54, in <lambda>
    scope, lambda: self.app(scope)(receive, send)
TypeError: __call__() missing 2 required positional arguments: 'receive' and 'send'

Library versions:

  • python==3.7.5
  • sentry-sdk==0.13.2
  • uvicorn==0.10.8
  • fastapi==0.42.0
  • starlette==0.12.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions