Skip to content

Ignore trailing slash by default when recording web metrics #18207

@rswart

Description

@rswart

The WebMvcMetricsFilter uses the HandlerMapping.BEST_MATCHING_HANDLER_ATTRIBUTE to determine which handler the metric should be labeled with.

Since useTrailingSlashMatch is true by default most mvc controllers configured with a request mapping like:

@GetMapping(path = "/foo", produces = {MediaType.APPLICATION_JSON_VALUE})

will match both /foo and /foo/ and as a result BEST_MATCHING_HANDLER_ATTRIBUTE for this request mapping can have 2 values.

This leads to split metrics for the same request mapping: one for /foo and one for /foo/.

For now I have worked around this with a MeterRegistryCustomizer that strips the trailing slash, but I wonder if this does not deserve a more structural solution, e.g inside the metrics filter itself.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions