Files
payloadcms/test/plugin-sentry/config.ts
Sasha 0b2a7a3606 feat(plugin-sentry): update plugin to 3.0 (#8613)
Updates the plugin to 3.0

Test:
```sh
NEXT_PUBLIC_SENTRY_DSN=<DSN here> pnpm dev plugin-sentry
```

Example:
```ts
sentryPlugin({
  options: {
    captureErrors: [400, 403],
    context: ({ defaultContext, req }) => {
      return {
        ...defaultContext,
        tags: {
          locale: req.locale,
        },
      }
    },
    debug: true,
  },
  Sentry,
})
```
2024-10-09 14:26:58 -04:00

56 lines
1.3 KiB
TypeScript

import { fileURLToPath } from 'node:url'
import path from 'path'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
import { sentryPlugin } from '@payloadcms/plugin-sentry'
import * as Sentry from '@sentry/nextjs'
import { APIError } from 'payload'
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'
import { devUser } from '../credentials.js'
import { Posts } from './collections/Posts.js'
import { Users } from './collections/Users.js'
export default buildConfigWithDefaults({
admin: {
components: {
beforeDashboard: ['/TestErrors.js#TestErrors'],
},
importMap: {
baseDir: path.resolve(dirname),
},
user: Users.slug,
},
collections: [Posts, Users],
onInit: async (payload) => {
await payload.create({
collection: 'users',
data: {
email: devUser.email,
password: devUser.password,
},
})
},
endpoints: [
{
path: '/exception',
handler: () => {
throw new APIError('Test Plugin-Sentry Exception', 500)
},
method: 'get',
},
],
plugins: [
sentryPlugin({
Sentry,
options: {
debug: true,
captureErrors: [400, 403, 404],
},
}),
],
typescript: {
outputFile: path.resolve(dirname, 'payload-types.ts'),
},
})