private string GetEncodedTransactionData(IInternalTransaction transaction)
        {
            var txMetadata = transaction.TransactionMetadata;
            // If CrossApplicationReferrerTripId is null, then this is the first transaction to make an external request. In this case, use its Guid as the tripId.
            var tripId          = txMetadata.CrossApplicationReferrerTripId ?? transaction.Guid;
            var transactionData = new CrossApplicationRequestData(transaction.Guid, false, tripId, txMetadata.LatestCrossApplicationPathHash);

            return(HeaderEncoder.EncodeSerializedData(JsonConvert.SerializeObject(transactionData), _configurationService.Configuration.EncodingKey));
        }
        private string GetEncodedAppData(IInternalTransaction transaction, TransactionMetricName transactionMetricName, string crossProcessId)
        {
            var txMetadata            = transaction.TransactionMetadata;
            var queueTime             = txMetadata.QueueTime?.TotalSeconds ?? 0;
            var referrerContentLength = txMetadata.GetCrossApplicationReferrerContentLength();
            var responseTimeInSeconds = txMetadata.CrossApplicationResponseTimeInSeconds;
            var appData = new CrossApplicationResponseData(crossProcessId, transactionMetricName.PrefixedName, (float)queueTime, responseTimeInSeconds, referrerContentLength, transaction.Guid);

            return(HeaderEncoder.EncodeSerializedData(JsonConvert.SerializeObject(appData), _configurationService.Configuration.EncodingKey));
        }
Exemplo n.º 3
0
        public void ExternalSegment_HasCorrectTraceNameAndMetrics_IfCatResponseReceived()
        {
            const string encodingKey = "foo";

            _compositeTestAgent.ServerConfiguration.EncodingKey = encodingKey;
            _compositeTestAgent.PushConfiguration();

            var tx = _agent.CreateTransaction(
                isWeb: true,
                category: EnumNameCache <WebTransactionType> .GetName(WebTransactionType.Action),
                transactionDisplayName: "name",
                doNotTrackAsUnitOfWork: true);
            var segment = _agent.StartExternalRequestSegmentOrThrow(new Uri("http://www.newrelic.com/test"), "POST");

            var catResponseData = new CrossApplicationResponseData("123#456", "transactionName", 1.1f, 2.2f, 3, "guid");
            var responseHeaders = new Dictionary <string, string>
            {
                { "X-NewRelic-App-Data", HeaderEncoder.EncodeSerializedData(JsonConvert.SerializeObject(catResponseData), encodingKey) }
            };

            tx.ProcessInboundResponse(responseHeaders, segment);
            segment.End();
            tx.End();

            _compositeTestAgent.Harvest();

            var expectedMetrics = new[]
            {
                new ExpectedMetric {
                    Name = "External/all"
                },
                new ExpectedMetric {
                    Name = "External/allWeb"
                },
                new ExpectedMetric {
                    Name = "External/www.newrelic.com/all"
                },
                new ExpectedMetric {
                    Name = "External/www.newrelic.com/Stream/POST"
                },
                new ExpectedMetric {
                    Name = "ExternalApp/www.newrelic.com/123#456/all"
                },
                new ExpectedMetric {
                    Name = "ExternalTransaction/www.newrelic.com/123#456/transactionName"
                },
                new ExpectedMetric {
                    Name = "ExternalTransaction/www.newrelic.com/123#456/transactionName", Scope = "WebTransaction/Action/name"
                }
            };
            var unexpectedMetrics = new[]
            {
                new ExpectedMetric {
                    Name = "External/allOther"
                },
                new ExpectedMetric {
                    Name = "External/www.newrelic.com/Stream/POST", Scope = "WebTransaction/Action/name"
                }
            };
            var unexpectedSegments = new[]
            {
                "External/www.newrelic.com/Stream/POST"
            };
            var expectedSegments = new[]
            {
                "ExternalTransaction/www.newrelic.com/123#456/transactionName"
            };
            var actualMetrics    = _compositeTestAgent.Metrics.ToList();
            var transactionTrace = _compositeTestAgent.TransactionTraces.First();

            NrAssert.Multiple(
                () => TransactionTraceAssertions.SegmentsExist(expectedSegments, transactionTrace),
                () => TransactionTraceAssertions.SegmentsDoNotExist(unexpectedSegments, transactionTrace),
                () => MetricAssertions.MetricsExist(expectedMetrics, actualMetrics),
                () => MetricAssertions.MetricsDoNotExist(unexpectedMetrics, actualMetrics)
                );
        }