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 c2873f45..79ec9b8e 100644 --- a/frontend/javascript/app.js +++ b/frontend/javascript/app.js @@ -1,10 +1,18 @@ // Install Sentry to send errors to Sentry import * as Sentry from '@sentry/browser'; -// 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 177074fc..b20a3d64 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,6 +31,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", @@ -3079,6 +3080,22 @@ "node": ">=8" } }, + "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 0df58b73..f29ee6a0 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,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 cb345e30..b80a7adb 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -2,12 +2,15 @@ const webpack = require('webpack'); const CopyPlugin = require('copy-webpack-plugin') const path = require('path'); const sass = require('sass'); +const dotenv = require('dotenv'); const jsSrc = path.resolve('./frontend'); const jsDest = path.resolve('./conditional/static'); const publicPath = 'static/js'; +dotenv.config(); const babelQuery = { + bootstrap-5 "presets": ["@babel/preset-env"], "plugins": [] } @@ -25,7 +28,8 @@ const 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({