---
title: Fetch configuration
description: Configuration for Allure Fetch | Customize attachment name | Control body capture | Redact sensitive values
---

# Allure Fetch configuration

This page describes the options that affect the behavior of the [Allure Fetch](/docs/fetch/) integration.

All options are passed as the second argument to `withAllure()` or `instrumentGlobalFetch()`:

```ts
withAllure(fetch, {
  // options here
});

instrumentGlobalFetch({
  // options here
});
```

`withAllure()` validates its first argument and throws `"allure-fetch requires a fetch implementation"` immediately if it is `null`, `undefined`, or otherwise falsy.

`instrumentGlobalFetch()` throws `"allure-fetch can't instrument global fetch because globalThis.fetch is not defined"` if `globalThis.fetch` is absent — for example, in Node.js environments without a `fetch` polyfill.

## Customize the attachment name

- `attachmentName: string | ((exchange: HttpExchange) => string)`

Specify the name under which Allure Fetch creates the attachment for each HTTP exchange. For the shape of the `HttpExchange` argument, see [Allure Fetch reference](/docs/fetch-reference/).

By default, each attachment is named `"HTTP Exchange"`. To use a different static name for all attachments, pass a string:

```ts
withAllure(fetch, {
  attachmentName: "API request",
});
```

To derive the name dynamically from the exchange data, pass a function. The URL available in `exchange.request.url` is the raw, unredacted URL. Redaction only applies to the structured fields inside the attachment (`query`, `headers`, `cookies`, `form`), not to the URL string used in `exchange.request.url`.

```ts
withAllure(fetch, {
  attachmentName: (exchange) =>
    `${exchange.request.method} ${new URL(exchange.request.url).pathname}`,
});
```

## Control body capture

- `captureRequestBody: boolean` (default: `true`)
- `captureResponseBody: boolean` (default: `true`)
- `maxBodySize: number` (default: `65536`)

By default, Allure Fetch captures both the request and response body. Set `captureRequestBody` or `captureResponseBody` to `false` to skip one or both:

```ts
withAllure(fetch, {
  captureRequestBody: false,
  captureResponseBody: false,
});
```

`maxBodySize` sets the maximum number of bytes to capture from any single body. Bodies that exceed this limit are captured up to the limit and flagged as truncated in the attachment. The default is 64 KiB (65 536 bytes).

```ts
withAllure(fetch, {
  maxBodySize: 1024 * 1024, // 1 MiB
});
```

Any value less than `1` is treated as `0`, which captures body metadata but stores an empty `value`.

For details on how captured bodies are encoded and what the attachment fields contain, see [Allure Fetch reference](/docs/fetch-reference/).

## Redaction

Allure Fetch replaces sensitive values with the sentinel string `__ALLURE_REDACTED__` before writing the attachment. The defaults are:

| Category                | Redacted by default                                                                                                                                                           |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Headers                 | `authorization`, `cookie`, `set-cookie`, and any header whose name contains `token`, `password`, `passwd`, `secret`, `api-key`/`api_key`/`apikey` (one pattern), or `session` |
| Query parameters        | Any parameter whose name contains the same patterns listed above                                                                                                              |
| Cookies                 | All cookies                                                                                                                                                                   |
| URL-encoded form fields | Any field whose name contains the same patterns listed above                                                                                                                  |

The following options let you override the defaults for each category. Each accepts an array of `RedactionMatcher` values — strings, regular expressions, or functions. Providing an array replaces the defaults for that category entirely. See [Allure Fetch reference](/docs/fetch-reference/) for the full `RedactionMatcher` and `RedactionContext` type documentation.

- `redactHeaders: RedactionMatcher[]`
- `redactQueryParams: RedactionMatcher[]`
- `redactCookies: RedactionMatcher[]`
- `redactFormFields: RedactionMatcher[]`

```ts
withAllure(fetch, {
  // Only redact headers explicitly listed, nothing else
  redactHeaders: ["authorization", "x-api-key"],
  // Allow cookies through unredacted
  redactCookies: [],
});
```

## Error options

- `includeErrorStack: boolean` (default: `false`)

When a request fails — whether due to a transport error, an abort, or a response body stream error — Allure Fetch records the error's name and message in the attachment. Set `includeErrorStack` to `true` to also capture the stack trace:

```ts
withAllure(fetch, {
  includeErrorStack: true,
});
```

- `throwAttachmentErrors: boolean` (default: `false`)

By default, if writing the attachment fails — for example, because no Allure runtime is active during the request — the error is silently ignored. Set `throwAttachmentErrors` to `true` to have such errors rethrow instead. This is useful when debugging why attachments are not appearing:

```ts
withAllure(fetch, {
  throwAttachmentErrors: true,
});
```

Info:
`throwAttachmentErrors` only takes effect when the HTTP request itself succeeds. If the request fails (due to a transport error, abort, or response body stream error) and writing the attachment also fails, the attachment error is still silently ignored so the original request error propagates cleanly.
