-
Notifications
You must be signed in to change notification settings - Fork 807
Description
There is a way to get the http.route included in autoinstrumented metrics for FastAPI?
Looking the following docs: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/http-metrics.md#parameterized-attributes
But the implementation of the recommended attributes doesn't include the http.route attribute:
opentelemetry-python-contrib/util/opentelemetry-util-http/src/opentelemetry/util/http/__init__.py
Lines 30 to 48 in 18e056b
| # List of recommended metrics attributes | |
| _duration_attrs = [ | |
| SpanAttributes.HTTP_METHOD, | |
| SpanAttributes.HTTP_HOST, | |
| SpanAttributes.HTTP_SCHEME, | |
| SpanAttributes.HTTP_STATUS_CODE, | |
| SpanAttributes.HTTP_FLAVOR, | |
| SpanAttributes.HTTP_SERVER_NAME, | |
| SpanAttributes.NET_HOST_NAME, | |
| SpanAttributes.NET_HOST_PORT, | |
| ] | |
| _active_requests_count_attrs = [ | |
| SpanAttributes.HTTP_METHOD, | |
| SpanAttributes.HTTP_HOST, | |
| SpanAttributes.HTTP_SCHEME, | |
| SpanAttributes.HTTP_FLAVOR, | |
| SpanAttributes.HTTP_SERVER_NAME, | |
| ] |
opentelemetry-python-contrib/util/opentelemetry-util-http/src/opentelemetry/util/http/__init__.py
Lines 152 to 165 in 18e056b
| def _parse_active_request_count_attrs(req_attrs): | |
| active_requests_count_attrs = {} | |
| for attr_key in _active_requests_count_attrs: | |
| if req_attrs.get(attr_key) is not None: | |
| active_requests_count_attrs[attr_key] = req_attrs[attr_key] | |
| return active_requests_count_attrs | |
| def _parse_duration_attrs(req_attrs): | |
| duration_attrs = {} | |
| for attr_key in _duration_attrs: | |
| if req_attrs.get(attr_key) is not None: | |
| duration_attrs[attr_key] = req_attrs[attr_key] | |
| return duration_attrs |
Also the implementation of ASGI instrumentation, parse attributes for both metrics (duration and active_requests) after the addition of additional attributes (where the http.routes comes):
Lines 446 to 450 in 3c24adf
| attributes.update(additional_attributes) | |
| active_requests_count_attrs = _parse_active_request_count_attrs( | |
| attributes | |
| ) | |
| duration_attrs = _parse_duration_attrs(attributes) |
Is your feature request related to a problem?
Maybe the inclusion of path or route attributes, could be usefull for metrics analysis.
Describe the solution you'd like
Move the additional attributes update in the ASGI instrumentation, after the call of recommended attributes for metrics.
Describe alternatives you've considered
Manually instrumentation of all paths in the API.