Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
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.
52 changes: 52 additions & 0 deletions docs/product/dev-toolbar/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
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 (e.g. Sentry project, issue title, and description, and when the issue was first and last seen) and take action (e.g. 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 user base.

![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 often describes suboptimal experiences that are not strictly code-thrown errors, such as misleading UX, broken links, and typos. The feedback panel works by pulling feedback messages from [Sentry’s User Feedback Widget](https://docs.sentry.io/product/user-feedback/#user-feedback-widget). Just like with the Issues panel, clicking on a particular user feedback will take you to the full detailed User Feedback page within Sentry.

![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 locally. 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).

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

![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. To access any information from your Sentry organization you have to click this button and login to sentry.
![Dev Toolbar login button](./img/login-button.png)

After clicking the button, you will 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 in Sentry on the Settings > Project > Dev Toolbar page.
![Sentry's Dev Toolbar Settings Page](./img/sentry-toolbar-settings.png)

Learn more about setting up the toolbar, including configuring a feature flag provider and integrating the toolbar in different environments, on the next page.
150 changes: 150 additions & 0 deletions docs/product/dev-toolbar/setup.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
---
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 level="warning">
[Enabling tracing](/platforms/javascript/tracing/) is a prerequisite using the Developer Toolbar. Tracing is used to collect page-specific issues and feedback through transactions.
</Alert>

You need to complete two steps to get the toolbar rendered on the page:
1. Add or dynamically inject the following script into your web app:
```html
<script src="https://browser.sentry-cdn.com/sentry-toolbar/latest/toolbar.min.js"></script>
```
It is recommended that you add the script tag at the bottom of the page so it doesn’t block other critical JavaScript.
Copy link
Contributor

@coolguyzone coolguyzone Dec 13, 2024

Choose a reason for hiding this comment

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

Since placement is important, can we be a little more specific here? Should it be at the body of the <Body> element?


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 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 src="https://browser.sentry-cdn.com/sentry-toolbar/latest/toolbar.min.js"></script>
<script>
const unmountToolbar = window.SentryToolbar.init({ … });

// sometime later...
unmountToolbar();
</script>
```

## Init Configuration Fields
Copy link
Contributor

Choose a reason for hiding this comment

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

In other parts of the docs I've more commonly seen these referred to as 'options', should we stick to that convention here? I'm also open to 'fields' being the correct term, if that's the case we should update other docs to maintain consistency.

@lizokm Do you have any thoughts on 'fields' vs 'options'?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've changed it to 'options' to stick with the convention


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

At minimum, you should be calling `.init()` with these three fields:
```javascript
window.SentryToolbar.init({
organizationSlug: 'acme',
projectIdOrSlug: 'website',
environment: 'production'
});
```
And you can include any additional fields from this list:

| 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` |
Copy link
Contributor

@coolguyzone coolguyzone Dec 13, 2024

Choose a reason for hiding this comment

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

Suggested change
| `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` |
| `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` |

Do we need to share all the different ways to set this to see results for all environments here('undefined', '""', or '[]')? It would simplify things if we just picked one.

| `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) below | `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` |

## 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](https://github.com/getsentry/sentry-toolbar/issues/150) soon.

The adapter interface 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.



## Deploying To Dev, Staging, and Production Environments
Since the Dev Toolbar is deployed onto specific pages, it's strongly recommended that you consider which environments the toolbar should apply to.

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, but in production only show the toolbar **if** an employee is logged in.


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`](https://github.com/getsentry/sentry-toolbar/blob/main/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.
Loading