Skip to content

Commit

Permalink
feat: strip traceparent header from cachekey (#64499)
Browse files Browse the repository at this point in the history
### What?
We strip the `traceparent` header from the cache-key.

### Why?
The traceparent header forms part of the W3C Trace Context standard,
installed to track individual HTTP requests from start to end across
multiple services. That means each individual HTTP request will have a
unique traceparent value, reflecting its unique journey across servers
and services.

If we include the traceparent header in the cache key, the uniqueness of
the traceparent means the cache key would always be different even for
requests that should yield the same response. This would cause the cache
to always miss and re-process the request.

Effectively rendering fetch-cache useless.

Co-authored-by: Jeffrey <[email protected]>
  • Loading branch information
2 people authored and ztanner committed Apr 17, 2024
1 parent cd344c8 commit df6e864
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/next/src/server/lib/incremental-cache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,14 +380,19 @@ export class IncrementalCache implements IncrementalCacheType {
}
}

const headers =
typeof (init.headers || {}).keys === 'function'
? Object.fromEntries(init.headers as Headers)
: Object.assign(init.headers || {}, {})

if ('traceparent' in headers) delete headers['traceparent']

const cacheString = JSON.stringify([
MAIN_KEY_PREFIX,
this.fetchCacheKeyPrefix || '',
url,
init.method,
typeof (init.headers || {}).keys === 'function'
? Object.fromEntries(init.headers as Headers)
: init.headers,
headers,
init.mode,
init.redirect,
init.credentials,
Expand Down

0 comments on commit df6e864

Please sign in to comment.