Skip to content

feat(instr-runtime-node): add configurable gcDurationBuckets option#3328

Open
lukeramsden wants to merge 2 commits intoopen-telemetry:mainfrom
lukeramsden:claude/configurable-bucket-boundaries-yBSUx
Open

feat(instr-runtime-node): add configurable gcDurationBuckets option#3328
lukeramsden wants to merge 2 commits intoopen-telemetry:mainfrom
lukeramsden:claude/configurable-bucket-boundaries-yBSUx

Conversation

@lukeramsden
Copy link

Which problem is this PR solving?

Monitoring precision being configurable but not the bucket boundary for GC duration seems like an oversight in this package. I'd like to add 2s and 5s boundaries in my application.

Short description of the changes

Allow users to customize the histogram bucket boundaries for the v8js.gc.duration metric via the gcDurationBuckets configuration option, similar to how monitoringPrecision is configurable.

@lukeramsden lukeramsden requested a review from a team as a code owner December 29, 2025 18:26
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Dec 29, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

Allow users to customize the histogram bucket boundaries for the
v8js.gc.duration metric via the gcDurationBuckets configuration option,
similar to how monitoringPrecision is configurable.
@lukeramsden lukeramsden force-pushed the claude/configurable-bucket-boundaries-yBSUx branch from 3e6cee2 to c627f76 Compare December 29, 2025 18:33
Copy link
Contributor

@maryliag maryliag left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution.
You will need to add a changelog and tests to this PR before we can merge it.

@trentm
Copy link
Contributor

trentm commented Jan 13, 2026

You will need to add a changelog and tests to this PR before we can merge it.

@maryliag This gets me and I have to check again almost everytime. The core repo requires PRs to explicitly include a CHANGELOG.md entry. The contrib repo does not, because the release process automatically adds changelog entries based on the commit titles.

@lukeramsden lukeramsden force-pushed the claude/configurable-bucket-boundaries-yBSUx branch from df45353 to 4490d1d Compare January 13, 2026 21:22
@maryliag
Copy link
Contributor

The contrib repo does not

this is what I get for having a bunch of tabs open to review and not checking the repo 🤦
Now just wait for tests to pass then 😄

@lukeramsden lukeramsden force-pushed the claude/configurable-bucket-boundaries-yBSUx branch from 4490d1d to 696905d Compare January 13, 2026 21:31
@lukeramsden
Copy link
Author

I have pushed some tests for the GC collection, which pass locally. Will leave the changelog alone then 😄

Add tests verifying that the GC duration histogram is created correctly
with both default and custom bucket boundaries.
@lukeramsden lukeramsden force-pushed the claude/configurable-bucket-boundaries-yBSUx branch from 696905d to b0c20ee Compare January 14, 2026 09:38
@lukeramsden
Copy link
Author

I've pushed a fix for prettier lint but the test failures don't make sense to me - no test files found?

"compile:with-dependencies": "nx run-many -t compile -p @opentelemetry/instrumentation-runtime-node",
"prepublishOnly": "npm run compile",
"test": "nyc --no-clean mocha 'test/**/*.test.ts'",
"test": "nyc --no-clean mocha --expose-gc 'test/**/*.test.ts'",
Copy link
Contributor

Choose a reason for hiding this comment

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

the test failures might be related to this change, what this parameter does? does it need some extra info to find specific files?

Copy link
Author

Choose a reason for hiding this comment

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

This exposes the ability to trigger GC which is what the test uses.

Copy link
Author

Choose a reason for hiding this comment

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

I don't see how it would be possible to test this instrumentation collector without this flag which is I assume why there were no tests in the first place

I believe that v18 and v20 of Node that your CI tests with do not have this flag and therefore I do not know how one would test this collector on those versions. Up to you how to proceed, we could:

  1. Not test this collector (which is the current state of the codebase and my change does not make particularly any worse) and therefore delete my tests
  2. Disable these tests in certain CI matrix formations where we use older Node.js versions
  3. Find an alternative way to do this on those versions, however I do not know of a way to do that

Copy link
Contributor

@david-luna david-luna Jan 20, 2026

Choose a reason for hiding this comment

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

There is a script that can be used to skip tests given a certain major version (only major). A possible solution is to:

  • have a test script without the flag (works for all versions)
  • have a test script with the flag and skip for nodejs versions lower than 22
  • refactor the new tests to skip if the global.gc() method is not avaiable

Example of how the scripts would look like.

    "test": "npm run test:nogc && npm run test:gc",
    "test:nogc": "nyc --no-clean mocha 'test/**/*.test.ts'",
    "test:gc": "SKIP_TEST_IF_NODE_OLDER_THAN=22 nyc --no-clean mocha --require '../../scripts/skip-test-if.js' --expose-gc 'test/**/*.ts'",

WDYT?

@pichlermarc
Copy link
Member

Silly question: is this not what the View concept is for (defining a custom aggregation based on meter+metric name?)
https://opentelemetry.io/docs/languages/js/instrumentation/#configure-metric-views

@lukeramsden
Copy link
Author

lukeramsden commented Jan 16, 2026

Silly question: is this not what the View concept is for (defining a custom aggregation based on meter+metric name?) https://opentelemetry.io/docs/languages/js/instrumentation/#configure-metric-views

Does that work if the view buckets are more granular or have larger ranges than the underlying histogram? I've never heard of views and no idea how they work internally (and docs aren't clear)

@pichlermarc
Copy link
Member

Silly question: is this not what the View concept is for (defining a custom aggregation based on meter+metric name?) https://opentelemetry.io/docs/languages/js/instrumentation/#configure-metric-views

Does that work if the view buckets are more granular or have larger ranges than the underlying histogram? I've never heard of views and no idea how they work internally (and docs aren't clear)

Yes. The underlying mechanism the same for View and advice - when you use Histogram#record() it passes the data to the Aggregation that was created based on either the default, the advice or the View. In any case, you'll not loose data-granularity and there's no estimation going on.

@david-luna
Copy link
Contributor

@lukeramsden did you have time to review the latest comments?

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.

6 participants