From 9f0e03be00b57bd75b9eebf0fd6c64f8c520d633 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Tue, 30 Aug 2022 11:35:25 -0700 Subject: [PATCH 01/14] Move validate_transaction_metrics to validators directory --- tests/adapter_cheroot/test_wsgi.py | 2 +- .../test_supportability_metrics.py | 2 +- tests/agent_features/test_time_trace.py | 2 +- tests/agent_features/test_transaction_name.py | 2 +- tests/application_celery/test_celery.py | 2 +- .../test_custom_conn_pool.py | 2 +- .../test_execute_command.py | 2 +- tests/datastore_aioredis/test_get_and_set.py | 2 +- tests/datastore_aioredis/test_multiple_dbs.py | 2 +- tests/datastore_bmemcached/test_memcache.py | 2 +- tests/datastore_mysql/test_database.py | 2 +- tests/datastore_postgresql/test_database.py | 2 +- tests/datastore_pylibmc/test_memcache.py | 2 +- tests/datastore_pymemcache/test_memcache.py | 2 +- tests/datastore_pysolr/test_solr.py | 2 +- tests/datastore_solrpy/test_solr.py | 2 +- tests/datastore_sqlite/test_database.py | 2 +- tests/datastore_umemcache/test_memcache.py | 2 +- tests/external_feedparser/test_feedparser.py | 2 +- tests/external_httplib/test_urllib.py | 3 +- tests/external_httplib/test_urllib2.py | 3 +- tests/framework_aiohttp/test_client.py | 2 +- .../test_client_async_await.py | 3 +- .../test_application_async.py | 3 +- tests/framework_ariadne/test_asgi.py | 3 +- tests/framework_ariadne/test_wsgi.py | 3 +- tests/framework_fastapi/test_application.py | 2 +- .../test_application_async.py | 3 +- tests/framework_starlette/test_bg_tasks.py | 2 +- tests/framework_starlette/test_graphql.py | 3 +- .../test_application_async.py | 3 +- tests/framework_strawberry/test_asgi.py | 3 +- .../framework_tornado/test_custom_handler.py | 2 +- .../test_pika_supportability.py | 2 +- tests/template_mako/test_mako.py | 2 +- .../validate_transaction_metrics.py | 135 ++++++++++++++++++ 36 files changed, 180 insertions(+), 35 deletions(-) create mode 100644 tests/testing_support/validators/validate_transaction_metrics.py diff --git a/tests/adapter_cheroot/test_wsgi.py b/tests/adapter_cheroot/test_wsgi.py index b59a12c2d0..49858e2f5f 100644 --- a/tests/adapter_cheroot/test_wsgi.py +++ b/tests/adapter_cheroot/test_wsgi.py @@ -16,7 +16,7 @@ import cheroot.wsgi import newrelic.api.transaction -from testing_support.fixtures import validate_transaction_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics def get_open_port(): diff --git a/tests/agent_features/test_supportability_metrics.py b/tests/agent_features/test_supportability_metrics.py index d3e4b9a690..d77502180b 100644 --- a/tests/agent_features/test_supportability_metrics.py +++ b/tests/agent_features/test_supportability_metrics.py @@ -20,7 +20,7 @@ from newrelic.core.agent import agent_instance -from testing_support.fixtures import validate_transaction_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_metric_payload import ( validate_metric_payload) diff --git a/tests/agent_features/test_time_trace.py b/tests/agent_features/test_time_trace.py index f81e8750d7..2b53b99853 100644 --- a/tests/agent_features/test_time_trace.py +++ b/tests/agent_features/test_time_trace.py @@ -14,7 +14,7 @@ import logging -from testing_support.fixtures import validate_transaction_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task from newrelic.api.function_trace import FunctionTrace diff --git a/tests/agent_features/test_transaction_name.py b/tests/agent_features/test_transaction_name.py index 492f64df33..beaf83b57e 100644 --- a/tests/agent_features/test_transaction_name.py +++ b/tests/agent_features/test_transaction_name.py @@ -15,7 +15,7 @@ from newrelic.api.background_task import background_task from newrelic.api.transaction import set_transaction_name, set_background_task -from testing_support.fixtures import validate_transaction_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics # test diff --git a/tests/application_celery/test_celery.py b/tests/application_celery/test_celery.py index 5bde177143..c2f9177fa5 100644 --- a/tests/application_celery/test_celery.py +++ b/tests/application_celery/test_celery.py @@ -15,7 +15,7 @@ from newrelic.api.background_task import background_task from newrelic.api.transaction import ignore_transaction, end_of_transaction -from testing_support.fixtures import validate_transaction_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics from tasks import add, tsum diff --git a/tests/datastore_aioredis/test_custom_conn_pool.py b/tests/datastore_aioredis/test_custom_conn_pool.py index 155765e5ae..9530961a4f 100644 --- a/tests/datastore_aioredis/test_custom_conn_pool.py +++ b/tests/datastore_aioredis/test_custom_conn_pool.py @@ -26,7 +26,7 @@ from newrelic.api.background_task import background_task # from testing_support.fixture.event_loop import event_loop as loop -from testing_support.fixtures import validate_transaction_metrics, override_application_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics, override_application_settings from testing_support.db_settings import redis_settings from testing_support.util import instance_hostname diff --git a/tests/datastore_aioredis/test_execute_command.py b/tests/datastore_aioredis/test_execute_command.py index 690007d6c6..89d6c5413e 100644 --- a/tests/datastore_aioredis/test_execute_command.py +++ b/tests/datastore_aioredis/test_execute_command.py @@ -16,7 +16,7 @@ import aioredis from newrelic.api.background_task import background_task -from testing_support.fixtures import validate_transaction_metrics, override_application_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics, override_application_settings from conftest import event_loop, loop, AIOREDIS_VERSION from testing_support.db_settings import redis_settings from testing_support.util import instance_hostname diff --git a/tests/datastore_aioredis/test_get_and_set.py b/tests/datastore_aioredis/test_get_and_set.py index b363f14d53..7e880f875a 100644 --- a/tests/datastore_aioredis/test_get_and_set.py +++ b/tests/datastore_aioredis/test_get_and_set.py @@ -18,7 +18,7 @@ from newrelic.api.background_task import background_task from conftest import event_loop, loop, AIOREDIS_VERSION -from testing_support.fixtures import validate_transaction_metrics, override_application_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics, override_application_settings from testing_support.db_settings import redis_settings from testing_support.util import instance_hostname diff --git a/tests/datastore_aioredis/test_multiple_dbs.py b/tests/datastore_aioredis/test_multiple_dbs.py index 248fb847d0..4ac98abf8a 100644 --- a/tests/datastore_aioredis/test_multiple_dbs.py +++ b/tests/datastore_aioredis/test_multiple_dbs.py @@ -16,7 +16,7 @@ import aioredis from newrelic.api.background_task import background_task -from testing_support.fixtures import validate_transaction_metrics, override_application_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics, override_application_settings from conftest import event_loop, loop, AIOREDIS_VERSION from testing_support.db_settings import redis_settings from testing_support.util import instance_hostname diff --git a/tests/datastore_bmemcached/test_memcache.py b/tests/datastore_bmemcached/test_memcache.py index 1bef31f592..68eee06333 100644 --- a/tests/datastore_bmemcached/test_memcache.py +++ b/tests/datastore_bmemcached/test_memcache.py @@ -19,7 +19,7 @@ from newrelic.api.background_task import background_task from newrelic.api.transaction import set_background_task -from testing_support.fixtures import validate_transaction_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.db_settings import memcached_settings diff --git a/tests/datastore_mysql/test_database.py b/tests/datastore_mysql/test_database.py index 0991d6df0e..2fc8ca129b 100644 --- a/tests/datastore_mysql/test_database.py +++ b/tests/datastore_mysql/test_database.py @@ -14,7 +14,7 @@ import mysql.connector -from testing_support.fixtures import validate_transaction_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_database_trace_inputs import validate_database_trace_inputs from testing_support.db_settings import mysql_settings diff --git a/tests/datastore_postgresql/test_database.py b/tests/datastore_postgresql/test_database.py index de53808c62..2ea930b051 100644 --- a/tests/datastore_postgresql/test_database.py +++ b/tests/datastore_postgresql/test_database.py @@ -15,7 +15,7 @@ import postgresql.driver.dbapi20 -from testing_support.fixtures import validate_transaction_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_database_trace_inputs import ( validate_database_trace_inputs, diff --git a/tests/datastore_pylibmc/test_memcache.py b/tests/datastore_pylibmc/test_memcache.py index 554581fdc9..769f3b483c 100644 --- a/tests/datastore_pylibmc/test_memcache.py +++ b/tests/datastore_pylibmc/test_memcache.py @@ -17,7 +17,7 @@ import pylibmc from testing_support.db_settings import memcached_settings -from testing_support.fixtures import validate_transaction_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task from newrelic.api.transaction import set_background_task diff --git a/tests/datastore_pymemcache/test_memcache.py b/tests/datastore_pymemcache/test_memcache.py index 12bd5da1a4..9aeea4d54d 100644 --- a/tests/datastore_pymemcache/test_memcache.py +++ b/tests/datastore_pymemcache/test_memcache.py @@ -16,7 +16,7 @@ import pymemcache.client -from testing_support.fixtures import validate_transaction_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.db_settings import memcached_settings from newrelic.api.background_task import background_task diff --git a/tests/datastore_pysolr/test_solr.py b/tests/datastore_pysolr/test_solr.py index 785c3cb9f9..a987a29ac9 100644 --- a/tests/datastore_pysolr/test_solr.py +++ b/tests/datastore_pysolr/test_solr.py @@ -14,7 +14,7 @@ from pysolr import Solr -from testing_support.fixtures import validate_transaction_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.db_settings import solr_settings from newrelic.api.background_task import background_task diff --git a/tests/datastore_solrpy/test_solr.py b/tests/datastore_solrpy/test_solr.py index 86dc23d4ad..ee1a7e91ef 100644 --- a/tests/datastore_solrpy/test_solr.py +++ b/tests/datastore_solrpy/test_solr.py @@ -14,7 +14,7 @@ from solr import SolrConnection -from testing_support.fixtures import validate_transaction_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.db_settings import solr_settings from newrelic.api.background_task import background_task diff --git a/tests/datastore_sqlite/test_database.py b/tests/datastore_sqlite/test_database.py index 5443ca1c99..4ca534c396 100644 --- a/tests/datastore_sqlite/test_database.py +++ b/tests/datastore_sqlite/test_database.py @@ -18,7 +18,7 @@ is_pypy = hasattr(sys, 'pypy_version_info') -from testing_support.fixtures import validate_transaction_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_database_trace_inputs import validate_database_trace_inputs from newrelic.api.background_task import background_task diff --git a/tests/datastore_umemcache/test_memcache.py b/tests/datastore_umemcache/test_memcache.py index ce6475a49e..4683a20d59 100644 --- a/tests/datastore_umemcache/test_memcache.py +++ b/tests/datastore_umemcache/test_memcache.py @@ -17,7 +17,7 @@ import umemcache from testing_support.db_settings import memcached_settings -from testing_support.fixtures import validate_transaction_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task from newrelic.api.transaction import set_background_task diff --git a/tests/external_feedparser/test_feedparser.py b/tests/external_feedparser/test_feedparser.py index 9cb175711d..5e515cfc30 100644 --- a/tests/external_feedparser/test_feedparser.py +++ b/tests/external_feedparser/test_feedparser.py @@ -14,7 +14,7 @@ import pytest from newrelic.api.background_task import background_task -from testing_support.fixtures import validate_transaction_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics @pytest.fixture(scope="session") diff --git a/tests/external_httplib/test_urllib.py b/tests/external_httplib/test_urllib.py index 38cf4f7135..cea88a8dde 100644 --- a/tests/external_httplib/test_urllib.py +++ b/tests/external_httplib/test_urllib.py @@ -25,7 +25,8 @@ cache_outgoing_headers, insert_incoming_headers, ) -from testing_support.fixtures import cat_enabled, validate_transaction_metrics +from testing_support.fixtures import cat_enabled +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_cross_process_headers import ( validate_cross_process_headers, ) diff --git a/tests/external_httplib/test_urllib2.py b/tests/external_httplib/test_urllib2.py index cbcb25a2f9..62ed230745 100644 --- a/tests/external_httplib/test_urllib2.py +++ b/tests/external_httplib/test_urllib2.py @@ -25,7 +25,8 @@ cache_outgoing_headers, insert_incoming_headers, ) -from testing_support.fixtures import cat_enabled, validate_transaction_metrics +from testing_support.fixtures import cat_enabled +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_cross_process_headers import ( validate_cross_process_headers, ) diff --git a/tests/framework_aiohttp/test_client.py b/tests/framework_aiohttp/test_client.py index b2d23dd235..172d349bb4 100644 --- a/tests/framework_aiohttp/test_client.py +++ b/tests/framework_aiohttp/test_client.py @@ -16,7 +16,7 @@ import aiohttp import pytest -from testing_support.fixtures import validate_transaction_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from yarl import URL from newrelic.api.background_task import background_task diff --git a/tests/framework_aiohttp/test_client_async_await.py b/tests/framework_aiohttp/test_client_async_await.py index 1e3eb79ec5..dedc64c9db 100644 --- a/tests/framework_aiohttp/test_client_async_await.py +++ b/tests/framework_aiohttp/test_client_async_await.py @@ -16,7 +16,8 @@ import aiohttp import pytest -from testing_support.fixtures import cat_enabled, validate_transaction_metrics +from testing_support.fixtures import cat_enabled +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from yarl import URL from newrelic.api.background_task import background_task diff --git a/tests/framework_ariadne/test_application_async.py b/tests/framework_ariadne/test_application_async.py index 8e46752f20..ada34ffade 100644 --- a/tests/framework_ariadne/test_application_async.py +++ b/tests/framework_ariadne/test_application_async.py @@ -15,7 +15,8 @@ import asyncio import pytest -from testing_support.fixtures import dt_enabled, validate_transaction_metrics +from testing_support.fixtures import dt_enabled +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_span_events import validate_span_events from newrelic.api.background_task import background_task diff --git a/tests/framework_ariadne/test_asgi.py b/tests/framework_ariadne/test_asgi.py index 6275e781f4..861f2aa932 100644 --- a/tests/framework_ariadne/test_asgi.py +++ b/tests/framework_ariadne/test_asgi.py @@ -16,7 +16,8 @@ import pytest from testing_support.asgi_testing import AsgiTest -from testing_support.fixtures import dt_enabled, validate_transaction_metrics +from testing_support.fixtures import dt_enabled +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_span_events import validate_span_events diff --git a/tests/framework_ariadne/test_wsgi.py b/tests/framework_ariadne/test_wsgi.py index 2c11276ed0..9ce2373d47 100644 --- a/tests/framework_ariadne/test_wsgi.py +++ b/tests/framework_ariadne/test_wsgi.py @@ -14,7 +14,8 @@ import pytest import webtest -from testing_support.fixtures import dt_enabled, validate_transaction_metrics +from testing_support.fixtures import dt_enabled +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_span_events import validate_span_events diff --git a/tests/framework_fastapi/test_application.py b/tests/framework_fastapi/test_application.py index 8fe4be34f8..85d230e26b 100644 --- a/tests/framework_fastapi/test_application.py +++ b/tests/framework_fastapi/test_application.py @@ -15,7 +15,7 @@ import logging import pytest -from testing_support.fixtures import validate_transaction_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics diff --git a/tests/framework_graphql/test_application_async.py b/tests/framework_graphql/test_application_async.py index 19b8b14936..28b435c436 100644 --- a/tests/framework_graphql/test_application_async.py +++ b/tests/framework_graphql/test_application_async.py @@ -16,7 +16,8 @@ import pytest from test_application import is_graphql_2 -from testing_support.fixtures import dt_enabled, validate_transaction_metrics +from testing_support.fixtures import dt_enabled +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_span_events import validate_span_events from newrelic.api.background_task import background_task diff --git a/tests/framework_starlette/test_bg_tasks.py b/tests/framework_starlette/test_bg_tasks.py index af929895f6..3a5a78bf2e 100644 --- a/tests/framework_starlette/test_bg_tasks.py +++ b/tests/framework_starlette/test_bg_tasks.py @@ -14,7 +14,7 @@ import pytest import sys -from testing_support.fixtures import validate_transaction_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_transaction_count import ( validate_transaction_count, ) diff --git a/tests/framework_starlette/test_graphql.py b/tests/framework_starlette/test_graphql.py index 241371eb1b..24ec3ab38c 100644 --- a/tests/framework_starlette/test_graphql.py +++ b/tests/framework_starlette/test_graphql.py @@ -15,7 +15,8 @@ import json import pytest -from testing_support.fixtures import dt_enabled, validate_transaction_metrics +from testing_support.fixtures import dt_enabled +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_span_events import validate_span_events diff --git a/tests/framework_strawberry/test_application_async.py b/tests/framework_strawberry/test_application_async.py index 8174eb36ee..1354c4c01c 100644 --- a/tests/framework_strawberry/test_application_async.py +++ b/tests/framework_strawberry/test_application_async.py @@ -15,7 +15,8 @@ import asyncio import pytest -from testing_support.fixtures import dt_enabled, validate_transaction_metrics +from testing_support.fixtures import dt_enabled +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_span_events import validate_span_events from newrelic.api.background_task import background_task diff --git a/tests/framework_strawberry/test_asgi.py b/tests/framework_strawberry/test_asgi.py index 0db1e8a58f..8acbaedfba 100644 --- a/tests/framework_strawberry/test_asgi.py +++ b/tests/framework_strawberry/test_asgi.py @@ -16,7 +16,8 @@ import pytest from testing_support.asgi_testing import AsgiTest -from testing_support.fixtures import dt_enabled, validate_transaction_metrics +from testing_support.fixtures import dt_enabled +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_span_events import validate_span_events diff --git a/tests/framework_tornado/test_custom_handler.py b/tests/framework_tornado/test_custom_handler.py index 4cabc5e1f2..a8cb77d76f 100644 --- a/tests/framework_tornado/test_custom_handler.py +++ b/tests/framework_tornado/test_custom_handler.py @@ -13,7 +13,7 @@ # limitations under the License. import pytest -from testing_support.fixtures import validate_transaction_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics pytestmark = pytest.mark.custom_app diff --git a/tests/messagebroker_pika/test_pika_supportability.py b/tests/messagebroker_pika/test_pika_supportability.py index fa0e466396..9f0d94e90f 100644 --- a/tests/messagebroker_pika/test_pika_supportability.py +++ b/tests/messagebroker_pika/test_pika_supportability.py @@ -19,7 +19,7 @@ from newrelic.api.background_task import background_task from conftest import QUEUE, BODY -from testing_support.fixtures import validate_transaction_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.db_settings import rabbitmq_settings DB_SETTINGS = rabbitmq_settings()[0] diff --git a/tests/template_mako/test_mako.py b/tests/template_mako/test_mako.py index fd598d7869..07d8f4974e 100644 --- a/tests/template_mako/test_mako.py +++ b/tests/template_mako/test_mako.py @@ -13,7 +13,7 @@ # limitations under the License. from mako.template import Template -from testing_support.fixtures import validate_transaction_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task diff --git a/tests/testing_support/validators/validate_transaction_metrics.py b/tests/testing_support/validators/validate_transaction_metrics.py new file mode 100644 index 0000000000..7122b009aa --- /dev/null +++ b/tests/testing_support/validators/validate_transaction_metrics.py @@ -0,0 +1,135 @@ +# Copyright 2010 New Relic, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import copy + +from newrelic.common.object_wrapper import ( + function_wrapper, + transient_function_wrapper, +) +from testing_support.fixtures import catch_background_exceptions + +def validate_transaction_metrics( + name, + group="Function", + background_task=False, + scoped_metrics=None, + rollup_metrics=None, + custom_metrics=None, + index=-1, +): + scoped_metrics = scoped_metrics or [] + rollup_metrics = rollup_metrics or [] + custom_metrics = custom_metrics or [] + + if background_task: + unscoped_metrics = [ + "OtherTransaction/all", + "OtherTransaction/%s/%s" % (group, name), + "OtherTransactionTotalTime", + "OtherTransactionTotalTime/%s/%s" % (group, name), + ] + transaction_scope_name = "OtherTransaction/%s/%s" % (group, name) + else: + unscoped_metrics = [ + "WebTransaction", + "WebTransaction/%s/%s" % (group, name), + "WebTransactionTotalTime", + "WebTransactionTotalTime/%s/%s" % (group, name), + "HttpDispatcher", + ] + transaction_scope_name = "WebTransaction/%s/%s" % (group, name) + + @function_wrapper + def _validate_wrapper(wrapped, instance, args, kwargs): + + record_transaction_called = [] + recorded_metrics = [] + + @transient_function_wrapper("newrelic.core.stats_engine", "StatsEngine.record_transaction") + @catch_background_exceptions + def _validate_transaction_metrics(wrapped, instance, args, kwargs): + record_transaction_called.append(True) + try: + result = wrapped(*args, **kwargs) + except: + raise + else: + metrics = instance.stats_table + # Record a copy of the metric value so that the values aren't + # merged in the future + _metrics = {} + for k, v in metrics.items(): + _metrics[k] = copy.copy(v) + recorded_metrics.append(_metrics) + + return result + + def _validate(metrics, name, scope, count): + key = (name, scope) + metric = metrics.get(key) + + def _metrics_table(): + out = [""] + out.append("Expected: {0}: {1}".format(key, count)) + for metric_key, metric_value in metrics.items(): + out.append("{0}: {1}".format(metric_key, metric_value[0])) + return "\n".join(out) + + def _metric_details(): + return "metric=%r, count=%r" % (key, metric.call_count) + + if count is not None: + assert metric is not None, _metrics_table() + if count == "present": + assert metric.call_count > 0, _metric_details() + else: + assert metric.call_count == count, _metric_details() + + assert metric.total_call_time >= 0, (key, metric) + assert metric.total_exclusive_call_time >= 0, (key, metric) + assert metric.min_call_time >= 0, (key, metric) + assert metric.sum_of_squares >= 0, (key, metric) + + else: + assert metric is None, _metrics_table() + + _new_wrapper = _validate_transaction_metrics(wrapped) + val = _new_wrapper(*args, **kwargs) + assert record_transaction_called + metrics = recorded_metrics[index] + + record_transaction_called[:] = [] + recorded_metrics[:] = [] + + for unscoped_metric in unscoped_metrics: + _validate(metrics, unscoped_metric, "", 1) + + for scoped_name, scoped_count in scoped_metrics: + _validate(metrics, scoped_name, transaction_scope_name, scoped_count) + + for rollup_name, rollup_count in rollup_metrics: + _validate(metrics, rollup_name, "", rollup_count) + + for custom_name, custom_count in custom_metrics: + _validate(metrics, custom_name, "", custom_count) + + custom_metric_names = {name for name, _ in custom_metrics} + for name, _ in metrics: + if name not in custom_metric_names: + assert not name.startswith("Supportability/api/"), name + + return val + + return _validate_wrapper \ No newline at end of file From f3d788f129f9ddef6d67dc4a17f9f51388a4d07f Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Tue, 30 Aug 2022 11:38:22 -0700 Subject: [PATCH 02/14] Comment out original validate_transaction_metrics from fixtures.py --- tests/testing_support/fixtures.py | 226 +++++++++++++++--------------- 1 file changed, 113 insertions(+), 113 deletions(-) diff --git a/tests/testing_support/fixtures.py b/tests/testing_support/fixtures.py index a897303774..e70c900c49 100644 --- a/tests/testing_support/fixtures.py +++ b/tests/testing_support/fixtures.py @@ -385,119 +385,119 @@ def make_synthetics_header(account_id, resource_id, job_id, monitor_id, encoding return {"X-NewRelic-Synthetics": value} -def validate_transaction_metrics( - name, - group="Function", - background_task=False, - scoped_metrics=None, - rollup_metrics=None, - custom_metrics=None, - index=-1, -): - scoped_metrics = scoped_metrics or [] - rollup_metrics = rollup_metrics or [] - custom_metrics = custom_metrics or [] - - if background_task: - unscoped_metrics = [ - "OtherTransaction/all", - "OtherTransaction/%s/%s" % (group, name), - "OtherTransactionTotalTime", - "OtherTransactionTotalTime/%s/%s" % (group, name), - ] - transaction_scope_name = "OtherTransaction/%s/%s" % (group, name) - else: - unscoped_metrics = [ - "WebTransaction", - "WebTransaction/%s/%s" % (group, name), - "WebTransactionTotalTime", - "WebTransactionTotalTime/%s/%s" % (group, name), - "HttpDispatcher", - ] - transaction_scope_name = "WebTransaction/%s/%s" % (group, name) - - @function_wrapper - def _validate_wrapper(wrapped, instance, args, kwargs): - - record_transaction_called = [] - recorded_metrics = [] - - @transient_function_wrapper("newrelic.core.stats_engine", "StatsEngine.record_transaction") - @catch_background_exceptions - def _validate_transaction_metrics(wrapped, instance, args, kwargs): - record_transaction_called.append(True) - try: - result = wrapped(*args, **kwargs) - except: - raise - else: - metrics = instance.stats_table - # Record a copy of the metric value so that the values aren't - # merged in the future - _metrics = {} - for k, v in metrics.items(): - _metrics[k] = copy.copy(v) - recorded_metrics.append(_metrics) - - return result - - def _validate(metrics, name, scope, count): - key = (name, scope) - metric = metrics.get(key) - - def _metrics_table(): - out = [""] - out.append("Expected: {0}: {1}".format(key, count)) - for metric_key, metric_value in metrics.items(): - out.append("{0}: {1}".format(metric_key, metric_value[0])) - return "\n".join(out) - - def _metric_details(): - return "metric=%r, count=%r" % (key, metric.call_count) - - if count is not None: - assert metric is not None, _metrics_table() - if count == "present": - assert metric.call_count > 0, _metric_details() - else: - assert metric.call_count == count, _metric_details() - - assert metric.total_call_time >= 0, (key, metric) - assert metric.total_exclusive_call_time >= 0, (key, metric) - assert metric.min_call_time >= 0, (key, metric) - assert metric.sum_of_squares >= 0, (key, metric) - - else: - assert metric is None, _metrics_table() - - _new_wrapper = _validate_transaction_metrics(wrapped) - val = _new_wrapper(*args, **kwargs) - assert record_transaction_called - metrics = recorded_metrics[index] - - record_transaction_called[:] = [] - recorded_metrics[:] = [] - - for unscoped_metric in unscoped_metrics: - _validate(metrics, unscoped_metric, "", 1) - - for scoped_name, scoped_count in scoped_metrics: - _validate(metrics, scoped_name, transaction_scope_name, scoped_count) - - for rollup_name, rollup_count in rollup_metrics: - _validate(metrics, rollup_name, "", rollup_count) - - for custom_name, custom_count in custom_metrics: - _validate(metrics, custom_name, "", custom_count) - - custom_metric_names = {name for name, _ in custom_metrics} - for name, _ in metrics: - if name not in custom_metric_names: - assert not name.startswith("Supportability/api/"), name - - return val - - return _validate_wrapper +# def validate_transaction_metrics( +# name, +# group="Function", +# background_task=False, +# scoped_metrics=None, +# rollup_metrics=None, +# custom_metrics=None, +# index=-1, +# ): +# scoped_metrics = scoped_metrics or [] +# rollup_metrics = rollup_metrics or [] +# custom_metrics = custom_metrics or [] + +# if background_task: +# unscoped_metrics = [ +# "OtherTransaction/all", +# "OtherTransaction/%s/%s" % (group, name), +# "OtherTransactionTotalTime", +# "OtherTransactionTotalTime/%s/%s" % (group, name), +# ] +# transaction_scope_name = "OtherTransaction/%s/%s" % (group, name) +# else: +# unscoped_metrics = [ +# "WebTransaction", +# "WebTransaction/%s/%s" % (group, name), +# "WebTransactionTotalTime", +# "WebTransactionTotalTime/%s/%s" % (group, name), +# "HttpDispatcher", +# ] +# transaction_scope_name = "WebTransaction/%s/%s" % (group, name) + +# @function_wrapper +# def _validate_wrapper(wrapped, instance, args, kwargs): + +# record_transaction_called = [] +# recorded_metrics = [] + +# @transient_function_wrapper("newrelic.core.stats_engine", "StatsEngine.record_transaction") +# @catch_background_exceptions +# def _validate_transaction_metrics(wrapped, instance, args, kwargs): +# record_transaction_called.append(True) +# try: +# result = wrapped(*args, **kwargs) +# except: +# raise +# else: +# metrics = instance.stats_table +# # Record a copy of the metric value so that the values aren't +# # merged in the future +# _metrics = {} +# for k, v in metrics.items(): +# _metrics[k] = copy.copy(v) +# recorded_metrics.append(_metrics) + +# return result + +# def _validate(metrics, name, scope, count): +# key = (name, scope) +# metric = metrics.get(key) + +# def _metrics_table(): +# out = [""] +# out.append("Expected: {0}: {1}".format(key, count)) +# for metric_key, metric_value in metrics.items(): +# out.append("{0}: {1}".format(metric_key, metric_value[0])) +# return "\n".join(out) + +# def _metric_details(): +# return "metric=%r, count=%r" % (key, metric.call_count) + +# if count is not None: +# assert metric is not None, _metrics_table() +# if count == "present": +# assert metric.call_count > 0, _metric_details() +# else: +# assert metric.call_count == count, _metric_details() + +# assert metric.total_call_time >= 0, (key, metric) +# assert metric.total_exclusive_call_time >= 0, (key, metric) +# assert metric.min_call_time >= 0, (key, metric) +# assert metric.sum_of_squares >= 0, (key, metric) + +# else: +# assert metric is None, _metrics_table() + +# _new_wrapper = _validate_transaction_metrics(wrapped) +# val = _new_wrapper(*args, **kwargs) +# assert record_transaction_called +# metrics = recorded_metrics[index] + +# record_transaction_called[:] = [] +# recorded_metrics[:] = [] + +# for unscoped_metric in unscoped_metrics: +# _validate(metrics, unscoped_metric, "", 1) + +# for scoped_name, scoped_count in scoped_metrics: +# _validate(metrics, scoped_name, transaction_scope_name, scoped_count) + +# for rollup_name, rollup_count in rollup_metrics: +# _validate(metrics, rollup_name, "", rollup_count) + +# for custom_name, custom_count in custom_metrics: +# _validate(metrics, custom_name, "", custom_count) + +# custom_metric_names = {name for name, _ in custom_metrics} +# for name, _ in metrics: +# if name not in custom_metric_names: +# assert not name.startswith("Supportability/api/"), name + +# return val + +# return _validate_wrapper def validate_time_metrics_outside_transaction(time_metrics=None, index=-1): From 96e752f951f9921ca5025d1904022ca20a3ea7b9 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Tue, 30 Aug 2022 11:45:40 -0700 Subject: [PATCH 03/14] Move validate_time_metrics_outside_transaction to validators directory --- .../test_ignore_expected_errors.py | 2 +- tests/testing_support/fixtures.py | 112 +++++++++--------- ...lidate_time_metrics_outside_transaction.py | 93 +++++++++++++++ 3 files changed, 150 insertions(+), 57 deletions(-) create mode 100644 tests/testing_support/validators/validate_time_metrics_outside_transaction.py diff --git a/tests/agent_features/test_ignore_expected_errors.py b/tests/agent_features/test_ignore_expected_errors.py index 7adc07e1c1..b044c8fa52 100644 --- a/tests/agent_features/test_ignore_expected_errors.py +++ b/tests/agent_features/test_ignore_expected_errors.py @@ -19,11 +19,11 @@ validate_error_event_attributes_outside_transaction, validate_error_event_sample_data, validate_error_trace_attributes_outside_transaction, - validate_time_metrics_outside_transaction, validate_transaction_error_trace_attributes, validate_transaction_errors, validate_transaction_metrics, ) +from testing_support.validators.validate_time_metrics_outside_transaction import validate_time_metrics_outside_transaction from newrelic.api.application import application_instance from newrelic.api.background_task import background_task diff --git a/tests/testing_support/fixtures.py b/tests/testing_support/fixtures.py index e70c900c49..30c0815f00 100644 --- a/tests/testing_support/fixtures.py +++ b/tests/testing_support/fixtures.py @@ -500,77 +500,77 @@ def make_synthetics_header(account_id, resource_id, job_id, monitor_id, encoding # return _validate_wrapper -def validate_time_metrics_outside_transaction(time_metrics=None, index=-1): - time_metrics = time_metrics or [] +# def validate_time_metrics_outside_transaction(time_metrics=None, index=-1): +# time_metrics = time_metrics or [] - @function_wrapper - def _validate_wrapper(wrapped, instance, args, kwargs): +# @function_wrapper +# def _validate_wrapper(wrapped, instance, args, kwargs): - record_time_metric_called = [] - recorded_metrics = [] +# record_time_metric_called = [] +# recorded_metrics = [] - @transient_function_wrapper("newrelic.core.stats_engine", "StatsEngine.record_time_metric") - @catch_background_exceptions - def _validate_transaction_metrics(wrapped, instance, args, kwargs): - record_time_metric_called.append(True) - try: - result = wrapped(*args, **kwargs) - except: - raise - else: - metrics = instance.stats_table - # Record a copy of the metric value so that the values aren't - # merged in the future - _metrics = {} - for k, v in metrics.items(): - _metrics[k] = copy.copy(v) - recorded_metrics.append(_metrics) +# @transient_function_wrapper("newrelic.core.stats_engine", "StatsEngine.record_time_metric") +# @catch_background_exceptions +# def _validate_transaction_metrics(wrapped, instance, args, kwargs): +# record_time_metric_called.append(True) +# try: +# result = wrapped(*args, **kwargs) +# except: +# raise +# else: +# metrics = instance.stats_table +# # Record a copy of the metric value so that the values aren't +# # merged in the future +# _metrics = {} +# for k, v in metrics.items(): +# _metrics[k] = copy.copy(v) +# recorded_metrics.append(_metrics) - return result +# return result - def _validate(metrics, name, count): - key = (name, "") - metric = metrics.get(key) +# def _validate(metrics, name, count): +# key = (name, "") +# metric = metrics.get(key) - def _metrics_table(): - out = [""] - out.append("Expected: {0}: {1}".format(key, count)) - for metric_key, metric_value in metrics.items(): - out.append("{0}: {1}".format(metric_key, metric_value[0])) - return "\n".join(out) +# def _metrics_table(): +# out = [""] +# out.append("Expected: {0}: {1}".format(key, count)) +# for metric_key, metric_value in metrics.items(): +# out.append("{0}: {1}".format(metric_key, metric_value[0])) +# return "\n".join(out) - def _metric_details(): - return "metric=%r, count=%r" % (key, metric.call_count) +# def _metric_details(): +# return "metric=%r, count=%r" % (key, metric.call_count) - if count is not None: - assert metric is not None, _metrics_table() - if count == "present": - assert metric.call_count > 0, _metric_details() - else: - assert metric.call_count == count, _metric_details() +# if count is not None: +# assert metric is not None, _metrics_table() +# if count == "present": +# assert metric.call_count > 0, _metric_details() +# else: +# assert metric.call_count == count, _metric_details() - assert metric.total_call_time >= 0, (key, metric) - assert metric.total_exclusive_call_time >= 0, (key, metric) - assert metric.min_call_time >= 0, (key, metric) - assert metric.sum_of_squares >= 0, (key, metric) +# assert metric.total_call_time >= 0, (key, metric) +# assert metric.total_exclusive_call_time >= 0, (key, metric) +# assert metric.min_call_time >= 0, (key, metric) +# assert metric.sum_of_squares >= 0, (key, metric) - else: - assert metric is None, _metrics_table() +# else: +# assert metric is None, _metrics_table() - _new_wrapper = _validate_transaction_metrics(wrapped) - val = _new_wrapper(*args, **kwargs) - assert record_time_metric_called - metrics = recorded_metrics[index] +# _new_wrapper = _validate_transaction_metrics(wrapped) +# val = _new_wrapper(*args, **kwargs) +# assert record_time_metric_called +# metrics = recorded_metrics[index] - record_time_metric_called[:] = [] - recorded_metrics[:] = [] +# record_time_metric_called[:] = [] +# recorded_metrics[:] = [] - for time_metric, count in time_metrics: - _validate(metrics, time_metric, count) +# for time_metric, count in time_metrics: +# _validate(metrics, time_metric, count) - return val +# return val - return _validate_wrapper +# return _validate_wrapper def capture_transaction_metrics(metrics_list, full_metrics=None): diff --git a/tests/testing_support/validators/validate_time_metrics_outside_transaction.py b/tests/testing_support/validators/validate_time_metrics_outside_transaction.py new file mode 100644 index 0000000000..1f6173a67d --- /dev/null +++ b/tests/testing_support/validators/validate_time_metrics_outside_transaction.py @@ -0,0 +1,93 @@ +# Copyright 2010 New Relic, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import copy + +from newrelic.common.object_wrapper import ( + function_wrapper, + transient_function_wrapper, +) +from testing_support.fixtures import catch_background_exceptions + +def validate_time_metrics_outside_transaction(time_metrics=None, index=-1): + time_metrics = time_metrics or [] + + @function_wrapper + def _validate_wrapper(wrapped, instance, args, kwargs): + + record_time_metric_called = [] + recorded_metrics = [] + + @transient_function_wrapper("newrelic.core.stats_engine", "StatsEngine.record_time_metric") + @catch_background_exceptions + def _validate_transaction_metrics(wrapped, instance, args, kwargs): + record_time_metric_called.append(True) + try: + result = wrapped(*args, **kwargs) + except: + raise + else: + metrics = instance.stats_table + # Record a copy of the metric value so that the values aren't + # merged in the future + _metrics = {} + for k, v in metrics.items(): + _metrics[k] = copy.copy(v) + recorded_metrics.append(_metrics) + + return result + + def _validate(metrics, name, count): + key = (name, "") + metric = metrics.get(key) + + def _metrics_table(): + out = [""] + out.append("Expected: {0}: {1}".format(key, count)) + for metric_key, metric_value in metrics.items(): + out.append("{0}: {1}".format(metric_key, metric_value[0])) + return "\n".join(out) + + def _metric_details(): + return "metric=%r, count=%r" % (key, metric.call_count) + + if count is not None: + assert metric is not None, _metrics_table() + if count == "present": + assert metric.call_count > 0, _metric_details() + else: + assert metric.call_count == count, _metric_details() + + assert metric.total_call_time >= 0, (key, metric) + assert metric.total_exclusive_call_time >= 0, (key, metric) + assert metric.min_call_time >= 0, (key, metric) + assert metric.sum_of_squares >= 0, (key, metric) + + else: + assert metric is None, _metrics_table() + + _new_wrapper = _validate_transaction_metrics(wrapped) + val = _new_wrapper(*args, **kwargs) + assert record_time_metric_called + metrics = recorded_metrics[index] + + record_time_metric_called[:] = [] + recorded_metrics[:] = [] + + for time_metric, count in time_metrics: + _validate(metrics, time_metric, count) + + return val + + return _validate_wrapper From 16d0361f0a96cf1faa4964e76fe6e978138098b0 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Tue, 30 Aug 2022 12:26:05 -0700 Subject: [PATCH 04/14] Move validate_internal_metrics into validators directory and fixed validate_transaction_metrics --- tests/adapter_daphne/test_daphne.py | 2 +- tests/adapter_uvicorn/test_uvicorn.py | 2 +- .../_test_async_coroutine_trace.py | 2 +- .../test_asgi_distributed_tracing.py | 4 +- tests/agent_features/test_asgi_transaction.py | 2 +- .../test_asgi_w3c_trace_context.py | 3 +- tests/agent_features/test_function_trace.py | 5 +- tests/agent_features/test_web_transaction.py | 4 +- tests/agent_unittests/test_agent_connect.py | 3 +- .../test_application.py | 6 +- .../component_flask_rest/test_application.py | 6 +- tests/component_tastypie/test_application.py | 6 +- .../cross_agent/test_aws_utilization_data.py | 2 +- .../test_azure_utilization_data.py | 2 +- .../test_boot_id_utilization_data.py | 2 +- .../cross_agent/test_gcp_utilization_data.py | 2 +- .../cross_agent/test_pcf_utilization_data.py | 2 +- .../datastore_aredis/test_custom_conn_pool.py | 4 +- .../datastore_aredis/test_execute_command.py | 4 +- tests/datastore_aredis/test_get_and_set.py | 4 +- .../test_elasticsearch.py | 6 +- tests/datastore_elasticsearch/test_mget.py | 4 +- .../test_multiple_dbs.py | 4 +- tests/datastore_memcache/test_memcache.py | 4 +- tests/datastore_memcache/test_multiple_dbs.py | 4 +- tests/datastore_psycopg2/test_async.py | 3 +- tests/datastore_psycopg2/test_cursor.py | 4 +- tests/datastore_psycopg2/test_multiple_dbs.py | 4 +- tests/datastore_psycopg2/test_register.py | 4 +- tests/datastore_psycopg2/test_rollback.py | 4 +- tests/datastore_psycopg2cffi/test_database.py | 3 +- .../test_pyelasticsearch.py | 4 +- tests/datastore_pymysql/test_database.py | 3 +- .../datastore_redis/test_custom_conn_pool.py | 4 +- tests/datastore_redis/test_execute_command.py | 4 +- tests/datastore_redis/test_get_and_set.py | 4 +- tests/datastore_redis/test_multiple_dbs.py | 4 +- tests/datastore_redis/test_rb.py | 4 +- tests/external_boto3/test_boto3_iam.py | 3 +- tests/external_boto3/test_boto3_s3.py | 7 +- tests/external_boto3/test_boto3_sns.py | 6 +- .../test_botocore_dynamodb.py | 3 +- tests/external_botocore/test_botocore_ec2.py | 3 +- tests/external_botocore/test_botocore_s3.py | 4 +- tests/external_botocore/test_botocore_sqs.py | 4 +- tests/framework_aiohttp/test_externals.py | 4 +- tests/framework_aiohttp/test_middleware.py | 4 +- tests/framework_aiohttp/test_server.py | 3 +- tests/framework_bottle/test_application.py | 4 +- tests/framework_django/test_application.py | 3 +- .../framework_django/test_asgi_application.py | 3 +- tests/framework_falcon/test_application.py | 3 +- tests/framework_flask/test_application.py | 3 +- tests/framework_flask/test_blueprints.py | 3 +- tests/framework_flask/test_compress.py | 3 +- tests/framework_flask/test_middleware.py | 3 +- tests/framework_flask/test_not_found.py | 4 +- tests/framework_flask/test_user_exceptions.py | 4 +- tests/framework_grpc/test_clients.py | 4 +- tests/framework_grpc/test_server.py | 4 +- .../test_append_slash_app.py | 4 +- tests/framework_pyramid/test_application.py | 3 +- tests/framework_sanic/test_application.py | 4 +- tests/framework_tornado/test_server.py | 4 +- ...a_blocking_connection_consume_generator.py | 4 +- tests/testing_support/fixtures.py | 66 +++++++++---------- .../validators/validate_internal_metrics.py | 64 ++++++++++++++++++ 67 files changed, 226 insertions(+), 143 deletions(-) create mode 100644 tests/testing_support/validators/validate_internal_metrics.py diff --git a/tests/adapter_daphne/test_daphne.py b/tests/adapter_daphne/test_daphne.py index 4953e9a9ff..a289e13115 100644 --- a/tests/adapter_daphne/test_daphne.py +++ b/tests/adapter_daphne/test_daphne.py @@ -22,9 +22,9 @@ override_application_settings, raise_background_exceptions, validate_transaction_errors, - validate_transaction_metrics, wait_for_background_threads, ) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.sample_asgi_applications import ( AppWithCall, AppWithCallRaw, diff --git a/tests/adapter_uvicorn/test_uvicorn.py b/tests/adapter_uvicorn/test_uvicorn.py index e3261f4e87..8d81778fc1 100644 --- a/tests/adapter_uvicorn/test_uvicorn.py +++ b/tests/adapter_uvicorn/test_uvicorn.py @@ -24,9 +24,9 @@ override_application_settings, raise_background_exceptions, validate_transaction_errors, - validate_transaction_metrics, wait_for_background_threads, ) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.sample_asgi_applications import ( AppWithCall, AppWithCallRaw, diff --git a/tests/agent_features/_test_async_coroutine_trace.py b/tests/agent_features/_test_async_coroutine_trace.py index 96cb3c7dcb..0b3aaa312f 100644 --- a/tests/agent_features/_test_async_coroutine_trace.py +++ b/tests/agent_features/_test_async_coroutine_trace.py @@ -19,8 +19,8 @@ import pytest from testing_support.fixtures import ( capture_transaction_metrics, - validate_transaction_metrics, ) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task from newrelic.api.database_trace import database_trace diff --git a/tests/agent_features/test_asgi_distributed_tracing.py b/tests/agent_features/test_asgi_distributed_tracing.py index bb34aba20c..90f57becc2 100644 --- a/tests/agent_features/test_asgi_distributed_tracing.py +++ b/tests/agent_features/test_asgi_distributed_tracing.py @@ -22,8 +22,8 @@ from newrelic.api.asgi_application import asgi_application, ASGIWebTransaction from testing_support.asgi_testing import AsgiTest -from testing_support.fixtures import (override_application_settings, - validate_transaction_metrics) +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics distributed_trace_intrinsics = ['guid', 'traceId', 'priority', 'sampled'] diff --git a/tests/agent_features/test_asgi_transaction.py b/tests/agent_features/test_asgi_transaction.py index 1820efa86d..cb930ba5b8 100644 --- a/tests/agent_features/test_asgi_transaction.py +++ b/tests/agent_features/test_asgi_transaction.py @@ -20,8 +20,8 @@ from testing_support.fixtures import ( override_application_settings, validate_transaction_errors, - validate_transaction_metrics, ) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.sample_asgi_applications import ( AppWithDescriptor, simple_app_v2, diff --git a/tests/agent_features/test_asgi_w3c_trace_context.py b/tests/agent_features/test_asgi_w3c_trace_context.py index 68c192a5d7..234e084092 100644 --- a/tests/agent_features/test_asgi_w3c_trace_context.py +++ b/tests/agent_features/test_asgi_w3c_trace_context.py @@ -20,7 +20,8 @@ from testing_support.asgi_testing import AsgiTest from testing_support.fixtures import (override_application_settings, - validate_transaction_event_attributes, validate_transaction_metrics) + validate_transaction_event_attributes) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_span_events import ( validate_span_events) diff --git a/tests/agent_features/test_function_trace.py b/tests/agent_features/test_function_trace.py index 78c012b306..f1f0cd9acd 100644 --- a/tests/agent_features/test_function_trace.py +++ b/tests/agent_features/test_function_trace.py @@ -17,9 +17,8 @@ from newrelic.api.background_task import background_task from newrelic.api.function_trace import FunctionTrace -from testing_support.fixtures import (validate_transaction_metrics, - validate_tt_parenting) - +from testing_support.fixtures import validate_tt_parenting +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics _test_function_trace_default_group_scoped_metrics = [ ('Function/FunctionTrace', 1)] diff --git a/tests/agent_features/test_web_transaction.py b/tests/agent_features/test_web_transaction.py index 22bfd6eb8e..5a6eeda690 100644 --- a/tests/agent_features/test_web_transaction.py +++ b/tests/agent_features/test_web_transaction.py @@ -19,8 +19,8 @@ import time from newrelic.api.application import application_instance from newrelic.api.web_transaction import WebTransaction -from testing_support.fixtures import (validate_transaction_metrics, - validate_attributes) +from testing_support.fixtures import validate_attributes +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.sample_applications import simple_app import newrelic.packages.six as six application = webtest.TestApp(simple_app) diff --git a/tests/agent_unittests/test_agent_connect.py b/tests/agent_unittests/test_agent_connect.py index 46c4edf446..eb944c072a 100644 --- a/tests/agent_unittests/test_agent_connect.py +++ b/tests/agent_unittests/test_agent_connect.py @@ -19,10 +19,9 @@ from testing_support.fixtures import ( override_generic_settings, - validate_internal_metrics, failing_endpoint ) - +from testing_support.validators.validate_internal_metrics import validate_internal_metrics SETTINGS = global_settings() diff --git a/tests/component_djangorestframework/test_application.py b/tests/component_djangorestframework/test_application.py index 2951e04019..472f2f0297 100644 --- a/tests/component_djangorestframework/test_application.py +++ b/tests/component_djangorestframework/test_application.py @@ -18,9 +18,11 @@ from newrelic.packages import six from newrelic.core.config import global_settings -from testing_support.fixtures import (validate_transaction_metrics, - validate_transaction_errors, override_generic_settings, +from testing_support.fixtures import ( + validate_transaction_errors, + override_generic_settings, function_not_called) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics import django diff --git a/tests/component_flask_rest/test_application.py b/tests/component_flask_rest/test_application.py index 94b6fbc5c5..391a35674c 100644 --- a/tests/component_flask_rest/test_application.py +++ b/tests/component_flask_rest/test_application.py @@ -15,9 +15,11 @@ import pytest from newrelic.packages import six -from testing_support.fixtures import (validate_transaction_metrics, - validate_transaction_errors, override_ignore_status_codes, +from testing_support.fixtures import ( + validate_transaction_errors, + override_ignore_status_codes, override_generic_settings) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics from newrelic.core.config import global_settings diff --git a/tests/component_tastypie/test_application.py b/tests/component_tastypie/test_application.py index 16521425c9..378a94c169 100644 --- a/tests/component_tastypie/test_application.py +++ b/tests/component_tastypie/test_application.py @@ -21,8 +21,10 @@ from newrelic.api.background_task import background_task from newrelic.api.transaction import end_of_transaction -from testing_support.fixtures import (validate_transaction_metrics, - validate_transaction_errors, override_ignore_status_codes) +from testing_support.fixtures import ( + validate_transaction_errors, + override_ignore_status_codes) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics from wsgi import application diff --git a/tests/cross_agent/test_aws_utilization_data.py b/tests/cross_agent/test_aws_utilization_data.py index 7ff2e623be..807b1a97b2 100644 --- a/tests/cross_agent/test_aws_utilization_data.py +++ b/tests/cross_agent/test_aws_utilization_data.py @@ -18,7 +18,7 @@ from newrelic.common.utilization import AWSUtilization from testing_support.mock_http_client import create_client_cls -from testing_support.fixtures import validate_internal_metrics +from testing_support.validators.validate_internal_metrics import validate_internal_metrics CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) diff --git a/tests/cross_agent/test_azure_utilization_data.py b/tests/cross_agent/test_azure_utilization_data.py index 897fadec05..772a96f989 100644 --- a/tests/cross_agent/test_azure_utilization_data.py +++ b/tests/cross_agent/test_azure_utilization_data.py @@ -18,7 +18,7 @@ from newrelic.common.utilization import AzureUtilization from testing_support.mock_http_client import create_client_cls -from testing_support.fixtures import validate_internal_metrics +from testing_support.validators.validate_internal_metrics import validate_internal_metrics CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) diff --git a/tests/cross_agent/test_boot_id_utilization_data.py b/tests/cross_agent/test_boot_id_utilization_data.py index 2eaeae6707..ea5b26a9e7 100644 --- a/tests/cross_agent/test_boot_id_utilization_data.py +++ b/tests/cross_agent/test_boot_id_utilization_data.py @@ -20,7 +20,7 @@ from newrelic.common.system_info import BootIdUtilization -from testing_support.fixtures import validate_internal_metrics +from testing_support.validators.validate_internal_metrics import validate_internal_metrics CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) diff --git a/tests/cross_agent/test_gcp_utilization_data.py b/tests/cross_agent/test_gcp_utilization_data.py index 1d77ed0a26..7bbf6ce0a8 100644 --- a/tests/cross_agent/test_gcp_utilization_data.py +++ b/tests/cross_agent/test_gcp_utilization_data.py @@ -18,7 +18,7 @@ from newrelic.common.utilization import GCPUtilization from testing_support.mock_http_client import create_client_cls -from testing_support.fixtures import validate_internal_metrics +from testing_support.validators.validate_internal_metrics import validate_internal_metrics CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) diff --git a/tests/cross_agent/test_pcf_utilization_data.py b/tests/cross_agent/test_pcf_utilization_data.py index ce86bfb9f3..28b56f7592 100644 --- a/tests/cross_agent/test_pcf_utilization_data.py +++ b/tests/cross_agent/test_pcf_utilization_data.py @@ -18,7 +18,7 @@ from newrelic.common.utilization import PCFUtilization -from testing_support.fixtures import validate_internal_metrics +from testing_support.validators.validate_internal_metrics import validate_internal_metrics CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) diff --git a/tests/datastore_aredis/test_custom_conn_pool.py b/tests/datastore_aredis/test_custom_conn_pool.py index 3441544120..70c75de9ea 100644 --- a/tests/datastore_aredis/test_custom_conn_pool.py +++ b/tests/datastore_aredis/test_custom_conn_pool.py @@ -23,8 +23,8 @@ from newrelic.api.background_task import background_task from testing_support.fixture.event_loop import event_loop as loop -from testing_support.fixtures import (validate_transaction_metrics, - override_application_settings) +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.db_settings import redis_settings from testing_support.util import instance_hostname diff --git a/tests/datastore_aredis/test_execute_command.py b/tests/datastore_aredis/test_execute_command.py index 7db3c9c59a..c5b0fc3323 100644 --- a/tests/datastore_aredis/test_execute_command.py +++ b/tests/datastore_aredis/test_execute_command.py @@ -17,8 +17,8 @@ from newrelic.api.background_task import background_task -from testing_support.fixtures import (validate_transaction_metrics, - override_application_settings) +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.fixture.event_loop import event_loop as loop from testing_support.db_settings import redis_settings from testing_support.util import instance_hostname diff --git a/tests/datastore_aredis/test_get_and_set.py b/tests/datastore_aredis/test_get_and_set.py index fbde29d867..2eeee947bc 100644 --- a/tests/datastore_aredis/test_get_and_set.py +++ b/tests/datastore_aredis/test_get_and_set.py @@ -17,8 +17,8 @@ from newrelic.api.background_task import background_task from testing_support.fixture.event_loop import event_loop as loop -from testing_support.fixtures import (validate_transaction_metrics, - override_application_settings) +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.db_settings import redis_settings from testing_support.util import instance_hostname diff --git a/tests/datastore_elasticsearch/test_elasticsearch.py b/tests/datastore_elasticsearch/test_elasticsearch.py index 5480432161..f219e01b5e 100644 --- a/tests/datastore_elasticsearch/test_elasticsearch.py +++ b/tests/datastore_elasticsearch/test_elasticsearch.py @@ -17,8 +17,10 @@ from newrelic.api.background_task import background_task -from testing_support.fixtures import (validate_transaction_metrics, - validate_transaction_errors, override_application_settings) +from testing_support.fixtures import ( + validate_transaction_errors, + override_application_settings) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.db_settings import elasticsearch_settings from testing_support.util import instance_hostname diff --git a/tests/datastore_elasticsearch/test_mget.py b/tests/datastore_elasticsearch/test_mget.py index 417b231d6a..9f0b442e84 100644 --- a/tests/datastore_elasticsearch/test_mget.py +++ b/tests/datastore_elasticsearch/test_mget.py @@ -17,8 +17,8 @@ from elasticsearch import Elasticsearch from elasticsearch.connection_pool import RoundRobinSelector -from testing_support.fixtures import (validate_transaction_metrics, - override_application_settings) +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.db_settings import elasticsearch_settings from testing_support.util import instance_hostname diff --git a/tests/datastore_elasticsearch/test_multiple_dbs.py b/tests/datastore_elasticsearch/test_multiple_dbs.py index b4b1559a79..70a7be4f12 100644 --- a/tests/datastore_elasticsearch/test_multiple_dbs.py +++ b/tests/datastore_elasticsearch/test_multiple_dbs.py @@ -16,8 +16,8 @@ from elasticsearch import Elasticsearch -from testing_support.fixtures import (validate_transaction_metrics, - override_application_settings) +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.db_settings import elasticsearch_settings from testing_support.util import instance_hostname diff --git a/tests/datastore_memcache/test_memcache.py b/tests/datastore_memcache/test_memcache.py index d8afab3b12..a66c114eef 100644 --- a/tests/datastore_memcache/test_memcache.py +++ b/tests/datastore_memcache/test_memcache.py @@ -14,8 +14,8 @@ import memcache -from testing_support.fixtures import (validate_transaction_metrics, - override_application_settings) +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.db_settings import memcached_settings from testing_support.util import instance_hostname diff --git a/tests/datastore_memcache/test_multiple_dbs.py b/tests/datastore_memcache/test_multiple_dbs.py index b83d7dfcc1..dbc3ea2b3b 100644 --- a/tests/datastore_memcache/test_multiple_dbs.py +++ b/tests/datastore_memcache/test_multiple_dbs.py @@ -17,8 +17,8 @@ from newrelic.api.background_task import background_task -from testing_support.fixtures import (validate_transaction_metrics, - override_application_settings) +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.db_settings import memcached_settings from testing_support.util import instance_hostname diff --git a/tests/datastore_psycopg2/test_async.py b/tests/datastore_psycopg2/test_async.py index 78df2becad..32224b681d 100644 --- a/tests/datastore_psycopg2/test_async.py +++ b/tests/datastore_psycopg2/test_async.py @@ -16,10 +16,11 @@ import psycopg2.extras import pytest -from testing_support.fixtures import (validate_transaction_metrics, +from testing_support.fixtures import ( validate_transaction_errors, validate_stats_engine_explain_plan_output_is_none, override_application_settings) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_database_trace_inputs import validate_database_trace_inputs from testing_support.validators.validate_transaction_slow_sql_count import ( diff --git a/tests/datastore_psycopg2/test_cursor.py b/tests/datastore_psycopg2/test_cursor.py index e7a549c130..d66d73ff84 100644 --- a/tests/datastore_psycopg2/test_cursor.py +++ b/tests/datastore_psycopg2/test_cursor.py @@ -21,8 +21,8 @@ except ImportError: sql = None -from testing_support.fixtures import (validate_transaction_metrics, - override_application_settings) +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_database_trace_inputs import validate_database_trace_inputs from testing_support.util import instance_hostname from utils import DB_SETTINGS diff --git a/tests/datastore_psycopg2/test_multiple_dbs.py b/tests/datastore_psycopg2/test_multiple_dbs.py index bf7629ebf0..afbdd66f2d 100644 --- a/tests/datastore_psycopg2/test_multiple_dbs.py +++ b/tests/datastore_psycopg2/test_multiple_dbs.py @@ -15,8 +15,8 @@ import psycopg2 import pytest -from testing_support.fixtures import (validate_transaction_metrics, - override_application_settings) +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_database_trace_inputs import validate_database_trace_inputs from testing_support.util import instance_hostname from utils import DB_MULTIPLE_SETTINGS diff --git a/tests/datastore_psycopg2/test_register.py b/tests/datastore_psycopg2/test_register.py index 03b553749d..8f6d8bfd9b 100644 --- a/tests/datastore_psycopg2/test_register.py +++ b/tests/datastore_psycopg2/test_register.py @@ -16,8 +16,8 @@ import psycopg2 import psycopg2.extras -from testing_support.fixtures import (validate_transaction_metrics, - validate_transaction_errors) +from testing_support.fixtures import validate_transaction_errors +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from utils import DB_SETTINGS from newrelic.api.background_task import background_task diff --git a/tests/datastore_psycopg2/test_rollback.py b/tests/datastore_psycopg2/test_rollback.py index f0ef8149fc..0a23b1005e 100644 --- a/tests/datastore_psycopg2/test_rollback.py +++ b/tests/datastore_psycopg2/test_rollback.py @@ -15,8 +15,8 @@ import psycopg2 import pytest -from testing_support.fixtures import (validate_transaction_metrics, - override_application_settings) +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_database_trace_inputs import validate_database_trace_inputs from testing_support.util import instance_hostname from utils import DB_SETTINGS diff --git a/tests/datastore_psycopg2cffi/test_database.py b/tests/datastore_psycopg2cffi/test_database.py index c0eb6e722a..48e85e77b7 100644 --- a/tests/datastore_psycopg2cffi/test_database.py +++ b/tests/datastore_psycopg2cffi/test_database.py @@ -16,8 +16,9 @@ import psycopg2cffi.extensions import psycopg2cffi.extras -from testing_support.fixtures import (validate_transaction_metrics, +from testing_support.fixtures import ( validate_transaction_errors, validate_stats_engine_explain_plan_output_is_none) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_transaction_slow_sql_count import \ validate_transaction_slow_sql_count from testing_support.validators.validate_database_trace_inputs import validate_database_trace_inputs diff --git a/tests/datastore_pyelasticsearch/test_pyelasticsearch.py b/tests/datastore_pyelasticsearch/test_pyelasticsearch.py index 837c9ae193..7554e9a3db 100644 --- a/tests/datastore_pyelasticsearch/test_pyelasticsearch.py +++ b/tests/datastore_pyelasticsearch/test_pyelasticsearch.py @@ -15,8 +15,8 @@ import sqlite3 from pyelasticsearch import ElasticSearch -from testing_support.fixtures import (validate_transaction_metrics, - validate_transaction_errors) +from testing_support.fixtures import validate_transaction_errors +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.db_settings import elasticsearch_settings from testing_support.validators.validate_database_duration import validate_database_duration diff --git a/tests/datastore_pymysql/test_database.py b/tests/datastore_pymysql/test_database.py index 2f20d8cbd3..5943b12665 100644 --- a/tests/datastore_pymysql/test_database.py +++ b/tests/datastore_pymysql/test_database.py @@ -14,8 +14,7 @@ import pymysql -from testing_support.fixtures import (validate_transaction_metrics, - ) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_database_trace_inputs import validate_database_trace_inputs from testing_support.db_settings import mysql_settings diff --git a/tests/datastore_redis/test_custom_conn_pool.py b/tests/datastore_redis/test_custom_conn_pool.py index 9700392cc9..156c9ce31f 100644 --- a/tests/datastore_redis/test_custom_conn_pool.py +++ b/tests/datastore_redis/test_custom_conn_pool.py @@ -22,8 +22,8 @@ from newrelic.api.background_task import background_task -from testing_support.fixtures import (validate_transaction_metrics, - override_application_settings) +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.db_settings import redis_settings from testing_support.util import instance_hostname diff --git a/tests/datastore_redis/test_execute_command.py b/tests/datastore_redis/test_execute_command.py index c86295b354..7475880725 100644 --- a/tests/datastore_redis/test_execute_command.py +++ b/tests/datastore_redis/test_execute_command.py @@ -17,8 +17,8 @@ from newrelic.api.background_task import background_task -from testing_support.fixtures import (validate_transaction_metrics, - override_application_settings) +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.db_settings import redis_settings from testing_support.util import instance_hostname diff --git a/tests/datastore_redis/test_get_and_set.py b/tests/datastore_redis/test_get_and_set.py index 2c40ddc129..0e2df4bb1d 100644 --- a/tests/datastore_redis/test_get_and_set.py +++ b/tests/datastore_redis/test_get_and_set.py @@ -16,8 +16,8 @@ from newrelic.api.background_task import background_task -from testing_support.fixtures import (validate_transaction_metrics, - override_application_settings) +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.db_settings import redis_settings from testing_support.util import instance_hostname diff --git a/tests/datastore_redis/test_multiple_dbs.py b/tests/datastore_redis/test_multiple_dbs.py index 67f7b7fe8f..15777cc38f 100644 --- a/tests/datastore_redis/test_multiple_dbs.py +++ b/tests/datastore_redis/test_multiple_dbs.py @@ -17,8 +17,8 @@ from newrelic.api.background_task import background_task -from testing_support.fixtures import (validate_transaction_metrics, - override_application_settings) +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.db_settings import redis_settings from testing_support.util import instance_hostname diff --git a/tests/datastore_redis/test_rb.py b/tests/datastore_redis/test_rb.py index 7f4feeda7d..5678c2787f 100644 --- a/tests/datastore_redis/test_rb.py +++ b/tests/datastore_redis/test_rb.py @@ -24,8 +24,8 @@ from newrelic.api.background_task import background_task -from testing_support.fixtures import (validate_transaction_metrics, - override_application_settings) +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.db_settings import redis_settings from testing_support.util import instance_hostname diff --git a/tests/external_boto3/test_boto3_iam.py b/tests/external_boto3/test_boto3_iam.py index 9c6246c8c7..ac49214f44 100644 --- a/tests/external_boto3/test_boto3_iam.py +++ b/tests/external_boto3/test_boto3_iam.py @@ -19,10 +19,11 @@ import moto from newrelic.api.background_task import background_task -from testing_support.fixtures import (validate_transaction_metrics, +from testing_support.fixtures import ( validate_tt_segment_params, override_application_settings) from testing_support.validators.validate_span_events import ( validate_span_events) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics MOTO_VERSION = tuple(int(v) for v in moto.__version__.split('.')[:3]) diff --git a/tests/external_boto3/test_boto3_s3.py b/tests/external_boto3/test_boto3_s3.py index ba65bc950f..7d232a689f 100644 --- a/tests/external_boto3/test_boto3_s3.py +++ b/tests/external_boto3/test_boto3_s3.py @@ -20,10 +20,9 @@ import moto from newrelic.api.background_task import background_task -from testing_support.fixtures import (validate_transaction_metrics, - override_application_settings) -from testing_support.validators.validate_span_events import ( - validate_span_events) +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_span_events import validate_span_events +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics MOTO_VERSION = tuple(int(v) for v in moto.__version__.split('.')[:3]) diff --git a/tests/external_boto3/test_boto3_sns.py b/tests/external_boto3/test_boto3_sns.py index 38c8c951cb..3718d52924 100644 --- a/tests/external_boto3/test_boto3_sns.py +++ b/tests/external_boto3/test_boto3_sns.py @@ -18,10 +18,10 @@ import pytest from newrelic.api.background_task import background_task -from testing_support.fixtures import (validate_transaction_metrics, +from testing_support.fixtures import ( validate_tt_segment_params, override_application_settings) -from testing_support.validators.validate_span_events import ( - validate_span_events) +from testing_support.validators.validate_span_events import validate_span_events +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics MOTO_VERSION = tuple(int(v) for v in moto.__version__.split('.')[:3]) diff --git a/tests/external_botocore/test_botocore_dynamodb.py b/tests/external_botocore/test_botocore_dynamodb.py index eb0432aba1..44862d827d 100644 --- a/tests/external_botocore/test_botocore_dynamodb.py +++ b/tests/external_botocore/test_botocore_dynamodb.py @@ -19,10 +19,11 @@ import moto from newrelic.api.background_task import background_task -from testing_support.fixtures import (validate_transaction_metrics, +from testing_support.fixtures import ( validate_tt_segment_params, override_application_settings) from testing_support.validators.validate_span_events import ( validate_span_events) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics MOTO_VERSION = tuple(int(v) for v in moto.__version__.split('.')[:3]) diff --git a/tests/external_botocore/test_botocore_ec2.py b/tests/external_botocore/test_botocore_ec2.py index 6f91ad75f1..0cfd09b6fd 100644 --- a/tests/external_botocore/test_botocore_ec2.py +++ b/tests/external_botocore/test_botocore_ec2.py @@ -19,10 +19,11 @@ import moto from newrelic.api.background_task import background_task -from testing_support.fixtures import (validate_transaction_metrics, +from testing_support.fixtures import ( validate_tt_segment_params, override_application_settings) from testing_support.validators.validate_span_events import ( validate_span_events) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics MOTO_VERSION = tuple(int(v) for v in moto.__version__.split('.')[:3]) diff --git a/tests/external_botocore/test_botocore_s3.py b/tests/external_botocore/test_botocore_s3.py index 3cd4ecd933..35f3f07d2e 100644 --- a/tests/external_botocore/test_botocore_s3.py +++ b/tests/external_botocore/test_botocore_s3.py @@ -19,10 +19,10 @@ import moto from newrelic.api.background_task import background_task -from testing_support.fixtures import (validate_transaction_metrics, - override_application_settings) +from testing_support.fixtures import override_application_settings from testing_support.validators.validate_span_events import ( validate_span_events) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics MOTO_VERSION = tuple(int(v) for v in moto.__version__.split('.')[:3]) diff --git a/tests/external_botocore/test_botocore_sqs.py b/tests/external_botocore/test_botocore_sqs.py index 46482c6755..63b3566d6e 100644 --- a/tests/external_botocore/test_botocore_sqs.py +++ b/tests/external_botocore/test_botocore_sqs.py @@ -20,10 +20,10 @@ import moto from newrelic.api.background_task import background_task -from testing_support.fixtures import (validate_transaction_metrics, - override_application_settings) +from testing_support.fixtures import override_application_settings from testing_support.validators.validate_span_events import ( validate_span_events) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics MOTO_VERSION = tuple(int(v) for v in moto.__version__.split('.')[:3]) diff --git a/tests/framework_aiohttp/test_externals.py b/tests/framework_aiohttp/test_externals.py index a410590efe..97710630a5 100644 --- a/tests/framework_aiohttp/test_externals.py +++ b/tests/framework_aiohttp/test_externals.py @@ -15,8 +15,8 @@ import pytest import asyncio -from testing_support.fixtures import (validate_transaction_metrics, - validate_tt_parenting) +from testing_support.fixtures import validate_tt_parenting +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics expected_parenting = ( 'TransactionNode', [ diff --git a/tests/framework_aiohttp/test_middleware.py b/tests/framework_aiohttp/test_middleware.py index 47050232f8..7e3ac97d4f 100644 --- a/tests/framework_aiohttp/test_middleware.py +++ b/tests/framework_aiohttp/test_middleware.py @@ -17,9 +17,9 @@ import aiohttp from newrelic.core.config import global_settings -from testing_support.fixtures import (validate_transaction_metrics, - override_generic_settings) +from testing_support.fixtures import override_generic_settings from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics version_info = tuple(int(_) for _ in aiohttp.__version__.split('.')[:2]) diff --git a/tests/framework_aiohttp/test_server.py b/tests/framework_aiohttp/test_server.py index 2b4e28b5f8..f09f2b615b 100644 --- a/tests/framework_aiohttp/test_server.py +++ b/tests/framework_aiohttp/test_server.py @@ -17,11 +17,12 @@ import aiohttp from newrelic.core.config import global_settings -from testing_support.fixtures import (validate_transaction_metrics, +from testing_support.fixtures import ( validate_transaction_errors, validate_transaction_event_attributes, count_transactions, override_generic_settings, override_application_settings, override_ignore_status_codes) from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics version_info = tuple(int(_) for _ in aiohttp.__version__.split('.')[:2]) diff --git a/tests/framework_bottle/test_application.py b/tests/framework_bottle/test_application.py index f9fb0915e0..56e3b0f65d 100644 --- a/tests/framework_bottle/test_application.py +++ b/tests/framework_bottle/test_application.py @@ -15,10 +15,10 @@ import pytest import base64 -from testing_support.fixtures import (validate_transaction_metrics, +from testing_support.fixtures import ( validate_transaction_errors, override_ignore_status_codes, override_application_settings) - +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.packages import six from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics diff --git a/tests/framework_django/test_application.py b/tests/framework_django/test_application.py index 1876b9a690..1bee82346a 100644 --- a/tests/framework_django/test_application.py +++ b/tests/framework_django/test_application.py @@ -12,11 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -from testing_support.fixtures import (validate_transaction_metrics, +from testing_support.fixtures import ( validate_transaction_errors, override_application_settings, override_generic_settings, override_ignore_status_codes) from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics from newrelic.hooks.framework_django import django_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics import os diff --git a/tests/framework_django/test_asgi_application.py b/tests/framework_django/test_asgi_application.py index 98f157f85d..e714d52770 100644 --- a/tests/framework_django/test_asgi_application.py +++ b/tests/framework_django/test_asgi_application.py @@ -18,10 +18,11 @@ from newrelic.core.config import global_settings from newrelic.common.encoding_utils import gzip_decompress -from testing_support.fixtures import (validate_transaction_metrics, +from testing_support.fixtures import ( validate_transaction_errors, override_application_settings, override_generic_settings, override_ignore_status_codes) from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics DJANGO_VERSION = tuple(map(int, django.get_version().split('.')[:2])) diff --git a/tests/framework_falcon/test_application.py b/tests/framework_falcon/test_application.py index 6f59ea826c..e0810c345c 100644 --- a/tests/framework_falcon/test_application.py +++ b/tests/framework_falcon/test_application.py @@ -14,10 +14,11 @@ import pytest from newrelic.core.config import global_settings -from testing_support.fixtures import (validate_transaction_metrics, +from testing_support.fixtures import ( validate_transaction_errors, override_ignore_status_codes, override_generic_settings) from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics SETTINGS = global_settings() diff --git a/tests/framework_flask/test_application.py b/tests/framework_flask/test_application.py index 98757a805a..5aebc11176 100644 --- a/tests/framework_flask/test_application.py +++ b/tests/framework_flask/test_application.py @@ -14,10 +14,11 @@ import pytest -from testing_support.fixtures import (validate_transaction_metrics, +from testing_support.fixtures import ( validate_transaction_errors, override_application_settings, validate_tt_parenting) from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.packages import six diff --git a/tests/framework_flask/test_blueprints.py b/tests/framework_flask/test_blueprints.py index 6a76d405b2..5f8abd4412 100644 --- a/tests/framework_flask/test_blueprints.py +++ b/tests/framework_flask/test_blueprints.py @@ -14,9 +14,10 @@ import pytest -from testing_support.fixtures import (validate_transaction_metrics, +from testing_support.fixtures import ( validate_transaction_errors, override_application_settings) from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.packages import six diff --git a/tests/framework_flask/test_compress.py b/tests/framework_flask/test_compress.py index ac7f323fda..49138fe272 100644 --- a/tests/framework_flask/test_compress.py +++ b/tests/framework_flask/test_compress.py @@ -12,8 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -from testing_support.fixtures import (validate_transaction_metrics, +from testing_support.fixtures import ( validate_transaction_errors, override_application_settings) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics diff --git a/tests/framework_flask/test_middleware.py b/tests/framework_flask/test_middleware.py index d92d4d8517..9f56163b73 100644 --- a/tests/framework_flask/test_middleware.py +++ b/tests/framework_flask/test_middleware.py @@ -14,9 +14,10 @@ import pytest -from testing_support.fixtures import (validate_transaction_metrics, +from testing_support.fixtures import ( validate_transaction_errors, override_application_settings) from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics def target_application(): # We need to delay Flask application creation because of ordering diff --git a/tests/framework_flask/test_not_found.py b/tests/framework_flask/test_not_found.py index 22ad5efcde..523a8e593f 100644 --- a/tests/framework_flask/test_not_found.py +++ b/tests/framework_flask/test_not_found.py @@ -14,8 +14,8 @@ import pytest -from testing_support.fixtures import (validate_transaction_metrics, - validate_transaction_errors) +from testing_support.fixtures import validate_transaction_errors +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics def target_application(): # We need to delay Flask application creation because of ordering diff --git a/tests/framework_flask/test_user_exceptions.py b/tests/framework_flask/test_user_exceptions.py index 5c8f3a6587..a69c69b92e 100644 --- a/tests/framework_flask/test_user_exceptions.py +++ b/tests/framework_flask/test_user_exceptions.py @@ -14,8 +14,8 @@ import pytest -from testing_support.fixtures import (validate_transaction_metrics, - validate_transaction_errors) +from testing_support.fixtures import validate_transaction_errors +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics def target_application(): # We need to delay Flask application creation because of ordering diff --git a/tests/framework_grpc/test_clients.py b/tests/framework_grpc/test_clients.py index e8fed1da52..9fa62d5574 100644 --- a/tests/framework_grpc/test_clients.py +++ b/tests/framework_grpc/test_clients.py @@ -18,8 +18,8 @@ from newrelic.api.background_task import background_task -from testing_support.fixtures import (validate_transaction_metrics, - validate_transaction_errors) +from testing_support.fixtures import validate_transaction_errors +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from _test_common import create_request, get_result diff --git a/tests/framework_grpc/test_server.py b/tests/framework_grpc/test_server.py index d1ed47ff5b..e80b103b8d 100644 --- a/tests/framework_grpc/test_server.py +++ b/tests/framework_grpc/test_server.py @@ -18,12 +18,12 @@ from conftest import create_stub_and_channel from _test_common import create_request, wait_for_transaction_completion from newrelic.core.config import global_settings -from testing_support.fixtures import (validate_transaction_metrics, +from testing_support.fixtures import ( validate_transaction_event_attributes, override_application_settings, override_generic_settings, function_not_called, validate_transaction_errors) from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics - +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics def select_python_version(py2, py3): return six.PY3 and py3 or py2 diff --git a/tests/framework_pyramid/test_append_slash_app.py b/tests/framework_pyramid/test_append_slash_app.py index 875f910128..10053e7cc7 100644 --- a/tests/framework_pyramid/test_append_slash_app.py +++ b/tests/framework_pyramid/test_append_slash_app.py @@ -34,9 +34,9 @@ import pytest import re -from testing_support.fixtures import (validate_transaction_metrics, +from testing_support.fixtures import ( validate_transaction_errors, override_application_settings) - +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics def _to_int(version_str): m = re.match(r'\d+', version_str) diff --git a/tests/framework_pyramid/test_application.py b/tests/framework_pyramid/test_application.py index 6b912d6325..6bae117e9c 100644 --- a/tests/framework_pyramid/test_application.py +++ b/tests/framework_pyramid/test_application.py @@ -14,8 +14,9 @@ import pytest -from testing_support.fixtures import (validate_transaction_metrics, +from testing_support.fixtures import ( validate_transaction_errors, override_application_settings) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.packages import six from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics diff --git a/tests/framework_sanic/test_application.py b/tests/framework_sanic/test_application.py index ac2726bd9c..9ea9b92c42 100644 --- a/tests/framework_sanic/test_application.py +++ b/tests/framework_sanic/test_application.py @@ -22,13 +22,13 @@ from newrelic.api.transaction import Transaction from newrelic.api.external_trace import ExternalTrace -from testing_support.fixtures import (validate_transaction_metrics, +from testing_support.fixtures import ( override_application_settings, validate_transaction_errors, validate_transaction_event_attributes, override_ignore_status_codes, override_generic_settings, function_not_called) from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics - +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics sanic_21 = int(sanic.__version__.split('.', 1)[0]) >= 21 diff --git a/tests/framework_tornado/test_server.py b/tests/framework_tornado/test_server.py index 16aced3566..9a0bb96d49 100644 --- a/tests/framework_tornado/test_server.py +++ b/tests/framework_tornado/test_server.py @@ -14,7 +14,7 @@ import pytest from newrelic.core.config import global_settings -from testing_support.fixtures import (validate_transaction_metrics, +from testing_support.fixtures import ( override_generic_settings, function_not_called, validate_transaction_event_attributes, validate_transaction_errors, override_ignore_status_codes, @@ -22,7 +22,7 @@ from testing_support.validators.validate_transaction_count import ( validate_transaction_count) from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics - +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics @pytest.mark.parametrize('uri,name,metrics, method_metric', ( # ('/native-simple', '_target_application:NativeSimpleHandler.get', None, diff --git a/tests/messagebroker_pika/test_pika_blocking_connection_consume_generator.py b/tests/messagebroker_pika/test_pika_blocking_connection_consume_generator.py index a9ee1b3316..4fff114874 100644 --- a/tests/messagebroker_pika/test_pika_blocking_connection_consume_generator.py +++ b/tests/messagebroker_pika/test_pika_blocking_connection_consume_generator.py @@ -17,9 +17,9 @@ from newrelic.api.background_task import background_task from conftest import QUEUE, EXCHANGE, CORRELATION_ID, REPLY_TO, HEADERS, BODY -from testing_support.fixtures import (validate_transaction_metrics, - validate_tt_collector_json) +from testing_support.fixtures import validate_tt_collector_json from testing_support.db_settings import rabbitmq_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics DB_SETTINGS = rabbitmq_settings()[0] diff --git a/tests/testing_support/fixtures.py b/tests/testing_support/fixtures.py index 30c0815f00..0d2f73c065 100644 --- a/tests/testing_support/fixtures.py +++ b/tests/testing_support/fixtures.py @@ -65,8 +65,8 @@ ) from newrelic.core.config import apply_config_setting, flatten_settings, global_settings from newrelic.core.database_utils import SQLConnections -from newrelic.core.internal_metrics import InternalTraceContext -from newrelic.core.stats_engine import CustomMetrics +#from newrelic.core.internal_metrics import InternalTraceContext +#from newrelic.core.stats_engine import CustomMetrics from newrelic.network.exceptions import RetryDataForRequest from newrelic.packages import six @@ -594,48 +594,48 @@ def _capture_transaction_metrics(wrapped, instance, args, kwargs): return _capture_transaction_metrics -def validate_internal_metrics(metrics=None): - metrics = metrics or [] +# def validate_internal_metrics(metrics=None): +# metrics = metrics or [] - def no_op(wrapped, instance, args, kwargs): - pass +# def no_op(wrapped, instance, args, kwargs): +# pass - @function_wrapper - def _validate_wrapper(wrapped, instance, args, kwargs): - # Apply no-op wrappers to prevent new internal trace contexts from being started, preventing capture - wrapped = transient_function_wrapper("newrelic.core.internal_metrics", "InternalTraceContext.__enter__")(no_op)(wrapped) - wrapped = transient_function_wrapper("newrelic.core.internal_metrics", "InternalTraceContext.__exit__")(no_op)(wrapped) +# @function_wrapper +# def _validate_wrapper(wrapped, instance, args, kwargs): +# # Apply no-op wrappers to prevent new internal trace contexts from being started, preventing capture +# wrapped = transient_function_wrapper("newrelic.core.internal_metrics", "InternalTraceContext.__enter__")(no_op)(wrapped) +# wrapped = transient_function_wrapper("newrelic.core.internal_metrics", "InternalTraceContext.__exit__")(no_op)(wrapped) - captured_metrics = CustomMetrics() - with InternalTraceContext(captured_metrics): - result = wrapped(*args, **kwargs) - captured_metrics = dict(captured_metrics.metrics()) +# captured_metrics = CustomMetrics() +# with InternalTraceContext(captured_metrics): +# result = wrapped(*args, **kwargs) +# captured_metrics = dict(captured_metrics.metrics()) - def _validate(name, count): - metric = captured_metrics.get(name) +# def _validate(name, count): +# metric = captured_metrics.get(name) - def _metrics_table(): - return "metric=%r, metrics=%r" % (name, captured_metrics) +# def _metrics_table(): +# return "metric=%r, metrics=%r" % (name, captured_metrics) - def _metric_details(): - return "metric=%r, count=%r" % (name, metric.call_count) +# def _metric_details(): +# return "metric=%r, count=%r" % (name, metric.call_count) - if count is not None and count > 0: - assert metric is not None, _metrics_table() - if count == "present": - assert metric.call_count > 0, _metric_details() - else: - assert metric.call_count == count, _metric_details() +# if count is not None and count > 0: +# assert metric is not None, _metrics_table() +# if count == "present": +# assert metric.call_count > 0, _metric_details() +# else: +# assert metric.call_count == count, _metric_details() - else: - assert metric is None, _metrics_table() +# else: +# assert metric is None, _metrics_table() - for metric, count in metrics: - _validate(metric, count) +# for metric, count in metrics: +# _validate(metric, count) - return result +# return result - return _validate_wrapper +# return _validate_wrapper def validate_transaction_errors(errors=None, required_params=None, forgone_params=None): diff --git a/tests/testing_support/validators/validate_internal_metrics.py b/tests/testing_support/validators/validate_internal_metrics.py new file mode 100644 index 0000000000..c685d9b5f5 --- /dev/null +++ b/tests/testing_support/validators/validate_internal_metrics.py @@ -0,0 +1,64 @@ +# Copyright 2010 New Relic, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from newrelic.common.object_wrapper import ( + function_wrapper, + transient_function_wrapper, +) +from newrelic.core.stats_engine import CustomMetrics +from newrelic.core.internal_metrics import InternalTraceContext + + +def validate_internal_metrics(metrics=None): + metrics = metrics or [] + + def no_op(wrapped, instance, args, kwargs): + pass + + @function_wrapper + def _validate_wrapper(wrapped, instance, args, kwargs): + # Apply no-op wrappers to prevent new internal trace contexts from being started, preventing capture + wrapped = transient_function_wrapper("newrelic.core.internal_metrics", "InternalTraceContext.__enter__")(no_op)(wrapped) + wrapped = transient_function_wrapper("newrelic.core.internal_metrics", "InternalTraceContext.__exit__")(no_op)(wrapped) + + captured_metrics = CustomMetrics() + with InternalTraceContext(captured_metrics): + result = wrapped(*args, **kwargs) + captured_metrics = dict(captured_metrics.metrics()) + + def _validate(name, count): + metric = captured_metrics.get(name) + + def _metrics_table(): + return "metric=%r, metrics=%r" % (name, captured_metrics) + + def _metric_details(): + return "metric=%r, count=%r" % (name, metric.call_count) + + if count is not None and count > 0: + assert metric is not None, _metrics_table() + if count == "present": + assert metric.call_count > 0, _metric_details() + else: + assert metric.call_count == count, _metric_details() + + else: + assert metric is None, _metrics_table() + + for metric, count in metrics: + _validate(metric, count) + + return result + + return _validate_wrapper \ No newline at end of file From 2dbea7910758fdb05f12c8a142db9f8faa63c570 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Tue, 30 Aug 2022 17:08:26 -0700 Subject: [PATCH 05/14] Move validate_transaction_errors into validators directory --- tests/adapter_daphne/test_daphne.py | 2 +- tests/adapter_uvicorn/test_uvicorn.py | 2 +- tests/agent_features/test_asgi_browser.py | 4 +- tests/agent_features/test_asgi_transaction.py | 6 +- .../test_async_context_propagation.py | 3 +- tests/agent_features/test_browser.py | 4 +- tests/agent_features/test_coroutine_trace.py | 5 +- .../test_coroutine_transaction.py | 3 +- .../test_distributed_tracing.py | 3 +- .../test_event_loop_wait_time.py | 2 +- .../agent_features/test_high_security_mode.py | 3 +- .../test_ignore_expected_errors.py | 5 +- tests/agent_features/test_notice_error.py | 2 +- tests/agent_features/test_span_events.py | 3 +- .../agent_features/test_w3c_trace_context.py | 4 +- .../test_application.py | 2 +- .../component_flask_rest/test_application.py | 2 +- tests/component_graphqlserver/test_graphql.py | 8 +- tests/component_tastypie/test_application.py | 5 +- .../test_context_propagation.py | 2 +- tests/cross_agent/test_distributed_tracing.py | 3 +- tests/cross_agent/test_w3c_trace_context.py | 3 +- tests/datastore_aredis/test_multiple_dbs.py | 6 +- tests/datastore_asyncpg/test_multiple_dbs.py | 6 +- tests/datastore_asyncpg/test_query.py | 6 +- .../test_elasticsearch.py | 5 +- tests/datastore_psycopg2/test_async.py | 3 +- tests/datastore_psycopg2/test_register.py | 2 +- tests/datastore_psycopg2cffi/test_database.py | 4 +- .../test_pyelasticsearch.py | 2 +- tests/datastore_pymongo/test_pymongo.py | 7 +- tests/external_http/test_http.py | 2 +- tests/external_httplib/test_httplib.py | 2 +- tests/external_httplib2/test_httplib2.py | 2 +- tests/external_httpx/test_client.py | 4 +- tests/external_requests/test_requests.py | 5 +- tests/external_urllib3/test_urllib3.py | 5 +- tests/framework_aiohttp/test_client_cat.py | 6 +- tests/framework_aiohttp/test_server.py | 3 +- tests/framework_ariadne/test_application.py | 12 +-- tests/framework_bottle/test_application.py | 3 +- tests/framework_cherrypy/test_application.py | 6 +- tests/framework_cherrypy/test_dispatch.py | 2 +- tests/framework_cherrypy/test_resource.py | 2 +- tests/framework_cherrypy/test_routes.py | 2 +- tests/framework_django/test_application.py | 3 +- .../framework_django/test_asgi_application.py | 3 +- tests/framework_falcon/test_application.py | 3 +- tests/framework_flask/test_application.py | 3 +- tests/framework_flask/test_blueprints.py | 4 +- tests/framework_flask/test_compress.py | 4 +- tests/framework_flask/test_middleware.py | 4 +- tests/framework_flask/test_not_found.py | 2 +- tests/framework_flask/test_user_exceptions.py | 2 +- tests/framework_flask/test_views.py | 7 +- tests/framework_graphene/test_application.py | 8 +- tests/framework_graphql/test_application.py | 8 +- tests/framework_grpc/test_clients.py | 2 +- .../test_distributed_tracing.py | 5 +- tests/framework_grpc/test_server.py | 4 +- .../test_append_slash_app.py | 4 +- tests/framework_pyramid/test_application.py | 4 +- tests/framework_pyramid/test_cornice.py | 4 +- tests/framework_sanic/test_application.py | 3 +- .../framework_sanic/test_cross_application.py | 4 +- tests/framework_starlette/test_application.py | 8 +- .../framework_strawberry/test_application.py | 12 +-- tests/framework_tornado/test_externals.py | 6 +- tests/framework_tornado/test_inbound_cat.py | 4 +- tests/framework_tornado/test_server.py | 3 +- tests/logger_logging/test_metrics.py | 5 +- tests/logger_logging/test_settings.py | 7 +- tests/logger_loguru/test_metrics.py | 4 +- tests/logger_loguru/test_settings.py | 7 +- tests/messagebroker_pika/test_cat.py | 3 +- .../test_distributed_tracing.py | 4 +- .../test_pika_async_connection_consume.py | 4 +- .../test_pika_blocking_connection_consume.py | 3 +- tests/messagebroker_pika/test_pika_produce.py | 2 +- tests/testing_support/fixtures.py | 82 +++++++++---------- .../validators/validate_transaction_errors.py | 76 +++++++++++++++++ 81 files changed, 260 insertions(+), 224 deletions(-) create mode 100644 tests/testing_support/validators/validate_transaction_errors.py diff --git a/tests/adapter_daphne/test_daphne.py b/tests/adapter_daphne/test_daphne.py index a289e13115..34438482ee 100644 --- a/tests/adapter_daphne/test_daphne.py +++ b/tests/adapter_daphne/test_daphne.py @@ -21,10 +21,10 @@ from testing_support.fixtures import ( override_application_settings, raise_background_exceptions, - validate_transaction_errors, wait_for_background_threads, ) from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics +from testing_support.validators.validate_transaction_errors import validate_transaction_errors from testing_support.sample_asgi_applications import ( AppWithCall, AppWithCallRaw, diff --git a/tests/adapter_uvicorn/test_uvicorn.py b/tests/adapter_uvicorn/test_uvicorn.py index 8d81778fc1..93d155aa85 100644 --- a/tests/adapter_uvicorn/test_uvicorn.py +++ b/tests/adapter_uvicorn/test_uvicorn.py @@ -23,10 +23,10 @@ from testing_support.fixtures import ( override_application_settings, raise_background_exceptions, - validate_transaction_errors, wait_for_background_threads, ) from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics +from testing_support.validators.validate_transaction_errors import validate_transaction_errors from testing_support.sample_asgi_applications import ( AppWithCall, AppWithCallRaw, diff --git a/tests/agent_features/test_asgi_browser.py b/tests/agent_features/test_asgi_browser.py index c2c7ce7157..ef21d7a0b9 100644 --- a/tests/agent_features/test_asgi_browser.py +++ b/tests/agent_features/test_asgi_browser.py @@ -19,9 +19,9 @@ import six from testing_support.fixtures import (override_application_settings, - validate_transaction_errors, validate_custom_parameters) + validate_custom_parameters) from testing_support.asgi_testing import AsgiTest - +from testing_support.validators.validate_transaction_errors import validate_transaction_errors from newrelic.api.application import application_settings from newrelic.api.transaction import (get_browser_timing_header, get_browser_timing_footer, add_custom_parameter, diff --git a/tests/agent_features/test_asgi_transaction.py b/tests/agent_features/test_asgi_transaction.py index cb930ba5b8..1f4b21354e 100644 --- a/tests/agent_features/test_asgi_transaction.py +++ b/tests/agent_features/test_asgi_transaction.py @@ -17,10 +17,8 @@ import pytest from testing_support.asgi_testing import AsgiTest -from testing_support.fixtures import ( - override_application_settings, - validate_transaction_errors, -) +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_transaction_errors import validate_transaction_errors from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.sample_asgi_applications import ( AppWithDescriptor, diff --git a/tests/agent_features/test_async_context_propagation.py b/tests/agent_features/test_async_context_propagation.py index ea850c095d..8026cbbccf 100644 --- a/tests/agent_features/test_async_context_propagation.py +++ b/tests/agent_features/test_async_context_propagation.py @@ -16,9 +16,8 @@ from testing_support.fixtures import ( function_not_called, override_generic_settings, - validate_transaction_metrics, ) - +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.application import application_instance as application from newrelic.api.background_task import BackgroundTask, background_task from newrelic.api.database_trace import database_trace diff --git a/tests/agent_features/test_browser.py b/tests/agent_features/test_browser.py index 5f84920161..98ad22192e 100644 --- a/tests/agent_features/test_browser.py +++ b/tests/agent_features/test_browser.py @@ -19,8 +19,8 @@ import six from testing_support.fixtures import (override_application_settings, - validate_transaction_errors, validate_custom_parameters) - + validate_custom_parameters) +from testing_support.validators.validate_transaction_errors import validate_transaction_errors from newrelic.api.application import application_settings from newrelic.api.transaction import (get_browser_timing_header, get_browser_timing_footer, add_custom_parameter, diff --git a/tests/agent_features/test_coroutine_trace.py b/tests/agent_features/test_coroutine_trace.py index b155375734..31cb3cb9a1 100644 --- a/tests/agent_features/test_coroutine_trace.py +++ b/tests/agent_features/test_coroutine_trace.py @@ -20,11 +20,10 @@ import pytest from testing_support.fixtures import ( capture_transaction_metrics, - validate_transaction_errors, - validate_transaction_metrics, validate_tt_parenting, ) - +from testing_support.validators.validate_transaction_errors import validate_transaction_errors +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task from newrelic.api.database_trace import database_trace from newrelic.api.datastore_trace import datastore_trace diff --git a/tests/agent_features/test_coroutine_transaction.py b/tests/agent_features/test_coroutine_transaction.py index 1a55385c70..315707bc25 100644 --- a/tests/agent_features/test_coroutine_transaction.py +++ b/tests/agent_features/test_coroutine_transaction.py @@ -19,9 +19,8 @@ from testing_support.fixtures import ( capture_transaction_metrics, override_generic_settings, - validate_transaction_errors, ) - +from testing_support.validators.validate_transaction_errors import validate_transaction_errors from newrelic.api.background_task import background_task from newrelic.api.function_trace import function_trace from newrelic.api.message_transaction import message_transaction diff --git a/tests/agent_features/test_distributed_tracing.py b/tests/agent_features/test_distributed_tracing.py index ae6b4f32db..aed7de100a 100644 --- a/tests/agent_features/test_distributed_tracing.py +++ b/tests/agent_features/test_distributed_tracing.py @@ -27,7 +27,8 @@ from testing_support.fixtures import (override_application_settings, validate_attributes, validate_transaction_event_attributes, - validate_error_event_attributes, validate_transaction_metrics) + validate_error_event_attributes) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics distributed_trace_intrinsics = ['guid', 'traceId', 'priority', 'sampled'] inbound_payload_intrinsics = ['parent.type', 'parent.app', 'parent.account', diff --git a/tests/agent_features/test_event_loop_wait_time.py b/tests/agent_features/test_event_loop_wait_time.py index ccf57c9a4d..f93e78c233 100644 --- a/tests/agent_features/test_event_loop_wait_time.py +++ b/tests/agent_features/test_event_loop_wait_time.py @@ -19,10 +19,10 @@ from testing_support.fixtures import ( override_application_settings, validate_transaction_event_attributes, - validate_transaction_metrics, validate_transaction_trace_attributes, ) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task from newrelic.api.function_trace import FunctionTrace, function_trace from newrelic.api.transaction import current_transaction diff --git a/tests/agent_features/test_high_security_mode.py b/tests/agent_features/test_high_security_mode.py index 89499d3658..fd6065b91f 100644 --- a/tests/agent_features/test_high_security_mode.py +++ b/tests/agent_features/test_high_security_mode.py @@ -27,10 +27,9 @@ validate_custom_parameters, validate_non_transaction_error_event, validate_request_params_omitted, - validate_transaction_errors, validate_tt_segment_params, ) - +from testing_support.validators.validate_transaction_errors import validate_transaction_errors from newrelic.api.application import application_instance as application from newrelic.api.background_task import background_task from newrelic.api.function_trace import FunctionTrace diff --git a/tests/agent_features/test_ignore_expected_errors.py b/tests/agent_features/test_ignore_expected_errors.py index b044c8fa52..f2cd8861a6 100644 --- a/tests/agent_features/test_ignore_expected_errors.py +++ b/tests/agent_features/test_ignore_expected_errors.py @@ -20,11 +20,10 @@ validate_error_event_sample_data, validate_error_trace_attributes_outside_transaction, validate_transaction_error_trace_attributes, - validate_transaction_errors, - validate_transaction_metrics, ) from testing_support.validators.validate_time_metrics_outside_transaction import validate_time_metrics_outside_transaction - +from testing_support.validators.validate_transaction_errors import validate_transaction_errors +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.application import application_instance from newrelic.api.background_task import background_task from newrelic.api.time_trace import notice_error diff --git a/tests/agent_features/test_notice_error.py b/tests/agent_features/test_notice_error.py index e052602a0a..b47335068d 100644 --- a/tests/agent_features/test_notice_error.py +++ b/tests/agent_features/test_notice_error.py @@ -24,9 +24,9 @@ validate_application_errors, validate_transaction_error_event_count, validate_transaction_error_trace_count, - validate_transaction_errors, ) +from testing_support.validators.validate_transaction_errors import validate_transaction_errors from newrelic.api.application import application_instance as application from newrelic.api.application import application_settings from newrelic.api.background_task import background_task diff --git a/tests/agent_features/test_span_events.py b/tests/agent_features/test_span_events.py index 0024c1b8b8..4c4eecc69c 100644 --- a/tests/agent_features/test_span_events.py +++ b/tests/agent_features/test_span_events.py @@ -31,10 +31,11 @@ from testing_support.fixtures import (override_application_settings, function_not_called, validate_tt_segment_params, - validate_transaction_metrics, dt_enabled, + dt_enabled, validate_transaction_event_attributes) from testing_support.validators.validate_span_events import ( validate_span_events) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics ERROR = ValueError("whoops") ERROR_NAME = callable_name(ERROR) diff --git a/tests/agent_features/test_w3c_trace_context.py b/tests/agent_features/test_w3c_trace_context.py index 17e40fdb07..7143e0f46e 100644 --- a/tests/agent_features/test_w3c_trace_context.py +++ b/tests/agent_features/test_w3c_trace_context.py @@ -20,10 +20,10 @@ from newrelic.api.external_trace import ExternalTrace from newrelic.api.wsgi_application import wsgi_application from testing_support.fixtures import (override_application_settings, - validate_transaction_event_attributes, validate_transaction_metrics) + validate_transaction_event_attributes) from testing_support.validators.validate_span_events import ( validate_span_events) - +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics @wsgi_application() def target_wsgi_application(environ, start_response): diff --git a/tests/component_djangorestframework/test_application.py b/tests/component_djangorestframework/test_application.py index 472f2f0297..9ed60aa33d 100644 --- a/tests/component_djangorestframework/test_application.py +++ b/tests/component_djangorestframework/test_application.py @@ -19,9 +19,9 @@ from newrelic.core.config import global_settings from testing_support.fixtures import ( - validate_transaction_errors, override_generic_settings, function_not_called) +from testing_support.validators.validate_transaction_errors import validate_transaction_errors from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics import django diff --git a/tests/component_flask_rest/test_application.py b/tests/component_flask_rest/test_application.py index 391a35674c..bd54b3eba8 100644 --- a/tests/component_flask_rest/test_application.py +++ b/tests/component_flask_rest/test_application.py @@ -16,11 +16,11 @@ from newrelic.packages import six from testing_support.fixtures import ( - validate_transaction_errors, override_ignore_status_codes, override_generic_settings) from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics +from testing_support.validators.validate_transaction_errors import validate_transaction_errors from newrelic.core.config import global_settings from newrelic.common.object_names import callable_name diff --git a/tests/component_graphqlserver/test_graphql.py b/tests/component_graphqlserver/test_graphql.py index 997df11742..e5566047ec 100644 --- a/tests/component_graphqlserver/test_graphql.py +++ b/tests/component_graphqlserver/test_graphql.py @@ -15,11 +15,9 @@ import importlib import pytest -from testing_support.fixtures import ( - dt_enabled, - validate_transaction_errors, - validate_transaction_metrics, -) +from testing_support.fixtures import dt_enabled +from testing_support.validators.validate_transaction_errors import validate_transaction_errors +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_span_events import validate_span_events from testing_support.validators.validate_transaction_count import ( validate_transaction_count, diff --git a/tests/component_tastypie/test_application.py b/tests/component_tastypie/test_application.py index 378a94c169..5f81d08319 100644 --- a/tests/component_tastypie/test_application.py +++ b/tests/component_tastypie/test_application.py @@ -21,9 +21,8 @@ from newrelic.api.background_task import background_task from newrelic.api.transaction import end_of_transaction -from testing_support.fixtures import ( - validate_transaction_errors, - override_ignore_status_codes) +from testing_support.fixtures import override_ignore_status_codes +from testing_support.validators.validate_transaction_errors import validate_transaction_errors from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics diff --git a/tests/coroutines_asyncio/test_context_propagation.py b/tests/coroutines_asyncio/test_context_propagation.py index 3beef38d08..09fccffb2d 100644 --- a/tests/coroutines_asyncio/test_context_propagation.py +++ b/tests/coroutines_asyncio/test_context_propagation.py @@ -18,9 +18,9 @@ from testing_support.fixtures import ( function_not_called, override_generic_settings, - validate_transaction_metrics, ) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.application import application_instance as application from newrelic.api.background_task import BackgroundTask, background_task from newrelic.api.database_trace import database_trace diff --git a/tests/cross_agent/test_distributed_tracing.py b/tests/cross_agent/test_distributed_tracing.py index 2ec246275b..7b0be1ca20 100644 --- a/tests/cross_agent/test_distributed_tracing.py +++ b/tests/cross_agent/test_distributed_tracing.py @@ -23,10 +23,11 @@ from newrelic.common.object_wrapper import transient_function_wrapper from testing_support.fixtures import (override_application_settings, - validate_transaction_metrics, validate_transaction_event_attributes, + validate_transaction_event_attributes, validate_error_event_attributes, validate_attributes) from testing_support.validators.validate_span_events import ( validate_span_events) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) JSON_DIR = os.path.normpath(os.path.join(CURRENT_DIR, 'fixtures', diff --git a/tests/cross_agent/test_w3c_trace_context.py b/tests/cross_agent/test_w3c_trace_context.py index 479d799bc2..efc13c25dd 100644 --- a/tests/cross_agent/test_w3c_trace_context.py +++ b/tests/cross_agent/test_w3c_trace_context.py @@ -24,9 +24,10 @@ from testing_support.validators.validate_span_events import ( validate_span_events) from testing_support.fixtures import (override_application_settings, - validate_transaction_metrics, validate_transaction_event_attributes, + validate_transaction_event_attributes, validate_attributes) from newrelic.common.encoding_utils import W3CTraceState +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) JSON_DIR = os.path.normpath(os.path.join(CURRENT_DIR, 'fixtures', diff --git a/tests/datastore_aredis/test_multiple_dbs.py b/tests/datastore_aredis/test_multiple_dbs.py index e16ae94831..cb4cbac5b2 100644 --- a/tests/datastore_aredis/test_multiple_dbs.py +++ b/tests/datastore_aredis/test_multiple_dbs.py @@ -15,10 +15,8 @@ import aredis import pytest from testing_support.db_settings import redis_settings -from testing_support.fixtures import ( - override_application_settings, - validate_transaction_metrics, -) +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.util import instance_hostname from newrelic.api.background_task import background_task diff --git a/tests/datastore_asyncpg/test_multiple_dbs.py b/tests/datastore_asyncpg/test_multiple_dbs.py index a24eaa3885..a917a9e83d 100644 --- a/tests/datastore_asyncpg/test_multiple_dbs.py +++ b/tests/datastore_asyncpg/test_multiple_dbs.py @@ -17,10 +17,8 @@ import asyncpg import pytest from testing_support.db_settings import postgresql_settings -from testing_support.fixtures import ( - override_application_settings, - validate_transaction_metrics, -) +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.util import instance_hostname from newrelic.api.background_task import background_task diff --git a/tests/datastore_asyncpg/test_query.py b/tests/datastore_asyncpg/test_query.py index eb44cfd164..a952e062ab 100644 --- a/tests/datastore_asyncpg/test_query.py +++ b/tests/datastore_asyncpg/test_query.py @@ -20,10 +20,8 @@ import asyncpg import pytest from testing_support.db_settings import postgresql_settings -from testing_support.fixtures import ( - validate_transaction_metrics, - validate_tt_collector_json, -) +from testing_support.fixtures import validate_tt_collector_json +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.util import instance_hostname from newrelic.api.background_task import background_task diff --git a/tests/datastore_elasticsearch/test_elasticsearch.py b/tests/datastore_elasticsearch/test_elasticsearch.py index f219e01b5e..65a0374df0 100644 --- a/tests/datastore_elasticsearch/test_elasticsearch.py +++ b/tests/datastore_elasticsearch/test_elasticsearch.py @@ -17,9 +17,8 @@ from newrelic.api.background_task import background_task -from testing_support.fixtures import ( - validate_transaction_errors, - override_application_settings) +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_transaction_errors import validate_transaction_errors from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.db_settings import elasticsearch_settings from testing_support.util import instance_hostname diff --git a/tests/datastore_psycopg2/test_async.py b/tests/datastore_psycopg2/test_async.py index 32224b681d..7af9adc6a5 100644 --- a/tests/datastore_psycopg2/test_async.py +++ b/tests/datastore_psycopg2/test_async.py @@ -17,11 +17,10 @@ import pytest from testing_support.fixtures import ( - validate_transaction_errors, validate_stats_engine_explain_plan_output_is_none, override_application_settings) from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics - +from testing_support.validators.validate_transaction_errors import validate_transaction_errors from testing_support.validators.validate_database_trace_inputs import validate_database_trace_inputs from testing_support.validators.validate_transaction_slow_sql_count import ( validate_transaction_slow_sql_count) diff --git a/tests/datastore_psycopg2/test_register.py b/tests/datastore_psycopg2/test_register.py index 8f6d8bfd9b..b5450c3588 100644 --- a/tests/datastore_psycopg2/test_register.py +++ b/tests/datastore_psycopg2/test_register.py @@ -16,7 +16,7 @@ import psycopg2 import psycopg2.extras -from testing_support.fixtures import validate_transaction_errors +from testing_support.validators.validate_transaction_errors import validate_transaction_errors from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from utils import DB_SETTINGS diff --git a/tests/datastore_psycopg2cffi/test_database.py b/tests/datastore_psycopg2cffi/test_database.py index 48e85e77b7..54ff6ad09d 100644 --- a/tests/datastore_psycopg2cffi/test_database.py +++ b/tests/datastore_psycopg2cffi/test_database.py @@ -16,8 +16,8 @@ import psycopg2cffi.extensions import psycopg2cffi.extras -from testing_support.fixtures import ( - validate_transaction_errors, validate_stats_engine_explain_plan_output_is_none) +from testing_support.fixtures import validate_stats_engine_explain_plan_output_is_none +from testing_support.validators.validate_transaction_errors import validate_transaction_errors from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_transaction_slow_sql_count import \ validate_transaction_slow_sql_count diff --git a/tests/datastore_pyelasticsearch/test_pyelasticsearch.py b/tests/datastore_pyelasticsearch/test_pyelasticsearch.py index 7554e9a3db..deb3f68ff5 100644 --- a/tests/datastore_pyelasticsearch/test_pyelasticsearch.py +++ b/tests/datastore_pyelasticsearch/test_pyelasticsearch.py @@ -15,7 +15,7 @@ import sqlite3 from pyelasticsearch import ElasticSearch -from testing_support.fixtures import validate_transaction_errors +from testing_support.validators.validate_transaction_errors import validate_transaction_errors from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.db_settings import elasticsearch_settings from testing_support.validators.validate_database_duration import validate_database_duration diff --git a/tests/datastore_pymongo/test_pymongo.py b/tests/datastore_pymongo/test_pymongo.py index 09ea62e0b3..4649062cee 100644 --- a/tests/datastore_pymongo/test_pymongo.py +++ b/tests/datastore_pymongo/test_pymongo.py @@ -16,14 +16,11 @@ import pymongo from testing_support.db_settings import mongodb_settings -from testing_support.fixtures import ( - validate_transaction_errors, - validate_transaction_metrics, -) from testing_support.validators.validate_database_duration import ( validate_database_duration, ) - +from testing_support.validators.validate_transaction_errors import validate_transaction_errors +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task from newrelic.packages import six diff --git a/tests/external_http/test_http.py b/tests/external_http/test_http.py index 16bef3f2af..e08518f5ff 100644 --- a/tests/external_http/test_http.py +++ b/tests/external_http/test_http.py @@ -21,8 +21,8 @@ from testing_support.fixtures import ( cat_enabled, override_application_settings, - validate_transaction_metrics, ) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_cross_process_headers import ( validate_cross_process_headers, ) diff --git a/tests/external_httplib/test_httplib.py b/tests/external_httplib/test_httplib.py index 69f7908468..c7747f8ff7 100644 --- a/tests/external_httplib/test_httplib.py +++ b/tests/external_httplib/test_httplib.py @@ -26,9 +26,9 @@ from testing_support.fixtures import ( cat_enabled, override_application_settings, - validate_transaction_metrics, validate_tt_segment_params, ) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_cross_process_headers import ( validate_cross_process_headers, ) diff --git a/tests/external_httplib2/test_httplib2.py b/tests/external_httplib2/test_httplib2.py index d3e71e7b3f..288aa84ee9 100644 --- a/tests/external_httplib2/test_httplib2.py +++ b/tests/external_httplib2/test_httplib2.py @@ -21,7 +21,6 @@ from testing_support.fixtures import ( cat_enabled, override_application_settings, - validate_transaction_metrics, ) from testing_support.validators.validate_cross_process_headers import ( validate_cross_process_headers, @@ -29,6 +28,7 @@ from testing_support.validators.validate_external_node_params import ( validate_external_node_params, ) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task diff --git a/tests/external_httpx/test_client.py b/tests/external_httpx/test_client.py index 1d170a5fa2..87a1bc7d01 100644 --- a/tests/external_httpx/test_client.py +++ b/tests/external_httpx/test_client.py @@ -19,8 +19,6 @@ dt_enabled, override_application_settings, override_generic_settings, - validate_transaction_errors, - validate_transaction_metrics, validate_tt_segment_params, ) from testing_support.mock_external_http_server import ( @@ -30,6 +28,8 @@ validate_cross_process_headers, ) from testing_support.validators.validate_span_events import validate_span_events +from testing_support.validators.validate_transaction_errors import validate_transaction_errors +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task from newrelic.api.time_trace import current_trace diff --git a/tests/external_requests/test_requests.py b/tests/external_requests/test_requests.py index b61cf36df8..f6f4506e51 100644 --- a/tests/external_requests/test_requests.py +++ b/tests/external_requests/test_requests.py @@ -22,8 +22,6 @@ from testing_support.fixtures import ( cat_enabled, override_application_settings, - validate_transaction_errors, - validate_transaction_metrics, validate_tt_parenting, ) from testing_support.validators.validate_cross_process_headers import ( @@ -32,7 +30,8 @@ from testing_support.validators.validate_external_node_params import ( validate_external_node_params, ) - +from testing_support.validators.validate_transaction_errors import validate_transaction_errors +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task diff --git a/tests/external_urllib3/test_urllib3.py b/tests/external_urllib3/test_urllib3.py index 93287e000e..68e15d4634 100644 --- a/tests/external_urllib3/test_urllib3.py +++ b/tests/external_urllib3/test_urllib3.py @@ -28,8 +28,6 @@ from testing_support.fixtures import ( cat_enabled, override_application_settings, - validate_transaction_errors, - validate_transaction_metrics, ) from testing_support.util import version2tuple from testing_support.validators.validate_cross_process_headers import ( @@ -38,7 +36,8 @@ from testing_support.validators.validate_external_node_params import ( validate_external_node_params, ) - +from testing_support.validators.validate_transaction_errors import validate_transaction_errors +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task diff --git a/tests/framework_aiohttp/test_client_cat.py b/tests/framework_aiohttp/test_client_cat.py index a830c2269f..0cb39a604c 100644 --- a/tests/framework_aiohttp/test_client_cat.py +++ b/tests/framework_aiohttp/test_client_cat.py @@ -18,10 +18,8 @@ import aiohttp import pytest from testing_support.external_fixtures import create_incoming_headers -from testing_support.fixtures import ( - override_application_settings, - validate_transaction_metrics, -) +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_cross_process_headers import ( validate_cross_process_headers, ) diff --git a/tests/framework_aiohttp/test_server.py b/tests/framework_aiohttp/test_server.py index f09f2b615b..4f0347df1a 100644 --- a/tests/framework_aiohttp/test_server.py +++ b/tests/framework_aiohttp/test_server.py @@ -18,11 +18,12 @@ from newrelic.core.config import global_settings from testing_support.fixtures import ( - validate_transaction_errors, validate_transaction_event_attributes, + validate_transaction_event_attributes, count_transactions, override_generic_settings, override_application_settings, override_ignore_status_codes) from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics +from testing_support.validators.validate_transaction_errors import validate_transaction_errors version_info = tuple(int(_) for _ in aiohttp.__version__.split('.')[:2]) diff --git a/tests/framework_ariadne/test_application.py b/tests/framework_ariadne/test_application.py index f0b3587b87..ed60397b95 100644 --- a/tests/framework_ariadne/test_application.py +++ b/tests/framework_ariadne/test_application.py @@ -13,15 +13,11 @@ # limitations under the License. import pytest -from testing_support.fixtures import ( - dt_enabled, - validate_transaction_errors, - validate_transaction_metrics, -) +from testing_support.fixtures import dt_enabled from testing_support.validators.validate_span_events import validate_span_events -from testing_support.validators.validate_transaction_count import ( - validate_transaction_count, -) +from testing_support.validators.validate_transaction_errors import validate_transaction_errors +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics +from testing_support.validators.validate_transaction_count import validate_transaction_count from newrelic.api.background_task import background_task from newrelic.common.object_names import callable_name diff --git a/tests/framework_bottle/test_application.py b/tests/framework_bottle/test_application.py index 56e3b0f65d..28619d5eb5 100644 --- a/tests/framework_bottle/test_application.py +++ b/tests/framework_bottle/test_application.py @@ -16,11 +16,12 @@ import base64 from testing_support.fixtures import ( - validate_transaction_errors, override_ignore_status_codes, + override_ignore_status_codes, override_application_settings) from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.packages import six from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics +from testing_support.validators.validate_transaction_errors import validate_transaction_errors import webtest diff --git a/tests/framework_cherrypy/test_application.py b/tests/framework_cherrypy/test_application.py index 1dd7f837d1..39f8b5c16d 100644 --- a/tests/framework_cherrypy/test_application.py +++ b/tests/framework_cherrypy/test_application.py @@ -17,9 +17,11 @@ from newrelic.packages import six -from testing_support.fixtures import (validate_transaction_errors, - override_application_settings, override_ignore_status_codes) +from testing_support.fixtures import ( + override_application_settings, + override_ignore_status_codes) from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics +from testing_support.validators.validate_transaction_errors import validate_transaction_errors import cherrypy diff --git a/tests/framework_cherrypy/test_dispatch.py b/tests/framework_cherrypy/test_dispatch.py index 0a3f8e7c71..64dccb2146 100644 --- a/tests/framework_cherrypy/test_dispatch.py +++ b/tests/framework_cherrypy/test_dispatch.py @@ -17,7 +17,7 @@ from newrelic.packages import six -from testing_support.fixtures import validate_transaction_errors +from testing_support.validators.validate_transaction_errors import validate_transaction_errors import cherrypy diff --git a/tests/framework_cherrypy/test_resource.py b/tests/framework_cherrypy/test_resource.py index 09c68f9fc5..385d28d91e 100644 --- a/tests/framework_cherrypy/test_resource.py +++ b/tests/framework_cherrypy/test_resource.py @@ -14,7 +14,7 @@ import webtest -from testing_support.fixtures import validate_transaction_errors +from testing_support.validators.validate_transaction_errors import validate_transaction_errors from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics import cherrypy diff --git a/tests/framework_cherrypy/test_routes.py b/tests/framework_cherrypy/test_routes.py index 7c1b231812..9111a29ced 100644 --- a/tests/framework_cherrypy/test_routes.py +++ b/tests/framework_cherrypy/test_routes.py @@ -16,7 +16,7 @@ import sys import webtest -from testing_support.fixtures import validate_transaction_errors +from testing_support.validators.validate_transaction_errors import validate_transaction_errors from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics import cherrypy diff --git a/tests/framework_django/test_application.py b/tests/framework_django/test_application.py index 1bee82346a..1f2616b0fa 100644 --- a/tests/framework_django/test_application.py +++ b/tests/framework_django/test_application.py @@ -13,11 +13,12 @@ # limitations under the License. from testing_support.fixtures import ( - validate_transaction_errors, override_application_settings, + override_application_settings, override_generic_settings, override_ignore_status_codes) from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics from newrelic.hooks.framework_django import django_settings from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics +from testing_support.validators.validate_transaction_errors import validate_transaction_errors import os diff --git a/tests/framework_django/test_asgi_application.py b/tests/framework_django/test_asgi_application.py index e714d52770..4570427662 100644 --- a/tests/framework_django/test_asgi_application.py +++ b/tests/framework_django/test_asgi_application.py @@ -19,10 +19,11 @@ from newrelic.core.config import global_settings from newrelic.common.encoding_utils import gzip_decompress from testing_support.fixtures import ( - validate_transaction_errors, override_application_settings, + override_application_settings, override_generic_settings, override_ignore_status_codes) from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics +from testing_support.validators.validate_transaction_errors import validate_transaction_errors DJANGO_VERSION = tuple(map(int, django.get_version().split('.')[:2])) diff --git a/tests/framework_falcon/test_application.py b/tests/framework_falcon/test_application.py index e0810c345c..6b64c8c678 100644 --- a/tests/framework_falcon/test_application.py +++ b/tests/framework_falcon/test_application.py @@ -15,10 +15,11 @@ import pytest from newrelic.core.config import global_settings from testing_support.fixtures import ( - validate_transaction_errors, override_ignore_status_codes, + override_ignore_status_codes, override_generic_settings) from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics +from testing_support.validators.validate_transaction_errors import validate_transaction_errors SETTINGS = global_settings() diff --git a/tests/framework_flask/test_application.py b/tests/framework_flask/test_application.py index 5aebc11176..de7a430191 100644 --- a/tests/framework_flask/test_application.py +++ b/tests/framework_flask/test_application.py @@ -15,10 +15,11 @@ import pytest from testing_support.fixtures import ( - validate_transaction_errors, override_application_settings, + override_application_settings, validate_tt_parenting) from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics +from testing_support.validators.validate_transaction_errors import validate_transaction_errors from newrelic.packages import six diff --git a/tests/framework_flask/test_blueprints.py b/tests/framework_flask/test_blueprints.py index 5f8abd4412..4a1e361fb4 100644 --- a/tests/framework_flask/test_blueprints.py +++ b/tests/framework_flask/test_blueprints.py @@ -14,10 +14,10 @@ import pytest -from testing_support.fixtures import ( - validate_transaction_errors, override_application_settings) +from testing_support.fixtures import override_application_settings from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics +from testing_support.validators.validate_transaction_errors import validate_transaction_errors from newrelic.packages import six diff --git a/tests/framework_flask/test_compress.py b/tests/framework_flask/test_compress.py index 49138fe272..f6feb01ee4 100644 --- a/tests/framework_flask/test_compress.py +++ b/tests/framework_flask/test_compress.py @@ -12,9 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -from testing_support.fixtures import ( - validate_transaction_errors, override_application_settings) +from testing_support.fixtures import override_application_settings from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics +from testing_support.validators.validate_transaction_errors import validate_transaction_errors from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics diff --git a/tests/framework_flask/test_middleware.py b/tests/framework_flask/test_middleware.py index 9f56163b73..3c81ebc47a 100644 --- a/tests/framework_flask/test_middleware.py +++ b/tests/framework_flask/test_middleware.py @@ -14,10 +14,10 @@ import pytest -from testing_support.fixtures import ( - validate_transaction_errors, override_application_settings) +from testing_support.fixtures import override_application_settings from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics +from testing_support.validators.validate_transaction_errors import validate_transaction_errors def target_application(): # We need to delay Flask application creation because of ordering diff --git a/tests/framework_flask/test_not_found.py b/tests/framework_flask/test_not_found.py index 523a8e593f..c1c55475ea 100644 --- a/tests/framework_flask/test_not_found.py +++ b/tests/framework_flask/test_not_found.py @@ -14,7 +14,7 @@ import pytest -from testing_support.fixtures import validate_transaction_errors +from testing_support.validators.validate_transaction_errors import validate_transaction_errors from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics def target_application(): diff --git a/tests/framework_flask/test_user_exceptions.py b/tests/framework_flask/test_user_exceptions.py index a69c69b92e..844b4b9ef6 100644 --- a/tests/framework_flask/test_user_exceptions.py +++ b/tests/framework_flask/test_user_exceptions.py @@ -14,7 +14,7 @@ import pytest -from testing_support.fixtures import validate_transaction_errors +from testing_support.validators.validate_transaction_errors import validate_transaction_errors from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics def target_application(): diff --git a/tests/framework_flask/test_views.py b/tests/framework_flask/test_views.py index d4dd8178f2..d45021bff0 100644 --- a/tests/framework_flask/test_views.py +++ b/tests/framework_flask/test_views.py @@ -16,10 +16,9 @@ async_handler_support, skip_if_not_async_handler_support, ) -from testing_support.fixtures import ( - validate_transaction_errors, - validate_transaction_metrics, -) +from testing_support.validators.validate_transaction_errors import validate_transaction_errors +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics + scoped_metrics = [ ("Function/flask.app:Flask.wsgi_app", 1), diff --git a/tests/framework_graphene/test_application.py b/tests/framework_graphene/test_application.py index b4e8e07394..b9d374a3ce 100644 --- a/tests/framework_graphene/test_application.py +++ b/tests/framework_graphene/test_application.py @@ -14,15 +14,13 @@ import pytest import six -from testing_support.fixtures import ( - dt_enabled, - validate_transaction_errors, - validate_transaction_metrics, -) +from testing_support.fixtures import dt_enabled from testing_support.validators.validate_span_events import validate_span_events from testing_support.validators.validate_transaction_count import ( validate_transaction_count, ) +from testing_support.validators.validate_transaction_errors import validate_transaction_errors +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task from newrelic.common.object_names import callable_name diff --git a/tests/framework_graphql/test_application.py b/tests/framework_graphql/test_application.py index 770c6f6e15..56dc3a7382 100644 --- a/tests/framework_graphql/test_application.py +++ b/tests/framework_graphql/test_application.py @@ -13,16 +13,14 @@ # limitations under the License. import pytest -from testing_support.fixtures import ( - dt_enabled, - validate_transaction_errors, - validate_transaction_metrics, -) +from testing_support.fixtures import dt_enabled from testing_support.validators.validate_span_events import validate_span_events from testing_support.validators.validate_transaction_count import ( validate_transaction_count, ) from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics +from testing_support.validators.validate_transaction_errors import validate_transaction_errors +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task from newrelic.common.object_names import callable_name diff --git a/tests/framework_grpc/test_clients.py b/tests/framework_grpc/test_clients.py index 9fa62d5574..c6ada806bc 100644 --- a/tests/framework_grpc/test_clients.py +++ b/tests/framework_grpc/test_clients.py @@ -18,7 +18,7 @@ from newrelic.api.background_task import background_task -from testing_support.fixtures import validate_transaction_errors +from testing_support.validators.validate_transaction_errors import validate_transaction_errors from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from _test_common import create_request, get_result diff --git a/tests/framework_grpc/test_distributed_tracing.py b/tests/framework_grpc/test_distributed_tracing.py index 7cd134ca00..7f253651dc 100644 --- a/tests/framework_grpc/test_distributed_tracing.py +++ b/tests/framework_grpc/test_distributed_tracing.py @@ -21,12 +21,11 @@ from newrelic.common.encoding_utils import ( DistributedTracePayload, W3CTraceParent, W3CTraceState, NrTraceState) -from testing_support.fixtures import (override_application_settings, - validate_transaction_metrics) +from testing_support.fixtures import override_application_settings from testing_support.validators.validate_span_events import ( validate_span_events) from _test_common import create_request, wait_for_transaction_completion - +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics _test_matrix = ('method_name,streaming_request', ( ('DoUnaryUnary', False), diff --git a/tests/framework_grpc/test_server.py b/tests/framework_grpc/test_server.py index e80b103b8d..92ec9c4b3c 100644 --- a/tests/framework_grpc/test_server.py +++ b/tests/framework_grpc/test_server.py @@ -20,10 +20,10 @@ from newrelic.core.config import global_settings from testing_support.fixtures import ( validate_transaction_event_attributes, override_application_settings, - override_generic_settings, function_not_called, - validate_transaction_errors) + override_generic_settings, function_not_called) from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics +from testing_support.validators.validate_transaction_errors import validate_transaction_errors def select_python_version(py2, py3): return six.PY3 and py3 or py2 diff --git a/tests/framework_pyramid/test_append_slash_app.py b/tests/framework_pyramid/test_append_slash_app.py index 10053e7cc7..f09e14b55d 100644 --- a/tests/framework_pyramid/test_append_slash_app.py +++ b/tests/framework_pyramid/test_append_slash_app.py @@ -34,9 +34,9 @@ import pytest import re -from testing_support.fixtures import ( - validate_transaction_errors, override_application_settings) +from testing_support.fixtures import override_application_settings from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics +from testing_support.validators.validate_transaction_errors import validate_transaction_errors def _to_int(version_str): m = re.match(r'\d+', version_str) diff --git a/tests/framework_pyramid/test_application.py b/tests/framework_pyramid/test_application.py index 6bae117e9c..132e0f72af 100644 --- a/tests/framework_pyramid/test_application.py +++ b/tests/framework_pyramid/test_application.py @@ -14,9 +14,9 @@ import pytest -from testing_support.fixtures import ( - validate_transaction_errors, override_application_settings) +from testing_support.fixtures import override_application_settings from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics +from testing_support.validators.validate_transaction_errors import validate_transaction_errors from newrelic.packages import six from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics diff --git a/tests/framework_pyramid/test_cornice.py b/tests/framework_pyramid/test_cornice.py index 8b8dc58d24..fe36831e00 100644 --- a/tests/framework_pyramid/test_cornice.py +++ b/tests/framework_pyramid/test_cornice.py @@ -14,9 +14,9 @@ import pytest -from testing_support.fixtures import (validate_transaction_errors, - validate_transaction_metrics) from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics +from testing_support.validators.validate_transaction_errors import validate_transaction_errors from newrelic.packages import six diff --git a/tests/framework_sanic/test_application.py b/tests/framework_sanic/test_application.py index 9ea9b92c42..ccb0dec67e 100644 --- a/tests/framework_sanic/test_application.py +++ b/tests/framework_sanic/test_application.py @@ -23,12 +23,13 @@ from newrelic.api.external_trace import ExternalTrace from testing_support.fixtures import ( - override_application_settings, validate_transaction_errors, + override_application_settings, validate_transaction_event_attributes, override_ignore_status_codes, override_generic_settings, function_not_called) from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics +from testing_support.validators.validate_transaction_errors import validate_transaction_errors sanic_21 = int(sanic.__version__.split('.', 1)[0]) >= 21 diff --git a/tests/framework_sanic/test_cross_application.py b/tests/framework_sanic/test_cross_application.py index 0c1c724cf0..55e5a35783 100644 --- a/tests/framework_sanic/test_cross_application.py +++ b/tests/framework_sanic/test_cross_application.py @@ -25,8 +25,8 @@ from testing_support.fixtures import (override_application_settings, make_cross_agent_headers, validate_analytics_catmap_data, - validate_transaction_metrics, validate_transaction_event_attributes) - + validate_transaction_event_attributes) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics BASE_METRICS = [ ('Function/_target_application:index', 1), diff --git a/tests/framework_starlette/test_application.py b/tests/framework_starlette/test_application.py index 9c5944bd00..7d36d66ccc 100644 --- a/tests/framework_starlette/test_application.py +++ b/tests/framework_starlette/test_application.py @@ -16,14 +16,12 @@ import pytest import starlette -from testing_support.fixtures import ( - override_ignore_status_codes, - validate_transaction_errors, - validate_transaction_metrics, -) +from testing_support.fixtures import override_ignore_status_codes from newrelic.common.object_names import callable_name from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics +from testing_support.validators.validate_transaction_errors import validate_transaction_errors +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics starlette_version = tuple(int(x) for x in starlette.__version__.split(".")) diff --git a/tests/framework_strawberry/test_application.py b/tests/framework_strawberry/test_application.py index ff6d0e2ed6..d57de74f44 100644 --- a/tests/framework_strawberry/test_application.py +++ b/tests/framework_strawberry/test_application.py @@ -13,15 +13,11 @@ # limitations under the License. import pytest -from testing_support.fixtures import ( - dt_enabled, - validate_transaction_errors, - validate_transaction_metrics, -) +from testing_support.fixtures import dt_enabled from testing_support.validators.validate_span_events import validate_span_events -from testing_support.validators.validate_transaction_count import ( - validate_transaction_count, -) +from testing_support.validators.validate_transaction_errors import validate_transaction_errors +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics +from testing_support.validators.validate_transaction_count import validate_transaction_count from newrelic.api.background_task import background_task from newrelic.common.object_names import callable_name diff --git a/tests/framework_tornado/test_externals.py b/tests/framework_tornado/test_externals.py index 7d973ac5f5..0c44e43361 100644 --- a/tests/framework_tornado/test_externals.py +++ b/tests/framework_tornado/test_externals.py @@ -17,10 +17,8 @@ import sys import pytest -from testing_support.fixtures import ( - override_application_settings, - validate_transaction_metrics, -) +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.mock_external_http_server import ( MockExternalHTTPHResponseHeadersServer, MockExternalHTTPServer, diff --git a/tests/framework_tornado/test_inbound_cat.py b/tests/framework_tornado/test_inbound_cat.py index 87ebe03d0b..c399f70d5c 100644 --- a/tests/framework_tornado/test_inbound_cat.py +++ b/tests/framework_tornado/test_inbound_cat.py @@ -15,8 +15,8 @@ import json import pytest from testing_support.fixtures import (make_cross_agent_headers, - override_application_settings, validate_transaction_event_attributes, - validate_transaction_metrics) + override_application_settings, validate_transaction_event_attributes) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics ENCODING_KEY = '1234567890123456789012345678901234567890' diff --git a/tests/framework_tornado/test_server.py b/tests/framework_tornado/test_server.py index 9a0bb96d49..57eb8b5761 100644 --- a/tests/framework_tornado/test_server.py +++ b/tests/framework_tornado/test_server.py @@ -17,12 +17,13 @@ from testing_support.fixtures import ( override_generic_settings, function_not_called, validate_transaction_event_attributes, - validate_transaction_errors, override_ignore_status_codes, + override_ignore_status_codes, override_application_settings) from testing_support.validators.validate_transaction_count import ( validate_transaction_count) from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics +from testing_support.validators.validate_transaction_errors import validate_transaction_errors @pytest.mark.parametrize('uri,name,metrics, method_metric', ( # ('/native-simple', '_target_application:NativeSimpleHandler.get', None, diff --git a/tests/logger_logging/test_metrics.py b/tests/logger_logging/test_metrics.py index eb9419daff..f5a1c5e8da 100644 --- a/tests/logger_logging/test_metrics.py +++ b/tests/logger_logging/test_metrics.py @@ -16,10 +16,7 @@ from newrelic.api.background_task import background_task from testing_support.fixtures import reset_core_stats_engine from testing_support.validators.validate_custom_metrics_outside_transaction import validate_custom_metrics_outside_transaction -from testing_support.fixtures import ( - validate_transaction_metrics, -) - +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics def exercise_logging(logger): logger.debug("A") diff --git a/tests/logger_logging/test_settings.py b/tests/logger_logging/test_settings.py index 2406d87c0b..0581e62188 100644 --- a/tests/logger_logging/test_settings.py +++ b/tests/logger_logging/test_settings.py @@ -18,11 +18,8 @@ from newrelic.api.background_task import background_task from testing_support.fixtures import reset_core_stats_engine from testing_support.validators.validate_log_event_count import validate_log_event_count -from testing_support.fixtures import ( - override_application_settings, - validate_transaction_metrics, -) - +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics def basic_logging(logger): logger.warning("C") diff --git a/tests/logger_loguru/test_metrics.py b/tests/logger_loguru/test_metrics.py index c8a9299c86..9c02d405ec 100644 --- a/tests/logger_loguru/test_metrics.py +++ b/tests/logger_loguru/test_metrics.py @@ -15,9 +15,7 @@ from newrelic.api.background_task import background_task from testing_support.fixtures import reset_core_stats_engine from testing_support.validators.validate_custom_metrics_outside_transaction import validate_custom_metrics_outside_transaction -from testing_support.fixtures import ( - validate_transaction_metrics, -) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics def exercise_logging(logger): diff --git a/tests/logger_loguru/test_settings.py b/tests/logger_loguru/test_settings.py index 4e5dadf5d3..43d675d562 100644 --- a/tests/logger_loguru/test_settings.py +++ b/tests/logger_loguru/test_settings.py @@ -19,11 +19,8 @@ from newrelic.api.background_task import background_task from testing_support.fixtures import reset_core_stats_engine from testing_support.validators.validate_log_event_count import validate_log_event_count -from testing_support.fixtures import ( - override_application_settings, - validate_transaction_metrics, -) - +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics def get_metadata_string(log_message, is_txn): host = platform.uname().node diff --git a/tests/messagebroker_pika/test_cat.py b/tests/messagebroker_pika/test_cat.py index 2b1aac4a76..e6ca848cc0 100644 --- a/tests/messagebroker_pika/test_cat.py +++ b/tests/messagebroker_pika/test_cat.py @@ -23,9 +23,8 @@ from testing_support.fixtures import ( cat_enabled, override_application_settings, - validate_transaction_metrics, ) - +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task from newrelic.api.transaction import current_transaction diff --git a/tests/messagebroker_pika/test_distributed_tracing.py b/tests/messagebroker_pika/test_distributed_tracing.py index f911aaad8f..548d41a0dc 100644 --- a/tests/messagebroker_pika/test_distributed_tracing.py +++ b/tests/messagebroker_pika/test_distributed_tracing.py @@ -23,8 +23,8 @@ from newrelic.common.encoding_utils import DistributedTracePayload from testing_support.db_settings import rabbitmq_settings -from testing_support.fixtures import (override_application_settings, - validate_transaction_metrics) +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics DB_SETTINGS = rabbitmq_settings()[0] diff --git a/tests/messagebroker_pika/test_pika_async_connection_consume.py b/tests/messagebroker_pika/test_pika_async_connection_consume.py index 0ed76503f8..7edf6b6440 100644 --- a/tests/messagebroker_pika/test_pika_async_connection_consume.py +++ b/tests/messagebroker_pika/test_pika_async_connection_consume.py @@ -26,11 +26,11 @@ from conftest import (QUEUE, QUEUE_2, EXCHANGE, EXCHANGE_2, CORRELATION_ID, REPLY_TO, HEADERS, BODY) from testing_support.fixtures import (capture_transaction_metrics, - validate_transaction_metrics, validate_tt_collector_json, + validate_tt_collector_json, function_not_called, override_application_settings) from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics from testing_support.db_settings import rabbitmq_settings - +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics DB_SETTINGS = rabbitmq_settings()[0] diff --git a/tests/messagebroker_pika/test_pika_blocking_connection_consume.py b/tests/messagebroker_pika/test_pika_blocking_connection_consume.py index 417055bfce..c96d42d985 100644 --- a/tests/messagebroker_pika/test_pika_blocking_connection_consume.py +++ b/tests/messagebroker_pika/test_pika_blocking_connection_consume.py @@ -24,9 +24,10 @@ from conftest import QUEUE, EXCHANGE, CORRELATION_ID, REPLY_TO, HEADERS, BODY from testing_support.fixtures import (capture_transaction_metrics, - validate_transaction_metrics, validate_tt_collector_json) + validate_tt_collector_json) from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics from testing_support.db_settings import rabbitmq_settings +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics DB_SETTINGS = rabbitmq_settings()[0] diff --git a/tests/messagebroker_pika/test_pika_produce.py b/tests/messagebroker_pika/test_pika_produce.py index 60e6526e44..0960159fa3 100644 --- a/tests/messagebroker_pika/test_pika_produce.py +++ b/tests/messagebroker_pika/test_pika_produce.py @@ -17,12 +17,12 @@ from testing_support.db_settings import rabbitmq_settings from testing_support.fixtures import ( override_application_settings, - validate_transaction_metrics, validate_tt_collector_json, ) from testing_support.validators.validate_messagebroker_headers import ( validate_messagebroker_headers, ) +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task from newrelic.api.transaction import current_transaction diff --git a/tests/testing_support/fixtures.py b/tests/testing_support/fixtures.py index 0d2f73c065..80122eeebc 100644 --- a/tests/testing_support/fixtures.py +++ b/tests/testing_support/fixtures.py @@ -638,60 +638,60 @@ def _capture_transaction_metrics(wrapped, instance, args, kwargs): # return _validate_wrapper -def validate_transaction_errors(errors=None, required_params=None, forgone_params=None): - errors = errors or [] - required_params = required_params or [] - forgone_params = forgone_params or [] - captured_errors = [] +# def validate_transaction_errors(errors=None, required_params=None, forgone_params=None): +# errors = errors or [] +# required_params = required_params or [] +# forgone_params = forgone_params or [] +# captured_errors = [] - @transient_function_wrapper("newrelic.core.stats_engine", "StatsEngine.record_transaction") - @catch_background_exceptions - def _capture_transaction_errors(wrapped, instance, args, kwargs): - def _bind_params(transaction, *args, **kwargs): - return transaction +# @transient_function_wrapper("newrelic.core.stats_engine", "StatsEngine.record_transaction") +# @catch_background_exceptions +# def _capture_transaction_errors(wrapped, instance, args, kwargs): +# def _bind_params(transaction, *args, **kwargs): +# return transaction - transaction = _bind_params(*args, **kwargs) - captured = transaction.errors +# transaction = _bind_params(*args, **kwargs) +# captured = transaction.errors - captured_errors.append(captured) +# captured_errors.append(captured) - return wrapped(*args, **kwargs) +# return wrapped(*args, **kwargs) - @function_wrapper - def _validate_transaction_errors(wrapped, instance, args, kwargs): - _new_wrapped = _capture_transaction_errors(wrapped) - output = _new_wrapped(*args, **kwargs) +# @function_wrapper +# def _validate_transaction_errors(wrapped, instance, args, kwargs): +# _new_wrapped = _capture_transaction_errors(wrapped) +# output = _new_wrapped(*args, **kwargs) - expected = sorted(errors) +# expected = sorted(errors) - if captured_errors: - captured = captured_errors[0] - else: - captured = [] +# if captured_errors: +# captured = captured_errors[0] +# else: +# captured = [] - if errors and isinstance(errors[0], (tuple, list)): - compare_to = sorted([(e.type, e.message) for e in captured]) - else: - compare_to = sorted([e.type for e in captured]) +# if errors and isinstance(errors[0], (tuple, list)): +# compare_to = sorted([(e.type, e.message) for e in captured]) +# else: +# compare_to = sorted([e.type for e in captured]) - assert expected == compare_to, "expected=%r, captured=%r, errors=%r" % (expected, compare_to, captured) +# assert expected == compare_to, "expected=%r, captured=%r, errors=%r" % (expected, compare_to, captured) - for e in captured: - assert e.span_id - for name, value in required_params: - assert name in e.custom_params, "name=%r, params=%r" % (name, e.custom_params) - assert e.custom_params[name] == value, "name=%r, value=%r, params=%r" % ( - name, - value, - e.custom_params, - ) +# for e in captured: +# assert e.span_id +# for name, value in required_params: +# assert name in e.custom_params, "name=%r, params=%r" % (name, e.custom_params) +# assert e.custom_params[name] == value, "name=%r, value=%r, params=%r" % ( +# name, +# value, +# e.custom_params, +# ) - for name, value in forgone_params: - assert name not in e.custom_params, "name=%r, params=%r" % (name, e.custom_params) +# for name, value in forgone_params: +# assert name not in e.custom_params, "name=%r, params=%r" % (name, e.custom_params) - return output +# return output - return _validate_transaction_errors +# return _validate_transaction_errors def validate_application_errors(errors=None, required_params=None, forgone_params=None): diff --git a/tests/testing_support/validators/validate_transaction_errors.py b/tests/testing_support/validators/validate_transaction_errors.py new file mode 100644 index 0000000000..b00b7facd1 --- /dev/null +++ b/tests/testing_support/validators/validate_transaction_errors.py @@ -0,0 +1,76 @@ +# Copyright 2010 New Relic, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import copy + +from newrelic.common.object_wrapper import ( + function_wrapper, + transient_function_wrapper, +) +from testing_support.fixtures import catch_background_exceptions + +def validate_transaction_errors(errors=None, required_params=None, forgone_params=None): + errors = errors or [] + required_params = required_params or [] + forgone_params = forgone_params or [] + captured_errors = [] + + @transient_function_wrapper("newrelic.core.stats_engine", "StatsEngine.record_transaction") + @catch_background_exceptions + def _capture_transaction_errors(wrapped, instance, args, kwargs): + def _bind_params(transaction, *args, **kwargs): + return transaction + + transaction = _bind_params(*args, **kwargs) + captured = transaction.errors + + captured_errors.append(captured) + + return wrapped(*args, **kwargs) + + @function_wrapper + def _validate_transaction_errors(wrapped, instance, args, kwargs): + _new_wrapped = _capture_transaction_errors(wrapped) + output = _new_wrapped(*args, **kwargs) + + expected = sorted(errors) + + if captured_errors: + captured = captured_errors[0] + else: + captured = [] + + if errors and isinstance(errors[0], (tuple, list)): + compare_to = sorted([(e.type, e.message) for e in captured]) + else: + compare_to = sorted([e.type for e in captured]) + + assert expected == compare_to, "expected=%r, captured=%r, errors=%r" % (expected, compare_to, captured) + + for e in captured: + assert e.span_id + for name, value in required_params: + assert name in e.custom_params, "name=%r, params=%r" % (name, e.custom_params) + assert e.custom_params[name] == value, "name=%r, value=%r, params=%r" % ( + name, + value, + e.custom_params, + ) + + for name, value in forgone_params: + assert name not in e.custom_params, "name=%r, params=%r" % (name, e.custom_params) + + return output + + return _validate_transaction_errors From f20b9b56f883531441fdef69477a36d656e0045b Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Tue, 30 Aug 2022 17:22:38 -0700 Subject: [PATCH 06/14] Move validate_application_errors into validators directory --- tests/agent_features/test_notice_error.py | 2 +- tests/testing_support/fixtures.py | 56 +++++++++---------- .../validators/validate_application_errors.py | 56 +++++++++++++++++++ 3 files changed, 85 insertions(+), 29 deletions(-) create mode 100644 tests/testing_support/validators/validate_application_errors.py diff --git a/tests/agent_features/test_notice_error.py b/tests/agent_features/test_notice_error.py index b47335068d..a4509e2151 100644 --- a/tests/agent_features/test_notice_error.py +++ b/tests/agent_features/test_notice_error.py @@ -21,11 +21,11 @@ reset_core_stats_engine, validate_application_error_event_count, validate_application_error_trace_count, - validate_application_errors, validate_transaction_error_event_count, validate_transaction_error_trace_count, ) +from testing_support.validators.validate_application_errors import validate_application_errors from testing_support.validators.validate_transaction_errors import validate_transaction_errors from newrelic.api.application import application_instance as application from newrelic.api.application import application_settings diff --git a/tests/testing_support/fixtures.py b/tests/testing_support/fixtures.py index 80122eeebc..fc53fc895e 100644 --- a/tests/testing_support/fixtures.py +++ b/tests/testing_support/fixtures.py @@ -694,44 +694,44 @@ def _capture_transaction_metrics(wrapped, instance, args, kwargs): # return _validate_transaction_errors -def validate_application_errors(errors=None, required_params=None, forgone_params=None): - errors = errors or [] - required_params = required_params or [] - forgone_params = forgone_params or [] +# def validate_application_errors(errors=None, required_params=None, forgone_params=None): +# errors = errors or [] +# required_params = required_params or [] +# forgone_params = forgone_params or [] - @function_wrapper - def _validate_application_errors(wrapped, instace, args, kwargs): +# @function_wrapper +# def _validate_application_errors(wrapped, instace, args, kwargs): - try: - result = wrapped(*args, **kwargs) - except: - raise - else: +# try: +# result = wrapped(*args, **kwargs) +# except: +# raise +# else: - stats = core_application_stats_engine() +# stats = core_application_stats_engine() - app_errors = stats.error_data() +# app_errors = stats.error_data() - expected = sorted(errors) - captured = sorted([(e.type, e.message) for e in stats.error_data()]) +# expected = sorted(errors) +# captured = sorted([(e.type, e.message) for e in stats.error_data()]) - assert expected == captured, "expected=%r, captured=%r, errors=%r" % (expected, captured, app_errors) +# assert expected == captured, "expected=%r, captured=%r, errors=%r" % (expected, captured, app_errors) - for e in app_errors: - for name, value in required_params: - assert name in e.parameters["userAttributes"], "name=%r, params=%r" % (name, e.parameters) - assert e.parameters["userAttributes"][name] == value, "name=%r, value=%r, params=%r" % ( - name, - value, - e.parameters, - ) +# for e in app_errors: +# for name, value in required_params: +# assert name in e.parameters["userAttributes"], "name=%r, params=%r" % (name, e.parameters) +# assert e.parameters["userAttributes"][name] == value, "name=%r, value=%r, params=%r" % ( +# name, +# value, +# e.parameters, +# ) - for name, value in forgone_params: - assert name not in e.parameters["userAttributes"], "name=%r, params=%r" % (name, e.parameters) +# for name, value in forgone_params: +# assert name not in e.parameters["userAttributes"], "name=%r, params=%r" % (name, e.parameters) - return result +# return result - return _validate_application_errors +# return _validate_application_errors def validate_custom_parameters(required_params=None, forgone_params=None): diff --git a/tests/testing_support/validators/validate_application_errors.py b/tests/testing_support/validators/validate_application_errors.py new file mode 100644 index 0000000000..7f653d691e --- /dev/null +++ b/tests/testing_support/validators/validate_application_errors.py @@ -0,0 +1,56 @@ +# Copyright 2010 New Relic, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +from newrelic.common.object_wrapper import function_wrapper +from testing_support.fixtures import core_application_stats_engine + +def validate_application_errors(errors=None, required_params=None, forgone_params=None): + errors = errors or [] + required_params = required_params or [] + forgone_params = forgone_params or [] + + @function_wrapper + def _validate_application_errors(wrapped, instace, args, kwargs): + + try: + result = wrapped(*args, **kwargs) + except: + raise + else: + + stats = core_application_stats_engine() + + app_errors = stats.error_data() + + expected = sorted(errors) + captured = sorted([(e.type, e.message) for e in stats.error_data()]) + + assert expected == captured, "expected=%r, captured=%r, errors=%r" % (expected, captured, app_errors) + + for e in app_errors: + for name, value in required_params: + assert name in e.parameters["userAttributes"], "name=%r, params=%r" % (name, e.parameters) + assert e.parameters["userAttributes"][name] == value, "name=%r, value=%r, params=%r" % ( + name, + value, + e.parameters, + ) + + for name, value in forgone_params: + assert name not in e.parameters["userAttributes"], "name=%r, params=%r" % (name, e.parameters) + + return result + + return _validate_application_errors From 5efcfa80f6a13ec5367859906d7d80739be70124 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Tue, 30 Aug 2022 17:27:09 -0700 Subject: [PATCH 07/14] Move validate_custom_parameters into validators directory --- tests/agent_features/test_asgi_browser.py | 4 +- tests/agent_features/test_attribute.py | 4 +- tests/agent_features/test_browser.py | 4 +- .../agent_features/test_high_security_mode.py | 2 +- tests/testing_support/fixtures.py | 44 ++++++++--------- .../validators/validate_custom_parameters.py | 48 +++++++++++++++++++ 6 files changed, 77 insertions(+), 29 deletions(-) create mode 100644 tests/testing_support/validators/validate_custom_parameters.py diff --git a/tests/agent_features/test_asgi_browser.py b/tests/agent_features/test_asgi_browser.py index ef21d7a0b9..379f6752cb 100644 --- a/tests/agent_features/test_asgi_browser.py +++ b/tests/agent_features/test_asgi_browser.py @@ -18,10 +18,10 @@ import pytest import six -from testing_support.fixtures import (override_application_settings, - validate_custom_parameters) +from testing_support.fixtures import override_application_settings from testing_support.asgi_testing import AsgiTest from testing_support.validators.validate_transaction_errors import validate_transaction_errors +from testing_support.validators.validate_custom_parameters import validate_custom_parameters from newrelic.api.application import application_settings from newrelic.api.transaction import (get_browser_timing_header, get_browser_timing_footer, add_custom_parameter, diff --git a/tests/agent_features/test_attribute.py b/tests/agent_features/test_attribute.py index edfffae2f6..985cf1f81e 100644 --- a/tests/agent_features/test_attribute.py +++ b/tests/agent_features/test_attribute.py @@ -27,9 +27,9 @@ from testing_support.fixtures import (override_application_settings, validate_attributes, validate_attributes_complete, - validate_custom_parameters, validate_agent_attribute_types) + validate_agent_attribute_types) from testing_support.sample_applications import fully_featured_app - +from testing_support.validators.validate_custom_parameters import validate_custom_parameters # Python 3 lacks longs diff --git a/tests/agent_features/test_browser.py b/tests/agent_features/test_browser.py index 98ad22192e..944d649ace 100644 --- a/tests/agent_features/test_browser.py +++ b/tests/agent_features/test_browser.py @@ -18,9 +18,9 @@ import six -from testing_support.fixtures import (override_application_settings, - validate_custom_parameters) +from testing_support.fixtures import override_application_settings from testing_support.validators.validate_transaction_errors import validate_transaction_errors +from testing_support.validators.validate_custom_parameters import validate_custom_parameters from newrelic.api.application import application_settings from newrelic.api.transaction import (get_browser_timing_header, get_browser_timing_footer, add_custom_parameter, diff --git a/tests/agent_features/test_high_security_mode.py b/tests/agent_features/test_high_security_mode.py index fd6065b91f..3f6dbdef02 100644 --- a/tests/agent_features/test_high_security_mode.py +++ b/tests/agent_features/test_high_security_mode.py @@ -24,11 +24,11 @@ validate_attributes_complete, validate_custom_event_count, validate_custom_event_in_application_stats_engine, - validate_custom_parameters, validate_non_transaction_error_event, validate_request_params_omitted, validate_tt_segment_params, ) +from testing_support.validators.validate_custom_parameters import validate_custom_parameters from testing_support.validators.validate_transaction_errors import validate_transaction_errors from newrelic.api.application import application_instance as application from newrelic.api.background_task import background_task diff --git a/tests/testing_support/fixtures.py b/tests/testing_support/fixtures.py index fc53fc895e..000804d92d 100644 --- a/tests/testing_support/fixtures.py +++ b/tests/testing_support/fixtures.py @@ -734,36 +734,36 @@ def _capture_transaction_metrics(wrapped, instance, args, kwargs): # return _validate_application_errors -def validate_custom_parameters(required_params=None, forgone_params=None): - required_params = required_params or [] - forgone_params = forgone_params or [] +# def validate_custom_parameters(required_params=None, forgone_params=None): +# required_params = required_params or [] +# forgone_params = forgone_params or [] - @transient_function_wrapper("newrelic.core.stats_engine", "StatsEngine.record_transaction") - @catch_background_exceptions - def _validate_custom_parameters(wrapped, instance, args, kwargs): - def _bind_params(transaction, *args, **kwargs): - return transaction +# @transient_function_wrapper("newrelic.core.stats_engine", "StatsEngine.record_transaction") +# @catch_background_exceptions +# def _validate_custom_parameters(wrapped, instance, args, kwargs): +# def _bind_params(transaction, *args, **kwargs): +# return transaction - transaction = _bind_params(*args, **kwargs) +# transaction = _bind_params(*args, **kwargs) - # these are pre-destination applied attributes, so they may not - # actually end up in a transaction/error trace, we are merely testing - # for presence on the TransactionNode +# # these are pre-destination applied attributes, so they may not +# # actually end up in a transaction/error trace, we are merely testing +# # for presence on the TransactionNode - attrs = {} - for attr in transaction.user_attributes: - attrs[attr.name] = attr.value +# attrs = {} +# for attr in transaction.user_attributes: +# attrs[attr.name] = attr.value - for name, value in required_params: - assert name in attrs, "name=%r, params=%r" % (name, attrs) - assert attrs[name] == value, "name=%r, value=%r, params=%r" % (name, value, attrs) +# for name, value in required_params: +# assert name in attrs, "name=%r, params=%r" % (name, attrs) +# assert attrs[name] == value, "name=%r, value=%r, params=%r" % (name, value, attrs) - for name, value in forgone_params: - assert name not in attrs, "name=%r, params=%r" % (name, attrs) +# for name, value in forgone_params: +# assert name not in attrs, "name=%r, params=%r" % (name, attrs) - return wrapped(*args, **kwargs) +# return wrapped(*args, **kwargs) - return _validate_custom_parameters +# return _validate_custom_parameters def validate_synthetics_event(required_attrs=None, forgone_attrs=None, should_exist=True): diff --git a/tests/testing_support/validators/validate_custom_parameters.py b/tests/testing_support/validators/validate_custom_parameters.py new file mode 100644 index 0000000000..9dc92fb129 --- /dev/null +++ b/tests/testing_support/validators/validate_custom_parameters.py @@ -0,0 +1,48 @@ +# Copyright 2010 New Relic, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from newrelic.common.object_wrapper import transient_function_wrapper +from testing_support.fixtures import catch_background_exceptions + + +def validate_custom_parameters(required_params=None, forgone_params=None): + required_params = required_params or [] + forgone_params = forgone_params or [] + + @transient_function_wrapper("newrelic.core.stats_engine", "StatsEngine.record_transaction") + @catch_background_exceptions + def _validate_custom_parameters(wrapped, instance, args, kwargs): + def _bind_params(transaction, *args, **kwargs): + return transaction + + transaction = _bind_params(*args, **kwargs) + + # these are pre-destination applied attributes, so they may not + # actually end up in a transaction/error trace, we are merely testing + # for presence on the TransactionNode + + attrs = {} + for attr in transaction.user_attributes: + attrs[attr.name] = attr.value + + for name, value in required_params: + assert name in attrs, "name=%r, params=%r" % (name, attrs) + assert attrs[name] == value, "name=%r, value=%r, params=%r" % (name, value, attrs) + + for name, value in forgone_params: + assert name not in attrs, "name=%r, params=%r" % (name, attrs) + + return wrapped(*args, **kwargs) + + return _validate_custom_parameters \ No newline at end of file From 76ee5a4b43059eaac77a9eb4c8036c5928f9fb57 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Tue, 30 Aug 2022 17:36:16 -0700 Subject: [PATCH 08/14] Move validate_synthetics_event into validators directory --- tests/agent_features/test_synthetics.py | 2 +- tests/testing_support/fixtures.py | 80 +++++++++---------- .../validators/validate_synthetics_event.py | 71 ++++++++++++++++ 3 files changed, 112 insertions(+), 41 deletions(-) create mode 100644 tests/testing_support/validators/validate_synthetics_event.py diff --git a/tests/agent_features/test_synthetics.py b/tests/agent_features/test_synthetics.py index cdf02e3e43..ec7b78e960 100644 --- a/tests/agent_features/test_synthetics.py +++ b/tests/agent_features/test_synthetics.py @@ -19,10 +19,10 @@ cat_enabled, make_synthetics_header, override_application_settings, - validate_synthetics_event, validate_synthetics_transaction_trace, ) +from testing_support.validators.validate_synthetics_event import validate_synthetics_event from newrelic.api.web_transaction import web_transaction from newrelic.api.wsgi_application import wsgi_application from newrelic.common.encoding_utils import deobfuscate, json_decode diff --git a/tests/testing_support/fixtures.py b/tests/testing_support/fixtures.py index 000804d92d..ed83244e3d 100644 --- a/tests/testing_support/fixtures.py +++ b/tests/testing_support/fixtures.py @@ -766,56 +766,56 @@ def _capture_transaction_metrics(wrapped, instance, args, kwargs): # return _validate_custom_parameters -def validate_synthetics_event(required_attrs=None, forgone_attrs=None, should_exist=True): - required_attrs = required_attrs or [] - forgone_attrs = forgone_attrs or [] - failed = [] +# def validate_synthetics_event(required_attrs=None, forgone_attrs=None, should_exist=True): +# required_attrs = required_attrs or [] +# forgone_attrs = forgone_attrs or [] +# failed = [] - @transient_function_wrapper("newrelic.core.stats_engine", "StatsEngine.record_transaction") - def _validate_synthetics_event(wrapped, instance, args, kwargs): - result = wrapped(*args, **kwargs) +# @transient_function_wrapper("newrelic.core.stats_engine", "StatsEngine.record_transaction") +# def _validate_synthetics_event(wrapped, instance, args, kwargs): +# result = wrapped(*args, **kwargs) - try: - if not should_exist: - assert instance.synthetics_events == [] - else: - assert len(instance.synthetics_events) == 1 - event = instance.synthetics_events[0] - assert event is not None - assert len(event) == 3 +# try: +# if not should_exist: +# assert instance.synthetics_events == [] +# else: +# assert len(instance.synthetics_events) == 1 +# event = instance.synthetics_events[0] +# assert event is not None +# assert len(event) == 3 - def _flatten(event): - result = {} - for elem in event: - for k, v in elem.items(): - result[k] = v - return result +# def _flatten(event): +# result = {} +# for elem in event: +# for k, v in elem.items(): +# result[k] = v +# return result - flat_event = _flatten(event) +# flat_event = _flatten(event) - assert "nr.guid" in flat_event, "name=%r, event=%r" % ("nr.guid", flat_event) +# assert "nr.guid" in flat_event, "name=%r, event=%r" % ("nr.guid", flat_event) - for name, value in required_attrs: - assert name in flat_event, "name=%r, event=%r" % (name, flat_event) - assert flat_event[name] == value, "name=%r, value=%r, event=%r" % (name, value, flat_event) +# for name, value in required_attrs: +# assert name in flat_event, "name=%r, event=%r" % (name, flat_event) +# assert flat_event[name] == value, "name=%r, value=%r, event=%r" % (name, value, flat_event) - for name, value in forgone_attrs: - assert name not in flat_event, "name=%r, value=%r, event=%r" % (name, value, flat_event) - except Exception as e: - failed.append(e) +# for name, value in forgone_attrs: +# assert name not in flat_event, "name=%r, value=%r, event=%r" % (name, value, flat_event) +# except Exception as e: +# failed.append(e) - return result +# return result - @function_wrapper - def wrapper(wrapped, instance, args, kwargs): - _new_wrapper = _validate_synthetics_event(wrapped) - result = _new_wrapper(*args, **kwargs) - if failed: - e = failed.pop() - raise e - return result +# @function_wrapper +# def wrapper(wrapped, instance, args, kwargs): +# _new_wrapper = _validate_synthetics_event(wrapped) +# result = _new_wrapper(*args, **kwargs) +# if failed: +# e = failed.pop() +# raise e +# return result - return wrapper +# return wrapper def validate_transaction_event_attributes(required_params=None, forgone_params=None, exact_attrs=None, index=-1): diff --git a/tests/testing_support/validators/validate_synthetics_event.py b/tests/testing_support/validators/validate_synthetics_event.py new file mode 100644 index 0000000000..221cf7e6ef --- /dev/null +++ b/tests/testing_support/validators/validate_synthetics_event.py @@ -0,0 +1,71 @@ +# Copyright 2010 New Relic, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +from newrelic.common.object_wrapper import ( + function_wrapper, + transient_function_wrapper, +) + +def validate_synthetics_event(required_attrs=None, forgone_attrs=None, should_exist=True): + required_attrs = required_attrs or [] + forgone_attrs = forgone_attrs or [] + failed = [] + + @transient_function_wrapper("newrelic.core.stats_engine", "StatsEngine.record_transaction") + def _validate_synthetics_event(wrapped, instance, args, kwargs): + result = wrapped(*args, **kwargs) + + try: + if not should_exist: + assert instance.synthetics_events == [] + else: + assert len(instance.synthetics_events) == 1 + event = instance.synthetics_events[0] + assert event is not None + assert len(event) == 3 + + def _flatten(event): + result = {} + for elem in event: + for k, v in elem.items(): + result[k] = v + return result + + flat_event = _flatten(event) + + assert "nr.guid" in flat_event, "name=%r, event=%r" % ("nr.guid", flat_event) + + for name, value in required_attrs: + assert name in flat_event, "name=%r, event=%r" % (name, flat_event) + assert flat_event[name] == value, "name=%r, value=%r, event=%r" % (name, value, flat_event) + + for name, value in forgone_attrs: + assert name not in flat_event, "name=%r, value=%r, event=%r" % (name, value, flat_event) + except Exception as e: + failed.append(e) + + return result + + @function_wrapper + def wrapper(wrapped, instance, args, kwargs): + _new_wrapper = _validate_synthetics_event(wrapped) + result = _new_wrapper(*args, **kwargs) + if failed: + e = failed.pop() + raise e + return result + + return wrapper + From f47c397013e069a214b70adecc3c4a545aed0753 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 31 Aug 2022 16:37:35 -0700 Subject: [PATCH 09/14] Move validate_transaction_event_attributes into validators directory --- .../test_asgi_w3c_trace_context.py | 5 +- .../test_distributed_tracing.py | 3 +- .../agent_features/test_w3c_trace_context.py | 4 +- tests/cross_agent/test_distributed_tracing.py | 2 +- tests/cross_agent/test_lambda_event_source.py | 4 +- tests/cross_agent/test_w3c_trace_context.py | 2 +- tests/framework_aiohttp/test_server.py | 2 +- tests/framework_grpc/test_server.py | 3 +- tests/framework_tornado/test_inbound_cat.py | 3 +- tests/testing_support/fixtures.py | 50 ++++++++--------- .../validate_transaction_event_attributes.py | 53 +++++++++++++++++++ 11 files changed, 93 insertions(+), 38 deletions(-) create mode 100644 tests/testing_support/validators/validate_transaction_event_attributes.py diff --git a/tests/agent_features/test_asgi_w3c_trace_context.py b/tests/agent_features/test_asgi_w3c_trace_context.py index 234e084092..8cec2eb7a1 100644 --- a/tests/agent_features/test_asgi_w3c_trace_context.py +++ b/tests/agent_features/test_asgi_w3c_trace_context.py @@ -19,12 +19,11 @@ from newrelic.api.asgi_application import asgi_application from testing_support.asgi_testing import AsgiTest -from testing_support.fixtures import (override_application_settings, - validate_transaction_event_attributes) +from testing_support.fixtures import override_application_settings from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_span_events import ( validate_span_events) - +from testing_support.validators.validate_transaction_event_attributes import validate_transaction_event_attributes @asgi_application() async def target_asgi_application(scope, receive, send): diff --git a/tests/agent_features/test_distributed_tracing.py b/tests/agent_features/test_distributed_tracing.py index aed7de100a..7f795573a6 100644 --- a/tests/agent_features/test_distributed_tracing.py +++ b/tests/agent_features/test_distributed_tracing.py @@ -26,9 +26,10 @@ from newrelic.api.wsgi_application import wsgi_application from testing_support.fixtures import (override_application_settings, - validate_attributes, validate_transaction_event_attributes, + validate_attributes, validate_error_event_attributes) from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics +from testing_support.validators.validate_transaction_event_attributes import validate_transaction_event_attributes distributed_trace_intrinsics = ['guid', 'traceId', 'priority', 'sampled'] inbound_payload_intrinsics = ['parent.type', 'parent.app', 'parent.account', diff --git a/tests/agent_features/test_w3c_trace_context.py b/tests/agent_features/test_w3c_trace_context.py index 7143e0f46e..726cf011aa 100644 --- a/tests/agent_features/test_w3c_trace_context.py +++ b/tests/agent_features/test_w3c_trace_context.py @@ -19,11 +19,11 @@ from newrelic.api.transaction import current_transaction from newrelic.api.external_trace import ExternalTrace from newrelic.api.wsgi_application import wsgi_application -from testing_support.fixtures import (override_application_settings, - validate_transaction_event_attributes) +from testing_support.fixtures import override_application_settings from testing_support.validators.validate_span_events import ( validate_span_events) from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics +from testing_support.validators.validate_transaction_event_attributes import validate_transaction_event_attributes @wsgi_application() def target_wsgi_application(environ, start_response): diff --git a/tests/cross_agent/test_distributed_tracing.py b/tests/cross_agent/test_distributed_tracing.py index 7b0be1ca20..0ff46eea24 100644 --- a/tests/cross_agent/test_distributed_tracing.py +++ b/tests/cross_agent/test_distributed_tracing.py @@ -23,11 +23,11 @@ from newrelic.common.object_wrapper import transient_function_wrapper from testing_support.fixtures import (override_application_settings, - validate_transaction_event_attributes, validate_error_event_attributes, validate_attributes) from testing_support.validators.validate_span_events import ( validate_span_events) from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics +from testing_support.validators.validate_transaction_event_attributes import validate_transaction_event_attributes CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) JSON_DIR = os.path.normpath(os.path.join(CURRENT_DIR, 'fixtures', diff --git a/tests/cross_agent/test_lambda_event_source.py b/tests/cross_agent/test_lambda_event_source.py index 3a90aec58b..511294cf6f 100644 --- a/tests/cross_agent/test_lambda_event_source.py +++ b/tests/cross_agent/test_lambda_event_source.py @@ -17,8 +17,8 @@ import pytest from newrelic.api.lambda_handler import lambda_handler -from testing_support.fixtures import (override_application_settings, - validate_transaction_event_attributes) +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_transaction_event_attributes import validate_transaction_event_attributes CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) FIXTURE_DIR = os.path.normpath(os.path.join(CURRENT_DIR, 'fixtures')) diff --git a/tests/cross_agent/test_w3c_trace_context.py b/tests/cross_agent/test_w3c_trace_context.py index efc13c25dd..05f157f7b7 100644 --- a/tests/cross_agent/test_w3c_trace_context.py +++ b/tests/cross_agent/test_w3c_trace_context.py @@ -24,10 +24,10 @@ from testing_support.validators.validate_span_events import ( validate_span_events) from testing_support.fixtures import (override_application_settings, - validate_transaction_event_attributes, validate_attributes) from newrelic.common.encoding_utils import W3CTraceState from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics +from testing_support.validators.validate_transaction_event_attributes import validate_transaction_event_attributes CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) JSON_DIR = os.path.normpath(os.path.join(CURRENT_DIR, 'fixtures', diff --git a/tests/framework_aiohttp/test_server.py b/tests/framework_aiohttp/test_server.py index 4f0347df1a..ac7cd7d31f 100644 --- a/tests/framework_aiohttp/test_server.py +++ b/tests/framework_aiohttp/test_server.py @@ -18,12 +18,12 @@ from newrelic.core.config import global_settings from testing_support.fixtures import ( - validate_transaction_event_attributes, count_transactions, override_generic_settings, override_application_settings, override_ignore_status_codes) from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_transaction_errors import validate_transaction_errors +from testing_support.validators.validate_transaction_event_attributes import validate_transaction_event_attributes version_info = tuple(int(_) for _ in aiohttp.__version__.split('.')[:2]) diff --git a/tests/framework_grpc/test_server.py b/tests/framework_grpc/test_server.py index 92ec9c4b3c..534d780050 100644 --- a/tests/framework_grpc/test_server.py +++ b/tests/framework_grpc/test_server.py @@ -19,11 +19,12 @@ from _test_common import create_request, wait_for_transaction_completion from newrelic.core.config import global_settings from testing_support.fixtures import ( - validate_transaction_event_attributes, override_application_settings, + override_application_settings, override_generic_settings, function_not_called) from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from testing_support.validators.validate_transaction_errors import validate_transaction_errors +from testing_support.validators.validate_transaction_event_attributes import validate_transaction_event_attributes def select_python_version(py2, py3): return six.PY3 and py3 or py2 diff --git a/tests/framework_tornado/test_inbound_cat.py b/tests/framework_tornado/test_inbound_cat.py index c399f70d5c..44fbf29337 100644 --- a/tests/framework_tornado/test_inbound_cat.py +++ b/tests/framework_tornado/test_inbound_cat.py @@ -15,8 +15,9 @@ import json import pytest from testing_support.fixtures import (make_cross_agent_headers, - override_application_settings, validate_transaction_event_attributes) + override_application_settings) from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics +from testing_support.validators.validate_transaction_event_attributes import validate_transaction_event_attributes ENCODING_KEY = '1234567890123456789012345678901234567890' diff --git a/tests/testing_support/fixtures.py b/tests/testing_support/fixtures.py index ed83244e3d..b6cbcf1026 100644 --- a/tests/testing_support/fixtures.py +++ b/tests/testing_support/fixtures.py @@ -818,38 +818,38 @@ def _capture_transaction_metrics(wrapped, instance, args, kwargs): # return wrapper -def validate_transaction_event_attributes(required_params=None, forgone_params=None, exact_attrs=None, index=-1): - required_params = required_params or {} - forgone_params = forgone_params or {} - exact_attrs = exact_attrs or {} +# def validate_transaction_event_attributes(required_params=None, forgone_params=None, exact_attrs=None, index=-1): +# required_params = required_params or {} +# forgone_params = forgone_params or {} +# exact_attrs = exact_attrs or {} - captured_events = [] +# captured_events = [] - @transient_function_wrapper("newrelic.core.stats_engine", "StatsEngine.record_transaction") - def _capture_transaction_events(wrapped, instance, args, kwargs): - try: - result = wrapped(*args, **kwargs) - except: - raise - else: - event_data = instance.transaction_events - captured_events.append(event_data) - return result +# @transient_function_wrapper("newrelic.core.stats_engine", "StatsEngine.record_transaction") +# def _capture_transaction_events(wrapped, instance, args, kwargs): +# try: +# result = wrapped(*args, **kwargs) +# except: +# raise +# else: +# event_data = instance.transaction_events +# captured_events.append(event_data) +# return result - @function_wrapper - def _validate_transaction_event_attributes(wrapped, instance, args, kwargs): - _new_wrapper = _capture_transaction_events(wrapped) - result = _new_wrapper(*args, **kwargs) +# @function_wrapper +# def _validate_transaction_event_attributes(wrapped, instance, args, kwargs): +# _new_wrapper = _capture_transaction_events(wrapped) +# result = _new_wrapper(*args, **kwargs) - assert captured_events, "No events captured" - event_data = captured_events[index] - captured_events[:] = [] +# assert captured_events, "No events captured" +# event_data = captured_events[index] +# captured_events[:] = [] - check_event_attributes(event_data, required_params, forgone_params, exact_attrs) +# check_event_attributes(event_data, required_params, forgone_params, exact_attrs) - return result +# return result - return _validate_transaction_event_attributes +# return _validate_transaction_event_attributes def check_event_attributes(event_data, required_params=None, forgone_params=None, exact_attrs=None): diff --git a/tests/testing_support/validators/validate_transaction_event_attributes.py b/tests/testing_support/validators/validate_transaction_event_attributes.py new file mode 100644 index 0000000000..7ef8c06291 --- /dev/null +++ b/tests/testing_support/validators/validate_transaction_event_attributes.py @@ -0,0 +1,53 @@ +# Copyright 2010 New Relic, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +from newrelic.common.object_wrapper import ( + function_wrapper, + transient_function_wrapper, +) +from testing_support.fixtures import check_event_attributes + +def validate_transaction_event_attributes(required_params=None, forgone_params=None, exact_attrs=None, index=-1): + required_params = required_params or {} + forgone_params = forgone_params or {} + exact_attrs = exact_attrs or {} + + captured_events = [] + + @transient_function_wrapper("newrelic.core.stats_engine", "StatsEngine.record_transaction") + def _capture_transaction_events(wrapped, instance, args, kwargs): + try: + result = wrapped(*args, **kwargs) + except: + raise + else: + event_data = instance.transaction_events + captured_events.append(event_data) + return result + + @function_wrapper + def _validate_transaction_event_attributes(wrapped, instance, args, kwargs): + _new_wrapper = _capture_transaction_events(wrapped) + result = _new_wrapper(*args, **kwargs) + + assert captured_events, "No events captured" + event_data = captured_events[index] + captured_events[:] = [] + + check_event_attributes(event_data, required_params, forgone_params, exact_attrs) + + return result + + return _validate_transaction_event_attributes \ No newline at end of file From f3423dbfba001ee40bae06376a4b4778d79755e1 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Tue, 6 Sep 2022 12:58:48 -0700 Subject: [PATCH 10/14] Move validate_non_transaction_error_event into validators directory --- tests/agent_features/test_error_events.py | 4 +- .../agent_features/test_high_security_mode.py | 13 ++- tests/testing_support/fixtures.py | 108 +++++++++--------- .../validate_non_transaction_error_event.py | 71 ++++++++++++ 4 files changed, 139 insertions(+), 57 deletions(-) create mode 100644 tests/testing_support/validators/validate_non_transaction_error_event.py diff --git a/tests/agent_features/test_error_events.py b/tests/agent_features/test_error_events.py index d93f9908b9..99b3935bef 100644 --- a/tests/agent_features/test_error_events.py +++ b/tests/agent_features/test_error_events.py @@ -23,10 +23,12 @@ override_application_settings, reset_core_stats_engine, validate_error_event_sample_data, - validate_non_transaction_error_event, validate_transaction_error_event_count, ) from testing_support.sample_applications import fully_featured_app +from testing_support.validators.validate_non_transaction_error_event import ( + validate_non_transaction_error_event, +) from newrelic.api.application import application_instance as application from newrelic.api.application import application_settings diff --git a/tests/agent_features/test_high_security_mode.py b/tests/agent_features/test_high_security_mode.py index 3f6dbdef02..6c093d1511 100644 --- a/tests/agent_features/test_high_security_mode.py +++ b/tests/agent_features/test_high_security_mode.py @@ -24,12 +24,19 @@ validate_attributes_complete, validate_custom_event_count, validate_custom_event_in_application_stats_engine, - validate_non_transaction_error_event, validate_request_params_omitted, validate_tt_segment_params, ) -from testing_support.validators.validate_custom_parameters import validate_custom_parameters -from testing_support.validators.validate_transaction_errors import validate_transaction_errors +from testing_support.validators.validate_custom_parameters import ( + validate_custom_parameters, +) +from testing_support.validators.validate_non_transaction_error_event import ( + validate_non_transaction_error_event, +) +from testing_support.validators.validate_transaction_errors import ( + validate_transaction_errors, +) + from newrelic.api.application import application_instance as application from newrelic.api.background_task import background_task from newrelic.api.function_trace import FunctionTrace diff --git a/tests/testing_support/fixtures.py b/tests/testing_support/fixtures.py index b6cbcf1026..bd90d2c50b 100644 --- a/tests/testing_support/fixtures.py +++ b/tests/testing_support/fixtures.py @@ -65,8 +65,9 @@ ) from newrelic.core.config import apply_config_setting, flatten_settings, global_settings from newrelic.core.database_utils import SQLConnections -#from newrelic.core.internal_metrics import InternalTraceContext -#from newrelic.core.stats_engine import CustomMetrics + +# from newrelic.core.internal_metrics import InternalTraceContext +# from newrelic.core.stats_engine import CustomMetrics from newrelic.network.exceptions import RetryDataForRequest from newrelic.packages import six @@ -889,56 +890,56 @@ def check_event_attributes(event_data, required_params=None, forgone_params=None assert intrinsics[param] == value, ((param, value), intrinsics) -def validate_non_transaction_error_event(required_intrinsics=None, num_errors=1, required_user=None, forgone_user=None): - """Validate error event data for a single error occurring outside of a - transaction. - """ - required_intrinsics = required_intrinsics or {} - required_user = required_user or {} - forgone_user = forgone_user or [] +# def validate_non_transaction_error_event(required_intrinsics=None, num_errors=1, required_user=None, forgone_user=None): +# """Validate error event data for a single error occurring outside of a +# transaction. +# """ +# required_intrinsics = required_intrinsics or {} +# required_user = required_user or {} +# forgone_user = forgone_user or [] - @function_wrapper - def _validate_non_transaction_error_event(wrapped, instace, args, kwargs): +# @function_wrapper +# def _validate_non_transaction_error_event(wrapped, instace, args, kwargs): - try: - result = wrapped(*args, **kwargs) - except: - raise - else: +# try: +# result = wrapped(*args, **kwargs) +# except: +# raise +# else: - stats = core_application_stats_engine(None) +# stats = core_application_stats_engine(None) - assert stats.error_events.num_seen == num_errors - for event in stats.error_events: +# assert stats.error_events.num_seen == num_errors +# for event in stats.error_events: - assert len(event) == 3 # [intrinsic, user, agent attributes] +# assert len(event) == 3 # [intrinsic, user, agent attributes] - intrinsics = event[0] +# intrinsics = event[0] - # The following attributes are all required, and also the only - # intrinsic attributes that can be included in an error event - # recorded outside of a transaction +# # The following attributes are all required, and also the only +# # intrinsic attributes that can be included in an error event +# # recorded outside of a transaction - assert intrinsics["type"] == "TransactionError" - assert intrinsics["transactionName"] is None - assert intrinsics["error.class"] == required_intrinsics["error.class"] - assert intrinsics["error.message"].startswith(required_intrinsics["error.message"]) - assert intrinsics["error.expected"] == required_intrinsics["error.expected"] - now = time.time() - assert isinstance(intrinsics["timestamp"], int) - assert intrinsics["timestamp"] <= 1000.0 * now - - user_params = event[1] - for name, value in required_user.items(): - assert name in user_params, "name=%r, params=%r" % (name, user_params) - assert user_params[name] == value, "name=%r, value=%r, params=%r" % (name, value, user_params) - - for param in forgone_user: - assert param not in user_params +# assert intrinsics["type"] == "TransactionError" +# assert intrinsics["transactionName"] is None +# assert intrinsics["error.class"] == required_intrinsics["error.class"] +# assert intrinsics["error.message"].startswith(required_intrinsics["error.message"]) +# assert intrinsics["error.expected"] == required_intrinsics["error.expected"] +# now = time.time() +# assert isinstance(intrinsics["timestamp"], int) +# assert intrinsics["timestamp"] <= 1000.0 * now - return result +# user_params = event[1] +# for name, value in required_user.items(): +# assert name in user_params, "name=%r, params=%r" % (name, user_params) +# assert user_params[name] == value, "name=%r, value=%r, params=%r" % (name, value, user_params) + +# for param in forgone_user: +# assert param not in user_params - return _validate_non_transaction_error_event +# return result + +# return _validate_non_transaction_error_event def validate_application_error_trace_count(num_errors): @@ -2434,25 +2435,25 @@ def _override_ignore_status_codes(wrapped, instance, args, kwargs): return _override_ignore_status_codes -def code_coverage_fixture(source=['newrelic']): - @pytest.fixture(scope='session') +def code_coverage_fixture(source=["newrelic"]): + @pytest.fixture(scope="session") def _code_coverage_fixture(request): if not source: return - if os.environ.get('GITHUB_ACTIONS') is not None: + if os.environ.get("GITHUB_ACTIONS") is not None: return from coverage import coverage - env_directory = os.environ.get('TOX_ENVDIR', None) + env_directory = os.environ.get("TOX_ENVDIR", None) if env_directory is not None: - coverage_directory = os.path.join(env_directory, 'htmlcov') - xml_report = os.path.join(env_directory, 'coverage.xml') + coverage_directory = os.path.join(env_directory, "htmlcov") + xml_report = os.path.join(env_directory, "coverage.xml") else: - coverage_directory = 'htmlcov' - xml_report = 'coverage.xml' + coverage_directory = "htmlcov" + xml_report = "coverage.xml" def finalize(): cov.stop() @@ -2469,18 +2470,19 @@ def finalize(): def reset_core_stats_engine(): """Reset the StatsEngine and custom StatsEngine of the core application.""" + @function_wrapper def _reset_core_stats_engine(wrapped, instance, args, kwargs): api_application = application_instance() api_name = api_application.name core_application = api_application._agent.application(api_name) - + stats = core_application._stats_engine stats.reset_stats(stats.settings) - + custom_stats = core_application._stats_custom_engine custom_stats.reset_stats(custom_stats.settings) - + return wrapped(*args, **kwargs) return _reset_core_stats_engine diff --git a/tests/testing_support/validators/validate_non_transaction_error_event.py b/tests/testing_support/validators/validate_non_transaction_error_event.py new file mode 100644 index 0000000000..dc97d7a421 --- /dev/null +++ b/tests/testing_support/validators/validate_non_transaction_error_event.py @@ -0,0 +1,71 @@ +# Copyright 2010 New Relic, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from time import time + +from testing_support.fixtures import core_application_stats_engine + +from newrelic.common.object_wrapper import function_wrapper + + +def validate_non_transaction_error_event(required_intrinsics=None, num_errors=1, required_user=None, forgone_user=None): + """Validate error event data for a single error occurring outside of a + transaction. + """ + required_intrinsics = required_intrinsics or {} + required_user = required_user or {} + forgone_user = forgone_user or [] + + @function_wrapper + def _validate_non_transaction_error_event(wrapped, instace, args, kwargs): + + try: + result = wrapped(*args, **kwargs) + except: + raise + else: + + stats = core_application_stats_engine(None) + + assert stats.error_events.num_seen == num_errors + for event in stats.error_events: + + assert len(event) == 3 # [intrinsic, user, agent attributes] + + intrinsics = event[0] + + # The following attributes are all required, and also the only + # intrinsic attributes that can be included in an error event + # recorded outside of a transaction + + assert intrinsics["type"] == "TransactionError" + assert intrinsics["transactionName"] is None + assert intrinsics["error.class"] == required_intrinsics["error.class"] + assert intrinsics["error.message"].startswith(required_intrinsics["error.message"]) + assert intrinsics["error.expected"] == required_intrinsics["error.expected"] + now = time.time() + assert isinstance(intrinsics["timestamp"], int) + assert intrinsics["timestamp"] <= 1000.0 * now + + user_params = event[1] + for name, value in required_user.items(): + assert name in user_params, "name=%r, params=%r" % (name, user_params) + assert user_params[name] == value, "name=%r, value=%r, params=%r" % (name, value, user_params) + + for param in forgone_user: + assert param not in user_params + + return result + + return _validate_non_transaction_error_event From e58d521e632360724ca34b52ca82b7131feac3cc Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Tue, 25 Oct 2022 15:20:39 -0700 Subject: [PATCH 11/14] Fix import issues --- tests/adapter_hypercorn/test_hypercorn.py | 14 +- .../test_attributes_in_action.py | 4 +- .../test_event_loop_wait_time.py | 8 +- tests/agent_features/test_lambda_handler.py | 279 +++++++++--------- ...n_event_data_and_some_browser_stuff_too.py | 272 ++++++++--------- tests/agent_features/test_wsgi_attributes.py | 8 +- tests/datastore_aioredis/test_transactions.py | 12 +- tests/framework_aiohttp/test_server_cat.py | 173 ++++++----- .../framework_sanic/test_cross_application.py | 148 +++++----- tests/framework_tornado/test_server.py | 219 +++++++------- .../test_consumer.py | 8 +- .../test_producer.py | 10 +- .../test_serialization.py | 4 +- .../test_consumer.py | 8 +- .../test_producer.py | 10 +- .../test_serialization.py | 4 + 16 files changed, 631 insertions(+), 550 deletions(-) diff --git a/tests/adapter_hypercorn/test_hypercorn.py b/tests/adapter_hypercorn/test_hypercorn.py index 05bf9fdc59..f9405b3526 100644 --- a/tests/adapter_hypercorn/test_hypercorn.py +++ b/tests/adapter_hypercorn/test_hypercorn.py @@ -22,8 +22,6 @@ from testing_support.fixtures import ( override_application_settings, raise_background_exceptions, - validate_transaction_errors, - validate_transaction_metrics, wait_for_background_threads, ) from testing_support.sample_asgi_applications import ( @@ -32,6 +30,12 @@ simple_app_v2_raw, ) from testing_support.util import get_open_port +from testing_support.validators.validate_transaction_errors import ( + validate_transaction_errors, +) +from testing_support.validators.validate_transaction_metrics import ( + validate_transaction_metrics, +) from newrelic.api.transaction import ignore_transaction from newrelic.common.object_names import callable_name @@ -115,7 +119,7 @@ def wait_for_port(port, retries=10): status = None for _ in range(retries): try: - status = urlopen("http://localhost:%d/ignored" % port, timeout=1).status + status = urlopen("http://localhost:%d/ignored" % port, timeout=1).status # nosec assert status == 200 return except Exception as e: @@ -132,7 +136,7 @@ def test_hypercorn_200(port, app): @raise_background_exceptions() @wait_for_background_threads() def response(): - return urlopen("http://localhost:%d" % port, timeout=10) + return urlopen("http://localhost:%d" % port, timeout=10) # nosec assert response().status == 200 @@ -145,6 +149,6 @@ def test_hypercorn_500(port, app): @wait_for_background_threads() def _test(): with pytest.raises(HTTPError): - urlopen("http://localhost:%d/exc" % port) + urlopen("http://localhost:%d/exc" % port) # nosec _test() diff --git a/tests/agent_features/test_attributes_in_action.py b/tests/agent_features/test_attributes_in_action.py index 31c5d625df..ae417a53ea 100644 --- a/tests/agent_features/test_attributes_in_action.py +++ b/tests/agent_features/test_attributes_in_action.py @@ -25,10 +25,12 @@ validate_error_event_attributes_outside_transaction, validate_error_trace_attributes_outside_transaction, validate_transaction_error_trace_attributes, - validate_transaction_event_attributes, validate_transaction_trace_attributes, ) from testing_support.validators.validate_span_events import validate_span_events +from testing_support.validators.validate_transaction_event_attributes import ( + validate_transaction_event_attributes, +) from newrelic.api.application import application_instance as application from newrelic.api.message_transaction import message_transaction diff --git a/tests/agent_features/test_event_loop_wait_time.py b/tests/agent_features/test_event_loop_wait_time.py index f93e78c233..2404efd315 100644 --- a/tests/agent_features/test_event_loop_wait_time.py +++ b/tests/agent_features/test_event_loop_wait_time.py @@ -18,11 +18,15 @@ import pytest from testing_support.fixtures import ( override_application_settings, - validate_transaction_event_attributes, validate_transaction_trace_attributes, ) +from testing_support.validators.validate_transaction_event_attributes import ( + validate_transaction_event_attributes, +) +from testing_support.validators.validate_transaction_metrics import ( + validate_transaction_metrics, +) -from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task from newrelic.api.function_trace import FunctionTrace, function_trace from newrelic.api.transaction import current_transaction diff --git a/tests/agent_features/test_lambda_handler.py b/tests/agent_features/test_lambda_handler.py index 4ff932e366..f388aa51b4 100644 --- a/tests/agent_features/test_lambda_handler.py +++ b/tests/agent_features/test_lambda_handler.py @@ -13,11 +13,17 @@ # limitations under the License. import functools -import pytest from copy import deepcopy -from testing_support.fixtures import (override_application_settings, - validate_transaction_trace_attributes, - validate_transaction_event_attributes) + +import pytest +from testing_support.fixtures import ( + override_application_settings, + validate_transaction_trace_attributes, +) +from testing_support.validators.validate_transaction_event_attributes import ( + validate_transaction_event_attributes, +) + import newrelic.api.lambda_handler as lambda_handler @@ -27,7 +33,7 @@ @pytest.fixture(autouse=True) def force_cold_start_status(request): try: - is_cold_start = request.getfixturevalue('is_cold') + is_cold_start = request.getfixturevalue("is_cold") lambda_handler.COLD_START_RECORDED = not is_cold_start except Exception: lambda_handler.COLD_START_RECORDED = True @@ -36,63 +42,65 @@ def force_cold_start_status(request): @lambda_handler.lambda_handler() def handler(event, context): return { - 'statusCode': '200', - 'body': '{}', - 'headers': { - 'Content-Type': 'application/json', - 'Content-Length': 2, + "statusCode": "200", + "body": "{}", + "headers": { + "Content-Type": "application/json", + "Content-Length": 2, }, } _override_settings = { - 'attributes.include': ['request.parameters.*', 'request.headers.*'], + "attributes.include": ["request.parameters.*", "request.headers.*"], } _expected_attributes = { - 'agent': [ - 'aws.requestId', - 'aws.lambda.arn', - 'request.method', - 'request.uri', - 'response.status', - 'response.headers.contentType', - 'response.headers.contentLength', + "agent": [ + "aws.requestId", + "aws.lambda.arn", + "request.method", + "request.uri", + "response.status", + "response.headers.contentType", + "response.headers.contentLength", ], - 'user': [], - 'intrinsic': [], + "user": [], + "intrinsic": [], } _exact_attrs = { - 'agent': { - 'request.parameters.foo': 'bar', - 'request.headers.host': 'myhost', + "agent": { + "request.parameters.foo": "bar", + "request.headers.host": "myhost", }, - 'user': {}, - 'intrinsic': {} + "user": {}, + "intrinsic": {}, } empty_event = {} firehose_event = { - "records": [{ - "recordId": "495469866831355442", - "data": "SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IDEyMy4=", - "approximateArrivalTimestamp": 1495072949453 - }], + "records": [ + { + "recordId": "495469866831355442", + "data": "SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IDEyMy4=", + "approximateArrivalTimestamp": 1495072949453, + } + ], "region": "us-west-2", "deliveryStreamArn": "arn:aws:kinesis:EXAMPLE", - "invocationId": "invocationIdExample" + "invocationId": "invocationIdExample", } class Context(object): - aws_request_id = 'cookies' - invoked_function_arn = 'arn' - function_name = 'cats' - function_version = '$LATEST' + aws_request_id = "cookies" + invoked_function_arn = "arn" + function_name = "cats" + function_version = "$LATEST" memory_limit_in_mb = 128 -@pytest.mark.parametrize('is_cold', (False, True)) +@pytest.mark.parametrize("is_cold", (False, True)) def test_lambda_transaction_attributes(is_cold, monkeypatch): # setup copies of the attribute lists for this test only _forgone_params = {} @@ -101,36 +109,32 @@ def test_lambda_transaction_attributes(is_cold, monkeypatch): # if we have a cold start, then we should see aws.lambda.coldStart=True if is_cold: - _exact['agent']['aws.lambda.coldStart'] = True - _expected['agent'].append('aws.lambda.coldStart') + _exact["agent"]["aws.lambda.coldStart"] = True + _expected["agent"].append("aws.lambda.coldStart") # otherwise, then we need to make sure that we don't see it at all else: - _forgone_params = { - 'agent': ['aws.lambda.coldStart'], - 'user': [], - 'intrinsic': [] - } + _forgone_params = {"agent": ["aws.lambda.coldStart"], "user": [], "intrinsic": []} - @validate_transaction_trace_attributes( - required_params=_expected, - forgone_params=_forgone_params) + @validate_transaction_trace_attributes(required_params=_expected, forgone_params=_forgone_params) @validate_transaction_event_attributes( - required_params=_expected, - forgone_params=_forgone_params, - exact_attrs=_exact) + required_params=_expected, forgone_params=_forgone_params, exact_attrs=_exact + ) @override_application_settings(_override_settings) def _test(): - monkeypatch.setenv('AWS_REGION', 'earth') - handler({ - 'httpMethod': 'GET', - 'path': '/', - 'headers': { - 'HOST': 'myhost', + monkeypatch.setenv("AWS_REGION", "earth") + handler( + { + "httpMethod": "GET", + "path": "/", + "headers": { + "HOST": "myhost", + }, + "queryStringParameters": {"foo": "bar"}, + "multiValueQueryStringParameters": {"foo": ["bar"]}, }, - 'queryStringParameters': {'foo': 'bar'}, - 'multiValueQueryStringParameters': {'foo': ['bar']}, - }, Context) + Context, + ) _test() @@ -139,23 +143,26 @@ def _test(): @validate_transaction_event_attributes(_expected_attributes) @override_application_settings(_override_settings) def test_lambda_malformed_api_gateway_payload(monkeypatch): - monkeypatch.setenv('AWS_REGION', 'earth') - handler({ - 'httpMethod': 'GET', - 'path': '/', - 'headers': {}, - 'queryStringParameters': 42, - 'multiValueQueryStringParameters': 42, - }, Context) + monkeypatch.setenv("AWS_REGION", "earth") + handler( + { + "httpMethod": "GET", + "path": "/", + "headers": {}, + "queryStringParameters": 42, + "multiValueQueryStringParameters": 42, + }, + Context, + ) _malformed_request_attributes = { - 'agent': [ - 'aws.requestId', - 'aws.lambda.arn', + "agent": [ + "aws.requestId", + "aws.lambda.arn", ], - 'user': [], - 'intrinsic': [], + "user": [], + "intrinsic": [], } @@ -163,23 +170,26 @@ def test_lambda_malformed_api_gateway_payload(monkeypatch): @validate_transaction_event_attributes(_malformed_request_attributes) @override_application_settings(_override_settings) def test_lambda_malformed_request_headers(): - handler({ - 'httpMethod': 'GET', - 'path': '/', - 'headers': None, - }, Context) + handler( + { + "httpMethod": "GET", + "path": "/", + "headers": None, + }, + Context, + ) _malformed_response_attributes = { - 'agent': [ - 'aws.requestId', - 'aws.lambda.arn', - 'request.method', - 'request.uri', - 'response.status', + "agent": [ + "aws.requestId", + "aws.lambda.arn", + "request.method", + "request.uri", + "response.status", ], - 'user': [], - 'intrinsic': [], + "user": [], + "intrinsic": [], } @@ -187,33 +197,35 @@ def test_lambda_malformed_request_headers(): @validate_transaction_event_attributes(_malformed_response_attributes) @override_application_settings(_override_settings) def test_lambda_malformed_response_headers(): - @lambda_handler.lambda_handler() def handler(event, context): return { - 'statusCode': 200, - 'body': '{}', - 'headers': None, + "statusCode": 200, + "body": "{}", + "headers": None, } - handler({ - 'httpMethod': 'GET', - 'path': '/', - 'headers': {}, - }, Context) + handler( + { + "httpMethod": "GET", + "path": "/", + "headers": {}, + }, + Context, + ) _no_status_code_response = { - 'agent': [ - 'aws.requestId', - 'aws.lambda.arn', - 'request.method', - 'request.uri', - 'response.headers.contentType', - 'response.headers.contentLength', + "agent": [ + "aws.requestId", + "aws.lambda.arn", + "request.method", + "request.uri", + "response.headers.contentType", + "response.headers.contentLength", ], - 'user': [], - 'intrinsic': [], + "user": [], + "intrinsic": [], } @@ -221,53 +233,51 @@ def handler(event, context): @validate_transaction_event_attributes(_no_status_code_response) @override_application_settings(_override_settings) def test_lambda_no_status_code_response(): - @lambda_handler.lambda_handler() def handler(event, context): return { - 'body': '{}', - 'headers': { - 'Content-Type': 'application/json', - 'Content-Length': 2, + "body": "{}", + "headers": { + "Content-Type": "application/json", + "Content-Length": 2, }, } - handler({ - 'httpMethod': 'GET', - 'path': '/', - 'headers': {}, - }, Context) + handler( + { + "httpMethod": "GET", + "path": "/", + "headers": {}, + }, + Context, + ) -@pytest.mark.parametrize('event,arn', ( - (empty_event, None), - (firehose_event, 'arn:aws:kinesis:EXAMPLE'))) +@pytest.mark.parametrize("event,arn", ((empty_event, None), (firehose_event, "arn:aws:kinesis:EXAMPLE"))) def test_lambda_event_source_arn_attribute(event, arn): if arn is None: _exact = None _expected = None _forgone = { - 'user': [], 'intrinsic': [], - 'agent': ['aws.lambda.eventSource.arn'], + "user": [], + "intrinsic": [], + "agent": ["aws.lambda.eventSource.arn"], } else: _exact = { - 'user': {}, 'intrinsic': {}, - 'agent': {'aws.lambda.eventSource.arn': arn}, + "user": {}, + "intrinsic": {}, + "agent": {"aws.lambda.eventSource.arn": arn}, } _expected = { - 'user': [], 'intrinsic': [], - 'agent': ['aws.lambda.eventSource.arn'], + "user": [], + "intrinsic": [], + "agent": ["aws.lambda.eventSource.arn"], } _forgone = None - @validate_transaction_trace_attributes( - required_params=_expected, - forgone_params=_forgone) - @validate_transaction_event_attributes( - required_params=_expected, - forgone_params=_forgone, - exact_attrs=_exact) + @validate_transaction_trace_attributes(required_params=_expected, forgone_params=_forgone) + @validate_transaction_event_attributes(required_params=_expected, forgone_params=_forgone, exact_attrs=_exact) @override_application_settings(_override_settings) def _test(): handler(event, Context) @@ -275,10 +285,13 @@ def _test(): _test() -@pytest.mark.parametrize('api', ( - lambda_handler.lambda_handler, - functools.partial(lambda_handler.LambdaHandlerWrapper, handler), -)) +@pytest.mark.parametrize( + "api", + ( + lambda_handler.lambda_handler, + functools.partial(lambda_handler.LambdaHandlerWrapper, handler), + ), +) def test_deprecation_warnings(api): with pytest.deprecated_call(): api() diff --git a/tests/agent_features/test_transaction_event_data_and_some_browser_stuff_too.py b/tests/agent_features/test_transaction_event_data_and_some_browser_stuff_too.py index a99fc1cdd1..c2e22b68aa 100644 --- a/tests/agent_features/test_transaction_event_data_and_some_browser_stuff_too.py +++ b/tests/agent_features/test_transaction_event_data_and_some_browser_stuff_too.py @@ -13,36 +13,39 @@ # limitations under the License. import json + import webtest +from testing_support.fixtures import ( + override_application_settings, + validate_transaction_event_sample_data, +) +from testing_support.sample_applications import ( + fully_featured_app, + user_attributes_added, +) +from testing_support.validators.validate_transaction_event_attributes import ( + validate_transaction_event_attributes, +) from newrelic.api.application import application_settings from newrelic.api.background_task import background_task - from newrelic.common.encoding_utils import deobfuscate from newrelic.common.object_wrapper import transient_function_wrapper -from testing_support.fixtures import (override_application_settings, - validate_transaction_event_sample_data, - validate_transaction_event_attributes) -from testing_support.sample_applications import (fully_featured_app, - user_attributes_added) - - fully_featured_application = webtest.TestApp(fully_featured_app) _user_attributes = user_attributes_added() -#====================== Test cases ==================================== +# ====================== Test cases ==================================== -_test_capture_attributes_enabled_settings = { - 'browser_monitoring.attributes.enabled': True } +_test_capture_attributes_enabled_settings = {"browser_monitoring.attributes.enabled": True} _intrinsic_attributes = { - 'name': 'WebTransaction/Uri/', - 'port': 80, + "name": "WebTransaction/Uri/", + "port": 80, } -@validate_transaction_event_sample_data(required_attrs=_intrinsic_attributes, - required_user_attrs=_user_attributes) + +@validate_transaction_event_sample_data(required_attrs=_intrinsic_attributes, required_user_attrs=_user_attributes) @override_application_settings(_test_capture_attributes_enabled_settings) def test_capture_attributes_enabled(): settings = application_settings() @@ -52,7 +55,7 @@ def test_capture_attributes_enabled(): assert settings.js_agent_loader - response = fully_featured_application.get('/') + response = fully_featured_application.get("/") header = response.html.html.head.script.string content = response.html.html.body.p.string @@ -60,25 +63,23 @@ def test_capture_attributes_enabled(): # Validate actual body content. - assert content == 'RESPONSE' + assert content == "RESPONSE" # We no longer are in control of the JS contents of the header so # just check to make sure it contains at least the magic string # 'NREUM'. - assert header.find('NREUM') != -1 + assert header.find("NREUM") != -1 # Now validate the various fields of the footer related to analytics. # The fields are held by a JSON dictionary. - data = json.loads(footer.split('NREUM.info=')[1]) + data = json.loads(footer.split("NREUM.info=")[1]) obfuscation_key = settings.license_key[:13] - attributes = json.loads(deobfuscate(data['atts'], - obfuscation_key)) - user_attrs = attributes['u'] - + attributes = json.loads(deobfuscate(data["atts"], obfuscation_key)) + user_attrs = attributes["u"] # When you round-trip through json encoding and json decoding, you # always end up with unicode (unicode in Python 2, str in Python 3.) @@ -90,22 +91,18 @@ def test_capture_attributes_enabled(): browser_attributes = _user_attributes.copy() - browser_attributes['bytes'] = u'bytes-value' - browser_attributes['invalid-utf8'] = _user_attributes[ - 'invalid-utf8'].decode('latin-1') - browser_attributes['multibyte-utf8'] = _user_attributes[ - 'multibyte-utf8'].decode('latin-1') + browser_attributes["bytes"] = "bytes-value" + browser_attributes["invalid-utf8"] = _user_attributes["invalid-utf8"].decode("latin-1") + browser_attributes["multibyte-utf8"] = _user_attributes["multibyte-utf8"].decode("latin-1") for attr, value in browser_attributes.items(): - assert user_attrs[attr] == value, ( - "attribute %r expected %r, found %r" % - (attr, value, user_attrs[attr])) + assert user_attrs[attr] == value, "attribute %r expected %r, found %r" % (attr, value, user_attrs[attr]) + + +_test_no_attributes_recorded_settings = {"browser_monitoring.attributes.enabled": True} -_test_no_attributes_recorded_settings = { - 'browser_monitoring.attributes.enabled': True } -@validate_transaction_event_sample_data(required_attrs=_intrinsic_attributes, - required_user_attrs={}) +@validate_transaction_event_sample_data(required_attrs=_intrinsic_attributes, required_user_attrs={}) @override_application_settings(_test_no_attributes_recorded_settings) def test_no_attributes_recorded(): settings = application_settings() @@ -115,8 +112,7 @@ def test_no_attributes_recorded(): assert settings.js_agent_loader - response = fully_featured_application.get('/', extra_environ={ - 'record_attributes': 'FALSE'}) + response = fully_featured_application.get("/", extra_environ={"record_attributes": "FALSE"}) header = response.html.html.head.script.string content = response.html.html.body.p.string @@ -124,32 +120,33 @@ def test_no_attributes_recorded(): # Validate actual body content. - assert content == 'RESPONSE' + assert content == "RESPONSE" # We no longer are in control of the JS contents of the header so # just check to make sure it contains at least the magic string # 'NREUM'. - assert header.find('NREUM') != -1 + assert header.find("NREUM") != -1 # Now validate the various fields of the footer related to analytics. # The fields are held by a JSON dictionary. - data = json.loads(footer.split('NREUM.info=')[1]) + data = json.loads(footer.split("NREUM.info=")[1]) # As we are not recording any user or agent attributes, we should not # actually have an entry at all in the footer. - assert 'atts' not in data + assert "atts" not in data + _test_analytic_events_capture_attributes_disabled_settings = { - 'transaction_events.attributes.enabled': False, - 'browser_monitoring.attributes.enabled': True } + "transaction_events.attributes.enabled": False, + "browser_monitoring.attributes.enabled": True, +} -@validate_transaction_event_sample_data(required_attrs=_intrinsic_attributes, - required_user_attrs={}) -@override_application_settings( - _test_analytic_events_capture_attributes_disabled_settings) + +@validate_transaction_event_sample_data(required_attrs=_intrinsic_attributes, required_user_attrs={}) +@override_application_settings(_test_analytic_events_capture_attributes_disabled_settings) def test_analytic_events_capture_attributes_disabled(): settings = application_settings() @@ -162,7 +159,7 @@ def test_analytic_events_capture_attributes_disabled(): assert settings.js_agent_loader - response = fully_featured_application.get('/') + response = fully_featured_application.get("/") header = response.html.html.head.script.string content = response.html.html.body.p.string @@ -170,23 +167,23 @@ def test_analytic_events_capture_attributes_disabled(): # Validate actual body content. - assert content == 'RESPONSE' + assert content == "RESPONSE" # We no longer are in control of the JS contents of the header so # just check to make sure it contains at least the magic string # 'NREUM'. - assert header.find('NREUM') != -1 + assert header.find("NREUM") != -1 # Now validate that attributes are present, since browser monitoring should # be enabled. - data = json.loads(footer.split('NREUM.info=')[1]) + data = json.loads(footer.split("NREUM.info=")[1]) + + assert "atts" in data - assert 'atts' in data -@validate_transaction_event_sample_data(required_attrs=_intrinsic_attributes, - required_user_attrs=_user_attributes) +@validate_transaction_event_sample_data(required_attrs=_intrinsic_attributes, required_user_attrs=_user_attributes) def test_capture_attributes_default(): settings = application_settings() @@ -195,7 +192,7 @@ def test_capture_attributes_default(): assert settings.js_agent_loader - response = fully_featured_application.get('/') + response = fully_featured_application.get("/") header = response.html.html.head.script.string content = response.html.html.body.p.string @@ -203,32 +200,29 @@ def test_capture_attributes_default(): # Validate actual body content. - assert content == 'RESPONSE' + assert content == "RESPONSE" # We no longer are in control of the JS contents of the header so # just check to make sure it contains at least the magic string # 'NREUM'. - assert header.find('NREUM') != -1 + assert header.find("NREUM") != -1 # Now validate that attributes are not present, since should # be disabled. - data = json.loads(footer.split('NREUM.info=')[1]) + data = json.loads(footer.split("NREUM.info=")[1]) - assert 'atts' not in data + assert "atts" not in data -_test_analytic_events_background_task_settings = { - 'browser_monitoring.attributes.enabled': True } -_intrinsic_attributes = { - 'name': 'OtherTransaction/Uri/' -} +_test_analytic_events_background_task_settings = {"browser_monitoring.attributes.enabled": True} + +_intrinsic_attributes = {"name": "OtherTransaction/Uri/"} -@validate_transaction_event_sample_data(required_attrs=_intrinsic_attributes, - required_user_attrs=_user_attributes) -@override_application_settings( - _test_analytic_events_background_task_settings) + +@validate_transaction_event_sample_data(required_attrs=_intrinsic_attributes, required_user_attrs=_user_attributes) +@override_application_settings(_test_analytic_events_background_task_settings) def test_analytic_events_background_task(): settings = application_settings() @@ -240,20 +234,17 @@ def test_analytic_events_background_task(): assert settings.js_agent_loader - response = fully_featured_application.get('/', extra_environ={ - 'newrelic.set_background_task': True}) + response = fully_featured_application.get("/", extra_environ={"newrelic.set_background_task": True}) assert response.html.html.head.script is None -_test_capture_attributes_disabled_settings = { - 'browser_monitoring.attributes.enabled': False } -_intrinsic_attributes = { - 'name': 'WebTransaction/Uri/' -} +_test_capture_attributes_disabled_settings = {"browser_monitoring.attributes.enabled": False} + +_intrinsic_attributes = {"name": "WebTransaction/Uri/"} -@validate_transaction_event_sample_data(required_attrs=_intrinsic_attributes, - required_user_attrs=_user_attributes) + +@validate_transaction_event_sample_data(required_attrs=_intrinsic_attributes, required_user_attrs=_user_attributes) @override_application_settings(_test_capture_attributes_disabled_settings) def test_capture_attributes_disabled(): settings = application_settings() @@ -263,7 +254,7 @@ def test_capture_attributes_disabled(): assert settings.js_agent_loader - response = fully_featured_application.get('/') + response = fully_featured_application.get("/") header = response.html.html.head.script.string content = response.html.html.body.p.string @@ -271,30 +262,33 @@ def test_capture_attributes_disabled(): # Validate actual body content. - assert content == 'RESPONSE' + assert content == "RESPONSE" # We no longer are in control of the JS contents of the header so # just check to make sure it contains at least the magic string # 'NREUM'. - assert header.find('NREUM') != -1 + assert header.find("NREUM") != -1 # Now validate that attributes are not present, since should # be disabled. - data = json.loads(footer.split('NREUM.info=')[1]) + data = json.loads(footer.split("NREUM.info=")[1]) + + assert "atts" not in data - assert 'atts' not in data -@transient_function_wrapper('newrelic.core.stats_engine', - 'SampledDataSet.add') +@transient_function_wrapper("newrelic.core.stats_engine", "SampledDataSet.add") def validate_no_analytics_sample_data(wrapped, instance, args, kwargs): - assert False, 'Should not be recording analytic event.' + assert False, "Should not be recording analytic event." return wrapped(*args, **kwargs) + _test_collect_analytic_events_disabled_settings = { - 'collect_analytics_events': False, - 'browser_monitoring.attributes.enabled': True } + "collect_analytics_events": False, + "browser_monitoring.attributes.enabled": True, +} + @validate_no_analytics_sample_data @override_application_settings(_test_collect_analytic_events_disabled_settings) @@ -308,7 +302,7 @@ def test_collect_analytic_events_disabled(): assert settings.js_agent_loader - response = fully_featured_application.get('/') + response = fully_featured_application.get("/") header = response.html.html.head.script.string content = response.html.html.body.p.string @@ -316,24 +310,27 @@ def test_collect_analytic_events_disabled(): # Validate actual body content. - assert content == 'RESPONSE' + assert content == "RESPONSE" # We no longer are in control of the JS contents of the header so # just check to make sure it contains at least the magic string # 'NREUM'. - assert header.find('NREUM') != -1 + assert header.find("NREUM") != -1 # Now validate that attributes are present, since should # be enabled. - data = json.loads(footer.split('NREUM.info=')[1]) + data = json.loads(footer.split("NREUM.info=")[1]) + + assert "atts" in data - assert 'atts' in data _test_analytic_events_disabled_settings = { - 'transaction_events.enabled': False, - 'browser_monitoring.attributes.enabled': True } + "transaction_events.enabled": False, + "browser_monitoring.attributes.enabled": True, +} + @validate_no_analytics_sample_data @override_application_settings(_test_analytic_events_disabled_settings) @@ -348,7 +345,7 @@ def test_analytic_events_disabled(): assert settings.js_agent_loader - response = fully_featured_application.get('/') + response = fully_featured_application.get("/") header = response.html.html.head.script.string content = response.html.html.body.p.string @@ -356,25 +353,26 @@ def test_analytic_events_disabled(): # Validate actual body content. - assert content == 'RESPONSE' + assert content == "RESPONSE" # We no longer are in control of the JS contents of the header so # just check to make sure it contains at least the magic string # 'NREUM'. - assert header.find('NREUM') != -1 + assert header.find("NREUM") != -1 # Now validate that attributes are present, since should # be enabled. - data = json.loads(footer.split('NREUM.info=')[1]) + data = json.loads(footer.split("NREUM.info=")[1]) + + assert "atts" in data - assert 'atts' in data # -------------- Test call counts in analytic events ---------------- -@validate_transaction_event_sample_data(required_attrs=_intrinsic_attributes, - required_user_attrs=_user_attributes) + +@validate_transaction_event_sample_data(required_attrs=_intrinsic_attributes, required_user_attrs=_user_attributes) def test_no_database_or_external_attributes_in_analytics(): """Make no external calls or database calls in the transaction and check if the analytic event doesn't have the databaseCallCount, databaseDuration, @@ -385,7 +383,7 @@ def test_no_database_or_external_attributes_in_analytics(): assert settings.browser_monitoring.enabled - response = fully_featured_application.get('/') + response = fully_featured_application.get("/") # Validation of analytic data happens in the decorator. @@ -393,15 +391,16 @@ def test_no_database_or_external_attributes_in_analytics(): # Validate actual body content. - assert content == 'RESPONSE' + assert content == "RESPONSE" + _intrinsic_attributes = { - 'name': 'WebTransaction/Uri/db', - 'databaseCallCount': 2, + "name": "WebTransaction/Uri/db", + "databaseCallCount": 2, } -@validate_transaction_event_sample_data(required_attrs=_intrinsic_attributes, - required_user_attrs=_user_attributes) + +@validate_transaction_event_sample_data(required_attrs=_intrinsic_attributes, required_user_attrs=_user_attributes) def test_database_attributes_in_analytics(): """Make database calls in the transaction and check if the analytic event has the databaseCallCount and databaseDuration attributes. @@ -412,9 +411,9 @@ def test_database_attributes_in_analytics(): assert settings.browser_monitoring.enabled test_environ = { - 'db' : '2', + "db": "2", } - response = fully_featured_application.get('/db', extra_environ=test_environ) + response = fully_featured_application.get("/db", extra_environ=test_environ) # Validation of analytic data happens in the decorator. @@ -422,15 +421,16 @@ def test_database_attributes_in_analytics(): # Validate actual body content. - assert content == 'RESPONSE' + assert content == "RESPONSE" + _intrinsic_attributes = { - 'name': 'WebTransaction/Uri/ext', - 'externalCallCount': 2, + "name": "WebTransaction/Uri/ext", + "externalCallCount": 2, } -@validate_transaction_event_sample_data(required_attrs=_intrinsic_attributes, - required_user_attrs=_user_attributes) + +@validate_transaction_event_sample_data(required_attrs=_intrinsic_attributes, required_user_attrs=_user_attributes) def test_external_attributes_in_analytics(): """Make external calls in the transaction and check if the analytic event has the externalCallCount and externalDuration attributes. @@ -441,10 +441,9 @@ def test_external_attributes_in_analytics(): assert settings.browser_monitoring.enabled test_environ = { - 'external' : '2', + "external": "2", } - response = fully_featured_application.get('/ext', - extra_environ=test_environ) + response = fully_featured_application.get("/ext", extra_environ=test_environ) # Validation of analytic data happens in the decorator. @@ -452,16 +451,17 @@ def test_external_attributes_in_analytics(): # Validate actual body content. - assert content == 'RESPONSE' + assert content == "RESPONSE" + _intrinsic_attributes = { - 'name': 'WebTransaction/Uri/dbext', - 'databaseCallCount': 2, - 'externalCallCount': 2, + "name": "WebTransaction/Uri/dbext", + "databaseCallCount": 2, + "externalCallCount": 2, } -@validate_transaction_event_sample_data(required_attrs=_intrinsic_attributes, - required_user_attrs=_user_attributes) + +@validate_transaction_event_sample_data(required_attrs=_intrinsic_attributes, required_user_attrs=_user_attributes) def test_database_and_external_attributes_in_analytics(): """Make external calls and database calls in the transaction and check if the analytic event has the databaseCallCount, databaseDuration, @@ -473,11 +473,10 @@ def test_database_and_external_attributes_in_analytics(): assert settings.browser_monitoring.enabled test_environ = { - 'db' : '2', - 'external' : '2', + "db": "2", + "external": "2", } - response = fully_featured_application.get('/dbext', - extra_environ=test_environ) + response = fully_featured_application.get("/dbext", extra_environ=test_environ) # Validation of analytic data happens in the decorator. @@ -485,24 +484,25 @@ def test_database_and_external_attributes_in_analytics(): # Validate actual body content. - assert content == 'RESPONSE' + assert content == "RESPONSE" + # -------------- Test background tasks ---------------- _expected_attributes = { - 'user': [], - 'agent': [], - 'intrinsic' : ('name', 'duration', 'type', 'timestamp', 'totalTime'), + "user": [], + "agent": [], + "intrinsic": ("name", "duration", "type", "timestamp", "totalTime"), } _expected_absent_attributes = { - 'user': ('foo'), - 'agent': ('response.status', 'request.method'), - 'intrinsic': ('port'), + "user": ("foo"), + "agent": ("response.status", "request.method"), + "intrinsic": ("port"), } -@validate_transaction_event_attributes(_expected_attributes, - _expected_absent_attributes) + +@validate_transaction_event_attributes(_expected_attributes, _expected_absent_attributes) @background_task() def test_background_task_intrinsics_has_no_port(): pass diff --git a/tests/agent_features/test_wsgi_attributes.py b/tests/agent_features/test_wsgi_attributes.py index 0f7f7d6f29..7543e45d8e 100644 --- a/tests/agent_features/test_wsgi_attributes.py +++ b/tests/agent_features/test_wsgi_attributes.py @@ -18,9 +18,11 @@ override_application_settings, validate_error_event_attributes, validate_transaction_error_trace_attributes, - validate_transaction_event_attributes, ) from testing_support.sample_applications import fully_featured_app +from testing_support.validators.validate_transaction_event_attributes import ( + validate_transaction_event_attributes, +) WSGI_ATTRIBUTES = [ "wsgi.input.seconds", @@ -44,6 +46,4 @@ @override_application_settings({"attributes.include": ["*"]}) @dt_enabled def test_wsgi_attributes(): - app.post_json( - "/", {"foo": "bar"}, extra_environ={"n_errors": "1", "err_message": "oops"} - ) + app.post_json("/", {"foo": "bar"}, extra_environ={"n_errors": "1", "err_message": "oops"}) diff --git a/tests/datastore_aioredis/test_transactions.py b/tests/datastore_aioredis/test_transactions.py index 168de008b5..0f84ca684e 100644 --- a/tests/datastore_aioredis/test_transactions.py +++ b/tests/datastore_aioredis/test_transactions.py @@ -13,11 +13,12 @@ # limitations under the License. import pytest +from conftest import AIOREDIS_VERSION, SKIPIF_AIOREDIS_V1, SKIPIF_AIOREDIS_V2 +from testing_support.validators.validate_transaction_errors import ( + validate_transaction_errors, +) from newrelic.api.background_task import background_task -from testing_support.fixtures import validate_transaction_errors - -from conftest import SKIPIF_AIOREDIS_V1, SKIPIF_AIOREDIS_V2, AIOREDIS_VERSION @background_task() @@ -28,7 +29,7 @@ async def exercise(): pipe = client.pipeline(transaction=in_transaction) else: pipe = client.pipeline() # Transaction kwarg unsupported - + pipe.set("TXN", 1) return await pipe.execute() @@ -68,6 +69,7 @@ async def exercise(): @background_task() def test_pipeline_immediate_execution_no_harm(client, loop): key = "TXN_WATCH" + async def exercise(): await client.set(key, 1) @@ -94,6 +96,7 @@ async def exercise(): @background_task() def test_transaction_immediate_execution_no_harm(client, loop): key = "TXN_WATCH" + async def exercise(): async def exercise_transaction(pipe): value = int(await pipe.get(key)) @@ -118,6 +121,7 @@ async def exercise_transaction(pipe): @background_task() def test_transaction_watch_error_no_harm(client, loop): key = "TXN_WATCH" + async def exercise(): async def exercise_transaction(pipe): value = int(await pipe.get(key)) diff --git a/tests/framework_aiohttp/test_server_cat.py b/tests/framework_aiohttp/test_server_cat.py index a09fa6b797..e668bed652 100644 --- a/tests/framework_aiohttp/test_server_cat.py +++ b/tests/framework_aiohttp/test_server_cat.py @@ -14,45 +14,53 @@ import asyncio import json + import pytest +from testing_support.fixtures import ( + make_cross_agent_headers, + override_application_settings, + validate_analytics_catmap_data, +) +from testing_support.validators.validate_transaction_event_attributes import ( + validate_transaction_event_attributes, +) -from newrelic.common.object_wrapper import transient_function_wrapper from newrelic.common.encoding_utils import deobfuscate -from testing_support.fixtures import (override_application_settings, - make_cross_agent_headers, validate_analytics_catmap_data, - validate_transaction_event_attributes) +from newrelic.common.object_wrapper import transient_function_wrapper -ENCODING_KEY = '1234567890123456789012345678901234567890' +ENCODING_KEY = "1234567890123456789012345678901234567890" test_uris = [ - ('/error?hello=world', '_target_application:error'), - ('/coro?hello=world', '_target_application:index'), - ('/class?hello=world', '_target_application:HelloWorldView._respond'), + ("/error?hello=world", "_target_application:error"), + ("/coro?hello=world", "_target_application:index"), + ("/class?hello=world", "_target_application:HelloWorldView._respond"), ] def record_aiohttp1_raw_headers(raw_headers): try: - import aiohttp.protocol + import aiohttp.protocol # noqa: F401 except ImportError: + def pass_through(function): return function + return pass_through - @transient_function_wrapper('aiohttp.protocol', 'HttpParser.parse_headers') + @transient_function_wrapper("aiohttp.protocol", "HttpParser.parse_headers") def recorder(wrapped, instance, args, kwargs): def _bind_params(lines): return lines lines = _bind_params(*args, **kwargs) for line in lines: - line = line.decode('utf-8') + line = line.decode("utf-8") # This is the request, not the response - if line.startswith('GET'): + if line.startswith("GET"): break - if ':' in line: - key, value = line.split(':', maxsplit=1) + if ":" in line: + key, value = line.split(":", maxsplit=1) raw_headers[key.strip()] = value.strip() return wrapped(*args, **kwargs) @@ -61,59 +69,62 @@ def _bind_params(lines): @pytest.mark.parametrize( - 'inbound_payload,expected_intrinsics,forgone_intrinsics,cat_id', [ - - # Valid payload from trusted account - (["b854df4feb2b1f06", False, "7e249074f277923d", "5d2957be"], - {"nr.referringTransactionGuid": "b854df4feb2b1f06", - "nr.tripId": "7e249074f277923d", - "nr.referringPathHash": "5d2957be"}, - [], - '1#1'), - - # Valid payload from an untrusted account - (["b854df4feb2b1f06", False, "7e249074f277923d", "5d2957be"], - {}, - ['nr.referringTransactionGuid', 'nr.tripId', 'nr.referringPathHash'], - '80#1'), -]) -@pytest.mark.parametrize('method', ['GET']) -@pytest.mark.parametrize('uri,metric_name', test_uris) -def test_cat_headers(method, uri, metric_name, inbound_payload, - expected_intrinsics, forgone_intrinsics, cat_id, aiohttp_app): + "inbound_payload,expected_intrinsics,forgone_intrinsics,cat_id", + [ + # Valid payload from trusted account + ( + ["b854df4feb2b1f06", False, "7e249074f277923d", "5d2957be"], + { + "nr.referringTransactionGuid": "b854df4feb2b1f06", + "nr.tripId": "7e249074f277923d", + "nr.referringPathHash": "5d2957be", + }, + [], + "1#1", + ), + # Valid payload from an untrusted account + ( + ["b854df4feb2b1f06", False, "7e249074f277923d", "5d2957be"], + {}, + ["nr.referringTransactionGuid", "nr.tripId", "nr.referringPathHash"], + "80#1", + ), + ], +) +@pytest.mark.parametrize("method", ["GET"]) +@pytest.mark.parametrize("uri,metric_name", test_uris) +def test_cat_headers( + method, uri, metric_name, inbound_payload, expected_intrinsics, forgone_intrinsics, cat_id, aiohttp_app +): _raw_headers = {} @asyncio.coroutine def fetch(): - headers = make_cross_agent_headers(inbound_payload, ENCODING_KEY, - cat_id) - resp = yield from aiohttp_app.client.request(method, uri, - headers=headers) + headers = make_cross_agent_headers(inbound_payload, ENCODING_KEY, cat_id) + resp = yield from aiohttp_app.client.request(method, uri, headers=headers) if _raw_headers: raw_headers = _raw_headers else: - raw_headers = {k.decode('utf-8'): v.decode('utf-8') - for k, v in resp.raw_headers} + raw_headers = {k.decode("utf-8"): v.decode("utf-8") for k, v in resp.raw_headers} if expected_intrinsics: # test valid CAT response header - assert 'X-NewRelic-App-Data' in raw_headers + assert "X-NewRelic-App-Data" in raw_headers - app_data = json.loads(deobfuscate( - raw_headers['X-NewRelic-App-Data'], ENCODING_KEY)) + app_data = json.loads(deobfuscate(raw_headers["X-NewRelic-App-Data"], ENCODING_KEY)) assert app_data[0] == cat_id - assert app_data[1] == ('WebTransaction/Function/%s' % metric_name) + assert app_data[1] == ("WebTransaction/Function/%s" % metric_name) else: - assert 'X-NewRelic-App-Data' not in resp.headers + assert "X-NewRelic-App-Data" not in resp.headers _custom_settings = { - 'cross_process_id': '1#1', - 'encoding_key': ENCODING_KEY, - 'trusted_account_ids': [1], - 'cross_application_tracer.enabled': True, - 'distributed_tracing.enabled': False, + "cross_process_id": "1#1", + "encoding_key": ENCODING_KEY, + "trusted_account_ids": [1], + "cross_application_tracer.enabled": True, + "distributed_tracing.enabled": False, } # NOTE: the logic-flow of this test can be a bit confusing. @@ -125,9 +136,11 @@ def fetch(): # is received and subsequently processed. that code is # a fixture from conftest.py/_target_application.py - @validate_analytics_catmap_data('WebTransaction/Function/%s' % metric_name, - expected_attributes=expected_intrinsics, - non_expected_attributes=forgone_intrinsics) + @validate_analytics_catmap_data( + "WebTransaction/Function/%s" % metric_name, + expected_attributes=expected_intrinsics, + non_expected_attributes=forgone_intrinsics, + ) @override_application_settings(_custom_settings) @record_aiohttp1_raw_headers(_raw_headers) def _test(): @@ -136,8 +149,8 @@ def _test(): _test() -account_id = '33' -primary_application_id = '2827902' +account_id = "33" +primary_application_id = "2827902" inbound_payload = { "v": [0, 1], @@ -150,14 +163,14 @@ def _test(): "sa": True, "ti": 1518469636035, "tr": "d6b4ba0c3a712ca", - "ty": "App" - } + "ty": "App", + }, } expected_attributes = { - 'agent': [], - 'user': [], - 'intrinsic': { + "agent": [], + "user": [], + "intrinsic": { "traceId": "d6b4ba0c3a712ca", "priority": 1.234567, "sampled": True, @@ -166,32 +179,29 @@ def _test(): "parent.account": account_id, "parent.transportType": "HTTP", "parentId": "e8b91a159289ff74", - "parentSpanId": "7d3efb1b173fecfa" - } + "parentSpanId": "7d3efb1b173fecfa", + }, } unexpected_attributes = { - 'agent': [], - 'user': [], - 'intrinsic': [ - "grandparentId", "cross_process_id", "nr.tripId", "nr.pathHash" - ] + "agent": [], + "user": [], + "intrinsic": ["grandparentId", "cross_process_id", "nr.tripId", "nr.pathHash"], } -@pytest.mark.parametrize('uri,metric_name', test_uris) +@pytest.mark.parametrize("uri,metric_name", test_uris) def test_distributed_tracing_headers(uri, metric_name, aiohttp_app): @asyncio.coroutine def fetch(): - headers = {'newrelic': json.dumps(inbound_payload)} - resp = yield from aiohttp_app.client.request('GET', uri, - headers=headers) + headers = {"newrelic": json.dumps(inbound_payload)} + resp = yield from aiohttp_app.client.request("GET", uri, headers=headers) # better cat does not send a response in the headers - assert 'newrelic' not in resp.headers + assert "newrelic" not in resp.headers # old-cat headers should not be in the response - assert 'X-NewRelic-App-Data' not in resp.headers + assert "X-NewRelic-App-Data" not in resp.headers # NOTE: the logic-flow of this test can be a bit confusing. # the override settings and attribute validation occur @@ -202,14 +212,15 @@ def fetch(): # is received and subsequently processed. that code is # a fixture from conftest.py/_target_application.py - @validate_transaction_event_attributes( - expected_attributes, unexpected_attributes) - @override_application_settings({ - 'account_id': '33', - 'trusted_account_key': '33', - 'primary_application_id': primary_application_id, - 'distributed_tracing.enabled': True - }) + @validate_transaction_event_attributes(expected_attributes, unexpected_attributes) + @override_application_settings( + { + "account_id": "33", + "trusted_account_key": "33", + "primary_application_id": primary_application_id, + "distributed_tracing.enabled": True, + } + ) def _test(): aiohttp_app.loop.run_until_complete(fetch()) diff --git a/tests/framework_sanic/test_cross_application.py b/tests/framework_sanic/test_cross_application.py index 55e5a35783..7199fae551 100644 --- a/tests/framework_sanic/test_cross_application.py +++ b/tests/framework_sanic/test_cross_application.py @@ -13,30 +13,36 @@ # limitations under the License. import json -import pytest -import re import random import string -from newrelic.common.encoding_utils import deobfuscate +import pytest +from testing_support.fixtures import ( + make_cross_agent_headers, + override_application_settings, + validate_analytics_catmap_data, +) +from testing_support.validators.validate_transaction_event_attributes import ( + validate_transaction_event_attributes, +) +from testing_support.validators.validate_transaction_metrics import ( + validate_transaction_metrics, +) + from newrelic.api.application import application_instance from newrelic.api.external_trace import ExternalTrace from newrelic.api.transaction import Transaction - -from testing_support.fixtures import (override_application_settings, - make_cross_agent_headers, validate_analytics_catmap_data, - validate_transaction_event_attributes) -from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics +from newrelic.common.encoding_utils import deobfuscate BASE_METRICS = [ - ('Function/_target_application:index', 1), + ("Function/_target_application:index", 1), ] DT_METRICS = [ - ('Supportability/DistributedTrace/AcceptPayload/Success', None), - ('Supportability/TraceContext/TraceParent/Accept/Success', 1), + ("Supportability/DistributedTrace/AcceptPayload/Success", None), + ("Supportability/TraceContext/TraceParent/Accept/Success", 1), ] -BASE_ATTRS = ['response.status', 'response.headers.contentType', - 'response.headers.contentLength'] +BASE_ATTRS = ["response.status", "response.headers.contentType", "response.headers.contentLength"] + def raw_headers(response): try: @@ -50,62 +56,69 @@ def raw_headers(response): @validate_transaction_metrics( - '_target_application:index', + "_target_application:index", scoped_metrics=BASE_METRICS, rollup_metrics=BASE_METRICS + DT_METRICS, ) -@override_application_settings({ - 'distributed_tracing.enabled': True, -}) +@override_application_settings( + { + "distributed_tracing.enabled": True, + } +) @validate_transaction_event_attributes( - required_params={'agent': BASE_ATTRS, 'user': [], 'intrinsic': []}, + required_params={"agent": BASE_ATTRS, "user": [], "intrinsic": []}, ) def test_inbound_distributed_trace(app): transaction = Transaction(application_instance()) dt_headers = ExternalTrace.generate_request_headers(transaction) - response = app.fetch('get', '/', headers=dict(dt_headers)) + response = app.fetch("get", "/", headers=dict(dt_headers)) assert response.status == 200 -ENCODING_KEY = "".join(random.choice(string.ascii_lowercase) for _ in range(40)) +ENCODING_KEY = "".join(random.choice(string.ascii_lowercase) for _ in range(40)) # nosec _cat_response_header_urls_to_test = ( - ('/', '_target_application:index'), - ('/streaming', '_target_application:streaming'), - ('/error', '_target_application:error'), + ("/", "_target_application:index"), + ("/streaming", "_target_application:streaming"), + ("/error", "_target_application:error"), ) _custom_settings = { - 'cross_process_id': '1#1', - 'encoding_key': ENCODING_KEY, - 'trusted_account_ids': [1], - 'cross_application_tracer.enabled': True, - 'distributed_tracing.enabled': False, + "cross_process_id": "1#1", + "encoding_key": ENCODING_KEY, + "trusted_account_ids": [1], + "cross_application_tracer.enabled": True, + "distributed_tracing.enabled": False, } @pytest.mark.parametrize( - 'inbound_payload,expected_intrinsics,forgone_intrinsics,cat_id', [ - - # Valid payload from trusted account - (['b854df4feb2b1f06', False, '7e249074f277923d', '5d2957be'], - {'nr.referringTransactionGuid': 'b854df4feb2b1f06', - 'nr.tripId': '7e249074f277923d', - 'nr.referringPathHash': '5d2957be'}, - [], - '1#1'), - - # Valid payload from an untrusted account - (['b854df4feb2b1f06', False, '7e249074f277923d', '5d2957be'], - {}, - ['nr.referringTransactionGuid', 'nr.tripId', 'nr.referringPathHash'], - '80#1'), -]) -@pytest.mark.parametrize('url,metric_name', _cat_response_header_urls_to_test) -def test_cat_response_headers(app, inbound_payload, expected_intrinsics, - forgone_intrinsics, cat_id, url, metric_name): + "inbound_payload,expected_intrinsics,forgone_intrinsics,cat_id", + [ + # Valid payload from trusted account + ( + ["b854df4feb2b1f06", False, "7e249074f277923d", "5d2957be"], + { + "nr.referringTransactionGuid": "b854df4feb2b1f06", + "nr.tripId": "7e249074f277923d", + "nr.referringPathHash": "5d2957be", + }, + [], + "1#1", + ), + # Valid payload from an untrusted account + ( + ["b854df4feb2b1f06", False, "7e249074f277923d", "5d2957be"], + {}, + ["nr.referringTransactionGuid", "nr.tripId", "nr.referringPathHash"], + "80#1", + ), + ], +) +@pytest.mark.parametrize("url,metric_name", _cat_response_header_urls_to_test) +def test_cat_response_headers(app, inbound_payload, expected_intrinsics, forgone_intrinsics, cat_id, url, metric_name): _base_metrics = [ - ('Function/%s' % metric_name, 1), + ("Function/%s" % metric_name, 1), ] @validate_transaction_metrics( @@ -114,39 +127,36 @@ def test_cat_response_headers(app, inbound_payload, expected_intrinsics, rollup_metrics=_base_metrics, ) @validate_analytics_catmap_data( - 'WebTransaction/Function/%s' % metric_name, - expected_attributes=expected_intrinsics, - non_expected_attributes=forgone_intrinsics) + "WebTransaction/Function/%s" % metric_name, + expected_attributes=expected_intrinsics, + non_expected_attributes=forgone_intrinsics, + ) @override_application_settings(_custom_settings) def _test(): - cat_headers = make_cross_agent_headers(inbound_payload, ENCODING_KEY, - cat_id) - response = app.fetch('get', url, headers=dict(cat_headers)) + cat_headers = make_cross_agent_headers(inbound_payload, ENCODING_KEY, cat_id) + response = app.fetch("get", url, headers=dict(cat_headers)) if expected_intrinsics: # test valid CAT response header - assert b'X-NewRelic-App-Data' in raw_headers(response) + assert b"X-NewRelic-App-Data" in raw_headers(response) cat_response_header = response.headers.get("X-NewRelic-App-Data", None) - app_data = json.loads(deobfuscate(cat_response_header, - ENCODING_KEY)) + app_data = json.loads(deobfuscate(cat_response_header, ENCODING_KEY)) assert app_data[0] == cat_id - assert app_data[1] == ('WebTransaction/Function/%s' % metric_name) + assert app_data[1] == ("WebTransaction/Function/%s" % metric_name) else: - assert b'X-NewRelic-App-Data' not in raw_headers(response) + assert b"X-NewRelic-App-Data" not in raw_headers(response) _test() @override_application_settings(_custom_settings) def test_cat_response_custom_header(app): - inbound_payload = ['b854df4feb2b1f06', False, '7e249074f277923d', - '5d2957be'] - cat_id = '1#1' - custom_header_value = b'my-custom-header-value' - cat_headers = make_cross_agent_headers(inbound_payload, ENCODING_KEY, - cat_id) - - response = app.fetch('get', '/custom-header/%s/%s' % ( - 'X-NewRelic-App-Data', custom_header_value), - headers=dict(cat_headers)) + inbound_payload = ["b854df4feb2b1f06", False, "7e249074f277923d", "5d2957be"] + cat_id = "1#1" + custom_header_value = b"my-custom-header-value" + cat_headers = make_cross_agent_headers(inbound_payload, ENCODING_KEY, cat_id) + + response = app.fetch( + "get", "/custom-header/%s/%s" % ("X-NewRelic-App-Data", custom_header_value), headers=dict(cat_headers) + ) assert custom_header_value in raw_headers(response), raw_headers(response) diff --git a/tests/framework_tornado/test_server.py b/tests/framework_tornado/test_server.py index 57eb8b5761..ffeae3685c 100644 --- a/tests/framework_tornado/test_server.py +++ b/tests/framework_tornado/test_server.py @@ -13,42 +13,56 @@ # limitations under the License. import pytest -from newrelic.core.config import global_settings from testing_support.fixtures import ( - override_generic_settings, function_not_called, - validate_transaction_event_attributes, - override_ignore_status_codes, - override_application_settings) + function_not_called, + override_application_settings, + override_generic_settings, + override_ignore_status_codes, +) +from testing_support.validators.validate_code_level_metrics import ( + validate_code_level_metrics, +) from testing_support.validators.validate_transaction_count import ( - validate_transaction_count) -from testing_support.validators.validate_code_level_metrics import validate_code_level_metrics -from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics -from testing_support.validators.validate_transaction_errors import validate_transaction_errors - -@pytest.mark.parametrize('uri,name,metrics, method_metric', ( - # ('/native-simple', '_target_application:NativeSimpleHandler.get', None, - # True), - # ('/simple', '_target_application:SimpleHandler.get', None, True), - ('/call-simple', '_target_application:CallSimpleHandler.get', None, True), - ('/super-simple', '_target_application:SuperSimpleHandler.get', None, - True), - ('/coro', '_target_application:CoroHandler.get', None, False), - ('/fake-coro', '_target_application:FakeCoroHandler.get', None, False), - ('/coro-throw', '_target_application:CoroThrowHandler.get', None, False), - ('/init', '_target_application:InitializeHandler.get', None, True), - ('/multi-trace', '_target_application:MultiTraceHandler.get', - [('Function/trace', 2)], True), -)) -@override_application_settings({'attributes.include': ['request.*']}) + validate_transaction_count, +) +from testing_support.validators.validate_transaction_errors import ( + validate_transaction_errors, +) +from testing_support.validators.validate_transaction_event_attributes import ( + validate_transaction_event_attributes, +) +from testing_support.validators.validate_transaction_metrics import ( + validate_transaction_metrics, +) + +from newrelic.core.config import global_settings + + +@pytest.mark.parametrize( + "uri,name,metrics, method_metric", + ( + # ('/native-simple', '_target_application:NativeSimpleHandler.get', None, + # True), + # ('/simple', '_target_application:SimpleHandler.get', None, True), + ("/call-simple", "_target_application:CallSimpleHandler.get", None, True), + ("/super-simple", "_target_application:SuperSimpleHandler.get", None, True), + ("/coro", "_target_application:CoroHandler.get", None, False), + ("/fake-coro", "_target_application:FakeCoroHandler.get", None, False), + ("/coro-throw", "_target_application:CoroThrowHandler.get", None, False), + ("/init", "_target_application:InitializeHandler.get", None, True), + ("/multi-trace", "_target_application:MultiTraceHandler.get", [("Function/trace", 2)], True), + ), +) +@override_application_settings({"attributes.include": ["request.*"]}) def test_server(app, uri, name, metrics, method_metric): - FRAMEWORK_METRIC = 'Python/Framework/Tornado/%s' % app.tornado_version - METHOD_METRIC = 'Function/%s' % name + FRAMEWORK_METRIC = "Python/Framework/Tornado/%s" % app.tornado_version + METHOD_METRIC = "Function/%s" % name metrics = metrics or [] metrics.append((FRAMEWORK_METRIC, 1)) metrics.append((METHOD_METRIC, 1 if method_metric else None)) - host = '127.0.0.1:' + str(app.get_http_port()) + host = "127.0.0.1:" + str(app.get_http_port()) namespace, func_name = name.split(".") namespace = namespace.replace(":", ".") @@ -57,21 +71,21 @@ def test_server(app, uri, name, metrics, method_metric): rollup_metrics=metrics, ) @validate_transaction_event_attributes( - required_params={ - 'agent': ('response.headers.contentType',), - 'user': (), 'intrinsic': ()}, + required_params={"agent": ("response.headers.contentType",), "user": (), "intrinsic": ()}, exact_attrs={ - 'agent': {'request.headers.contentType': '1234', - 'request.headers.host': host, - 'request.method': 'GET', - 'request.uri': uri, - 'response.status': '200'}, - 'user': {}, - 'intrinsic': {'port': app.get_http_port()}, + "agent": { + "request.headers.contentType": "1234", + "request.headers.host": host, + "request.method": "GET", + "request.uri": uri, + "response.status": "200", + }, + "user": {}, + "intrinsic": {"port": app.get_http_port()}, }, ) def _test(): - response = app.fetch(uri, headers=(('Content-Type', '1234'),)) + response = app.fetch(uri, headers=(("Content-Type", "1234"),)) assert response.code == 200 if method_metric: @@ -80,33 +94,31 @@ def _test(): _test() -@pytest.mark.parametrize('uri,name,metrics,method_metric', ( - ('/native-simple', '_target_application:NativeSimpleHandler.get', None, - True), - ('/simple', '_target_application:SimpleHandler.get', None, True), - ('/call-simple', '_target_application:CallSimpleHandler.get', None, True), - ('/super-simple', '_target_application:SuperSimpleHandler.get', None, - True), - ('/coro', '_target_application:CoroHandler.get', None, False), - ('/fake-coro', '_target_application:FakeCoroHandler.get', None, False), - ('/coro-throw', '_target_application:CoroThrowHandler.get', None, False), - ('/init', '_target_application:InitializeHandler.get', None, True), - ('/ensure-future', - '_target_application:EnsureFutureHandler.get', - [('Function/trace', None)], True), - ('/multi-trace', '_target_application:MultiTraceHandler.get', - [('Function/trace', 2)], True), -)) +@pytest.mark.parametrize( + "uri,name,metrics,method_metric", + ( + ("/native-simple", "_target_application:NativeSimpleHandler.get", None, True), + ("/simple", "_target_application:SimpleHandler.get", None, True), + ("/call-simple", "_target_application:CallSimpleHandler.get", None, True), + ("/super-simple", "_target_application:SuperSimpleHandler.get", None, True), + ("/coro", "_target_application:CoroHandler.get", None, False), + ("/fake-coro", "_target_application:FakeCoroHandler.get", None, False), + ("/coro-throw", "_target_application:CoroThrowHandler.get", None, False), + ("/init", "_target_application:InitializeHandler.get", None, True), + ("/ensure-future", "_target_application:EnsureFutureHandler.get", [("Function/trace", None)], True), + ("/multi-trace", "_target_application:MultiTraceHandler.get", [("Function/trace", 2)], True), + ), +) def test_concurrent_inbound_requests(app, uri, name, metrics, method_metric): from tornado import gen - FRAMEWORK_METRIC = 'Python/Framework/Tornado/%s' % app.tornado_version - METHOD_METRIC = 'Function/%s' % name + FRAMEWORK_METRIC = "Python/Framework/Tornado/%s" % app.tornado_version + METHOD_METRIC = "Function/%s" % name metrics = metrics or [] metrics.append((FRAMEWORK_METRIC, 1)) metrics.append((METHOD_METRIC, 1 if method_metric else None)) - + namespace, func_name = name.split(".") namespace = namespace.replace(":", ".") @@ -128,85 +140,91 @@ def _test(): _test() + @validate_code_level_metrics("_target_application.CrashHandler", "get") -@validate_transaction_metrics('_target_application:CrashHandler.get') -@validate_transaction_errors(['builtins:ValueError']) +@validate_transaction_metrics("_target_application:CrashHandler.get") +@validate_transaction_errors(["builtins:ValueError"]) def test_exceptions_are_recorded(app): - response = app.fetch('/crash') + response = app.fetch("/crash") assert response.code == 500 -@pytest.mark.parametrize('nr_enabled,ignore_status_codes', [ - (True, [405]), - (True, []), - (False, None), -]) +@pytest.mark.parametrize( + "nr_enabled,ignore_status_codes", + [ + (True, [405]), + (True, []), + (False, None), + ], +) def test_unsupported_method(app, nr_enabled, ignore_status_codes): - def _test(): - response = app.fetch('/simple', - method='TEAPOT', body=b'', allow_nonstandard_methods=True) + response = app.fetch("/simple", method="TEAPOT", body=b"", allow_nonstandard_methods=True) assert response.code == 405 if nr_enabled: _test = override_ignore_status_codes(ignore_status_codes)(_test) - _test = validate_transaction_metrics( - '_target_application:SimpleHandler')(_test) + _test = validate_transaction_metrics("_target_application:SimpleHandler")(_test) if ignore_status_codes: _test = validate_transaction_errors(errors=[])(_test) else: - _test = validate_transaction_errors( - errors=['tornado.web:HTTPError'])(_test) + _test = validate_transaction_errors(errors=["tornado.web:HTTPError"])(_test) else: settings = global_settings() - _test = override_generic_settings(settings, {'enabled': False})(_test) + _test = override_generic_settings(settings, {"enabled": False})(_test) _test() @validate_transaction_errors(errors=[]) -@validate_transaction_metrics('tornado.web:ErrorHandler') +@validate_transaction_metrics("tornado.web:ErrorHandler") @validate_transaction_event_attributes( - required_params={'agent': (), 'user': (), 'intrinsic': ()}, + required_params={"agent": (), "user": (), "intrinsic": ()}, exact_attrs={ - 'agent': {'request.uri': '/does-not-exist'}, - 'user': {}, - 'intrinsic': {}, + "agent": {"request.uri": "/does-not-exist"}, + "user": {}, + "intrinsic": {}, }, ) def test_not_found(app): - response = app.fetch('/does-not-exist') + response = app.fetch("/does-not-exist") assert response.code == 404 -@override_generic_settings(global_settings(), { - 'enabled': False, -}) -@function_not_called('newrelic.core.stats_engine', - 'StatsEngine.record_transaction') +@override_generic_settings( + global_settings(), + { + "enabled": False, + }, +) +@function_not_called("newrelic.core.stats_engine", "StatsEngine.record_transaction") def test_nr_disabled(app): - response = app.fetch('/simple') + response = app.fetch("/simple") assert response.code == 200 -@pytest.mark.parametrize('uri,name', ( - ('/web-socket', '_target_application:WebSocketHandler'), - ('/call-web-socket', '_target_application:WebNestedHandler'), -)) +@pytest.mark.parametrize( + "uri,name", + ( + ("/web-socket", "_target_application:WebSocketHandler"), + ("/call-web-socket", "_target_application:WebNestedHandler"), + ), +) def test_web_socket(uri, name, app): import asyncio + from tornado.websocket import websocket_connect namespace, func_name = name.split(":") @validate_transaction_metrics( name, - rollup_metrics=[('Function/%s' % name, None)], + rollup_metrics=[("Function/%s" % name, None)], ) @validate_code_level_metrics(namespace, func_name) def _test(): - url = app.get_url(uri).replace('http', 'ws') + url = app.get_url(uri).replace("http", "ws") @asyncio.coroutine def _connect(): @@ -219,14 +237,14 @@ def _connect(): def connect(): return app.io_loop.run_sync(_connect) - @function_not_called('newrelic.core.stats_engine', - 'StatsEngine.record_transaction') + @function_not_called("newrelic.core.stats_engine", "StatsEngine.record_transaction") def call(call): @asyncio.coroutine def _call(): yield from conn.write_message("test") resp = yield from conn.read_message() assert resp == "hello test" + app.io_loop.run_sync(_call) conn = connect() @@ -236,13 +254,10 @@ def _call(): _test() -LOOP_TIME_METRICS = ( - ('EventLoop/Wait/' - 'WebTransaction/Function/_target_application:BlockingHandler.get', 1), -) +LOOP_TIME_METRICS = (("EventLoop/Wait/" "WebTransaction/Function/_target_application:BlockingHandler.get", 1),) -@pytest.mark.parametrize('yield_before_finish', (True, False)) +@pytest.mark.parametrize("yield_before_finish", (True, False)) @validate_transaction_metrics( "_target_application:BlockingHandler.get", scoped_metrics=LOOP_TIME_METRICS, @@ -251,9 +266,9 @@ def test_io_loop_blocking_time(app, yield_before_finish): from tornado import gen if yield_before_finish: - url = app.get_url('/block-with-yield/2') + url = app.get_url("/block-with-yield/2") else: - url = app.get_url('/block/2') + url = app.get_url("/block/2") coros = (app.http_client.fetch(url) for _ in range(2)) responses = app.io_loop.run_sync(lambda: gen.multi(coros)) diff --git a/tests/messagebroker_confluentkafka/test_consumer.py b/tests/messagebroker_confluentkafka/test_consumer.py index 61f532a784..3300537059 100644 --- a/tests/messagebroker_confluentkafka/test_consumer.py +++ b/tests/messagebroker_confluentkafka/test_consumer.py @@ -18,8 +18,6 @@ reset_core_stats_engine, validate_attributes, validate_error_event_attributes_outside_transaction, - validate_transaction_errors, - validate_transaction_metrics, ) from testing_support.validators.validate_distributed_trace_accepted import ( validate_distributed_trace_accepted, @@ -27,6 +25,12 @@ from testing_support.validators.validate_transaction_count import ( validate_transaction_count, ) +from testing_support.validators.validate_transaction_errors import ( + validate_transaction_errors, +) +from testing_support.validators.validate_transaction_metrics import ( + validate_transaction_metrics, +) from newrelic.api.background_task import background_task from newrelic.api.transaction import end_of_transaction diff --git a/tests/messagebroker_confluentkafka/test_producer.py b/tests/messagebroker_confluentkafka/test_producer.py index 71b674e80f..3f66cccba6 100644 --- a/tests/messagebroker_confluentkafka/test_producer.py +++ b/tests/messagebroker_confluentkafka/test_producer.py @@ -16,13 +16,15 @@ import pytest from conftest import cache_kafka_producer_headers -from testing_support.fixtures import ( - validate_transaction_errors, - validate_transaction_metrics, -) from testing_support.validators.validate_messagebroker_headers import ( validate_messagebroker_headers, ) +from testing_support.validators.validate_transaction_errors import ( + validate_transaction_errors, +) +from testing_support.validators.validate_transaction_metrics import ( + validate_transaction_metrics, +) from newrelic.api.background_task import background_task from newrelic.common.object_names import callable_name diff --git a/tests/messagebroker_confluentkafka/test_serialization.py b/tests/messagebroker_confluentkafka/test_serialization.py index 4d948713d1..0b8b41d52a 100644 --- a/tests/messagebroker_confluentkafka/test_serialization.py +++ b/tests/messagebroker_confluentkafka/test_serialization.py @@ -13,8 +13,10 @@ # limitations under the License. import pytest -from testing_support.fixtures import ( +from testing_support.validators.validate_transaction_errors import ( validate_transaction_errors, +) +from testing_support.validators.validate_transaction_metrics import ( validate_transaction_metrics, ) diff --git a/tests/messagebroker_kafkapython/test_consumer.py b/tests/messagebroker_kafkapython/test_consumer.py index f53b2acb31..bf71d3eb9a 100644 --- a/tests/messagebroker_kafkapython/test_consumer.py +++ b/tests/messagebroker_kafkapython/test_consumer.py @@ -18,8 +18,6 @@ reset_core_stats_engine, validate_attributes, validate_error_event_attributes_outside_transaction, - validate_transaction_errors, - validate_transaction_metrics, ) from testing_support.validators.validate_distributed_trace_accepted import ( validate_distributed_trace_accepted, @@ -27,6 +25,12 @@ from testing_support.validators.validate_transaction_count import ( validate_transaction_count, ) +from testing_support.validators.validate_transaction_errors import ( + validate_transaction_errors, +) +from testing_support.validators.validate_transaction_metrics import ( + validate_transaction_metrics, +) from newrelic.api.background_task import background_task from newrelic.api.transaction import end_of_transaction diff --git a/tests/messagebroker_kafkapython/test_producer.py b/tests/messagebroker_kafkapython/test_producer.py index 927956482f..af10a111cc 100644 --- a/tests/messagebroker_kafkapython/test_producer.py +++ b/tests/messagebroker_kafkapython/test_producer.py @@ -14,13 +14,15 @@ import pytest from conftest import cache_kafka_producer_headers -from testing_support.fixtures import ( - validate_transaction_errors, - validate_transaction_metrics, -) from testing_support.validators.validate_messagebroker_headers import ( validate_messagebroker_headers, ) +from testing_support.validators.validate_transaction_errors import ( + validate_transaction_errors, +) +from testing_support.validators.validate_transaction_metrics import ( + validate_transaction_metrics, +) from newrelic.api.background_task import background_task from newrelic.common.object_names import callable_name diff --git a/tests/messagebroker_kafkapython/test_serialization.py b/tests/messagebroker_kafkapython/test_serialization.py index b83b4e85ce..f58d082ec7 100644 --- a/tests/messagebroker_kafkapython/test_serialization.py +++ b/tests/messagebroker_kafkapython/test_serialization.py @@ -18,7 +18,11 @@ from testing_support.fixtures import ( reset_core_stats_engine, validate_error_event_attributes_outside_transaction, +) +from testing_support.validators.validate_transaction_errors import ( validate_transaction_errors, +) +from testing_support.validators.validate_transaction_metrics import ( validate_transaction_metrics, ) From 3e59665823425c2f21dcb638ccc02d0942ed9cd4 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Tue, 25 Oct 2022 15:50:33 -0700 Subject: [PATCH 12/14] Fix (more) import issues --- .../validators/validate_non_transaction_error_event.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testing_support/validators/validate_non_transaction_error_event.py b/tests/testing_support/validators/validate_non_transaction_error_event.py index dc97d7a421..fa14ae37d2 100644 --- a/tests/testing_support/validators/validate_non_transaction_error_event.py +++ b/tests/testing_support/validators/validate_non_transaction_error_event.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from time import time +import time from testing_support.fixtures import core_application_stats_engine From 743de4d23dbe250b26026624f89fffae044c1fdc Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Tue, 25 Oct 2022 16:03:27 -0700 Subject: [PATCH 13/14] Fix validate_transaction_metrics import in aioredis --- tests/datastore_aioredis/test_custom_conn_pool.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/datastore_aioredis/test_custom_conn_pool.py b/tests/datastore_aioredis/test_custom_conn_pool.py index 18c2244624..e59760ea39 100644 --- a/tests/datastore_aioredis/test_custom_conn_pool.py +++ b/tests/datastore_aioredis/test_custom_conn_pool.py @@ -18,11 +18,11 @@ """ from testing_support.db_settings import redis_settings +from testing_support.fixtures import override_application_settings from testing_support.util import instance_hostname # from testing_support.fixture.event_loop import event_loop as loop from testing_support.validators.validate_transaction_metrics import ( - override_application_settings, validate_transaction_metrics, ) From 889bc1e22c1c307f60ba5cc30e25f6d3cd8b62af Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Thu, 10 Nov 2022 10:43:17 -0800 Subject: [PATCH 14/14] Remove commented code from fixtures.py --- tests/testing_support/fixtures.py | 498 ------------------------------ 1 file changed, 498 deletions(-) diff --git a/tests/testing_support/fixtures.py b/tests/testing_support/fixtures.py index d064bcb228..9e99e89b21 100644 --- a/tests/testing_support/fixtures.py +++ b/tests/testing_support/fixtures.py @@ -386,194 +386,6 @@ def make_synthetics_header(account_id, resource_id, job_id, monitor_id, encoding return {"X-NewRelic-Synthetics": value} -# def validate_transaction_metrics( -# name, -# group="Function", -# background_task=False, -# scoped_metrics=None, -# rollup_metrics=None, -# custom_metrics=None, -# index=-1, -# ): -# scoped_metrics = scoped_metrics or [] -# rollup_metrics = rollup_metrics or [] -# custom_metrics = custom_metrics or [] - -# if background_task: -# unscoped_metrics = [ -# "OtherTransaction/all", -# "OtherTransaction/%s/%s" % (group, name), -# "OtherTransactionTotalTime", -# "OtherTransactionTotalTime/%s/%s" % (group, name), -# ] -# transaction_scope_name = "OtherTransaction/%s/%s" % (group, name) -# else: -# unscoped_metrics = [ -# "WebTransaction", -# "WebTransaction/%s/%s" % (group, name), -# "WebTransactionTotalTime", -# "WebTransactionTotalTime/%s/%s" % (group, name), -# "HttpDispatcher", -# ] -# transaction_scope_name = "WebTransaction/%s/%s" % (group, name) - -# @function_wrapper -# def _validate_wrapper(wrapped, instance, args, kwargs): - -# record_transaction_called = [] -# recorded_metrics = [] - -# @transient_function_wrapper("newrelic.core.stats_engine", "StatsEngine.record_transaction") -# @catch_background_exceptions -# def _validate_transaction_metrics(wrapped, instance, args, kwargs): -# record_transaction_called.append(True) -# try: -# result = wrapped(*args, **kwargs) -# except: -# raise -# else: -# metrics = instance.stats_table -# # Record a copy of the metric value so that the values aren't -# # merged in the future -# _metrics = {} -# for k, v in metrics.items(): -# _metrics[k] = copy.copy(v) -# recorded_metrics.append(_metrics) - -# return result - -# def _validate(metrics, name, scope, count): -# key = (name, scope) -# metric = metrics.get(key) - -# def _metrics_table(): -# out = [""] -# out.append("Expected: {0}: {1}".format(key, count)) -# for metric_key, metric_value in metrics.items(): -# out.append("{0}: {1}".format(metric_key, metric_value[0])) -# return "\n".join(out) - -# def _metric_details(): -# return "metric=%r, count=%r" % (key, metric.call_count) - -# if count is not None: -# assert metric is not None, _metrics_table() -# if count == "present": -# assert metric.call_count > 0, _metric_details() -# else: -# assert metric.call_count == count, _metric_details() - -# assert metric.total_call_time >= 0, (key, metric) -# assert metric.total_exclusive_call_time >= 0, (key, metric) -# assert metric.min_call_time >= 0, (key, metric) -# assert metric.sum_of_squares >= 0, (key, metric) - -# else: -# assert metric is None, _metrics_table() - -# _new_wrapper = _validate_transaction_metrics(wrapped) -# val = _new_wrapper(*args, **kwargs) -# assert record_transaction_called -# metrics = recorded_metrics[index] - -# record_transaction_called[:] = [] -# recorded_metrics[:] = [] - -# for unscoped_metric in unscoped_metrics: -# _validate(metrics, unscoped_metric, "", 1) - -# for scoped_name, scoped_count in scoped_metrics: -# _validate(metrics, scoped_name, transaction_scope_name, scoped_count) - -# for rollup_name, rollup_count in rollup_metrics: -# _validate(metrics, rollup_name, "", rollup_count) - -# for custom_name, custom_count in custom_metrics: -# _validate(metrics, custom_name, "", custom_count) - -# custom_metric_names = {name for name, _ in custom_metrics} -# for name, _ in metrics: -# if name not in custom_metric_names: -# assert not name.startswith("Supportability/api/"), name - -# return val - -# return _validate_wrapper - - -# def validate_time_metrics_outside_transaction(time_metrics=None, index=-1): -# time_metrics = time_metrics or [] - -# @function_wrapper -# def _validate_wrapper(wrapped, instance, args, kwargs): - -# record_time_metric_called = [] -# recorded_metrics = [] - -# @transient_function_wrapper("newrelic.core.stats_engine", "StatsEngine.record_time_metric") -# @catch_background_exceptions -# def _validate_transaction_metrics(wrapped, instance, args, kwargs): -# record_time_metric_called.append(True) -# try: -# result = wrapped(*args, **kwargs) -# except: -# raise -# else: -# metrics = instance.stats_table -# # Record a copy of the metric value so that the values aren't -# # merged in the future -# _metrics = {} -# for k, v in metrics.items(): -# _metrics[k] = copy.copy(v) -# recorded_metrics.append(_metrics) - -# return result - -# def _validate(metrics, name, count): -# key = (name, "") -# metric = metrics.get(key) - -# def _metrics_table(): -# out = [""] -# out.append("Expected: {0}: {1}".format(key, count)) -# for metric_key, metric_value in metrics.items(): -# out.append("{0}: {1}".format(metric_key, metric_value[0])) -# return "\n".join(out) - -# def _metric_details(): -# return "metric=%r, count=%r" % (key, metric.call_count) - -# if count is not None: -# assert metric is not None, _metrics_table() -# if count == "present": -# assert metric.call_count > 0, _metric_details() -# else: -# assert metric.call_count == count, _metric_details() - -# assert metric.total_call_time >= 0, (key, metric) -# assert metric.total_exclusive_call_time >= 0, (key, metric) -# assert metric.min_call_time >= 0, (key, metric) -# assert metric.sum_of_squares >= 0, (key, metric) - -# else: -# assert metric is None, _metrics_table() - -# _new_wrapper = _validate_transaction_metrics(wrapped) -# val = _new_wrapper(*args, **kwargs) -# assert record_time_metric_called -# metrics = recorded_metrics[index] - -# record_time_metric_called[:] = [] -# recorded_metrics[:] = [] - -# for time_metric, count in time_metrics: -# _validate(metrics, time_metric, count) - -# return val - -# return _validate_wrapper - - def capture_transaction_metrics(metrics_list, full_metrics=None): @transient_function_wrapper("newrelic.core.stats_engine", "StatsEngine.record_transaction") @catch_background_exceptions @@ -595,264 +407,6 @@ def _capture_transaction_metrics(wrapped, instance, args, kwargs): return _capture_transaction_metrics -# def validate_internal_metrics(metrics=None): -# metrics = metrics or [] - -# def no_op(wrapped, instance, args, kwargs): -# pass - -# @function_wrapper -# def _validate_wrapper(wrapped, instance, args, kwargs): -# # Apply no-op wrappers to prevent new internal trace contexts from being started, preventing capture -# wrapped = transient_function_wrapper("newrelic.core.internal_metrics", "InternalTraceContext.__enter__")(no_op)(wrapped) -# wrapped = transient_function_wrapper("newrelic.core.internal_metrics", "InternalTraceContext.__exit__")(no_op)(wrapped) - -# captured_metrics = CustomMetrics() -# with InternalTraceContext(captured_metrics): -# result = wrapped(*args, **kwargs) -# captured_metrics = dict(captured_metrics.metrics()) - -# def _validate(name, count): -# metric = captured_metrics.get(name) - -# def _metrics_table(): -# return "metric=%r, metrics=%r" % (name, captured_metrics) - -# def _metric_details(): -# return "metric=%r, count=%r" % (name, metric.call_count) - -# if count is not None and count > 0: -# assert metric is not None, _metrics_table() -# if count == "present": -# assert metric.call_count > 0, _metric_details() -# else: -# assert metric.call_count == count, _metric_details() - -# else: -# assert metric is None, _metrics_table() - -# for metric, count in metrics: -# _validate(metric, count) - -# return result - -# return _validate_wrapper - - -# def validate_transaction_errors(errors=None, required_params=None, forgone_params=None): -# errors = errors or [] -# required_params = required_params or [] -# forgone_params = forgone_params or [] -# captured_errors = [] - -# @transient_function_wrapper("newrelic.core.stats_engine", "StatsEngine.record_transaction") -# @catch_background_exceptions -# def _capture_transaction_errors(wrapped, instance, args, kwargs): -# def _bind_params(transaction, *args, **kwargs): -# return transaction - -# transaction = _bind_params(*args, **kwargs) -# captured = transaction.errors - -# captured_errors.append(captured) - -# return wrapped(*args, **kwargs) - -# @function_wrapper -# def _validate_transaction_errors(wrapped, instance, args, kwargs): -# _new_wrapped = _capture_transaction_errors(wrapped) -# output = _new_wrapped(*args, **kwargs) - -# expected = sorted(errors) - -# if captured_errors: -# captured = captured_errors[0] -# else: -# captured = [] - -# if errors and isinstance(errors[0], (tuple, list)): -# compare_to = sorted([(e.type, e.message) for e in captured]) -# else: -# compare_to = sorted([e.type for e in captured]) - -# assert expected == compare_to, "expected=%r, captured=%r, errors=%r" % (expected, compare_to, captured) - -# for e in captured: -# assert e.span_id -# for name, value in required_params: -# assert name in e.custom_params, "name=%r, params=%r" % (name, e.custom_params) -# assert e.custom_params[name] == value, "name=%r, value=%r, params=%r" % ( -# name, -# value, -# e.custom_params, -# ) - -# for name, value in forgone_params: -# assert name not in e.custom_params, "name=%r, params=%r" % (name, e.custom_params) - -# return output - -# return _validate_transaction_errors - - -# def validate_application_errors(errors=None, required_params=None, forgone_params=None): -# errors = errors or [] -# required_params = required_params or [] -# forgone_params = forgone_params or [] - -# @function_wrapper -# def _validate_application_errors(wrapped, instace, args, kwargs): - -# try: -# result = wrapped(*args, **kwargs) -# except: -# raise -# else: - -# stats = core_application_stats_engine() - -# app_errors = stats.error_data() - -# expected = sorted(errors) -# captured = sorted([(e.type, e.message) for e in stats.error_data()]) - -# assert expected == captured, "expected=%r, captured=%r, errors=%r" % (expected, captured, app_errors) - -# for e in app_errors: -# for name, value in required_params: -# assert name in e.parameters["userAttributes"], "name=%r, params=%r" % (name, e.parameters) -# assert e.parameters["userAttributes"][name] == value, "name=%r, value=%r, params=%r" % ( -# name, -# value, -# e.parameters, -# ) - -# for name, value in forgone_params: -# assert name not in e.parameters["userAttributes"], "name=%r, params=%r" % (name, e.parameters) - -# return result - -# return _validate_application_errors - - -# def validate_custom_parameters(required_params=None, forgone_params=None): -# required_params = required_params or [] -# forgone_params = forgone_params or [] - -# @transient_function_wrapper("newrelic.core.stats_engine", "StatsEngine.record_transaction") -# @catch_background_exceptions -# def _validate_custom_parameters(wrapped, instance, args, kwargs): -# def _bind_params(transaction, *args, **kwargs): -# return transaction - -# transaction = _bind_params(*args, **kwargs) - -# # these are pre-destination applied attributes, so they may not -# # actually end up in a transaction/error trace, we are merely testing -# # for presence on the TransactionNode - -# attrs = {} -# for attr in transaction.user_attributes: -# attrs[attr.name] = attr.value - -# for name, value in required_params: -# assert name in attrs, "name=%r, params=%r" % (name, attrs) -# assert attrs[name] == value, "name=%r, value=%r, params=%r" % (name, value, attrs) - -# for name, value in forgone_params: -# assert name not in attrs, "name=%r, params=%r" % (name, attrs) - -# return wrapped(*args, **kwargs) - -# return _validate_custom_parameters - - -# def validate_synthetics_event(required_attrs=None, forgone_attrs=None, should_exist=True): -# required_attrs = required_attrs or [] -# forgone_attrs = forgone_attrs or [] -# failed = [] - -# @transient_function_wrapper("newrelic.core.stats_engine", "StatsEngine.record_transaction") -# def _validate_synthetics_event(wrapped, instance, args, kwargs): -# result = wrapped(*args, **kwargs) - -# try: -# if not should_exist: -# assert instance.synthetics_events == [] -# else: -# assert len(instance.synthetics_events) == 1 -# event = instance.synthetics_events[0] -# assert event is not None -# assert len(event) == 3 - -# def _flatten(event): -# result = {} -# for elem in event: -# for k, v in elem.items(): -# result[k] = v -# return result - -# flat_event = _flatten(event) - -# assert "nr.guid" in flat_event, "name=%r, event=%r" % ("nr.guid", flat_event) - -# for name, value in required_attrs: -# assert name in flat_event, "name=%r, event=%r" % (name, flat_event) -# assert flat_event[name] == value, "name=%r, value=%r, event=%r" % (name, value, flat_event) - -# for name, value in forgone_attrs: -# assert name not in flat_event, "name=%r, value=%r, event=%r" % (name, value, flat_event) -# except Exception as e: -# failed.append(e) - -# return result - -# @function_wrapper -# def wrapper(wrapped, instance, args, kwargs): -# _new_wrapper = _validate_synthetics_event(wrapped) -# result = _new_wrapper(*args, **kwargs) -# if failed: -# e = failed.pop() -# raise e -# return result - -# return wrapper - - -# def validate_transaction_event_attributes(required_params=None, forgone_params=None, exact_attrs=None, index=-1): -# required_params = required_params or {} -# forgone_params = forgone_params or {} -# exact_attrs = exact_attrs or {} - -# captured_events = [] - -# @transient_function_wrapper("newrelic.core.stats_engine", "StatsEngine.record_transaction") -# def _capture_transaction_events(wrapped, instance, args, kwargs): -# try: -# result = wrapped(*args, **kwargs) -# except: -# raise -# else: -# event_data = instance.transaction_events -# captured_events.append(event_data) -# return result - -# @function_wrapper -# def _validate_transaction_event_attributes(wrapped, instance, args, kwargs): -# _new_wrapper = _capture_transaction_events(wrapped) -# result = _new_wrapper(*args, **kwargs) - -# assert captured_events, "No events captured" -# event_data = captured_events[index] -# captured_events[:] = [] - -# check_event_attributes(event_data, required_params, forgone_params, exact_attrs) - -# return result - -# return _validate_transaction_event_attributes - - def check_event_attributes(event_data, required_params=None, forgone_params=None, exact_attrs=None): """Check the event attributes from a single (first) event in a SampledDataSet. If necessary, clear out previous errors from StatsEngine @@ -890,58 +444,6 @@ def check_event_attributes(event_data, required_params=None, forgone_params=None assert intrinsics[param] == value, ((param, value), intrinsics) -# def validate_non_transaction_error_event(required_intrinsics=None, num_errors=1, required_user=None, forgone_user=None): -# """Validate error event data for a single error occurring outside of a -# transaction. -# """ -# required_intrinsics = required_intrinsics or {} -# required_user = required_user or {} -# forgone_user = forgone_user or [] - -# @function_wrapper -# def _validate_non_transaction_error_event(wrapped, instace, args, kwargs): - -# try: -# result = wrapped(*args, **kwargs) -# except: -# raise -# else: - -# stats = core_application_stats_engine(None) - -# assert stats.error_events.num_seen == num_errors -# for event in stats.error_events: - -# assert len(event) == 3 # [intrinsic, user, agent attributes] - -# intrinsics = event[0] - -# # The following attributes are all required, and also the only -# # intrinsic attributes that can be included in an error event -# # recorded outside of a transaction - -# assert intrinsics["type"] == "TransactionError" -# assert intrinsics["transactionName"] is None -# assert intrinsics["error.class"] == required_intrinsics["error.class"] -# assert intrinsics["error.message"].startswith(required_intrinsics["error.message"]) -# assert intrinsics["error.expected"] == required_intrinsics["error.expected"] -# now = time.time() -# assert isinstance(intrinsics["timestamp"], int) -# assert intrinsics["timestamp"] <= 1000.0 * now - -# user_params = event[1] -# for name, value in required_user.items(): -# assert name in user_params, "name=%r, params=%r" % (name, user_params) -# assert user_params[name] == value, "name=%r, value=%r, params=%r" % (name, value, user_params) - -# for param in forgone_user: -# assert param not in user_params - -# return result - -# return _validate_non_transaction_error_event - - def validate_application_error_trace_count(num_errors): """Validate error event data for a single error occurring outside of a transaction.