fix(sentry): use environments

This commit is contained in:
Mrugesh Mohapatra
2025-01-02 14:31:57 +05:30
parent abbd76fbc0
commit 4d4e617b7d
3 changed files with 13 additions and 2 deletions

View File

@@ -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)

View File

@@ -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;

View File

@@ -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