Issue
I cannot find a way to change a release or environment for events dynamically. For example, I am interested in changing all outgoing event environments on a button click.
Applies To
- Customers on JavaScript SDKs
- Anyone using EventProcessor
- Anyone trying to change event properties dynamically
Resolution
The EventProcessor can be used globally or within scope by calling Sentry.addEventProcessor to dynamically change event properties that can be set by the event itself such as a release or environment. You could configure that for a button click like below so that all outgoing events will pick up this dynamic environment value within an application.
let myDyamicEnvironment = 'development';
Sentry.addEventProcessor((event, hint) => ({
...event,
// override events environment value
environment: myDynamicEnviroment,
}));
const handleClick = (e) => {
// assign events environment value
myDynamicEnvironment = 'production';
};
Making this change would alter how your events are processed and wont override SDK options. Some things to consider is that Sentry applies processors in an undetermined order, potentially causing event changes to be made even after the EventProcessor runs. For example, event changes could still be made if using multiple EventProcessors or by later modifying events with a beforeSend.
You can read more on EventProcessors and how it behaves together with other methods in Lifecycle hooks.