Skip to content

Fix client metrics recording on round trip error #7146

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

Merged

Conversation

alimikegami
Copy link
Contributor

This pull request fixes client metrics recording on round trip error

Related issues: #6940

Does this approach correctly address the issue with round trip errors?
Should I add specific tests to verify metric recording (http.client.duration) during round trip errors?

@alimikegami alimikegami requested review from dmathieu and a team as code owners April 3, 2025 13:12
Copy link

linux-foundation-easycla bot commented Apr 3, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@dmathieu
Copy link
Member

dmathieu commented Apr 7, 2025

Duplicating code like isn't really maintainable long-term. We should be able to have the metrics recorded, with no code duplication. Possibly, by exporting the metric into its own method.

Also, this needs to be tested.

@alimikegami
Copy link
Contributor Author

Thank you for the review @dmathieu

What do you think of my latest commit? I’ve added a method to record metrics and removed most of the unnecessary code duplication. Thank you.

Copy link

codecov bot commented Apr 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.5%. Comparing base (1d195a9) to head (47d12a1).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #7146   +/-   ##
=====================================
  Coverage   81.5%   81.5%           
=====================================
  Files        198     198           
  Lines      17952   17961    +9     
=====================================
+ Hits       14634   14643    +9     
  Misses      2918    2918           
  Partials     400     400           
Files with missing lines Coverage Δ
instrumentation/net/http/otelhttp/transport.go 95.1% <100.0%> (+0.2%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@dmathieu dmathieu left a comment

Choose a reason for hiding this comment

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

Could you add a test?

@alimikegami
Copy link
Contributor Author

Thank you for the review @dmathieu
I've added the test and refactored the metric recording to use defer, removing the remaining code duplication.

Please check my latest commit. Thank you!

@dmathieu
Copy link
Member

This should close #6940

@dmathieu
Copy link
Member

@alimikegami the CI has been failing since your last commit. Could you fix it?

@alimikegami
Copy link
Contributor Author

@alimikegami the CI has been failing since your last commit. Could you fix it?

I'll fix it as soon as possible!

@alimikegami
Copy link
Contributor Author

image

Hi @dmathieu,

I've run the tests on my local machine, but I’m not seeing the http.client.request.body.size metric that appears in the CI test results. Instead, I'm seeing http.client.request.size. The same also applies to the duration metric.

Here's the test output from my local environment:


image


Do you know what might be causing the difference in metric names between the CI environment and my local machine?

@dmathieu
Copy link
Member

This error would hint on the semconv migration. Is your commit based on a rather old commit in this repo?
The proper metric is the one this CI sees (see https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-metrics.md).

@alimikegami
Copy link
Contributor Author

Thank you for the explanation, @dmathieu. It cleared up my confusion. Please kindly review my test and implementation! I have fixed the failing tests. Thank you!

@alimikegami
Copy link
Contributor Author

alimikegami commented May 22, 2025

I've committed the CHANGELOG update and removed the recordMetrics method. Please kindly review the changes @dmathieu. Thank you!

@alimikegami
Copy link
Contributor Author

Hi @dmathieu, I’ve moved the entry to the unreleased section. Would it be possible to get this merged, or is there anything I need to do on my end? Thank you!

@dmathieu
Copy link
Member

We need a second approval.

@alimikegami
Copy link
Contributor Author

Understood, thank you!

@pellared pellared added this to the v1.37.0 milestone Jun 12, 2025
@alimikegami
Copy link
Contributor Author

I've refactored the code according to your suggestions, @pellared. Please have a look at my latest commit. Thank you!

pellared
pellared previously approved these changes Jun 17, 2025
Copy link
Member

@pellared pellared left a comment

Choose a reason for hiding this comment

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

@dmathieu, can you take another look please?

@dmathieu
Copy link
Member

The latest changes appear to break the tests.

@pellared pellared dismissed their stale review June 17, 2025 13:06

I am not sure why but some tests are missing http.response.status_code attribute.

@alimikegami
Copy link
Contributor Author

I've fixed the failing tests, please kindly check my latest commit. Thank you!
@dmathieu @pellared

@alimikegami alimikegami requested a review from pellared June 17, 2025 14:19
@pellared pellared merged commit d71de1a into open-telemetry:main Jun 17, 2025
27 checks passed
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