Sentry Plugin

NPM

This plugin allows you to integrate Sentry seamlessly with your Payload application.

What is Sentry?

Sentry is a powerful error tracking and performance monitoring tool that helps developers identify, diagnose, and resolve issues in their applications.

This multi-faceted software offers a range of features that will help you manage errors with greater ease and ultimately ensure your application is running smoothly:

Core Features

  • Error Tracking: Instantly captures and logs errors as they occur in your application
  • Performance Monitoring: Tracks application performance to identify slowdowns and bottlenecks
  • Detailed Reports: Provides comprehensive insights into errors, including stack traces and context
  • Alerts and Notifications: Send and customize event-triggered notifications
  • Issue Grouping, Filtering and Search: Automatically groups similar errors, and allows filtering and searching issues by custom criteria
  • Breadcrumbs: Records user actions and events leading up to an error
  • Integrations: Connects with various tools and services for enhanced workflow and issue management

Installation

Install the plugin using any JavaScript package manager like Yarn, NPM, or PNPM:

1
yarn add @payloadcms/plugin-sentry

Basic Usage

In the plugins array of your Payload config, call the plugin and pass in your Sentry DSN as an option.

1
import { buildConfig } from 'payload/config'
2
import { sentry } from '@payloadcms/plugin-sentry'
3
import { Pages, Media } from './collections'
4
5
const config = buildConfig({
6
collections: [Pages, Media],
7
plugins: [
8
sentry({
9
dsn: 'https://61edebas776889984d323d777@o4505289711681536.ingest.sentry.io/4505357433352176',
10
}),
11
],
12
})
13
14
export default config

Options

  • 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.

  • enabled: boolean | optional

    Set to false to disable the plugin. Defaults to true.

  • 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.

To see all options available, visit the Sentry Docs.

Example

Configure any of these options by passing them to the plugin:

1
import { buildConfig } from 'payload/config'
2
import { sentry } from '@payloadcms/plugin-sentry'
3
import { Pages, Media } from './collections'
4
5
const config = buildConfig({
6
collections: [Pages, Media],
7
plugins: [
8
sentry({
9
dsn: 'https://61edebas777689984d323d777@o4505289711681536.ingest.sentry.io/4505357433352176',
10
options: {
11
init: {
12
debug: true,
13
environment: 'development',
14
tracesSampleRate: 1.0,
15
},
16
requestHandler: {
17
serverName: false,
18
user: ['email'],
19
},
20
captureErrors: [400, 403, 404],
21
},
22
}),
23
],
24
})
25
26
export default config

TypeScript

All types can be directly imported:

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

SEO Plugin