Skip to content

Conversation

@Qard
Copy link

@Qard Qard commented Dec 9, 2025

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.

@szegedi szegedi added the semver-patch Bug or security fixes, mainly label Dec 11, 2025
@szegedi
Copy link

szegedi commented Dec 11, 2025

@Qard there's a linter error – please run npm run format

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.
@Qard Qard force-pushed the fix-zero-column-source-map-issue branch from 9832939 to 362225f Compare December 13, 2025 08:04
@szegedi szegedi merged commit d0cd62c into DataDog:main Dec 15, 2025
60 of 61 checks passed
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.
@szegedi szegedi mentioned this pull request Dec 15, 2025
@szegedi
Copy link

szegedi commented Dec 15, 2025

Hey @Qard I just heard from @nsavoire that this is very similar to #81 but he had to revert in in #106 because it somehow caused failures with webpack source maps. Sadly, he didn't check in tests back then.

@Qard Qard deleted the fix-zero-column-source-map-issue branch December 29, 2025 18:42
@Qard
Copy link
Author

Qard commented Dec 29, 2025

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. 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver-patch Bug or security fixes, mainly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants