finish method

  1. @override
Future<void> finish({
  1. SpanStatus? status,
  2. DateTime? endTimestamp,
})
override

Sets span timestamp marking this span as finished.

Implementation

@override
Future<void> finish({SpanStatus? status, DateTime? endTimestamp}) async {
  if (finished) {
    return;
  }

  if (status != null) {
    _status = status;
  }

  if (endTimestamp == null) {
    endTimestamp = _hub.options.clock();
  } else if (endTimestamp.isBefore(_startTimestamp)) {
    _hub.options.logger(
      SentryLevel.warning,
      'End timestamp ($endTimestamp) cannot be before start timestamp ($_startTimestamp)',
    );
    endTimestamp = _hub.options.clock();
  } else {
    endTimestamp = endTimestamp.toUtc();
  }

  for (final collector in _hub.options.performanceCollectors) {
    if (collector is PerformanceContinuousCollector) {
      await collector.onSpanFinished(this, endTimestamp);
    }
  }

  // The finished flag depends on the _endTimestamp
  // If we set this earlier then finished is true and then we cannot use setData etc...
  _endTimestamp = endTimestamp;

  // associate error
  if (_throwable != null) {
    _hub.setSpanContext(_throwable, this, _tracer.name);
  }
  _metricSummaries = _localMetricsAggregator?.getSummaries();
  await _finishedCallback?.call(endTimestamp: _endTimestamp);
  return super.finish(status: status, endTimestamp: _endTimestamp);
}