Connect GraphQL Java to Bugsink
When a GraphQL resolver fails, Bugsink can show the original exception and application frame together with the operation and data fetcher which were being executed.
This guide adds Bugsink to an existing GraphQL Java service. You’ll initialize the SDK, attach its GraphQL instrumentation, and send a named query which fails inside a product data fetcher while the service returns its normal GraphQL error response.
To follow along, create a Bugsink project and copy its DSN. The quickstart guide shows where to find it.
Install the GraphQL integration
Add the open-source Sentry integration which matches your GraphQL Java line.
GraphQL Java 22 and newer use sentry-graphql-22; GraphQL Java 17 through 21
use sentry-graphql instead. Bugsink accepts the SDK’s error events directly:
<dependency> <groupId>io.sentry</groupId> <artifactId>sentry-graphql-22</artifactId> <version>${sentry.version}</version> </dependency><dependency> <groupId>io.sentry</groupId> <artifactId>sentry-graphql-22</artifactId> <version>${sentry.version}</version> </dependency>
Initialize the SDK
Initialize the SDK once when the service starts. Reading the DSN from the
environment keeps it out of source control, while addInAppInclude marks your
own package as application code in the stack trace:
Sentry.init(options -> { options.setDsn(System.getenv("SENTRY_DSN")); options.addInAppInclude("com.example.inventory"); });Sentry.init(options -> { options.setDsn(System.getenv("SENTRY_DSN")); options.addInAppInclude("com.example.inventory"); });
Set the DSN in the environment where the GraphQL service runs:
export SENTRY_DSN=https://key@bugsink.example/1export SENTRY_DSN=https://key@bugsink.example/1
Instrument GraphQL execution
The exception handler retains failures raised by data fetchers, while the
instrumentation reports them after GraphQL has assembled the result. Together
they preserve GraphQL’s normal errors response and add the named operation,
field path, resolver details, and unhandled mechanism to the Bugsink event:
return GraphQL.newGraphQL(executableSchema) .defaultDataFetcherExceptionHandler(new SentryGenericDataFetcherExceptionHandler( new SimpleDataFetcherExceptionHandler())) .instrumentation(new SentryInstrumentation( NoOpSubscriptionHandler.getInstance(), true)) .build();return GraphQL.newGraphQL(executableSchema) .defaultDataFetcherExceptionHandler(new SentryGenericDataFetcherExceptionHandler( new SimpleDataFetcherExceptionHandler())) .instrumentation(new SentryInstrumentation( NoOpSubscriptionHandler.getInstance(), true)) .build();
NoOpSubscriptionHandler is the normal choice for a standalone query and
mutation service. Applications built on Spring GraphQL or Netflix DGS use the
subscription handler supplied for that framework.
Send a failing query
Start the service and send a named query for a product which does not exist:
mvn package java -jar target/inventory-graphql-1.0.0.jar :::bash curl http://127.0.0.1:8080/graphql \ -H 'content-type: application/json' \ --data '{"query":"query FindProduct($sku: ID!) { product(sku: $sku) { sku name } }","variables":{"sku":"graphql-missing"}}'mvn package java -jar target/inventory-graphql-1.0.0.jar :::bash curl http://127.0.0.1:8080/graphql \ -H 'content-type: application/json' \ --data '{"query":"query FindProduct($sku: ID!) { product(sku: $sku) { sku name } }","variables":{"sku":"graphql-missing"}}'
GraphQL returns HTTP 200 with its usual errors array and a null data
result. The integration reports the underlying data-fetcher exception without
changing that application response.
See the query failure in Bugsink
Open your Bugsink project and select the new ProductNotFound issue. The event
shows the application frame, while its breadcrumbs identify the FindProduct
query and /product data fetcher.
query
event time
graphql.fetcher
event time
That’s it: unexpected data-fetcher failures will now reach Bugsink with the GraphQL execution details needed to identify the operation and field.
For handled exceptions, messages, Java logging integrations, tags, structured context, and breadcrumbs, continue with the Java guide.
