diff --git a/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py b/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py index 6ae6ce1790..4492d4e1f8 100644 --- a/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py @@ -513,7 +513,7 @@ def __init__( ) self.duration_histogram = self.meter.create_histogram( name=MetricInstruments.HTTP_SERVER_DURATION, - unit="ms", + unit="s", description="measures the duration of the inbound HTTP request", ) self.server_response_size_histogram = self.meter.create_histogram( @@ -609,7 +609,7 @@ async def __call__(self, scope, receive, send): target = _collect_target_attribute(scope) if target: duration_attrs[SpanAttributes.HTTP_TARGET] = target - duration = max(round((default_timer() - start) * 1000), 0) + duration = max(default_timer() - start, 0) self.duration_histogram.record(duration, duration_attrs) self.active_requests_counter.add( -1, active_requests_count_attrs diff --git a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py index 583f1adeb6..4714ad8976 100644 --- a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py @@ -321,7 +321,7 @@ def _instrument(self, **kwargs): ) _DjangoMiddleware._duration_histogram = meter.create_histogram( name=MetricInstruments.HTTP_SERVER_DURATION, - unit="ms", + unit="s", description="measures the duration of the inbound http request", ) _DjangoMiddleware._active_request_counter = meter.create_up_down_counter( diff --git a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware/otel_middleware.py b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware/otel_middleware.py index 491e78cab5..f4fcbcf5b1 100644 --- a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware/otel_middleware.py +++ b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware/otel_middleware.py @@ -377,9 +377,7 @@ def process_response(self, request, response): activation.__exit__(None, None, None) if request_start_time is not None: - duration = max( - round((default_timer() - request_start_time) * 1000), 0 - ) + duration = max(default_timer() - request_start_time, 0) self._duration_histogram.record(duration, duration_attrs) self._active_request_counter.add(-1, active_requests_count_attrs) if request.META.get(self._environ_token, None) is not None: diff --git a/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py b/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py index d6cf8249a4..a241acd53e 100644 --- a/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py @@ -267,7 +267,7 @@ def __init__(self, *args, **kwargs): ) self.duration_histogram = self._otel_meter.create_histogram( name=MetricInstruments.HTTP_SERVER_DURATION, - unit="ms", + unit="s", description="measures the duration of the inbound HTTP request", ) self.active_requests_counter = self._otel_meter.create_up_down_counter( @@ -385,7 +385,7 @@ def _start_response(status, response_headers, *args, **kwargs): duration_attrs[ SpanAttributes.HTTP_STATUS_CODE ] = span.attributes.get(SpanAttributes.HTTP_STATUS_CODE) - duration = max(round((default_timer() - start) * 1000), 0) + duration = max(default_timer() - start, 0) self.duration_histogram.record(duration, duration_attrs) self.active_requests_counter.add(-1, active_requests_count_attrs) if exception is None: diff --git a/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py b/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py index 18b4713eaf..e47704cec3 100644 --- a/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py @@ -354,7 +354,7 @@ def _start_response(status, response_headers, *args, **kwargs): return start_response(status, response_headers, *args, **kwargs) result = wsgi_app(wrapped_app_environ, _start_response) - duration = max(round((default_timer() - start) * 1000), 0) + duration = max((default_timer() - start), 0) duration_histogram.record(duration, duration_attrs) active_requests_counter.add(-1, active_requests_count_attrs) return result @@ -502,7 +502,7 @@ def __init__(self, *args, **kwargs): ) duration_histogram = meter.create_histogram( name=MetricInstruments.HTTP_SERVER_DURATION, - unit="ms", + unit="s", description="measures the duration of the inbound HTTP request", ) active_requests_counter = meter.create_up_down_counter( @@ -608,7 +608,7 @@ def instrument_app( ) duration_histogram = meter.create_histogram( name=MetricInstruments.HTTP_SERVER_DURATION, - unit="ms", + unit="s", description="measures the duration of the inbound HTTP request", ) active_requests_counter = meter.create_up_down_counter( diff --git a/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py b/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py index e3675fcfab..2ee8a5e7b0 100644 --- a/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py +++ b/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py @@ -139,7 +139,7 @@ def trace_tween_factory(handler, registry): ) duration_histogram = meter.create_histogram( name=MetricInstruments.HTTP_SERVER_DURATION, - unit="ms", + unit="s", description="measures the duration of the inbound HTTP request", ) active_requests_counter = meter.create_up_down_counter( @@ -197,7 +197,7 @@ def trace_tween(request): status = "500 InternalServerError" raise finally: - duration = max(round((default_timer() - start) * 1000), 0) + duration = max(default_timer() - start, 0) status = getattr(response, "status", status) status_code = otel_wsgi._parse_status_code(status) if status_code is not None: diff --git a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py index dfa4b217df..a99a320d99 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py @@ -295,7 +295,7 @@ def _create_server_histograms(meter) -> Dict[str, Histogram]: histograms = { MetricInstruments.HTTP_SERVER_DURATION: meter.create_histogram( name=MetricInstruments.HTTP_SERVER_DURATION, - unit="ms", + unit="s", description="measures the duration outbound HTTP requests", ), MetricInstruments.HTTP_SERVER_REQUEST_SIZE: meter.create_histogram( @@ -592,9 +592,7 @@ def _record_prepare_metrics(server_histograms, handler): def _record_on_finish_metrics(server_histograms, handler, error=None): - elapsed_time = round( - (default_timer() - server_histograms[_START_TIME]) * 1000 - ) + elapsed_time = (default_timer() - server_histograms[_START_TIME]) response_size = int(handler._headers.get("Content-Length", 0)) metric_attributes = _create_metric_attributes(handler) diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py index 87c73cc737..e705f5384d 100644 --- a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py @@ -506,7 +506,7 @@ def __init__( ) self.duration_histogram = self.meter.create_histogram( name=MetricInstruments.HTTP_SERVER_DURATION, - unit="ms", + unit="s", description="measures the duration of the inbound HTTP request", ) self.active_requests_counter = self.meter.create_up_down_counter( @@ -592,7 +592,7 @@ def __call__(self, environ, start_response): context.detach(token) raise finally: - duration = max(round((default_timer() - start) * 1000), 0) + duration = max(default_timer() - start, 0) self.duration_histogram.record(duration, duration_attrs) self.active_requests_counter.add(-1, active_requests_count_attrs)