Esempio n. 1
0
        public void apdexPerfZone_tolerating_if_time_is_more_than_apdexT_but_less_than_four_times_apdexT()
        {
            // ARRANGE
            var apdexT = TimeSpan.FromMilliseconds(20);

            _compositeTestAgent.ServerConfiguration.ApdexT = apdexT.TotalSeconds;
            _compositeTestAgent.PushConfiguration();

            // ==== ACT ====
            var tx = _agent.CreateTransaction(
                isWeb: true,
                category: EnumNameCache <WebTransactionType> .GetName(WebTransactionType.Action),
                transactionDisplayName: "name",
                doNotTrackAsUnitOfWork: true);
            var segment = _agent.StartTransactionSegmentOrThrow("segmentName");

            Thread.Sleep(apdexT.Multiply(2));
            segment.End();
            tx.End();
            _compositeTestAgent.Harvest();
            // ==== ACT ====

            // ASSERT
            var expectedEventAttributes = new List <ExpectedAttribute>
            {
                new ExpectedAttribute {
                    Key = "nr.apdexPerfZone", Value = "T"
                }
            };
            var transactionEvent = _compositeTestAgent.TransactionEvents.First();

            TransactionEventAssertions.HasAttributes(expectedEventAttributes, AttributeClassification.Intrinsics, transactionEvent);
        }
Esempio n. 2
0
        public void synthetics_attributes_when_no_header_is_present()
        {
            // ARRANGE
            var encodingKey = "foo";

            _compositeTestAgent.ServerConfiguration.TrustedIds  = new long[] { 123 };
            _compositeTestAgent.ServerConfiguration.EncodingKey = encodingKey;
            _compositeTestAgent.PushConfiguration();


            // ==== ACT ====
            var tx = _agent.CreateTransaction(
                isWeb: true,
                category: EnumNameCache <WebTransactionType> .GetName(WebTransactionType.Action),
                transactionDisplayName: "name",
                doNotTrackAsUnitOfWork: true);

            _agent.CurrentTransaction.AcceptDistributedTraceHeaders(new KeyValuePair <string, string> [0], HeaderFunctions.GetHeaders, TransportType.HTTP);

            var segment = _agent.StartTransactionSegmentOrThrow("segmentName");

            segment.End();
            tx.End();
            _compositeTestAgent.Harvest();

            // ASSERT
            var unexpectedEventAttributes = new List <string>
            {
                "nr.guid",
                "nr.syntheticsResourceId",
                "nr.syntheticsJobId",
                "nr.syntheticsMonitorId"
            };
            var unexpectedTraceAttributes = new List <string>
            {
                "synthetics_resource_id",
                "synthetics_job_id",
                "synthetics_monitor_id"
            };
            var transactionEvent = _compositeTestAgent.TransactionEvents.First();
            var transactionTrace = _compositeTestAgent.TransactionTraces.First();

            NrAssert.Multiple(
                () => TransactionEventAssertions.DoesNotHaveAttributes(unexpectedEventAttributes, AttributeClassification.Intrinsics, transactionEvent),
                () => TransactionTraceAssertions.DoesNotHaveAttributes(unexpectedTraceAttributes, AttributeClassification.Intrinsics, transactionTrace)
                );
        }
        public void cat_attributes_when_no_headers_are_provided()
        {
            // ARRANGE
            var encodingKey = "foo";

            _compositeTestAgent.ServerConfiguration.TrustedIds  = new long[] { 123 };
            _compositeTestAgent.ServerConfiguration.EncodingKey = encodingKey;
            _compositeTestAgent.PushConfiguration();


            // ==== ACT ====
            var tx = _agent.CreateTransaction(
                isWeb: true,
                category: EnumNameCache <WebTransactionType> .GetName(WebTransactionType.Action),
                transactionDisplayName: "name",
                doNotTrackAsUnitOfWork: true);
            var segment = _agent.StartTransactionSegmentOrThrow("segmentName");

            segment.End();
            tx.End();
            _compositeTestAgent.Harvest();

            // ASSERT
            var unexpectedEventAttributes = new List <string>
            {
                "nr.referringPathHash",
                "nr.referringTransactionGuid",
                "nr.alternatePathHashes",
                "nr.guid",
                "nr.pathHash"
            };
            var unexpectedTraceAttributes = new List <string>
            {
                "client_cross_process_id",
                "referring_transaction_guid",
                "path_hash"
            };
            var transactionEvent = _compositeTestAgent.TransactionEvents.First();
            var transactionTrace = _compositeTestAgent.TransactionTraces.First();

            NrAssert.Multiple(
                () => TransactionEventAssertions.DoesNotHaveAttributes(unexpectedEventAttributes, AttributeClassification.Intrinsics, transactionEvent),
                () => TransactionTraceAssertions.DoesNotHaveAttributes(unexpectedTraceAttributes, AttributeClassification.Intrinsics, transactionTrace)
                );
        }
Esempio n. 4
0
        public void keyTransaction_apdexPerfZone_frustrating_if_time_is_more_than_four_times_keyTransaction_apdexT()
        {
            // ARRANGE
            // config apdexT
            var serverApdexT = TimeSpan.FromMilliseconds(100);

            _compositeTestAgent.ServerConfiguration.ApdexT = serverApdexT.TotalSeconds;

            // key transaction apdexT
            var keyTransactionApdexT = TimeSpan.FromMilliseconds(1);

            _compositeTestAgent.ServerConfiguration.WebTransactionsApdex = new Dictionary <string, double> {
                { "WebTransaction/Action/name", keyTransactionApdexT.TotalSeconds }
            };

            // push the config
            _compositeTestAgent.PushConfiguration();

            // ==== ACT ====
            var tx = _agent.CreateTransaction(
                isWeb: true,
                category: EnumNameCache <WebTransactionType> .GetName(WebTransactionType.Action),
                transactionDisplayName: "name",
                doNotTrackAsUnitOfWork: true);
            var segment = _agent.StartTransactionSegmentOrThrow("segmentName");

            Thread.Sleep(keyTransactionApdexT.Multiply(5));
            segment.End();
            tx.End();

            _compositeTestAgent.Harvest();
            // ==== ACT ====

            // ASSERT
            var expectedEventAttributes = new List <ExpectedAttribute>
            {
                new ExpectedAttribute {
                    Key = "nr.apdexPerfZone", Value = "F"
                }
            };
            var transactionEvent = _compositeTestAgent.TransactionEvents.First();

            TransactionEventAssertions.HasAttributes(expectedEventAttributes, AttributeClassification.Intrinsics, transactionEvent);
        }
Esempio n. 5
0
        public void ShouldNotAcceptStringDistributedTracePayloadWhenDTNotEnabled()
        {
            _compositeTestAgent.LocalConfiguration.distributedTracing.enabled = false;
            _compositeTestAgent.PushConfiguration();

            var agentWrapperApi = _compositeTestAgent.GetAgent();
            var transaction     = agentWrapperApi.CreateTransaction(
                isWeb: true,
                category: EnumNameCache <WebTransactionType> .GetName(WebTransactionType.ASP),
                transactionDisplayName: "TransactionName",
                doNotTrackAsUnitOfWork: true);
            var transactionBridgeApi = new TransactionBridgeApi(transaction, _apiSupportabilityMetricCounters, _configSvc);

            var segment = agentWrapperApi.StartTransactionSegmentOrThrow("segment");

            transactionBridgeApi.AcceptDistributedTracePayload(_distributedTracePayload.ToJson(), 0 /*Unknown TransportType see Agent\NewRelic.Api.Agent\TransportType.cs for more info*/);

            segment.End();
            transaction.End();

            _compositeTestAgent.Harvest();

            var transactionEvent = _compositeTestAgent.TransactionEvents.First();

            var expectedMissingAttributes = new[]
            {
                "traceId",
                "parent.type",
                "parent.app",
                "parent.account",
                "parent.transportType",
                "parent.TransportDuration",
                "parentId",
                "priority",
                "sampled"
            };

            TransactionEventAssertions.DoesNotHaveAttributes(expectedMissingAttributes, AttributeClassification.Intrinsics, transactionEvent);
        }
Esempio n. 6
0
        public void synthetics_attributes_when_header_is_present()
        {
            // ARRANGE
            var encodingKey     = "foo";
            var version         = 1;
            var clientAccountId = 123;
            var resourceId      = "resourceId";
            var jobId           = "jobId";
            var monitorId       = "monitorId";

            _compositeTestAgent.ServerConfiguration.TrustedIds  = new long[] { clientAccountId };
            _compositeTestAgent.ServerConfiguration.EncodingKey = encodingKey;
            _compositeTestAgent.PushConfiguration();

            var syntheticsHeaderValue = Strings.Base64Encode(
                string.Format(@"[{0}, {1}, ""{2}"", ""{3}"", ""{4}""]", version, clientAccountId, resourceId, jobId,
                              monitorId), encodingKey);
            var requestHeaders = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>(SyntheticsHeaderKey, syntheticsHeaderValue)
            };

            // ==== ACT ====
            var tx = _agent.CreateTransaction(
                isWeb: true,
                category: EnumNameCache <WebTransactionType> .GetName(WebTransactionType.Action),
                transactionDisplayName: "name",
                doNotTrackAsUnitOfWork: true);

            tx.AcceptDistributedTraceHeaders(requestHeaders, HeaderFunctions.GetHeaders, TransportType.HTTP);

            var segment = _agent.StartTransactionSegmentOrThrow("segmentName");

            segment.End();
            tx.End();
            _compositeTestAgent.Harvest();

            // ASSERT
            var unexpectedEventAttributes = new List <string>
            {
                "nr.alternatePathHashes"
            };
            var expectedEventAttributes = new List <ExpectedAttribute>
            {
                new ExpectedAttribute {
                    Key = "nr.guid"
                },
                new ExpectedAttribute {
                    Key = "nr.syntheticsResourceId", Value = resourceId
                },
                new ExpectedAttribute {
                    Key = "nr.syntheticsJobId", Value = jobId
                },
                new ExpectedAttribute {
                    Key = "nr.syntheticsMonitorId", Value = monitorId
                }
            };
            var expectedTraceAttributes = new List <ExpectedAttribute>
            {
                new ExpectedAttribute {
                    Key = "synthetics_resource_id", Value = resourceId
                },
                new ExpectedAttribute {
                    Key = "synthetics_job_id", Value = jobId
                },
                new ExpectedAttribute {
                    Key = "synthetics_monitor_id", Value = monitorId
                }
            };
            var transactionEvent = _compositeTestAgent.TransactionEvents.First();
            var transactionTrace = _compositeTestAgent.TransactionTraces.First();

            NrAssert.Multiple(
                () =>
                TransactionEventAssertions.HasAttributes(expectedEventAttributes, AttributeClassification.Intrinsics,
                                                         transactionEvent),
                () =>
                TransactionEventAssertions.DoesNotHaveAttributes(unexpectedEventAttributes,
                                                                 AttributeClassification.Intrinsics, transactionEvent),
                () =>
                TransactionTraceAssertions.HasAttributes(expectedTraceAttributes, AttributeClassification.Intrinsics,
                                                         transactionTrace)
                );
        }
        public void cat_attributes_when_header_is_present()
        {
            // ARRANGE
            var encodingKey           = "foo";
            var clientAccountId       = 123;
            var crossProcessId        = $"{clientAccountId}#456";
            var clientTransactionGuid = "transaction guid";
            var clientTripId          = "trip id";
            var clientPathHash        = "path hash";

            _compositeTestAgent.ServerConfiguration.TrustedIds  = new long[] { clientAccountId };
            _compositeTestAgent.ServerConfiguration.EncodingKey = encodingKey;
            _compositeTestAgent.PushConfiguration();

            var newRelicIdHeader          = new KeyValuePair <string, string>("X-NewRelic-ID", Strings.Base64Encode(crossProcessId, encodingKey));
            var newRelicTransactionHeader = new KeyValuePair <string, string>("X-NewRelic-Transaction", Strings.Base64Encode($@"[""{clientTransactionGuid}"", ""{false}"", ""{clientTripId}"", ""{clientPathHash}""]", encodingKey));
            var requestHeaders            = new[] { newRelicIdHeader, newRelicTransactionHeader };

            // ==== ACT ====
            var tx = _agent.CreateTransaction(
                isWeb: true,
                category: EnumNameCache <WebTransactionType> .GetName(WebTransactionType.Action),
                transactionDisplayName: "name",
                doNotTrackAsUnitOfWork: true);

            _agent.CurrentTransaction.AcceptDistributedTraceHeaders(requestHeaders, HeaderFunctions.GetHeaders, TransportType.HTTP);

            var segment = _agent.StartTransactionSegmentOrThrow("segmentName");

            segment.End();
            tx.End();

            _compositeTestAgent.Harvest();

            // ASSERT
            var unexpectedEventAttributes = new List <string>
            {
                "nr.alternatePathHashes"
            };

            var expectedEventAttributes = new List <ExpectedAttribute>
            {
                new ExpectedAttribute {
                    Key = "nr.guid"
                },
                new ExpectedAttribute {
                    Key = "nr.tripId", Value = clientTripId
                },
                new ExpectedAttribute {
                    Key = "nr.pathHash", Value = "b5880367"
                },
                new ExpectedAttribute {
                    Key = "nr.referringTransactionGuid", Value = clientTransactionGuid
                },
                new ExpectedAttribute {
                    Key = "nr.referringPathHash", Value = "path hash"
                }
            };

            var expectedTraceAttributes = new List <ExpectedAttribute>
            {
                new ExpectedAttribute {
                    Key = "client_cross_process_id", Value = crossProcessId
                },
                new ExpectedAttribute {
                    Key = "trip_id", Value = clientTripId
                },
                new ExpectedAttribute {
                    Key = "path_hash", Value = "b5880367"
                },
                new ExpectedAttribute {
                    Key = "referring_transaction_guid", Value = clientTransactionGuid
                },
            };

            var transactionEvent = _compositeTestAgent.TransactionEvents.First();
            var transactionTrace = _compositeTestAgent.TransactionTraces.First();

            NrAssert.Multiple
            (
                () => TransactionEventAssertions.HasAttributes(expectedEventAttributes, AttributeClassification.Intrinsics, transactionEvent),
                () => TransactionEventAssertions.DoesNotHaveAttributes(unexpectedEventAttributes, AttributeClassification.Intrinsics, transactionEvent),
                () => TransactionTraceAssertions.HasAttributes(expectedTraceAttributes, AttributeClassification.Intrinsics, transactionTrace)
            );
        }