endSpan static method

void endSpan(
  1. _TelemetrySpan span, {
  2. Object? error,
})

End an existing span

Implementation

static void endSpan(_TelemetrySpan span, {Object? error}) {
  span.endTime = DateTime.now();

  if (error != null) {
    span.attributes['error'] = true;
    span.attributes['error.message'] = error.toString();
  }

  // Remove from active spans
  _spans.remove(span.id);

  // In production, this would export to OTel collector
  // For now, we log for debugging
  if (_debugMode) {
    print('[TELEMETRY] Span ended: ${span.name} (${span.duration?.inMilliseconds}ms)');
    print('  Attributes: ${span.attributes}');
    if (span.events.isNotEmpty) {
      print('  Events: ${span.events.length}');
    }
  }
}