-
Problem StatementIs it possible to document whether it is feasible to initialize Sentry with dynamic configuration ? My configuration depends on environment variable and dynamically fetched configurations from remote sources. I understand the Solution BrainstormI would expect something similar to this @Global()
@Module({
imports: [EnvModule],
providers: [
{
provide: SENTRY_CLIENT,
useFactory: (envService: EnvService, supabaseClient: SupabaseClient): SentryClient => {
return Sentry.init({
// usage of envService and supabase client
}}
},
inject: [EnvService, SupabaseClient],
},
],
exports: [SENTRY_CLIENT],
})
export class SentryModule {} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hey @noook, I converted this to a discussion since I don't think this is a bug or a feature request to track as an issue. You can probably use the late initialization installation method. Gotta check though if it is re-exported from |
Beta Was this translation helpful? Give feedback.
-
Thanks @Lms24 for your suggestions, I managed to run Sentry with Nest with the late init method as follows:
- "start": "nest start",
- "start:dev": "nest start --watch",
- "start:debug": "nest start --debug --watch",
- "start:prod": "node dist/main",
+ "start": "nest start -e \"node --import @sentry/node/preload\"",
+ "start:dev": "nest start --watch -e \"node --import @sentry/node/preload\"",
+ "start:debug": "nest start --debug --watch -e \"node --import @sentry/node/preload\"",
+ "start:prod": "node --import @sentry/node/preload dist/main",
import { Global, Module } from '@nestjs/common';
import { SentryGlobalFilter, SentryModule as SentryNestModule } from '@sentry/nestjs/setup';
import { SentryService } from './sentry.service';
import { APP_FILTER } from '@nestjs/core';
import { SentryExceptionFilter } from '../filters/http-exception.filter';
@Global()
@Module({
imports: [SentryNestModule.forRoot()],
providers: [
SentryService,
{
provide: APP_FILTER,
useClass: SentryGlobalFilter,
},
{
provide: APP_FILTER,
useClass: SentryExceptionFilter,
},
],
exports: [SentryService],
})
export class SentryModule {}
import { Injectable, OnModuleInit } from '@nestjs/common';
import { EnvService } from '../env/env.service';
import * as Sentry from '@sentry/nestjs';
import { nodeProfilingIntegration } from '@sentry/profiling-node';
@Injectable()
export class SentryService implements OnModuleInit {
constructor(private envService: EnvService) {}
onModuleInit() {
const environment = this.envService.get('NODE_ENV');
const dsn = this.envService.get('SENTRY_DSN');
Sentry.init({
dsn,
environment,
tracesSampleRate: 1.0,
integrations: [nodeProfilingIntegration()],
});
}
captureException(error: any) {
Sentry.captureException(error);
}
captureMessage(message: string) {
Sentry.captureMessage(message);
}
}
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { EnvModule } from './core/env/env.module';
import { envSchema } from './core/env/env';
import { SentryModule } from './core/sentry/sentry.module';
@Module({
imports: [
SentryModule,
ConfigModule.forRoot({
validate: (env) => envSchema.parse(env),
isGlobal: true,
}),
EnvModule,
],
controllers: [],
providers: [],
})
export class AppModule {} |
Beta Was this translation helpful? Give feedback.
Thanks @Lms24 for your suggestions, I managed to run Sentry with Nest with the late init method as follows:
package.json
scripts to require the@sentry/node/preload.js
SentryModule