Skip to content

Commit

Permalink
Fixed after CR
Browse files Browse the repository at this point in the history
  • Loading branch information
shalevr committed Jul 27, 2022
1 parent f4261ba commit 471dadf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def response_hook(span, request, response):

import contextlib
import typing
from typing import Collection
from timeit import default_timer
from typing import Collection

import urllib3.connectionpool
import wrapt
Expand Down Expand Up @@ -205,7 +205,7 @@ def instrumented_urlopen(wrapped, instance, args, kwargs):
with _suppress_further_instrumentation():
start_time = default_timer()
response = wrapped(*args, **kwargs)
elapsed_time = (default_timer() - start_time) * 1000
elapsed_time = round((default_timer() - start_time) * 1000)

_apply_response(span, response)
if callable(response_hook):
Expand All @@ -227,12 +227,14 @@ def instrumented_urlopen(wrapped, instance, args, kwargs):
)

request_size = 0 if body is None else len(body)
response_size = int(response.headers.get("Content-Length", 0))

duration_histogram.record(elapsed_time, attributes=metric_labels)
request_size_histogram.record(
request_size, attributes=metric_labels
)
response_size_histogram.record(
len(response.data), attributes=metric_labels
response_size, attributes=metric_labels
)

return response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "0.33b0"
__version__ = "0.32b0"
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from timeit import default_timer

import urllib3
import urllib3.exceptions
from urllib3.request import encode_multipart_formdata
from timeit import default_timer

from opentelemetry import trace
from opentelemetry.instrumentation.urllib3 import URLLib3Instrumentor
Expand Down Expand Up @@ -197,7 +198,7 @@ def test_basic_metric_check_client_size_post(self):
self.assertAlmostEqual(
data_point.sum,
client_duration_estimated,
delta=5000,
delta=1000,
)
self.assertIn(metric.name, expected_metrics)

Expand Down

0 comments on commit 471dadf

Please sign in to comment.