startSpan method
Span
startSpan({
- required String parentId,
- required String spanName,
- Map<
String, String> initialAttributes = const {},
override
Creates a child span within a trace.
The parentId should be a trace ID from startTrace.
The spanName should describe the sub-operation
(e.g., "query.execution").
Returns a Span object containing span ID.
Thread Safety: The returned Span object is not thread-safe. Do NOT share across isolates.
Implementation
@override
Span startSpan({
required String parentId,
required String spanName,
Map<String, String> initialAttributes = const {},
}) {
if (spanName.isEmpty) {
throw ArgumentError('Span name cannot be empty');
}
if (parentId.isEmpty) {
throw ArgumentError('Parent ID cannot be empty');
}
final spanId = _generateSpanId();
final now = DateTime.now().toUtc();
final span = Span(
spanId: spanId,
parentSpanId: parentId,
traceId: parentId,
name: spanName,
startTime: now,
attributes: initialAttributes,
);
_activeSpans[spanId] = span;
unawaited(_repository.exportSpan(span));
return span;
}