startTransaction method

Future<void> startTransaction(
  1. String name, {
  2. String? description,
  3. int? startNanoTime,
  4. int? autofinishWithStepsCount,
})

Start a performance transaction

Implementation

Future<void> startTransaction(
  String name, {
  String? description,
  int? startNanoTime,
  int? autofinishWithStepsCount,
}) async {
  final hub = _hub;
  if (!_isInitialized || hub == null) {
    ObslyLogger.warn('PerformanceController not initialized');
    return;
  }

  // Check if performance is enabled
  final config = ConfigController.instance.config;
  if (!(config?.enablePerformance ?? true)) {
    ObslyLogger.debug('Performance disabled, ignoring startTransaction call');
    return;
  }

  // Check if transaction already exists
  if (_activeTransactions.containsKey(name)) {
    ObslyLogger.warn('Transaction already started: $name');
    return;
  }

  try {
    final transaction = PerformanceTransaction(
      name: name,
      description: description,
      startTime: DateTime.now(),
      startNanoTime: startNanoTime ?? DateTime.now().microsecondsSinceEpoch,
      autofinishWithStepsCount: autofinishWithStepsCount,
    );

    _activeTransactions[name] = transaction;

    ObslyLogger.debug(
        '📊 Performance transaction started: $name (stored state only)');
  } catch (e) {
    ObslyLogger.error('Error starting transaction: $e');
  }
}