Sentry service provider for Adonis v6
npm i --save sentry-adonis-v6
node ace configure sentry-adonis-v6
- For other configuration, please update the
config/sentry.ts
.
After configure Sentry service will be initialized. After this you can import Sentry service anywhere in your application as follows:
import { Sentry } from 'sentry-adonis-v6'
-
Then you have to send your error details to Sentry. You can use Adonis Exception Handler for this purposes. For example you can implement and Exception Handler:
import { Sentry } from 'sentry-adonis-v6' import { HttpContext, ExceptionHandler } from '@adonisjs/core/http' export default class ExceptionHandler extends ExceptionHandler { /** * The method is used for handling errors and returning * response to the client */ public async handle (error: unknown, ctx: HttpContext) { Sentry.captureException(error) return super.handle(error, ctx) } }
Additionally, you can run a command to validate and test the connection to Sentry as follows:
node ace sentry:test
For additional details of Sentry API, please check the Sentry SDK documentation by this link Sentry docs