traceEnd method

void traceEnd(
  1. ISpectTraceToken? token, {
  2. Object? value,
  3. bool? success,
  4. Object? error,
  5. StackTrace? errorStackTrace,
  6. Map<String, Object?>? meta,
})

Ends a manual span. token is nullable - if traceStart returned null (logger disabled), this is a no-op.

Implementation

void traceEnd(
  ISpectTraceToken? token, {
  Object? value,
  bool? success,
  Object? error,
  StackTrace? errorStackTrace,
  Map<String, Object?>? meta,
}) {
  if (token == null) return;
  token.stopTiming();
  if (!isEnabled) return;
  final cfg = token.config ?? const ISpectTraceConfig();
  trace(
    category: token.category,
    source: token.source,
    operation: token.operation,
    target: token.target,
    key: token.key,
    value: value,
    success: success ?? (error == null),
    error: error,
    errorStackTrace: errorStackTrace,
    duration: token.elapsed,
    meta: _mergeTraceMeta(
      token.meta,
      meta,
      redactionActive: cfg.redact && ISpectRedaction.enabled,
      resourceLimits: cfg.resourceLimits ?? options.resourceLimits,
    ),
    config: token.config,
    correlationId: token.correlationId,
  );
}