Skip to content

Sentry profiling works when using forRoot but not forRootAsync #3

Open
@thenbe

Description

@thenbe

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":

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions