---
title: "XhrTracing"
description: "Create spans for outgoing XHR requests in the browser and attach trace propagation headers to them."
url: https://docs.sentry.io/platforms/javascript/guides/wasm/configuration/integrations/xhrtracing/
---

# XhrTracing for Wasm

This integration only works inside a browser environment. It requires JavaScript SDK version 11.14.0 or later.

*Import name: `Sentry.xhrTracingIntegration`*

The XhrTracing integration creates spans for outgoing `XMLHttpRequest` (XHR) requests and attaches trace propagation headers to them.

The [BrowserTracing](https://docs.sentry.io/platforms/javascript/guides/wasm/configuration/integrations/browsertracing.md) integration adds this integration automatically, so you don't need to add it yourself. Configure it through BrowserTracing's request options, or set `traceXHR: false` to turn it off. These options also apply to [FetchTracing](https://docs.sentry.io/platforms/javascript/guides/wasm/configuration/integrations/fetchtracing.md).

```javascript
Sentry.init({
  integrations: [
    Sentry.browserTracingIntegration({
      shouldCreateSpanForRequest: (url) => !url.includes("/health"),
    }),
  ],
});
```

To set its options directly, add the integration yourself. An explicitly added XhrTracing integration takes precedence over BrowserTracing's settings.

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

### [shouldCreateSpanForRequest](https://docs.sentry.io/platforms/javascript/guides/wasm/configuration/integrations/xhrtracing.md#shouldCreateSpanForRequest)

| Type | `(url: string) => boolean` |
| ---- | -------------------------- |

Return `false` to skip creating a span for the request to the given URL. By default, spans are created for all requests.

### [enableHTTPTimings](https://docs.sentry.io/platforms/javascript/guides/wasm/configuration/integrations/xhrtracing.md#enableHTTPTimings)

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

Add HTTP timing data, such as DNS lookup and TLS handshake durations, to request spans using the Resource Timing API.

### [onRequestSpanStart](https://docs.sentry.io/platforms/javascript/guides/wasm/configuration/integrations/xhrtracing.md#onRequestSpanStart)

| Type | `(span: Span, requestInformation: { headers?: WebFetchHeaders }) => void` |
| ---- | ------------------------------------------------------------------------- |

Called right after a request span starts. Use it to set span attributes based on the request headers.

### [onRequestSpanEnd](https://docs.sentry.io/platforms/javascript/guides/wasm/configuration/integrations/xhrtracing.md#onRequestSpanEnd)

| Type | `(span: Span, responseInformation: { headers?: WebFetchHeaders, error?: unknown }) => void` |
| ---- | ------------------------------------------------------------------------------------------- |

Called when a request span ends. Use it to set span attributes based on the response headers or the request error.

Trace propagation headers are only attached to requests that match the top-level [`tracePropagationTargets`](https://docs.sentry.io/platforms/javascript/guides/wasm/configuration/options.md#tracePropagationTargets) option.

---

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.
