GraphQL Client Errors

This feature captures graphql-client errors and reports them to Sentry

Once enabled, this feature captures and reports GraphQL over HTTP errors when you use the graphql-client library. In addition to basic information about the HTTP request and response, the error event can also capture details of the GraphQL request such as: operation name, type, query, and response.

To capture GraphQL over HTTP errors, you have to enable SentryOptions.CaptureFailedRequests and configure GraphQLHttpClientOptions.HttpMessageHandler to use SentryGraphQLHttpMessageHandler.

  1. Enable the feature in Sentry:
// Add this to the SDK initialization callback
options.CaptureFailedRequests = true;
  1. Configure Sentry instrumentation on the graphql-client:
var graphClient = new GraphQLHttpClient(
    options =>
        options.EndPoint = new Uri("");
        options.HttpMessageHandler = new SentryGraphQLHttpMessageHandler(); // <-- Configure GraphQL use Sentry Message Handler
    new SystemTextJsonSerializer()

By default, Sentry will capture GraphQL over HTTP client errors for requests to any GraphQL endpoint. You can change this behavior by updating the FailedRequestTargets option with either regular expressions or plain strings. Plain strings don't have to be full matches, meaning the URL of a request is matched when it contains a substring provided through the option:

options.FailedRequestTargets.Add("foo");      // substring
options.FailedRequestTargets.Add("foo.*bar"); // regex

When the SendDefaultPii option is enabled, error events may contain PII data such as Headers, Cookies, and the GraphQL request query. To scrub this data before it's sent, see Scrubbing Sensitive Data.

These events are searchable. You can set alerts for them using properties like the http.url and http.status_code. Read our Searchable Properties docs to learn more.

Any captured error event can be customized or dropped in the SetBeforeSend callback like this:

options.SetBeforeSend((@event, hint) =>
    return @event.Breadcrumbs.Any(b => b.Type == "graphql" && b?.Data?["operation_name"] == "fakeMutation")
        ? null  // Ignore errors for fakeMutations
        : @event;
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").