nameSpan function

void nameSpan(
  1. String route
)

Overrides the route the current span is labelled with.

The layer already names a span after the route that matched, so this is only for the cases the route table cannot describe — a mounted service that does its own dispatch, or a handler serving several logical operations:

nameSpan('/legacy/{action}');

An explicit name wins over the matched route, and does nothing when tracing is not installed.

Implementation

void nameSpan(String route) {
  final span = CurrentSpan.value;
  if (span == null) return;
  span
    ..name = route
    ..setAttribute('http.route', route);
}