Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(perf_hooks): add node instrumentation perf_hooks #1902

Merged
merged 19 commits into from
Feb 23, 2024
Merged

feat(perf_hooks): add node instrumentation perf_hooks #1902

merged 19 commits into from
Feb 23, 2024

Conversation

d4nyll
Copy link
Contributor

@d4nyll d4nyll commented Jan 16, 2024

Which problem is this PR solving?

#1106 - currently there is no Otel way to expose metrics provided by the Node.js runtime

(...continuation from #1272 and #1689)

Description of changes

This PR adds a @opentelemetry/instrumentation-perf-hooks package that exposes the utilization measurement from Node.js Performance measurement APIs' performance.eventLoopUtilization method.

The exposed metric will look something like this:

# HELP nodejs_performance_event_loop_utilization Event loop utilization
# UNIT nodejs_performance_event_loop_utilization 1
# TYPE nodejs_performance_event_loop_utilization gauge
nodejs_performance_event_loop_utilization 0.010140079547955264

Notes / Questions

  • I've named this package @opentelemetry/instrumentation-perf-hooks as this initial version only exposes one metric. Happy to use @opentelemetry/instrumentation-runtime but that implies a bigger scope than what this PR does.
  • The exposed metric is called nodejs.performance.event_loop.utilization, but perhaps nodejs.event_loop.utilization is sufficient?

@d4nyll d4nyll requested a review from a team January 16, 2024 12:10
Copy link

linux-foundation-easycla bot commented Jan 16, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

// the Meter (result of @opentelemetry/api's getMeter) is available as this.meter within this method
override _updateMetricInstruments() {
this.meter
.createObservableGauge('nodejs.performance.event_loop.utilization', {
Copy link
Member

Choose a reason for hiding this comment

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

Referring to the question from the PR body, I think omitting performance should be just fine 🙂

Suggested change
.createObservableGauge('nodejs.performance.event_loop.utilization', {
.createObservableGauge('nodejs.event_loop.utilization', {

@d4nyll d4nyll requested a review from pichlermarc January 29, 2024 10:05
Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

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

Thanks for working on this 🙂

Copy link

codecov bot commented Jan 29, 2024

Codecov Report

Merging #1902 (15028c0) into main (a7861f6) will increase coverage by 0.04%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1902      +/-   ##
==========================================
+ Coverage   91.00%   91.04%   +0.04%     
==========================================
  Files         146      147       +1     
  Lines        7493     7530      +37     
  Branches     1503     1507       +4     
==========================================
+ Hits         6819     6856      +37     
  Misses        674      674              
Files Coverage Δ
.../instrumentation-perf-hooks/src/instrumentation.ts 100.00% <100.00%> (ø)

@d4nyll
Copy link
Contributor Author

d4nyll commented Jan 29, 2024

Updated to fix the failed release-please-config and peer-api-checks workflows

@d4nyll d4nyll requested a review from pichlermarc January 29, 2024 10:52
@d4nyll
Copy link
Contributor Author

d4nyll commented Jan 30, 2024

I believe the unit-test (18.18.2) failed due to the test being flakey (c0ef756 should have fixed it)

However, I am struggling to see why unit-test (14) hangs and I don't see any test output. (would 928f8ac have fixed it? It's currently passing on my machine using Node.js v14.21.3)

@pichlermarc can we run the tests again?

@d4nyll
Copy link
Contributor Author

d4nyll commented Feb 14, 2024

@pichlermarc Hey, just want to double check if there are still changes that needs addressing, or we are just waiting for this to be included in the next release. Should I keep merging/resolving conflicts (which will cause the tests to be rerun) or just leave it be? Thanks

@pichlermarc
Copy link
Member

@pichlermarc Hey, just want to double check if there are still changes that needs addressing, or we are just waiting for this to be included in the next release. Should I keep merging/resolving conflicts (which will cause the tests to be rerun) or just leave it be? Thanks

Sorry for the delay. I should've merged it long ago. Running tests again and then this should be good to merge.

@pichlermarc pichlermarc merged commit 882fb4b into open-telemetry:main Feb 23, 2024
15 checks passed
@dyladan dyladan mentioned this pull request Feb 23, 2024
@d4nyll d4nyll deleted the feat/node/perf_hooks branch February 23, 2024 13:44
@trentm
Copy link
Contributor

trentm commented Feb 23, 2024

(Sorry this Q comes after this is reviewed and merged.)

Is this something that needs to be implemented as an instrumentation? Could it not be something like host-metrics (https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/packages/opentelemetry-host-metrics/README.md#usage) where one separately creates and starts it after a MeterProvider has been registered (via using NodeSDK or whatever). IIUC, this isn't actually instrumenting perf_hooks, but just using it.

@d4nyll
Copy link
Contributor Author

d4nyll commented Feb 23, 2024

IIUC, this isn't actually instrumenting perf_hooks, but just using it.

Yes, this is only using perf_hooks but not instrumenting the perf_hooks Node.js API.

Is this something that needs to be implemented as an instrumentation?

The purpose of the package is to export metrics exposed by the Node.js runtime. I see similar packages in other languages (e.g. Go) exposing the language runtime internals implemented as instrumentation packages.

If it is a matter of naming, I would be happy for it to be renamed to @opentelemetry/instrumentation-runtime.

If it is a matter of whether it should be a non-instrumentation package, I would need more guidance from the maintainers as to the distinction between an 'instrumentation' package and other types of packages. From my perspective, yes, it could work as a package similar to @opentelemetry/host-metrics

@trentm
Copy link
Contributor

trentm commented Feb 23, 2024

@d4nyll Thanks. I moved my Q to a new issue (#1956) so this doesn't get lost on a merged PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants