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();
  }

  // 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);
}