Set Up Dev Toolbar

Get started with Sentry's Dev Toolbar, bringing critical Sentry insights and tools into your web app to help your team troubleshoot more effectively.

For the Sentry Dev Toolbar to work best, enable tracing in your app. With tracing enabled, the Dev Toolbar will be able to associate issues and feedback with the current URL in the browser location.

Since the Dev Toolbar will be visible to users within your app, it's important to consider which environments should render it. See the FAQ: "In what environments should I enable the Dev Toolbar?" for tips.

You will need to edit the Project Settings page to allow the Toolbar to connect to Sentry. Add any production, staging, or development domains to the list. Only add domains that you trust and control to this list.

Sentry's Dev Toolbar Settings Page

If you are developing a React based application, it's time to add the Toolbar into your package.json file.

Or, you can skip ahead to the next step to find the CDN configuration instructions.

Copied
npm install --save @sentry/developer-toolbar

Finally, whether you have a React application or are loading the Toolbar from the CDN you need to initialize the Toolbar using JavaScript. This will prompt any visitor to login to your Sentry organization.

Copied
import { useSentryToolbar } from "@sentry/developer-toolbar";

useSentryToolbar({
  // Remember to conditionally enable the Toolbar.
  // This will reduce network traffic for users
  // who do not have credentials to login to Sentry.
  enabled,

  initProps: {
    organizationSlug: "acme",
    projectIdOrSlug: "website",
  },
});

See the FAQ: "How can I conditionally initialize the Toolbar?" for help implementing conditions for different environments.

At minimum, you must set organizationSlug and projectIdOrSlug.

The complete list of options is here:

OptionTypeDescriptionDefault Value
organizationSlugstringThe organization that users should login to. For example 'acme'Required Value
projectIdOrSlugstring | numberThe project for which this website/webapp is associated.Required Value
environment (optional)string | string[] | undefinedThe environment of this deployment. Used to narrow search results in the Toolbar UI. Set to undefined or "" or [] if you want to see results from all environments.undefined
placement (optional)'right-edge' | 'bottom-right-corner'Where to render the Toolbar on the screen.'right-edge'
theme (optional)'system' | 'dark' | 'light'Whether to use dark or light mode.'system'
featureFlags (optional)FeatureFlagAdapter | undefinedSee Feature Flag Panel belowundefined
sentryOrigin (optional)string | undefinedThe origin where Sentry can be found. Used for loading the connection to Sentry, and generating links to the website. For example: 'https://acme.sentry.io''https://sentry.io'
domId (optional)string | undefinedThe id given to the <div> that is created to contain the Toolbar html.'sentry-toolbar'
debug (optional)string | undefinedA comma separated string of debug targets to enable. Example: 'logging,state'. If the list contains 'all' or 'true' then all targets will be enabled. Valid targets: 'logging' 'login-success' 'settings' 'state'undefined
mountPoint (optional)HTMLElement | () => HTMLElement | undefinedWhere to mount the Toolbar in the DOM.document.body

The React hook supports some other top-level options. The defaults values are:

Copied
useSentryToolbar({
  initProps: {
    organizationSlug: "acme",
    projectIdOrSlug: "website",
  },

  // Optional:
  enabled: true,

  // Optional: Either `version` or `cdn`
  // If both are set then `cdn` will override `version`
  version: "latest",
  cdn: "https://browser.sentry-cdn.com/sentry-toolbar/latest/toolbar.min.js",
});
OptionsTypeDescriptionDefault Value
enabledbooleand (optional)Conditionally initialize the toolbar. Set this to false to avoid requesting the toolbar code on the browser, or to safely unmount an existing toolbar instancetrue
versionstring (optional)Request a speicifc version of the toolbar from the CDN. It's recommended to use latest for automatic updates. See https://github.com/getsentry/sentry-toolbar/releases for a list of available release tags.'latest'
cdnstring (optional)Overrides the version field above. Setting the CDN is useful if you want to self-host a specific version of the Toolbar.'https://browser.sentry-cdn.com/sentry-toolbar/latest/toolbar.min.js'

If you have called SentryToolbar.init({...}) to render the Toolbar, but now want to manually remove or unmount it from the page, you can call the cleanup function that is returned from init(). This will unmount all the injected HTML and CSS. Login credentials will not be removed, so you can re-insert the toolbar and still be authenticated.

If you are using the React hook, then the toolbar will unmount when the react component is unmounted. Or if you set enabled: false.

Copied
const unmountToolbar = window.SentryToolbar.init({ ... });

// sometime later...
unmountToolbar();

In order to integrate your feature flagging platform with the Dev Toolbar, you will need an adapter that can read flag data from your provider. It will also store and retrieve a list of overrides to apply to your local browser session.

There is a built-in OpenFeatureAdapter that is compatible with the open-feature/js-sdk-contrib. To use it, call the SentryToolbar.OpenFeatureAdapter implementation.

Copied
<script>
  // Define your provider
  const provider = new FlagdWebProvider({...});

  // Set the provider into the OpenFeature SDK
  OpenFeature.setProvider(provider);

  window.SentryToolbar.init({
    ...
    // Set the provider into the OpenFeatureAdapter
    featureFlags: window.SentryToolbar.OpenFeatureAdapter({provider})
  });
</script>

You can also create your own adapter by implementing the FeatureFlagAdapter interface.

The adapter interface is:

Copied
type FlagValue = boolean | string | number | undefined;
type FlagMap = Record<string, FlagValue>;
interface FeatureFlagAdapter {
  /**
   * All known flag names and their evaluated values.
   */
  getFlagMap: () => Promise<FlagMap>;

  /**
   * Any overridden or manually set flags and values.
   */
  getOverrides: () => Promise<FlagMap>;

  /**
   * Manually set a flag to be a specific value, overriding the evaluated value.
   */
  setOverride: (name: string, override: FlagValue) => void;

  /**
   * A callback to clear all overrides from this browser.
   */
  clearOverrides: () => void;

  /**
   * Deeplink into your external feature-flag provider and find out more about
   * this specific flag.
   */
  urlTemplate?: undefined | ((name: string) => string | URL | undefined);
}

MockFeatureFlagAdapter.tsx is an example adapter to use as a reference.

Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").