question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError using SentryAsgiMiddleware with FastAPI/Starlette app

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
untitakercommented, Nov 25, 2019

0.13.3 has been released, sorry for the delay

2reactions
untitakercommented, Nov 19, 2019

@Stigjb sometime this week

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced Middleware - FastAPI
As FastAPI is based on Starlette and implements the ASGI specification, you can use any ASGI middleware. A middleware doesn't have to be...
Read more >
tiangolo/fastapi - Gitter
Hey guys,. I'm developing a FastAPI app and was experimenting with Celery as a task queue. However, it seems that it often just...
Read more >
Python and FastAPI: keep getting 405 when posting response
First, you need to change request in the lectio_root resp = requests.post(url, data=payload, headers=headers). to resp = requests.get(url, ...
Read more >
Introducing Starlite: A New Python Asynchronous API ...
The idea to use Starlette and pydantic as bases is of course not new - it ... from typing import Optional from fastapi...
Read more >
ASGI - Sentry Documentation
Learn about using Sentry with ASGI applications. ... If you use an ASGI framework, please use our specific integrations for FastAPI, Starlette, Sanic, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found