๐Ÿ“ฆ payloadcms / plugin-sentry

The official Sentry plugin for Payload

โ˜… 22 stars โ‘‚ 1 forks ๐Ÿ‘ 22 watching โš–๏ธ MIT License
payloadpayload-pluginpayloadcms
๐Ÿ“ฅ Clone https://github.com/payloadcms/plugin-sentry.git
HTTPS git clone https://github.com/payloadcms/plugin-sentry.git
SSH git clone git@github.com:payloadcms/plugin-sentry.git
CLI gh repo clone payloadcms/plugin-sentry
Jessica Boezwinkle Jessica Boezwinkle chore: removes yarn test 9e503d6 2 years ago ๐Ÿ“ History
๐Ÿ“‚ 9e503d6b77a18679187ce7a7d2444345815ecf63 View all commits โ†’
๐Ÿ“ .github
๐Ÿ“ dev
๐Ÿ“ src
๐Ÿ“„ .editorconfig
๐Ÿ“„ .eslintrc.js
๐Ÿ“„ .gitignore
๐Ÿ“„ .prettierrc.js
๐Ÿ“„ LICENSE.md
๐Ÿ“„ package.json
๐Ÿ“„ README.md
๐Ÿ“„ tsconfig.json
๐Ÿ“„ yarn.lock
๐Ÿ“„ README.md
This repo is currently under active development.

Sentry Plugin for Payload

This plugin seamlessly integrates Sentry with Payload for performance monitoring and error tracking.

Installation

yarn add @payloadcms/plugin-sentry
  # OR
  npm i @payloadcms/plugin-sentry

Basic Usage

  • Import sentry from '@payloadcms/plugin-sentry'
  • Add it to the plugins array of your Payload config
  • Pass in your Data Source Name (DSN)
  • Pass additional options - not required
import { buildConfig } from 'payload/config';
import sentry from '@payloadcms/plugin-sentry';
import { Pages, Media } from './collections';

const config = buildConfig({
  collections: [Pages, Media],
  plugins: [
    sentry({
      dsn: 'https://61edebas777889984d323d777@o4505289711681536.ingest.sentry.io/4505357433352176',
    }),
  ]
});

export default config;

Options

Data Source Name (DSN) and where to find it

  • dsn : string[] | required
Sentry automatically assigns a DSN when you create a project, the unique DSN informs Sentry where to send events so they are associated with the correct project.

#### :rotating_light: You can find the DSN in your project settings by navigating to [Project] > Settings > Client Keys (DSN) in sentry.io.

Additional Options

  • init : ClientOptions | optional
Sentry allows a variety of options to be passed into the Sentry.init() function, see the full list of options here.

  • requestHandler : RequestHandlerOptions | optional
Accepts options that let you decide what data should be included in the event sent to Sentry, checkout the options here.

  • captureErrors: number[] | optional
By default, Sentry.errorHandler will capture only errors with a status code of 500 or higher. To capture additional error codes, pass the values as numbers in an array.

You can configure any of these options by passing them to the plugin under options:

import { buildConfig } from 'payload/config';
import seo from '@payloadcms/plugin-sentry';
import { Pages, Media } from './collections';

const config = buildConfig({
  collections: [Pages, Media],
  plugins: [
    sentry({
      dsn: 'https://61edebas777889984d323d777@o4505289711681536.ingest.sentry.io/4505357433352176',
      options: {
        init: {
          debug: true,
          environment: 'development',
          tracesSampleRate: 1.0,
        },
        requestHandler: {
          serverName: false,
          user: ["email"],
        },
        captureErrors: [400, 403, 404],
      }
    }),
  ]
});

export default config;

To learn more about these options and when to use them, visit the Sentry Docs.

TypeScript

All types can be directly imported:

import { PluginOptions } from '@payloadcms/plugin-sentry/types';

Development

To actively develop or debug this plugin you can either work directly within the demo directory of this repo, or link your own project.

Internal Demo

This repo includes a demo of Payload that installs the plugin directly from the source code. This is the easiest way to get started. To spin up this demo, follow these steps:

  • First clone the repo
  • Then, cd plugin-sentry && yarn && cd dev && yarn && yarn dev
  • Now open http://localhost:3000/admin in your browser
  • Create a new user and sign in
  • Use the buttons to throw test errors
That's it! Changes made in ./src will be reflected in the demo.