Add metric instrumentation for urllib#1553
Conversation
| key=lambda m: m.name, | ||
| ) | ||
|
|
||
| def assert_metric_expected( |
There was a problem hiding this comment.
I used utils function for metrics assert
they can be deleted after open-telemetry/opentelemetry-python#3092 merged
There was a problem hiding this comment.
I have some reservations about the PR on the main repo. I will leave a review there about it.
2e0961f to
a045675
Compare
a045675 to
749994b
Compare
|
|
||
| _record_histograms( | ||
| histograms, labels, request, result, elapsed_time | ||
| ) |
There was a problem hiding this comment.
Will there be a case where the result is None, but we should record the timing regardless of its return value?
There was a problem hiding this comment.
You are right this line should be outside the condition
There was a problem hiding this comment.
I changed it so if the result is None we add records only for http_client_duration and http_client_request size,
the status code and HTTP flavor are missing from attributes because we take them from the response.
how does it sound?
| ) | ||
|
|
||
| data = getattr(request, "data", None) | ||
| request_size = 0 if data is None else len(data) |
There was a problem hiding this comment.
Will this be a compressed size? Does data always return an iterable?
There was a problem hiding this comment.
Thanks for the comment, I checked this issue while I wrote the code and the difference is the urllib api works only with bytes, and urllib3 works with bytes and IO(like BytesIO)
| ) | ||
|
|
||
| response_size = int(response.headers.get("Content-Length", 0)) | ||
| histograms[MetricInstruments.HTTP_CLIENT_RESPONSE_SIZE].record( |
There was a problem hiding this comment.
Same question about the compression as the instrument description make it explicit
| key=lambda m: m.name, | ||
| ) | ||
|
|
||
| def assert_metric_expected( |
There was a problem hiding this comment.
I have some reservations about the PR on the main repo. I will leave a review there about it.
Description
Add metrics instrumentation for urllib accroding to https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/http-metrics.md#http-server
Fixes #1041
Type of change
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.