Skip to main content

How can Sentry be disabled and removed in specific environments?

Updated over a month ago

Issue

I would like to disable Sentry in specific environments, such as production, while keeping it active in QA and testing environments.

Applies To

  • All customers

Resolution

One method is to avoid initializing Sentry in environments where it is not needed. Use environment variables to determine whether Sentry.init() should be called.

You can also consider filtering out all events based on a certain environment using beforeSend. This method allows you to initialize Sentry in all environments but drop events before they are sent. An example in React:

import * as Sentry from "@sentry/react";

Sentry.init({

dsn: "your-dsn-here",

beforeSend(event) {

if (process.env.REACT_APP_ENVIRONMENT === "production") {

return null; // Drop event in production

}

return event;

},

});

Did this answer your question?