Skip to content

Commit

Permalink
add flask http route for metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitlinger committed Jun 11, 2024
1 parent ab0ea0e commit 91b9e72
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,13 @@ def get_default_span_name():
return span_name


def add_route(attributes):
if flask.request.url_rule:
# For 404 that result from no route found, etc, we
# don't have a url_rule.
attributes[SpanAttributes.HTTP_ROUTE] = flask.request.url_rule.rule


def _rewrapped_app(
wsgi_app,
active_requests_counter,
Expand Down Expand Up @@ -344,6 +351,7 @@ def _start_response(status, response_headers, *args, **kwargs):
excluded_urls is None
or not excluded_urls.url_disabled(flask.request.url)
):
add_route(attributes)
span = flask.request.environ.get(_ENVIRON_SPAN_KEY)

propagator = get_global_response_propagator()
Expand Down Expand Up @@ -420,10 +428,7 @@ def _before_request():
flask_request_environ,
sem_conv_opt_in_mode=sem_conv_opt_in_mode,
)
if flask.request.url_rule:
# For 404 that result from no route found, etc, we
# don't have a url_rule.
attributes[SpanAttributes.HTTP_ROUTE] = flask.request.url_rule.rule
add_route(attributes)
span, token = _start_internal_or_server_span(
tracer=tracer,
span_name=span_name,
Expand Down

0 comments on commit 91b9e72

Please sign in to comment.