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()) {
    final item = _peek();
    item.scope.propagationContext = PropagationContext();
  } else {
    final item = _peek();

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

    if (transactionContext.origin == null) {
      transactionContext = transactionContext.copyWith(
        origin: SentryTraceOrigins.manual,
      );
    }

    SentryProfiler? profiler;
    if (_profilerFactory != null &&
        _tracesSampler.sampleProfiling(samplingDecision)) {
      profiler = _profilerFactory?.startProfiler(transactionContext);
    }

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

    return tracer;
  }

  return NoOpSentrySpan();
}