Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@benhepburn/adonis-sentry

benhepburn1.5kMIT1.0.4TypeScript support: included

A Sentry integration for AdonisJS v6

adonis, adonisjs, sentry, sentry.io, v6, adonis 6, provider, service

readme

AdonisJS Sentry

Install

Install from npm:

npm install @benhepburn/adonis-sentry

or

pnpm install @benhepburn/adonis-sentry

or

yarn add @benhepburn/adonis-sentry

Then, configure the package for Adonis:

node ace configure @benhepburn/adonis-sentry

Configuration

Enter the Sentry DSN and Traces sample rate in your .env file:

SENTRY_DSN=https://<...>.sentry.io/<...>
SENTRY_TRACES_SAMPLE_RATE=1.0 # Set this to a lower value in production

To enable enhanced event data, you must enable useAsyncLocalStorage in config/app.ts so the current request can be fetched (see caveats here):

useAsyncLocalStorage: true,

Usage

Import the service to use it:

import sentry from "@benhepburn/adonis-sentry/service"

To capture all exceptions, add the capture line to app/exceptions/handler.ts inside the report function:

async report(error: unknown, ctx: HttpContext) {
  sentry.captureException(error); // Add this line
  ...
  return super.report(error, ctx);
}

Exceptions can be captured manually as well:

try {
  ...
} catch (error: unknown) {
  sentry.captureException(error);
}