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 {
  SentryTransaction? preparedTransaction =
      _prepareEvent(transaction) as SentryTransaction;

  final hint = Hint();

  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 _sentryId;
  }

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

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

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

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

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