fix(fetch): rename globalThis.fetch wrapper from "value" to "fetch"#8406
Merged
Conversation
`globalThis.fetch`'s wrapper carries the name `value`, so every stack frame that flows through fetch surfaces as `at value` instead of `at fetch`. Renaming the wrapper makes frames blend with bundled-undici fetch. The diff also renames the inner `let fetch` slot. A named function expression `function fetch (...)` binds `fetch` to itself inside its body; without the slot rename the wrapper calls itself and stack-overflows on first invocation. Retiring the wrap is blocked on upstream undici PR #2701: bundled undici in Node 18+ exposes only `undici:request:*` channels, and the existing undici plugin already subscribes to those. Architecture review (baseline -> proposal, 1-10): 1. Drift prevention 7 -> 7 2. Coupling at module boundary 8 -> 8 3. Explicit contracts 7 -> 7 4. Testability at boundaries 5 -> 8 (spec pins the name and the recursion-safety invariant) 5. Extensibility 7 -> 7 6. Hot-path fitness 8 -> 8 Refs: nodejs/undici#2701
Contributor
Overall package sizeSelf size: 5.81 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.0.1 | 82.56 kB | 817.39 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: e1e6c3c | Docs | Datadog PR Page | Give us feedback! |
BenchmarksBenchmark execution time: 2026-05-11 00:14:06 Comparing candidate commit e1e6c3c in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 1739 metrics, 105 unstable metrics. |
pabloerhard
approved these changes
May 11, 2026
Merged
rochdev
pushed a commit
that referenced
this pull request
May 13, 2026
…8406) `globalThis.fetch`'s wrapper carries the name `value`, so every stack frame that flows through fetch surfaces as `at value` instead of `at fetch`. Renaming the wrapper makes frames blend with bundled-undici fetch. The diff also renames the inner `let fetch` slot. A named function expression `function fetch (...)` binds `fetch` to itself inside its body; without the slot rename the wrapper calls itself and stack-overflows on first invocation. Retiring the wrap is blocked on upstream undici PR #2701: bundled undici in Node 18+ exposes only `undici:request:*` channels, and the existing undici plugin already subscribes to those. Architecture review (baseline -> proposal, 1-10): 1. Drift prevention 7 -> 7 2. Coupling at module boundary 8 -> 8 3. Explicit contracts 7 -> 7 4. Testability at boundaries 5 -> 8 (spec pins the name and the recursion-safety invariant) 5. Extensibility 7 -> 7 6. Hot-path fitness 8 -> 8 Refs: nodejs/undici#2701
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
globalThis.fetch's wrapper carries the namevalue, so every stack frame that flows through fetch surfaces asat valueinstead ofat fetch. Rename the wrapper -- and the innerlet fetchslot it forwards to, since the named function expression's name shadows the outer binding and would self-recurse otherwise -- so frames blend with bundled-undici fetch.Test plan
New
packages/datadog-instrumentations/test/fetch.spec.jspinsglobalThis.fetch.name === 'fetch'after the instrumentation loads and that the wrapper forwards calls without self-recursion:nycon the file reports 87.5% line / statement coverage. The uncovered region is the pre-existing serverless-only stub path (lines 9-11); the rename on those lines is identity-preserving.Refs: nodejs/undici#2701