recordPhase method
Records a measured phase duration in milliseconds.
durationMs is null when the phase was never measured (for example a
pooled connection that skipped DNS/connect). Those phases are omitted so
the backend can tell "not measured" apart from a real duration.
A finite value — including 0.0 and fractional values such as 0.4 —
is a measured duration and is emitted as a double.
Implementation
void recordPhase(HttpTimingPhase phase, double? durationMs) {
if (durationMs == null) return;
if (!supportedPhases.contains(phase)) return;
if (phase == HttpTimingPhase.total || phase == HttpTimingPhase.call) {
return; // recorded in end()
}
if (_completedPhases.contains(phase)) return;
final attrKey = 'http.client.timing.${phase.name}_ms';
span.setAttribute(Attribute.fromDouble(attrKey, durationMs));
span.addEvent(
'http.${phase.name}',
attributes: [Attribute.fromDouble('duration_ms', durationMs)],
);
_completedPhases.add(phase);
}