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.
Sentry does smart stuff with error data to make bugs easier to find and fix. - sentry.io
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 FeaturesError Tracking : Instantly captures and logs errors as they occur in your applicationPerformance Monitoring : Tracks application performance to identify slowdowns and bottlenecksDetailed Reports : Provides comprehensive insights into errors, including stack traces and contextAlerts and Notifications : Send and customize event-triggered notificationsIssue Grouping, Filtering and Search : Automatically groups similar errors, and allows filtering and searching issues by custom criteriaBreadcrumbs : Records user actions and events leading up to an errorIntegrations : Connects with various tools and services for enhanced workflow and issue management InstallationInstall the plugin using any JavaScript package manager like pnpm , npm , or Yarn :
1 pnpm add @ payloadcms / plugin - sentry
Sentry for Next.js setupThis plugin requires to complete the Sentry + Next.js setup before.
You can use either the automatic setup with the installation wizard:
1 npx @ sentry / wizard @ latest - i nextjs
Or the Manual Setup
Basic UsageIn the plugins array of your Payload Config , call the plugin and pass in your Sentry DSN as an option.
1 import { buildConfig } from 'payload'
2 import { sentryPlugin } from '@payloadcms/plugin-sentry'
3 import { Pages , Media } from './collections'
5 import * as Sentry from '@sentry/nextjs'
7 const config = buildConfig ( {
8 collections : [ Pages , Media ] ,
9 plugins : [ sentryPlugin ( { Sentry } ) ] ,
Instrumenting Database QueriesIf you want Sentry to capture Postgres query performance traces, you need to inject the Sentry-patched pg driver into the Postgres adapter. This ensures Sentry’s instrumentation hooks into your database calls.
1 import * as Sentry from '@sentry/nextjs'
2 import { buildConfig } from 'payload'
3 import { sentryPlugin } from '@payloadcms/plugin-sentry'
4 import { postgresAdapter } from '@payloadcms/db-postgres'
7 export default buildConfig ( {
9 pool : { connectionString : process . env . DATABASE_URL } ,
12 plugins : [ sentryPlugin ( { Sentry } ) ] ,
OptionsSentry : Sentry | required The Sentry instance
enabled: boolean | optional Set to false to disable the plugin. Defaults to true.
context: (args: ContextArgs) => Partial<ScopeContext> | Promise<Partial<ScopeContext>> Pass additional contextual data to Sentry
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.
ExampleConfigure any of these options by passing them to the plugin:
1 import { buildConfig } from 'payload'
2 import { sentryPlugin } from '@payloadcms/plugin-sentry'
4 import * as Sentry from '@sentry/nextjs'
6 import { Pages , Media } from './collections'
8 const config = buildConfig ( {
9 collections : [ Pages , Media ] ,
13 captureErrors : [ 400 , 403 ] ,
14 context : ( { defaultContext , req } ) => {
TypeScriptAll types can be directly imported:
1 import { PluginOptions } from '@payloadcms/plugin-sentry'