Skip to content

refactor(nitro): dedupe the request-id gate and tail-sampling emit in the v3 plugin - #795

Merged
HugoRCD merged 1 commit into
mainfrom
refactor/nitro-v3-dedupe-emit
Oct 9, 2026
Merged

HugoRCD merged 1 commit into
mainfrom
refactor/nitro-v3-dedupe-emit

Conversation

@evlogai

@evlogai evlogai Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Two sequences in packages/evlog/src/nitro-v3/plugin.ts were duplicated with a shared single owner available in the same file:

  • The Cloudflare cf-ray request-id gate and the requestId: override || ctx.requestId || crypto.randomUUID() expression ran in both the enabled and the globally-disabled request hooks. Extracted as resolveRequestId(event, ctx).
  • The tail-sampling emit sequence (_evlogStartTime duration, TailSamplingContext, evlog:emit:keep hook, plugin-runner keep, log.emit) ran verbatim in the response and error hooks. Extracted as emitWithTailSampling(hooks, log, event, status, ctx), mirroring the existing v2 owner emitTailSampling in packages/evlog/src/nitro/plugin.ts and matching callDrainHook's parameter shape (hence the existing max-params disable pattern).

Both call sites are token-identical copies of the extracted bodies, so behavior is preserved. The nitro-v3 integration suite is the matching test: it pins the evlog:emit:keep tail-sampling path (test/nitro-v3/nitro-v3.test.ts) and the cf-ray request-id (requestId assertions in the same file).

Diff shape

The two emit sequences deleted verbatim (response hook shown; the error hook copy is identical):

-      const startTime = ctx._evlogStartTime as number | undefined
-      const durationMs = startTime ? elapsedMs(startTime) : undefined
-      const { pathname } = parseURL(event.req.url)
-      const tailCtx: TailSamplingContext = { ... }
-      await hooks.callHook('evlog:emit:keep', tailCtx)
-      const runner = getGlobalPluginRunner()
-      if (runner.hasKeep) await runner.runKeep(tailCtx)
-      const emittedEvent = log.emit({ _forceKeep: tailCtx.shouldKeep, _durationMs: durationMs })
+      const emittedEvent = await emitWithTailSampling(hooks, log, event, responseStatus, ctx)

Net: 41 insertions, 51 deletions in one file. Found by the repo-health sweep at revision 54dcc504; confirmed by the workflow's verifier and reproduced in the sandbox.

Checks

  • pnpm --filter evlog exec vitest run test/nitro-v3/: 5 files, 29 tests passed with the edit.
  • pnpm run lint, pnpm run typecheck, pnpm run test: all exit 0 with the edit.
  • No changeset: internal dedupe with no observable consumer change (per AGENTS.md).
ELI5

Two pieces of request-logging logic existed in two copies each inside the same file. This puts each piece in one function that both places now call, with no change in behavior. The automated tests that watch those exact log paths still pass.

… the v3 plugin

The cf-ray request-id gate ran twice in plugin.ts and the tail-sampling
emit sequence ran verbatim in both the response and error hooks. Extract
resolveRequestId() and emitWithTailSampling() so each rule has one owner;
behavior is unchanged and the pinned integration tests still pass.
@vercel

vercel Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
evi Ready Ready Preview Oct 9, 2026 8:20am UTC
evlog-telemetry Ready Ready Preview Oct 9, 2026 8:20am UTC
3 Skipped Deployments
Project Deployment Actions Updated
evlog-docs Skipped Skipped v0 Oct 9, 2026 8:20am UTC
evlog-render-lab Skipped Skipped Oct 9, 2026 8:20am UTC
just-use-evlog Skipped Skipped Oct 9, 2026 8:20am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 59bc949d-6bbc-4def-86fa-06c5b629f964

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions
github-actions Bot requested a review from HugoRCD October 9, 2026 08:18
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Thank you for following the naming conventions! 🙏

@pkg-pr-new

pkg-pr-new Bot commented Oct 9, 2026

Copy link
Copy Markdown
@evlog/cli

npm i https://pkg.pr.new/@evlog/cli@795

evlog

npm i https://pkg.pr.new/evlog@795

@evlog/nuxthub

npm i https://pkg.pr.new/@evlog/nuxthub@795

@evlog/signals

npm i https://pkg.pr.new/@evlog/signals@795

@evlog/telemetry

npm i https://pkg.pr.new/@evlog/telemetry@795

commit: c2d6cd4

@HugoRCD
HugoRCD merged commit 1b6e1b9 into main Oct 9, 2026
20 checks passed
@HugoRCD
HugoRCD deleted the refactor/nitro-v3-dedupe-emit branch October 9, 2026 20:21

This branch was successfully deployed

2 active and 3 inactive deployments
Preview – evlog-telemetry — c2d6cd43 Deployed Oct 9, 2026 by vercel[bot]
Preview – evi — c2d6cd43 Deployed Oct 9, 2026 by vercel[bot]
Preview – evlog-render-lab — c2d6cd43 Deployed Oct 9, 2026 by vercel[bot]
Preview – evlog-docs — c2d6cd43 Deployed Oct 9, 2026 by vercel[bot]
Preview – just-use-evlog — c2d6cd43 Deployed Oct 9, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant