-
Notifications
You must be signed in to change notification settings - Fork 739
fix: Fix missing metric response attributes in HTTPX instrumentation #3615
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
base: main
Are you sure you want to change the base?
Conversation
…when span not recording
From manual testing this looks good and it's a simple change. Still need to figure out unit test updates tho |
Added unit tests for both old and new sem conv ✅ |
…ed-httpx-instrumentation
instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py
Outdated
Show resolved
Hide resolved
@xrmx let me know if further changes are required |
I think you missed this comment #3615 (comment) |
@xrmx Indeed I've missed, apologize. If you check previously existing tests those attributes are only asserted when test ends in 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 :
|
@@ -76,6 +87,7 @@ | |||
|
|||
|
|||
HTTP_RESPONSE_BODY = "http.response.body" | |||
SCHEMA_URL = "https://opentelemetry.io/schemas/1.21.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SCHEMA_URL = "https://opentelemetry.io/schemas/1.21.0" | |
SCHEMA_URL = Schemas.V1_21_0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Schemas does not have V1_21_0
I added this because I could not find any macro for schema 1.21.0.
Other instrumentations like requests
also have this version and they just repeat the raw string https://opentelemetry.io/schemas/1.21.0
in the asserts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added it right before writing that comment :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see your commit open-telemetry/opentelemetry-python@0e4cb44
But not very clear how to upgrade semconv package to include that change. Sorry, first time contributing in this project :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I re-create uv lock file? That does the trick, but not sure if that's the correct procedure
>>> rm uv.lock
>>> uv sync # new file is generated and semconv package includes new commit from opentelemetry-python repo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the meantime, I've pushed your suggestions. Let me know if new lock file should be commited
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah tht should have been Schemas.V1_21_0.value
or something, please run tests locally :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed and test passing locally ✅ . But could you clarify on the uv lock file question? Interested in understanding the process.
In tests I see it pulls latest version (main branch) of semantic convention repo. But trying to run locally with fresh uv sync
install does not pull that version and pulls from commit c9ad4bc2cefc64a918f0cda3cf76c64379c
since it's specified in uv lock file.
(opentelemetry-python-contrib) diosil1 % rm -rf .venv .ruff_cache
(opentelemetry-python-contrib) diosil1 % uv sync > /dev/null 2>&1
(opentelemetry-python-contrib) diosil1 % uv run python3
Python 3.12.11 (main, Jul 1 2025, 18:16:32) [Clang 20.1.4 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from opentelemetry.semconv.schemas import Schemas
>>> Schemas.V1_21_0.value
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: type object 'Schemas' has no attribute 'V1_21_0'. Did you mean: 'V1_25_0'?
Is this expected in a fresh local install?
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:Fixes #3614
Type of change
Please delete options that are not relevant.
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
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.