Question - Globally enable sentry in whole app without adding interceptor or injectables
abhimanusharma opened this issue ยท 6 comments
I am already using sentry with ReactJs and it is working great with my project. All errors are logging in Sentry dashboard globally without doing anything special or any 3rd party logging in entire application manually.
I am trying to implement the same feature globally by just adding the package's settings in AppModule,
SentryModule.forRoot({
dsn: envConfig.SENTRY_DSN,
debug: true,
environment: currentEnv,
release: null, // must create a release in sentry.io dashboard
logLevel: LogLevel.Debug //based on sentry.io loglevel
}),
This is not working properly even when all settings are correct.
Sorry, I know you said without interceptors, but so far I figured: you need to add interceptor in order for Sentry to receive any exceptions raised from any end-point. Example:
imports: [
SentryModule.forRoot({
dsn: 'dsn_here',
debug: true,
environment: 'production',
release: null, // must create a release in sentry.io dashboard
logLevel: LogLevel.Debug, //based on sentry.io loglevel //
tracesSampleRate: 1.0,
close: {
enabled: true,
timeout: 1000
},
}),
ConfigModule.forRoot(),
HttpModule,
],
controllers: [AppController],
providers: [
AppService,
{
provide: APP_INTERCEPTOR,
useValue: new SentryInterceptor()
}
]
What I can't figure out so far, is: how to get console.log('example')
to be sent to Sentry.
import { Injectable } from '@nestjs/common';
import { InjectSentry, SentryService } from '@ntegral/nestjs-sentry';
@Injectable()
export class AppService {
public constructor(@InjectSentry() private readonly client: SentryService) {
client.instance().captureMessage(message, Sentry.Severity.Log);
client.instance().captureException(exception);
... and more
}
}
Hey @MatthewHerbst
No, I haven't figured out how to automagically get console.log(..)
to be sent to Sentry.
@MatthewHerbst - To enable logging across the entire app you can do the following:
async function bootstrap() {
const app = await NestFactory.create(AppModule, {
logger: SentryService.SentryServiceInstance(),
});
or // app.useLogger(app.get(SentryService)); // either or will turn on logging at the application level.
await app.listen(3000);
}
bootstrap();
Note: this package extends NestJS logging. Please see the NestJS documentation of application logging for details. Thanks.