Skip to content

Conversation

diogosilva30
Copy link
Contributor

@diogosilva30 diogosilva30 commented Jul 4, 2025

Description

This PR fixes an issue where HTTP response attributes (status code, http version) are only recorded in metrics if span are recording. I believe this should not be the case because metrics should not be coupled with tracing. Based myself of requests instrumentation here, where it even states:

Also the decision to include status code on a histogram should
not be dependent on tracing decisions.

Fixes #3614

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Added unit tests for both old and new sem conv
  • Ran script provided in minimum reproducible code and saw after this change behaviour is as expected

Does This PR Require a Core Repo Change?

  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jul 4, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@diogosilva30 diogosilva30 requested a review from a team as a code owner July 4, 2025 17:18
@diogosilva30
Copy link
Contributor Author

From manual testing this looks good and it's a simple change. Still need to figure out unit test updates tho

@diogosilva30 diogosilva30 marked this pull request as draft July 5, 2025 13:13
@diogosilva30 diogosilva30 changed the title (WIP) fix: Fix missing metric response attributes in HTTPX instrumentation fix: Fix missing metric response attributes in HTTPX instrumentation Jul 5, 2025
@diogosilva30 diogosilva30 marked this pull request as ready for review July 5, 2025 14:35
@diogosilva30
Copy link
Contributor Author

Added unit tests for both old and new sem conv ✅
Should be ready for review!

@xrmx xrmx moved this to Ready for review in @xrmx's Python PR digest Jul 7, 2025
@diogosilva30
Copy link
Contributor Author

@xrmx let me know if further changes are required

@xrmx
Copy link
Contributor

xrmx commented Jul 9, 2025

@xrmx let me know if further changes are required

I think you missed this comment #3615 (comment)

@diogosilva30
Copy link
Contributor Author

diogosilva30 commented Jul 9, 2025

@xrmx Indeed I've missed, apologize.

If you check previously existing tests those attributes are only asserted when test ends in both_semconv which means its running with opt-in as http/dup. For "default" behaviour (old semantic) only HTTP_STATUS_CODE, HTTP_METHOD and HTTP_SCHEME are added. To have HTTP_FLAVOR, HTTP_HOST , NET_PEER_NAME , NET_PEER_PORT it needs to run in http/dup (both sem conv).

We can see this explanation in original implementation by @emdneto : #2631

Don't know if it makes sense, but it's the current behaviour. I've added a new test case so it covers all 3 scenarios according to logic previously implemented by @emdneto :

  • old sem conv: test_metrics_have_response_attributes_with_disabled_tracing
  • both sem conv: test_metrics_have_response_attributes_with_disabled_tracing_both_semconv
  • new sem conv: test_metrics_have_response_attributes_with_disabled_tracing_new_semconv

@diogosilva30 diogosilva30 requested a review from xrmx July 17, 2025 07:45
@diogosilva30
Copy link
Contributor Author

@xrmx any chance to review this again?

@diogosilva30
Copy link
Contributor Author

@xrmx @emdneto any update on this? Happy to make further changes if needed

@diogosilva30
Copy link
Contributor Author

diogosilva30 commented Aug 6, 2025

Thanks for review @emdneto @xrmx ! Everything good for merge?

@xrmx xrmx enabled auto-merge (squash) September 9, 2025 13:20
@xrmx xrmx merged commit 5caf8c2 into open-telemetry:main Sep 9, 2025
632 checks passed
@github-project-automation github-project-automation bot moved this from Ready for review to Done in @xrmx's Python PR digest Sep 9, 2025
chloe-zh97 pushed a commit to chloe-zh97/opentelemetry-python-contrib that referenced this pull request Sep 10, 2025
…pen-telemetry#3615)

* fix: Fix missing metric response attributes in HTTPX instrumentation when span not recording

* chore: add changelog

* feat: Add unit tests for old and new semconv

* fix: remove deprecated span attributes

* fix: add tests for both sem conv

* fix: add suggestions

* fix: fix unit tests

* Update CHANGELOG.md

---------

Co-authored-by: Emídio Neto <[email protected]>
Co-authored-by: Riccardo Magliocchetti <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Missing HTTP response attributes in HTTPX instrumentation

3 participants