|
| 1 | +--- |
| 2 | +title: FetchIntegration |
| 3 | +description: "A default integration that creates spans and attaches tracing headers to fetch requests in Cloudflare Workers." |
| 4 | +supported: |
| 5 | + - javascript.cloudflare |
| 6 | +--- |
| 7 | + |
| 8 | +<Alert> |
| 9 | + |
| 10 | +This integration only works inside the Cloudflare Workers runtime. |
| 11 | + |
| 12 | +</Alert> |
| 13 | + |
| 14 | +_Import name: `Sentry.fetchIntegration`_ |
| 15 | + |
| 16 | +This integration is enabled by default. If you want to disable it, you can [modify your default integrations](./../#modifying-default-integrations). |
| 17 | + |
| 18 | +The `fetchIntegration` creates [spans](/concepts/key-terms/tracing/distributed-tracing/#traces-transactions-and-spans) and attaches tracing headers to fetch requests in Cloudflare Workers. |
| 19 | + |
| 20 | +```JavaScript |
| 21 | +Sentry.init({ |
| 22 | + integrations: [Sentry.fetchIntegration()], |
| 23 | +}); |
| 24 | +``` |
| 25 | + |
| 26 | +## Options |
| 27 | + |
| 28 | +### `breadcrumbs` |
| 29 | + |
| 30 | +_Type: `boolean`_ |
| 31 | + |
| 32 | +If set to false, no breadcrumbs will be captured. |
| 33 | + |
| 34 | +### `shouldCreateSpanForRequest` |
| 35 | + |
| 36 | +_Type: `(url: string) => boolean`_ |
| 37 | + |
| 38 | +Allows you to define a method to determine whether or not to create spans to track outgoing requests to the given URL. By default, spans will be created for all outgoing requests. |
| 39 | + |
| 40 | +```JavaScript |
| 41 | +Sentry.init({ |
| 42 | + integrations: [ |
| 43 | + Sentry.fetchIntegration({ |
| 44 | + shouldCreateSpanForRequest: (url) => { |
| 45 | + // Only create spans for external API calls |
| 46 | + return url.includes('api.example.com'); |
| 47 | + }, |
| 48 | + }), |
| 49 | + ], |
| 50 | +}); |
| 51 | +``` |
| 52 | + |
| 53 | +## Usage |
| 54 | + |
| 55 | +The fetch integration automatically instruments all `fetch()` calls made within your Cloudflare Worker. This includes: |
| 56 | + |
| 57 | +- Creating performance spans for outgoing HTTP requests |
| 58 | +- Adding tracing headers to continue distributed traces |
| 59 | +- Capturing breadcrumbs for debugging purposes |
| 60 | +- Tracking request duration and response status |
| 61 | + |
| 62 | +The integration works with both the standard `fetch()` API and any libraries that use fetch under the hood. |
| 63 | + |
| 64 | +<Alert> |
| 65 | + |
| 66 | +**Note:** If you need to disable fetch instrumentation for specific requests, use the `shouldCreateSpanForRequest` option to filter out unwanted requests. |
| 67 | + |
| 68 | +</Alert> |
0 commit comments