Allure Fetch configuration
This page describes the options that affect the behavior of the Allure Fetch integration.
All options are passed as the second argument to withAllure() or instrumentGlobalFetch():
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.
By default, each attachment is named "HTTP Exchange". To use a different static name for all attachments, pass a string:
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.
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:
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).
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.
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 for the full RedactionMatcher and RedactionContext type documentation.
redactHeaders: RedactionMatcher[]redactQueryParams: RedactionMatcher[]redactCookies: RedactionMatcher[]redactFormFields: RedactionMatcher[]
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:
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:
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.