Adonis-Sentry
Installation
npm i @keqin/adonis-sentry
node ace configure @keqin/adonis-sentry
- Set Env
SENTRY_DSN=
- call
Sentry.captureException
inapp/Exceptions/Handler.ts
- Add types for ENV in
env.ts
SENTRY_DSN: Env.schema.string.optional({ format: 'url' }),
SENTRY_TRACES_SAMPLE_RATE: Env.schema.string.optional(),
SENTRY_DEBUG: Env.schema.boolean.optional(),
Test Sentry DSN
node ace sentry:ping
Performance monitoring
-
set a env variable
SENTRY_TRACES_SAMPLE_RATE
between0
to1
astracesSampleRate
. we suggest set it to1
in dev/testing environment. -
regisitry middleware in
kernel.ts
Server.middleware.register([ () => import('@keqin/adonis-sentry/build/TracingHandler') ])
it would startTransaction in a http request, and inject
sentry
/sentryTrx
to ctx -
Optional: create span in a request
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
export default class Controller {
public async index({ sentry, sentryTrx }: HttpContextContract) {
const span = sentryTrx.startChild({
op: 'query',
description: "more specific details"
})
// to do something
span.finish()
}
}
Example
import Sentry from '@ioc:Adonis/Addons/Sentry'
Sentry.captureMessage('Hello World')
Debug mode
set SENTRY_DEBUG
as true
to turn debug mode on
License
The MIT License