captureTransaction method

  1. @internal
Future<SentryId> captureTransaction(
  1. SentryTransaction transaction, {
  2. SentryTraceContextHeader? traceContext,
})

Implementation

@internal
Future<SentryId> captureTransaction(
  SentryTransaction transaction, {
  SentryTraceContextHeader? traceContext,
}) async {
  var sentryId = SentryId.empty();

  if (!_isEnabled) {
    _options.logger(
      SentryLevel.warning,
      "Instance is disabled and this 'captureTransaction' call is a no-op.",
    );
  } else if (!_options.isTracingEnabled()) {
    _options.logger(
      SentryLevel.info,
      "Tracing is disabled and this 'captureTransaction' call is a no-op.",
    );
  } else if (!transaction.finished) {
    _options.logger(
      SentryLevel.warning,
      'Capturing unfinished transaction: ${transaction.eventId}',
    );
  } else {
    final item = _peek();

    if (!transaction.sampled) {
      _options.recorder.recordLostEvent(
        DiscardReason.sampleRate,
        DataCategory.transaction,
      );
      _options.recorder.recordLostEvent(
        DiscardReason.sampleRate,
        DataCategory.span,
        count: transaction.spans.length + 1,
      );
      _options.logger(
        SentryLevel.warning,
        'Transaction ${transaction.eventId} was dropped due to sampling decision.',
      );
    } else {
      try {
        sentryId = await item.client.captureTransaction(
          transaction,
          scope: item.scope,
          traceContext: traceContext,
        );
      } catch (exception, stackTrace) {
        _options.logger(
          SentryLevel.error,
          'Error while capturing transaction with id: ${transaction.eventId}',
          exception: exception,
          stackTrace: stackTrace,
        );
        if (_options.automatedTestMode) {
          rethrow;
        }
      }
    }
  }
  return sentryId;
}