public void SpansAttributes()
        {
            foreach (var span in SenderAppSpanEvents)
            {
                Assert.Equal(TestTraceId, span.IntrinsicAttributes["traceId"]);
                Assert.True(AttributeComparer.IsEqualTo(SenderAppTxEvent.IntrinsicAttributes["priority"], span.IntrinsicAttributes["priority"]));
            }

            foreach (var span in ReceiverAppSpanEvents)
            {
                Assert.Equal(TestTraceId, span.IntrinsicAttributes["traceId"]);
                Assert.True(AttributeComparer.IsEqualTo(SenderAppTxEvent.IntrinsicAttributes["priority"], span.IntrinsicAttributes["priority"]));
            }
        }
        public void Test()
        {
            // attributes

            var headerValueTx = _fixture.AgentLog.TryGetTransactionEvent("WebTransaction/MVC/RabbitMQController/RabbitMQ_SendReceive_HeaderValue");

            var spanEvents = _fixture.AgentLog.GetSpanEvents();

            var produceSpan = spanEvents.Where(@event => @event.IntrinsicAttributes["name"].ToString().Contains("MessageBroker/RabbitMQ/Queue/Produce/Named/"))
                              .FirstOrDefault();

            var consumeSpan = spanEvents.Where(@event => @event.IntrinsicAttributes["name"].ToString().Contains("MessageBroker/RabbitMQ/Queue/Consume/Named/"))
                              .FirstOrDefault();

            Assert.Equal(headerValueTx.IntrinsicAttributes["guid"], produceSpan.IntrinsicAttributes["transactionId"]);
            Assert.Equal(headerValueTx.IntrinsicAttributes["traceId"], produceSpan.IntrinsicAttributes["traceId"]);
            Assert.True(AttributeComparer.IsEqualTo(headerValueTx.IntrinsicAttributes["priority"], produceSpan.IntrinsicAttributes["priority"]),
                        $"priority: expected: {headerValueTx.IntrinsicAttributes["priority"]}, actual: {produceSpan.IntrinsicAttributes["priority"]}");

            Assert.Equal(headerValueTx.IntrinsicAttributes["guid"], consumeSpan.IntrinsicAttributes["transactionId"]);
            Assert.Equal(headerValueTx.IntrinsicAttributes["traceId"], consumeSpan.IntrinsicAttributes["traceId"]);
            Assert.True(AttributeComparer.IsEqualTo(headerValueTx.IntrinsicAttributes["priority"], consumeSpan.IntrinsicAttributes["priority"]),
                        $"priority: expected: {headerValueTx.IntrinsicAttributes["priority"]}, actual: {consumeSpan.IntrinsicAttributes["priority"]}");

            // metrics

            var expectedMetrics = new List <Assertions.ExpectedMetric>
            {
                new Assertions.ExpectedMetric {
                    metricName = $"Supportability/DistributedTrace/CreatePayload/Success", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = $"Supportability/TraceContext/Create/Success", callCount = 1
                },
            };

            var metrics = _fixture.AgentLog.GetMetrics();

            Assertions.MetricsExist(expectedMetrics, metrics);
        }
Exemplo n.º 3
0
        private static void TestPayloadInfoMatchesSpanInfo(DistributedTracePayload payload, ISpanEventWireModel rootSpan, ISpanEventWireModel actualSpan)
        {
            Assert.NotNull(rootSpan);

            var rootSpanIntrinsicAttributes = rootSpan.IntrinsicAttributes();

            Assert.IsTrue(AttributeComparer.IsEqualTo(payload.TraceId, rootSpanIntrinsicAttributes["traceId"]));
            Assert.IsTrue(AttributeComparer.IsEqualTo(payload.Priority, rootSpanIntrinsicAttributes["priority"]));
            Assert.IsTrue(AttributeComparer.IsEqualTo(payload.Sampled, rootSpanIntrinsicAttributes["sampled"]));
            Assert.IsTrue(AttributeComparer.IsEqualTo(payload.Guid, rootSpanIntrinsicAttributes["parentId"]));
            Assert.IsTrue(AttributeComparer.IsEqualTo("generic", rootSpanIntrinsicAttributes["category"]));
            Assert.IsTrue(AttributeComparer.IsEqualTo(true, rootSpanIntrinsicAttributes["nr.entryPoint"]));

            Assert.NotNull(actualSpan);

            var actualSpanIntrinsicAttributes = actualSpan.IntrinsicAttributes();

            Assert.IsTrue(AttributeComparer.IsEqualTo(payload.TraceId, actualSpanIntrinsicAttributes["traceId"]));
            Assert.IsTrue(AttributeComparer.IsEqualTo(payload.Priority, actualSpanIntrinsicAttributes["priority"]));
            Assert.IsTrue(AttributeComparer.IsEqualTo(payload.Sampled, actualSpanIntrinsicAttributes["sampled"]));
            Assert.IsTrue(AttributeComparer.IsEqualTo(rootSpanIntrinsicAttributes["guid"], actualSpanIntrinsicAttributes["parentId"]));
            Assert.IsTrue(AttributeComparer.IsEqualTo(rootSpanIntrinsicAttributes["transactionId"], actualSpanIntrinsicAttributes["transactionId"]));
            Assert.IsTrue(AttributeComparer.IsEqualTo("datastore", actualSpanIntrinsicAttributes["category"]));
        }
        private void ValidateAttributeSettings(AttributesSettings testDataAttributesSettings, IDictionary <string, object> actualEventAttributes)
        {
            testDataAttributesSettings?.Exact?.Keys.ToList().ForEach(attr =>
            {
                Assert.That(actualEventAttributes.ContainsKey(attr), $"Exact attribute not present: {attr}");
                testDataAttributesSettings.Exact.TryGetValue(attr, out var expectedValue);

                var attrValue          = actualEventAttributes[attr];
                var attrType           = attrValue.GetType();
                var typedExpectedValue = Convert.ChangeType(expectedValue, attrType);

                Assert.That(AttributeComparer.IsEqualTo(typedExpectedValue, attrValue), $"{attr}, expected: {typedExpectedValue}, actual: {attrValue}");
            });

            testDataAttributesSettings?.Expected?.ToList().ForEach(attr =>
            {
                Assert.That(actualEventAttributes.ContainsKey(attr), $"{attr}");
            });

            testDataAttributesSettings?.Unexpected?.ToList().ForEach(attr =>
            {
                Assert.That(!actualEventAttributes.ContainsKey(attr), $"{attr}");
            });
        }
        public void Test()
        {
            var senderAppTxEvent = _fixture.FirstCallApplication.AgentLog.GetTransactionEvents().FirstOrDefault();

            Assert.NotNull(senderAppTxEvent);

            var receiverAppTxEvents = _fixture.SecondCallApplication.AgentLog.GetTransactionEvents().FirstOrDefault();

            Assert.NotNull(receiverAppTxEvents);

            var senderAppSpanEvents   = _fixture.FirstCallApplication.AgentLog.GetSpanEvents();
            var receiverAppSpanEvents = _fixture.SecondCallApplication.AgentLog.GetSpanEvents();

            Assert.Equal(senderAppTxEvent.IntrinsicAttributes["guid"], receiverAppTxEvents.IntrinsicAttributes["parentId"]);

            foreach (var span in senderAppSpanEvents)
            {
                Assert.Equal(TestTraceId, span.IntrinsicAttributes["traceId"]);
            }

            foreach (var span in receiverAppSpanEvents)
            {
                Assert.Equal(TestTraceId, span.IntrinsicAttributes["traceId"]);
            }

            var senderRootSpanEvent = senderAppSpanEvents.Where(@event => @event?.IntrinsicAttributes?["name"]?.ToString() == "WebTransaction/MVC/FirstCall/WebRequestCallNext/{nextUrl}").FirstOrDefault();
            var externalSpanEvent   = senderAppSpanEvents.Where(@event => @event?.IntrinsicAttributes?["name"]?.ToString() == "External/localhost/Stream/GET").FirstOrDefault();

            var receiverRootSpanEvent = receiverAppSpanEvents.Where(@event => @event?.IntrinsicAttributes?["name"]?.ToString() == "WebTransaction/MVC/SecondCall/WebRequestCallNext/{nextUrl}").FirstOrDefault();

            Assert.NotNull(senderRootSpanEvent);
            Assert.Equal(TestTracingVendors, senderRootSpanEvent.IntrinsicAttributes["tracingVendors"]);
            Assert.Equal(TestTraceParent, senderRootSpanEvent.IntrinsicAttributes["parentId"]);
            Assert.False(senderRootSpanEvent.IntrinsicAttributes.ContainsKey("trustedParentId"));

            Assert.NotNull(receiverRootSpanEvent);
            Assert.Equal(TestTracingVendors, receiverRootSpanEvent.IntrinsicAttributes["tracingVendors"]);
            Assert.Equal(externalSpanEvent.IntrinsicAttributes["guid"], receiverRootSpanEvent.IntrinsicAttributes["parentId"]);
            Assert.Equal(externalSpanEvent.IntrinsicAttributes["guid"], receiverAppTxEvents.IntrinsicAttributes["parentSpanId"]);
            Assert.Equal(externalSpanEvent.IntrinsicAttributes["guid"], receiverRootSpanEvent.IntrinsicAttributes["trustedParentId"]);
            Assert.True(AttributeComparer.IsEqualTo(senderAppTxEvent.IntrinsicAttributes["priority"], receiverRootSpanEvent.IntrinsicAttributes["priority"]));

            var senderExpectedMetrics = new List <Assertions.ExpectedMetric>
            {
                new Assertions.ExpectedMetric {
                    metricName = @"Supportability/DistributedTrace/CreatePayload/Success", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"Supportability/TraceContext/Accept/Success", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"Supportability/TraceContext/Create/Success", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"Supportability/TraceContext/TraceState/NoNrEntry", callCount = 1
                }
            };

            var accountId = _fixture.SecondCallApplication.AgentLog.GetAccountId();
            var appId     = _fixture.SecondCallApplication.AgentLog.GetApplicationId();

            var receiverExpectedMetrics = new List <Assertions.ExpectedMetric>
            {
                new Assertions.ExpectedMetric {
                    metricName = @"Supportability/TraceContext/Accept/Success", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"Supportability/TraceContext/Create/Success", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = $@"DurationByCaller/App/{accountId}/{appId}/HTTP/all", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = $@"DurationByCaller/App/{accountId}/{appId}/HTTP/allWeb", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = $@"TransportDuration/App/{accountId}/{appId}/HTTP/all", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = $@"TransportDuration/App/{accountId}/{appId}/HTTP/allWeb", callCount = 1
                }
            };

            var receiverUnexpectedMetrics = new List <Assertions.ExpectedMetric>
            {
                new Assertions.ExpectedMetric {
                    metricName = @"Supportability/TraceContext/TraceState/NoNrEntry", callCount = 1
                }
            };

            var senderActualMetrics   = _fixture.FirstCallApplication.AgentLog.GetMetrics();
            var receiverActualMetrics = _fixture.SecondCallApplication.AgentLog.GetMetrics();

            NrAssert.Multiple(
                () => Assertions.MetricsExist(senderExpectedMetrics, senderActualMetrics),
                () => Assertions.MetricsExist(receiverExpectedMetrics, receiverActualMetrics),
                () => Assertions.MetricsDoNotExist(receiverUnexpectedMetrics, receiverActualMetrics)
                );
        }
        public void Test()
        {
            // transaction attributes

            var produceTx = _fixture.AgentLog.TryGetTransactionEvent("WebTransaction/MVC/RabbitMQController/RabbitMQ_SendReceiveWithEventingConsumer");
            var consumeTx = _fixture.AgentLog.TryGetTransactionEvent($"OtherTransaction/Message/RabbitMQ/Queue/Named/{_queueName}");

            Assert.Equal(consumeTx.IntrinsicAttributes["traceId"], produceTx.IntrinsicAttributes["traceId"]);
            Assert.True(AttributeComparer.IsEqualTo(produceTx.IntrinsicAttributes["priority"], consumeTx.IntrinsicAttributes["priority"]),
                        $"priority: expected: {produceTx.IntrinsicAttributes["priority"]}, actual: {consumeTx.IntrinsicAttributes["priority"]}");
            Assert.Equal(consumeTx.IntrinsicAttributes["parentId"], produceTx.IntrinsicAttributes["guid"]);
            Assert.Equal("AMQP", consumeTx.IntrinsicAttributes["parent.transportType"]);

            // span attributes

            _fixture.AgentLog.GetSpanEvents().ToList().ForEach
                (span =>
            {
                Assert.Equal(produceTx.IntrinsicAttributes["traceId"], span.IntrinsicAttributes["traceId"]);
                Assert.True(AttributeComparer.IsEqualTo(produceTx.IntrinsicAttributes["priority"], span.IntrinsicAttributes["priority"]),
                            $"priority: expected: {produceTx.IntrinsicAttributes["priority"]}, actual: {span.IntrinsicAttributes["priority"]}");
            });

            var produceSpan = _fixture.AgentLog.TryGetSpanEvent($"MessageBroker/RabbitMQ/Queue/Produce/Named/{_queueName}");
            var consumeSpan = _fixture.AgentLog.TryGetSpanEvent($"MessageBroker/RabbitMQ/Queue/Consume/Named/{_queueName}");

            Assert.Equal(produceTx.IntrinsicAttributes["guid"], produceSpan.IntrinsicAttributes["transactionId"]);
            Assert.Equal(consumeTx.IntrinsicAttributes["guid"], consumeSpan.IntrinsicAttributes["transactionId"]);

            Assert.Equal(consumeTx.IntrinsicAttributes["parentSpanId"], produceSpan.IntrinsicAttributes["guid"]);

            // metrics
            var acctId = _fixture.AgentLog.GetAccountId();
            var appId  = _fixture.AgentLog.GetApplicationId();

            var expectedMetrics = new List <Assertions.ExpectedMetric>
            {
                new Assertions.ExpectedMetric {
                    metricName = $"DurationByCaller/App/{acctId}/{appId}/AMQP/all", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = $"DurationByCaller/App/{acctId}/{appId}/AMQP/allOther", callCount = 1
                },

                new Assertions.ExpectedMetric {
                    metricName = $"TransportDuration/App/{acctId}/{appId}/AMQP/all", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = $"TransportDuration/App/{acctId}/{appId}/AMQP/allOther", callCount = 1
                },

                new Assertions.ExpectedMetric {
                    metricName = $"Supportability/DistributedTrace/CreatePayload/Success", callCount = 2
                },
                new Assertions.ExpectedMetric {
                    metricName = $"Supportability/TraceContext/Create/Success", callCount = 2
                },
                new Assertions.ExpectedMetric {
                    metricName = $"Supportability/TraceContext/Accept/Success", callCount = 2
                }
            };

            var metrics = _fixture.AgentLog.GetMetrics();

            Assertions.MetricsExist(expectedMetrics, metrics);
        }