Skip to content

fix: trim trailing slash from the SLI operation name#63

Merged
xavierjohn merged 1 commit into
mainfrom
fix/trim-trailing-slash-operation-name
Jun 24, 2026
Merged

fix: trim trailing slash from the SLI operation name#63
xavierjohn merged 1 commit into
mainfrom
fix/trim-trailing-slash-operation-name

Conversation

@xavierjohn

Copy link
Copy Markdown
Owner

The issue

The Operation SLI tag is the HTTP method plus the endpoint's route template. A Minimal API route group's root endpoint — e.g. app.MapGroup("/orders").MapPost("/") — resolves to the raw route template /orders/ (the group prefix combined with the / pattern adds a trailing slash). So the emitted operation was POST /orders/: an unwanted trailing slash that also splits the metric into a separate series from /orders.

The fix

GetOperation trims a trailing slash from the resolved route template before composing the operation name, so /orders/ and /orders share one series. The literal root path / is preserved. The normalization applies to any resolved template (MVC AttributeRouteInfo.Template and Minimal API RouteEndpoint.RoutePattern.RawText alike), keeping the two hosting models aligned.

Regression tests cover a route-group root, an explicitly authored trailing-slash route, and the preserved literal root /.

A Minimal API route group's root endpoint (e.g. a "/orders" group mapped with
the "/" pattern) resolves to the raw route template "/orders/", so the Operation
tag was emitted as "POST /orders/" — an unwanted trailing slash that also split
it into a separate metric series from "/orders".

GetOperation now trims a trailing slash from the resolved route template (MVC and
Minimal API alike), while preserving the literal root path "/".
@github-actions

Copy link
Copy Markdown

Test Results

102 tests  +3   102 ✅ +3   13s ⏱️ ±0s
  3 suites ±0     0 💤 ±0 
  3 files   ±0     0 ❌ ±0 

Results for commit ccff3e4. ± Comparison against base commit 06499ed.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the ASP.NET Core middleware’s Operation tag normalization to trim a trailing / from resolved route templates (while preserving the literal root /) so route-group root endpoints like /orders/ don’t split metrics into a separate time series. This keeps Minimal APIs and MVC aligned and reduces unintended metric cardinality.

Changes:

  • Trim trailing slashes from resolved route templates in GetOperation (excluding the literal /).
  • Add regression tests for route-group roots, explicitly-authored trailing-slash routes, and the preserved root /.
  • Update package and root documentation to describe the normalization behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
Trellis.ServiceLevelIndicators.Asp/tests/ServiceLevelIndicatorMinimalApiTests.cs Adds regression tests validating trailing-slash normalization (including route groups) and preserving /.
Trellis.ServiceLevelIndicators.Asp/src/ServiceLevelIndicatorMiddleware.cs Normalizes resolved route templates by trimming trailing / while keeping / intact.
Trellis.ServiceLevelIndicators.Asp/src/README.md Documents trailing-slash trimming behavior for resolved templates.
README.md Updates public-facing description of Operation resolution to include trailing-slash trimming and root-path preservation.

@xavierjohn xavierjohn merged commit f5f30ba into main Jun 24, 2026
5 checks passed
@xavierjohn xavierjohn deleted the fix/trim-trailing-slash-operation-name branch June 24, 2026 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants