Sentry-javascript: How to update environment after initial init

Created on 10 Oct 2018  路  5Comments  路  Source: getsentry/sentry-javascript

Due to circumstances, I can only retrieve an app's proper environment asynchronously.
Initializing Sentry ASAP forces my hand to call init without the proper environment.

Is there a way for me to update the Sentry environment after init?
Otherwise, if I move the init call after the environment is obtained, errors that occur before that might pass unobserved.

Most helpful comment

small FYI: scope.addEventProcessor expected a Promise, so:

Sentry.configureScope(scope =>
  scope.addEventProcessor(
    event =>
      new Promise(resolve =>
        resolve({
          ...event,
          environment: 'something'
        })
      )
  )
);

All 5 comments

Sentry.configureScope(scope => scope.addEventProcessor(event => ({
  ...event,
  environment: 'something'
})))

or in ES5:

Sentry.configureScope(function (scope) {
  scope.addEventProcessor(function (event) {
    event.environment = 'something';
    return event;
  });
});

Cheers!

Useful info, thanks @kamilogorek!

small FYI: scope.addEventProcessor expected a Promise, so:

Sentry.configureScope(scope =>
  scope.addEventProcessor(
    event =>
      new Promise(resolve =>
        resolve({
          ...event,
          environment: 'something'
        })
      )
  )
);

Right, sorry 馃槄

copy/pasteable version for anyone who needs the ES5 method of adding release:
```
Sentry.configureScope(function (scope) {
scope.addEventProcessor(function (event) {
return new Promise(function(resolve) {
event.release = '1.2.3.4';
return resolve(event);
});
});
});

Was this page helpful?
0 / 5 - 0 ratings