|
| 1 | +--- |
| 2 | +title: Browser Profiling |
| 3 | +sidebar_order: 5000 |
| 4 | +supported: |
| 5 | + - javascript |
| 6 | +notSupported: |
| 7 | + - javascript.bun |
| 8 | + - javascript.cordova |
| 9 | + - javascript.capacitor |
| 10 | + - javascript.deno |
| 11 | + - javascript.cloudflare |
| 12 | + - javascript.node |
| 13 | + - javascript.aws-lambda |
| 14 | + - javascript.azure-functions |
| 15 | + - javascript.connect |
| 16 | + - javascript.express |
| 17 | + - javascript.fastify |
| 18 | + - javascript.gcp-functions |
| 19 | + - javascript.hapi |
| 20 | + - javascript.koa |
| 21 | + - javascript.nestjs |
| 22 | +description: "Collect & view performance insights for JavaScript programs with Sentry's JavaScript Profiling integration." |
| 23 | +--- |
| 24 | + |
| 25 | +<Note> |
| 26 | + |
| 27 | +Browser Profiling is currently in beta. Beta features are still in progress and may have bugs. We recognize the irony. |
| 28 | + |
| 29 | +</Note> |
| 30 | + |
| 31 | +The browser profiling integration is built using the [JS Self-Profiling API](https://wicg.github.io/js-self-profiling/) and will likely only move out of beta once the specification progresses and gains adoption. See [platform status](https://chromestatus.com/feature/5170190448852992). |
| 32 | + |
| 33 | +Note that since the profiling API is currently only exposed in Chromium, profiles collected only include that demographic. We hope that as the API gains adoption, other browsers will implement it as well. |
| 34 | + |
| 35 | +<PlatformContent includePath="profiling/index/why-profiling" /> |
| 36 | + |
| 37 | +## Prerequisites |
| 38 | + |
| 39 | +To get started with JavaScript browser profiling, you'll need to: |
| 40 | + |
| 41 | +- Install the <PlatformSdkPackageName fallback="@sentry/browser"/> SDK, minimum version 7.60.0 |
| 42 | +- Configure the document response header to include `Document-Policy: js-profiling` |
| 43 | +- Configure the SDK to use the `BrowserProfilingIntegration` and set `profilesSampleRate` |
| 44 | + |
| 45 | +## Step 1: Install the <PlatformOrGuideName/> SDK |
| 46 | + |
| 47 | +<PlatformSection notSupported={["javascript.electron"]}> |
| 48 | + |
| 49 | +Install our <PlatformOrGuideName/> SDK using either `yarn` or `npm`, the minimum version that supports profiling is **7.60.0**. |
| 50 | + |
| 51 | +</PlatformSection> |
| 52 | + |
| 53 | +<PlatformSection supported={["javascript.electron"]}> |
| 54 | + |
| 55 | +Install our Electron SDK using either `yarn` or `npm`, the minimum version that supports profiling is **4.16.0**. |
| 56 | + |
| 57 | +</PlatformSection> |
| 58 | + |
| 59 | +<PlatformContent includePath="profiling/automatic-instrumentation-intro" /> |
| 60 | + |
| 61 | +## Step 2: Add Document-Policy: js-profiling header |
| 62 | + |
| 63 | +For the JavaScript browser profiler to start, the document response header needs to include a `Document-Policy` header key with the `js-profiling` value. |
| 64 | + |
| 65 | +<PlatformContent includePath="profiling/automatic-instrumentation-headers" /> |
| 66 | + |
| 67 | +## Step 3: Configure the <PlatformOrGuideName/> SDK |
| 68 | + |
| 69 | +Configuration should happen as early as possible in your application's lifecycle. Once this is done, Sentry's JavaScript SDK will capture all unhandled exceptions and transactions. |
| 70 | + |
| 71 | +<PlatformContent includePath="profiling/automatic-instrumentation-setup" /> |
| 72 | + |
| 73 | +## The Difference Between DevTools & Sentry's JavaScript Browser Profiler |
| 74 | + |
| 75 | +What does Sentry's JavaScript browser profile offer that Chrome DevTools does not? |
| 76 | + |
| 77 | +- Sentry's JavaScript profiler runs in production and captures real user data, showing real-world performance. DevTools runs locally and only shows profiles of what's running on your machine. |
| 78 | +- Sentry runs at a lower sampling rate of 100Hz with a 10ms sample period versus a sampling rate of 1000Hz and a 1ms sample period for DevTools. |
| 79 | +- Sentry supports deobfuscation, making it so that all the function names in your code are correct. Typically, when you run JavaScript code, it's minified, meaning that all the function names are replaced with machine-generated abbreviations. |
| 80 | + |
| 81 | +Please note, that since the browser profiling API is currently only implemented in Chromium-based browsers, the profiles collected with Sentry's JavaScript browser profiling will inherently be biased toward that demographic. This is something that you'll need to consider if you're basing your decisions on the data collected. |
| 82 | + |
| 83 | +We hope that as the Javascript browser profiling API gains adoption, other browsers will implement it as well. If you find the browser profiling feature helpful and would like to see it gain further adoption, please consider supporting the spec at the official WICG repository. |
0 commit comments