endSpan method
Finishes a span with optional attributes.
Call this when the sub-operation completes.
The spanId must match a previously created span.
Returns Future<void> to allow for async repository operations.
Implementation
@override
Future<void> endSpan({
required String spanId,
Map<String, String> attributes = const {},
}) async {
if (spanId.isEmpty) {
throw ArgumentError('Span ID cannot be empty');
}
final cached = _activeSpans[spanId];
if (cached == null) {
throw Exception('Span $spanId not found');
}
final now = DateTime.now().toUtc();
await _repository.updateSpan(
spanId: spanId,
endTime: now,
attributes: {...cached.attributes, ...attributes},
);
_activeSpans.remove(spanId);
}