strawberry
strawberry copied to clipboard
Sentry integration broken in latest version 0.240.2
After updating Sentry (2.14.0) and Strawberry to the latest version, I get a fatal error:
Traceback (most recent call last):
File "/opt/pysetup/.venv/lib/python3.11/site-packages/graphql/execution/execute.py", line 530, in await_result
return_type, field_nodes, info, path, await result
^^^^^^^^^^^^
File "/opt/pysetup/.venv/lib/python3.11/site-packages/sentry_sdk/integrations/strawberry.py", line 254, in resolve
with self.graphql_span.start_child(
^^^^^^^^^^^^^^^^^
AttributeError: 'SentryAsyncExtension' object has no attribute 'graphql_span'
System Information
- Strawberry version (if applicable): 0.240.2
mmh, interesting, I'll try to investigate soon
@jaydensmith this seems to be working for me, can you provide more info? 😊
This is broken for us as well:
Traceback (most recent call last):
File "/app/.venv/lib/python3.12/site-packages/graphql/execution/execute.py", line 528, in await_result
return_type, field_nodes, info, path, await result
^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/sentry_sdk/integrations/strawberry.py", line 254, in resolve
with self.graphql_span.start_child(
^^^^^^^^^^^^^^^^^
AttributeError: 'SentryAsyncExtension' object has no attribute 'graphql_span'
Versions:
❯ poetry show sentry-sdk
name : sentry-sdk
version : 2.14.0
description : Python client for Sentry (https://sentry.io)
dependencies
- asyncpg >=0.23
- certifi *
- fastapi >=0.79.0
- httpx >=0.16.0
- sqlalchemy >=1.2
- starlette >=0.19.1
- urllib3 >=1.26.11
❯ poetry show strawberry-graphql
name : strawberry-graphql
version : 0.241.0
description : A library for creating GraphQL APIs
dependencies
- graphql-core >=3.2.0,<3.4.0
- libcst >=0.4.7
- pygments >=2.3,<3.0
- python-dateutil >=2.7.0,<3.0.0
- python-multipart >=0.0.7
- rich >=12.0.0
- starlette >=0.18.0
- typer >=0.7.0
- typing-extensions >=4.5.0
- uvicorn >=0.11.6
❯ poetry show fastapi
name : fastapi
version : 0.112.1
description : FastAPI framework, high performance, easy to learn, fast to code, ready for production
dependencies
- email_validator >=2.0.0
- fastapi-cli >=0.0.5
- httpx >=0.23.0
- itsdangerous >=1.1.0
- jinja2 >=2.11.2
- orjson >=3.2.1
- pydantic >=1.7.4,<1.8 || >1.8,<1.8.1 || >1.8.1,<2.0.0 || >2.0.0,<2.0.1 || >2.0.1,<2.1.0 || >2.1.0,<3.0.0
- pydantic-extra-types >=2.0.0
- pydantic-settings >=2.0.0
- python-multipart >=0.0.7
- pyyaml >=5.3.1
- starlette >=0.37.2,<0.39.0
- typing-extensions >=4.8.0
- ujson >=4.0.1,<4.0.2 || >4.0.2,<4.1.0 || >4.1.0,<4.2.0 || >4.2.0,<4.3.0 || >4.3.0,<5.0.0 || >5.0.0,<5.1.0 || >5.1.0
- uvicorn >=0.12.0
required by
- prometheus-fastapi-instrumentator >=0.38.1,<1.0.0
- sentry-sdk >=0.79.0
@knksmith57 are you able to get a minimal reproduction? 😊
I was just able to isolate to an underlying cause but not sure if it covers all cases.
We use a mix of sync and async resolvers and I had explicitly set async_execution=True per my understanding of the docs. This was working just fine until we upgraded:
StrawberryIntegration(
async_execution=True,
)
I'm not encountering that same exception anymore after removing the arg:
StrawberryIntegration()
But am also unsure of the consequences of removing the async_execution=True. A naive glance through the Sentry Extension code leads me to believe that either the Sync extension is installed or the Async extension is installed but not both. If that's true, what are the consequences given Strawberry explicitly supports mixing the two and we use both?
Aha, I think this is an ordering issue.
https://github.com/getsentry/sentry-python/blob/2.14.0/sentry_sdk/integrations/strawberry.py#L108-L121
# remove the built in strawberry sentry extension, if present
extensions = [
extension
for extension in extensions
if extension
not in (StrawberrySentryAsyncExtension, StrawberrySentrySyncExtension)
]
# add our extension
extensions.append(
SentryAsyncExtension if should_use_async_extension else SentrySyncExtension
)
kwargs["extensions"] = extensions
If I understand correctly, we want to prepend the Sentry extension here so that it runs before any other extension, right?
edit: or, if we want to be precise, in the case where the legacy extension was removed, insert the new extension at the same index to preserve the user's intended ordering.
Hey all, I am still experiencing the same error with these versions: sentry-sdk: 2.39.0 strawberry-graphql: 0.278.1 strawberry-graphql-django: 0.57.1
Any update on the issue?