All Projects → DiederikvandenB → Apollo Link Sentry

DiederikvandenB / Apollo Link Sentry

Licence: mit
Apollo Link middleware which enriches SentryJS with GraphQL data

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Apollo Link Sentry

Erxes Api
API for erxes
Stars: ✭ 57 (-9.52%)
Mutual labels:  graphql, apollo
Laravel Vuejs.com
Laravel and VueJs Blog, using Laravel nova, GraphQL, NuxtJs, Apollo and ...more
Stars: ✭ 54 (-14.29%)
Mutual labels:  graphql, apollo
Apollo Redux Form
Redux forms powered by Apollo
Stars: ✭ 52 (-17.46%)
Mutual labels:  graphql, apollo
Graphql Apq
🎯 Automatic persisted queries (APQ) for any GraphQL server.
Stars: ✭ 43 (-31.75%)
Mutual labels:  graphql, apollo
Apollo Cache Persist
🎏 Simple persistence for all Apollo Cache implementations
Stars: ✭ 1,078 (+1611.11%)
Mutual labels:  graphql, apollo
Omdb Graphql Wrapper
🚀 GraphQL wrapper for the OMDb API
Stars: ✭ 45 (-28.57%)
Mutual labels:  graphql, apollo
Graphql Upload
Middleware and an Upload scalar to add support for GraphQL multipart requests (file uploads via queries and mutations) to various Node.js GraphQL servers.
Stars: ✭ 1,071 (+1600%)
Mutual labels:  graphql, apollo
Graphql Modules
Enterprise Grade Tooling For Your GraphQL Server
Stars: ✭ 962 (+1426.98%)
Mutual labels:  graphql, apollo
Guide To Graphql
A Frontend Developer's Guide to GraphQL (Fluent Conf 2018)
Stars: ✭ 59 (-6.35%)
Mutual labels:  graphql, apollo
A Pop
🎶 HD Music Streaming and Sharing Web App
Stars: ✭ 55 (-12.7%)
Mutual labels:  graphql, apollo
React Apollo Decorators
Better decorators for Apollo and React
Stars: ✭ 39 (-38.1%)
Mutual labels:  graphql, apollo
Blaze Apollo
Blaze integration for the Apollo Client
Stars: ✭ 56 (-11.11%)
Mutual labels:  graphql, apollo
Crypto Grommet
Crypto and equities app
Stars: ✭ 39 (-38.1%)
Mutual labels:  graphql, apollo
Graphql Advanced Projection
Fully customizable Mongoose/MongoDB projection generator.
Stars: ✭ 46 (-26.98%)
Mutual labels:  graphql, apollo
React Boilerplate
⚛ The stable base upon which we build our React projects at Mirego.
Stars: ✭ 39 (-38.1%)
Mutual labels:  graphql, apollo
Graphql Modules
⚠️ [DEPRECATED] GraphQL module library for Apollo.
Stars: ✭ 53 (-15.87%)
Mutual labels:  graphql, apollo
Graphql Serverless
Sample project to guide the use of GraphQL and Serverless Architecture.
Stars: ✭ 28 (-55.56%)
Mutual labels:  graphql, apollo
Link state demo
🚀 Demonstrate how to support multiple stores in Apollo Link State
Stars: ✭ 30 (-52.38%)
Mutual labels:  graphql, apollo
Apollo Invalidation Policies
An extension of the Apollo 3 cache with support for type-based invalidation policies.
Stars: ✭ 55 (-12.7%)
Mutual labels:  graphql, apollo
Subscriptions Transport Sse
A Server-Side-Events (SSE) client + server for GraphQL subscriptions
Stars: ✭ 55 (-12.7%)
Mutual labels:  graphql, apollo

Apollo Link Sentry

Apollo Link middleware to enrich SentryJS events with GraphQL data.

npm GitHub Workflow Status Coveralls github branch npm-downloads David Dependabot Status

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

export interface FullOptions {
  /**
   * Determines if the given operation should be handled or discarded.
   *
   * If undefined, all operations will be included.
   */
  shouldHandleOperation: undefined | ((operation: Operation) => boolean);

  /**
   * The uri of the GraphQL endpoint.
   *
   * Used to add context information, e.g. to breadcrumbs.
   */
  uri: undefined | string;

  /**
   * Set the Sentry transaction name to the GraphQL operation name.
   *
   * May be overwritten by other parts of your app.
   */
  setTransaction: true | false;

  /**
   * Narrow Sentry's fingerprint by appending the GraphQL operation name to the {{default}} key.
   *
   * Only the last executed operation will be added, not every operation that's been through the link.
   * May be overwritten by other parts of your app.
   */
  setFingerprint: true | false;

  /**
   * Attach a breadcrumb for executed GraphQL operations.
   *
   * The following information will be included by default:
   * {
   *   type: 'http',
   *   category: `graphql.${operationType}`,
   *   message: operationName,
   *   level: errors ? 'error' : 'info',
   * }
   */
  attachBreadcrumbs: AttachBreadcrumbsOptions | false;
}

export type AttachBreadcrumbsOptions = {
  /**
   * Include the full query string?
   */
  includeQuery: false | true;

  /**
   * Include the variable values?
   *
   * Be careful not to leak sensitive information or send too much data.
   */
  includeVariables: false | true;

  /**
   * Include the fetched result (data, errors, extensions)?
   *
   * Be careful not to leak sensitive information or send too much data.
   */
  includeFetchResult: false | true;

  /**
   * Include the response error?
   *
   * Be careful not to leak sensitive information or send too much data.
   */
  includeError: false | true;

  /**
   * Include the contents of the Apollo Client cache?
   *
   * This is mostly useful for debugging purposes and not recommended for production environments,
   * see "Be careful what you include", unless carefully combined with `beforeBreadcrumb`.
   */
  includeCache: false | true;

  /**
   * Include arbitrary data from the `ApolloContext`?
   *
   * Accepts a list of keys in dot notation, e.g. `foo.bar`. Can be useful to include extra
   * information such as headers.
   */
  includeContext: false | NonEmptyArray<string>;

  /**
   * Modify the breadcrumb right before it is sent.
   *
   * Can be used to add additional data from the operation or clean up included data.
   * Very useful in combination with options like `includeVariables` and `includeContextKeys`.
   */
  transform:
    | undefined
    | ((breadcrumb: GraphQLBreadcrumb, operation: Operation) => Breadcrumb);
};

Compatibility with other Apollo Links

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.

  1. Disable the default integration for fetch requests. 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 }),
  ],
});
  1. 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
    • Note that this package (currently) only adds breadcrumbs. This means that you are still responsible for reporting errors to Sentry. You can do this by calling Sentry.captureException(). See this example:
    <Mutation mutation={ERROR_MUTATION}>
      {(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>
    

Caveats

  • This package has not been tested for subscriptions
  • We also need to test for different links, i.e. apollo-link-rest

Roadmap / notes

  • Write best practice scenario:
    • setting includeError true
    • catch errors manually
    • throw custom error
    • how to use together with apollo-link-error?
      • does it report errors twice if you do sentry capture there and in your catch
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].