Ariadne

Learn about importing the Ariadne GraphQL integration and how it captures GraphQL errors.

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

To get started, install sentry-sdk from PyPI.

Copied
pip install --upgrade sentry-sdk

Add AriadneIntegration() to your integrations list:

Copied
import sentry_sdk
from sentry_sdk.integrations.ariadne import AriadneIntegration

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

Create a file called app.py with the following contents:

Copied
from ariadne import QueryType, gql, make_executable_schema
from ariadne.asgi import GraphQL

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

type_defs = gql(
    """
    type Query {
        hello: String!
    }
"""
)

query = QueryType()

@query.field("hello")
def resolve_hello(*_):
    1 / 0
    return "Hello!"

schema = make_executable_schema(type_defs, query)
app = GraphQL(schema, debug=True)

Make sure you have uvicorn installed:

Copied
pip install uvicorn

And finally run your GraphQL web server with:

Copied
uvicorn app:app

Open http://127.0.0.1:8000 in your browser. You should see the GraphiQL graphical user interface.

Enter { hello } into the query field then press the "Execute query" button. Your web app will be queried and will encounter the ZeroDivisionError error we've snuck into the resolve_hello resolver function.

This will create a corresponding GraphQLError in the Issues section of sentry.io. It will take a couple of moments for the data to appear in Sentry.

The Ariadne integration can capture request and response payload for each GraphQL error that happens. Since these may contain sensitive data, the SDK needs to be initialized with the send_default_pii option set to True.

By default, no request and response data will be attached.

Copied
sentry_sdk.init(
    # same options as above
    send_default_pii=True,
)

  • ariadne: 0.20+
  • 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").