コード例 #1
0
        public override void AddMetricStats(Segment segment, TimeSpan durationOfChildren, TransactionMetricStatsCollection txStats, IConfigurationService configService)
        {
            var duration          = segment.Duration.Value;
            var exclusiveDuration = TimeSpanMath.Max(TimeSpan.Zero, duration - durationOfChildren);

            MetricBuilder.TryBuildExternalRollupMetrics(Uri.Host, duration, txStats);

            // The CAT response data will be null if the agent did not receive a response that contained CAT headers (e.g. if the request went to an app that isn't monitored by a supported New Relic agent).
            // According to the agent spec, in the event when CAT response data is present, the agent generates ExternalTransaction/{host}/{cross_process_id}/{transaction_name} scoped metric to replace External/{host}/{method} scoped metric.
            if (CrossApplicationResponseData == null)
            {
                // Generate scoped and unscoped external metrics as CAT not present.
                MetricBuilder.TryBuildExternalSegmentMetric(Uri.Host, Method, duration, exclusiveDuration, txStats, false);
            }
            else
            {
                // Only generate unscoped metric for response with CAT headers because segments should only produce a single scoped metric and the CAT metric is more interesting than the external segment metric.
                MetricBuilder.TryBuildExternalSegmentMetric(Uri.Host, Method, duration, exclusiveDuration, txStats, true);

                var externalCrossProcessId  = CrossApplicationResponseData.CrossProcessId;
                var externalTransactionName = CrossApplicationResponseData.TransactionName;

                MetricBuilder.TryBuildExternalAppMetric(Uri.Host, externalCrossProcessId, exclusiveDuration, txStats);
                MetricBuilder.TryBuildExternalTransactionMetric(Uri.Host, externalCrossProcessId, externalTransactionName, duration, exclusiveDuration, txStats);
            }
        }