private IInternalTransaction CreateInternalTransaction(ITransactionName initialTransactionName, Action onCreate)
        {
            RemoveOutstandingInternalTransactions(true, true);

            var transactionContext = GetFirstActivePrimaryContext();

            if (transactionContext == null)
            {
                Log.Error("Unable to locate a valid TransactionContext.");
                return(null);
            }
            var priority    = _tracePriorityManager.Create();
            var transaction = new Transaction(_configuration, initialTransactionName, _timerFactory.StartNewTimer(),
                                              DateTime.UtcNow, _callStackManagerFactory.CreateCallStackManager(), _databaseService, priority,
                                              _databaseStatementParser, _distributedTracePayloadHandler, _errorService, _attribDefSvc.AttributeDefs);

            try
            {
                transactionContext.SetData(transaction);
            }
            catch (Exception exception)
            {
                Log.Error($"The chosen TransactionContext threw an exception when setting the data: {exception}");
                return(null);
            }

            if (Log.IsFinestEnabled)
            {
                transaction.LogFinest($"Created transaction on {transactionContext}");
            }

            if (onCreate != null)
            {
                onCreate();
            }

            return(transaction);
        }
 public ICallStackManager CreateCallStackManager()
 {
     return(_callStackManagerFactory.CreateCallStackManager());
 }