Skip to content

Commit 659bc1b

Browse files
committed
feat(back): add sentry environment setting
1 parent eb7b69d commit 659bc1b

File tree

6 files changed

+13
-6
lines changed

6 files changed

+13
-6
lines changed

apps/backend/src/app/app.module.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { HealthcheckModule } from './modules/healthcheck/healthcheck.module';
3636
// production if a valid DSN is set.
3737
SentryModule.forRootAsync({
3838
useFactory: async (config: ConfigService) => ({
39-
environment: config.getOrThrow('env'),
39+
environment: config.getOrThrow('sentry.env'),
4040
// Whether to enable SentryInterceptor. If enabled, we run a transaction
4141
// for the lifetime of tracesSampleRate * all HTTP requests. This
4242
// provides more detailed error

apps/backend/src/app/config/config.interface.ts

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export interface ConfigInterface {
4141
enableTracing: boolean;
4242
tracesSampleRate: number;
4343
tracePrisma: boolean;
44+
env: 'production' | 'staging';
4445
};
4546
limits: {
4647
dailyReports: number;

apps/backend/src/app/config/config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ export const ConfigFactory = (): ConfigInterface => {
4444
dsn: process.env['SENTRY_DSN'] || '',
4545
enableTracing: process.env['SENTRY_ENABLE_TRACING'] === 'true' || false,
4646
tracesSampleRate: +process.env['SENTRY_TRACE_SAMPLE_RATE'] || 0,
47-
tracePrisma: process.env['SENTRY_TRACE_PRISMA'] === 'true' || false
47+
tracePrisma: process.env['SENTRY_TRACE_PRISMA'] === 'true' || false,
48+
env: (process.env['SENTRY_ENV'] || '') as 'production' | 'staging'
4849
},
4950
sessionSecret: process.env['SESSION_SECRET'] || '',
5051
steam: {

apps/backend/src/app/config/config.validation.ts

+4
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ export class ConfigValidation {
8282
@IsBoolean()
8383
readonly SENTRY_TRACE_PRISMA?: boolean;
8484

85+
@IsOptional()
86+
@IsIn(['production', 'staging'])
87+
readonly SENTRY_ENV?: 'production' | 'staging';
88+
8589
@IsUrl({ require_tld: false, protocols: ['postgresql'] })
8690
readonly DATABASE_URL?: string;
8791

apps/backend/src/app/modules/sentry/sentry.module.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ export class SentryModule {
4040
return false;
4141
}
4242

43-
if (!sentryOpts?.dsn) {
44-
logger.warn('Sentry DSN not set, not initializing!');
43+
if (!sentryOpts?.dsn || !sentryOpts?.environment) {
44+
logger.warn(
45+
'Sentry DSN or environment not set, not initializing!'
46+
);
4547
return false;
4648
}
4749

env.TEMPLATE

+1-2
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,4 @@ SENTRY_DSN=
7171
SENTRY_ENABLE_TRACING=
7272
SENTRY_TRACE_SAMPLE_RATE=
7373
SENTRY_TRACE_PRISMA=
74-
75-
74+
SENTRY_ENV=

0 commit comments

Comments
 (0)