Ejemplo n.º 1
0
        public void Test()
        {
            Assert.Contains("NREUM", _browserTimingHeader);

            var browserMonitoringConfig = JavaScriptAgent.GetJavaScriptAgentConfigFromSource(_browserTimingHeader);

            NrAssert.Multiple(
                () => Assert.Contains("beacon", browserMonitoringConfig.Keys),
                () => Assert.Contains("errorBeacon", browserMonitoringConfig.Keys),
                () => Assert.Contains("licenseKey", browserMonitoringConfig.Keys),
                () => Assert.Contains("applicationID", browserMonitoringConfig.Keys),
                () => Assert.Contains("transactionName", browserMonitoringConfig.Keys),
                () => Assert.Contains("queueTime", browserMonitoringConfig.Keys),
                () => Assert.Contains("applicationTime", browserMonitoringConfig.Keys),
                () => Assert.Contains("agent", browserMonitoringConfig.Keys),
                () => Assert.Contains("atts", browserMonitoringConfig.Keys)
                );
            var attrsDict = HeaderEncoder.DecodeAndDeserialize <Dictionary <string, IDictionary <string, object> > >(browserMonitoringConfig["atts"], _fixture.TestConfiguration.LicenseKey, 13);

            Assert.Contains("a", attrsDict.Keys);
            IDictionary <string, object> agentAttrsDict = attrsDict["a"];

            Assert.Contains("nr.tripId", agentAttrsDict.Keys);

            NrAssert.Multiple(
                () => Assert.NotNull(browserMonitoringConfig["beacon"]),
                () => Assert.NotNull(browserMonitoringConfig["errorBeacon"]),
                () => Assert.NotNull(browserMonitoringConfig["licenseKey"]),
                () => Assert.NotNull(browserMonitoringConfig["applicationID"]),
                () => Assert.NotNull(browserMonitoringConfig["transactionName"]),
                () => Assert.NotNull(browserMonitoringConfig["queueTime"]),
                () => Assert.NotNull(browserMonitoringConfig["applicationTime"]),
                () => Assert.NotNull(browserMonitoringConfig["agent"])
                );
        }
Ejemplo n.º 2
0
        private string GetUntrustedXNewRelicId()
        {
            var invalidAccountId = "999999";
            var applicationId    = AgentLog.GetApplicationId();
            var accountAndApp    = $@"{invalidAccountId}#{applicationId}";

            return(HeaderEncoder.Base64Encode(accountAndApp, HeaderEncoder.IntegrationTestEncodingKey));
        }
        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));
        }
Ejemplo n.º 5
0
        /// <summary> Writes the header data in the codestream and actualize ndata with the
        /// header length. The header is either a MainHeaderEncoder or a
        /// TileHeaderEncoder.
        ///
        /// </summary>
        /// <param name="he">The current header encoder.
        ///
        /// </param>
        /// <exception cref="IOException">If an I/O error occurs while writing the data.
        ///
        /// </exception>
        public override void  commitBitstreamHeader(HeaderEncoder he)
        {
            // Actualize ndata
            ndata += he.Length;
            he.writeTo(out_Renamed);             // Write the header
            // Reset packet index used for SOP markers
            packetIdx = 0;

            // Deal with ROI information
            lenLastNoROI += he.Length;
        }
        public void Test()
        {
            var catResponseHeader = _responseHeaders.GetValues(@"X-NewRelic-App-Data")?.FirstOrDefault();

            Assert.NotNull(catResponseHeader);
            var catResponseData          = HeaderEncoder.DecodeAndDeserialize <CrossApplicationResponseData>(catResponseHeader, HeaderEncoder.IntegrationTestEncodingKey);
            var transactionEventRedirect = _fixture.AgentLog.TryGetTransactionEvent("WebTransaction/StatusCode/301");

            Assert.NotNull(transactionEventRedirect);
            Assert.Equal("WebTransaction/StatusCode/301", catResponseData.TransactionName);
        }
        public CrossApplicationResponseData TryDecodeInboundResponseHeaders(IDictionary <string, string> headers)
        {
            if (!_configurationService.Configuration.CrossApplicationTracingEnabled)
            {
                return(null);
            }

            var responseHeader = headers.GetValueOrDefault(AppDataHttpHeader);

            if (responseHeader == null)
            {
                return(null);
            }

            //It is possible that multiple instrumentations, on the service side, try to add New Relic header
            //to the response on the same transaction. When that happens, the response received by the client
            //has the New Relic header contains multiple header data separated by commas. The agent will only
            //decode the first header data in this case.
            var separatorIndex = responseHeader.IndexOf(",");

            if (separatorIndex > 0)
            {
                _supportabilityMetrics.Record(CATSupportabilityCondition.Response_Accept_MultipleResponses);
                responseHeader = responseHeader.Substring(0, separatorIndex);
            }

            try
            {
                var result = HeaderEncoder.TryDecodeAndDeserialize <CrossApplicationResponseData>(responseHeader, _configurationService.Configuration.EncodingKey);

                if (result == null)
                {
                    _supportabilityMetrics.Record(CATSupportabilityCondition.Response_Accept_Failure);
                }
                else
                {
                    _supportabilityMetrics.Record(CATSupportabilityCondition.Response_Accept_Success);
                }

                return(result);
            }
            catch (Exception ex)
            {
                _supportabilityMetrics.Record(CATSupportabilityCondition.Response_Accept_Failure);

                if (ex is Newtonsoft.Json.JsonSerializationException)
                {
                    return(null);
                }

                throw;
            }
        }
Ejemplo n.º 8
0
        public static byte[] EncodeJPEG(Image jpgImage)
        {
            Tiler                 imgtiler;
            ForwCompTransf        fctransf;
            ImgDataConverter      converter;
            EncoderSpecs          encSpec;
            ForwardWT             dwt;
            Quantizer             quant;
            ROIScaler             rois;
            EntropyCoder          ecoder;
            PostCompRateAllocator ralloc;
            HeaderEncoder         headenc;
            CodestreamWriter      bwriter;

            float rate = Single.MaxValue;

            ImgReaderGDI imgsrc = new ImgReaderGDI(jpgImage);

            imgtiler = new Tiler(imgsrc, 0, 0, 0, 0, jpgImage.Width, jpgImage.Height);
            int ntiles = imgtiler.getNumTiles();

            encSpec = new EncoderSpecs(ntiles, 3, imgsrc, pl);

            fctransf  = new ForwCompTransf(imgtiler, encSpec);
            converter = new ImgDataConverter(fctransf);
            dwt       = ForwardWT.createInstance(converter, pl, encSpec);
            quant     = Quantizer.createInstance(dwt, encSpec);
            rois      = ROIScaler.createInstance(quant, pl, encSpec);
            ecoder    = EntropyCoder.createInstance(rois, pl, encSpec.cblks,
                                                    encSpec.pss, encSpec.bms,
                                                    encSpec.mqrs, encSpec.rts,
                                                    encSpec.css, encSpec.sss,
                                                    encSpec.lcs, encSpec.tts);

            using (MemoryStream stream = new MemoryStream())
            {
                bwriter = new FileCodestreamWriter(stream, Int32.MaxValue);
                ralloc  = PostCompRateAllocator.createInstance(ecoder, pl, rate, bwriter, encSpec);

                headenc = new HeaderEncoder(imgsrc, new bool[3], dwt, imgtiler, encSpec, rois, ralloc, pl);
                ralloc.HeaderEncoder = headenc;
                headenc.encodeMainHeader();
                ralloc.initialize();
                headenc.reset();
                headenc.encodeMainHeader();
                bwriter.commitBitstreamHeader(headenc);

                ralloc.runAndWrite();
                bwriter.close();

                return(stream.ToArray());
            }
        }
        public void Test()
        {
            var catResponseHeader = _responseHeaders.GetValues(@"X-NewRelic-App-Data")?.FirstOrDefault();

            Assert.NotNull(catResponseHeader);

            var catResponseData = HeaderEncoder.DecodeAndDeserialize <CrossApplicationResponseData>(catResponseHeader, HeaderEncoder.IntegrationTestEncodingKey);

            var transactionSample        = _fixture.AgentLog.TryGetTransactionSample("WebTransaction/MVC/DefaultController/Index");
            var transactionEventIndex    = _fixture.AgentLog.TryGetTransactionEvent("WebTransaction/MVC/DefaultController/Index");
            var transactionEventRedirect = _fixture.AgentLog.TryGetTransactionEvent("WebTransaction/MVC/DefaultController/DoRedirect");
            var metrics = _fixture.AgentLog.GetMetrics();

            NrAssert.Multiple
            (
                () => Assert.NotNull(transactionSample),
                () => Assert.NotNull(transactionEventRedirect),
                () => Assert.NotNull(transactionEventIndex)
            );

            NrAssert.Multiple
            (
                () => Assert.Equal(_fixture.AgentLog.GetCrossProcessId(), catResponseData.CrossProcessId),
                () => Assert.Equal("WebTransaction/MVC/DefaultController/Index", catResponseData.TransactionName),
                () => Assert.True(catResponseData.QueueTimeInSeconds >= 0),
                () => Assert.True(catResponseData.ResponseTimeInSeconds >= 0),
                () => Assert.Equal(-1, catResponseData.ContentLength),
                () => Assert.NotNull(catResponseData.TransactionGuid),
                () => Assert.False(catResponseData.Unused),

                // Trace attributes
                () => Assertions.TransactionTraceHasAttributes(Expectations.ExpectedTransactionTraceIntrinsicAttributesCatEnabled, TransactionTraceAttributeType.Intrinsic, transactionSample),
                () => Assertions.TransactionTraceDoesNotHaveAttributes(Expectations.UnexpectedTransactionTraceIntrinsicAttributesCatEnabled, TransactionTraceAttributeType.Intrinsic, transactionSample),

                // transactionEventIndex attributes
                () => Assertions.TransactionEventHasAttributes(Expectations.ExpectedTransactionEventIntrinsicAttributesCatEnabled, TransactionEventAttributeType.Intrinsic, transactionEventIndex),
                () => Assertions.TransactionEventDoesNotHaveAttributes(Expectations.UnexpectedTransactionEventIntrinsicAttributesCatEnabled, TransactionEventAttributeType.Intrinsic, transactionEventIndex),

                // transactionEventRedirect attributes
                () => Assertions.TransactionEventHasAttributes(Expectations.ExpectedTransactionEventIntrinsicAttributesCatEnabled, TransactionEventAttributeType.Intrinsic, transactionEventRedirect),
                () => Assertions.TransactionEventDoesNotHaveAttributes(Expectations.UnexpectedTransactionEventIntrinsicAttributesCatEnabled, TransactionEventAttributeType.Intrinsic, transactionEventRedirect),

                () => Assertions.MetricsExist(Expectations.ExpectedMetricsCatEnabled, metrics)
            );
        }
        public void SetUp()
        {
            _compositeTestAgent = new CompositeTestAgent();
            _compositeTestAgent.LocalConfiguration.distributedTracing.enabled     = false;
            _compositeTestAgent.LocalConfiguration.crossApplicationTracingEnabled = true;
            _compositeTestAgent.ServerConfiguration.AccountId            = _accountId.ToString();
            _compositeTestAgent.ServerConfiguration.TrustedAccountKey    = _trustKey;
            _compositeTestAgent.ServerConfiguration.PrimaryApplicationId = _appId.ToString();
            _catMetricCounters = _compositeTestAgent.Container.Resolve <ICATSupportabilityMetricCounters>();

            var crossProcessID = $"{_accountId}#{_appId}";

            _crossProcessIDEncoded = Strings.Base64Encode(crossProcessID, _agent.Configuration.EncodingKey);

            var reqData = new CrossApplicationRequestData("referrerTransactionGuid", false, "referrerTripId", "referrerPathHash");

            _reqDataEncoded = HeaderEncoder.SerializeAndEncode(reqData, _agent.Configuration.EncodingKey);

            _compositeTestAgent.ServerConfiguration.TrustedIds = new long[] { _accountId };

            _compositeTestAgent.PushConfiguration();
        }
        public CrossApplicationRequestData TryDecodeInboundRequestHeaders <T>(T carrier, Func <T, string, IEnumerable <string> > getter)
        {
            if (!_configurationService.Configuration.CrossApplicationTracingEnabled)
            {
                return(null);
            }

            var encodedTransactionDataHttpHeader = getter(carrier, TransactionDataHttpHeader).FirstOrDefault();

            if (encodedTransactionDataHttpHeader == null)
            {
                return(null);
            }

            var data = HeaderEncoder.TryDecodeAndDeserialize <CrossApplicationRequestData>(encodedTransactionDataHttpHeader, _configurationService.Configuration.EncodingKey);

            if (data == null)
            {
                _supportabilityMetrics.Record(CATSupportabilityCondition.Request_Accept_Failure_Decode);
            }

            return(data);
        }
        public void Test()
        {
            var catResponseHeader = _responseHeaders.GetValues(@"X-NewRelic-App-Data")?.FirstOrDefault();

            Assert.NotNull(catResponseHeader);

            var catResponseData = HeaderEncoder.DecodeAndDeserialize <CrossApplicationResponseData>(catResponseHeader, HeaderEncoder.IntegrationTestEncodingKey);

            var metrics = _fixture.AgentLog.GetMetrics().ToList();
            var calleeTransactionEvent = _fixture.AgentLog.TryGetTransactionEvent("WebTransaction/MVC/DefaultController/Index");

            Assert.NotNull(calleeTransactionEvent);

            var callerTransactionTrace = _fixture.AgentLog.TryGetTransactionSample("WebTransaction/MVC/DefaultController/ChainedHttpClient");

            Assert.NotNull(callerTransactionTrace);

            var crossProcessId = _fixture.AgentLog.GetCrossProcessId();

            // Note: we are checking the metrics that are generated by the *Caller* as a result of receiving a CAT response.
            var expectedMetrics = new List <Assertions.ExpectedMetric>
            {
                new Assertions.ExpectedMetric {
                    metricName = @"External/all", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"External/allWeb", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = $@"External/{_fixture.RemoteApplication.DestinationServerName}/all", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = $@"ExternalApp/{_fixture.RemoteApplication.DestinationServerName}/{crossProcessId}/all", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = $@"ExternalTransaction/{_fixture.RemoteApplication.DestinationServerName}/{crossProcessId}/WebTransaction/MVC/DefaultController/Index", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = $@"ExternalTransaction/{_fixture.RemoteApplication.DestinationServerName}/{crossProcessId}/WebTransaction/MVC/DefaultController/Index", metricScope = @"WebTransaction/MVC/DefaultController/ChainedHttpClient", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = $@"External/{_fixture.RemoteApplication.DestinationServerName}/Stream/GET", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"ClientApplication/[^/]+/all", IsRegexName = true
                }
            };
            var unexpectedMetrics = new List <Assertions.ExpectedMetric>
            {
                // This scoped metric should be superceded by the ExternalTransaction metric above
                new Assertions.ExpectedMetric {
                    metricName = $@"External/{_fixture.RemoteApplication.DestinationServerName}/Stream/GET", metricScope = @"WebTransaction/MVC/DefaultController/ChainedHttpClient"
                }
            };
            // Note: we are checking the attributes attached to the *Callee's* transaction, not the caller's transaction. The attributes attached to the caller's transaction are already fully vetted in the CatInbound tests.
            var expectedTransactionEventIntrinsicAttributes1 = new List <string>
            {
                "nr.guid",
                "nr.pathHash",
                "nr.referringPathHash",
                "nr.referringTransactionGuid"
            };
            var expectedTransactionEventIntrinsicAttributes2 = new Dictionary <string, string>
            {
                // This value comes from what we send to the application (see parameter passed to GetWithCatHeader above)
                { "nr.tripId", "tripId" }
            };
            var expectedCallerTraceSegmentParameters = new List <Assertions.ExpectedSegmentParameter>
            {
                new Assertions.ExpectedSegmentParameter {
                    segmentName = "ExternalTransaction/[^/]+/[^/]+/WebTransaction/MVC/DefaultController/Index", IsRegexSegmentName = true, parameterName = "transaction_guid"
                }
            };

            NrAssert.Multiple(
                () => Assert.Equal(crossProcessId, catResponseData.CrossProcessId),
                () => Assert.Equal("WebTransaction/MVC/DefaultController/ChainedHttpClient", catResponseData.TransactionName),
                () => Assert.True(catResponseData.QueueTimeInSeconds >= 0),
                () => Assert.True(catResponseData.ResponseTimeInSeconds >= 0),
                () => Assert.Equal(-1, catResponseData.ContentLength),
                () => Assert.NotNull(catResponseData.TransactionGuid),
                () => Assert.False(catResponseData.Unused),

                () => Assertions.MetricsExist(expectedMetrics, metrics),
                () => Assertions.MetricsDoNotExist(unexpectedMetrics, metrics),

                // Note: It is difficult (perhaps impossible) to ensure that a transaction trace is generate for the chained request. This is because only one transaction trace is collected per harvest, and the chained requests will both be eligible.

                // calleeTransactionEvent attributes
                () => Assertions.TransactionEventHasAttributes(expectedTransactionEventIntrinsicAttributes1, TransactionEventAttributeType.Intrinsic, calleeTransactionEvent),
                () => Assertions.TransactionEventHasAttributes(expectedTransactionEventIntrinsicAttributes2, TransactionEventAttributeType.Intrinsic, calleeTransactionEvent),

                // callerTransactionTrace segments
                () => Assertions.TransactionTraceSegmentParametersExist(expectedCallerTraceSegmentParameters, callerTransactionTrace)
                );
        }
Ejemplo n.º 13
0
 private string GetXNewRelicRequestData(CrossApplicationRequestData requestData)
 {
     return(HeaderEncoder.SerializeAndEncode(requestData, HeaderEncoder.IntegrationTestEncodingKey));
 }
        public void Test()
        {
            var catResponseHeader = _responseHeaders.GetValues(@"X-NewRelic-App-Data")?.FirstOrDefault();

            Assert.NotNull(catResponseHeader);

            var catResponseData = HeaderEncoder.DecodeAndDeserialize <CrossApplicationResponseData>(catResponseHeader, HeaderEncoder.IntegrationTestEncodingKey);

            var metrics = _fixture.AgentLog.GetMetrics().ToList();
            var calleeTransactionEvent = _fixture.AgentLog.TryGetTransactionEvent("WebTransaction/MVC/RestSharpController/TaskResultClient");

            Assert.NotNull(calleeTransactionEvent);

            var myHostname = _fixture.DestinationServerName;

            var crossProcessId = _fixture.AgentLog.GetCrossProcessId();

            // Note: we are checking the metrics that are generated by the *Caller* as a result of receiving a CAT response.
            var expectedMetrics = new List <Assertions.ExpectedMetric>
            {
                new Assertions.ExpectedMetric {
                    metricName = @"External/all", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"External/allWeb", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = $@"External/{myHostname}/all", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = $@"ExternalApp/{myHostname}/{crossProcessId}/all", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = $@"ExternalTransaction/{myHostname}/{crossProcessId}/WebTransaction/WebAPI/RestAPI/Get", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = $@"ExternalTransaction/{myHostname}/{crossProcessId}/WebTransaction/WebAPI/RestAPI/Get", metricScope = @"WebTransaction/MVC/RestSharpController/TaskResultClient", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = $@"External/{myHostname}/Stream/GET", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"ClientApplication/[^/]+/all", IsRegexName = true
                }
            };

            var unexpectedMetrics = new List <Assertions.ExpectedMetric>
            {
                // This scoped metric should be superceded by the ExternalTransaction metric above
                new Assertions.ExpectedMetric {
                    metricName = $@"External/{_fixture.RemoteApplication.DestinationServerName}/Stream/GET", metricScope = @"WebTransaction/MVC/RestSharpController/TaskResultClient"
                }
            };

            // Note: we are checking the attributes attached to the *Callee's* transaction, not the caller's transaction. The attributes attached to the caller's transaction are already fully vetted in the CatInbound tests.
            var expectedTransactionEventIntrinsicAttributes1 = new List <string>
            {
                "nr.guid",
                "nr.pathHash",
                "nr.referringPathHash",
                "nr.referringTransactionGuid"
            };
            var expectedTransactionEventIntrinsicAttributes2 = new Dictionary <string, string>
            {
                // This value comes from what we send to the application (see parameter passed to GetWithCatHeader above)
                { "nr.tripId", "tripId" }
            };

            var transactionSample = _fixture.AgentLog.GetTransactionSamples()
                                    .Where(sample => sample.Path == @"WebTransaction/MVC/RestSharpController/TaskResultClient" || sample.Path == @"WebTransaction/WebAPI/RestAPI/Get")
                                    .FirstOrDefault();

            Assert.NotNull(transactionSample);


            NrAssert.Multiple(
                () => Assert.Equal(crossProcessId, catResponseData.CrossProcessId),
                () => Assert.Equal("WebTransaction/MVC/RestSharpController/TaskResultClient", catResponseData.TransactionName),
                () => Assert.True(catResponseData.QueueTimeInSeconds >= 0),
                () => Assert.True(catResponseData.ResponseTimeInSeconds >= 0),
                () => Assert.Equal(-1, catResponseData.ContentLength),
                () => Assert.NotNull(catResponseData.TransactionGuid),
                () => Assert.False(catResponseData.Unused),

                () => Assertions.MetricsExist(expectedMetrics, metrics),
                () => Assertions.MetricsDoNotExist(unexpectedMetrics, metrics),

                // calleeTransactionEvent attributes
                () => Assertions.TransactionEventHasAttributes(expectedTransactionEventIntrinsicAttributes1, TransactionEventAttributeType.Intrinsic, calleeTransactionEvent),
                () => Assertions.TransactionEventHasAttributes(expectedTransactionEventIntrinsicAttributes2, TransactionEventAttributeType.Intrinsic, calleeTransactionEvent)
                );
        }
Ejemplo n.º 15
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)
                );
        }
Ejemplo n.º 16
0
 /// <summary> Writes the header data to the bit stream, if it has not been already
 /// done. In some implementations this method can be called only once, and
 /// an IllegalArgumentException is thrown if called more than once.
 ///
 /// </summary>
 /// <exception cref="IOException">If an I/O error occurs while writing the data.
 ///
 /// </exception>
 /// <exception cref="IllegalArgumentException">If this method has already been
 /// called.
 ///
 /// </exception>
 public abstract void commitBitstreamHeader(HeaderEncoder he);
Ejemplo n.º 17
0
        public void Test()
        {
            var catResponseHeader = _responseHeaders.GetValues(@"X-NewRelic-App-Data")?.FirstOrDefault();

            Assert.NotNull(catResponseHeader);

            var catResponseData = HeaderEncoder.DecodeAndDeserialize <CrossApplicationResponseData>(catResponseHeader, HeaderEncoder.IntegrationTestEncodingKey);

            var transactionSample = _fixture.AgentLog.TryGetTransactionSample("WebTransaction/MVC/DefaultController/Index");
            var transactionEvent  = _fixture.AgentLog.TryGetTransactionEvent("WebTransaction/MVC/DefaultController/Index");
            var metrics           = _fixture.AgentLog.GetMetrics();

            NrAssert.Multiple
            (
                () => Assert.NotNull(transactionSample),
                () => Assert.NotNull(transactionEvent)
            );

            var expectedTransactionTraceIntrinsicAttributes1 = new List <string>
            {
                "client_cross_process_id",
                "path_hash"
            };
            var expectedTransactionTraceIntrinsicAttributes2 = new Dictionary <string, string>
            {
                // These values come from what we send to the application (see parameter passed to GetWithCatHeader above)
                { "referring_transaction_guid", "guid" },
                { "trip_id", "tripId" }
            };
            var expectedTransactionEventIntrinsicAttributes1 = new List <string>
            {
                "nr.guid",
                "nr.pathHash"
            };
            var expectedTransactionEventIntrinsicAttributes2 = new Dictionary <string, string>
            {
                // These values come from what we send to the application (see parameter passed to GetWithCatHeader above)
                { "nr.referringPathHash", "pathHash" },
                { "nr.referringTransactionGuid", "guid" },
                { "nr.tripId", "tripId" }
            };

            NrAssert.Multiple
            (
                () => Assert.Equal(_fixture.AgentLog.GetCrossProcessId(), catResponseData.CrossProcessId),
                () => Assert.Equal("WebTransaction/MVC/DefaultController/Index", catResponseData.TransactionName),
                () => Assert.True(catResponseData.QueueTimeInSeconds >= 0),
                () => Assert.True(catResponseData.ResponseTimeInSeconds >= 0),
                () => Assert.Equal(-1, catResponseData.ContentLength),
                () => Assert.NotNull(catResponseData.TransactionGuid),
                () => Assert.False(catResponseData.Unused),

                // Trace attributes
                () => Assertions.TransactionTraceHasAttributes(expectedTransactionTraceIntrinsicAttributes1, TransactionTraceAttributeType.Intrinsic, transactionSample),
                () => Assertions.TransactionTraceHasAttributes(expectedTransactionTraceIntrinsicAttributes2, TransactionTraceAttributeType.Intrinsic, transactionSample),

                // Event attributes
                () => Assertions.TransactionEventHasAttributes(expectedTransactionEventIntrinsicAttributes1, TransactionEventAttributeType.Intrinsic, transactionEvent),
                () => Assertions.TransactionEventHasAttributes(expectedTransactionEventIntrinsicAttributes2, TransactionEventAttributeType.Intrinsic, transactionEvent),

                () => Assertions.MetricsExist(Expectations.ExpectedMetricsCatEnabled, metrics)
            );
        }