startActiveSpan<T> method

T startActiveSpan<T>({
  1. required String name,
  2. required T fn(
    1. APISpan span
    ),
  3. SpanKind kind = SpanKind.internal,
  4. Attributes? attributes,
})

TODO - needs better doc. Is recordSpan superfluous?

Implementation

T startActiveSpan<T>({
  required String name,
  required T Function(APISpan span) fn,
  SpanKind kind = SpanKind.internal,
  Attributes? attributes,
}) {
  final span = startSpan(name, kind: kind, attributes: attributes);
  try {
    // Use our own withSpan to ensure proper context propagation
    return withSpan(span, () => fn(span));
  } finally {
    span.end();
  }
}