Skip to content

refactor(instrumentation-http): refactor getIncomingRequestAttributes() to reduce work#6207

Merged
maryliag merged 4 commits intoopen-telemetry:mainfrom
cjihrig:getincoming-req-attr
Dec 18, 2025
Merged

refactor(instrumentation-http): refactor getIncomingRequestAttributes() to reduce work#6207
maryliag merged 4 commits intoopen-telemetry:mainfrom
cjihrig:getincoming-req-attr

Conversation

@cjihrig
Copy link
Copy Markdown
Contributor

@cjihrig cjihrig commented Dec 10, 2025

Which problem is this PR solving?

getIncomingRequestAttributes() is on the stack 12% of the time in a flame graph I created for an HTTP server. Since this function is somewhat hot, it makes sense to optimize it a bit. More specifically, this function is computing two sets of attributes even though often only a single set of attributes is needed.

Fixes # N/A

Short description of the changes

This commit updates getIncomingRequestAttributes() to only compute the necessary attributes. On my local macOS machine running Node 25, this reduced the amount of time it was on the stack from 12% to 7%. The number of requests served also went from 372k to 390k (for more context, this was at 1350k requests for the same Node server without any OTel).

Type of change

None of these - performance refactor.

How Has This Been Tested?

  • Test suite

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated
Screenshot 2025-12-10 at 12 13 37 AM copy

@cjihrig cjihrig requested a review from a team as a code owner December 10, 2025 13:06
Comment thread experimental/CHANGELOG.md Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 10, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.40%. Comparing base (f9c995d) to head (43116f2).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6207   +/-   ##
=======================================
  Coverage   95.40%   95.40%           
=======================================
  Files         317      317           
  Lines        9514     9514           
  Branches     2192     2192           
=======================================
  Hits         9077     9077           
  Misses        437      437           
🚀 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.

@cjihrig
Copy link
Copy Markdown
Contributor Author

cjihrig commented Dec 15, 2025

Maybe ping @maryliag who had originally asked me to look into potential perf improvements?

Copy link
Copy Markdown
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.

Nice improvement! Thank you for working on this!

@maryliag maryliag added this pull request to the merge queue Dec 18, 2025
Merged via the queue into open-telemetry:main with commit 0433df9 Dec 18, 2025
27 checks passed
@otelbot
Copy link
Copy Markdown
Contributor

otelbot Bot commented Dec 18, 2025

Thank you for your contribution @cjihrig! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey.

@cjihrig cjihrig deleted the getincoming-req-attr branch December 18, 2025 21:28
@otelbot-js otelbot-js Bot mentioned this pull request Jan 7, 2026
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.

2 participants