An Apollo Plugin for Sentry Monitoring 🔍
Tracking Errors in Apollo GraphQL with Sentry
Apollo server uses lifecycle events, enabling us to easily instrument an app for sentry integration.
Here's a visual diagram of the flow of lifecycle events. Learn more at the Apollo Plugin Docs 📚
# yarn
yarn add @pointblankdev/apollo-plugin-sentry
# npm
npm install @pointblankdev/apollo-plugin-sentry
- To get started, you need to have a Sentry DSN which you can get here. This value should be assigned to the
SENTRY_DSN
environment variable. - Make sure you have the
ENV
variable set so Sentry knows which environment to use for tracking your errors
-
Import the package and pass an array containing the variable to the plugin options of your Apollo Server and you're good to go 🚀
const { sentryPlugin, } = require('@pointblankdev/apollo-plugin-sentry');
const server = new ApolloServer({ ..., plugins: [sentryPlugin], });
-
Import the package, initialize it by calling it with an optional service name, pass the result to the plugin options of your Apollo Server and you're good to go
const { sentryPlugin, } = require('@pointblankdev/apollo-plugin-sentry'); const plugin = sentryPlugin('my-repo');
const server = new ApolloServer({ ..., plugins: [plugin], });
-
The service name is added as a
service_name
tag in your error reporting, therefore making it much easier to identify individual services at first glance when you have a project that serves multiple services.