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.
pip install --upgrade sentry-sdk
Add GrapheneIntegration()
to your integrations
list:
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:
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.
sentry_sdk.init(
# same options as above
send_default_pii=True,
)
Note
Since send_default_pii
is a global SDK option, setting it to True
affects all integrations, not just Graphene. Please make sure to take care of scrubbing sensitive data from events before enabling this option.
- graphene: 3.3+
- Python: 3.8+
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").
- Package:
- pypi:sentry-sdk
- Version:
- 1.45.0
- Repository:
- https://github.com/getsentry/sentry-python
- API Documentation:
- https://getsentry.github.io/sentry-python/