travelerdev / nestjs-sentry

Provides an injectable sentry.io client to provide enterprise logging nestjs modules

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sentry profiling works when using `forRoot` but not `forRootAsync`

thenbe opened this issue · comments

Repro here.

In app.module.ts:

  1. Uncomment forRoot, run dev to see profiling logs.
  2. Uncomment forRootAsync, run dev, 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":