Skip to content

Commit 471dadf

Browse files
author
sroda
committed
Fixed after CR
1 parent f4261ba commit 471dadf

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

instrumentation/opentelemetry-instrumentation-urllib3/src/opentelemetry/instrumentation/urllib3/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ def response_hook(span, request, response):
6666

6767
import contextlib
6868
import typing
69-
from typing import Collection
7069
from timeit import default_timer
70+
from typing import Collection
7171

7272
import urllib3.connectionpool
7373
import wrapt
@@ -205,7 +205,7 @@ def instrumented_urlopen(wrapped, instance, args, kwargs):
205205
with _suppress_further_instrumentation():
206206
start_time = default_timer()
207207
response = wrapped(*args, **kwargs)
208-
elapsed_time = (default_timer() - start_time) * 1000
208+
elapsed_time = round((default_timer() - start_time) * 1000)
209209

210210
_apply_response(span, response)
211211
if callable(response_hook):
@@ -227,12 +227,14 @@ def instrumented_urlopen(wrapped, instance, args, kwargs):
227227
)
228228

229229
request_size = 0 if body is None else len(body)
230+
response_size = int(response.headers.get("Content-Length", 0))
231+
230232
duration_histogram.record(elapsed_time, attributes=metric_labels)
231233
request_size_histogram.record(
232234
request_size, attributes=metric_labels
233235
)
234236
response_size_histogram.record(
235-
len(response.data), attributes=metric_labels
237+
response_size, attributes=metric_labels
236238
)
237239

238240
return response

instrumentation/opentelemetry-instrumentation-urllib3/src/opentelemetry/instrumentation/urllib3/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
__version__ = "0.33b0"
15+
__version__ = "0.32b0"

instrumentation/opentelemetry-instrumentation-urllib3/tests/test_urllib3_ip_support.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from timeit import default_timer
16+
1517
import urllib3
1618
import urllib3.exceptions
1719
from urllib3.request import encode_multipart_formdata
18-
from timeit import default_timer
1920

2021
from opentelemetry import trace
2122
from opentelemetry.instrumentation.urllib3 import URLLib3Instrumentor
@@ -197,7 +198,7 @@ def test_basic_metric_check_client_size_post(self):
197198
self.assertAlmostEqual(
198199
data_point.sum,
199200
client_duration_estimated,
200-
delta=5000,
201+
delta=1000,
201202
)
202203
self.assertIn(metric.name, expected_metrics)
203204

0 commit comments

Comments
 (0)