startTransactionWithContext method

ISentrySpan startTransactionWithContext(
  1. SentryTransactionContext transactionContext, {
  2. Map<String, dynamic>? customSamplingContext,
  3. DateTime? startTimestamp,
  4. bool? bindToScope,
  5. bool? waitForChildren,
  6. Duration? autoFinishAfter,
  7. bool? trimEnd,
  8. OnTransactionFinish? onFinish,
})

Creates a Transaction and returns the instance.

Implementation

ISentrySpan startTransactionWithContext(
  SentryTransactionContext transactionContext, {
  Map<String, dynamic>? customSamplingContext,
  DateTime? startTimestamp,
  bool? bindToScope,
  bool? waitForChildren,
  Duration? autoFinishAfter,
  bool? trimEnd,
  OnTransactionFinish? onFinish,
}) {
  if (!_isEnabled) {
    _options.logger(
      SentryLevel.warning,
      "Instance is disabled and this 'startTransaction' call is a no-op.",
    );
  } else if (!_options.isTracingEnabled()) {
    _options.logger(
      SentryLevel.info,
      "Tracing is disabled and this 'startTransaction' returns a no-op.",
    );
  } else {
    final item = _peek();

    final samplingContext = SentrySamplingContext(
        transactionContext, customSamplingContext ?? {});

    // if transactionContext has no sampled decision, run the traces sampler
    if (transactionContext.samplingDecision == null) {
      final samplingDecision = _tracesSampler.sample(samplingContext);
      transactionContext =
          transactionContext.copyWith(samplingDecision: samplingDecision);
    }

    final tracer = SentryTracer(
      transactionContext,
      this,
      startTimestamp: startTimestamp,
      waitForChildren: waitForChildren ?? false,
      autoFinishAfter: autoFinishAfter,
      trimEnd: trimEnd ?? false,
      onFinish: onFinish,
    );
    if (bindToScope ?? false) {
      item.scope.span = tracer;
    }

    return tracer;
  }

  return NoOpSentrySpan();
}