startTrace method

  1. @override
Trace startTrace(
  1. String operationName
)
override

Starts a new distributed trace.

The operationName should describe the operation (e.g., "odbc.query"). Returns a Trace object containing trace ID and start time.

Thread Safety: The returned Trace object is not thread-safe. Do NOT share across isolates. Use within the creating isolate only.

Implementation

@override
Trace startTrace(String operationName) {
  if (operationName.isEmpty) {
    throw ArgumentError('Operation name cannot be empty');
  }

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

  final trace = Trace(
    traceId: traceId,
    name: operationName,
    startTime: now,
    attributes: {},
  );

  _activeTraces[traceId] = trace;
  unawaited(_repository.exportTrace(trace));
  return trace;
}