opentelemetry-go-contrib icon indicating copy to clipboard operation
opentelemetry-go-contrib copied to clipboard

Fix client metrics recording on round trip error

Open alimikegami opened this issue 8 months ago • 15 comments

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 avatar Apr 03 '25 13:04 alimikegami

CLA Signed

The committers listed above are authorized under a signed CLA.

  • :white_check_mark: login: alimikegami / name: Alim Ikegami (1f27a0cf765c22d0a12577911c2d87a347540de2, c0daa42862db752c20bff5fc453f06432a035f7f, a12084e205402a1cb59402a9303928d8c13da2bb, e604a8704cb5699ee22385608f4de3588da3dfe9, 8bf794adbdbe15dd16bcc722b2fed504fcbe7047, 5fae8b3b3e0fe67b31eeafc67c119b0e53365667, 2c42ebe317fe54d548bbffe6249ca0a1ed067f14, 18a32cb3a62d231bed095e9fe599c4de59ad466e, a2476c81265eb9a47f43a5974facb436a81b4fca, fcc71ee3a9c9980fcde890c6bc29855671b81e17, 08233ad0d1c5ca2672dda799bcbedc44abe07465, 7cda07a2cdf6658b48ccc6c28175803b609bd77e, 5c0dd9247ffcdb85f3fbb74f4da5d753f807cc02, 7bc8b76c87ad7bd868663b8e7f7fd92f043443f0, 435ce7161a51cfaeaa659c60fba2f4613c432627, 9a9d726757453c3f849d58a51dc68c14b4d11757, 2d10c70e23c1a4983214c631fb2f0cf21ec1c49e, 99c76ecae9b8bd9c87430b209135c942700504b8)
  • :white_check_mark: login: pellared / name: Robert Pająk (645ebc0a185c66ddb155b4dadb1d1f7bfea8f144, 09a51c226b2cdc1a05e7338268563a7f275df261, 47d12a13c0fb76510cd619304e4b4e0a4a1fda07, 0d7034da30ab196ab11782994d8de9f05ee14555, fc7196a605096d6dc8d9ed826e3cbe8062113042)

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.

dmathieu avatar Apr 07 '25 13:04 dmathieu

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.

alimikegami avatar Apr 08 '25 15:04 alimikegami

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

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%) :arrow_up:
:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Apr 08 '25 20:04 codecov[bot]

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!

alimikegami avatar Apr 09 '25 13:04 alimikegami

This should close https://github.com/open-telemetry/opentelemetry-go-contrib/issues/6940

dmathieu avatar May 15 '25 07:05 dmathieu

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

dmathieu avatar May 15 '25 07:05 dmathieu

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

I'll fix it as soon as possible!

alimikegami avatar May 19 '25 01:05 alimikegami

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?

alimikegami avatar May 20 '25 10:05 alimikegami

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).

dmathieu avatar May 20 '25 11:05 dmathieu

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 avatar May 21 '25 08:05 alimikegami

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

alimikegami avatar May 22 '25 12:05 alimikegami

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!

alimikegami avatar May 25 '25 07:05 alimikegami

We need a second approval.

dmathieu avatar May 25 '25 10:05 dmathieu

Understood, thank you!

alimikegami avatar May 25 '25 15:05 alimikegami

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

alimikegami avatar Jun 17 '25 02:06 alimikegami

The latest changes appear to break the tests.

dmathieu avatar Jun 17 '25 07:06 dmathieu

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

alimikegami avatar Jun 17 '25 14:06 alimikegami