Connect Strawberry GraphQL to Bugsink

When a Strawberry resolver fails, Bugsink shows the original exception and resolver frame together with the named GraphQL operation and HTTP request.

This guide adds error reporting to an existing ASGI Strawberry service. You’ll initialize the SDK before building the schema, send a named query which fails inside a resolver, and see the result in Bugsink. To follow along, create a Bugsink project and copy its DSN; the quickstart guide shows where to find it.

Install the SDK

Install the open-source Sentry Python SDK in the environment which runs your GraphQL service. Bugsink accepts the SDK’s error events directly, so the DSN can point at your Bugsink project:

python -m pip install --upgrade sentry-sdk

Initialize the Strawberry integration

Import the SDK and Strawberry integration in the module where the schema is created:

import os

import sentry_sdk
import strawberry
from sentry_sdk.integrations.strawberry import StrawberryIntegration

Initialize the SDK before calling strawberry.Schema(). This lets the integration add its error hook as the schema is built. async_execution=True matches an ASGI application or a schema with asynchronous resolvers; use False only when schema execution is entirely synchronous:

sentry_sdk.init(
    dsn=os.environ["SENTRY_DSN"],
    integrations=[StrawberryIntegration(async_execution=True)],
)

Set the DSN in the environment where the application runs:

export SENTRY_DSN=https://key@bugsink.example/1

Trigger a resolver error

Resolver errors normally become entries in GraphQL’s errors array rather than escaping as an HTTP server exception. The Strawberry integration sees that result and reports the original application exception automatically; the resolver itself contains no Bugsink-specific call:

@strawberry.type
class Query:
    @strawberry.field
    def product(self, sku: str) -> Product:
        try:
            item = inventory[sku]
        except KeyError:
            raise ProductNotFound(f"Product {sku} is not in inventory") from None
        return Product(sku=sku, **item)

Start the application as usual:

uvicorn app:app

Send a named query which reaches the failing resolver:

curl --json '{"query":"query FindProduct($sku: String!) { product(sku: $sku) { sku name available } }","variables":{"sku":"strawberry-missing"},"operationName":"FindProduct"}' http://127.0.0.1:8000/graphql/

Strawberry keeps its normal HTTP 200 response with data: null and a GraphQL error. That response does not mean error reporting failed.

See the resolver error in Bugsink

Open your Bugsink project and select the new issue. Strawberry wraps resolver failures in GraphQLError, so that is the issue type Bugsink uses for grouping. The event still shows the original ProductNotFound exception, points to the resolver line, names the FindProduct operation, and includes the POST request.

Bugsink preview

That’s it: resolver failures will now be reported to Bugsink while Strawberry continues to control the GraphQL response.

For handled exceptions, logging, messages, and additional context options, continue with the Python guide.