Fix source mapping of zero-column locations#248
Merged
szegedi merged 1 commit intoDataDog:mainfrom Dec 15, 2025
Merged
Conversation
szegedi
reviewed
Dec 11, 2025
|
@Qard there's a linter error – please run |
When lineNumbers is enabled, the column is always zero. If only one occurence of a call occurs on one line then that is correctly selected. However, in cases where the same function is called multiple times in the same line it will be unable to differentiate them and would use the unmapped value. This now makes it select the first call in the line as a best-guess for the match, and in Node.js v25 will use the new column field in LineTick to select the correct column where possible.
9832939 to
362225f
Compare
szegedi
approved these changes
Dec 15, 2025
szegedi
pushed a commit
that referenced
this pull request
Dec 15, 2025
When lineNumbers is enabled, the column is always zero. If only one occurence of a call occurs on one line then that is correctly selected. However, in cases where the same function is called multiple times in the same line it will be unable to differentiate them and would use the unmapped value. This now makes it select the first call in the line as a best-guess for the match, and in Node.js v25 will use the new column field in LineTick to select the correct column where possible.
Merged
Author
|
Odd. Any idea what the issue was? Seemed to work in our environment, but I'm not sure if we actually use webpack in there anywhere. 🤔 |
szegedi
added a commit
that referenced
this pull request
Mar 13, 2026
Add tests for SourceMapper.mappingInfo with a synthetic webpack-style single-line bundle to document the known limitation introduced by #248. Background ---------- PR #81 changed originalPositionFor to always try LEAST_UPPER_BOUND first (then fall back to GREATEST_LOWER_BOUND). This was reverted in #106 because it broke webpack source maps: for real non-zero columns LEAST_UPPER_BOUND finds the *next* mapping (≥ column) rather than the one at the column, returning wrong function names. PR #248 fixed that regression by using LEAST_UPPER_BOUND only when column === 0, and GREATEST_LOWER_BOUND otherwise. This correctly handles Node.js ≥ 25 where V8's LineTick struct carries real column numbers. Residual limitation (Node.js < 25) ----------------------------------- On Node.js < 25, the LineTick struct has no column field. The C++ layer therefore always emits column=0 for every LineTick sample. With column=0, the sourcemapper uses LEAST_UPPER_BOUND, which finds the *first* mapping on the line. In a webpack bundle (all output on one line) every function maps to the same first source function in the map. This is not a regression vs. the pre-#248 state: before #248, those functions were simply unmapped (column=0 + GREATEST_LOWER_BOUND → nothing ≤ 0 → null → falls back to generated name/file). Both outcomes are imperfect; #248 trades "unmapped" for "mapped to first function", which may or may not be preferable depending on the use case. The two new tests pin both behaviours explicitly so any future change to this logic is immediately visible. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This was referenced Mar 13, 2026
Merged
szegedi
pushed a commit
that referenced
this pull request
Mar 13, 2026
When lineNumbers is enabled, the column is always zero. If only one occurence of a call occurs on one line then that is correctly selected. However, in cases where the same function is called multiple times in the same line it will be unable to differentiate them and would use the unmapped value. This now makes it select the first call in the line as a best-guess for the match, and in Node.js v25 will use the new column field in LineTick to select the correct column where possible.
szegedi
pushed a commit
that referenced
this pull request
Mar 18, 2026
When lineNumbers is enabled, the column is always zero. If only one occurence of a call occurs on one line then that is correctly selected. However, in cases where the same function is called multiple times in the same line it will be unable to differentiate them and would use the unmapped value. This now makes it select the first call in the line as a best-guess for the match, and in Node.js v25 will use the new column field in LineTick to select the correct column where possible.
szegedi
pushed a commit
that referenced
this pull request
Mar 18, 2026
When lineNumbers is enabled, the column is always zero. If only one occurence of a call occurs on one line then that is correctly selected. However, in cases where the same function is called multiple times in the same line it will be unable to differentiate them and would use the unmapped value. This now makes it select the first call in the line as a best-guess for the match, and in Node.js v25 will use the new column field in LineTick to select the correct column where possible.
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.
What does this PR do?:
Fixes an issue with source maps not being applied correctly when multiple calls to the same function occur within the same line.
In Node.js v25+ time profiles with lineNumber enabled will use the new column field in the LineTick type to correlate with the correct entry in the source map file. In prior versions it will match against the first call to a same-named function in the line for which mapping is being attempted.
This means all calls after the first in a line will be correctly attributed in Node.js v25+ and will become a best-guess of the first match in any older versions.
It also fixes a smaller bug that functions in a bundle could be mapped incorrectly if they share a same name but only different source files.
Motivation:
Currently if two calls to the same function occur within the same line they are undifferentiated. The way the logic works presently will result in the first call being mapped to the first mapping and the second call left unmapped.
How to test the change?:
Try profiling a source-mapped fibonacci function. You'll see the leaf node, where it's slightly more costly to do the second return expression call than the first, is left unmapped.