Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased

### Fixed
- `opentelemetry-instrumentation-flask` Fixed an issue where http_server_request_duration metrics was being recorded for excluded urls.
([#3794](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3794))

- `opentelemetry-instrumentation-dbapi`: fix crash retrieving libpq version when enabling commenter with psycopg
([#3796](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3796))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,30 +395,34 @@ 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_s = default_timer() - start
if duration_histogram_old:
duration_attrs_old = otel_wsgi._parse_duration_attrs(
attributes, _StabilityMode.DEFAULT
)
if flask.request and (
excluded_urls is None
or not excluded_urls.url_disabled(flask.request.url)
):
duration_s = default_timer() - start
if duration_histogram_old:
duration_attrs_old = otel_wsgi._parse_duration_attrs(
attributes, _StabilityMode.DEFAULT
)

if request_route:
# http.target to be included in old semantic conventions
duration_attrs_old[HTTP_TARGET] = str(request_route)
if request_route:
# http.target to be included in old semantic conventions
duration_attrs_old[HTTP_TARGET] = str(request_route)

duration_histogram_old.record(
max(round(duration_s * 1000), 0), duration_attrs_old
)
if duration_histogram_new:
duration_attrs_new = otel_wsgi._parse_duration_attrs(
attributes, _StabilityMode.HTTP
)
duration_histogram_old.record(
max(round(duration_s * 1000), 0), duration_attrs_old
)
if duration_histogram_new:
duration_attrs_new = otel_wsgi._parse_duration_attrs(
attributes, _StabilityMode.HTTP
)

if request_route:
duration_attrs_new[HTTP_ROUTE] = str(request_route)
if request_route:
duration_attrs_new[HTTP_ROUTE] = str(request_route)

duration_histogram_new.record(
max(duration_s, 0), duration_attrs_new
)
duration_histogram_new.record(
max(duration_s, 0), duration_attrs_new
)
active_requests_counter.add(-1, active_requests_count_attrs)
return result

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,8 @@ def test_flask_metrics(self):
attr,
_recommended_metrics_attrs_old[metric.name],
)
self.assertTrue(number_data_point_seen and histogram_data_point_seen)
self.assertTrue(number_data_point_seen)
self.assertFalse(histogram_data_point_seen)

def test_flask_metrics_new_semconv(self):
start = default_timer()
Expand Down Expand Up @@ -561,7 +562,8 @@ def test_flask_metrics_new_semconv(self):
attr,
_recommended_metrics_attrs_new[metric.name],
)
self.assertTrue(number_data_point_seen and histogram_data_point_seen)
self.assertTrue(number_data_point_seen)
self.assertFalse(histogram_data_point_seen)

def test_flask_metric_values(self):
start = default_timer()
Expand Down