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;

  if (scope != null) {
    preparedTransaction =
        await scope.applyToEvent(preparedTransaction) 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 _processEvent(
    preparedTransaction,
    eventProcessors: _options.eventProcessors,
  ) as SentryTransaction?;

  // dropped by event processors
  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 id = await captureEnvelope(envelope);

  return id ?? SentryId.empty();
}