Skip to content

feat(instrumentation-runtime-node): add v8js.memory.heap.max metric from v8.getHeapStatistics()#3405

Open
Hronom wants to merge 1 commit intoopen-telemetry:mainfrom
Hronom:feat/add-v8js-heap-max-metric
Open

feat(instrumentation-runtime-node): add v8js.memory.heap.max metric from v8.getHeapStatistics()#3405
Hronom wants to merge 1 commit intoopen-telemetry:mainfrom
Hronom:feat/add-v8js-heap-max-metric

Conversation

@Hronom
Copy link
Copy Markdown

@Hronom Hronom commented Feb 26, 2026

What

Adds a new v8js.memory.heap.max metric to @opentelemetry/instrumentation-runtime-node that exposes the absolute maximum heap size (heap_size_limit) from v8.getHeapStatistics().

Why

The existing V8 heap metrics (v8js.memory.heap.limit, v8js.memory.heap.used, etc.) are all sourced from v8.getHeapSpaceStatistics(), which provides per-space data. However, the absolute heap ceiling (heap_size_limit) -- controlled by --max-old-space-size or V8 defaults -- is only available from v8.getHeapStatistics() and is not currently exposed.

This value is critical for:

  • Calculating true heap utilization (heap_used / heap_size_limit)
  • Alerting on proximity to OOM conditions
  • Understanding the configured memory ceiling vs. actual usage

Note: v8js.memory.heap.limit (which maps to space_size from getHeapSpaceStatistics()) represents pre-allocated space size per heap space, not the hard OOM ceiling.

Changes

  1. src/semconv.ts -- Added METRIC_V8JS_MEMORY_HEAP_MAX constant
  2. src/metrics/heapSizeLimitCollector.ts -- New collector using v8.getHeapStatistics() and observing heap_size_limit as a gauge (unit: By)
  3. src/instrumentation.ts -- Registered HeapSizeLimitCollector alongside existing collectors
  4. test/heap_size_limit.test.ts -- Tests verifying metric is emitted as gauge with positive value and no per-space attribute

Semantic Conventions

This metric is proposed in open-telemetry/semantic-conventions#3476. This PR is a draft pending the semconv discussion.

Checklist

  • New collector follows existing patterns (BaseCollector, addBatchObservableCallback)
  • Tests follow existing test patterns (TestMetricReader, MeterProvider)
  • No breaking changes
  • No new dependencies

Pull Request opened by Augment Code with guidance from the PR author

@maryliag
Copy link
Copy Markdown
Contributor

just a drive by feedback (since this is marked as draft): before you make it ready for review, can you update the semantic convention for it? similar to open-telemetry/semantic-conventions#3445

Hronom added a commit to Hronom/semantic-conventions that referenced this pull request Feb 26, 2026
Add v8js.memory.heap.max gauge metric representing the absolute maximum
heap size (heap_size_limit) from v8.getHeapStatistics(). This value is
the hard ceiling controlled by --max-old-space-size or V8 defaults.

Related issue: open-telemetry#3476
Related instrumentation PR: open-telemetry/opentelemetry-js-contrib#3405
@Hronom
Copy link
Copy Markdown
Author

Hronom commented Feb 26, 2026

Semantic conventions PR created: open-telemetry/semantic-conventions#3481

This adds the v8js.memory.heap.max metric definition to the V8 JS engine runtime semantic conventions, following the same pattern as open-telemetry/semantic-conventions#3445.

@Hronom Hronom marked this pull request as ready for review February 26, 2026 22:43
@Hronom Hronom requested a review from a team as a code owner February 26, 2026 22:43
@Hronom
Copy link
Copy Markdown
Author

Hronom commented Feb 27, 2026

Fixed lint

New collector that calls v8.getHeapStatistics() and emits
v8js.memory.heap.max metric representing the absolute maximum
heap size (heap_size_limit).

Related: open-telemetry/semantic-conventions#3476
@Hronom Hronom force-pushed the feat/add-v8js-heap-max-metric branch from 99691cb to 7073049 Compare March 4, 2026 03:39
@Hronom Hronom requested a review from maryliag March 4, 2026 11:38
@Hronom
Copy link
Copy Markdown
Author

Hronom commented Mar 6, 2026

Fixed conflict

@Hronom
Copy link
Copy Markdown
Author

Hronom commented Mar 19, 2026

Please can someone review?

@raphael-theriault-swi
Copy link
Copy Markdown
Member

We're waiting on the upstream changes to the semantic conventions to be accepted, per this comment.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants