timing function
Creates middleware that records downstream request handling time.
Implementation
Middleware timing({String metricName = 'app', int fractionDigits = 1}) {
RangeError.checkValueInInterval(fractionDigits, 0, 20, 'fractionDigits');
return (event, next) async {
final stopwatch = Stopwatch()..start();
final response = await next();
stopwatch.stop();
response.headers.append(
'server-timing',
_formatServerTimingMetric(
metricName,
stopwatch.elapsedMicroseconds,
fractionDigits,
),
);
return response;
};
}