diff --git a/api/src/plugins/error-handling.ts b/api/src/plugins/error-handling.ts index c9f9a1ca3bb..05fefba7652 100644 --- a/api/src/plugins/error-handling.ts +++ b/api/src/plugins/error-handling.ts @@ -2,7 +2,7 @@ import type { FastifyPluginCallback } from 'fastify'; import fastifySentry from '@immobiliarelabs/fastify-sentry'; import fp from 'fastify-plugin'; -import { SENTRY_DSN } from '../utils/env'; +import { SENTRY_DSN, SENTRY_ENVIRONMENT } from '../utils/env'; import { getRedirectParams } from '../utils/redirection'; /** @@ -15,6 +15,7 @@ import { getRedirectParams } from '../utils/redirection'; const errorHandling: FastifyPluginCallback = (fastify, _options, done) => { void fastify.register(fastifySentry, { dsn: SENTRY_DSN, + environment: SENTRY_ENVIRONMENT, maxValueLength: 8192, // the default is 250, which is too small. // No need to initialize if DSN is not provided (e.g. in development and // test environments) diff --git a/api/src/utils/env.ts b/api/src/utils/env.ts index 10c88e74971..52d2316ad99 100644 --- a/api/src/utils/env.ts +++ b/api/src/utils/env.ts @@ -71,6 +71,7 @@ if (process.env.FREECODECAMP_NODE_ENV !== 'development') { assert.ok(process.env.PORT); assert.ok(process.env.HOST); assert.ok(process.env.SENTRY_DSN); + assert.ok(process.env.SENTRY_ENVIRONMENT); // The following values can exist in development, but production-like // environments need to override the defaults. assert.notEqual( @@ -78,6 +79,11 @@ if (process.env.FREECODECAMP_NODE_ENV !== 'development') { 'dsn_from_sentry_dashboard', `The DSN from Sentry's dashboard should be used.` ); + assert.notEqual( + process.env.SENTRY_ENVIRONMENT, + 'development', + `The Sentry environment should be changed from the default.` + ); assert.notEqual( process.env.JWT_SECRET, 'a_jwt_secret', @@ -133,6 +139,10 @@ export const SENTRY_DSN = process.env.SENTRY_DSN === 'dsn_from_sentry_dashboard' ? '' : process.env.SENTRY_DSN; +export const SENTRY_ENVIRONMENT = + process.env.SENTRY_ENVIRONMENT === 'development' + ? '' + : process.env.SENTRY_ENVIRONMENT; export const COOKIE_DOMAIN = process.env.COOKIE_DOMAIN; export const COOKIE_SECRET = process.env.COOKIE_SECRET; export const JWT_SECRET = process.env.JWT_SECRET; diff --git a/sample.env b/sample.env index 02d454da719..1150fff9a5a 100644 --- a/sample.env +++ b/sample.env @@ -4,7 +4,7 @@ MONGOHQ_URL=mongodb://127.0.0.1:27017/freecodecamp?directConnection=true # Logging SENTRY_DSN=dsn_from_sentry_dashboard SENTRY_CLIENT_DSN=dsn_from_sentry_dashboard -SENTRY_ENVIRONMENT=staging +SENTRY_ENVIRONMENT=development # Auth0 - OAuth 2.0 Credentials AUTH0_CLIENT_ID=client_id_from_auth0_dashboard