traceStart function

TraceContext? traceStart(
  1. String kind,
  2. String method,
  3. ({bool sampled, String spanId, String traceId})? parent
)

Implementation

TraceContext? traceStart(
    String kind, String method,
    ({String traceId, String spanId, bool sampled})? parent) {
  final tracer = _tracer;
  if (tracer == null || !_traceAllowed(method)) return null;
  final ctx = TraceContext(
    parent?.traceId ?? _randomHex(16),
    _randomHex(8),
    parent?.spanId ?? '',
    parent?.sampled ?? true,
  );
  if (!ctx.sampled) return ctx;
  try {
    tracer.onStart(kind, method, ctx.traceId, ctx.spanId, ctx.parentSpanId);
  } catch (_) {
    // observers must never break the call
  }
  return ctx;
}