getsentry / sentry-python

The official Python SDK for Sentry.io
https://sentry.io/for/python/
MIT License
1.76k stars 462 forks source link

[Quart] sentry_patched_asgi_app() missing 1 required positional argument: 'send' #3040

Closed KingsleyKelly closed 4 weeks ago

KingsleyKelly commented 4 weeks ago

How do you use Sentry?

Sentry Saas (sentry.io)

Version

latest

Steps to Reproduce

Requirements

aiohttp==3.8.1
annotated-types==0.6.0
anyio==4.2.0
blinker==1.7.0
beautifulsoup4==4.10.0
cachetools==5.3.2
certifi==2023.11.17
charset-normalizer==2.1.1
click==8.1.7
distro==1.9.0
quart
google-ads==21.3.0
google-api-core==2.15.0
google-api-python-client==2.15.0
google-auth==2.25.1
google-auth-httplib2==0.1.0
google-auth-oauthlib==0.4.6
googleapis-common-protos==1.61.0
grpcio==1.59.3
grpcio-status==1.59.3
hypercorn
h11==0.14.0
httpcore==1.0.2
httplib2==0.22.0
httpx==0.26.0
idna==3.6
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.3
oauthlib==3.2.2
openai==1.6.1
packaging==23.2
proto-plus==1.22.3
protobuf==4.25.1
psycopg2-binary==2.9.9
pyasn1==0.5.1
pyasn1-modules==0.3.0
pydantic==2.5.3
pydantic_core==2.14.6
pyparsing==3.1.1
pytest==6.2.5
PyYAML==6.0.1
requests==2.31.0
requests-oauthlib==1.3.1
rsa==4.9
six==1.16.0
sniffio==1.3.0
tqdm==4.66.1
typing_extensions==4.9.0
uritemplate==3.0.1
urllib3==2.1.0
Werkzeug==3.0.1
protobuf==4.25.1
cachetools==5.3.2
mock==5.1.0
pytest-env==0.6.2
sentry-sdk[quart]
python-dotenv==0.19.1

Note that sentry, hypercorn and quart arent locked.

With the following invocation

import sentry_sdk
from sentry_sdk.integrations.quart import QuartIntegration
sentry_sdk.init(
    dsn="https://94e1b1ff4eb4da3636a3e8d55c2c0acf@o4506739227426816.ingest.sentry.io/4506739299254272",
    auto_enabling_integrations=False,
    integrations=[QuartIntegration()],
    # Set traces_sample_rate to 1.0 to capture 100%
    # of transactions for performance monitoring.
    traces_sample_rate=1.0,
    # Set profiles_sample_rate to 1.0 to profile 100%
    # of sampled transactions.
    # We recommend adjusting this value in production.
    profiles_sample_rate=1.0,

It gives the following error

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/hypercorn/asyncio/task_group.py", line 27, in _handle
    await app(scope, receive, send, sync_spawn, call_soon)
  File "/usr/local/lib/python3.8/site-packages/hypercorn/app_wrappers.py", line 51, in __call__
    await self.handle_http(scope, receive, send, sync_spawn, call_soon)
  File "/usr/local/lib/python3.8/site-packages/hypercorn/app_wrappers.py", line 83, in handle_http
    await sync_spawn(self.run_app, environ, partial(call_soon, send))
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.8/site-packages/hypercorn/app_wrappers.py", line 107, in run_app
    response_body = self.app(environ, start_response)
  File "/usr/local/lib/python3.8/site-packages/sentry_sdk/utils.py", line 1711, in runner
    return sentry_patched_function(*args, **kwargs)
TypeError: sentry_patched_asgi_app() missing 1 required positional argument: 'send' 

Expected Result

We can use Sentry

Actual Result

App 404s all requests

KingsleyKelly commented 4 weeks ago

I resolved this by rolling back to version 1.

Is there a way this can fail gracefully in the future or raise an "This is an issue with the Sentry SDK" type error message as it was only after rolling back our app and all changes I realised it was Sentry, from the error I assumed a request being passed to sentry was malformed.

szokeasaurusrex commented 4 weeks ago

Thanks for the issue report. This indeed appears to be a regression – I was able to reproduce the error here (although I received 500 status codes, not 404 as stated in this issue). But, the error message is the same.

szokeasaurusrex commented 4 weeks ago

Hey @KingsleyKelly, so we have a fix (#3043) for this issue already. We plan to release the fix on Monday (May 6) in the morning (CET). Until then, please use version 1.x to work around this issue.

We apologize for any inconvenience caused by this bug.

szokeasaurusrex commented 3 weeks ago

@KingsleyKelly We just released version 2.1.0, which should fix this problem!

jay-tuckey commented 3 weeks ago

Thanks @szokeasaurusrex I will give it a test tomorrow also.

jay-tuckey commented 3 weeks ago

Thanks @szokeasaurusrex I will give it a test tomorrow also.

Tested with both Quart and QuartTrio - all working well. Thanks for the quick fix.