Sentry profiling works when using `forRoot` but not `forRootAsync`
thenbe opened this issue · comments
Naser Aleisa commented
Repro here.
In app.module.ts:
- Uncomment
forRoot
, rundev
to see profiling logs. - Uncomment
forRootAsync
, rundev
, profiling logs won't appear.
I dug around a bit, noticed that SentryService
constructor is being called twice when using forRootAsync
. This part would get logged twice:
packages/nestjs-sentry/lib/sentry.service.ts
const { integrations = [], ...sentryOptions } = opts;
+ console.log('constructor - SentryService');
Sentry.init({
Making the following change will make the constructor run only once. It also fixes this issue. However, I'm not familiar with nest's DI system enough to know whether this will break something for other folks.
packages/nestjs-sentry/lib/sentry-core.module.ts
return {
- exports: [provider, SentryService],
+ exports: [provider],
imports: options.imports,
module: SentryCoreModule,
- providers: [...this.createAsyncProviders(options), provider, SentryService]
+ providers: [...this.createAsyncProviders(options), provider]
};
Related: ntegral#102
Fork with "fix":