Set Up
Get started with Sentry's Dev Toolbar, bringing critical Sentry insights and tools into your web app to help your team troubleshoot more effectively..
The Dev Toolbar is currently in beta. Beta features are still in progress and may have bugs. Please reach out on GitHub if you have any feedback or concerns.
Note
Enabling tracing is a prerequisite for having page-aware panels, as it allows us to collect page-specific issues and feedback through transactions.
You need to complete two steps to get the toolbar rendered on the page:
- Add or dynamically inject
<script defer src="https://browser.sentry-cdn.com/sentry-toolbar/latest/toolbar.min.js"></script>
into your web app. This script uses thedefer
attribute so that it does not block document parsing. The script tag can be inserted at the bottom of the page so it doesn’t block other critical Javascript. - Call
window.SentryToolbar.init(initConfig)
to set up a toolbar instance on each page where you want to see the Dev Toolbar.Copied<html> <head> ... </head> <body> … <script async src="https://browser.sentry-cdn.com/sentry-toolbar/latest/toolbar.min.js" ></script> <script> window.SentryToolbar.init({ … }); </script> </body> </html>
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.
<script
defer
src="https://browser.sentry-cdn.com/sentry-toolbar/latest/toolbar.min.js"
></script>
<script>
const unmountToolbar = window.SentryToolbar.init({ … });
// sometime later...
unmountToolbar();
</script>
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, and also store and retrieve a list of overrides to apply to your local browser session.
We plan to create adapters for OpenFeature and LaunchDarkly soon!
The interface you need to implement for an Adapter is:
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);
}
MockFeatureFlagIntegration.tsx is an example adapter to use as a reference.
The following fields can be passed into the .init()
function.
For example, a minimal configuration looks like:
window.SentryToolbar.init({
organizationSlug: ‘acme’,
projectIdOrSlug: ‘website’,
environment: ‘production’
});
Field Name | Type | Description | Default Value |
---|---|---|---|
organizationSlug | string | The organization that users should login to. For example `acme` | Required Value |
projectIdOrSlug | string | number | The project for which this website/webapp is associated. | Required Value |
environment (optional) | string | string[] | undefined | The 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 | undefined | See Implement FeatureFlagAdapter above | undefined |
sentryOrigin (optional) | string | undefined | The 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 | undefined | The `id` given to the <div> that is created to contain the toolbar html. | "sentry-toolbar" |
debug (optional) | string | undefined | A 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 | undefined | Where to mount the toolbar in the DOM. | document.body |
Since the Dev Toolbar is deployed onto specific pages, it's strongly recommended that you consider which environments your app is deployed to should have the toolbar available.
In dev and staging environments, you might want to unconditionally include the toolbar so that all developers and testers can use it and quickly go from the page they're looking at back to Sentry for further debugging.
In production however, it's strongly recommended to conditionally include the Dev Toolbar <script>
tag so that only members of your Sentry organization can see it. The specific implementation for conditionally including the Dev Toolbar is something you'll need to write based on how your app works and how your dev team is set up.
For example, if your web application requires authentication to access, you could add a conditional where the Dev Toolbar is shown always when deployed to development and staging and is shown only if an employee is logged in when deployed to production.
The code might look like this:
// example conditions to render the toolbar in different environments.
const env = process.env.SENTRY_ENVIRONMENT || 'development';
const isEmployee = user.email.endsWith('@joshys-pizza.com')
const isDev = env === 'development' || env === staging;
const isEmployeeInProd = env === 'production' && isEmployee;
if (isDev || isEmployeeInProd) {
SentryToolbar.init({ ... });
}
If the toolbar <script>
is accidentally included on your site, and SentryToolbar.init()
is called, then a "Login to Sentry" button will be visible to the public. This is not ideal, but your data in Sentry will still be safe as users outside of your Sentry organization will not be able to authenticate themselves.
It's possible to dynamically insert the script tag inside a single-page app, prior to calling SentryToolbar.init()
, so that it’s only visible to authorized users. See docs/conditional-script.md
for example code. This will help reduce network traffic for your users because they do not have the credentials needed to login. This example code will be eventually implemented as an NPM package, but for now it can be done manually.
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").