Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/product/dev-toolbar/img/configure-domain.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/product/dev-toolbar/img/feedback-panel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/product/dev-toolbar/img/issues-panel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/product/dev-toolbar/img/login-button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/product/dev-toolbar/img/login-popup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions docs/product/dev-toolbar/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
title: Dev Toolbar
sidebar_order: 120
description: "Bring critical Sentry insights and tools directly into your web app for easier troubleshooting with the Dev Toolbar."
---

<Alert level="info">
The Dev Toolbar is currently in **beta**. Beta features are still in progress and may have bugs. Please reach out on
[GitHub](https://github.com/getsentry/sentry-toolbar/issues) if you have any feedback or concerns.
</Alert>

Developers spend a lot of time troubleshooting their web apps on local, staging, and production environments. The Sentry Dev Toolbar pulls data from [sentry.io](http://sentry.io) and surfaces relevant actionable issues to you when you have the most context for understanding it: as you browse your own site. The Dev Toolbar is a floating widget in your web app, offering meaningful Sentry insights for the specific page being viewed through three different **page-aware** panels: Issues, Feedback and Feature Flags.

![Collapsed Dev Toolbar in context of a website](./img/toolbar-collapsed.png)

## Issues Panel

The issues panel shows you your highest priority frontend [issues](https://docs.sentry.io/product/issues/) for the page you are currently viewing. From the Dev Toolbar, you can quickly jump into specific issues in Sentry to get more detailed information and take action (for example, assign to a team member or mark as resolved). With the issues panel, you can browse the pages that are most important to your business and understand the top issues impacting your userbase.

![Dev Toolbar with the Issues Panel open](./img/issues-panel.png)

## Feedback Panel

The feedback panel shows you the most recent user feedback messages for the page you are on, so you can more easily contextualize user feedback. The feedback can include misleading UX, broken links, typos, and so on, covering more bugs and suboptimal experiences than code thrown errors. The feedback panel works by pulling feedback messages from [Sentry’s User Feedback Widget](https://docs.sentry.io/product/user-feedback/#user-feedback-widget).

![Dev Toolbar with the Feedback Panel open](./img/feedback-panel.png)

## Feature Flags Panel

Feature flags are a powerful tool that allow you to control the visibility of features in your app, enabling you to ship, test, and experiment with confidence. The feature flag panel allows you to quickly view and override feature flags that your team has enabled for your web application. You can override any feature flag to be ‘true’ or ‘false’ for your browser session, so you can verify its behavior and observe the impact it might have on errors. Learn more about how to [configure the feature flag panel](/product/dev-toolbar/setup/#implement-feature-flag-adapter).

[Learn more](/product/explore/feature-flags/) about what data Sentry can track related to your feature flagging system.

![Dev Toolbar with the Feature Flags Panel open](./img/feature-flags-panel.png)

## Login Flow

After setting up the Dev Toolbar you’ll see a “Login to Sentry” button floating in the center of the page. Your team will need to click this button and login to sentry before they can access any information from your Sentry organization.
![Dev Toolbar login button](./img/login-button.png)

After clicking the button, you should see a pop up for logging in to Sentry.
![Sentry log in pop up](./img/login-popup.png)

If it's your first time setting up the Dev Toolbar, there will be a button with a link to Sentry's Dev Toolbar settings page to configure your domain.
![Dev Toolbar configure domains button](./img/configure-domain.png)

You'll need to add your domain URL to Allowed Origins on Sentry's Dev Toolbar settings page.
![Sentry's Dev Toolbar Settings Page](./img/sentry-toolbar-settings.png)

Learn more about [deploying the toolbar to different environments](/product/dev-toolbar/setup/#deploying-to-production--dev-environments), and [conditionally inserting the toolbar script tag](/product/dev-toolbar/setup/#conditionally-inserting-script-tag).
144 changes: 144 additions & 0 deletions docs/product/dev-toolbar/setup.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
---
title: "Set Up"
sidebar_order: 10
description: "Get started with Sentry's Dev Toolbar, bringing critical Sentry insights and tools into your web app to help your team troubleshoot more effectively.."
---

<Alert level="info">
The Dev Toolbar is currently in **beta**. Beta features are still in progress and may have bugs. Please reach out on
[GitHub](https://github.com/getsentry/sentry-toolbar/issues) if you have any feedback or concerns.
</Alert>

## Set Up Your Web App

<Alert title="Note" level="warning">
Enabling performance is a prerequisite for having page-aware panels, as it allows us to collect page-specific issues and feedback through transactions.
</Alert>

You need to do two things to get the toolbar rendered on the page:
1. 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 the `defer` 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.
2. Call `window.SentryToolbar.init(initConfig)` to set up a toolbar instance on each page where you want to see the Dev Toolbar.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes it feel like you have to add both to every page instead of just the window.SentryToolbar.init(initConfig). Is that true? If not, we should consider removing the first script from this code snippet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryan953 I'm not sure how to rewrite so that it's clear that only the init needs to be added to every page. Any ideas?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both need to exist together whenever, and can be inserted whenever a full pageload happens. So if we're talking nextjs they can go in the custom _document.tsx file, or if it's laravel it'll go into master.blade.php for example.

Only having <script src="https://browser.sentry-cdn.com/sentry-toolbar/latest/toolbar.min.js"></script> will load up the JS bundle, but won't render anything. While calling window.SentryToolbar.init() without the other script tag existing will cause an error. So they both have to exist, in this order on the page.

```html
<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>
```

### Unmounting The Toolbar
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little confused by this, why would you want to mount the toolbar and then later unmount it on the same page? Am I misunderstanding this? Is there a brief use case we can provide to illustrate when you would want to do this?


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.
```html
<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>
```

## Implement Feature Flag Adapter

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, coming soon!

The interface you need to implement for an Adapter is:
```javascript
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](https://github.com/getsentry/sentry-toolbar/blob/301c31d561a81e3fd8ffc9532aad3a60af685916/src/env/demo/MockFeatureFlagIntegration.tsx) is an example adapter to use as a reference.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like it needs to be above the interface but I can't think of how I would word it.


## Init Configuration Fields

The following fields can be passed into the `.init()` function.

For example, a minimal configuration looks like:
```javascript
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](/product/dev-toolbar/setup//#implement-feature-flag-adapter) 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://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` |


## Deploying To Production & Dev Environments
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:
```javascript
// 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.

## Conditionally Inserting Script Tag

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`](http://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.
Loading