captureTransaction method

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

Implementation

@internal
Future<SentryId> captureTransaction(
  SentryTransaction transaction, {
  Scope? scope,
  SentryTraceContextHeader? traceContext,
}) async {
  final hint = Hint();

  SentryTransaction? preparedTransaction =
      _prepareEvent(transaction, hint) as SentryTransaction;

  if (scope != null) {
    preparedTransaction = await scope.applyToEvent(preparedTransaction, hint)
        as SentryTransaction?;
  } else {
    _options.logger(
        SentryLevel.debug, 'No scope to apply on transaction was provided');
  }

  // dropped by scope event processors
  if (preparedTransaction == null) {
    return _emptySentryId;
  }

  preparedTransaction = await _runEventProcessors(
    preparedTransaction,
    hint,
    eventProcessors: _options.eventProcessors,
  ) as SentryTransaction?;

  // dropped by event processors
  if (preparedTransaction == null) {
    return _emptySentryId;
  }

  if (_isIgnoredTransaction(preparedTransaction)) {
    _options.logger(
      SentryLevel.debug,
      'Transaction was ignored as specified in the ignoredTransactions options.',
    );

    _options.recorder.recordLostEvent(
        DiscardReason.ignored, _getCategory(preparedTransaction));
    return _emptySentryId;
  }

  preparedTransaction = _createUserOrSetDefaultIpAddress(preparedTransaction)
      as SentryTransaction;

  preparedTransaction =
      await _runBeforeSend(preparedTransaction, hint) as SentryTransaction?;

  // dropped by beforeSendTransaction
  if (preparedTransaction == null) {
    return _emptySentryId;
  }

  final attachments = scope?.attachments
      .where((element) => element.addToTransactions)
      .toList();
  final envelope = SentryEnvelope.fromTransaction(
    preparedTransaction,
    _options.sdk,
    dsn: _options.dsn,
    traceContext: traceContext,
    attachments: attachments,
  );

  final profileInfo = preparedTransaction.tracer.profileInfo;
  if (profileInfo != null) {
    envelope.items.add(profileInfo.asEnvelopeItem());
  }
  final id = await captureEnvelope(envelope);

  return id ?? SentryId.empty();
}