-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Sentry instrument.js file to use environment variables and dis…
…able when environment is not set
- Loading branch information
1 parent
e6e800b
commit 5ce38b8
Showing
1 changed file
with
26 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
|