Skip to content

Commit 5795151

Browse files
feat: requestId override in a worker environment (#43)
Co-authored-by: Hugo <hugo.richard@vercel.com>
1 parent 3125fcf commit 5795151

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

packages/evlog/src/nitro/plugin.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,17 @@ export default defineNitroPlugin((nitroApp) => {
147147

148148
// Store start time for duration calculation in tail sampling
149149
e.context._evlogStartTime = Date.now()
150+
151+
let requestIdOverride: string | undefined = undefined
152+
if (globalThis.navigator?.userAgent === 'Cloudflare-Workers') {
153+
const cfRay = getSafeHeaders(event)?.['cf-ray']
154+
if (cfRay) requestIdOverride = cfRay
155+
}
150156

151157
const log = createRequestLogger({
152158
method: e.method,
153159
path: e.path,
154-
requestId: e.context.requestId || crypto.randomUUID(),
160+
requestId: requestIdOverride || e.context.requestId || crypto.randomUUID(),
155161
})
156162

157163
// Apply route-based service configuration if a matching route is found

0 commit comments

Comments
 (0)