Graphene

The Graphene integration captures errors from the Graphene GraphQL library, which can then be viewed in Sentry.

To get started, install sentry-sdk from PyPI.

Copied
pip install --upgrade sentry-sdk

Add GrapheneIntegration() to your integrations list:

Copied
import sentry_sdk
from sentry_sdk.integrations.graphene import GrapheneIntegration

sentry_sdk.init(
    dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
    enable_tracing=True,
    integrations=[
        GrapheneIntegration(),
    ],
)

To verify:

Copied
import graphene

sentry_sdk.init(...)  # same as above

class Query(graphene.ObjectType):
    hello = graphene.String()

    def resolve_hello(self, info):
        1 / 0
        return "World"

schema = graphene.Schema(query=Query)

schema.execute("""
  query {
    hello
  }
""")

We've snuck a ZeroDivisionError into our resolve_hello resolver to ensure things are working as intended. When this code snippet is run, a new error event should appear in the Issues section of sentry.io. It will take a couple of moments for the data to appear in sentry.io.

When used together with one of our web framework integrations like FastAPI or Flask, the Graphene integration can capture the request body for each GraphQL error that happens. Since the requests may contain sensitive data, no request bodies will be attached by default.

To capture request bodies:

  • Initialize the SDK with the send_default_pii option set to True.
  • Make sure the integration for the web framework you're using is enabled.
Copied
sentry_sdk.init(
    # same options as above
    send_default_pii=True,
)

  • graphene: 3.3+
  • Python: 3.8+
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").