Beispiel #1
0
        public void Test()
        {
            var parameterPlaceholder = string.Join(",", DbParameterData.OdbcMsSqlParameters.Select(_ => "?"));
            var expectedSqlStatement = $"{{call {_fixture.ProcedureName.ToLower()}({parameterPlaceholder})}}";

            var expectedMetrics = new List <Assertions.ExpectedMetric>
            {
                new Assertions.ExpectedMetric {
                    metricName = $@"Datastore/statement/Other/{expectedSqlStatement}/ExecuteProcedure", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = $@"Datastore/statement/Other/{expectedSqlStatement}/ExecuteProcedure", callCount = 1, metricScope = "WebTransaction/MVC/MsSqlController/MsSqlParameterizedStoredProcedureUsingOdbcDriver"
                }
            };

            var expectedTransactionTraceSegments = new List <string>
            {
                $"Datastore/statement/Other/{expectedSqlStatement}/ExecuteProcedure"
            };

            var expectedQueryParameters = _paramsWithAtSigns
                    ? DbParameterData.OdbcMsSqlParameters.ToDictionary(p => p.ParameterName, p => p.ExpectedValue)
                    : DbParameterData.OdbcMsSqlParameters.ToDictionary(p => p.ParameterName.TrimStart('@'), p => p.ExpectedValue);

            var expectedTransactionTraceQueryParameters = new Assertions.ExpectedSegmentQueryParameters {
                segmentName = $"Datastore/statement/Other/{expectedSqlStatement}/ExecuteProcedure", QueryParameters = expectedQueryParameters
            };

            var expectedSqlTraces = new List <Assertions.ExpectedSqlTrace>
            {
                new Assertions.ExpectedSqlTrace
                {
                    TransactionName     = "WebTransaction/MVC/MsSqlController/MsSqlParameterizedStoredProcedureUsingOdbcDriver",
                    Sql                 = $"{{call {_fixture.ProcedureName}({parameterPlaceholder})}}",
                    DatastoreMetricName = $"Datastore/statement/Other/{expectedSqlStatement}/ExecuteProcedure",
                    QueryParameters     = expectedQueryParameters
                }
            };

            var metrics           = _fixture.AgentLog.GetMetrics().ToList();
            var transactionSample = _fixture.AgentLog.TryGetTransactionSample("WebTransaction/MVC/MsSqlController/MsSqlParameterizedStoredProcedureUsingOdbcDriver");
            var transactionEvent  = _fixture.AgentLog.TryGetTransactionEvent("WebTransaction/MVC/MsSqlController/MsSqlParameterizedStoredProcedureUsingOdbcDriver");
            var sqlTraces         = _fixture.AgentLog.GetSqlTraces().ToList();
            var logEntries        = _fixture.AgentLog.GetFileLines().ToList();

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

            NrAssert.Multiple
            (
                () => Assertions.MetricsExist(expectedMetrics, metrics),
                () => Assertions.TransactionTraceSegmentsExist(expectedTransactionTraceSegments, transactionSample),
                () => Assertions.TransactionTraceSegmentQueryParametersExist(expectedTransactionTraceQueryParameters, transactionSample),
                () => Assertions.SqlTraceExists(expectedSqlTraces, sqlTraces),
                () => Assertions.LogLinesNotExist(new[] { AgentLogFile.ErrorLogLinePrefixRegex }, logEntries)
            );
        }
        public void Test()
        {
            var expectedMetrics = new List <Assertions.ExpectedMetric>
            {
                new Assertions.ExpectedMetric {
                    metricName = $@"Datastore/statement/MySQL/{_fixture.ProcedureName.ToLower()}/ExecuteProcedure", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = $@"Datastore/statement/MySQL/{_fixture.ProcedureName.ToLower()}/ExecuteProcedure", callCount = 1, metricScope = "WebTransaction/MVC/MySqlController/MySqlParameterizedStoredProcedure"
                }
            };

            var expectedTransactionTraceSegments = new List <string>
            {
                $"Datastore/statement/MySQL/{_fixture.ProcedureName.ToLower()}/ExecuteProcedure"
            };

            var expectedQueryParameters = _paramsWithAtSigns
                ? DbParameterData.MySqlParameters.ToDictionary(p => p.ParameterName, p => p.ExpectedValue)
                : DbParameterData.MySqlParameters.ToDictionary(p => p.ParameterName.TrimStart('@'), p => p.ExpectedValue);

            var expectedTransactionTraceQueryParameters = new Assertions.ExpectedSegmentQueryParameters
            {
                segmentName     = $"Datastore/statement/MySQL/{_fixture.ProcedureName.ToLower()}/ExecuteProcedure",
                QueryParameters = expectedQueryParameters
            };

            var expectedSqlTraces = new List <Assertions.ExpectedSqlTrace>
            {
                new Assertions.ExpectedSqlTrace
                {
                    TransactionName     = "WebTransaction/MVC/MySqlController/MySqlParameterizedStoredProcedure",
                    Sql                 = _fixture.ProcedureName,
                    DatastoreMetricName = $"Datastore/statement/MySQL/{_fixture.ProcedureName.ToLower()}/ExecuteProcedure",
                    QueryParameters     = expectedQueryParameters,
                    HasExplainPlan      = false
                }
            };

            var metrics           = _fixture.AgentLog.GetMetrics().ToList();
            var transactionSample = _fixture.AgentLog.TryGetTransactionSample("WebTransaction/MVC/MySqlController/MySqlParameterizedStoredProcedure");
            var transactionEvent  = _fixture.AgentLog.TryGetTransactionEvent("WebTransaction/MVC/MySqlController/MySqlParameterizedStoredProcedure");
            var sqlTraces         = _fixture.AgentLog.GetSqlTraces().ToList();

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

            NrAssert.Multiple
            (
                () => Assertions.MetricsExist(expectedMetrics, metrics),
                () => Assertions.TransactionTraceSegmentsExist(expectedTransactionTraceSegments, transactionSample),
                () => Assertions.TransactionTraceSegmentQueryParametersExist(expectedTransactionTraceQueryParameters, transactionSample),
                () => Assertions.SqlTraceExists(expectedSqlTraces, sqlTraces)
            );
        }
        public void Test()
        {
            var expectedMetrics = new List <Assertions.ExpectedMetric>
            {
                new Assertions.ExpectedMetric {
                    metricName = $@"Datastore/statement/MSSQL/{_fixture.ProcedureName.ToLower()}/ExecuteProcedure", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = $@"Datastore/statement/MSSQL/{_fixture.ProcedureName.ToLower()}/ExecuteProcedure", callCount = 1, metricScope = _expectedTransactionName
                }
            };

            var expectedTransactionTraceSegments = new List <string>
            {
                $"Datastore/statement/MSSQL/{_fixture.ProcedureName.ToLower()}/ExecuteProcedure"
            };

            var expectedQueryParameters = _paramsWithAtSigns
                    ? DbParameterData.MsSqlParameters.ToDictionary(p => p.ParameterName, p => p.ExpectedValue)
                    : DbParameterData.MsSqlParameters.ToDictionary(p => p.ParameterName.TrimStart('@'), p => p.ExpectedValue);


            var expectedTransactionTraceQueryParameters = new Assertions.ExpectedSegmentQueryParameters {
                segmentName = $"Datastore/statement/MSSQL/{_fixture.ProcedureName.ToLower()}/ExecuteProcedure", QueryParameters = expectedQueryParameters
            };

            var expectedSqlTraces = new List <Assertions.ExpectedSqlTrace>
            {
                new Assertions.ExpectedSqlTrace
                {
                    TransactionName     = _expectedTransactionName,
                    Sql                 = _fixture.ProcedureName,
                    DatastoreMetricName = $"Datastore/statement/MSSQL/{_fixture.ProcedureName.ToLower()}/ExecuteProcedure",
                    QueryParameters     = expectedQueryParameters
                }
            };

            var metrics           = _fixture.AgentLog.GetMetrics().ToList();
            var transactionSample = _fixture.AgentLog.TryGetTransactionSample(_expectedTransactionName);
            var transactionEvent  = _fixture.AgentLog.TryGetTransactionEvent(_expectedTransactionName);
            var sqlTraces         = _fixture.AgentLog.GetSqlTraces().ToList();
            var logEntries        = _fixture.AgentLog.GetFileLines().ToList();

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

            NrAssert.Multiple
            (
                () => Assertions.MetricsExist(expectedMetrics, metrics),
                () => Assertions.TransactionTraceSegmentsExist(expectedTransactionTraceSegments, transactionSample),
                () => Assertions.TransactionTraceSegmentQueryParametersExist(expectedTransactionTraceQueryParameters, transactionSample),
                () => Assertions.SqlTraceExists(expectedSqlTraces, sqlTraces),
                () => Assertions.LogLinesNotExist(new[] { AgentLogFile.ErrorLogLinePrefixRegex }, logEntries)
            );
        }
        public void Test()
        {
            var expectedMetrics = new List <Assertions.ExpectedMetric>
            {
                new Assertions.ExpectedMetric {
                    metricName = @"Datastore/all", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"Datastore/allWeb", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"Datastore/MSSQL/all", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"Datastore/MSSQL/allWeb", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = $@"Datastore/instance/MSSQL/{MsSqlConfiguration.MsSqlServer}/default", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = @"Datastore/operation/MSSQL/select", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = $@"Datastore/statement/MSSQL/teammembers/select", callCount = 1
                },
                new Assertions.ExpectedMetric {
                    metricName = $@"Datastore/statement/MSSQL/teammembers/select", callCount = 1, metricScope = _expectedTransactionName
                },
            };
            var unexpectedMetrics = new List <Assertions.ExpectedMetric>
            {
                // The datastore operation happened inside a web transaction so there should be no allOther metrics
                new Assertions.ExpectedMetric {
                    metricName = @"Datastore/allOther"
                },
                new Assertions.ExpectedMetric {
                    metricName = @"Datastore/MSSQL/allOther"
                },

                // The operation metric should not be scoped because the statement metric is scoped instead
                new Assertions.ExpectedMetric {
                    metricName = @"Datastore/operation/MSSQL/select", metricScope = _expectedTransactionName
                },
            };
            var expectedTransactionTraceSegments = new List <string>
            {
                $"Datastore/statement/MSSQL/teammembers/select"
            };


            var expectedQueryParameters = _paramsWithAtSigns
                ? new Dictionary <string, object> {
                { "@FN", "O'Keefe" }
            }
                : new Dictionary <string, object> {
                { "FN", "O'Keefe" }
            };


            var expectedTransactionTraceSegmentParameters = new List <Assertions.ExpectedSegmentParameter>
            {
                new Assertions.ExpectedSegmentParameter {
                    segmentName = $"Datastore/statement/MSSQL/teammembers/select", parameterName = "explain_plan"
                },
                new Assertions.ExpectedSegmentParameter {
                    segmentName = $"Datastore/statement/MSSQL/teammembers/select", parameterName = "sql", parameterValue = "SELECT * FROM NewRelic.dbo.TeamMembers WHERE FirstName = @FN"
                },
                new Assertions.ExpectedSegmentParameter {
                    segmentName = "Datastore/statement/MSSQL/teammembers/select", parameterName = "host", parameterValue = MsSqlConfiguration.MsSqlServer
                },
                new Assertions.ExpectedSegmentParameter {
                    segmentName = "Datastore/statement/MSSQL/teammembers/select", parameterName = "port_path_or_id", parameterValue = "default"
                },
                new Assertions.ExpectedSegmentParameter {
                    segmentName = "Datastore/statement/MSSQL/teammembers/select", parameterName = "database_name", parameterValue = "NewRelic"
                },
            };

            var expectedTransactionTraceQueryParameters = new Assertions.ExpectedSegmentQueryParameters {
                segmentName = $"Datastore/statement/MSSQL/teammembers/select", QueryParameters = expectedQueryParameters
            };

            var expectedTransactionEventIntrinsicAttributes = new List <string>
            {
                "databaseDuration"
            };

            var expectedSqlTraces = new List <Assertions.ExpectedSqlTrace>
            {
                new Assertions.ExpectedSqlTrace
                {
                    TransactionName     = _expectedTransactionName,
                    Sql                 = "SELECT * FROM NewRelic.dbo.TeamMembers WHERE FirstName = @FN",
                    DatastoreMetricName = "Datastore/statement/MSSQL/teammembers/select",
                    QueryParameters     = expectedQueryParameters,
                    HasExplainPlan      = true
                },
            };

            var metrics           = _fixture.AgentLog.GetMetrics().ToList();
            var transactionSample = _fixture.AgentLog.TryGetTransactionSample(_expectedTransactionName);
            var transactionEvent  = _fixture.AgentLog.TryGetTransactionEvent(_expectedTransactionName);
            var sqlTraces         = _fixture.AgentLog.GetSqlTraces().ToList();
            var logEntries        = _fixture.AgentLog.GetFileLines();

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

            NrAssert.Multiple
            (
                () => Assertions.MetricsExist(expectedMetrics, metrics),
                () => Assertions.MetricsDoNotExist(unexpectedMetrics, metrics),
                () => Assertions.TransactionTraceSegmentsExist(expectedTransactionTraceSegments, transactionSample),

                () => Assertions.TransactionTraceSegmentParametersExist(expectedTransactionTraceSegmentParameters, transactionSample),
                () => Assertions.TransactionTraceSegmentQueryParametersExist(expectedTransactionTraceQueryParameters, transactionSample),

                () => Assertions.TransactionEventHasAttributes(expectedTransactionEventIntrinsicAttributes, TransactionEventAttributeType.Intrinsic, transactionEvent),
                () => Assertions.SqlTraceExists(expectedSqlTraces, sqlTraces),
                () => Assertions.LogLinesNotExist(new[] { AgentLogFile.ErrorLogLinePrefixRegex }, logEntries)
            );
        }