Exemplo n.º 1
0
        public void DatastoreSegment_HasCorrectTraceNameAndMetrics_WhenNullModelAndOperation()
        {
            var tx = _agent.CreateTransaction(
                isWeb: true,
                category: EnumNameCache <WebTransactionType> .GetName(WebTransactionType.Action),
                transactionDisplayName: "name",
                doNotTrackAsUnitOfWork: true);
            var segment = _agent.StartDatastoreRequestSegmentOrThrow(null, DatastoreVendor.MSSQL, null);

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

            _compositeTestAgent.Harvest();

            var expectedMetrics = new[]
            {
                new ExpectedMetric {
                    Name = "Datastore/all"
                },
                new ExpectedMetric {
                    Name = "Datastore/allWeb"
                },
                new ExpectedMetric {
                    Name = "Datastore/MSSQL/all"
                },
                new ExpectedMetric {
                    Name = "Datastore/MSSQL/allWeb"
                },
                new ExpectedMetric {
                    Name = "Datastore/operation/MSSQL/other", Scope = "WebTransaction/Action/name"
                },
                new ExpectedMetric {
                    Name = "Datastore/operation/MSSQL/other"
                }
            };
            var unexpectedMetrics = new[]
            {
                new ExpectedMetric {
                    Name = "Datastore/allOther"
                }
            };
            var expectedSegments = new[]
            {
                "Datastore/operation/MSSQL/other"
            };
            var actualMetrics    = _compositeTestAgent.Metrics.ToList();
            var transactionTrace = _compositeTestAgent.TransactionTraces.First();

            NrAssert.Multiple(
                () => TransactionTraceAssertions.SegmentsExist(expectedSegments, transactionTrace),
                () => MetricAssertions.MetricsExist(expectedMetrics, actualMetrics),
                () => MetricAssertions.MetricsDoNotExist(unexpectedMetrics, actualMetrics)
                );
        }
Exemplo n.º 2
0
        public void ExternalSegment_HasCorrectTraceNameAndMetrics()
        {
            var tx = _agent.CreateTransaction(
                isWeb: true,
                category: EnumNameCache <WebTransactionType> .GetName(WebTransactionType.Action),
                transactionDisplayName: "name",
                doNotTrackAsUnitOfWork: true);
            var segment = _agent.StartExternalRequestSegmentOrThrow(new Uri("http://www.newrelic.com/test"), "POST");

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

            _compositeTestAgent.Harvest();

            var expectedMetrics = new[]
            {
                new ExpectedMetric {
                    Name = "External/all"
                },
                new ExpectedMetric {
                    Name = "External/allWeb"
                },
                new ExpectedMetric {
                    Name = "External/www.newrelic.com/all"
                },
                new ExpectedMetric {
                    Name = "External/www.newrelic.com/Stream/POST"
                },
                new ExpectedMetric {
                    Name = "External/www.newrelic.com/Stream/POST", Scope = "WebTransaction/Action/name"
                }
            };
            var unexpectedMetrics = new[]
            {
                new ExpectedMetric {
                    Name = "External/allOther"
                }
            };
            var expectedSegments = new[]
            {
                "External/www.newrelic.com/Stream/POST"
            };
            var actualMetrics    = _compositeTestAgent.Metrics.ToList();
            var transactionTrace = _compositeTestAgent.TransactionTraces.First();

            NrAssert.Multiple(
                () => TransactionTraceAssertions.SegmentsExist(expectedSegments, transactionTrace),
                () => MetricAssertions.MetricsExist(expectedMetrics, actualMetrics),
                () => MetricAssertions.MetricsDoNotExist(unexpectedMetrics, actualMetrics)
                );
        }
Exemplo n.º 3
0
        public void CustomSegment_ShouldNotHaveMetrics_OutsideATransaction()
        {
            var segment = _agent.StartCustomSegmentOrThrow("customName");

            segment.End();

            _compositeTestAgent.Harvest();

            var unexpectedMetrics = new[]
            {
                new ExpectedMetric {
                    Name = "Custom/customName"
                }
            };
            var actualMetrics = _compositeTestAgent.Metrics.ToList();

            MetricAssertions.MetricsDoNotExist(unexpectedMetrics, actualMetrics);
        }
Exemplo n.º 4
0
        public void MethodSegment_ShouldNotHaveMetrics_OutsideATransaction()
        {
            var segment = _agent.StartMethodSegmentOrThrow("typeName", "methodName");

            segment.End();

            _compositeTestAgent.Harvest();

            var unexpectedMetrics = new[]
            {
                new ExpectedMetric {
                    Name = "DotNet/typeName/methodName"
                }
            };
            var actualMetrics = _compositeTestAgent.Metrics.ToList();

            MetricAssertions.MetricsDoNotExist(unexpectedMetrics, actualMetrics);
        }
Exemplo n.º 5
0
        public void MessageBrokerSegment_ShouldNotHaveMetrics_OutsideATransaction()
        {
            var segment = _agent.StartMessageBrokerSegmentOrThrow("vendor1", MessageBrokerDestinationType.Queue, "queueA",
                                                                  MessageBrokerAction.Consume);

            segment.End();

            _compositeTestAgent.Harvest();

            var unexpectedMetrics = new[]
            {
                new ExpectedMetric {
                    Name = "MessageBroker/vendor1/Queue/Consume/Named/queueA"
                }
            };
            var actualMetrics = _compositeTestAgent.Metrics.ToList();

            MetricAssertions.MetricsDoNotExist(unexpectedMetrics, actualMetrics);
        }
Exemplo n.º 6
0
        public void ExternalSegment_ShouldNotHaveMetrics_OutsideATransaction()
        {
            var segment = _agent.StartExternalRequestSegmentOrThrow(new Uri("http://www.newrelic.com/test"), "POST");

            segment.End();

            _compositeTestAgent.Harvest();

            var unexpectedMetrics = new[]
            {
                new ExpectedMetric {
                    Name = "External/all"
                },
                new ExpectedMetric {
                    Name = "External/www.newrelic.com/all"
                },
                new ExpectedMetric {
                    Name = "External/www.newrelic.com/Stream/POST"
                },
            };
            var actualMetrics = _compositeTestAgent.Metrics.ToList();

            MetricAssertions.MetricsDoNotExist(unexpectedMetrics, actualMetrics);
        }
Exemplo n.º 7
0
        public void DatastoreSegment_HasNoInstanceMetric_WhenInstanceReportingIsDisabled()
        {
            _compositeTestAgent.LocalConfiguration.datastoreTracer.instanceReporting.enabled = false;
            var tx = _agent.CreateTransaction(
                isWeb: true,
                category: EnumNameCache <WebTransactionType> .GetName(WebTransactionType.Action),
                transactionDisplayName: "name",
                doNotTrackAsUnitOfWork: true);
            var segment = _agent.StartDatastoreRequestSegmentOrThrow("INSERT", DatastoreVendor.MSSQL, "MyAwesomeTable", null, null, "HostName", "1433", "MyDatabase");

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

            _compositeTestAgent.Harvest();

            var expectedMetrics = new[]
            {
                new ExpectedMetric {
                    Name = "Datastore/all"
                },
                new ExpectedMetric {
                    Name = "Datastore/allWeb"
                },
                new ExpectedMetric {
                    Name = "Datastore/MSSQL/all"
                },
                new ExpectedMetric {
                    Name = "Datastore/MSSQL/allWeb"
                },
                new ExpectedMetric {
                    Name = "Datastore/statement/MSSQL/MyAwesomeTable/INSERT"
                },
                new ExpectedMetric {
                    Name = "Datastore/statement/MSSQL/MyAwesomeTable/INSERT", Scope = "WebTransaction/Action/name"
                },
                new ExpectedMetric {
                    Name = "Datastore/operation/MSSQL/INSERT"
                }
            };
            var unexpectedMetrics = new[]
            {
                new ExpectedMetric {
                    Name = "Datastore/allOther"
                },
                new ExpectedMetric {
                    Name = "Datastore/instance/MSSQL/HostName/1433"
                }
            };
            var expectedSegments = new[]
            {
                "Datastore/statement/MSSQL/MyAwesomeTable/INSERT"
            };
            var actualMetrics    = _compositeTestAgent.Metrics.ToList();
            var transactionTrace = _compositeTestAgent.TransactionTraces.First();

            NrAssert.Multiple(
                () => TransactionTraceAssertions.SegmentsExist(expectedSegments, transactionTrace),
                () => MetricAssertions.MetricsExist(expectedMetrics, actualMetrics),
                () => MetricAssertions.MetricsDoNotExist(unexpectedMetrics, actualMetrics)
                );
        }
Exemplo n.º 8
0
        public void ExternalSegment_HasCorrectTraceNameAndMetrics_IfCatResponseReceived()
        {
            const string encodingKey = "foo";

            _compositeTestAgent.ServerConfiguration.EncodingKey = encodingKey;
            _compositeTestAgent.PushConfiguration();

            var tx = _agent.CreateTransaction(
                isWeb: true,
                category: EnumNameCache <WebTransactionType> .GetName(WebTransactionType.Action),
                transactionDisplayName: "name",
                doNotTrackAsUnitOfWork: true);
            var segment = _agent.StartExternalRequestSegmentOrThrow(new Uri("http://www.newrelic.com/test"), "POST");

            var catResponseData = new CrossApplicationResponseData("123#456", "transactionName", 1.1f, 2.2f, 3, "guid");
            var responseHeaders = new Dictionary <string, string>
            {
                { "X-NewRelic-App-Data", HeaderEncoder.EncodeSerializedData(JsonConvert.SerializeObject(catResponseData), encodingKey) }
            };

            tx.ProcessInboundResponse(responseHeaders, segment);
            segment.End();
            tx.End();

            _compositeTestAgent.Harvest();

            var expectedMetrics = new[]
            {
                new ExpectedMetric {
                    Name = "External/all"
                },
                new ExpectedMetric {
                    Name = "External/allWeb"
                },
                new ExpectedMetric {
                    Name = "External/www.newrelic.com/all"
                },
                new ExpectedMetric {
                    Name = "External/www.newrelic.com/Stream/POST"
                },
                new ExpectedMetric {
                    Name = "ExternalApp/www.newrelic.com/123#456/all"
                },
                new ExpectedMetric {
                    Name = "ExternalTransaction/www.newrelic.com/123#456/transactionName"
                },
                new ExpectedMetric {
                    Name = "ExternalTransaction/www.newrelic.com/123#456/transactionName", Scope = "WebTransaction/Action/name"
                }
            };
            var unexpectedMetrics = new[]
            {
                new ExpectedMetric {
                    Name = "External/allOther"
                },
                new ExpectedMetric {
                    Name = "External/www.newrelic.com/Stream/POST", Scope = "WebTransaction/Action/name"
                }
            };
            var unexpectedSegments = new[]
            {
                "External/www.newrelic.com/Stream/POST"
            };
            var expectedSegments = new[]
            {
                "ExternalTransaction/www.newrelic.com/123#456/transactionName"
            };
            var actualMetrics    = _compositeTestAgent.Metrics.ToList();
            var transactionTrace = _compositeTestAgent.TransactionTraces.First();

            NrAssert.Multiple(
                () => TransactionTraceAssertions.SegmentsExist(expectedSegments, transactionTrace),
                () => TransactionTraceAssertions.SegmentsDoNotExist(unexpectedSegments, transactionTrace),
                () => MetricAssertions.MetricsExist(expectedMetrics, actualMetrics),
                () => MetricAssertions.MetricsDoNotExist(unexpectedMetrics, actualMetrics)
                );
        }
        public void SqlParsingCacheMetricsAreGenerated()
        {
            var transaction = _agent.CreateTransaction(
                isWeb: true,
                category: EnumNameCache <WebTransactionType> .GetName(WebTransactionType.Action),
                transactionDisplayName: "name",
                doNotTrackAsUnitOfWork: true);

            _agent.StartDatastoreRequestSegmentOrThrow(DatastoreVendor.MSSQL, CommandType.Text, "SELECT * FROM Table1").End();
            _agent.StartDatastoreRequestSegmentOrThrow(DatastoreVendor.MSSQL, CommandType.Text, "SELECT * FROM Table1").End();
            _agent.StartDatastoreRequestSegmentOrThrow(DatastoreVendor.MSSQL, CommandType.Text, "SELECT * FROM Table1").End();
            _agent.StartDatastoreRequestSegmentOrThrow(DatastoreVendor.MSSQL, CommandType.Text, "SELECT * FROM Table2").End();
            _agent.StartDatastoreRequestSegmentOrThrow(DatastoreVendor.MSSQL, CommandType.Text, "SELECT * FROM Table2").End();

            _agent.StartDatastoreRequestSegmentOrThrow(DatastoreVendor.IBMDB2, CommandType.Text, "SELECT * FROM Table1").End();
            _agent.StartDatastoreRequestSegmentOrThrow(DatastoreVendor.IBMDB2, CommandType.Text, "SELECT * FROM Table1").End();

            transaction.End();

            _compositeTestAgent.Harvest();

            const int defaultCapacity = 1000;

            // ASSERT
            var expectedMetrics = new List <ExpectedMetric>
            {
                new ExpectedCountMetric {
                    Name = SqlParsingCacheMetricPrefix + "/MSSQL/Capacity", CallCount = 1, Total = defaultCapacity
                },
                new ExpectedCountMetric {
                    Name = SqlParsingCacheMetricPrefix + "/MSSQL/Hits", CallCount = 3
                },
                new ExpectedCountMetric {
                    Name = SqlParsingCacheMetricPrefix + "/MSSQL/Misses", CallCount = 2
                },
                new ExpectedCountMetric {
                    Name = SqlParsingCacheMetricPrefix + "/MSSQL/Ejections", CallCount = 0
                },
                new ExpectedCountMetric {
                    Name = SqlParsingCacheMetricPrefix + "/MSSQL/Size", CallCount = 1, Total = 2
                },

                new ExpectedCountMetric {
                    Name = SqlParsingCacheMetricPrefix + "/IBMDB2/Capacity", CallCount = 1, Total = defaultCapacity
                },
                new ExpectedCountMetric {
                    Name = SqlParsingCacheMetricPrefix + "/IBMDB2/Hits", CallCount = 1
                },
                new ExpectedCountMetric {
                    Name = SqlParsingCacheMetricPrefix + "/IBMDB2/Misses", CallCount = 1
                },
                new ExpectedCountMetric {
                    Name = SqlParsingCacheMetricPrefix + "/IBMDB2/Ejections", CallCount = 0
                },
                new ExpectedCountMetric {
                    Name = SqlParsingCacheMetricPrefix + "/IBMDB2/Size", CallCount = 1, Total = 1
                },

                new ExpectedCountMetric {
                    Name = SqlObfuscationMetricPrefix + "/MSSQL/Capacity", CallCount = 1, Total = defaultCapacity
                },
                new ExpectedCountMetric {
                    Name = SqlObfuscationMetricPrefix + "/MSSQL/Hits", CallCount = 3
                },
                new ExpectedCountMetric {
                    Name = SqlObfuscationMetricPrefix + "/MSSQL/Misses", CallCount = 2
                },
                new ExpectedCountMetric {
                    Name = SqlObfuscationMetricPrefix + "/MSSQL/Ejections", CallCount = 0
                },
                new ExpectedCountMetric {
                    Name = SqlObfuscationMetricPrefix + "/MSSQL/Size", CallCount = 1, Total = 2
                },

                new ExpectedCountMetric {
                    Name = SqlObfuscationMetricPrefix + "/IBMDB2/Capacity", CallCount = 1, Total = defaultCapacity
                },
                new ExpectedCountMetric {
                    Name = SqlObfuscationMetricPrefix + "/IBMDB2/Hits", CallCount = 1
                },
                new ExpectedCountMetric {
                    Name = SqlObfuscationMetricPrefix + "/IBMDB2/Misses", CallCount = 1
                },
                new ExpectedCountMetric {
                    Name = SqlObfuscationMetricPrefix + "/IBMDB2/Ejections", CallCount = 0
                },
                new ExpectedCountMetric {
                    Name = SqlObfuscationMetricPrefix + "/IBMDB2/Size", CallCount = 1, Total = 1
                }
            };

            var unexpectedMetrics = new List <ExpectedMetric>
            {
                new ExpectedCountMetric {
                    Name = SqlParsingCacheMetricPrefix + "/MongoDB/Hits"
                },
                new ExpectedCountMetric {
                    Name = SqlParsingCacheMetricPrefix + "/MongoDB/Misses"
                },
                new ExpectedCountMetric {
                    Name = SqlParsingCacheMetricPrefix + "/MongoDB/Ejections"
                },
                new ExpectedCountMetric {
                    Name = SqlParsingCacheMetricPrefix + "/MongoDB/Size"
                },

                new ExpectedCountMetric {
                    Name = SqlObfuscationMetricPrefix + "/MongoDB/Hits"
                },
                new ExpectedCountMetric {
                    Name = SqlObfuscationMetricPrefix + "/MongoDB/Misses"
                },
                new ExpectedCountMetric {
                    Name = SqlObfuscationMetricPrefix + "/MongoDB/Ejections"
                },
                new ExpectedCountMetric {
                    Name = SqlObfuscationMetricPrefix + "/MongoDB/Size"
                }
            };

            MetricAssertions.MetricsExist(expectedMetrics, _compositeTestAgent.Metrics);
            MetricAssertions.MetricsDoNotExist(unexpectedMetrics, _compositeTestAgent.Metrics);
        }