Skip to content

Commit

Permalink
Update Sentry instrument.js file to use environment variables and dis…
Browse files Browse the repository at this point in the history
…able when environment is not set
  • Loading branch information
TylerMatteo committed Oct 30, 2024
1 parent e6e800b commit 5ce38b8
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions server/src/sentry/instrument.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
import * as Sentry from "@sentry/nestjs";
import { nodeProfilingIntegration } from '@sentry/profiling-node';
import * as dotenv from "dotenv";
import * as fs from "fs";

// Load Sentry environment variables from process.env or development.env file
let envConfig: { [key: string]: string } = {};
if (
process.env.NODE_ENV === "production" ||
process.env.NODE_ENV === "test"
) {
envConfig = process.env;
} else {
try {
const filePath = "development.env";
const envValuesFromFile: { [key: string]: string } = {} = dotenv.parse(fs.readFileSync(filePath)) || {};

envConfig = { ...process.env, ...envValuesFromFile };
} catch (e) {
console.log(`Something went wrong loading the environment file: ${e}`);

// fallback to whatever the environment is
envConfig = process.env;
}
}

// Ensure to call this before importing any other modules!
Sentry.init({
dsn: "https://[email protected]/6410746",
environment: process.env.NODE_ENV === "production" ? "production" : "staging",
dsn: process.env.SENTRY_DSN,
environment: process.env.SENTRY_ENVIRONMENT === undefined ? "local" : process.env.SENTRY_ENVIRONMENT,
enabled: process.env.SENTRY_ENVIRONMENT === undefined ? false : true,
integrations: [
// Add our Profiling integration
nodeProfilingIntegration(),
Expand Down

0 comments on commit 5ce38b8

Please sign in to comment.