コード例 #1
0
        public void Test()
        {
            var metrics = _fixture.AgentLog.GetMetrics().ToList();

            Assert.NotNull(metrics);

            Assertions.MetricsExist(_generalMetrics, metrics);
            Assertions.MetricsDoNotExist(_unexpectedMetrics, metrics);

            NrAssert.Multiple
            (
                () => Assertions.MetricsExist(_indexMetrics, metrics),
                () => Assertions.MetricsExist(_throwMetrics, metrics)
            );

            var expectedTransactionTraceSegments = new List <string>
            {
                @"Middleware Pipeline",
                @"DotNet/HomeController/Index"
            };

            var transactionSample = _fixture.AgentLog.GetTransactionSamples()
                                    .FirstOrDefault(sample => sample.Path == @"WebTransaction/MVC/Home/Index");


            Assert.NotNull(transactionSample);
            Assertions.TransactionTraceSegmentsExist(expectedTransactionTraceSegments, transactionSample);

            var getTransactionEvent = _fixture.AgentLog.TryGetTransactionEvent("WebTransaction/MVC/Home/Index");

            // Ensure false error attribute was included even with no errors
            Assert.True(getTransactionEvent.IntrinsicAttributes.ContainsKey("error"));
            Assert.Equal(false, getTransactionEvent.IntrinsicAttributes["error"]);

            var expectedErrorEventAttributes = new Dictionary <string, string>
            {
                { "error.class", "System.Exception" },
                { "error.message", "ExceptionMessage" },
            };

            var errorTraces = _fixture.AgentLog.GetErrorTraces().ToList();
            var errorEvents = _fixture.AgentLog.GetErrorEvents().ToList();

            NrAssert.Multiple(
                () => Assert.True(errorTraces.Any(), "No error trace found."),
                () => Assert.True(errorTraces.Count == 1, $"Expected 1 errors traces but found {errorTraces.Count}"),
                () => Assert.Equal("WebTransaction/MVC/Home/ThrowException", errorTraces[0].Path),
                () => Assert.Equal("System.Exception", errorTraces[0].ExceptionClassName),
                () => Assert.Equal("ExceptionMessage", errorTraces[0].Message),
                () => Assert.NotEmpty(errorTraces[0].Attributes.StackTrace),
                () => Assert.Single(errorEvents),
                () => Assertions.ErrorEventHasAttributes(expectedErrorEventAttributes, EventAttributeType.Intrinsic, errorEvents[0])
                );
        }
コード例 #2
0
        public void Test()
        {
            var expectedMetrics = new List <Assertions.ExpectedMetric>
            {
                new Assertions.ExpectedMetric {
                    metricName = @"DotNet/Owin Middleware Pipeline", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"WebTransaction", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"Errors/all", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"Errors/allWeb", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"Errors/WebTransaction/StatusCode/500", callCount = 1
                },
            };

            var expectedExceptionClassName = "System.ArgumentException";
            var expectedExceptionMessage   = "This exception is from the BadMiddleware";

            var expectedTransactionEventAttributes = new Dictionary <string, string>
            {
                { "errorType", expectedExceptionClassName },
                { "errorMessage", expectedExceptionMessage },
            };

            var expectedErrorEventAttributes = new Dictionary <string, string>
            {
                { "error.class", expectedExceptionClassName },
                { "error.message", expectedExceptionMessage },
            };

            var metrics           = _fixture.AgentLog.GetMetrics().ToList();
            var errorTraces       = _fixture.AgentLog.GetErrorTraces().ToList();
            var errorEvents       = _fixture.AgentLog.GetErrorEvents().ToList();
            var transactionEvents = _fixture.AgentLog.GetTransactionEvents().ToList();


            NrAssert.Multiple(
                () => Assertions.MetricsExist(expectedMetrics, metrics),
                () => Assert.NotEmpty(errorTraces),
                () => Assert.NotEmpty(errorEvents),
                () => Assert.Equal("WebTransaction/StatusCode/500", errorTraces[0].Path),
                () => Assert.Equal(expectedExceptionClassName, errorTraces[0].ExceptionClassName),
                () => Assert.Equal(expectedExceptionMessage, errorTraces[0].Message),
                () => Assertions.TransactionEventHasAttributes(expectedTransactionEventAttributes, TransactionEventAttributeType.Intrinsic, transactionEvents[0]),
                () => Assertions.ErrorEventHasAttributes(expectedErrorEventAttributes, EventAttributeType.Intrinsic, errorEvents[0])
                );
        }
コード例 #3
0
        public void Test()
        {
            var expectedTransactionName      = @"WebTransaction/WebAPI/My/CustomAttributes";
            var expectedTracedErrorPathAsync = @"WebTransaction/WebAPI/My/CustomErrorAttributes";

            var expectedTransactionTraceAttributes = new Dictionary <string, string>
            {
                { "key", "value" },
                { "foo", "bar" },
            };
            var expectedErrorTraceAttributes = new Dictionary <string, string>
            {
                { "hey", "dude" },
                { "faz", "baz" }
            };
            var expectedErrorEventAttributes = new Dictionary <string, string>
            {
                { "hey", "dude" },
                { "faz", "baz" }
            };
            var expectedTransactionEventAttributes = new Dictionary <string, string>
            {
                { "key", "value" },
                { "foo", "bar" }
            };

            var errorEvents = _fixture.AgentLog.GetErrorEvents().ToList();

            var transactionSample = _fixture.AgentLog.GetTransactionSamples()
                                    .Where(sample => sample.Path == expectedTransactionName)
                                    .FirstOrDefault();

            var errorTrace = _fixture.AgentLog.GetErrorTraces()
                             .Where(trace => trace.Path == expectedTracedErrorPathAsync)
                             .FirstOrDefault();


            var transactionEvent = _fixture.AgentLog.TryGetTransactionEvent(expectedTransactionName);

            NrAssert.Multiple
            (
                () => Assertions.TransactionTraceHasAttributes(expectedTransactionTraceAttributes, TransactionTraceAttributeType.User, transactionSample),
                () => Assertions.ErrorTraceHasAttributes(expectedErrorTraceAttributes, ErrorTraceAttributeType.User, errorTrace),
                () => Assertions.TransactionEventHasAttributes(expectedTransactionEventAttributes, TransactionEventAttributeType.User, transactionEvent),
                () => Assert.Single(errorEvents),
                () => Assertions.ErrorEventHasAttributes(expectedErrorEventAttributes, EventAttributeType.User, errorEvents[0].Events[0])
            );
        }
コード例 #4
0
        public void Test()
        {
            var expectedTransactionTraceAttributes = new Dictionary <string, string>
            {
                { "request.parameters.data", QueryStringParameterValue },
                { "host.displayName", "custom-host-name" }
            };

            var expectedTransactionEventAgentAttributes = new Dictionary <string, object>
            {
                { "response.status", "200" },
                { "http.statusCode", 200 },
                { "host.displayName", "custom-host-name" }
            };

            var expectedAgentErrorTraceAttributes = new Dictionary <string, string>
            {
                { "host.displayName", "custom-host-name" }
            };

            var expectedAgentErrorEventAttributes = new Dictionary <string, string>
            {
                { "host.displayName", "custom-host-name" }
            };

            var displayHost             = _fixture.AgentLog.GetConnectData().DisplayHost;
            var getDataTransactionEvent = _fixture.AgentLog.TryGetTransactionEvent("WebTransaction/MVC/DefaultController/Query");
            var transactionSample       = _fixture.AgentLog.GetTransactionSamples().FirstOrDefault();
            var errorEvents             = _fixture.AgentLog.GetErrorEvents().ToList();
            var errorTraces             = _fixture.AgentLog.GetErrorTraces().ToList();
            var firstErrorEvent         = errorEvents.FirstOrDefault();
            var firstErrorTrace         = errorTraces.FirstOrDefault();

            NrAssert.Multiple(
                () => Assert.Equal("custom-host-name", displayHost),
                () => Assertions.TransactionEventHasAttributes(expectedTransactionEventAgentAttributes, TransactionEventAttributeType.Agent, getDataTransactionEvent),
                () => Assertions.TransactionTraceHasAttributes(expectedTransactionTraceAttributes, TransactionTraceAttributeType.Agent, transactionSample),
                () => Assert.NotNull(firstErrorEvent),
                () => Assertions.ErrorEventHasAttributes(expectedAgentErrorEventAttributes, EventAttributeType.Agent, firstErrorEvent),
                () => Assertions.ErrorTraceHasAttributes(expectedAgentErrorTraceAttributes, ErrorTraceAttributeType.Agent, firstErrorTrace)


                );
        }
コード例 #5
0
        public void Test()
        {
            var expectedMetrics = new[]
            {
                new Assertions.ExpectedMetric {
                    metricName = "Custom/MyMetric", callCount = 1
                }
            };

            var expectedErrorEventIntrinsicAttributes = new Dictionary <string, string>
            {
                { "error.class", "System.Exception" },
                { "error.message", "Rawr!" },
                { "type", "TransactionError" }
            };

            var expectedErrorEventCustomAttributes = new Dictionary <string, string>
            {
                { "hey", "dude" },
                { "faz", "baz" }
            };

            var actualMetrics     = _fixture.AgentLog.GetMetrics();
            var errorTrace        = _fixture.AgentLog.GetErrorTraces().FirstOrDefault();
            var errorEventPayload = _fixture.AgentLog.GetErrorEvents().FirstOrDefault();

            //order events chronologically
            var errorEvents = errorEventPayload.Events
                              .Where(ev => ev.IntrinsicAttributes != null && ev.IntrinsicAttributes.ContainsKey("timestamp"))
                              .OrderBy(ev => ev.IntrinsicAttributes["timestamp"]).ToList();

            NrAssert.Multiple
            (
                () => Assertions.MetricsExist(expectedMetrics, actualMetrics),
                () => Assert.NotNull(errorTrace),
                () => Assert.Equal("2", errorEventPayload.Additions.EventsSeen.ToString()),
                () => Assertions.ErrorEventHasAttributes(expectedErrorEventIntrinsicAttributes, EventAttributeType.Intrinsic, errorEvents[0]),
                () => Assertions.ErrorEventHasAttributes(expectedErrorEventIntrinsicAttributes, EventAttributeType.Intrinsic, errorEvents[1]),
                () => Assertions.ErrorEventHasAttributes(expectedErrorEventCustomAttributes, EventAttributeType.User, errorEvents[1])
            );
        }
コード例 #6
0
        public void Test()
        {
            var expectedAttributes = new List <string>()
            {
                "parent.type",
                "parent.app",
                "parent.account",
                "parent.transportType",
                "parent.transportDuration",
                "guid",
                "traceId",
                "priority",
                "sampled"
            };

            var transactionEventExpectedAttributes = new List <string>(expectedAttributes)
            {
                "parentId"
            };

            var transactionEvent  = _fixture.AgentLog.GetTransactionEvents().FirstOrDefault();
            var errorEvent        = _fixture.AgentLog.GetErrorEvents().First().Events.First();
            var errorTrace        = _fixture.AgentLog.GetErrorTraces().FirstOrDefault();
            var transactionSample = _fixture.AgentLog.GetTransactionSamples()
                                    .FirstOrDefault(sample => sample.Path == @"WebTransaction/MVC/DistributedTracingController/ReceivePayload");

            NrAssert.Multiple(
                () => Assertions.TransactionEventHasAttributes(transactionEventExpectedAttributes, TransactionEventAttributeType.Intrinsic, transactionEvent),
                () => Assertions.ErrorEventHasAttributes(expectedAttributes, EventAttributeType.Intrinsic, errorEvent),
                () => Assertions.ErrorTraceHasAttributes(expectedAttributes, ErrorTraceAttributeType.Intrinsic, errorTrace),
                () => Assertions.TransactionTraceHasAttributes(expectedAttributes, TransactionTraceAttributeType.Intrinsic, transactionSample)
                );

            var parentIdKey      = "parentId";
            var expectedParentId = "27856f70d3d314b7";

            var transactionEventParentId = transactionEvent.IntrinsicAttributes[parentIdKey];

            Assert.Equal(expectedParentId, transactionEventParentId);
        }
コード例 #7
0
        public void Test()
        {
            var expectedAttributes = new List <string>()
            {
                "guid",
                "traceId",
                "priority",
                "sampled"
            };

            var transactionEvent = _fixture.AgentLog.GetTransactionEvents().FirstOrDefault();
            var errorEvent       = _fixture.AgentLog.GetErrorEvents().FirstOrDefault();
            var errorTrace       = _fixture.AgentLog.GetErrorTraces().FirstOrDefault();

            var transactionSample = _fixture.AgentLog.GetTransactionSamples()
                                    .FirstOrDefault(sample => sample.Path == @"WebTransaction/MVC/DistributedTracingController/Initiate");

            NrAssert.Multiple(
                () => Assertions.TransactionEventHasAttributes(expectedAttributes, TransactionEventAttributeType.Intrinsic, transactionEvent),
                () => Assertions.ErrorEventHasAttributes(expectedAttributes, EventAttributeType.Intrinsic, errorEvent),
                () => Assertions.ErrorTraceHasAttributes(expectedAttributes, ErrorTraceAttributeType.Intrinsic, errorTrace),
                () => Assertions.TransactionTraceHasAttributes(expectedAttributes, TransactionTraceAttributeType.Intrinsic, transactionSample)
                );
        }
        public void Test()
        {
            var expectedMetrics = new[]
            {
                new Assertions.ExpectedMetric {
                    metricName = "Custom/MyMetric", callCount = 1
                }
            };

            var expectedErrorEventIntrinsicAttributes = new Dictionary <string, string>
            {
                { "error.class", "System.Exception" },
                { "type", "TransactionError" },
                { "error.message", StripExeptionMessagesMessage }
            };

            var unexpectedErrorEventCustomAttributes = new List <string>
            {
                "hey",
                "faz"
            };

            var actualMetrics     = _fixture.AgentLog.GetMetrics();
            var errorTrace        = _fixture.AgentLog.GetErrorTraces().FirstOrDefault();
            var errorEventPayload = _fixture.AgentLog.GetErrorEvents().FirstOrDefault();

            NrAssert.Multiple
            (
                () => Assertions.MetricsExist(expectedMetrics, actualMetrics),
                () => Assert.NotNull(errorTrace),
                () => Assert.Equal("2", errorEventPayload.Additions.EventsSeen.ToString()),
                () => Assertions.ErrorEventHasAttributes(expectedErrorEventIntrinsicAttributes, EventAttributeType.Intrinsic, errorEventPayload.Events[0]),
                () => Assertions.ErrorEventHasAttributes(expectedErrorEventIntrinsicAttributes, EventAttributeType.Intrinsic, errorEventPayload.Events[1]),
                () => Assertions.ErrorEventDoesNotHaveAttributes(unexpectedErrorEventCustomAttributes, EventAttributeType.User, errorEventPayload.Events[1])
            );
        }
コード例 #9
0
        public void Test()
        {
            var expectedMetrics = new List <Assertions.ExpectedMetric>
            {
                // error metrics
                new Assertions.ExpectedMetric {
                    metricName = @"Errors/all", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"Errors/allWeb", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"Errors/WebTransaction/MVC/DefaultController/ThrowException", callCount = 1
                },

                // other
                new Assertions.ExpectedMetric {
                    metricName = @"Supportability/AnalyticsEvents/TotalEventsCollected", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"WebTransaction/MVC/DefaultController/ThrowException", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"HttpDispatcher", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"WebTransaction", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"DotNet/AuthenticateRequest", metricScope = @"WebTransaction/MVC/DefaultController/ThrowException", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"DotNet/AuthorizeRequest", metricScope = @"WebTransaction/MVC/DefaultController/ThrowException", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"DotNet/ResolveRequestCache", metricScope = @"WebTransaction/MVC/DefaultController/ThrowException", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"DotNet/MapRequestHandler", metricScope = @"WebTransaction/MVC/DefaultController/ThrowException", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"DotNet/AcquireRequestState", metricScope = @"WebTransaction/MVC/DefaultController/ThrowException", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"DotNet/ExecuteRequestHandler", metricScope = @"WebTransaction/MVC/DefaultController/ThrowException", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"DotNet/DefaultController/ThrowException", metricScope = @"WebTransaction/MVC/DefaultController/ThrowException", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"DotNet/EndRequest", metricScope = @"WebTransaction/MVC/DefaultController/ThrowException", callCount = 1
                },
            };

            var unexpectedMetrics = new List <Assertions.ExpectedMetric>
            {
                // These metrics won't get generated because of the exception
                new Assertions.ExpectedMetric {
                    metricName = @"DotNet/ReleaseRequestState", metricScope = @"WebTransaction/MVC/DefaultController/ThrowException", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"DotNet/UpdateRequestCache", metricScope = @"WebTransaction/MVC/DefaultController/ThrowException", callCount = 1
                },

                new Assertions.ExpectedMetric {
                    metricName = @"WebTransaction/MVC/Integrated Pipeline"
                },
                new Assertions.ExpectedMetric {
                    metricName = @"WebTransaction/MVC/Default/Ignored"
                },
                new Assertions.ExpectedMetric {
                    metricName = @"OtherTransaction/Normalized/*"
                },
                new Assertions.ExpectedMetric {
                    metricName = @"OtherTransaction/all"
                },
                new Assertions.ExpectedMetric {
                    metricName = @"Supportability/Transactions/allOther"
                },
            };

            var expectedAttributes = new Dictionary <string, string>
            {
                { "errorType", "System.Exception" },
                { "errorMessage", "!Exception~Message!" },
            };

            var expectedErrorEventAttributes = new Dictionary <string, string>
            {
                { "error.class", "System.Exception" },
                { "error.message", "!Exception~Message!" },
            };

            var expectedErrorTransactionEventAttributes2 = new List <string> {
                "error"
            };

            var metrics           = _fixture.AgentLog.GetMetrics().ToList();
            var errorTraces       = _fixture.AgentLog.GetErrorTraces().ToList();
            var transactionEvents = _fixture.AgentLog.GetTransactionEvents().ToList();
            var errorEvents       = _fixture.AgentLog.GetErrorEvents().ToList();

            NrAssert.Multiple(
                () => Assertions.MetricsExist(expectedMetrics, metrics),
                () => Assertions.MetricsDoNotExist(unexpectedMetrics, metrics),
                () => Assert.True(errorTraces.Any(), "No error trace found."),
                () => Assert.True(errorTraces.Count == 1, $"Expected 1 errors traces but found {errorTraces.Count}"),
                () => Assert.Equal("WebTransaction/MVC/DefaultController/ThrowException", errorTraces[0].Path),
                () => Assert.Equal("System.Exception", errorTraces[0].ExceptionClassName),
                () => Assert.Equal("!Exception~Message!", errorTraces[0].Message),
                () => Assert.NotEmpty(errorTraces[0].Attributes.StackTrace),
                () => Assert.True(transactionEvents.Any(), "No transaction events found."),
                () => Assert.True(transactionEvents.Count == 1, $"Expected 1 transaction event but found {transactionEvents.Count}"),
                () => Assertions.TransactionEventHasAttributes(expectedAttributes, TransactionEventAttributeType.Intrinsic, transactionEvents[0]),
                () => Assert.Single(errorEvents),
                () => Assertions.ErrorEventHasAttributes(expectedErrorEventAttributes, EventAttributeType.Intrinsic, errorEvents[0]),
                () => Assertions.TransactionEventHasAttributes(expectedErrorTransactionEventAttributes2, TransactionEventAttributeType.Intrinsic, transactionEvents[0])
                );
        }
コード例 #10
0
        public void Test()
        {
            var unexpectedAgentAttributes = new List <string>
            {
                @"request.parameters.data",
            };

            var expectedTransactionTraceAgentAttributes = new Dictionary <string, object>
            {
                { "response.status", "200" },
                { "http.statusCode", 200 },
                { "host.displayName", "custom-host-name" }
            };
            var expectedTransactionEventIntrinsicAttributes1 = new Dictionary <string, string>
            {
                { "type", "Transaction" }
            };

            var expectedTransactionEventIntrinsicAttributes2 = new List <string>
            {
                "timestamp",
                "duration",
                "webDuration",
                "queueDuration",
                "totalTime",
                "name",
                "nr.apdexPerfZone"
            };
            var expectedTransactionEventAgentAttributes = new Dictionary <string, object>
            {
                { "response.status", "200" },
                { "http.statusCode", 200 },
                { "host.displayName", "custom-host-name" }
            };

            var expectedErrorTransactionEventAttributes = new List <string>
            {
                "errorType",
                "errorMessage"
            };

            var expectedAgentErrorTraceAttributes = new Dictionary <string, string>
            {
                { "host.displayName", "custom-host-name" }
            };

            var expectedIntrinsicErrorEventAttributes = new Dictionary <string, string>
            {
                { "error.message", StripExceptionMessagesMessage },
            };

            var expectedAgentErrorEventAttributes = new Dictionary <string, string>
            {
                { "host.displayName", "custom-host-name" }
            };

            const string originalErrorMessage = "!Exception~Message!";

            var displayHost                  = _fixture.AgentLog.GetConnectData().DisplayHost;
            var transactionSample            = _fixture.AgentLog.GetTransactionSamples().FirstOrDefault();
            var getDataTransactionEvent      = _fixture.AgentLog.TryGetTransactionEvent("WebTransaction/MVC/DefaultController/Query");
            var getExceptionTransactionEvent = _fixture.AgentLog.TryGetTransactionEvent("WebTransaction/MVC/DefaultController/ThrowException");

            var errorEvents = _fixture.AgentLog.GetErrorEvents().ToList();
            var errorTraces = _fixture.AgentLog.GetErrorTraces().ToList();

            var firstErrorEvent = errorEvents.FirstOrDefault()?.Events.FirstOrDefault();
            var firstErrorTrace = errorTraces.FirstOrDefault();

            var stackTrace = firstErrorTrace.Attributes.StackTrace.ToList();

            NrAssert.Multiple(
                () => Assert.NotNull(transactionSample),
                () => Assert.NotNull(getDataTransactionEvent),
                () => Assert.NotNull(getExceptionTransactionEvent),
                () => Assert.NotNull(firstErrorEvent),
                () => Assert.NotNull(firstErrorTrace)
                );

            NrAssert.Multiple(
                () => Assertions.TransactionTraceDoesNotHaveAttributes(unexpectedAgentAttributes, TransactionTraceAttributeType.Agent, transactionSample),
                () => Assert.Equal(StripExceptionMessagesMessage, firstErrorTrace.Message),
                () => Assert.Contains(StripExceptionMessagesMessage, stackTrace[0]),
                () => Assert.DoesNotContain(originalErrorMessage, stackTrace[0]),
                () => Assert.Equal("custom-host-name", displayHost)
                );

            NrAssert.Multiple
            (
                () => Assertions.TransactionTraceHasAttributes(expectedTransactionTraceAgentAttributes, TransactionTraceAttributeType.Agent, transactionSample),
                () => Assertions.TransactionEventHasAttributes(expectedTransactionEventIntrinsicAttributes1, TransactionEventAttributeType.Intrinsic, getDataTransactionEvent),
                () => Assertions.TransactionEventHasAttributes(expectedTransactionEventIntrinsicAttributes2, TransactionEventAttributeType.Intrinsic, getDataTransactionEvent),
                () => Assertions.TransactionEventHasAttributes(expectedTransactionEventIntrinsicAttributes1, TransactionEventAttributeType.Intrinsic, getExceptionTransactionEvent),
                () => Assertions.TransactionEventHasAttributes(expectedTransactionEventIntrinsicAttributes2, TransactionEventAttributeType.Intrinsic, getExceptionTransactionEvent),
                () => Assertions.TransactionEventHasAttributes(expectedTransactionEventAgentAttributes, TransactionEventAttributeType.Agent, getDataTransactionEvent),
                () => Assertions.TransactionEventHasAttributes(expectedErrorTransactionEventAttributes, TransactionEventAttributeType.Intrinsic, getExceptionTransactionEvent),
                () => Assertions.ErrorTraceHasAttributes(expectedAgentErrorTraceAttributes, ErrorTraceAttributeType.Agent, firstErrorTrace),
                () => Assertions.ErrorEventHasAttributes(expectedIntrinsicErrorEventAttributes, EventAttributeType.Intrinsic, firstErrorEvent),
                () => Assertions.ErrorEventHasAttributes(expectedAgentErrorEventAttributes, EventAttributeType.Agent, firstErrorEvent)
            );
        }
コード例 #11
0
        public void Test()
        {
            var expectedMetrics = new List <Assertions.ExpectedMetric>
            {
                // error metrics
                new Assertions.ExpectedMetric {
                    metricName = @"Errors/all", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"Errors/allWeb", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"Errors/WebTransaction/WebAPI/Values/ThrowException", callCount = 1
                },

                // other
                new Assertions.ExpectedMetric {
                    metricName = @"WebTransaction", callCount = 1
                }
            };

            var unexpectedMetrics = new List <Assertions.ExpectedMetric>
            {
                new Assertions.ExpectedMetric {
                    metricName = @"OtherTransaction/all", callCount = 5
                },
            };

            var expectedErrorClass   = "System.Exception";
            var expectedErrorMessage = "ExceptionMessage";

            var expectedAttributes = new Dictionary <string, string>
            {
                { "errorType", expectedErrorClass },
                { "errorMessage", expectedErrorMessage },
            };


            var expectedErrorEventAttributes = new Dictionary <string, string>
            {
                { "error.class", expectedErrorClass },
                { "error.message", expectedErrorMessage },
            };

            var expectedErrorTransactionEventAttributes2 = new List <string> {
                "error"
            };

            var metrics          = _fixture.AgentLog.GetMetrics().ToList();
            var errorTrace       = _fixture.AgentLog.GetErrorTraces().ToList().FirstOrDefault();
            var transactionEvent = _fixture.AgentLog.GetTransactionEvents().ToList().FirstOrDefault();
            var errorEvent       = _fixture.AgentLog.GetErrorEvents().ToList().FirstOrDefault();

            NrAssert.Multiple(
                () => Assertions.MetricsExist(expectedMetrics, metrics),
                () => Assertions.MetricsDoNotExist(unexpectedMetrics, metrics),
                () => Assert.True(errorTrace != null, "No error trace found."),
                () => Assert.True(transactionEvent != null, "No transaction event found."),
                () => Assert.True(errorEvent != null, "No error event found."),
                () => Assert.Equal("WebTransaction/WebAPI/Values/ThrowException", errorTrace.Path),
                () => Assert.Equal(expectedErrorClass, errorTrace.ExceptionClassName),
                () => Assert.Equal(expectedErrorMessage, errorTrace.Message),
                () => Assert.NotEmpty(errorTrace.Attributes.StackTrace),
                () => Assertions.TransactionEventHasAttributes(expectedAttributes, TransactionEventAttributeType.Intrinsic, transactionEvent),
                () => Assertions.ErrorEventHasAttributes(expectedErrorEventAttributes, EventAttributeType.Intrinsic, errorEvent.Events[0]),
                () => Assertions.TransactionEventHasAttributes(expectedErrorTransactionEventAttributes2, TransactionEventAttributeType.Intrinsic, transactionEvent)
                );
        }
コード例 #12
0
        public void Test()
        {
            var metrics = _fixture.AgentLog.GetMetrics().ToList();

            Assert.NotNull(metrics);

            var expectedMetrics = new List <Assertions.ExpectedMetric>
            {
                new Assertions.ExpectedMetric {
                    metricName = @"ErrorsExpected/all", callCount = 3
                },
                new Assertions.ExpectedMetric {
                    metricName = @"Supportability/Events/TransactionError/Seen", callCount = 3
                },
                new Assertions.ExpectedMetric {
                    metricName = @"Supportability/Events/TransactionError/Sent", callCount = 3
                },
            };

            var unexpectedMetrics = new List <Assertions.ExpectedMetric>
            {
                // error metrics
                new Assertions.ExpectedMetric {
                    metricName = @"Errors/all"
                },
                new Assertions.ExpectedMetric {
                    metricName = @"Errors/allWeb"
                },
                new Assertions.ExpectedMetric {
                    metricName = @"Errors/WebTransaction/MVC/ExpectedErrorTest/ThrowExceptionWithMessage/{exceptionMessage}"
                },
                new Assertions.ExpectedMetric {
                    metricName = @"Errors/WebTransaction/MVC/ExpectedErrorTest/ThrowCustomException"
                },
                new Assertions.ExpectedMetric {
                    metricName = @"Errors/WebTransaction/MVC/ExpectedErrorTest/ReturnADesiredStatusCode/{statusCode}"
                },
            };


            var expectedErrorAttributes = new Dictionary <string, string>
            {
                { "error.expected", "true" }
            };

            var errorTraces = _fixture.AgentLog.GetErrorTraces().ToList();
            var errorEvents = _fixture.AgentLog.GetErrorEvents().ToList();

            NrAssert.Multiple(
                () => Assertions.MetricsExist(expectedMetrics, metrics),
                () => Assertions.MetricsDoNotExist(unexpectedMetrics, metrics),
                () => Assert.True(errorTraces.Count == 3, $"Expected 3 error traces but found {errorTraces.Count}"),
                () => Assert.True(errorEvents.Count == 3, $"Expected 3 error events but found {errorEvents.Count}")
                );

            foreach (var errorEvent in errorEvents)
            {
                Assertions.ErrorEventHasAttributes(expectedErrorAttributes, EventAttributeType.Intrinsic, errorEvent);
            }

            foreach (var errorTrace in errorTraces)
            {
                Assertions.ErrorTraceHasAttributes(expectedErrorAttributes, ErrorTraceAttributeType.Intrinsic, errorTrace);
            }


            var spanEvents      = _fixture.AgentLog.GetSpanEvents().ToList();
            var errorSpanEvents = spanEvents.Where(se => se.AgentAttributes.ContainsKey("error.expected"));

            Assert.True(errorSpanEvents.Count() > 0);
        }
コード例 #13
0
        public void Test()
        {
            var expectedMetrics = new List <Assertions.ExpectedMetric>
            {
                // error metrics
                new Assertions.ExpectedMetric {
                    metricName = @"Errors/all", callCount = 2
                },
                new Assertions.ExpectedMetric {
                    metricName = @"Errors/allWeb", callCount = 2
                },
                new Assertions.ExpectedMetric {
                    metricName = @"Errors/WebTransaction/WebService/BasicWebService.TestWebService.ThrowException", callCount = 2
                },

                // other
                new Assertions.ExpectedMetric {
                    metricName = @"WebTransaction/WebService/BasicWebService.TestWebService.ThrowException", callCount = 2
                },
                new Assertions.ExpectedMetric {
                    metricName = @"DotNet/BasicWebService.TestWebService.ThrowException", callCount = 2
                },
                new Assertions.ExpectedMetric {
                    metricName = @"DotNet/BasicWebService.TestWebService.ThrowException", metricScope = "WebTransaction/WebService/BasicWebService.TestWebService.ThrowException", callCount = 2
                }
            };

            var unexpectedMetrics = new List <Assertions.ExpectedMetric>
            {
                new Assertions.ExpectedMetric {
                    metricName = @"External/all"
                },
                new Assertions.ExpectedMetric {
                    metricName = @"ApdexOther"
                },
                new Assertions.ExpectedMetric {
                    metricName = @"OtherTransaction/all"
                },
            };

            var expectedAttributes = new Dictionary <string, string>
            {
                { "errorType", ExpectedExceptionType },
                { "errorMessage", "Oh no!" },
            };

            var expectedErrorEventAttributes = new Dictionary <string, string>
            {
                { "error.class", ExpectedExceptionType },
                { "error.message", "Oh no!" },
            };

            var metrics           = _fixture.AgentLog.GetMetrics().ToList();
            var errorTraces       = _fixture.AgentLog.GetErrorTraces().ToList();
            var transactionEvents = _fixture.AgentLog.GetTransactionEvents().ToList();
            var errorEvents       = _fixture.AgentLog.GetErrorEvents().ToList();

            NrAssert.Multiple(
                () => Assertions.MetricsExist(expectedMetrics, metrics),
                () => Assertions.MetricsDoNotExist(unexpectedMetrics, metrics),
                () => Assert.True(errorTraces.Any(), "No error trace found."),
                () => Assert.True(errorTraces.Count == 2, $"Expected 2 errors traces but found {errorTraces.Count}"),
                () => Assert.Equal("WebTransaction/WebService/BasicWebService.TestWebService.ThrowException", errorTraces[0].Path),
                () => Assert.Equal(ExpectedExceptionType, errorTraces[0].ExceptionClassName),
                () => Assert.Equal("Oh no!", errorTraces[0].Message),
                () => Assert.NotEmpty(errorTraces[0].Attributes.StackTrace),
                () => Assert.Equal("WebTransaction/WebService/BasicWebService.TestWebService.ThrowException", errorTraces[1].Path),
                () => Assert.Equal(ExpectedExceptionType, errorTraces[1].ExceptionClassName),
                () => Assert.Equal("Oh no!", errorTraces[1].Message),
                () => Assert.NotEmpty(errorTraces[1].Attributes.StackTrace),
                () => Assert.True(transactionEvents.Any(), "No transaction events found."),
                () => Assert.True(transactionEvents.Count == 2, $"Expected 2 transaction event but found {transactionEvents.Count}"),
                () => Assertions.TransactionEventHasAttributes(expectedAttributes, TransactionEventAttributeType.Intrinsic, transactionEvents[0]),
                () => Assertions.TransactionEventHasAttributes(expectedAttributes, TransactionEventAttributeType.Intrinsic, transactionEvents[1]),
                () => Assert.Single(errorEvents),
                () => Assertions.ErrorEventHasAttributes(expectedErrorEventAttributes, EventAttributeType.Intrinsic, errorEvents[0].Events[0])
                );
        }