---
title: "BrowserTracing"
description: "Capture browser traces for page loads and requests, and see where they fail or slow down."
url: https://docs.sentry.io/platforms/javascript/guides/svelte/configuration/integrations/browsertracing/
---

# BrowserTracing for Svelte

This integration only works inside a browser environment.

*Import name: `Sentry.browserTracingIntegration`*

With [tracing](https://docs.sentry.io/concepts/key-terms/tracing.md), Sentry follows page loads, navigations, and requests in the browser so you can see where they fail or slow down. Spans record each of those operations.

The BrowserTracing integration sets up automatic tracing for your frontend applications. It captures transactions and spans from the browser and sends them to Sentry.

Read more about [setting up BrowserTracing](https://docs.sentry.io/platforms/javascript/guides/svelte/tracing.md).

```JavaScript
Sentry.init({
  integrations: [Sentry.browserTracingIntegration()],
});
```

See [Configuration Options](https://docs.sentry.io/platforms/javascript/guides/svelte/tracing/instrumentation/automatic-instrumentation.md#configuration-options) for a full list of available options for `browserTracingIntegration`

## [Included Integrations](https://docs.sentry.io/platforms/javascript/guides/svelte/configuration/integrations/browsertracing.md#included-integrations)

BrowserTracing creates pageload and navigation spans itself. Since SDK version 11.14.0, it sets up the rest of its features by adding these integrations for you:

| Integration                                                                                                          | What it captures                                  | BrowserTracing options                                                                                    |
| -------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
| [WebVitals](https://docs.sentry.io/platforms/javascript/guides/svelte/configuration/integrations/webvitals.md)       | LCP, CLS, and INP                                 | `webVitals`                                                                                               |
| [FetchTracing](https://docs.sentry.io/platforms/javascript/guides/svelte/configuration/integrations/fetchtracing.md) | Spans and trace headers for `fetch` requests      | `traceFetch`, `shouldCreateSpanForRequest`, `enableHTTPTimings`, `onRequestSpanStart`, `onRequestSpanEnd` |
| [XhrTracing](https://docs.sentry.io/platforms/javascript/guides/svelte/configuration/integrations/xhrtracing.md)     | Spans and trace headers for XHR requests          | `traceXHR`, `shouldCreateSpanForRequest`, `enableHTTPTimings`, `onRequestSpanStart`, `onRequestSpanEnd`   |
| [LinkedTraces](https://docs.sentry.io/platforms/javascript/guides/svelte/configuration/integrations/linkedtraces.md) | Links from each trace to the previous one         | `linkPreviousTrace`, `consistentTraceSampling`                                                            |
| [LongTasks](https://docs.sentry.io/platforms/javascript/guides/svelte/configuration/integrations/longtasks.md)       | Long animation frames and long tasks              | `enableLongTask`, `enableLongAnimationFrame`                                                              |
| [Resources](https://docs.sentry.io/platforms/javascript/guides/svelte/configuration/integrations/resources.md)       | Scripts, stylesheets, images, and other resources | `ignoreResourceSpans`                                                                                     |

You don't need to change anything: the options above still work on `browserTracingIntegration`. If you add one of these integrations yourself, your instance takes precedence over the one BrowserTracing would add.

## [Configuration Options](https://docs.sentry.io/platforms/javascript/guides/svelte/configuration/integrations/browsertracing.md#configuration-options)

These options configure pageload and navigation spans.

### [instrumentPageLoad](https://docs.sentry.io/platforms/javascript/guides/svelte/configuration/integrations/browsertracing.md#instrumentPageLoad)

| Type    | `boolean` |
| ------- | --------- |
| Default | `true`    |

Enable/disable automatic `pageload` span creation on initial page load.

### [instrumentNavigation](https://docs.sentry.io/platforms/javascript/guides/svelte/configuration/integrations/browsertracing.md#instrumentNavigation)

| Type    | `boolean` |
| ------- | --------- |
| Default | `true`    |

Enable/disable automatic `navigation` span creation on history changes.

### [instrumentBfcacheRestore](https://docs.sentry.io/platforms/javascript/guides/svelte/configuration/integrations/browsertracing.md#instrumentBfcacheRestore)

| Available since | `11.0.0`  |
| --------------- | --------- |
| Type            | `boolean` |
| Default         | `true`    |

Start a navigation span when the page is restored from the back/forward cache. This starts a new trace for activity after the restore. It is independent of `instrumentNavigation`.

Web Vitals for restored pages are collected by default in stream mode. Set `webVitals: { bfcacheNavigations: false }` to disable this collection. See [WebVitals](https://docs.sentry.io/platforms/javascript/guides/svelte/configuration/integrations/webvitals.md#bfcachenavigations) for requirements.

### [detectRedirects](https://docs.sentry.io/platforms/javascript/guides/svelte/configuration/integrations/browsertracing.md#detectRedirects)

| Type    | `boolean` |
| ------- | --------- |
| Default | `true`    |

Detect redirects and avoid creating separate `navigation` spans for them. Set to `false` to create a span for every navigation.

### [beforeStartSpan](https://docs.sentry.io/platforms/javascript/guides/svelte/configuration/integrations/browsertracing.md#beforeStartSpan)

| Type | `(options: StartSpanOptions) => StartSpanOptions` |
| ---- | ------------------------------------------------- |

Modify span data before it's captured. Useful for adding context or normalizing URLs with dynamic segments:

One common use case is parameterizing transaction names. For both `pageload` and `navigation` transactions, the `browserTracingIntegration` uses the browser's `window.location` value to generate a transaction name. Using `beforeStartSpan` lets you modify the transaction name to make it more generic, so that for example, transactions named `GET /users/12312012` and `GET /users/11212012` can both be renamed to `GET /users/:userid`. That way they'll be grouped together.

```javascript
Sentry.init({
  // ...
  integrations: [
    Sentry.browserTracingIntegration({
      beforeStartSpan: (context) => {
        return {
          ...context,
          // You could use your UI's routing library to find the matching
          // route template here. We don't have one right now, so do some basic
          // parameter replacements.
          name: location.pathname
            .replace(/\/[a-f0-9]{32}/g, "/<hash>")
            .replace(/\/\d+/g, "/<digits>"),
        };
      },
    }),
  ],
});
```

### [idleTimeout](https://docs.sentry.io/platforms/javascript/guides/svelte/configuration/integrations/browsertracing.md#idleTimeout)

| Type    | `number` |
| ------- | -------- |
| Default | `1000`   |

Time in ms to wait before finishing a pageload/navigation span when no unfinished child spans remain.

### [finalTimeout](https://docs.sentry.io/platforms/javascript/guides/svelte/configuration/integrations/browsertracing.md#finalTimeout)

| Type    | `number` |
| ------- | -------- |
| Default | `30000`  |

Maximum duration in ms for pageload/navigation spans. Spans exceeding this are automatically finished.

### [childSpanTimeout](https://docs.sentry.io/platforms/javascript/guides/svelte/configuration/integrations/browsertracing.md#childSpanTimeout)

| Type    | `number` |
| ------- | -------- |
| Default | `15000`  |

Maximum time in ms a child span can run before the parent pageload/navigation span is finished.

### [markBackgroundSpan](https://docs.sentry.io/platforms/javascript/guides/svelte/configuration/integrations/browsertracing.md#markBackgroundSpan)

| Type    | `boolean` |
| ------- | --------- |
| Default | `true`    |

Mark pageload/navigation spans as "cancelled" when the tab moves to background. Recommended to keep enabled for accurate measurements.

### [enableReportPageLoaded](https://docs.sentry.io/platforms/javascript/guides/svelte/configuration/integrations/browsertracing.md#enableReportPageLoaded)

| Available since | `10.13.0` |
| --------------- | --------- |
| Type            | `boolean` |
| Default         | `false`   |

Enable the [`Sentry.reportPageLoaded()` function](https://docs.sentry.io/platforms/javascript/guides/svelte/apis.md#reportPageLoaded).

---

Find other pages: [Sitemap](https://docs.sentry.io/sitemap.md) lists every page with a one-line summary, and [llms.txt](https://docs.sentry.io/llms.txt) gives an overview with guidance for agents.
