Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

apollo-link-sentry

DiederikvandenB376kMIT4.3.0TypeScript support: included

Apollo Link to enrich Sentry events with GraphQL data

apollo, graphql, sentry, error reporting

readme

Apollo Link Sentry

Apollo Link to enrich Sentry events with GraphQL data

Code Coverage semantic-release

npm-version npm-downloads

Installation

yarn add apollo-link-sentry

Note: Due to a release issue, v3.0.0 of this package has been unpublished. Please use v3.0.1 Note: starting from v2.0.0 of this package we support @apollo/client v3.0.

Features

Turn this:

Before

Into this:

After

Basic setup

Initialize Sentry as you would normally. Then, add apollo-link-sentry to your Apollo Client's link array:

import { SentryLink } from 'apollo-link-sentry';

const client = new ApolloClient({
  link: ApolloLink.from([
    new SentryLink(/* See options */),
    new HttpLink({ uri: 'http://localhost:4000' }),
  ]),
  cache: new InMemoryCache(),
});

Options

See src/options.ts.

apollo-link-sentry aims to be friendly with other apollo-link packages, in the sense that we would like for you to be able to attach as much data as you want. For example, if you would like to add the HTTP headers you set with apollo-link-context, you can do that by setting includeContextKeys: ['headers'].

In case you find that there's a piece of data you're missing, feel free to open an issue.

Be careful what you include

Please note that Sentry sets some limits to how big events can be. For instance, events greater than 200KiB are immediately dropped (pre decompression). More information on that here. Be especially careful with the includeCache option, as caches can become quite large.

Furthermore, much of the data you are sending to Sentry can include (sensitive) personal information. This might lead you to violating the terms of the GDPR. Use Sentry's beforeBreadcrumb function to filter out all sensitive data.

Exclude redundant fetch breadcrumbs

By default, Sentry attaches all fetch events as breadcrumbs. Since this package tracks GraphQL requests as breadcrumbs, they would show up duplicated in Sentry.

You can use either one of the following options to exclude redundant fetch breadcrumbs:

  1. Disable the default integration for fetch requests entirely. Note that this is only recommended if you only use GraphQL requests in your application. The default integration can be disabled like this:

    Sentry.init({
      ...,
      defaultIntegrations: [
        new Sentry.BrowserTracing({ traceFetch: false }),
      ],
    });
  2. Use the beforeBreadcrumb option of Sentry to filter out the duplicates. The helpers in this package recognize every breadcrumb of category fetch where the URL contains /graphql as a GraphQL request.

    import { excludeGraphQLFetch } from 'apollo-link-sentry';
    
    Sentry.init({
      ...,
      beforeBreadcrumb: excludeGraphQLFetch,
    })

    If you have a custom wrapper, use the higher order function:

    import { withoutGraphQLFetch } from 'apollo-link-sentry';
    
    Sentry.init({
      ...,
      beforeBreadcrumb: withoutGraphQLFetch((breadcrumb, hint) => { ... }),
    })

FAQ

I don't see any events appearing in my Sentry stream

This package only adds breadcrumbs, you are still responsible for reporting errors to Sentry. You can do this by calling Sentry.captureException():

<Mutation mutation={MUTATION_THAT_MIGHT_FAIL}>
  {(mutate, { data, error, loading }) => {
    if (loading) return <div>loading</div>;
    if (error) return <div>{error.toString()}</div>;

    const onClick = () =>
      mutate().catch((error) => {
        Sentry.captureException(error);
      });

    return (
      <div>
        <button type="button" onClick={() => onClick()}>
          Mutate
        </button>
        {JSON.stringify(data)}
      </div>
    );
  }}
</Mutation>

changelog

4.3.0 (2025-05-09)

Features

  • Simplify SentryLink to just forward the operation if attachBreadcrumb is not set (#483) (dedb6ee)

4.2.0 (2025-03-24)

Features

4.1.0 (2025-02-04)

Features

  • depend on @sentry/core instead of @sentry/browser (#480) (278a514)

4.0.0 (2024-05-21)

Features

  • upgrade to @sentry/browser 8 (08c48a4)

BREAKING CHANGES

  • require @sentry/browser` 8

3.3.0 (2024-01-02)

Features

3.2.3 (2023-03-09)

Bug Fixes

  • suggest @sentry/browser:^7.41.0 as peer dependency (8868643)

3.2.2 (2023-02-10)

Bug Fixes

  • use zen-observable-ts over zen-observable (a0acb0b)

3.2.1 (2022-11-18)

Bug Fixes

  • warn about mutating data in option transform (#443) (3c9522d)

3.2.0 (2022-07-07)

Features

  • use SeverityLevel over Severity enum (#431) (e758576)

3.1.3 (2022-06-24)

Bug Fixes

  • move tslib and zen-observable to dependencies (#439) (4a622b7)

3.1.2 (2022-06-07)

Bug Fixes

  • remove source and declaration maps from build output (db5f8a0)

3.1.1 (2022-02-27)

Bug Fixes

  • import only from @sentry/browser (23886b1)

3.1.0 (2022-02-27)

Features

3.0.3 (2022-02-27)

Bug Fixes

  • display correct name for operations with fragments (#411) (6b759b9)
  • include errors in breadcrumbs starting with the first (0d272ce)
  • include partial GraphQL errors in breadcrumbs (#410) (a3d929d)

Performance Improvements

  • avoid repeated property accesses in SentryLink.ts (#422) (b32e4f5)

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

3.0.2 (2021-02-18)

Features

  • Only include result from ServerError if includeFetchResult is set (0f0a919)
  • Stringify objects in breadcrumb data (bd5ceda)

Chores

  • Update tooling to support new functionality and test cases (3582fa6)

3.0.1 (2021-02-15)

Chores

  • release with correct artifacts (965483d)

3.0.0 (2021-02-11)

Check UPGRADE.md for more information on how to upgrade.

⚠ BREAKING CHANGES

  • Restructure options and describe upgrade process (e1db20e)
  • Use native ApolloOperation instead of our own Operation type (370b9b5)
  • Replace OperationBreadcrumb class with plain GraphQLBreadcrumb object (036b746)
  • Rename response key in breadcrumbs to fetchResult

Features

  • Change breadcrumb type to http
  • Add operationName key to breadcrumbs
  • Allow specifying uri to add url key to breadcrumbs

Fix

  • Handle queries without operation name gracefully
  • Indicate if errors occurred by setting the breadcrumb level

Chores

  • Clarify peer dependencies (c8b43c3)
  • Update tooling and dev dependencies (79b6be6)
  • Increase type, line and branch coverage

2.1.0 (2021-02-04)

Features

  • add helpers to exclude GraphQL fetch breadcrumbs (#264) (a8fa792)

Chores

  • deps-dev: bump @sentry/browser and @sentry/minimal to v6 (a223504)

2.0.2 (2021-01-15)

  • Updated dependencies, specifically two minor security updates

2.0.1 (2020-10-12)

Chores

  • moves most dependencies to peer-dependencies (94372ef)

2.0.0 (2020-10-12)

⚠ BREAKING CHANGES

  • move to apollo client v3

Features

  • move to apollo client v3 (0afc327)

1.3.1 (2020-10-12)

Chores

Bug fixes

  • update setTransaction to setTransactionName (9bf26db)

1.3.0 (2020-05-02)

Features

Chores

  • deps: bump @sentry/browser from 5.15.4 to 5.15.5 (#69) (c738091)
  • deps: bump apollo-link from 1.2.13 to 1.2.14 (#60) (c62f973)
  • deps-dev: bump @typescript-eslint/parser from 2.26.0 to 2.29.0 (#67) (b60e94b)
  • deps-dev: bump eslint-config-airbnb-typescript (#61) (8f09087)
  • deps-dev: bump jest from 25.2.6 to 25.4.0 (#65) (ad4e01e)
  • deps-dev: bump ts-jest from 25.3.0 to 25.4.0 (#64) (f736b0e)

1.2.1 (2020-04-02)

Chores

  • deps: bump @sentry/browser from 5.14.2 to 5.15.4 (#47) (2f09386)
  • deps-dev: bump @typescript-eslint/eslint-plugin (#33) (6a6d2da)
  • added more data to package.json (d14b89a)
  • deps-dev: bump @typescript-eslint/parser from 2.24.0 to 2.26.0 (#51) (69e854a)
  • update dependencies (6384f61)
  • deps-dev: bump @typescript-eslint/eslint-plugin (#40) (2483697)
  • deps-dev: bump @typescript-eslint/eslint-plugin (#49) (7875ca0)
  • deps-dev: bump @typescript-eslint/parser from 2.23.0 to 2.24.0 (#34) (e019eb3)
  • deps-dev: bump eslint-config-airbnb-typescript (#36) (59d0503)
  • deps-dev: bump eslint-plugin-import from 2.20.1 to 2.20.2 (#46) (766fcf2)
  • deps-dev: bump jest from 25.1.0 to 25.2.0 (#41) (46fc002)
  • deps-dev: bump jest from 25.2.0 to 25.2.4 (#45) (d1dcf96)
  • deps-dev: bump ts-jest from 25.2.1 to 25.3.0 (#50) (14bf523)

1.2.0 (2020-03-16)

Chores

  • deps: [security] bump acorn from 6.4.0 to 6.4.1 (#29) (463218c)
  • drops release-it dependency (4e69a4e)
  • deps: bump @sentry/browser from 5.12.5 to 5.13.0 (#14) (44fbaf7)
  • deps: bump @sentry/browser from 5.13.0 to 5.13.2 (#20) (a776f76)
  • deps: bump @sentry/browser from 5.13.2 to 5.14.1 (#27) (f675a5f)
  • deps: bump @sentry/browser from 5.14.1 to 5.14.2 (#32) (f119f67)
  • deps: bump @sentry/types from 5.14.1 to 5.14.2 (#30) (2ebfed8)
  • deps-dev: bump @types/jest from 25.1.3 to 25.1.4 (#22) (e69dd65)
  • deps-dev: bump @typescript-eslint/eslint-plugin (#18) (00bccbc)
  • deps-dev: bump @typescript-eslint/eslint-plugin (#24) (086329c)
  • deps-dev: bump @typescript-eslint/parser from 2.21.0 to 2.22.0 (#19) (5d6a4b9)
  • deps-dev: bump @typescript-eslint/parser from 2.22.0 to 2.23.0 (#23) (4fe15b2)
  • deps-dev: bump eslint-config-airbnb-base from 14.0.0 to 14.1.0 (#31) (74d6b84)
  • deps-dev: bump tsc-watch from 4.1.0 to 4.2.3 (#15) (abf2a97)
  • deps-dev: bump typescript from 3.8.2 to 3.8.3 (#16) (e74be6b)

1.1.1 (2020-03-01)

Bug fixes

  • allows reading data from OperationBreadcrumb (#13) (253d74b)

Chores

  • deps: bump @sentry/browser from 5.12.4 to 5.12.5 (#12) (776d21c)

1.1.0 (2020-02-26)

⚠ BREAKING CHANGES

  • rename class and methods in OperationBreadcrumb.ts (#11)

Features

  • allow adding keys from the context to the breadcrumb (#7) (15ea217)
  • allows altering breadcrumb with beforeBreadcrumb (8b101e9)
  • provides callback for filtering operations (a330abd)

Documentation

  • adds section on beforeBreadcrumb (1923195)
  • adds section on filter option (0a0e6ce)
  • rename class and methods in OperationBreadcrumb.ts (#11) (72b6b67)

1.0.0 (2020-02-25)

Features

  • add setFingerprint and setTransaction methods (be8535d)
  • allow disabling attaching a breadcrumb (2ba8188)
  • show console message when a breadcrumb is flushed multiple times (5b06a99)

Chores

  • add LICENSE (54ceadf)
  • creates github CI/CD action (9a49e22)
  • fix failing action (2eb812c)
  • improves jest reporter (dd56299)
  • deps-dev: bump @types/react from 16.9.19 to 16.9.22 (91931b0)
  • initial commit (68e12b8)
  • prepares for release (ffd4e37)
  • deps: bump @sentry/browser from 5.12.1 to 5.12.4 (457cefc)
  • deps: bump @sentry/browser from 5.12.1 to 5.12.4 (d7a0d6c)
  • preparing package for release (fde947e)
  • small & insignificant improvements (1090710)
  • updates yarn lock file (315673a)
  • deps-dev: bump @types/node from 13.7.1 to 13.7.4 (#1) (e80fbd5)
  • deps-dev: bump @typescript-eslint/eslint-plugin (#3) (9b949a3)
  • deps-dev: bump @typescript-eslint/parser from 2.19.2 to 2.20.0 (#4) (0985a65)
  • deps-dev: bump typescript from 3.7.5 to 3.8.2 (#5) (5e1b210)

Documentation