nestjs-sentry icon indicating copy to clipboard operation
nestjs-sentry copied to clipboard

options not found. Did you use SentryModule.forRoot?

Open garviand opened this issue 3 years ago • 5 comments

Hi,

I'm using version 2.x because I have Nest 7.x

Everything seems to be working (logs are sending to sentry and local debug works) but I am curious about this console log I am getting ("options not found. Did you use SentryModule.forRoot?"). I noticed that in 3.x this log was commented out (shown below). Should I be concerned that the service isn't being initialized correctly?

Thanks for the awesome library!

3.x:

export class SentryService extends ConsoleLogger {
  app = '@ntegral/nestjs-sentry: ';
  private static serviceInstance: SentryService;
  constructor(
    @Inject(SENTRY_MODULE_OPTIONS)
    readonly opts?: SentryModuleOptions,
  ) {
    super();
    if (!(opts && opts.dsn)) {
      // console.log('options not found. Did you use SentryModule.forRoot?');
      return;
    }

2.x:

export class SentryService extends Logger {
  app: string = '@ntegral/nestjs-sentry: ';
  private static serviceInstance: SentryService;
  constructor(
    @Inject(SENTRY_MODULE_OPTIONS)
    private readonly options?: SentryModuleOptions,
    @Optional() prior?: SentryService
  ) {
    super();
    if (!(options && options.dsn)) {
      console.log('options not found. Did you use SentryModule.forRoot?');
      return;
    }

For reference, here is how I am importing:

SentryModule.forRootAsync({
  imports: [ConfigModule],
  useFactory: async (config: ConfigService) => {
    return {
      dsn: config.get('SENTRY_DSN'),
      debug: true,
      environment: 'development',
      logLevel: LogLevel.Error
    }
  },
  inject: [ConfigService],
}),

^ made sure sentry dsn is set correctly

and my bootstrap (not sure this is relevant):

async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    logger: false
  });
  app.useLogger(SentryService.SentryServiceInstance());
  await app.listen(3000);
}
bootstrap();

garviand avatar Jan 19 '22 15:01 garviand

Some additional info – I logged out the options right before the if (!(options && options.dsn)) and when I start my app it logs three times. The first two times the options look correct and the third is undefined. Seems like it might be an issue on my end?

{
  dsn: '[my_dsn],
  debug: true,
  environment: 'development',
  logLevel: 1
}

{
  dsn: '[my_dsn],
  debug: true,
  environment: 'development',
  logLevel: 1
}

undefined

garviand avatar Jan 19 '22 15:01 garviand

i get same issue. did you find any solution ?

davidquintard avatar Jan 31 '22 18:01 davidquintard

+1

iiewad avatar Mar 08 '22 09:03 iiewad

I am curious if you found a solution to this problem as well

simplenotezy avatar Mar 10 '22 22:03 simplenotezy

Confirming that I'm seeing this as well on 2.0.9, with @nestjs/core at 7.2.0

wbobeirne avatar Jan 19 '23 21:01 wbobeirne