Skip to content

feat: Add source mapping support to HeapProfiler#4122

Open
amychisholm03 wants to merge 2 commits into
newrelic:mainfrom
amychisholm03:NR-4102/heap-profiler-source-mapping
Open

feat: Add source mapping support to HeapProfiler#4122
amychisholm03 wants to merge 2 commits into
newrelic:mainfrom
amychisholm03:NR-4102/heap-profiler-source-mapping

Conversation

@amychisholm03

@amychisholm03 amychisholm03 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Description

This PR adds source mapping support for our HeapProfiler. This is done by passing in our shared sourceMapper instance into pprof.heap.profile(), which is called in HeapProfiler.collect(). Coordinating unit and integrations tests have been added.

How to Test

Test Files

node --test test/integration/profiling/source-mapping.test.js
node --test test/unit/lib/profiling/index.test.js
node --test test/unit/lib/profiling/profilers/base.test.js
node --test test/unit/lib/profiling/profilers/heap.test.js

With the Example App

Example app: newrelic/newrelic-node-examples#378

With heap profiling enabled, and selecting "Objects" in the dropdown on the Profiling UI, you can see *.ts files listed instead of *.js (expected behavior with source mapping).
image

Related Issues

Closes #4102


async collect() {
const profile = this.#pprof.heap.profile()
const profile = this.#pprof.heap.profile(undefined, this.sourceMapper)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This first parameter is ignoreSamplePath which we do not need, so it is always undefined.

@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.40%. Comparing base (b1ad2da) to head (da42bee).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4122      +/-   ##
==========================================
- Coverage   97.48%   97.40%   -0.09%     
==========================================
  Files         517      517              
  Lines       62270    62275       +5     
  Branches        1        1              
==========================================
- Hits        60705    60657      -48     
- Misses       1565     1618      +53     
Flag Coverage Δ
integration-tests-cjs-22.x 73.75% <100.00%> (+0.04%) ⬆️
integration-tests-cjs-24.x 74.32% <100.00%> (+0.03%) ⬆️
integration-tests-cjs-26.x 74.32% <100.00%> (+0.03%) ⬆️
integration-tests-esm-22.x 54.36% <0.00%> (-0.01%) ⬇️
integration-tests-esm-24.x 55.52% <0.00%> (-0.01%) ⬇️
integration-tests-esm-26.x 55.52% <0.00%> (-0.01%) ⬇️
unit-tests-22.x 89.06% <100.00%> (-0.01%) ⬇️
unit-tests-24.x 89.00% <100.00%> (+<0.01%) ⬆️
unit-tests-26.x 89.00% <100.00%> (+<0.01%) ⬆️
versioned-tests-22.x 97.40% <100.00%> (-0.09%) ⬇️
versioned-tests-24.x 97.40% <100.00%> (-0.09%) ⬇️
versioned-tests-26.x 97.40% <100.00%> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@amychisholm03 amychisholm03 marked this pull request as ready for review July 10, 2026 16:52
@amychisholm03 amychisholm03 force-pushed the NR-4102/heap-profiler-source-mapping branch from 9c0b757 to da42bee Compare July 10, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Needs PR Review

Development

Successfully merging this pull request may close these issues.

Add source mapping support to HeapProfiler

2 participants