Search code examples
pythonsentryquart

Using Sentry.io with QuartTrio - Has anyone got this working?


Has anyone been able to make Sentry.io work with QuartTrio? I have made the simplest app, literally copied from the example code at (https://quart-trio.readthedocs.io/en/latest/tutorials/deployment.html):

from quart_trio import QuartTrio

app = QuartTrio(__name__)

@app.route('/')
async def hello():
    return 'Hello World'

And then I'm running it with hypercorn -k trio quarttriosentry:app and all working as expected.

But as soon as I add the sentry SDK I get a crash:

  • Run pip install --upgrade sentry-sdk
  • Add the most basic sentry code block:
from quart_trio import QuartTrio
import sentry_sdk

sentry_sdk.init(
    dsn="https://<removed>@<removed>.ingest.de.sentry.io/<removed>",
    # Enable performance monitoring
    enable_tracing=True,
)

app = QuartTrio(__name__)

@app.route('/')
async def hello():
    return 'Hello World'

I now get a crash:

> hypercorn -k trio quarttriosentry:app
Process SpawnProcess-1:
  + Exception Group Traceback (most recent call last):
  |   File "/usr/lib/python3.10/multiprocessing/process.py", line 314, in _bootstrap
  |     self.run()
  |   File "/usr/lib/python3.10/multiprocessing/process.py", line 108, in run
  |     self._target(*self._args, **self._kwargs)
  |   File "/home/jtuckey/.pyenv/versions/quarttriosentry/lib/python3.10/site-packages/hypercorn/trio/run.py", line 127, in trio_worker
  |     trio.run(partial(worker_serve, app, config, sockets=sockets, shutdown_trigger=shutdown_trigger))
  |   File "/home/jtuckey/.pyenv/versions/quarttriosentry/lib/python3.10/site-packages/trio/_core/_run.py", line 2288, in run
  |     raise runner.main_task_outcome.error
  |   File "/home/jtuckey/.pyenv/versions/quarttriosentry/lib/python3.10/site-packages/hypercorn/trio/run.py", line 46, in worker_serve
  |     async with trio.open_nursery() as lifespan_nursery:
  |   File "/home/jtuckey/.pyenv/versions/quarttriosentry/lib/python3.10/site-packages/trio/_core/_run.py", line 954, in __aexit__
  |     raise combined_error_from_nursery
  | exceptiongroup.ExceptionGroup: Exceptions from Trio nursery (1 sub-exception)
  +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    |   File "/home/jtuckey/.pyenv/versions/quarttriosentry/lib/python3.10/site-packages/hypercorn/trio/run.py", line 48, in worker_serve
    |     await lifespan.wait_for_startup()
    |   File "/home/jtuckey/.pyenv/versions/quarttriosentry/lib/python3.10/site-packages/hypercorn/trio/lifespan.py", line 66, in wait_for_startup
    |     await self.app_send_channel.send({"type": "lifespan.startup"})
    |   File "/home/jtuckey/.pyenv/versions/quarttriosentry/lib/python3.10/site-packages/trio/_channel.py", line 194, in send
    |     self.send_nowait(value)
    |   File "/home/jtuckey/.pyenv/versions/quarttriosentry/lib/python3.10/site-packages/trio/_core/_ki.py", line 181, in wrapper
    |     return fn(*args, **kwargs)
    |   File "/home/jtuckey/.pyenv/versions/quarttriosentry/lib/python3.10/site-packages/trio/_channel.py", line 172, in send_nowait
    |     raise trio.ClosedResourceError
    | trio.ClosedResourceError
    +------------------------------------

I'm not really sure what's going on here, or even where to get started debugging it? Any help would be appreciated.


Solution

  • It seems this might just be a bug in the Quart integration in Sentry.io.

    See bug: https://github.com/getsentry/sentry-python/issues/3040

    They have said they will fix this (for Quart) in the next release.

    I have tested using sentry-sdk version 1.45.0 and it is working correctly on both Quart and QuartTrio - command to install v1.45.0 was:

    pip install --upgrade 'sentry-sdk[quart]<2.0.0'
    

    I will test again once the bug is fixed for Quart.

    Edit: Tested with both Quart and QuartTrio on v2.1.1 - all working correctly.