endTrace method
Finishes a trace by calculating duration.
Returns ResultDart with success or TelemetryException on error.
Implementation
@override
Future<ResultDart<void, TelemetryException>> endTrace({
required String traceId,
Map<String, String> attributes = const {},
}) async {
final cached = _activeTraces[traceId];
if (cached == null) {
return Failure(
TelemetryException(
message: 'Trace $traceId not found',
code: 'TRACE_NOT_FOUND',
),
);
}
final now = DateTime.now().toUtc();
final updatedTrace = cached.copyWith(
endTime: now,
attributes: {...cached.attributes, ...attributes},
);
await _repository.updateTrace(
traceId: traceId,
endTime: now,
attributes: updatedTrace.attributes,
);
_activeTraces.remove(traceId);
return const Success(unit);
}