Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] add metric to count responses per endpoint #3175

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,11 @@ def __init__(
unit="{request}",
description="Number of active HTTP server requests.",
)
self.response_counter = self.meter.create_counter(
name="wsgi_response_count",
unit="responses",
description="Counter for responses per endpoint",
)
self.request_hook = request_hook
self.response_hook = response_hook
self._sem_conv_opt_in_mode = sem_conv_opt_in_mode
Expand All @@ -594,9 +599,12 @@ def _create_start_response(
response_hook,
duration_attrs,
sem_conv_opt_in_mode,
response_counter,
endpoint_name
):
@functools.wraps(start_response)
def _start_response(status, response_headers, *args, **kwargs):
response_counter.add(1, {"status_code": status, "view": endpoint_name})
add_response_attributes(
span,
status,
Expand Down Expand Up @@ -658,12 +666,15 @@ def __call__(self, environ, start_response):
self.active_requests_counter.add(1, active_requests_count_attrs)
try:
with trace.use_span(span):
endpoint_name = environ.get("PATH_INFO")
start_response = self._create_start_response(
span,
start_response,
response_hook,
req_attrs,
self._sem_conv_opt_in_mode,
self.response_counter,
endpoint_name
)
iterable = self.wsgi(environ, start_response)
return _end_span_after_iterating(iterable, span, token)
Expand Down
Loading