endTrace method

  1. @override
Future<void> endTrace({
  1. required String traceId,
  2. Map<String, String> attributes = const {},
})
override

Finishes a trace with optional attributes.

Call this when the operation completes successfully. The traceId must match a previously started trace. Additional attributes can be attached for filtering.

Returns Future<void> to allow for async repository operations.

Implementation

@override
Future<void> endTrace({
  required String traceId,
  Map<String, String> attributes = const {},
}) async {
  if (traceId.isEmpty) {
    throw ArgumentError('Trace ID cannot be empty');
  }

  final cached = _activeTraces[traceId];
  if (cached == null) {
    throw Exception('Trace $traceId not found');
  }

  final now = DateTime.now().toUtc();

  await _repository.updateTrace(
    traceId: traceId,
    endTime: now,
    attributes: {...cached.attributes, ...attributes},
  );

  _activeTraces.remove(traceId);
}