Skip to content

Commit a85fa42

Browse files
jorgemoyaclaude
andauthored
feat(core): add X-Correlation-ID header to all GraphQL requests (bigcommerce#2976)
* feat(core): add X-Correlation-ID header to all GraphQL requests Each page render gets a stable UUID (via React.cache) that persists across all fetches within the same render, enabling easier request tracing in server logs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(core): wrap correlation-id import in try/catch for config resolution The dynamic import of correlation-id.ts fails during next.config.ts resolution because React.cache is unavailable in that context. Wrap in try/catch to match the existing pattern for next-intl/server. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * chore: change correlation-id changeset to patch Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a8dd99e commit a85fa42

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@bigcommerce/catalyst-core": patch
3+
---
4+
5+
Add X-Correlation-ID header to all GraphQL requests. Each page render gets a stable UUID that persists across all fetches within the same render, enabling easier request tracing in server logs.

core/client/correlation-id.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { cache } from 'react';
2+
3+
export const getCorrelationId = cache(() => crypto.randomUUID());

core/client/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ export const client = createClient({
5252
const requestHeaders: Record<string, string> = {};
5353
const locale = await getLocale();
5454

55+
try {
56+
const { getCorrelationId } = await import('./correlation-id');
57+
58+
requestHeaders['X-Correlation-ID'] = getCorrelationId();
59+
} catch {
60+
// correlation-id imports React.cache which is unavailable during next.config.ts resolution
61+
}
62+
5563
if (fetchOptions?.cache && ['no-store', 'no-cache'].includes(fetchOptions.cache)) {
5664
const { headers } = await import('next/headers');
5765
const ipAddress = (await headers()).get('X-Forwarded-For');

0 commit comments

Comments
 (0)