@onlyknoppas/sentry-nestjs
v0.0.11
Published
<h1 align="center"></h1>
Downloads
3
Readme
Features
- Handles creating Transactions, Span and configuring the Scope
- Avoid Boilerplate for setting up Sentry Express Integration
TraceInterceptor
For Controllers to help with creating a Span or TransactionTrace
andSpan
Decorators for Provider MethodsInjectSentry
Decorator which provides SentryService with helper methods and getters for Sentry
Installation
- Using Yarn
yarn add sentry-nestjs @sentry/node @sentry/tracing
- Using NPM
npm install sentry-nestjs @sentry/node @sentry/tracing
Usage
- Register Module
import { LogLevel } from '@sentry/types'
import { SentryModule } from 'sentry-nestjs'
@Module( {
imports: [
SentryModule.forRoot( {
dsn: '<sentry-dsn>',
environment: 'dev',
debug: true,
logLevel: LogLevel.Debug,
sampleRate: 1,
tracesSampleRate: 1,
expressTracing: true, // use sentry tracing extensions for express
// rest of the Sentry.Options
} ),
],
controllers: [ AppController ],
service: [ AppService ]
} )
- On HTTP Controller
import { Span, Transaction } from '@sentry/types'
import { TraceInterceptor, CurrentSpan, CurrentTransaction } from 'sentry-nestjs'
@Controller()
@UseInterceptor( TraceInterceptor ) // use on controller
class AppController {
constructor(private readonly appService: AppService)
@Get()
@UseInterceptor( TraceInterceptor ) // or just on method
getHello(
@CurrentSpan() span: CurrentSpan,
@CurrentTransaction(): transaction: Transaction
) {
return this.appService.getHello()
}
}
- On any Provider
import { InjectSentry, SentryService } from 'sentry-nestjs'
@Injectable()
@Instrument() // use Instrument to trace all methods
class AppService {
constructor(
@InjectSentry() sentry: SentryService
) {}
@Trace() // or, use Trace to trace for individual methods
getHello() {
this.sentry.currentSpan.setData('data', 'some-data)
return this.appService.getHello()
}
}
- Inspect the generated Trace on your Sentry Dashboard
TODO
- Add Tests
Author
Mahendra Dambe [email protected]
License
Licensed under the MIT License - see the LICENSE file for details.