matchedPathOf function

String? matchedPathOf(
  1. Request request
)

The route pattern that matched request, or null when none did.

The pattern, not the path: /todos/{id} rather than /todos/7. That is what a span name, a metric label, or a log line should carry — naming them after the path makes every id its own operation, and a dashboard of a million one-request operations says nothing.

null for a request that reached the fallback, or one built in a test without a router, because no route matched it.

Implementation

String? matchedPathOf(Request request) {
  final raw = request.context[matchedPathKey];
  return raw is String ? raw : null;
}