private void GenerateAndCollectSqlTrace(ImmutableTransaction immutableTransaction, TransactionMetricName transactionMetricName, TransactionMetricStatsCollection txStats)
        {
            if (!_configurationService.Configuration.SlowSqlEnabled)
            {
                return;
            }

            var txSqlTrStats = new SqlTraceStatsCollection();

            foreach (var segment in immutableTransaction.Segments.Where(s => s.Data is DatastoreSegmentData))
            {
                var datastoreSegmentData = (DatastoreSegmentData)segment.Data;
                if (datastoreSegmentData.CommandText != null &&
                    segment.Duration >= _configurationService.Configuration.SqlExplainPlanThreshold)
                {
                    AddSqlTraceStats(txSqlTrStats, _sqlTraceMaker.TryGetSqlTrace(immutableTransaction, transactionMetricName, segment));
                }
            }

            if (txSqlTrStats.Collection.Count > 0)
            {
                using (_agentTimerService.StartNew("CollectSqlTrace"))
                {
                    _sqlTraceAggregator.Collect(txSqlTrStats);
                }

                MetricBuilder.TryBuildSqlTracesCollectedMetric(txSqlTrStats.TracesCollected, txStats);
            }
        }