apollo-link-sentry icon indicating copy to clipboard operation
apollo-link-sentry copied to clipboard

Test usage with `apollo-link-error`

Open spawnia opened this issue 2 years ago • 1 comments

Does it report errors twice if you do sentry capture there and in your catch?

spawnia avatar Dec 18 '21 13:12 spawnia

We're running into some issues with apollo-link-error that might fit under this issue, although please let me know if you think it might be better as a standalone.

We have the following structure for our links:

ApolloLink.from([
      errorLink,
      retryLink,
      new SentryLink({...}),
      httpLink,
    ]),

The SentryLink is immediately preceding the terminating httpLink, and between it and the errorLink. This is intentional - we were hoping that the sentry link would report to sentry before the error link executes.

In our error link, we want to automatically capture network and graphql errors and report them to sentry. We do not report to Sentry in our product code as part of a catch block after executing a mutation - it is automatically handled by the error link

The error link looks something like this:

if (errorResponse.networkError) {
        Sentry.Native.captureException(errorResponse.networkError);
      } else if (errorResponse.graphQLErrors?.length) {
        for (const err of errorResponse.graphQLErrors) {
          Sentry.Native.captureMessage(
            err.message,
            Sentry.Native.Severity.Error
          );
        }
      }

When an error occurs, the ErrorLink successfully reports to Sentry. And in the Sentry alert, we see all the breadcrumbs from apollo-link-sentry of previous graphql requests.

However, we do not actually see a breadcrumb of the request that has the error. This is super unfortunate because that's breadcrumb we want to see the most!

It seems like SentryLink will only call attachBreadcrumbToSentry after the ErrorLink has completed. Meaning that we won't see this information in the history because captureMessage is called before attachBreadcrumbToSentry

For our use case, we were hoping that attachBreadcrumbToSentry would be called in the next block and not wait until complete. However, I'm not sure if this interferes with other use cases of the library.

Let me know if this is something you think apollo-link-sentry could support!

hpersson avatar Mar 28 '22 22:03 hpersson