Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sentry integration broken in latest version 0.240.2 #3623

Open
jaydensmith opened this issue Sep 12, 2024 · 6 comments
Open

Sentry integration broken in latest version 0.240.2 #3623

jaydensmith opened this issue Sep 12, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@jaydensmith
Copy link

jaydensmith commented Sep 12, 2024

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

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@jaydensmith jaydensmith added the bug Something isn't working label Sep 12, 2024
@patrick91
Copy link
Member

mmh, interesting, I'll try to investigate soon

@patrick91
Copy link
Member

@jaydensmith this seems to be working for me, can you provide more info? 😊

@knksmith57
Copy link

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

@patrick91
Copy link
Member

@knksmith57 are you able to get a minimal reproduction? 😊

@patrick91 patrick91 reopened this Sep 20, 2024
@knksmith57
Copy link

knksmith57 commented Sep 20, 2024

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?

@knksmith57
Copy link

knksmith57 commented Sep 20, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants