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

fix(instr-undici): wrong user agent reported if no user agent were set #2282

Merged
merged 2 commits into from
Jun 19, 2024

Conversation

YoannMa
Copy link
Contributor

@YoannMa YoannMa commented Jun 14, 2024

Which problem is this PR solving?

  • undici instrumentation wrongly reports the first header's name as the user-agent if no user-agent header was set (default behavior of undici from what I can tell)

Short description of the changes

request.headers.findIndex(h => h.toLowerCase() === 'user-agent') returns -1 if no user-agent header was present.

I added a check to avoid reporting headers[0] as user-agent

Added a test, not sure if it's useful? Especially as it might break in the future if undici decide to add a default user-agent

@YoannMa YoannMa requested a review from a team June 14, 2024 16:50
Copy link

linux-foundation-easycla bot commented Jun 14, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: YoannMa / name: Yoann MALLEMANCHE (0004ea7)
  • ✅ login: pichlermarc / name: Marc Pichler (79fdc41)

Copy link
Contributor

@david-luna david-luna left a comment

Choose a reason for hiding this comment

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

@YoannMa

Having no user agent header is a scenario that is likely to happen. Thanks for contributing to OpenTelemetry with this bugfix :)

Copy link

codecov bot commented Jun 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.29%. Comparing base (dfb2dff) to head (79fdc41).
Report is 166 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2282      +/-   ##
==========================================
- Coverage   90.97%   90.29%   -0.68%     
==========================================
  Files         146      147       +1     
  Lines        7492     7247     -245     
  Branches     1502     1505       +3     
==========================================
- Hits         6816     6544     -272     
- Misses        676      703      +27     
Files Coverage Δ
plugins/node/instrumentation-undici/src/undici.ts 96.29% <100.00%> (ø)

... and 53 files with indirect coverage changes

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