Environment variable does not respect multiple sentry Nodes
Closed this issue · 2 comments
Description
If you have multiple sentry nodes, the environment variable won't respect the environment in the config because Sentry is part of a global scope (not a local scope)
Example
As you can see here there are multiple sentry nodes with a different Environment variable but due to Sentry's global scope this isn't respected. All Sentry nodes use the last Environment variable found in the last Sentry node initialized.
Potential Solution
I patched it like so to avoid this switch. And inside my .env
I have ENVIRONMENT=STAGING
.
diff --git a/node_modules/node-red-contrib-sentrynode/sentry/sentry.js b/node_modules/node-red-contrib-sentrynode/sentry/sentry.js
index cb8508f..39fd3c6 100644
--- a/node_modules/node-red-contrib-sentrynode/sentry/sentry.js
+++ b/node_modules/node-red-contrib-sentrynode/sentry/sentry.js
@@ -110,11 +110,12 @@ module.exports = function(RED) {
function SentryNode(config) {
RED.nodes.createNode(this, config);
var node = this;
+ var ENVIRONMENT = RED.util.getSetting(node, 'ENVIRONMENT')
/**
* init the sentry only on deployment
*/
- Sentry.init({ dsn: config.dsn, environment: config.environment || 'debug' });
+ Sentry.init({ dsn: config.dsn, environment: ENVIRONMENT || config.environment || 'debug' });
node.on('input', function(msg, send, done) {
Thanks for reporting the issue, and for providing a fix.
Note that when preceding ENVIRONMENT
over config.environment
that means priority is always for ENVIRONMENT
, and the node config in most cases gets ignored, but preceding config.environment
makes the Sentry environment overridable by node config, in any case, it needed that.
Please open a pull request for this fix and consider the above note, and I will merge it.
@ibraheem-ghazi Sounds good. Here is a PR with this feature:
#7
Please review it when you have a chance!