Skip to content

Commit

Permalink
evaluate labels after path is set
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenhillier committed May 28, 2024
1 parent a47c5f0 commit 4dc9590
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions starlette_exporter/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,15 +407,6 @@ async def wrapped_send(message: Message) -> None:
else:
status_code = 500

labels = [
method,
path,
status_code,
self.app_name,
*request_labels,
*response_labels,
]

if self.filter_unhandled_paths or self.group_paths:
grouped_path: Optional[str] = None

Expand All @@ -438,6 +429,15 @@ async def wrapped_send(message: Message) -> None:
if self.group_paths and grouped_path is not None:
path = grouped_path

labels = [
method,
path,
status_code,
self.app_name,
*request_labels,
*response_labels,
]

# optional extra arguments to be passed as kwargs to observations
# note: only used for histogram observations and counters to support exemplars
extra = {}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def test_mounted_path_404(self, testapp):

def test_mounted_path_404_filter(self, testapp):
"""test an unhandled path from mounted base path can be excluded from metrics"""
client = TestClient(testapp(filter_unhandled_paths=True))
client = TestClient(testapp())
client.get("/mounted/404")
metrics = client.get("/metrics").content.decode()

Expand Down

0 comments on commit 4dc9590

Please sign in to comment.