diff --git a/README.md b/README.md index 6dfd4846..fc01d576 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ AWS_ACCESS_KEY_ID = env.get("AWS_ACCESS_KEY_ID", "") AWS_SECRET_ACCESS_KEY = env.get("AWS_SECRET_ACCESS_KEY", "") ``` -### Database +### Database You can either develop using the dev database, or use the local database provided in the docker compose file Using the local database is detailed below, but both options will require the dev database password, so you will have to ask an RTP for this too @@ -106,6 +106,10 @@ Using the local database is detailed below, but both options will require the de ### Forcing evals/rtp or anything else All of the role checking is done in `conditional/utils/user_dict.py`, and you can change the various functions to `return True` for debugging +### Using Sentry +If you want to opt-into logging errors through Sentry then set the `CONDITIONAL_SENTRY_ENV` environment variable to anything other than `local-development`. +Setting it to `local-development` or having the environment variable unset disables Sentry in both the frontend and backend (Re-building the container may be required). + ## Dependencies diff --git a/conditional/__init__.py b/conditional/__init__.py index c2644948..c5883f4a 100644 --- a/conditional/__init__.py +++ b/conditional/__init__.py @@ -39,11 +39,12 @@ ) # Sentry setup -sentry_sdk.init( - dsn=app.config['SENTRY_DSN'], - integrations=[FlaskIntegration(), SqlalchemyIntegration()], - environment=app.config['SENTRY_ENV'], -) +if app.config['SENTRY_ENV'] != "local-development": + sentry_sdk.init( + dsn=app.config['SENTRY_DSN'], + integrations=[FlaskIntegration(), SqlalchemyIntegration()], + environment=app.config['SENTRY_ENV'], + ) ldap = CSHLDAP(app.config['LDAP_BIND_DN'], app.config['LDAP_BIND_PW'], diff --git a/frontend/javascript/app.js b/frontend/javascript/app.js index 28de75e4..54a50d12 100644 --- a/frontend/javascript/app.js +++ b/frontend/javascript/app.js @@ -1,15 +1,18 @@ // Install Sentry to send errors to Sentry import * as Sentry from '@sentry/browser'; -Sentry.init( - { - dsn: 'https://151ecfab1a8242009012d45a19064cfd@sentry.io/133175' - } -); -// Capture unhandled exceptions in promises -window.addEventListener('unhandledrejection', err => { - Sentry.captureException(err.reason); -}); +if (process.env.SENTRY_ENV !== "local-development") { + Sentry.init( + { + dsn: 'https://151ecfab1a8242009012d45a19064cfd@sentry.io/133175' + } + ); + + // Capture unhandled exceptions in promises + window.addEventListener('unhandledrejection', err => { + Sentry.captureException(err.reason); + }); +} // Load the rest of the modules import "jquery"; diff --git a/package-lock.json b/package-lock.json index b33f83ad..9428be90 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,6 +32,7 @@ "bootstrap-icons": "^1.13.1", "copy-webpack-plugin": "^14.0.0", "css-loader": "^7.1.4", + "dotenv": "^18.0.5", "eslint-config-google": "^0.14.0", "expose-loader": "^5.0.1", "imports-loader": "^5.0.0", @@ -3270,6 +3271,22 @@ "node": ">=0.10" } }, + "node_modules/dotenv": { + "version": "18.0.5", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-18.0.5.tgz", + "integrity": "sha512-aBrGvt6KhjxbEnatqMWOMidftwsrCiCvqh1yNIGB9QyF0J+VcWkKDMsvYOEm7ZS82oiV+BT1sTOtIlAmUlTpwQ==", + "dev": true, + "license": "BSD-2-Clause", + "bin": { + "dotenv": "dist/index.cjs" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/dropzone": { "version": "5.9.3", "resolved": "https://registry.npmjs.org/dropzone/-/dropzone-5.9.3.tgz", diff --git a/package.json b/package.json index c916305f..4c0264bd 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "bootstrap-icons": "^1.13.1", "copy-webpack-plugin": "^14.0.0", "css-loader": "^7.1.4", + "dotenv": "^18.0.5", "eslint-config-google": "^0.14.0", "expose-loader": "^5.0.1", "imports-loader": "^5.0.0", diff --git a/webpack.config.js b/webpack.config.js index f184daee..b2e0b6db 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -2,11 +2,14 @@ const webpack = require('webpack'); const CopyPlugin = require('copy-webpack-plugin') const path = require('path'); const sass = require('sass'); +const dotenv = require('dotenv'); var jsSrc = path.resolve('./frontend'); var jsDest = path.resolve('./conditional/static'); var publicPath = 'static/js'; +dotenv.config(); + var babelQuery = { "presets": ["@babel/preset-env"], "plugins": [] @@ -25,7 +28,8 @@ var webpackConfig = { plugins: [ new webpack.DefinePlugin({ 'process.env': { - 'NODE_ENV': JSON.stringify('production') + 'NODE_ENV': JSON.stringify('production'), + 'SENTRY_ENV': JSON.stringify(process.env.CONDITIONAL_SENTRY_ENV ?? "local-development") } }), new CopyPlugin({