Exemplo n.º 1
0
        private void ValidateIntrinsics(DistributedTraceTestData testData)
        {
            foreach (var eventType in testData.IntrinsicSettings.TargetEvents)
            {
                switch (eventType)
                {
                case "Transaction":
                    var transactionEvent = _compositeTestAgent.TransactionEvents.First();
                    ValidateAttributes(transactionEvent.IntrinsicAttributes(), testData, testData.IntrinsicSettings.Events?["Transaction"]);
                    break;

                case "Span":
                    Assert.That(_compositeTestAgent.SpanEvents.Count, Is.EqualTo(2));       // fake parent and first segment
                    var spanEvent = _compositeTestAgent.SpanEvents.First();
                    ValidateAttributes(spanEvent.IntrinsicAttributes(), testData, testData.IntrinsicSettings.Events?["Span"]);
                    break;

                case "Error":
                    var errorEvent = _compositeTestAgent.ErrorEvents.First();
                    ValidateAttributes(errorEvent.IntrinsicAttributes(), testData, testData.IntrinsicSettings.Events?["Error"]);
                    break;

                default:
                    break;
                }
            }
        }
Exemplo n.º 2
0
        void MakeTransaction(DistributedTraceTestData testData)
        {
            var testDataInboundPayloads = MakeHeaders(testData);

            var transaction = _agent.CreateTransaction(
                isWeb: testData.WebTransaction,
                category: testData.WebTransaction ? "Action" : "Other",
                transactionDisplayName: "name",
                doNotTrackAsUnitOfWork: true);

            AcceptPayloads(testDataInboundPayloads, testData);

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

            if (testData.RaisesException)
            {
                transaction.NoticeError(new Exception("This is a new exception."));
            }

            testData.OutboundPayloadsSettings?.ForEach(payloadSettings =>
            {
                var payload = _agent.CurrentTransaction.CreateDistributedTracePayload();

                if (testData.OutboundPayloadsSettings != null)
                {
                    ValidateOutboundPayload(payloadSettings, payload.Text());
                }
            });
            segment.End();
            transaction.End();
        }
Exemplo n.º 3
0
        public void DistributedTrace_CrossAgentTests(DistributedTraceTestData testData)
        {
            InitializeSettings(testData);

            MakeTransaction(testData);

            _compositeTestAgent.Harvest();

            ValidateIntrinsics(testData);

            ValidateMetrics(testData);
        }
Exemplo n.º 4
0
        private void AcceptPayloads(List <string> testDataInboundPayloads, DistributedTraceTestData testData)
        {
            testDataInboundPayloads.ForEach(serializedPayload =>
            {
                var validEnumValue = Enum.TryParse(testData.TransportType, ignoreCase: false, result: out TransportType transportType);
                if (!validEnumValue)
                {
                    transportType = (TransportType)(-1);
                }

                _agent.CurrentTransaction.AcceptDistributedTracePayload(serializedPayload, transportType);
            });
        }
Exemplo n.º 5
0
        private void ValidateMetrics(DistributedTraceTestData testData)
        {
            var expectedMetrics = new List <ExpectedMetric>();

            // convert json ExpectedMetrics for CompositeTests.MetricAssertions
            foreach (var metric in testData.ExpectedMetrics)
            {
                expectedMetrics.Add(new ExpectedTimeMetric()
                {
                    Name = metric.Name, CallCount = metric.Count
                });
            }

            MetricAssertions.MetricsExist(expectedMetrics, _compositeTestAgent.Metrics);
        }
Exemplo n.º 6
0
        List <string> MakeHeaders(DistributedTraceTestData testData)
        {
            List <string> testDataInboundPayloads = new List <string>();

            if (testData.InboundPayloadSettings == null)
            {
                testDataInboundPayloads.Add(null);
            }
            else
            {
                foreach (PayloadSettings payload in testData.InboundPayloadSettings)
                {
                    testDataInboundPayloads.Add(Strings.Base64Encode(JsonConvert.SerializeObject(payload)));
                }
            }

            return(testDataInboundPayloads);
        }
Exemplo n.º 7
0
        private static void InitializeSettings(DistributedTraceTestData testData)
        {
            Assert.That(testData.MajorVersionSupported, Is.GreaterThanOrEqualTo(DistributedTracePayload.SupportedMajorVersion));
            Assert.That(testData.MinorVersionSupported, Is.GreaterThanOrEqualTo(DistributedTracePayload.SupportedMinorVersion));

            if (testData.ForceSampledTrue)
            {
                var priority = 1.0f;
                Mock.Arrange(() => _adaptiveSampler.ComputeSampled(ref priority)).IgnoreArguments().Returns(true);
            }

            _compositeTestAgent.LocalConfiguration.spanEvents.enabled    = testData.SpanEventsEnabled;
            _compositeTestAgent.ServerConfiguration.TrustedAccountKey    = testData.TrustedAccountKey;
            _compositeTestAgent.ServerConfiguration.AccountId            = testData.AccountId;
            _compositeTestAgent.ServerConfiguration.PrimaryApplicationId = "primaryApplicationId";

            _compositeTestAgent.PushConfiguration();
            //SpanEvents were not enabled when the aggregators were first started so we need to start them here.
            EventBus <AgentConnectedEvent> .Publish(new AgentConnectedEvent());
        }
Exemplo n.º 8
0
        private void ValidateAttributes(IDictionary <string, object> actualAttributes, DistributedTraceTestData testData, JToken eventSpecificAttributes = null)
        {
            // Common (for all target_events)
            ValidateAttributeSettings(testData.IntrinsicSettings.CommonAttributes, actualAttributes);

            // event-specific attrs
            ValidateAttributeSettings(eventSpecificAttributes?.ToObject <AttributesSettings>(), actualAttributes);
        }