From 61e2b9adaf5ea413fbfc00642b7f186d5adc4e34 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Tue, 9 Sep 2025 12:53:56 -0700 Subject: [PATCH 01/95] Remove cross_application_tracer.enabled setting --- newrelic/api/cat_header_mixin.py | 74 +++--- newrelic/api/message_transaction.py | 8 +- newrelic/api/transaction.py | 117 +++++----- newrelic/config.py | 18 +- newrelic/core/agent_protocol.py | 2 +- newrelic/core/config.py | 8 +- newrelic/hooks/application_celery.py | 20 +- tests/agent_features/test_cat.py | 102 --------- tests/agent_features/test_serverless_mode.py | 2 +- tests/agent_unittests/test_agent_protocol.py | 4 +- tests/cross_agent/test_cat_map.py | 211 ------------------ 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 | 160 ++++++------- tests/external_requests/test_requests.py | 2 +- tests/external_urllib3/test_urllib3.py | 2 +- tests/framework_aiohttp/test_client_cat.py | 36 +-- tests/framework_aiohttp/test_server_cat.py | 2 +- .../framework_sanic/test_cross_application.py | 2 +- tests/framework_tornado/test_externals.py | 14 +- tests/framework_tornado/test_inbound_cat.py | 2 +- .../test_distributed_tracing.py | 2 +- tests/messagebroker_pika/test_pika_produce.py | 2 +- 24 files changed, 242 insertions(+), 554 deletions(-) delete mode 100644 tests/agent_features/test_cat.py delete mode 100644 tests/cross_agent/test_cat_map.py diff --git a/newrelic/api/cat_header_mixin.py b/newrelic/api/cat_header_mixin.py index f4a3e02bc9..b905f9dc80 100644 --- a/newrelic/api/cat_header_mixin.py +++ b/newrelic/api/cat_header_mixin.py @@ -15,7 +15,7 @@ from newrelic.common.encoding_utils import ( base64_decode, base64_encode, - deobfuscate, + # deobfuscate, json_decode, json_encode, obfuscate, @@ -39,35 +39,35 @@ def __enter__(self): self.settings = self.transaction.settings or None return result - def process_response_headers(self, response_headers): - """ - Decode the response headers and create appropriate metrics based on the - header values. The response_headers are passed in as a list of tuples. - [(HEADER_NAME0, HEADER_VALUE0), (HEADER_NAME1, HEADER_VALUE1)] + # def process_response_headers(self, response_headers): + # """ + # Decode the response headers and create appropriate metrics based on the + # header values. The response_headers are passed in as a list of tuples. + # [(HEADER_NAME0, HEADER_VALUE0), (HEADER_NAME1, HEADER_VALUE1)] - """ + # """ - settings = self.settings - if not settings: - return + # settings = self.settings + # if not settings: + # return - if not settings.cross_application_tracer.enabled: - return + # if not settings.cross_application_tracer.enabled: + # return - appdata = None - try: - for k, v in response_headers: - if k.upper() == self.cat_appdata_key.upper(): - appdata = json_decode(deobfuscate(v, settings.encoding_key)) - break + # appdata = None + # try: + # for k, v in response_headers: + # if k.upper() == self.cat_appdata_key.upper(): + # appdata = json_decode(deobfuscate(v, settings.encoding_key)) + # break - if appdata: - self.params["cross_process_id"] = appdata[0] - self.params["external_txn_name"] = appdata[1] - self.params["transaction_guid"] = appdata[5] + # if appdata: + # self.params["cross_process_id"] = appdata[0] + # self.params["external_txn_name"] = appdata[1] + # self.params["transaction_guid"] = appdata[5] - except Exception: - pass + # except Exception: + # pass def process_response_metadata(self, cat_linking_value): payload = base64_decode(cat_linking_value) @@ -92,19 +92,19 @@ def generate_request_headers(cls, transaction): if settings.distributed_tracing.enabled: transaction.insert_distributed_trace_headers(nr_headers) - elif settings.cross_application_tracer.enabled: - transaction.is_part_of_cat = True - path_hash = transaction.path_hash - if path_hash is None: - # Disable cat if path_hash fails to generate. - transaction.is_part_of_cat = False - else: - encoded_cross_process_id = obfuscate(settings.cross_process_id, settings.encoding_key) - nr_headers.append((cls.cat_id_key, encoded_cross_process_id)) - - transaction_data = [transaction.guid, transaction.record_tt, transaction.trip_id, path_hash] - encoded_transaction = obfuscate(json_encode(transaction_data), settings.encoding_key) - nr_headers.append((cls.cat_transaction_key, encoded_transaction)) + # elif settings.cross_application_tracer.enabled: + # transaction.is_part_of_cat = True + # path_hash = transaction.path_hash + # if path_hash is None: + # # Disable cat if path_hash fails to generate. + # transaction.is_part_of_cat = False + # else: + # encoded_cross_process_id = obfuscate(settings.cross_process_id, settings.encoding_key) + # nr_headers.append((cls.cat_id_key, encoded_cross_process_id)) + + # transaction_data = [transaction.guid, transaction.record_tt, transaction.trip_id, path_hash] + # encoded_transaction = obfuscate(json_encode(transaction_data), settings.encoding_key) + # nr_headers.append((cls.cat_transaction_key, encoded_transaction)) if transaction.synthetics_header: nr_headers.append((cls.cat_synthetics_key, transaction.synthetics_header)) diff --git a/newrelic/api/message_transaction.py b/newrelic/api/message_transaction.py index 0c94b83fbb..f37bdf8070 100644 --- a/newrelic/api/message_transaction.py +++ b/newrelic/api/message_transaction.py @@ -47,10 +47,10 @@ def __init__( if headers is not None and self.settings is not None: if self.settings.distributed_tracing.enabled: self.accept_distributed_trace_headers(headers, transport_type=transport_type) - elif self.settings.cross_application_tracer.enabled: - self._process_incoming_cat_headers( - headers.pop(MessageTrace.cat_id_key, None), headers.pop(MessageTrace.cat_transaction_key, None) - ) + # elif self.settings.cross_application_tracer.enabled: + # self._process_incoming_cat_headers( + # headers.pop(MessageTrace.cat_id_key, None), headers.pop(MessageTrace.cat_transaction_key, None) + # ) self.routing_key = routing_key self.exchange_type = exchange_type diff --git a/newrelic/api/transaction.py b/newrelic/api/transaction.py index b163ff54fd..5a904d2365 100644 --- a/newrelic/api/transaction.py +++ b/newrelic/api/transaction.py @@ -1343,64 +1343,65 @@ def accept_distributed_trace_headers(self, headers, transport_type="HTTP"): # metric for the lack of payload/distributed_header self._accept_distributed_trace_payload(distributed_header, transport_type) - def _process_incoming_cat_headers(self, encoded_cross_process_id, encoded_txn_header): - settings = self._settings - - if not self.enabled: - return - - if not ( - settings.cross_application_tracer.enabled - and settings.cross_process_id - and settings.trusted_account_ids - and settings.encoding_key - ): - return - - if encoded_cross_process_id is None: - return - - try: - client_cross_process_id = deobfuscate(encoded_cross_process_id, settings.encoding_key) - - # The cross process ID consists of the client - # account ID and the ID of the specific application - # the client is recording requests against. We need - # to validate that the client account ID is in the - # list of trusted account IDs and ignore it if it - # isn't. The trusted account IDs list has the - # account IDs as integers, so save the client ones - # away as integers here so easier to compare later. - - client_account_id, client_application_id = map(int, client_cross_process_id.split("#")) - - if client_account_id not in settings.trusted_account_ids: - return - - self.client_cross_process_id = client_cross_process_id - self.client_account_id = client_account_id - self.client_application_id = client_application_id - - txn_header = json_decode(deobfuscate(encoded_txn_header, settings.encoding_key)) - - if txn_header: - self.is_part_of_cat = True - self.referring_transaction_guid = txn_header[0] - - # Incoming record_tt is OR'd with existing - # record_tt. In the scenario where we make multiple - # ext request, this will ensure we don't set the - # record_tt to False by a later request if it was - # set to True by an earlier request. - - self.record_tt = self.record_tt or txn_header[1] - - if isinstance(txn_header[2], str): - self._trip_id = txn_header[2] - if isinstance(txn_header[3], str): - self._referring_path_hash = txn_header[3] - except Exception: - pass + # def _process_incoming_cat_headers(self, encoded_cross_process_id, encoded_txn_header): + # settings = self._settings + + # if not self.enabled: + # return + + # If CAT is disabled, function will exit early. + # if not ( + # settings.cross_application_tracer.enabled + # and settings.cross_process_id + # and settings.trusted_account_ids + # and settings.encoding_key + # ): + # return + + # if encoded_cross_process_id is None: + # return + + # try: + # client_cross_process_id = deobfuscate(encoded_cross_process_id, settings.encoding_key) + + # # The cross process ID consists of the client + # # account ID and the ID of the specific application + # # the client is recording requests against. We need + # # to validate that the client account ID is in the + # # list of trusted account IDs and ignore it if it + # # isn't. The trusted account IDs list has the + # # account IDs as integers, so save the client ones + # # away as integers here so easier to compare later. + + # client_account_id, client_application_id = map(int, client_cross_process_id.split("#")) + + # if client_account_id not in settings.trusted_account_ids: + # return + + # self.client_cross_process_id = client_cross_process_id + # self.client_account_id = client_account_id + # self.client_application_id = client_application_id + + # txn_header = json_decode(deobfuscate(encoded_txn_header, settings.encoding_key)) + + # if txn_header: + # self.is_part_of_cat = True + # self.referring_transaction_guid = txn_header[0] + + # # Incoming record_tt is OR'd with existing + # # record_tt. In the scenario where we make multiple + # # ext request, this will ensure we don't set the + # # record_tt to False by a later request if it was + # # set to True by an earlier request. + + # self.record_tt = self.record_tt or txn_header[1] + + # if isinstance(txn_header[2], str): + # self._trip_id = txn_header[2] + # if isinstance(txn_header[3], str): + # self._referring_path_hash = txn_header[3] + # except Exception: + # pass def _generate_response_headers(self, read_length=None): nr_headers = [] diff --git a/newrelic/config.py b/newrelic/config.py index 5cbd233862..2d60f8df14 100644 --- a/newrelic/config.py +++ b/newrelic/config.py @@ -450,7 +450,7 @@ def _process_configuration(section): _process_setting(section, "debug.disable_harvest_until_shutdown", "getboolean", None) _process_setting(section, "debug.connect_span_stream_in_developer_mode", "getboolean", None) _process_setting(section, "debug.otlp_content_encoding", "get", None) - _process_setting(section, "cross_application_tracer.enabled", "getboolean", None) + # _process_setting(section, "cross_application_tracer.enabled", "getboolean", None) _process_setting(section, "message_tracer.segment_parameters_enabled", "getboolean", None) _process_setting(section, "process_host.display_name", "get", None) _process_setting(section, "utilization.detect_aws", "getboolean", None) @@ -701,14 +701,14 @@ def translate_deprecated_settings(settings, cached_settings): "attributes.exclude." ) - if "cross_application_tracer.enabled" in cached: - # CAT Deprecation Warning - _logger.info( - "Deprecated setting found: cross_application_tracer.enabled. Please replace Cross Application Tracing " - "(CAT) with the newer Distributed Tracing by setting 'distributed_tracing.enabled' to True in your agent " - "configuration. For further details on distributed tracing, please refer to our documentation: " - "https://docs.newrelic.com/docs/distributed-tracing/concepts/distributed-tracing-planning-guide/#changes." - ) + # if "cross_application_tracer.enabled" in cached: + # # CAT Deprecation Warning + # _logger.info( + # "Deprecated setting found: cross_application_tracer.enabled. Please replace Cross Application Tracing " + # "(CAT) with the newer Distributed Tracing by setting 'distributed_tracing.enabled' to True in your agent " + # "configuration. For further details on distributed tracing, please refer to our documentation: " + # "https://docs.newrelic.com/docs/distributed-tracing/concepts/distributed-tracing-planning-guide/#changes." + # ) return settings diff --git a/newrelic/core/agent_protocol.py b/newrelic/core/agent_protocol.py index de0cab678b..7570dd00e2 100644 --- a/newrelic/core/agent_protocol.py +++ b/newrelic/core/agent_protocol.py @@ -522,7 +522,7 @@ def finalize(self): @classmethod def connect(cls, app_name, linked_applications, environment, settings, client_cls=ServerlessModeClient): aws_lambda_metadata = settings.aws_lambda_metadata - settings = finalize_application_settings({"cross_application_tracer.enabled": False}, settings) + # settings = finalize_application_settings({"cross_application_tracer.enabled": False}, settings) # Metadata must come from the original settings object since it # can be modified later settings.aws_lambda_metadata = aws_lambda_metadata diff --git a/newrelic/core/config.py b/newrelic/core/config.py index 39f9f3f55a..83e18bb250 100644 --- a/newrelic/core/config.py +++ b/newrelic/core/config.py @@ -256,8 +256,8 @@ class DebugSettings(Settings): pass -class CrossApplicationTracerSettings(Settings): - pass +# class CrossApplicationTracerSettings(Settings): +# pass class TransactionEventsSettings(Settings): @@ -497,7 +497,7 @@ class EventHarvestConfigHarvestLimitSettings(Settings): _settings.browser_monitoring.attributes = BrowserMonitorAttributesSettings() _settings.code_level_metrics = CodeLevelMetricsSettings() _settings.console = ConsoleSettings() -_settings.cross_application_tracer = CrossApplicationTracerSettings() +# _settings.cross_application_tracer = CrossApplicationTracerSettings() _settings.custom_insights_events = CustomInsightsEventsSettings() _settings.ml_insights_events = MlInsightsEventsSettings() _settings.datastore_tracer = DatastoreTracerSettings() @@ -808,7 +808,7 @@ def default_otlp_host(host): _settings.attributes.include = [] _settings.thread_profiler.enabled = True -_settings.cross_application_tracer.enabled = False +# _settings.cross_application_tracer.enabled = False _settings.gc_runtime_metrics.enabled = _environ_as_bool("NEW_RELIC_GC_RUNTIME_METRICS_ENABLED", default=False) _settings.gc_runtime_metrics.top_object_count_limit = 5 diff --git a/newrelic/hooks/application_celery.py b/newrelic/hooks/application_celery.py index e5856141f0..6f25bbbf57 100644 --- a/newrelic/hooks/application_celery.py +++ b/newrelic/hooks/application_celery.py @@ -127,11 +127,11 @@ def wrapper(wrapped, instance, args, kwargs): headers.update(dict(dt_headers)) except Exception: pass - elif transaction.settings.cross_application_tracer.enabled: - transaction._process_incoming_cat_headers( - headers.get(MessageTrace.cat_id_key, None), - headers.get(MessageTrace.cat_transaction_key, None), - ) + # elif transaction.settings.cross_application_tracer.enabled: + # transaction._process_incoming_cat_headers( + # headers.get(MessageTrace.cat_id_key, None), + # headers.get(MessageTrace.cat_transaction_key, None), + # ) except Exception: pass @@ -247,11 +247,11 @@ def wrap_task_call(wrapped, instance, args, kwargs): headers.update(dict(dt_headers)) except Exception: pass - elif transaction.settings.cross_application_tracer.enabled: - transaction._process_incoming_cat_headers( - headers.get(MessageTrace.cat_id_key, None), - headers.get(MessageTrace.cat_transaction_key, None), - ) + # elif transaction.settings.cross_application_tracer.enabled: + # transaction._process_incoming_cat_headers( + # headers.get(MessageTrace.cat_id_key, None), + # headers.get(MessageTrace.cat_transaction_key, None), + # ) except Exception: pass diff --git a/tests/agent_features/test_cat.py b/tests/agent_features/test_cat.py deleted file mode 100644 index 41c7b0d6ae..0000000000 --- a/tests/agent_features/test_cat.py +++ /dev/null @@ -1,102 +0,0 @@ -# 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. - -""" -This file contains a special case test for CAT. Most CAT testing is found at -`tests/cross_agent/test_cat_map.py` and -`newrelic/api/tests/test_cross_process.py`. This test does not fit either of -those spaces, the former being reserved for cross agent testing and the latter -being a unittest for the `process_response` method. Since this is a more end to -end style test, it does not fit as a unittest. -""" - -import pytest -import webtest -from testing_support.fixtures import cat_enabled, make_cross_agent_headers, override_application_settings - -from newrelic.api.background_task import background_task -from newrelic.api.external_trace import ExternalTrace -from newrelic.api.wsgi_application import wsgi_application - -ENCODING_KEY = "1234567890123456789012345678901234567890" - - -@wsgi_application() -def target_wsgi_application(environ, start_response): - status_code = int(environ["PATH_INFO"].strip("/")) - status = f"{status_code} STATUS" - - if status_code == 304: - output = b"" - response_headers = [] - else: - output = b"hello world" - response_headers = [("Content-type", "text/html; charset=utf-8"), ("Content-Length", str(len(output)))] - start_response(status, response_headers) - - return [output] - - -test_application = webtest.TestApp(target_wsgi_application) - -_override_settings = { - "cross_process_id": "1#1", - "encoding_key": ENCODING_KEY, - "trusted_account_ids": [1], - "browser_monitoring.enabled": False, -} - -payload = ["b854df4feb2b1f06", False, "7e249074f277923d", "5d2957be"] - - -@cat_enabled -@override_application_settings(_override_settings) -def test_cat_disabled_browser_monitoring(): - headers = make_cross_agent_headers(payload, ENCODING_KEY, "1#1") - response = test_application.get("/200", headers=headers) - assert "X-NewRelic-App-Data" in response.headers - - -@override_application_settings(_override_settings) -def test_cat_insertion_disabled_on_304(): - headers = make_cross_agent_headers(payload, ENCODING_KEY, "1#1") - response = test_application.get("/304", headers=headers) - assert "X-NewRelic-App-Data" not in response.headers - - -_override_settings = {"cross_application_tracer.enabled": True, "distributed_tracing.enabled": False} - - -@cat_enabled -@override_application_settings(_override_settings) -@pytest.mark.parametrize("fips_enabled", (False, True)) -@background_task() -def test_cat_fips_compliance(monkeypatch, fips_enabled): - # Set md5 to raise a ValueError to simulate FIPS compliance issues. - def md5_crash(*args, **kwargs): - raise ValueError - - if fips_enabled: - # monkeypatch.setattr("hashlib.md5", md5_crash) - import hashlib - - monkeypatch.setattr(hashlib, "md5", md5_crash) - - # Generate and send request using actual transaction api instead of fixture. - # Otherwise the proper code paths are not exercised. - with ExternalTrace("cat_test", "http://localhost/200") as tracer: - headers = tracer.generate_request_headers(tracer.transaction) - - expected = not fips_enabled # Invert to make more human readable - assert ("X-NewRelic-Transaction" in dict(headers)) == expected diff --git a/tests/agent_features/test_serverless_mode.py b/tests/agent_features/test_serverless_mode.py index 9c705c5c24..8a05db6fe1 100644 --- a/tests/agent_features/test_serverless_mode.py +++ b/tests/agent_features/test_serverless_mode.py @@ -78,7 +78,7 @@ def _test_cat_headers(): with trace: trace.process_response_headers(response_headers) - assert transaction.settings.cross_application_tracer.enabled is False + # assert transaction.settings.cross_application_tracer.enabled is False _test_cat_headers() diff --git a/tests/agent_unittests/test_agent_protocol.py b/tests/agent_unittests/test_agent_protocol.py index f87f48f7f6..590cad66f8 100644 --- a/tests/agent_unittests/test_agent_protocol.py +++ b/tests/agent_unittests/test_agent_protocol.py @@ -488,8 +488,8 @@ def test_serverless_protocol_connect(): # No client calls should be made assert len(HttpClientRecorder.SENT) == 0 - # cross application tracing must be disabled - assert not protocol.configuration.cross_application_tracer.enabled + # # cross application tracing must be disabled + # assert not protocol.configuration.cross_application_tracer.enabled def test_serverless_protocol_finalize(capsys): diff --git a/tests/cross_agent/test_cat_map.py b/tests/cross_agent/test_cat_map.py deleted file mode 100644 index 01ede0b19a..0000000000 --- a/tests/cross_agent/test_cat_map.py +++ /dev/null @@ -1,211 +0,0 @@ -# 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. - -""" -This is an implementation of the cross agent tests for cat map using a wsgi -application. Another implementation of these tests using a tornado application -can be found in test/framework_tornado_r3/test_cat_map.py -""" - -import json -from pathlib import Path -from urllib.request import urlopen - -import pytest -import webtest -from testing_support.fixtures import ( - make_cross_agent_headers, - override_application_name, - override_application_settings, - validate_analytics_catmap_data, -) -from testing_support.mock_external_http_server import MockExternalHTTPHResponseHeadersServer -from testing_support.validators.validate_tt_parameters import validate_tt_parameters - -from newrelic.api.external_trace import ExternalTrace -from newrelic.api.transaction import ( - current_transaction, - get_browser_timing_header, - set_background_task, - set_transaction_name, -) -from newrelic.api.wsgi_application import wsgi_application -from newrelic.common.encoding_utils import json_encode, obfuscate - -ENCODING_KEY = "1234567890123456789012345678901234567890" -FIXTURE = Path(__file__).parent / "fixtures" / "cat_map.json" -OUTBOUD_REQUESTS = {} - -_parameters_list = [ - "name", - "appName", - "transactionName", - "transactionGuid", - "inboundPayload", - "outboundRequests", - "expectedIntrinsicFields", - "nonExpectedIntrinsicFields", -] - - -@pytest.fixture(scope="module") -def server(): - with MockExternalHTTPHResponseHeadersServer() as _server: - yield _server - - -def load_tests(): - result = [] - with FIXTURE.open() as fh: - tests = json.load(fh) - - for test in tests: - values = tuple([test.get(param, None) for param in _parameters_list]) - result.append(values) - - return result - - -_parameters = ",".join(_parameters_list) - - -@wsgi_application() -def target_wsgi_application(environ, start_response): - status = "200 OK" - - txn_name = environ.get("txn").split("/", 3) - - guid = environ.get("guid") - old_cat = environ.get("old_cat") == "True" - txn = current_transaction() - - txn.guid = guid - for req in OUTBOUD_REQUESTS: - # Change the transaction name before making an outbound call. - outgoing_name = req["outboundTxnName"].split("/", 3) - if outgoing_name[0] != "WebTransaction": - set_background_task(True) - - set_transaction_name(outgoing_name[2], group=outgoing_name[1]) - - expected_outbound_header = obfuscate(json_encode(req["expectedOutboundPayload"]), ENCODING_KEY) - generated_outbound_header = dict(ExternalTrace.generate_request_headers(txn)) - - # A 500 error is returned because 'assert' statements in the wsgi app - # are ignored. - - if old_cat: - if expected_outbound_header != generated_outbound_header["X-NewRelic-Transaction"]: - status = "500 Outbound Headers Check Failed." - else: - if "X-NewRelic-Transaction" in generated_outbound_header: - status = "500 Outbound Headers Check Failed." - r = urlopen(environ["server_url"]) - r.read(10) - - # Set the final transaction name. - - if txn_name[0] != "WebTransaction": - set_background_task(True) - set_transaction_name(txn_name[2], group=txn_name[1]) - - text = "%s

RESPONSE

" - - output = (text % get_browser_timing_header()).encode("UTF-8") - - response_headers = [("Content-type", "text/html; charset=utf-8"), ("Content-Length", str(len(output)))] - start_response(status, response_headers) - - return [output] - - -target_application = webtest.TestApp(target_wsgi_application) - - -@pytest.mark.parametrize(_parameters, load_tests()) -@pytest.mark.parametrize("old_cat", (True, False)) -def test_cat_map( - name, - appName, - transactionName, - transactionGuid, - inboundPayload, - outboundRequests, - expectedIntrinsicFields, - nonExpectedIntrinsicFields, - old_cat, - server, -): - global OUTBOUD_REQUESTS - OUTBOUD_REQUESTS = outboundRequests or {} - - _custom_settings = { - "cross_process_id": "1#1", - "encoding_key": ENCODING_KEY, - "trusted_account_ids": [1], - "cross_application_tracer.enabled": True, - "distributed_tracing.enabled": not old_cat, - "transaction_tracer.transaction_threshold": 0.0, - } - - if expectedIntrinsicFields and old_cat: - _external_node_params = { - "path_hash": expectedIntrinsicFields["nr.pathHash"], - "trip_id": expectedIntrinsicFields["nr.tripId"], - } - else: - _external_node_params = [] - - if not old_cat: - # since no better cat headers will be generated, no intrinsics should - # be added - expectedIntrinsicFields = {} - - @validate_tt_parameters(required_params=_external_node_params) - @validate_analytics_catmap_data( - transactionName, expected_attributes=expectedIntrinsicFields, non_expected_attributes=nonExpectedIntrinsicFields - ) - @override_application_settings(_custom_settings) - @override_application_name(appName) - def run_cat_test(): - txn_name = transactionName - guid = transactionGuid - - # Only generate old cat style headers. This will test to make sure we - # are properly ignoring these headers when the agent is using better - # cat. - - headers = make_cross_agent_headers(inboundPayload, ENCODING_KEY, "1#1") - response = target_application.get( - "/", - headers=headers, - extra_environ={ - "txn": txn_name, - "guid": guid, - "old_cat": str(old_cat), - "server_url": f"http://localhost:{server.port}", - }, - ) - - # Validation of analytic data happens in the decorator. - - assert response.status == "200 OK" - - content = response.html.html.body.p.string - - # Validate actual body content as sanity check. - - assert content == "RESPONSE" - - run_cat_test() diff --git a/tests/external_http/test_http.py b/tests/external_http/test_http.py index 590e659600..f7c43343fc 100644 --- a/tests/external_http/test_http.py +++ b/tests/external_http/test_http.py @@ -86,7 +86,7 @@ def _test(): _test = override_application_settings( { "distributed_tracing.enabled": distributed_tracing, - "cross_application_tracer.enabled": not distributed_tracing, + # "cross_application_tracer.enabled": not distributed_tracing, "span_events.enabled": span_events, } )(_test) diff --git a/tests/external_httplib/test_httplib.py b/tests/external_httplib/test_httplib.py index 64b7c94f77..8afd178bd9 100644 --- a/tests/external_httplib/test_httplib.py +++ b/tests/external_httplib/test_httplib.py @@ -124,7 +124,7 @@ def _test(): _test = override_application_settings( { "distributed_tracing.enabled": distributed_tracing, - "cross_application_tracer.enabled": not distributed_tracing, + # "cross_application_tracer.enabled": not distributed_tracing, "span_events.enabled": span_events, } )(_test) diff --git a/tests/external_httplib2/test_httplib2.py b/tests/external_httplib2/test_httplib2.py index 19edf44028..e3dc7d3fa6 100644 --- a/tests/external_httplib2/test_httplib2.py +++ b/tests/external_httplib2/test_httplib2.py @@ -104,7 +104,7 @@ def _test(): _test = override_application_settings( { "distributed_tracing.enabled": distributed_tracing, - "cross_application_tracer.enabled": not distributed_tracing, + # "cross_application_tracer.enabled": not distributed_tracing, "span_events.enabled": span_events, } )(_test) diff --git a/tests/external_httpx/test_client.py b/tests/external_httpx/test_client.py index 6f442fb87d..a3b1d080f9 100644 --- a/tests/external_httpx/test_client.py +++ b/tests/external_httpx/test_client.py @@ -124,7 +124,7 @@ def test_sync_cross_process_request(httpx, sync_client, mock_server, distributed { "distributed_tracing.enabled": distributed_tracing, "span_events.enabled": span_events, - "cross_application_tracer.enabled": not distributed_tracing, + # "cross_application_tracer.enabled": not distributed_tracing, } ) @validate_transaction_errors(errors=[]) @@ -206,85 +206,85 @@ async def _test(): assert response.request.headers["newrelic"] == "1234" -@pytest.mark.parametrize("cat_enabled", [True, False]) -@pytest.mark.parametrize("response_code", [200, 500]) -def test_sync_client_cat_response_processing(cat_enabled, response_code, sync_client, mock_server, httpx): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = response_code - - _custom_settings = { - "cross_process_id": "1#1", - "encoding_key": ENCODING_KEY, - "trusted_account_ids": [1], - "cross_application_tracer.enabled": cat_enabled, - "distributed_tracing.enabled": False, - "transaction_tracer.transaction_threshold": 0.0, - } - - expected_metrics = [ - ( - f"ExternalTransaction/localhost:{mock_server.port}/1#1/WebTransaction/Function/app:beep", - 1 if cat_enabled else None, - ) - ] - - @validate_transaction_metrics( - "test_sync_client_cat_response_processing", - background_task=True, - rollup_metrics=expected_metrics, - scoped_metrics=expected_metrics, - ) - @validate_tt_segment_params(exact_params={"http.statusCode": response_code}) - @override_application_settings(_custom_settings) - @background_task(name="test_sync_client_cat_response_processing") - def _test(): - with sync_client: - response = sync_client.get(f"http://localhost:{mock_server.port}") - - _test() - - -@pytest.mark.parametrize("cat_enabled", [True, False]) -@pytest.mark.parametrize("response_code", [200, 500]) -def test_async_client_cat_response_processing(cat_enabled, response_code, httpx, async_client, mock_server, loop): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = response_code - - _custom_settings = { - "cross_process_id": "1#1", - "encoding_key": ENCODING_KEY, - "trusted_account_ids": [1], - "cross_application_tracer.enabled": cat_enabled, - "distributed_tracing.enabled": False, - "transaction_tracer.transaction_threshold": 0.0, - } - - expected_metrics = [ - ( - f"ExternalTransaction/localhost:{mock_server.port}/1#1/WebTransaction/Function/app:beep", - 1 if cat_enabled else None, - ) - ] - - @validate_transaction_metrics( - "test_async_client_cat_response_processing", - background_task=True, - rollup_metrics=expected_metrics, - scoped_metrics=expected_metrics, - ) - @validate_tt_segment_params(exact_params={"http.statusCode": response_code}) - @override_application_settings(_custom_settings) - @background_task(name="test_async_client_cat_response_processing") - def _test(): - async def coro(): - async with async_client: - response = await async_client.get(f"http://localhost:{mock_server.port}") - - return response - - response = loop.run_until_complete(coro()) - - _test() +# @pytest.mark.parametrize("cat_enabled", [True, False]) +# @pytest.mark.parametrize("response_code", [200, 500]) +# def test_sync_client_cat_response_processing(cat_enabled, response_code, sync_client, mock_server, httpx): +# global CAT_RESPONSE_CODE +# CAT_RESPONSE_CODE = response_code + +# _custom_settings = { +# "cross_process_id": "1#1", +# "encoding_key": ENCODING_KEY, +# "trusted_account_ids": [1], +# "cross_application_tracer.enabled": cat_enabled, +# "distributed_tracing.enabled": False, +# "transaction_tracer.transaction_threshold": 0.0, +# } + +# expected_metrics = [ +# ( +# f"ExternalTransaction/localhost:{mock_server.port}/1#1/WebTransaction/Function/app:beep", +# 1 if cat_enabled else None, +# ) +# ] + +# @validate_transaction_metrics( +# "test_sync_client_cat_response_processing", +# background_task=True, +# rollup_metrics=expected_metrics, +# scoped_metrics=expected_metrics, +# ) +# @validate_tt_segment_params(exact_params={"http.statusCode": response_code}) +# @override_application_settings(_custom_settings) +# @background_task(name="test_sync_client_cat_response_processing") +# def _test(): +# with sync_client: +# response = sync_client.get(f"http://localhost:{mock_server.port}") + +# _test() + + +# @pytest.mark.parametrize("cat_enabled", [True, False]) +# @pytest.mark.parametrize("response_code", [200, 500]) +# def test_async_client_cat_response_processing(cat_enabled, response_code, httpx, async_client, mock_server, loop): +# global CAT_RESPONSE_CODE +# CAT_RESPONSE_CODE = response_code + +# _custom_settings = { +# "cross_process_id": "1#1", +# "encoding_key": ENCODING_KEY, +# "trusted_account_ids": [1], +# "cross_application_tracer.enabled": cat_enabled, +# "distributed_tracing.enabled": False, +# "transaction_tracer.transaction_threshold": 0.0, +# } + +# expected_metrics = [ +# ( +# f"ExternalTransaction/localhost:{mock_server.port}/1#1/WebTransaction/Function/app:beep", +# 1 if cat_enabled else None, +# ) +# ] + +# @validate_transaction_metrics( +# "test_async_client_cat_response_processing", +# background_task=True, +# rollup_metrics=expected_metrics, +# scoped_metrics=expected_metrics, +# ) +# @validate_tt_segment_params(exact_params={"http.statusCode": response_code}) +# @override_application_settings(_custom_settings) +# @background_task(name="test_async_client_cat_response_processing") +# def _test(): +# async def coro(): +# async with async_client: +# response = await async_client.get(f"http://localhost:{mock_server.port}") + +# return response + +# response = loop.run_until_complete(coro()) + +# _test() @dt_enabled diff --git a/tests/external_requests/test_requests.py b/tests/external_requests/test_requests.py index bb67691451..e98d37fec2 100644 --- a/tests/external_requests/test_requests.py +++ b/tests/external_requests/test_requests.py @@ -167,7 +167,7 @@ def _test(): _test = override_application_settings( { "distributed_tracing.enabled": distributed_tracing, - "cross_application_tracer.enabled": not distributed_tracing, + # "cross_application_tracer.enabled": not distributed_tracing, "span_events.enabled": span_events, } )(_test) diff --git a/tests/external_urllib3/test_urllib3.py b/tests/external_urllib3/test_urllib3.py index 6827fcf4cc..6328a2510f 100644 --- a/tests/external_urllib3/test_urllib3.py +++ b/tests/external_urllib3/test_urllib3.py @@ -216,7 +216,7 @@ def _test(): _test = override_application_settings( { "distributed_tracing.enabled": distributed_tracing, - "cross_application_tracer.enabled": not distributed_tracing, + # "cross_application_tracer.enabled": not distributed_tracing, "span_events.enabled": span_events, } )(_test) diff --git a/tests/framework_aiohttp/test_client_cat.py b/tests/framework_aiohttp/test_client_cat.py index bbba2f88b9..61a73d96aa 100644 --- a/tests/framework_aiohttp/test_client_cat.py +++ b/tests/framework_aiohttp/test_client_cat.py @@ -18,7 +18,7 @@ import pytest from testing_support.external_fixtures import create_incoming_headers from testing_support.fixtures import override_application_settings -from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers +# from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers from testing_support.validators.validate_external_node_params import validate_external_node_params from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics @@ -64,10 +64,11 @@ async def fetch(url, headers=None, raise_for_status=False, connector=None): return headers -@pytest.mark.parametrize("cat_enabled", (True, False)) +# @pytest.mark.parametrize("cat_enabled", (True, False)) @pytest.mark.parametrize("distributed_tracing", (True, False)) @pytest.mark.parametrize("span_events", (True, False)) -def test_outbound_cross_process_headers(event_loop, cat_enabled, distributed_tracing, span_events, mock_header_server): +def test_outbound_cross_process_headers(event_loop, distributed_tracing, span_events, mock_header_server): +# def test_outbound_cross_process_headers(event_loop, cat_enabled, distributed_tracing, span_events, mock_header_server): @background_task(name="test_outbound_cross_process_headers") async def _test(): headers = await fetch(f"http://127.0.0.1:{mock_header_server.port}") @@ -77,9 +78,9 @@ async def _test(): if distributed_tracing: assert "newrelic" in headers - elif cat_enabled: - assert ExternalTrace.cat_id_key in headers - assert ExternalTrace.cat_transaction_key in headers + # elif cat_enabled: + # assert ExternalTrace.cat_id_key in headers + # assert ExternalTrace.cat_transaction_key in headers else: assert "newrelic" not in headers assert ExternalTrace.cat_id_key not in headers @@ -88,14 +89,14 @@ async def _test(): def _validate(): pass - if cat_enabled or distributed_tracing: - _validate = validate_cross_process_headers(_validate) + # if cat_enabled or distributed_tracing: + # _validate = validate_cross_process_headers(_validate) _validate() @override_application_settings( { - "cross_application_tracer.enabled": cat_enabled, + # "cross_application_tracer.enabled": cat_enabled, "distributed_tracing.enabled": distributed_tracing, "span_events.enabled": span_events, } @@ -155,12 +156,13 @@ async def _resolve_host(self, host, port, *args, **kwargs): return res -@pytest.mark.parametrize("cat_enabled", [True, False]) +# @pytest.mark.parametrize("cat_enabled", [True, False]) @pytest.mark.parametrize("response_code", [200, 404]) @pytest.mark.parametrize("raise_for_status", [True, False]) @pytest.mark.parametrize("connector_class", [None, PoorResolvingConnector]) # None will use default def test_process_incoming_headers( - event_loop, cat_enabled, response_code, raise_for_status, connector_class, mock_external_http_server + event_loop, response_code, raise_for_status, connector_class, mock_external_http_server + # event_loop, cat_enabled, response_code, raise_for_status, connector_class, mock_external_http_server ): # It was discovered via packnsend that the `throw` method of the `_request` # coroutine is used in the case of poorly resolved hosts. An older version @@ -174,15 +176,15 @@ def test_process_incoming_headers( port = server.port _test_cross_process_response_scoped_metrics = [ - (f"ExternalTransaction/127.0.0.1:{port}/1#2/test", 1 if cat_enabled else None) + (f"ExternalTransaction/127.0.0.1:{port}/1#2/test", None) ] _test_cross_process_response_rollup_metrics = [ ("External/all", 1), ("External/allOther", 1), (f"External/127.0.0.1:{port}/all", 1), - (f"ExternalApp/127.0.0.1:{port}/1#2/all", 1 if cat_enabled else None), - (f"ExternalTransaction/127.0.0.1:{port}/1#2/test", 1 if cat_enabled else None), + (f"ExternalApp/127.0.0.1:{port}/1#2/all", None), + (f"ExternalTransaction/127.0.0.1:{port}/1#2/test", None), ] _test_cross_process_response_external_node_params = [ @@ -207,7 +209,7 @@ async def _test(): await fetch(address, raise_for_status=raise_for_status, connector=connector) @override_application_settings( - {"cross_application_tracer.enabled": cat_enabled, "distributed_tracing.enabled": False} + {"distributed_tracing.enabled": False} ) @validate_transaction_metrics( "test_process_incoming_headers", @@ -216,8 +218,8 @@ async def _test(): background_task=True, ) @validate_external_node_params( - params=(_test_cross_process_response_external_node_params if cat_enabled else []), - forgone_params=([] if cat_enabled else _test_cross_process_response_external_node_forgone_params), + params=[], + forgone_params=_test_cross_process_response_external_node_forgone_params, ) def test(): event_loop.run_until_complete(_test()) diff --git a/tests/framework_aiohttp/test_server_cat.py b/tests/framework_aiohttp/test_server_cat.py index 5af4933ca3..3fc651ad19 100644 --- a/tests/framework_aiohttp/test_server_cat.py +++ b/tests/framework_aiohttp/test_server_cat.py @@ -118,7 +118,7 @@ async def fetch(): "cross_process_id": "1#1", "encoding_key": ENCODING_KEY, "trusted_account_ids": [1], - "cross_application_tracer.enabled": True, + # "cross_application_tracer.enabled": True, "distributed_tracing.enabled": False, } diff --git a/tests/framework_sanic/test_cross_application.py b/tests/framework_sanic/test_cross_application.py index a327166419..60e1980533 100644 --- a/tests/framework_sanic/test_cross_application.py +++ b/tests/framework_sanic/test_cross_application.py @@ -74,7 +74,7 @@ def test_inbound_distributed_trace(app): "cross_process_id": "1#1", "encoding_key": ENCODING_KEY, "trusted_account_ids": [1], - "cross_application_tracer.enabled": True, + # "cross_application_tracer.enabled": True, "distributed_tracing.enabled": False, } diff --git a/tests/framework_tornado/test_externals.py b/tests/framework_tornado/test_externals.py index fd40b9423f..40d71e9ab8 100644 --- a/tests/framework_tornado/test_externals.py +++ b/tests/framework_tornado/test_externals.py @@ -160,7 +160,7 @@ def test_httpclient( { "distributed_tracing.enabled": distributed_tracing, "span_events.enabled": span_events, - "cross_application_tracer.enabled": not distributed_tracing, + # "cross_application_tracer.enabled": not distributed_tracing, } ) @validate_transaction_metrics( @@ -243,11 +243,11 @@ def cat_response_server(): @pytest.mark.parametrize("client_class", ["AsyncHTTPClient", "CurlAsyncHTTPClient", "HTTPClient"]) -@pytest.mark.parametrize("cat_enabled", [True, False]) +@pytest.mark.parametrize("dt_enabled", [True, False]) @pytest.mark.parametrize("request_type", ["uri", "class"]) @pytest.mark.parametrize("response_code,raise_error", [(500, True), (500, False), (200, False)]) def test_client_cat_response_processing( - cat_enabled, request_type, client_class, raise_error, response_code, cat_response_server + dt_enabled, request_type, client_class, raise_error, response_code, cat_response_server ): global CAT_RESPONSE_CODE CAT_RESPONSE_CODE = response_code @@ -256,15 +256,13 @@ def test_client_cat_response_processing( "cross_process_id": "1#1", "encoding_key": ENCODING_KEY, "trusted_account_ids": [1], - "cross_application_tracer.enabled": cat_enabled, - "distributed_tracing.enabled": not cat_enabled, + # "cross_application_tracer.enabled": cat_enabled, + "distributed_tracing.enabled": dt_enabled, "transaction_tracer.transaction_threshold": 0.0, } port = cat_response_server.port - expected_metrics = [ - (f"ExternalTransaction/localhost:{port}/1#1/WebTransaction/Function/app:beep", 1 if cat_enabled else None) - ] + expected_metrics = None @validate_transaction_metrics( "make_request", background_task=True, rollup_metrics=expected_metrics, scoped_metrics=expected_metrics diff --git a/tests/framework_tornado/test_inbound_cat.py b/tests/framework_tornado/test_inbound_cat.py index a0773dcb5d..fb935f174a 100644 --- a/tests/framework_tornado/test_inbound_cat.py +++ b/tests/framework_tornado/test_inbound_cat.py @@ -26,7 +26,7 @@ "cross_process_id": "1#1", "encoding_key": ENCODING_KEY, "trusted_account_ids": [1], - "cross_application_tracer.enabled": True, + # "cross_application_tracer.enabled": True, "distributed_tracing.enabled": False, "transaction_tracer.transaction_threshold": 0.0, } diff --git a/tests/messagebroker_pika/test_distributed_tracing.py b/tests/messagebroker_pika/test_distributed_tracing.py index 472db1c0b2..ee8a643ced 100644 --- a/tests/messagebroker_pika/test_distributed_tracing.py +++ b/tests/messagebroker_pika/test_distributed_tracing.py @@ -31,7 +31,7 @@ "primary_application_id": "12345", "account_id": "33", "trusted_account_key": "1", - "cross_application_tracer.enabled": True, + # "cross_application_tracer.enabled": True, "distributed_tracing.enabled": True, } diff --git a/tests/messagebroker_pika/test_pika_produce.py b/tests/messagebroker_pika/test_pika_produce.py index 57605c6539..1d8a01c6ec 100644 --- a/tests/messagebroker_pika/test_pika_produce.py +++ b/tests/messagebroker_pika/test_pika_produce.py @@ -173,7 +173,7 @@ def test_blocking_connection_reply_to(producer): def test_blocking_connection_headers(enable_distributed_tracing): override_settings = { "distributed_tracing.enabled": enable_distributed_tracing, - "cross_application_tracer.enabled": not enable_distributed_tracing, + # "cross_application_tracer.enabled": not enable_distributed_tracing, } rollup_metrics = list(_test_blocking_connection_metrics) if enable_distributed_tracing: From e9bab5249cfbe9236c8770a4667f5ea0d56e5bdf Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Tue, 9 Sep 2025 13:00:22 -0700 Subject: [PATCH 02/95] Remove cat_enabled fixture --- .../test_attributes_in_action.py | 6 +-- tests/agent_features/test_error_events.py | 4 +- tests/agent_features/test_synthetics.py | 10 ++--- tests/external_http/test_http.py | 4 +- tests/external_httplib/test_httplib.py | 6 +-- tests/external_httplib/test_urllib.py | 6 +-- tests/external_httplib/test_urllib2.py | 4 +- tests/external_httplib2/test_httplib2.py | 4 +- tests/external_requests/test_requests.py | 4 +- tests/external_urllib3/test_urllib3.py | 4 +- .../test_client_async_await.py | 14 +++---- tests/framework_tornado/test_externals.py | 39 +++++++++---------- tests/messagebroker_pika/test_cat.py | 4 +- tests/testing_support/fixtures.py | 10 ++--- 14 files changed, 58 insertions(+), 61 deletions(-) diff --git a/tests/agent_features/test_attributes_in_action.py b/tests/agent_features/test_attributes_in_action.py index 0b24a3100a..954b477fda 100644 --- a/tests/agent_features/test_attributes_in_action.py +++ b/tests/agent_features/test_attributes_in_action.py @@ -15,7 +15,7 @@ import pytest import webtest from testing_support.fixtures import ( - cat_enabled, + # cat_enabled, dt_enabled, override_application_settings, reset_core_stats_engine, @@ -186,7 +186,7 @@ def normal_application(request): _expected_absent_attributes = {"agent": REQ_PARAMS, "user": [], "intrinsic": DISTRIBUTED_TRACE_ATTRS} -@cat_enabled +# @cat_enabled @validate_error_event_attributes(_expected_attributes_event, _expected_absent_attributes) @validate_transaction_error_trace_attributes(_expected_attributes, _expected_absent_attributes) def test_error_in_transaction_default_settings(normal_application): @@ -196,7 +196,7 @@ def test_error_in_transaction_default_settings(normal_application): _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} -@cat_enabled +# @cat_enabled @validate_transaction_trace_attributes(_expected_attributes, _expected_absent_attributes) @override_application_settings({}) def test_transaction_trace_default_attribute_settings(normal_application): diff --git a/tests/agent_features/test_error_events.py b/tests/agent_features/test_error_events.py index 30a89c9044..08195cf991 100644 --- a/tests/agent_features/test_error_events.py +++ b/tests/agent_features/test_error_events.py @@ -17,7 +17,7 @@ import webtest from testing_support.fixtures import ( - cat_enabled, + # cat_enabled, make_cross_agent_headers, make_synthetics_headers, override_application_settings, @@ -112,7 +112,7 @@ def test_transaction_error_background_task(): } -@cat_enabled +# @cat_enabled @validate_error_event_sample_data(required_attrs=_intrinsic_attributes, required_user_attrs=True) def test_transaction_error_cross_agent(): test_environ = {"err_message": ERR_MESSAGE} diff --git a/tests/agent_features/test_synthetics.py b/tests/agent_features/test_synthetics.py index f584a12237..a5916f7a42 100644 --- a/tests/agent_features/test_synthetics.py +++ b/tests/agent_features/test_synthetics.py @@ -15,7 +15,7 @@ import pytest import webtest from testing_support.external_fixtures import validate_synthetics_external_trace_header -from testing_support.fixtures import cat_enabled, make_synthetics_headers, override_application_settings +from testing_support.fixtures import make_synthetics_headers, override_application_settings from testing_support.validators.validate_synthetics_event import validate_synthetics_event from testing_support.validators.validate_synthetics_transaction_trace import validate_synthetics_transaction_trace @@ -187,7 +187,7 @@ def test_synthetics_event_mismatched_info_encoding_key(): } -@cat_enabled +# @cat_enabled @validate_synthetics_transaction_trace(_test_valid_synthetics_tt_required) @override_application_settings(_override_settings) def test_valid_synthetics_in_transaction_trace(): @@ -220,7 +220,7 @@ def test_synthetics_disabled(): _external_synthetics_info_header = _external_synthetics_headers["X-NewRelic-Synthetics-Info"] -@cat_enabled +# @cat_enabled @validate_synthetics_external_trace_header(_external_synthetics_header, _external_synthetics_info_header) @override_application_settings(_override_settings) def test_valid_synthetics_external_trace_header(): @@ -228,7 +228,7 @@ def test_valid_synthetics_external_trace_header(): response = target_application.get("/", headers=headers) -@cat_enabled +# @cat_enabled @validate_synthetics_external_trace_header(_external_synthetics_header, None) @override_application_settings(_override_settings) def test_valid_synthetics_external_trace_header_without_info(): @@ -236,7 +236,7 @@ def test_valid_synthetics_external_trace_header_without_info(): response = target_application.get("/", headers=headers) -@cat_enabled +# @cat_enabled @validate_synthetics_external_trace_header(_external_synthetics_header, _external_synthetics_info_header) @override_application_settings(_override_settings) def test_valid_external_trace_header_with_byte_inbound_header(): diff --git a/tests/external_http/test_http.py b/tests/external_http/test_http.py index f7c43343fc..74ab0833e6 100644 --- a/tests/external_http/test_http.py +++ b/tests/external_http/test_http.py @@ -16,7 +16,7 @@ import pytest from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers -from testing_support.fixtures import cat_enabled, override_application_settings +from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers from testing_support.validators.validate_external_node_params import validate_external_node_params from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics @@ -94,7 +94,7 @@ def _test(): _test() -@cat_enabled +# @cat_enabled def test_http_cross_process_response(server): _test_http_cross_process_response_scoped_metrics = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] diff --git a/tests/external_httplib/test_httplib.py b/tests/external_httplib/test_httplib.py index 8afd178bd9..46372adb1c 100644 --- a/tests/external_httplib/test_httplib.py +++ b/tests/external_httplib/test_httplib.py @@ -16,7 +16,7 @@ import pytest from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers -from testing_support.fixtures import cat_enabled, override_application_settings +from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers from testing_support.validators.validate_external_node_params import validate_external_node_params from testing_support.validators.validate_span_events import validate_span_events @@ -139,7 +139,7 @@ def _test(): ] -@cat_enabled +# @cat_enabled @insert_incoming_headers def test_httplib_cross_process_response(server): scoped = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] @@ -170,7 +170,7 @@ def _test(): _test() -@cat_enabled +# @cat_enabled def test_httplib_multiple_requests_cross_process_response(server): connection = httplib.HTTPConnection("localhost", server.port) diff --git a/tests/external_httplib/test_urllib.py b/tests/external_httplib/test_urllib.py index 8d9dd1820d..b0b9abb75b 100644 --- a/tests/external_httplib/test_urllib.py +++ b/tests/external_httplib/test_urllib.py @@ -22,7 +22,7 @@ import urllib from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers -from testing_support.fixtures import cat_enabled +# from testing_support.fixtures import cat_enabled from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers from testing_support.validators.validate_external_node_params import validate_external_node_params from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics @@ -131,7 +131,7 @@ def test_urlopener_cross_process_request(server): opener.open(f"http://localhost:{server.port}/") -@cat_enabled +# @cat_enabled def test_urlopener_cross_process_response(server): _test_urlopener_cross_process_response_scoped_metrics = [ (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) @@ -205,7 +205,7 @@ def test_urlretrieve_cross_process_request(server): urllib.urlretrieve(f"http://localhost:{server.port}/") -@cat_enabled +# @cat_enabled def test_urlretrieve_cross_process_response(server): _test_urlretrieve_cross_process_response_scoped_metrics = [ (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) diff --git a/tests/external_httplib/test_urllib2.py b/tests/external_httplib/test_urllib2.py index 54aeed7217..f18ca3de8c 100644 --- a/tests/external_httplib/test_urllib2.py +++ b/tests/external_httplib/test_urllib2.py @@ -17,7 +17,7 @@ import pytest from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers -from testing_support.fixtures import cat_enabled +# from testing_support.fixtures import cat_enabled from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers from testing_support.validators.validate_external_node_params import validate_external_node_params from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics @@ -121,7 +121,7 @@ def test_urlopen_cross_process_request(server): urllib2.urlopen(f"http://localhost:{server.port}/") -@cat_enabled +# @cat_enabled def test_urlopen_cross_process_response(server): _test_urlopen_cross_process_response_scoped_metrics = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] diff --git a/tests/external_httplib2/test_httplib2.py b/tests/external_httplib2/test_httplib2.py index e3dc7d3fa6..f4fa0e7c9b 100644 --- a/tests/external_httplib2/test_httplib2.py +++ b/tests/external_httplib2/test_httplib2.py @@ -15,7 +15,7 @@ import httplib2 import pytest from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers -from testing_support.fixtures import cat_enabled, override_application_settings +from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers from testing_support.validators.validate_external_node_params import validate_external_node_params from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics @@ -112,7 +112,7 @@ def _test(): _test() -@cat_enabled +# @cat_enabled def test_httplib2_cross_process_response(server): _test_httplib2_cross_process_response_scoped_metrics = [ (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) diff --git a/tests/external_requests/test_requests.py b/tests/external_requests/test_requests.py index e98d37fec2..b2d39e7289 100644 --- a/tests/external_requests/test_requests.py +++ b/tests/external_requests/test_requests.py @@ -16,7 +16,7 @@ import requests import requests.exceptions from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers -from testing_support.fixtures import cat_enabled, override_application_settings, validate_tt_parenting +from testing_support.fixtures import override_application_settings, validate_tt_parenting from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers from testing_support.validators.validate_external_node_params import validate_external_node_params from testing_support.validators.validate_transaction_errors import validate_transaction_errors @@ -175,7 +175,7 @@ def _test(): _test() -@cat_enabled +# @cat_enabled def test_requests_cross_process_response(server): _test_requests_cross_process_response_scoped_metrics = [ (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) diff --git a/tests/external_urllib3/test_urllib3.py b/tests/external_urllib3/test_urllib3.py index 6328a2510f..0669ab1b9d 100644 --- a/tests/external_urllib3/test_urllib3.py +++ b/tests/external_urllib3/test_urllib3.py @@ -22,7 +22,7 @@ pass from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers -from testing_support.fixtures import cat_enabled, override_application_settings +from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers from testing_support.validators.validate_external_node_params import validate_external_node_params from testing_support.validators.validate_transaction_errors import validate_transaction_errors @@ -224,7 +224,7 @@ def _test(): _test() -@cat_enabled +# @cat_enabled def test_urlopen_cross_process_response(server): _test_urlopen_cross_process_response_scoped_metrics = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] diff --git a/tests/framework_aiohttp/test_client_async_await.py b/tests/framework_aiohttp/test_client_async_await.py index 4ca83b9432..8e57305060 100644 --- a/tests/framework_aiohttp/test_client_async_await.py +++ b/tests/framework_aiohttp/test_client_async_await.py @@ -16,7 +16,7 @@ import aiohttp import pytest -from testing_support.fixtures import cat_enabled +# from testing_support.fixtures import cat_enabled from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from yarl import URL @@ -66,7 +66,7 @@ def task(loop, method, exc_expected, url): ) -@cat_enabled +# @cat_enabled @pytest.mark.parametrize("method,exc_expected", test_matrix) def test_client_async_await(event_loop, local_server_info, method, exc_expected): @validate_transaction_metrics( @@ -81,7 +81,7 @@ def task_test(): task_test() -@cat_enabled +# @cat_enabled def test_client_yarl_async_await(event_loop, local_server_info): method = "get" @@ -98,7 +98,7 @@ def task_test(): @pytest.mark.parametrize("method,exc_expected", test_matrix) -@cat_enabled +# @cat_enabled def test_client_no_txn_async_await(event_loop, local_server_info, method, exc_expected): def task_test(): task(event_loop, method, exc_expected, local_server_info.url) @@ -107,7 +107,7 @@ def task_test(): @pytest.mark.parametrize("method,exc_expected", test_matrix) -@cat_enabled +# @cat_enabled def test_await_request_async_await(event_loop, local_server_info, method, exc_expected): async def request_with_await(): async with aiohttp.ClientSession() as session: @@ -160,7 +160,7 @@ def task_test(): @pytest.mark.parametrize("method,exc_expected", test_matrix) -@cat_enabled +# @cat_enabled def test_create_task_async_await(event_loop, local_server_info, method, exc_expected): # `loop.create_task` returns a Task object which uses the coroutine's # `send` method, not `__next__` @@ -195,7 +195,7 @@ def task_test(): @pytest.mark.parametrize("method,exc_expected", test_matrix) -@cat_enabled +# @cat_enabled def test_terminal_parent_async_await(event_loop, local_server_info, method, exc_expected): """ This test injects a terminal node into a simple background task workflow. diff --git a/tests/framework_tornado/test_externals.py b/tests/framework_tornado/test_externals.py index 40d71e9ab8..1f00db5b6b 100644 --- a/tests/framework_tornado/test_externals.py +++ b/tests/framework_tornado/test_externals.py @@ -124,13 +124,10 @@ def _make_request(): ], ) @pytest.mark.parametrize( - "cat_enabled,user_header,span_events,distributed_tracing", + "user_header,span_events,distributed_tracing", [ - (True, None, False, False), - (True, "X-NewRelic-ID", False, False), - (True, "X-NewRelic-Transaction", False, False), - (False, None, True, True), - (False, None, False, True), + (None, True, True), + (None, False, True), ], ) # @pytest.mark.parametrize('cat_enabled,user_header', [ @@ -142,10 +139,10 @@ def _make_request(): @pytest.mark.parametrize("request_type", ["uri", "class"]) @pytest.mark.parametrize("num_requests", [1, 2]) def test_httpclient( - cat_enabled, + # cat_enabled, request_type, client_class, - user_header, + # user_header, num_requests, distributed_tracing, span_events, @@ -172,8 +169,8 @@ def test_httpclient( @background_task(name="test_externals:test_httpclient") def _test(): headers = {} - if user_header: - headers = {user_header: "USER"} + # if user_header: + # headers = {user_header: "USER"} response = make_request( port, request_type, client_class, headers=headers, count=num_requests, as_kwargs=as_kwargs @@ -194,17 +191,17 @@ def _test(): headers[header_key] = header_val # User headers override all inserted NR headers - if user_header: - assert headers[user_header] == "USER" - elif cat_enabled: - t = current_transaction() - assert t - t._test_request_headers = headers - - if distributed_tracing: - validate_distributed_tracing_header(header="Newrelic") - else: - validate_outbound_headers() + # if user_header: + # assert headers[user_header] == "USER" + # elif cat_enabled: + # t = current_transaction() + # assert t + # t._test_request_headers = headers + + # if distributed_tracing: + # validate_distributed_tracing_header(header="Newrelic") + # else: + validate_outbound_headers() else: # new relic shouldn't add anything to the outgoing assert "x-newrelic" not in body, body diff --git a/tests/messagebroker_pika/test_cat.py b/tests/messagebroker_pika/test_cat.py index 295d988aa3..e4d9ea1c59 100644 --- a/tests/messagebroker_pika/test_cat.py +++ b/tests/messagebroker_pika/test_cat.py @@ -19,7 +19,7 @@ import pika from compat import basic_consume from testing_support.db_settings import rabbitmq_settings -from testing_support.fixtures import cat_enabled, override_application_settings +from testing_support.fixtures import override_application_settings from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task @@ -60,7 +60,7 @@ def do_basic_consume(channel): channel.start_consuming() -@cat_enabled +# @cat_enabled @override_application_settings(_override_settings) def test_basic_consume_cat_headers(): def on_receive(ch, method, properties, msg): diff --git a/tests/testing_support/fixtures.py b/tests/testing_support/fixtures.py index c0eb26b6a5..55fc223b50 100644 --- a/tests/testing_support/fixtures.py +++ b/tests/testing_support/fixtures.py @@ -1039,12 +1039,12 @@ def force_sampled(wrapped, instance, args, kwargs): return wrapped(*args, **kwargs) -@function_wrapper -def cat_enabled(wrapped, instance, args, kwargs): - settings = {"cross_application_tracer.enabled": True, "distributed_tracing.enabled": False} - wrapped = override_application_settings(settings)(wrapped) +# @function_wrapper +# def cat_enabled(wrapped, instance, args, kwargs): +# settings = {"cross_application_tracer.enabled": True, "distributed_tracing.enabled": False} +# wrapped = override_application_settings(settings)(wrapped) - return wrapped(*args, **kwargs) +# return wrapped(*args, **kwargs) def override_application_settings(overrides): From fb1b85ea54dec253fee874852cf0798b51288f98 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Tue, 9 Sep 2025 14:09:51 -0700 Subject: [PATCH 03/95] Remove validate_outbound_headers, make_cross_agent_headers --- newrelic/api/cat_header_mixin.py | 22 ++-- newrelic/api/external_trace.py | 2 +- newrelic/api/transaction.py | 124 +++++++++--------- newrelic/api/web_transaction.py | 8 +- newrelic/core/transaction_node.py | 2 +- newrelic/hooks/external_httplib.py | 26 ++-- newrelic/hooks/framework_aiohttp.py | 30 +++-- tests/agent_features/test_error_events.py | 5 +- tests/agent_unittests/test_harvest_loop.py | 2 +- .../framework_tornado/_target_application.py | 6 +- tests/framework_tornado/test_externals.py | 4 +- tests/testing_support/fixtures.py | 8 +- .../validate_cross_process_headers.py | 6 +- .../validate_messagebroker_headers.py | 6 +- .../validators/validate_outbound_headers.py | 55 -------- 15 files changed, 127 insertions(+), 179 deletions(-) delete mode 100644 tests/testing_support/validators/validate_outbound_headers.py diff --git a/newrelic/api/cat_header_mixin.py b/newrelic/api/cat_header_mixin.py index b905f9dc80..a6675ab3a5 100644 --- a/newrelic/api/cat_header_mixin.py +++ b/newrelic/api/cat_header_mixin.py @@ -24,13 +24,13 @@ # CatHeaderMixin assumes the mixin class also inherits from TimeTrace class CatHeaderMixin: - cat_id_key = "X-NewRelic-ID" - cat_transaction_key = "X-NewRelic-Transaction" - cat_appdata_key = "X-NewRelic-App-Data" - cat_synthetics_key = "X-NewRelic-Synthetics" - cat_synthetics_info_key = "X-NewRelic-Synthetics-Info" - cat_metadata_key = "x-newrelic-trace" - cat_distributed_trace_key = "newrelic" + # cat_id_key = "X-NewRelic-ID" + # cat_transaction_key = "X-NewRelic-Transaction" + # cat_appdata_key = "X-NewRelic-App-Data" + # cat_synthetics_key = "X-NewRelic-Synthetics" + # cat_synthetics_info_key = "X-NewRelic-Synthetics-Info" + # cat_metadata_key = "x-newrelic-trace" + # cat_distributed_trace_key = "newrelic" settings = None def __enter__(self): @@ -69,10 +69,10 @@ def __enter__(self): # except Exception: # pass - def process_response_metadata(self, cat_linking_value): - payload = base64_decode(cat_linking_value) - nr_headers = json_decode(payload) - self.process_response_headers(nr_headers.items()) + # def process_response_metadata(self, cat_linking_value): + # payload = base64_decode(cat_linking_value) + # nr_headers = json_decode(payload) + # self.process_response_headers(nr_headers.items()) @classmethod def generate_request_headers(cls, transaction): diff --git a/newrelic/api/external_trace.py b/newrelic/api/external_trace.py index 372eb2ca09..32796ccd9f 100644 --- a/newrelic/api/external_trace.py +++ b/newrelic/api/external_trace.py @@ -40,7 +40,7 @@ def __repr__(self): def process_response(self, status_code, headers): self._add_agent_attribute("http.statusCode", status_code) - self.process_response_headers(headers) + # self.process_response_headers(headers) def terminal_node(self): return True diff --git a/newrelic/api/transaction.py b/newrelic/api/transaction.py index 5a904d2365..be48631acb 100644 --- a/newrelic/api/transaction.py +++ b/newrelic/api/transaction.py @@ -297,7 +297,7 @@ def __init__(self, application, enabled=None, source=None): self._trip_id = None self._referring_path_hash = None self._alternate_path_hashes = {} - self.is_part_of_cat = False + # self.is_part_of_cat = False # Synthetics Header self.synthetics_resource_id = None @@ -614,7 +614,7 @@ def __exit__(self, exc, value, tb): synthetics_initiator=self.synthetics_initiator, synthetics_attributes=self.synthetics_attributes, synthetics_info_header=self.synthetics_info_header, - is_part_of_cat=self.is_part_of_cat, + # is_part_of_cat=self.is_part_of_cat, trip_id=self.trip_id, path_hash=self.path_hash, referring_path_hash=self._referring_path_hash, @@ -752,53 +752,53 @@ def alternate_path_hashes(self): """ return sorted(set(self._alternate_path_hashes.values()) - {self.path_hash}) - @property - def path_hash(self): - """Path hash is a 32-bit digest of the string "appname;txn_name" - XORed with the referring_path_hash. Since the txn_name can change - during the course of a transaction, up to 10 path_hashes are stored - in _alternate_path_hashes. Before generating the path hash, check the - _alternate_path_hashes to determine if we've seen this identifier and - return the value. + # @property + # def path_hash(self): + # """Path hash is a 32-bit digest of the string "appname;txn_name" + # XORed with the referring_path_hash. Since the txn_name can change + # during the course of a transaction, up to 10 path_hashes are stored + # in _alternate_path_hashes. Before generating the path hash, check the + # _alternate_path_hashes to determine if we've seen this identifier and + # return the value. - """ + # """ - if not self.is_part_of_cat: - return None + # if not self.is_part_of_cat: + # return None - identifier = f"{self.application.name};{self.path}" + # identifier = f"{self.application.name};{self.path}" - # Check if identifier is already part of the _alternate_path_hashes and - # return the value if available. + # # Check if identifier is already part of the _alternate_path_hashes and + # # return the value if available. - if self._alternate_path_hashes.get(identifier): - return self._alternate_path_hashes[identifier] + # if self._alternate_path_hashes.get(identifier): + # return self._alternate_path_hashes[identifier] - # If the referring_path_hash is unavailable then we use '0' as the - # seed. + # # If the referring_path_hash is unavailable then we use '0' as the + # # seed. - try: - seed = int((self._referring_path_hash or "0"), base=16) - except Exception: - seed = 0 + # try: + # seed = int((self._referring_path_hash or "0"), base=16) + # except Exception: + # seed = 0 - try: - path_hash = generate_path_hash(identifier, seed) - except ValueError: - _logger.warning( - "Unable to generate cross application tracer headers. " - "MD5 hashing may not be available. (Is this system FIPS compliant?) " - "We recommend enabling distributed tracing instead. For details and a transition guide see " - "https://docs.newrelic.com/docs/agents/python-agent/configuration/python-agent-configuration#distributed-tracing-settings" - ) - return None + # try: + # path_hash = generate_path_hash(identifier, seed) + # except ValueError: + # _logger.warning( + # "Unable to generate cross application tracer headers. " + # "MD5 hashing may not be available. (Is this system FIPS compliant?) " + # "We recommend enabling distributed tracing instead. For details and a transition guide see " + # "https://docs.newrelic.com/docs/agents/python-agent/configuration/python-agent-configuration#distributed-tracing-settings" + # ) + # return None - # Only store up to 10 alternate path hashes. + # # Only store up to 10 alternate path hashes. - if len(self._alternate_path_hashes) < 10: - self._alternate_path_hashes[identifier] = path_hash + # if len(self._alternate_path_hashes) < 10: + # self._alternate_path_hashes[identifier] = path_hash - return path_hash + # return path_hash @property def attribute_filter(self): @@ -1453,31 +1453,31 @@ def _generate_response_headers(self, read_length=None): return nr_headers - # This function is CAT related and has been deprecated. - # Eventually, this will be removed. Until then, coverage - # does not need to factor this function into its analysis. - def get_response_metadata(self): # pragma: no cover - nr_headers = dict(self._generate_response_headers()) - return convert_to_cat_metadata_value(nr_headers) - - # This function is CAT related and has been deprecated. - # Eventually, this will be removed. Until then, coverage - # does not need to factor this function into its analysis. - def process_request_metadata(self, cat_linking_value): # pragma: no cover - try: - payload = base64_decode(cat_linking_value) - except: - # `cat_linking_value` should always be able to be base64_decoded. - # If this is encountered, the data being sent is corrupt. No - # exception should be raised. - return + # # This function is CAT related and has been deprecated. + # # Eventually, this will be removed. Until then, coverage + # # does not need to factor this function into its analysis. + # def get_response_metadata(self): # pragma: no cover + # nr_headers = dict(self._generate_response_headers()) + # return convert_to_cat_metadata_value(nr_headers) + + # # This function is CAT related and has been deprecated. + # # Eventually, this will be removed. Until then, coverage + # # does not need to factor this function into its analysis. + # def process_request_metadata(self, cat_linking_value): # pragma: no cover + # try: + # payload = base64_decode(cat_linking_value) + # except: + # # `cat_linking_value` should always be able to be base64_decoded. + # # If this is encountered, the data being sent is corrupt. No + # # exception should be raised. + # return - nr_headers = json_decode(payload) - # TODO: All the external CAT APIs really need to - # be refactored into the transaction class. - encoded_cross_process_id = nr_headers.get("X-NewRelic-ID") - encoded_txn_header = nr_headers.get("X-NewRelic-Transaction") - return self._process_incoming_cat_headers(encoded_cross_process_id, encoded_txn_header) + # nr_headers = json_decode(payload) + # # TODO: All the external CAT APIs really need to + # # be refactored into the transaction class. + # encoded_cross_process_id = nr_headers.get("X-NewRelic-ID") + # encoded_txn_header = nr_headers.get("X-NewRelic-Transaction") + # return self._process_incoming_cat_headers(encoded_cross_process_id, encoded_txn_header) def set_transaction_name(self, name, group=None, priority=None): # Always perform this operation even if the transaction diff --git a/newrelic/api/web_transaction.py b/newrelic/api/web_transaction.py index 4c2b575b96..822ce25a4b 100644 --- a/newrelic/api/web_transaction.py +++ b/newrelic/api/web_transaction.py @@ -284,10 +284,10 @@ def _process_context_headers(self): # the relevant details. if self._settings.distributed_tracing.enabled: self.accept_distributed_trace_headers(self._request_headers) - else: - client_cross_process_id = self._request_headers.get("x-newrelic-id") - txn_header = self._request_headers.get("x-newrelic-transaction") - self._process_incoming_cat_headers(client_cross_process_id, txn_header) + # else: + # client_cross_process_id = self._request_headers.get("x-newrelic-id") + # txn_header = self._request_headers.get("x-newrelic-transaction") + # self._process_incoming_cat_headers(client_cross_process_id, txn_header) def process_response(self, status_code, response_headers): """Processes response status and headers, extracting any diff --git a/newrelic/core/transaction_node.py b/newrelic/core/transaction_node.py index 34871d8b21..4a60e46356 100644 --- a/newrelic/core/transaction_node.py +++ b/newrelic/core/transaction_node.py @@ -77,7 +77,7 @@ "synthetics_initiator", "synthetics_attributes", "synthetics_info_header", - "is_part_of_cat", + # "is_part_of_cat", "trip_id", "path_hash", "referring_path_hash", diff --git a/newrelic/hooks/external_httplib.py b/newrelic/hooks/external_httplib.py index f9f5621287..94baa37790 100644 --- a/newrelic/hooks/external_httplib.py +++ b/newrelic/hooks/external_httplib.py @@ -93,24 +93,24 @@ def httplib_getresponse_wrapper(wrapped, instance, args, kwargs): return response -def httplib_putheader_wrapper(wrapped, instance, args, kwargs): - transaction = current_transaction() +# def httplib_putheader_wrapper(wrapped, instance, args, kwargs): +# transaction = current_transaction() - if transaction is None: - return wrapped(*args, **kwargs) +# if transaction is None: +# return wrapped(*args, **kwargs) - # Remember if we see any NR headers being set. This is only doing - # it if we see either, but they should always both be getting set. +# # # Remember if we see any NR headers being set. This is only doing +# # # it if we see either, but they should always both be getting set. - def nr_header(header, *args, **kwargs): - return header.upper() in ("NEWRELIC", "X-NEWRELIC-ID", "X-NEWRELIC-TRANSACTION") +# # def nr_header(header, *args, **kwargs): +# # return header.upper() in ("NEWRELIC", "X-NEWRELIC-ID", "X-NEWRELIC-TRANSACTION") - connection = instance +# # connection = instance - if nr_header(*args, **kwargs): - connection._nr_skip_headers = True +# # if nr_header(*args, **kwargs): +# # connection._nr_skip_headers = True - return wrapped(*args, **kwargs) +# return wrapped(*args, **kwargs) def instrument(module): @@ -125,4 +125,4 @@ def instrument(module): functools.partial(httplib_endheaders_wrapper, scheme="https", library="http"), ) wrap_function_wrapper(module, "HTTPConnection.getresponse", httplib_getresponse_wrapper) - wrap_function_wrapper(module, "HTTPConnection.putheader", httplib_putheader_wrapper) + # wrap_function_wrapper(module, "HTTPConnection.putheader", httplib_putheader_wrapper) diff --git a/newrelic/hooks/framework_aiohttp.py b/newrelic/hooks/framework_aiohttp.py index e43ffaddef..277b2fad4c 100644 --- a/newrelic/hooks/framework_aiohttp.py +++ b/newrelic/hooks/framework_aiohttp.py @@ -33,15 +33,15 @@ def aiohttp_version_info(): return tuple(int(_) for _ in aiohttp.__version__.split(".")[:2]) -def headers_preserve_casing(): - try: - from multidict import CIMultiDict - except: - return True +# def headers_preserve_casing(): +# try: +# from multidict import CIMultiDict +# except: +# return True - d = CIMultiDict() - d.update({"X-NewRelic-ID": "value"}) - return "X-NewRelic-ID" in dict(d.items()) +# d = CIMultiDict() +# d.update({"X-NewRelic-ID": "value"}) +# return "X-NewRelic-ID" in dict(d.items()) def should_ignore(transaction): @@ -303,10 +303,11 @@ def instrument_aiohttp_client_reqrep(module): version_info = aiohttp_version_info() if version_info >= (2, 0): - if headers_preserve_casing(): - cat_wrapper = _nr_aiohttp_add_cat_headers_simple_ - else: - cat_wrapper = _nr_aiohttp_add_cat_headers_ + # TODO: Verify that headers_preserve_casting is always True + # if headers_preserve_casing(): + cat_wrapper = _nr_aiohttp_add_cat_headers_simple_ + # else: + # cat_wrapper = _nr_aiohttp_add_cat_headers_ wrap_function_wrapper(module, "ClientRequest.send", cat_wrapper) @@ -381,8 +382,9 @@ async def _coro(*_args, **_kwargs): def instrument_aiohttp_web(module): global _nr_process_response - if not headers_preserve_casing(): - _nr_process_response = _nr_process_response_proxy + # TODO: Verify that this is correct/not always True + # if not headers_preserve_casing(): + # _nr_process_response = _nr_process_response_proxy wrap_function_wrapper(module, "Application._handle", _nr_request_wrapper) wrap_function_wrapper(module, "Application.__init__", _nr_aiohttp_wrap_application_init_) diff --git a/tests/agent_features/test_error_events.py b/tests/agent_features/test_error_events.py index 08195cf991..1e9a6116db 100644 --- a/tests/agent_features/test_error_events.py +++ b/tests/agent_features/test_error_events.py @@ -18,7 +18,7 @@ import webtest from testing_support.fixtures import ( # cat_enabled, - make_cross_agent_headers, + # make_cross_agent_headers, make_synthetics_headers, override_application_settings, reset_core_stats_engine, @@ -113,12 +113,13 @@ def test_transaction_error_background_task(): # @cat_enabled +# COMEBACK: Change to DT tests. @validate_error_event_sample_data(required_attrs=_intrinsic_attributes, required_user_attrs=True) def test_transaction_error_cross_agent(): test_environ = {"err_message": ERR_MESSAGE} settings = application_settings() transaction_data = [7, 1, 77, "/path-hash"] - headers = make_cross_agent_headers(transaction_data, settings.encoding_key, settings.cross_process_id) + # headers = make_cross_agent_headers(transaction_data, settings.encoding_key, settings.cross_process_id) response = fully_featured_application.get("/", headers=headers, extra_environ=test_environ) diff --git a/tests/agent_unittests/test_harvest_loop.py b/tests/agent_unittests/test_harvest_loop.py index 9a6fb2a257..59ca46cec6 100644 --- a/tests/agent_unittests/test_harvest_loop.py +++ b/tests/agent_unittests/test_harvest_loop.py @@ -145,7 +145,7 @@ def transaction_node(request): synthetics_initiator=None, synthetics_attributes=None, synthetics_info_header=None, - is_part_of_cat=False, + # is_part_of_cat=False, trip_id="4485b89db608aece", path_hash=None, referring_path_hash=None, diff --git a/tests/framework_tornado/_target_application.py b/tests/framework_tornado/_target_application.py index 2570b72d0e..78161e1aaa 100644 --- a/tests/framework_tornado/_target_application.py +++ b/tests/framework_tornado/_target_application.py @@ -43,9 +43,9 @@ def __init__(self, application, request, response_code=200, **kwargs): def get(self, client_cross_process_id, txn_header, flush=None): import newrelic.api.transaction as _transaction - txn = _transaction.current_transaction() - if txn: - txn._process_incoming_cat_headers(client_cross_process_id, txn_header) + # txn = _transaction.current_transaction() + # if txn: + # txn._process_incoming_cat_headers(client_cross_process_id, txn_header) if self.response_code != 200: self.set_status(self.response_code) diff --git a/tests/framework_tornado/test_externals.py b/tests/framework_tornado/test_externals.py index 1f00db5b6b..4b6733f100 100644 --- a/tests/framework_tornado/test_externals.py +++ b/tests/framework_tornado/test_externals.py @@ -20,7 +20,7 @@ from testing_support.fixtures import override_application_settings from testing_support.mock_external_http_server import MockExternalHTTPHResponseHeadersServer, MockExternalHTTPServer from testing_support.validators.validate_distributed_tracing_header import validate_distributed_tracing_header -from testing_support.validators.validate_outbound_headers import validate_outbound_headers +# from testing_support.validators.validate_outbound_headers import validate_outbound_headers from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task @@ -201,7 +201,7 @@ def _test(): # if distributed_tracing: # validate_distributed_tracing_header(header="Newrelic") # else: - validate_outbound_headers() + # validate_outbound_headers() else: # new relic shouldn't add anything to the outgoing assert "x-newrelic" not in body, body diff --git a/tests/testing_support/fixtures.py b/tests/testing_support/fixtures.py index 55fc223b50..c25b2bb9a6 100644 --- a/tests/testing_support/fixtures.py +++ b/tests/testing_support/fixtures.py @@ -419,10 +419,10 @@ def catch_background_exceptions(wrapped, instance, args, kwargs): raise_background_exceptions.event.set() -def make_cross_agent_headers(payload, encoding_key, cat_id): - value = obfuscate(json_encode(payload), encoding_key) - id_value = obfuscate(cat_id, encoding_key) - return {"X-NewRelic-Transaction": value, "X-NewRelic-ID": id_value} +# def make_cross_agent_headers(payload, encoding_key, cat_id): +# value = obfuscate(json_encode(payload), encoding_key) +# id_value = obfuscate(cat_id, encoding_key) +# return {"X-NewRelic-Transaction": value, "X-NewRelic-ID": id_value} def make_synthetics_headers( diff --git a/tests/testing_support/validators/validate_cross_process_headers.py b/tests/testing_support/validators/validate_cross_process_headers.py index 2668fb665b..214d3c8db1 100644 --- a/tests/testing_support/validators/validate_cross_process_headers.py +++ b/tests/testing_support/validators/validate_cross_process_headers.py @@ -15,7 +15,7 @@ from newrelic.api.transaction import current_transaction from newrelic.common.object_wrapper import function_wrapper from testing_support.validators.validate_distributed_tracing_header import validate_distributed_tracing_header -from testing_support.validators.validate_outbound_headers import validate_outbound_headers +# from testing_support.validators.validate_outbound_headers import validate_outbound_headers @function_wrapper @@ -27,7 +27,7 @@ def validate_cross_process_headers(wrapped, instance, args, kwargs): if settings.distributed_tracing.enabled: validate_distributed_tracing_header() - else: - validate_outbound_headers() + # else: + # validate_outbound_headers() return result diff --git a/tests/testing_support/validators/validate_messagebroker_headers.py b/tests/testing_support/validators/validate_messagebroker_headers.py index 78f5fb7a62..e86e7188d0 100644 --- a/tests/testing_support/validators/validate_messagebroker_headers.py +++ b/tests/testing_support/validators/validate_messagebroker_headers.py @@ -15,7 +15,7 @@ from newrelic.api.transaction import current_transaction from newrelic.common.object_wrapper import function_wrapper from testing_support.validators.validate_distributed_tracing_header import validate_distributed_tracing_header -from testing_support.validators.validate_outbound_headers import validate_outbound_headers +# from testing_support.validators.validate_outbound_headers import validate_outbound_headers @function_wrapper @@ -27,7 +27,7 @@ def validate_messagebroker_headers(wrapped, instance, args, kwargs): if settings.distributed_tracing.enabled: validate_distributed_tracing_header() - else: - validate_outbound_headers(header_id="NewRelicID", header_transaction="NewRelicTransaction") + # else: + # validate_outbound_headers(header_id="NewRelicID", header_transaction="NewRelicTransaction") return result diff --git a/tests/testing_support/validators/validate_outbound_headers.py b/tests/testing_support/validators/validate_outbound_headers.py deleted file mode 100644 index 8ddb2d5cbc..0000000000 --- a/tests/testing_support/validators/validate_outbound_headers.py +++ /dev/null @@ -1,55 +0,0 @@ -# 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.api.transaction import current_transaction -from newrelic.common.encoding_utils import deobfuscate, json_decode - -OUTBOUND_TRACE_KEYS_REQUIRED = ("ty", "ac", "ap", "tr", "pr", "sa", "ti") - - -def validate_outbound_headers(header_id="X-NewRelic-ID", header_transaction="X-NewRelic-Transaction"): - transaction = current_transaction() - headers = transaction._test_request_headers - settings = transaction.settings - encoding_key = settings.encoding_key - - assert header_id in headers - - values = headers[header_id] - if isinstance(values, list): - assert len(values) == 1, headers - assert isinstance(values[0], str) - value = values[0] - else: - value = values - - cross_process_id = deobfuscate(value, encoding_key) - assert cross_process_id == settings.cross_process_id - - assert header_transaction in headers - - values = headers[header_transaction] - if isinstance(values, list): - assert len(values) == 1, headers - assert isinstance(values[0], str) - value = values[0] - else: - value = values - - (guid, record_tt, trip_id, path_hash) = json_decode(deobfuscate(value, encoding_key)) - - assert guid == transaction.guid - assert record_tt == transaction.record_tt - assert trip_id == transaction.trip_id - assert path_hash == transaction.path_hash From 4df07f37e05a1baef248dc3a0a4e356e41f10011 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Tue, 9 Sep 2025 15:28:44 -0700 Subject: [PATCH 04/95] Remove path_hash --- newrelic/api/cat_header_mixin.py | 2 +- newrelic/api/transaction.py | 34 ++++++++++++---------- newrelic/common/encoding_utils.py | 22 +++++++------- newrelic/core/transaction_node.py | 20 ++++++------- newrelic/hooks/framework_tornado.py | 6 ++-- tests/agent_unittests/test_harvest_loop.py | 6 ++-- tests/framework_aiohttp/test_server_cat.py | 21 ++++++------- 7 files changed, 57 insertions(+), 54 deletions(-) diff --git a/newrelic/api/cat_header_mixin.py b/newrelic/api/cat_header_mixin.py index a6675ab3a5..8008423778 100644 --- a/newrelic/api/cat_header_mixin.py +++ b/newrelic/api/cat_header_mixin.py @@ -15,7 +15,7 @@ from newrelic.common.encoding_utils import ( base64_decode, base64_encode, - # deobfuscate, + deobfuscate, json_decode, json_encode, obfuscate, diff --git a/newrelic/api/transaction.py b/newrelic/api/transaction.py index be48631acb..4a79c91bbd 100644 --- a/newrelic/api/transaction.py +++ b/newrelic/api/transaction.py @@ -37,7 +37,7 @@ convert_to_cat_metadata_value, deobfuscate, ensure_str, - generate_path_hash, + # generate_path_hash, json_decode, json_encode, obfuscate, @@ -295,8 +295,8 @@ def __init__(self, application, enabled=None, source=None): self.referring_transaction_guid = None self.record_tt = False self._trip_id = None - self._referring_path_hash = None - self._alternate_path_hashes = {} + # self._referring_path_hash = None + # self._alternate_path_hashes = {} # self.is_part_of_cat = False # Synthetics Header @@ -616,9 +616,9 @@ def __exit__(self, exc, value, tb): synthetics_info_header=self.synthetics_info_header, # is_part_of_cat=self.is_part_of_cat, trip_id=self.trip_id, - path_hash=self.path_hash, - referring_path_hash=self._referring_path_hash, - alternate_path_hashes=self.alternate_path_hashes, + # path_hash=self.path_hash, + # referring_path_hash=self._referring_path_hash, + # alternate_path_hashes=self.alternate_path_hashes, trace_intrinsics=self.trace_intrinsics, distributed_trace_intrinsics=self.distributed_trace_intrinsics, agent_attributes=agent_attributes, @@ -744,13 +744,14 @@ def trip_id(self): def trace_id(self): return self._trace_id - @property - def alternate_path_hashes(self): - """Return the alternate path hashes but not including the current path - hash. + # @property + # def alternate_path_hashes(self): + # """Return the alternate path hashes but not including the current path + # hash. - """ - return sorted(set(self._alternate_path_hashes.values()) - {self.path_hash}) + # """ + # # return sorted(set(self._alternate_path_hashes.values()) - {self.path_hash}) + # return sorted(set(self._alternate_path_hashes.values()) - {None}) # @property # def path_hash(self): @@ -763,8 +764,9 @@ def alternate_path_hashes(self): # """ - # if not self.is_part_of_cat: - # return None + # # if not self.is_part_of_cat: + # # return None + # return None # identifier = f"{self.application.name};{self.path}" @@ -843,8 +845,8 @@ def trace_intrinsics(self): i_attrs["client_cross_process_id"] = self.client_cross_process_id if self.trip_id: i_attrs["trip_id"] = self.trip_id - if self.path_hash: - i_attrs["path_hash"] = self.path_hash + # if self.path_hash: + # i_attrs["path_hash"] = self.path_hash if self.synthetics_resource_id: i_attrs["synthetics_resource_id"] = self.synthetics_resource_id if self.synthetics_job_id: diff --git a/newrelic/common/encoding_utils.py b/newrelic/common/encoding_utils.py index 6f7e9d199f..38f81ea397 100644 --- a/newrelic/common/encoding_utils.py +++ b/newrelic/common/encoding_utils.py @@ -232,21 +232,21 @@ def unpack_field(field): return data -def generate_path_hash(name, seed): - """Algorithm for generating the path hash: - * Rotate Left the seed value and truncate to 32-bits. - * Compute the md5 digest of the name, take the last 4 bytes (32-bits). - * XOR the 4 bytes of digest with the seed and return the result. +# def generate_path_hash(name, seed): +# """Algorithm for generating the path hash: +# * Rotate Left the seed value and truncate to 32-bits. +# * Compute the md5 digest of the name, take the last 4 bytes (32-bits). +# * XOR the 4 bytes of digest with the seed and return the result. - """ +# """ - rotated = ((seed << 1) | (seed >> 31)) & 0xFFFFFFFF +# rotated = ((seed << 1) | (seed >> 31)) & 0xFFFFFFFF - if not isinstance(name, bytes): - name = name.encode("UTF-8") +# if not isinstance(name, bytes): +# name = name.encode("UTF-8") - path_hash = rotated ^ int(hashlib.md5(name).hexdigest()[-8:], base=16) # noqa: S324 - return f"{path_hash:08x}" +# path_hash = rotated ^ int(hashlib.md5(name).hexdigest()[-8:], base=16) # noqa: S324 +# return f"{path_hash:08x}" def base64_encode(text): diff --git a/newrelic/core/transaction_node.py b/newrelic/core/transaction_node.py index 4a60e46356..5468065faf 100644 --- a/newrelic/core/transaction_node.py +++ b/newrelic/core/transaction_node.py @@ -79,9 +79,9 @@ "synthetics_info_header", # "is_part_of_cat", "trip_id", - "path_hash", - "referring_path_hash", - "alternate_path_hashes", + # "path_hash", + # "referring_path_hash", + # "alternate_path_hashes", "trace_intrinsics", "agent_attributes", "distributed_trace_intrinsics", @@ -470,14 +470,14 @@ def _add_if_not_empty(key, value): if self.errors: intrinsics["error"] = True - if self.path_hash: - intrinsics["nr.guid"] = self.guid - intrinsics["nr.tripId"] = self.trip_id - intrinsics["nr.pathHash"] = self.path_hash + # if self.path_hash: + # intrinsics["nr.guid"] = self.guid + # intrinsics["nr.tripId"] = self.trip_id + # intrinsics["nr.pathHash"] = self.path_hash - _add_if_not_empty("nr.referringPathHash", self.referring_path_hash) - _add_if_not_empty("nr.alternatePathHashes", ",".join(self.alternate_path_hashes)) - _add_if_not_empty("nr.referringTransactionGuid", self.referring_transaction_guid) + # _add_if_not_empty("nr.referringPathHash", self.referring_path_hash) + # _add_if_not_empty("nr.alternatePathHashes", ",".join(self.alternate_path_hashes)) + # _add_if_not_empty("nr.referringTransactionGuid", self.referring_transaction_guid) if self.synthetics_resource_id: intrinsics["nr.guid"] = self.guid diff --git a/newrelic/hooks/framework_tornado.py b/newrelic/hooks/framework_tornado.py index c80a45a585..a88c66a1b0 100644 --- a/newrelic/hooks/framework_tornado.py +++ b/newrelic/hooks/framework_tornado.py @@ -251,9 +251,9 @@ async def wrapper(req, raise_error): except Exception as e: response = getattr(e, "response", None) raise - finally: - if response: - trace.process_response_headers(response.headers.get_all()) + # finally: + # if response: + # trace.process_response_headers(response.headers.get_all()) return response return wrapper diff --git a/tests/agent_unittests/test_harvest_loop.py b/tests/agent_unittests/test_harvest_loop.py index 59ca46cec6..9f78214575 100644 --- a/tests/agent_unittests/test_harvest_loop.py +++ b/tests/agent_unittests/test_harvest_loop.py @@ -147,9 +147,9 @@ def transaction_node(request): synthetics_info_header=None, # is_part_of_cat=False, trip_id="4485b89db608aece", - path_hash=None, - referring_path_hash=None, - alternate_path_hashes=[], + # path_hash=None, + # referring_path_hash=None, + # alternate_path_hashes=[], trace_intrinsics={}, distributed_trace_intrinsics={}, agent_attributes=[], diff --git a/tests/framework_aiohttp/test_server_cat.py b/tests/framework_aiohttp/test_server_cat.py index 3fc651ad19..9d4cf581ce 100644 --- a/tests/framework_aiohttp/test_server_cat.py +++ b/tests/framework_aiohttp/test_server_cat.py @@ -178,11 +178,11 @@ def _test(): }, } -unexpected_attributes = { - "agent": [], - "user": [], - "intrinsic": ["grandparentId", "cross_process_id", "nr.tripId", "nr.pathHash"], -} +# unexpected_attributes = { +# "agent": [], +# "user": [], +# "intrinsic": ["grandparentId", "cross_process_id", "nr.tripId", "nr.pathHash"], +# } @pytest.mark.parametrize("uri,metric_name", test_uris) @@ -191,11 +191,11 @@ async def fetch(): headers = {"newrelic": json.dumps(inbound_payload)} resp = await aiohttp_app.client.request("GET", uri, headers=headers) - # better cat does not send a response in the headers - assert "newrelic" not in resp.headers + # # better cat does not send a response in the 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 + # # old-cat headers should not be in the response + # 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 @@ -206,7 +206,8 @@ async 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) + @validate_transaction_event_attributes(expected_attributes) + # @validate_transaction_event_attributes(expected_attributes, unexpected_attributes) @override_application_settings( { "account_id": "33", From e5a0d4e6c2da81b2bb011db17947906cc38a5df5 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Tue, 9 Sep 2025 15:54:26 -0700 Subject: [PATCH 05/95] Fix tornado tests --- .../framework_tornado/_target_application.py | 46 ++--- tests/framework_tornado/test_externals.py | 158 ++++++++---------- tests/framework_tornado/test_inbound_cat.py | 117 ------------- tests/framework_tornado/test_inbound_dt.py | 125 ++++++++++++++ 4 files changed, 220 insertions(+), 226 deletions(-) delete mode 100644 tests/framework_tornado/test_inbound_cat.py create mode 100644 tests/framework_tornado/test_inbound_dt.py diff --git a/tests/framework_tornado/_target_application.py b/tests/framework_tornado/_target_application.py index 78161e1aaa..396f357570 100644 --- a/tests/framework_tornado/_target_application.py +++ b/tests/framework_tornado/_target_application.py @@ -35,33 +35,33 @@ def get_status(self, *args, **kwargs): raise ValueError("Bad Status") -class ProcessCatHeadersHandler(tornado.web.RequestHandler): - def __init__(self, application, request, response_code=200, **kwargs): - super().__init__(application, request, **kwargs) - self.response_code = response_code +# class ProcessCatHeadersHandler(tornado.web.RequestHandler): +# def __init__(self, application, request, response_code=200, **kwargs): +# super().__init__(application, request, **kwargs) +# self.response_code = response_code - def get(self, client_cross_process_id, txn_header, flush=None): - import newrelic.api.transaction as _transaction +# def get(self, client_cross_process_id, txn_header, flush=None): +# import newrelic.api.transaction as _transaction - # txn = _transaction.current_transaction() - # if txn: - # txn._process_incoming_cat_headers(client_cross_process_id, txn_header) +# # txn = _transaction.current_transaction() +# # if txn: +# # txn._process_incoming_cat_headers(client_cross_process_id, txn_header) - if self.response_code != 200: - self.set_status(self.response_code) - return +# if self.response_code != 200: +# self.set_status(self.response_code) +# return - self.write("Hello, world") +# self.write("Hello, world") - if flush == "flush": - # Force a flush prior to calling finish - # This causes the headers to get written immediately. The tests - # which hit this endpoint will check that the response has been - # properly processed even though we send the headers here. - self.flush() +# if flush == "flush": +# # Force a flush prior to calling finish +# # This causes the headers to get written immediately. The tests +# # which hit this endpoint will check that the response has been +# # properly processed even though we send the headers here. +# self.flush() - # change the headers to garbage - self.set_header("Content-Type", "garbage") +# # change the headers to garbage +# self.set_header("Content-Type", "garbage") class EchoHeaderHandler(tornado.web.RequestHandler): @@ -250,8 +250,8 @@ def make_app(custom=False): (r"/init", InitializeHandler), (r"/html-insertion", HTMLInsertionHandler), (r"/bad-get-status", BadGetStatusHandler), - (r"/force-cat-response/(\S+)/(\S+)/(\S+)", ProcessCatHeadersHandler), - (r"/304-cat-response/(\S+)/(\S+)", ProcessCatHeadersHandler, {"response_code": 304}), + # (r"/force-cat-response/(\S+)/(\S+)/(\S+)", ProcessCatHeadersHandler), + # (r"/304-cat-response/(\S+)/(\S+)", ProcessCatHeadersHandler, {"response_code": 304}), (r"/echo-headers", EchoHeaderHandler), (r"/native-simple", NativeSimpleHandler), (r"/multi-trace", MultiTraceHandler), diff --git a/tests/framework_tornado/test_externals.py b/tests/framework_tornado/test_externals.py index 4b6733f100..9553ca4140 100644 --- a/tests/framework_tornado/test_externals.py +++ b/tests/framework_tornado/test_externals.py @@ -123,28 +123,14 @@ def _make_request(): ("HTTPClient", True), ], ) -@pytest.mark.parametrize( - "user_header,span_events,distributed_tracing", - [ - (None, True, True), - (None, False, True), - ], -) -# @pytest.mark.parametrize('cat_enabled,user_header', [ -# (True, None), -# (True, 'X-NewRelic-ID'), -# (True, 'X-NewRelic-Transaction'), -# (False, None), -# ]) +@pytest.mark.parametrize("span_events", [True, False]) @pytest.mark.parametrize("request_type", ["uri", "class"]) @pytest.mark.parametrize("num_requests", [1, 2]) def test_httpclient( # cat_enabled, request_type, client_class, - # user_header, num_requests, - distributed_tracing, span_events, external, as_kwargs, @@ -155,7 +141,7 @@ def test_httpclient( @override_application_settings( { - "distributed_tracing.enabled": distributed_tracing, + "distributed_tracing.enabled": True, "span_events.enabled": span_events, # "cross_application_tracer.enabled": not distributed_tracing, } @@ -202,11 +188,11 @@ def _test(): # validate_distributed_tracing_header(header="Newrelic") # else: # validate_outbound_headers() - else: - # new relic shouldn't add anything to the outgoing - assert "x-newrelic" not in body, body + # else: + # # new relic shouldn't add anything to the outgoing + # assert "x-newrelic" not in body, body - assert "X-NewRelic-App-Data" not in headers + # assert "X-NewRelic-App-Data" not in headers _test() @@ -214,72 +200,72 @@ def _test(): CAT_RESPONSE_CODE = None -def cat_response_handler(self): - # payload - # ( - # u'1#1', u'WebTransaction/Function/app:beep', - # 0, 1.23, -1, - # 'dd4a810b7cb7f937', - # False, - # ) - cat_response_header = ( - "X-NewRelic-App-Data", - "ahACFwQUGxpuVVNmQVVbRVZbTVleXBxyQFhUTFBfXx1SREUMVV1cQBMeAxgEGAULFR0AHhFQUQJWAAgAUwVQVgJQDgsOEh1UUlhGU2o=", - ) - self.send_response(CAT_RESPONSE_CODE) - self.send_header(*cat_response_header) - self.end_headers() - self.wfile.write(b"Example Data") - - -@pytest.fixture(scope="module") -def cat_response_server(): - external = MockExternalHTTPServer(handler=cat_response_handler) - with external: - yield external - - -@pytest.mark.parametrize("client_class", ["AsyncHTTPClient", "CurlAsyncHTTPClient", "HTTPClient"]) -@pytest.mark.parametrize("dt_enabled", [True, False]) -@pytest.mark.parametrize("request_type", ["uri", "class"]) -@pytest.mark.parametrize("response_code,raise_error", [(500, True), (500, False), (200, False)]) -def test_client_cat_response_processing( - dt_enabled, request_type, client_class, raise_error, response_code, cat_response_server -): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = response_code - - _custom_settings = { - "cross_process_id": "1#1", - "encoding_key": ENCODING_KEY, - "trusted_account_ids": [1], - # "cross_application_tracer.enabled": cat_enabled, - "distributed_tracing.enabled": dt_enabled, - "transaction_tracer.transaction_threshold": 0.0, - } - - port = cat_response_server.port - expected_metrics = None - - @validate_transaction_metrics( - "make_request", background_task=True, rollup_metrics=expected_metrics, scoped_metrics=expected_metrics - ) - @override_application_settings(_custom_settings) - def _test(): - import tornado - import tornado.httpclient - - try: - response = make_request(port, request_type, client_class, raise_error=raise_error) - except tornado.httpclient.HTTPError as e: - assert raise_error - response = e.response - else: - assert not raise_error - - assert response.code == response_code - - _test() +# def cat_response_handler(self): +# # payload +# # ( +# # u'1#1', u'WebTransaction/Function/app:beep', +# # 0, 1.23, -1, +# # 'dd4a810b7cb7f937', +# # False, +# # ) +# cat_response_header = ( +# "X-NewRelic-App-Data", +# "ahACFwQUGxpuVVNmQVVbRVZbTVleXBxyQFhUTFBfXx1SREUMVV1cQBMeAxgEGAULFR0AHhFQUQJWAAgAUwVQVgJQDgsOEh1UUlhGU2o=", +# ) +# self.send_response(CAT_RESPONSE_CODE) +# self.send_header(*cat_response_header) +# self.end_headers() +# self.wfile.write(b"Example Data") + + +# @pytest.fixture(scope="module") +# def cat_response_server(): +# external = MockExternalHTTPServer(handler=cat_response_handler) +# with external: +# yield external + + +# @pytest.mark.parametrize("client_class", ["AsyncHTTPClient", "CurlAsyncHTTPClient", "HTTPClient"]) +# @pytest.mark.parametrize("dt_enabled", [True, False]) +# @pytest.mark.parametrize("request_type", ["uri", "class"]) +# @pytest.mark.parametrize("response_code,raise_error", [(500, True), (500, False), (200, False)]) +# def test_client_cat_response_processing( +# dt_enabled, request_type, client_class, raise_error, response_code, cat_response_server +# ): +# global CAT_RESPONSE_CODE +# CAT_RESPONSE_CODE = response_code + +# _custom_settings = { +# "cross_process_id": "1#1", +# "encoding_key": ENCODING_KEY, +# "trusted_account_ids": [1], +# # "cross_application_tracer.enabled": cat_enabled, +# "distributed_tracing.enabled": dt_enabled, +# "transaction_tracer.transaction_threshold": 0.0, +# } + +# port = cat_response_server.port +# expected_metrics = None + +# @validate_transaction_metrics( +# "make_request", background_task=True, rollup_metrics=expected_metrics, scoped_metrics=expected_metrics +# ) +# @override_application_settings(_custom_settings) +# def _test(): +# import tornado +# import tornado.httpclient + +# try: +# response = make_request(port, request_type, client_class, raise_error=raise_error) +# except tornado.httpclient.HTTPError as e: +# assert raise_error +# response = e.response +# else: +# assert not raise_error + +# assert response.code == response_code + +# _test() @pytest.mark.parametrize("client_class", ["AsyncHTTPClient", "CurlAsyncHTTPClient", "HTTPClient"]) diff --git a/tests/framework_tornado/test_inbound_cat.py b/tests/framework_tornado/test_inbound_cat.py deleted file mode 100644 index fb935f174a..0000000000 --- a/tests/framework_tornado/test_inbound_cat.py +++ /dev/null @@ -1,117 +0,0 @@ -# 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 json - -import pytest -from testing_support.fixtures import make_cross_agent_headers, override_application_settings -from testing_support.validators.validate_transaction_event_attributes import validate_transaction_event_attributes -from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics - -ENCODING_KEY = "1234567890123456789012345678901234567890" - - -_custom_settings = { - "cross_process_id": "1#1", - "encoding_key": ENCODING_KEY, - "trusted_account_ids": [1], - # "cross_application_tracer.enabled": True, - "distributed_tracing.enabled": False, - "transaction_tracer.transaction_threshold": 0.0, -} - - -@override_application_settings(_custom_settings) -@validate_transaction_event_attributes( - required_params={"agent": (), "user": (), "intrinsic": ()}, - forgone_params={"agent": (), "user": (), "intrinsic": ()}, - exact_attrs={ - "agent": {"response.status": "200", "response.headers.contentType": "text/html; charset=UTF-8"}, - "user": {}, - "intrinsic": {}, - }, -) -@pytest.mark.parametrize("manual_flush", ["flush", "no-flush"]) -def test_response_to_inbound_cat(app, manual_flush): - payload = ("1#1", "WebTransaction/Function/app:beep", 0, 1.23, -1, "dd4a810b7cb7f937", False) - headers = make_cross_agent_headers(payload, ENCODING_KEY, "1#1") - - client_cross_process_id = headers["X-NewRelic-ID"] - txn_header = headers["X-NewRelic-Transaction"] - - response = app.fetch(f"/force-cat-response/{client_cross_process_id}/{txn_header}/{manual_flush}") - assert response.code == 200 - assert "X-NewRelic-App-Data" in list(response.headers.keys()) - - -@validate_transaction_event_attributes( - required_params={"agent": (), "user": (), "intrinsic": ()}, - forgone_params={"agent": ("response.headers",), "user": (), "intrinsic": ()}, - exact_attrs={"agent": {"request.method": "GET", "response.status": "304"}, "user": {}, "intrinsic": {}}, -) -@override_application_settings(_custom_settings) -def test_cat_headers_not_inserted(app): - payload = ("1#1", "WebTransaction/Function/app:beep", 0, 1.23, -1, "dd4a810b7cb7f937", False) - headers = make_cross_agent_headers(payload, ENCODING_KEY, "1#1") - - client_cross_process_id = headers["X-NewRelic-ID"] - txn_header = headers["X-NewRelic-Transaction"] - - response = app.fetch(f"/304-cat-response/{client_cross_process_id}/{txn_header}") - assert response.code == 304 - assert "X-NewRelic-App-Data" not in list(response.headers.keys()) - - -@override_application_settings(_custom_settings) -@validate_transaction_metrics( - "_target_application:SimpleHandler.get", rollup_metrics=[("ClientApplication/1#1/all", 1)] -) -@validate_transaction_event_attributes( - required_params={"agent": [], "user": [], "intrinsic": []}, - forgone_params={"agent": [], "user": [], "intrinsic": []}, - exact_attrs={"agent": {}, "user": {}, "intrinsic": {"nr.referringTransactionGuid": "b854df4feb2b1f06"}}, -) -def test_inbound_cat_metrics_and_intrinsics(app): - payload = ["b854df4feb2b1f06", False, "7e249074f277923d", "5d2957be"] - headers = make_cross_agent_headers(payload, ENCODING_KEY, "1#1") - - response = app.fetch("/simple", headers=headers) - assert response.code == 200 - - -@override_application_settings( - {"account_id": 1, "trusted_account_key": 1, "primary_application_id": 1, "distributed_tracing.enabled": True} -) -@validate_transaction_metrics( - "_target_application:SimpleHandler.get", - rollup_metrics=(("Supportability/DistributedTrace/AcceptPayload/Success", 1),), -) -def test_inbound_dt(app): - PAYLOAD = { - "v": [0, 1], - "d": { - "ac": 1, - "ap": 1, - "id": "7d3efb1b173fecfa", - "tx": "e8b91a159289ff74", - "pr": 1.234567, - "sa": True, - "ti": 1518469636035, - "tr": "d6b4ba0c3a712ca", - "ty": "App", - }, - } - headers = {"newrelic": json.dumps(PAYLOAD)} - response = app.fetch("/simple", headers=headers) - assert response.code == 200 diff --git a/tests/framework_tornado/test_inbound_dt.py b/tests/framework_tornado/test_inbound_dt.py new file mode 100644 index 0000000000..319fc00229 --- /dev/null +++ b/tests/framework_tornado/test_inbound_dt.py @@ -0,0 +1,125 @@ +# 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 json + +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_transaction_event_attributes import validate_transaction_event_attributes +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics + +# ENCODING_KEY = "1234567890123456789012345678901234567890" + + +# _custom_settings = { +# "cross_process_id": "1#1", +# "encoding_key": ENCODING_KEY, +# "trusted_account_ids": [1], +# # "cross_application_tracer.enabled": True, +# "distributed_tracing.enabled": False, +# "transaction_tracer.transaction_threshold": 0.0, +# } + + +# @override_application_settings(_custom_settings) +# @validate_transaction_event_attributes( +# required_params={"agent": (), "user": (), "intrinsic": ()}, +# forgone_params={"agent": (), "user": (), "intrinsic": ()}, +# exact_attrs={ +# "agent": {"response.status": "200", "response.headers.contentType": "text/html; charset=UTF-8"}, +# "user": {}, +# "intrinsic": {}, +# }, +# ) +# @pytest.mark.parametrize("manual_flush", ["flush", "no-flush"]) +# def test_response_to_inbound_cat(app, manual_flush): +# payload = ("1#1", "WebTransaction/Function/app:beep", 0, 1.23, -1, "dd4a810b7cb7f937", False) +# headers = make_cross_agent_headers(payload, ENCODING_KEY, "1#1") + +# client_cross_process_id = headers["X-NewRelic-ID"] +# txn_header = headers["X-NewRelic-Transaction"] + +# response = app.fetch(f"/force-cat-response/{client_cross_process_id}/{txn_header}/{manual_flush}") +# assert response.code == 200 +# assert "X-NewRelic-App-Data" in list(response.headers.keys()) + + +# # @validate_transaction_event_attributes( +# # required_params={"agent": (), "user": (), "intrinsic": ()}, +# # forgone_params={"agent": ("response.headers",), "user": (), "intrinsic": ()}, +# # exact_attrs={"agent": {"request.method": "GET", "response.status": "304"}, "user": {}, "intrinsic": {}}, +# # ) +# # @override_application_settings(_custom_settings) +# # def test_cat_headers_not_inserted(app): +# # payload = ("1#1", "WebTransaction/Function/app:beep", 0, 1.23, -1, "dd4a810b7cb7f937", False) +# # headers = make_cross_agent_headers(payload, ENCODING_KEY, "1#1") + +# # client_cross_process_id = headers["X-NewRelic-ID"] +# # txn_header = headers["X-NewRelic-Transaction"] + +# # response = app.fetch(f"/304-cat-response/{client_cross_process_id}/{txn_header}") +# # assert response.code == 304 +# # assert "X-NewRelic-App-Data" not in list(response.headers.keys()) + + +# @override_application_settings(_custom_settings) +# @validate_transaction_metrics( +# "_target_application:SimpleHandler.get", rollup_metrics=[("ClientApplication/1#1/all", 1)] +# ) +# @validate_transaction_event_attributes( +# required_params={"agent": [], "user": [], "intrinsic": []}, +# forgone_params={"agent": [], "user": [], "intrinsic": []}, +# exact_attrs={"agent": {}, "user": {}, "intrinsic": {"nr.referringTransactionGuid": "b854df4feb2b1f06"}}, +# ) +# def test_inbound_cat_metrics_and_intrinsics(app): +# payload = ["b854df4feb2b1f06", False, "7e249074f277923d", "5d2957be"] +# headers = make_cross_agent_headers(payload, ENCODING_KEY, "1#1") + +# response = app.fetch("/simple", headers=headers) +# assert response.code == 200 + + +@validate_transaction_event_attributes( + required_params={"agent": (), "user": (), "intrinsic": ()}, + forgone_params={"agent": (), "user": (), "intrinsic": ()}, + exact_attrs={ + "agent": {"response.status": "200", "response.headers.contentType": "text/html; charset=UTF-8"}, + "user": {}, + "intrinsic": {}, + }, +) +@override_application_settings( + {"account_id": 1, "trusted_account_key": 1, "primary_application_id": 1, "distributed_tracing.enabled": True} +) +@validate_transaction_metrics( + "_target_application:SimpleHandler.get", + rollup_metrics=(("Supportability/DistributedTrace/AcceptPayload/Success", 1),), +) +def test_inbound_dt(app): + PAYLOAD = { + "v": [0, 1], + "d": { + "ac": 1, + "ap": 1, + "id": "7d3efb1b173fecfa", + "tx": "e8b91a159289ff74", + "pr": 1.234567, + "sa": True, + "ti": 1518469636035, + "tr": "d6b4ba0c3a712ca", + "ty": "App", + }, + } + headers = {"newrelic": json.dumps(PAYLOAD)} + response = app.fetch("/simple", headers=headers) + assert response.code == 200 From d1459405520b7b4ba0a9c0359fe1565fb7ebcfab Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Tue, 9 Sep 2025 17:08:49 -0700 Subject: [PATCH 06/95] Fix aiohttp tests --- tests/framework_aiohttp/conftest.py | 3 +- tests/framework_aiohttp/test_client_cat.py | 227 --------------------- tests/framework_aiohttp/test_server_cat.py | 222 -------------------- tests/framework_aiohttp/test_server_dt.py | 222 ++++++++++++++++++++ 4 files changed, 224 insertions(+), 450 deletions(-) delete mode 100644 tests/framework_aiohttp/test_client_cat.py delete mode 100644 tests/framework_aiohttp/test_server_cat.py create mode 100644 tests/framework_aiohttp/test_server_dt.py diff --git a/tests/framework_aiohttp/conftest.py b/tests/framework_aiohttp/conftest.py index 3c2a783b24..cfcea49122 100644 --- a/tests/framework_aiohttp/conftest.py +++ b/tests/framework_aiohttp/conftest.py @@ -123,7 +123,8 @@ def respond_with_cat_header(self): self.end_headers() self.wfile.write(b"") - with MockExternalHTTPServer(handler=respond_with_cat_header) as server: + # with MockExternalHTTPServer(handler=respond_with_cat_header) as server: + with MockExternalHTTPServer() as server: yield (server, response_values) diff --git a/tests/framework_aiohttp/test_client_cat.py b/tests/framework_aiohttp/test_client_cat.py deleted file mode 100644 index 61a73d96aa..0000000000 --- a/tests/framework_aiohttp/test_client_cat.py +++ /dev/null @@ -1,227 +0,0 @@ -# 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 asyncio - -import aiohttp -import pytest -from testing_support.external_fixtures import create_incoming_headers -from testing_support.fixtures import override_application_settings -# from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers -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 -from newrelic.api.external_trace import ExternalTrace -from newrelic.api.transaction import current_transaction - -version_info = tuple(int(_) for _ in aiohttp.__version__.split(".")[:2]) - -if version_info < (2, 0): - _expected_error_class = aiohttp.errors.HttpProcessingError -else: - _expected_error_class = aiohttp.client_exceptions.ClientResponseError - - -async def fetch(url, headers=None, raise_for_status=False, connector=None): - kwargs = {} - if version_info >= (2, 0): - kwargs = {"raise_for_status": raise_for_status} - - session = aiohttp.ClientSession(connector=connector, **kwargs) - request = session._request("GET", url, headers=headers) - headers = {} - - try: - response = await request - if raise_for_status and version_info < (2, 0): - response.raise_for_status() - except _expected_error_class: - return headers - - response_text = await response.text() - for header in response_text.split("\n"): - if not header: - continue - try: - h, v = header.split(":", 1) - except ValueError: - continue - headers[h.strip()] = v.strip() - f = session.close() - await asyncio.ensure_future(f) - return headers - - -# @pytest.mark.parametrize("cat_enabled", (True, False)) -@pytest.mark.parametrize("distributed_tracing", (True, False)) -@pytest.mark.parametrize("span_events", (True, False)) -def test_outbound_cross_process_headers(event_loop, distributed_tracing, span_events, mock_header_server): -# def test_outbound_cross_process_headers(event_loop, cat_enabled, distributed_tracing, span_events, mock_header_server): - @background_task(name="test_outbound_cross_process_headers") - async def _test(): - headers = await fetch(f"http://127.0.0.1:{mock_header_server.port}") - - transaction = current_transaction() - transaction._test_request_headers = headers - - if distributed_tracing: - assert "newrelic" in headers - # elif cat_enabled: - # assert ExternalTrace.cat_id_key in headers - # assert ExternalTrace.cat_transaction_key in headers - else: - assert "newrelic" not in headers - assert ExternalTrace.cat_id_key not in headers - assert ExternalTrace.cat_transaction_key not in headers - - def _validate(): - pass - - # if cat_enabled or distributed_tracing: - # _validate = validate_cross_process_headers(_validate) - - _validate() - - @override_application_settings( - { - # "cross_application_tracer.enabled": cat_enabled, - "distributed_tracing.enabled": distributed_tracing, - "span_events.enabled": span_events, - } - ) - def test(): - event_loop.run_until_complete(_test()) - - test() - - -_nr_key = ExternalTrace.cat_id_key -_customer_headers_tests = [{"Test-Header": "Test Data 1"}, {_nr_key.title(): "Test Data 2"}] - - -@pytest.mark.parametrize("customer_headers", _customer_headers_tests) -def test_outbound_cross_process_headers_custom_headers(event_loop, customer_headers, mock_header_server): - headers = event_loop.run_until_complete( - background_task()(fetch)(f"http://127.0.0.1:{mock_header_server.port}", customer_headers.copy()) - ) - - # always honor customer headers - for expected_header, expected_value in customer_headers.items(): - assert headers.get(expected_header) == expected_value - - -def test_outbound_cross_process_headers_no_txn(event_loop, mock_header_server): - headers = event_loop.run_until_complete(fetch(f"http://127.0.0.1:{mock_header_server.port}")) - - assert not headers.get(ExternalTrace.cat_id_key) - assert not headers.get(ExternalTrace.cat_transaction_key) - - -def test_outbound_cross_process_headers_exception(event_loop, mock_header_server): - @background_task(name="test_outbound_cross_process_headers_exception") - async def test(): - # corrupt the transaction object to force an error - transaction = current_transaction() - guid = transaction.guid - delattr(transaction, "guid") - - try: - headers = await fetch(f"http://127.0.0.1:{mock_header_server.port}") - - assert not headers.get(ExternalTrace.cat_id_key) - assert not headers.get(ExternalTrace.cat_transaction_key) - finally: - transaction.guid = guid - - event_loop.run_until_complete(test()) - - -class PoorResolvingConnector(aiohttp.TCPConnector): - async def _resolve_host(self, host, port, *args, **kwargs): - res = [{"hostname": host, "host": host, "port": 1234, "family": self._family, "proto": 0, "flags": 0}] - hosts = await super()._resolve_host(host, port, *args, **kwargs) - res.extend(hosts) - return res - - -# @pytest.mark.parametrize("cat_enabled", [True, False]) -@pytest.mark.parametrize("response_code", [200, 404]) -@pytest.mark.parametrize("raise_for_status", [True, False]) -@pytest.mark.parametrize("connector_class", [None, PoorResolvingConnector]) # None will use default -def test_process_incoming_headers( - event_loop, response_code, raise_for_status, connector_class, mock_external_http_server - # event_loop, cat_enabled, response_code, raise_for_status, connector_class, mock_external_http_server -): - # It was discovered via packnsend that the `throw` method of the `_request` - # coroutine is used in the case of poorly resolved hosts. An older version - # of the instrumentation ended the ExternalTrace anytime `throw` was called - # which meant that incoming CAT headers were never processed. The - # `PoorResolvingConnector` connector in this test ensures that `throw` is - # always called and thus makes sure the trace is not ended before - # StopIteration is called. - server, response_values = mock_external_http_server - address = f"http://127.0.0.1:{server.port}" - port = server.port - - _test_cross_process_response_scoped_metrics = [ - (f"ExternalTransaction/127.0.0.1:{port}/1#2/test", None) - ] - - _test_cross_process_response_rollup_metrics = [ - ("External/all", 1), - ("External/allOther", 1), - (f"External/127.0.0.1:{port}/all", 1), - (f"ExternalApp/127.0.0.1:{port}/1#2/all", None), - (f"ExternalTransaction/127.0.0.1:{port}/1#2/test", None), - ] - - _test_cross_process_response_external_node_params = [ - ("cross_process_id", "1#2"), - ("external_txn_name", "test"), - ("transaction_guid", "0123456789012345"), - ] - - _test_cross_process_response_external_node_forgone_params = [ - k for k, v in _test_cross_process_response_external_node_params - ] - - @background_task(name="test_process_incoming_headers") - async def _test(): - transaction = current_transaction() - headers = create_incoming_headers(transaction) - - response_values.append((headers, response_code)) - - connector = connector_class() if connector_class else None - - await fetch(address, raise_for_status=raise_for_status, connector=connector) - - @override_application_settings( - {"distributed_tracing.enabled": False} - ) - @validate_transaction_metrics( - "test_process_incoming_headers", - scoped_metrics=_test_cross_process_response_scoped_metrics, - rollup_metrics=_test_cross_process_response_rollup_metrics, - background_task=True, - ) - @validate_external_node_params( - params=[], - forgone_params=_test_cross_process_response_external_node_forgone_params, - ) - def test(): - event_loop.run_until_complete(_test()) - - test() diff --git a/tests/framework_aiohttp/test_server_cat.py b/tests/framework_aiohttp/test_server_cat.py deleted file mode 100644 index 9d4cf581ce..0000000000 --- a/tests/framework_aiohttp/test_server_cat.py +++ /dev/null @@ -1,222 +0,0 @@ -# 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 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.encoding_utils import deobfuscate -from newrelic.common.object_wrapper import transient_function_wrapper - -ENCODING_KEY = "1234567890123456789012345678901234567890" -test_uris = [ - ("/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 - except ImportError: - - def pass_through(function): - return function - - return pass_through - - @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") - - # This is the request, not the response - if line.startswith("GET"): - break - - if ":" in line: - key, value = line.split(":", maxsplit=1) - raw_headers[key.strip()] = value.strip() - - return wrapped(*args, **kwargs) - - return recorder - - -@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 -): - _raw_headers = {} - - async def fetch(): - headers = make_cross_agent_headers(inbound_payload, ENCODING_KEY, cat_id) - resp = await 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} - - if expected_intrinsics: - # test valid CAT response header - assert "X-NewRelic-App-Data" in raw_headers - - app_data = json.loads(deobfuscate(raw_headers["X-NewRelic-App-Data"], ENCODING_KEY)) - assert app_data[0] == cat_id - assert app_data[1] == f"WebTransaction/Function/{metric_name}" - else: - 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, - } - - # NOTE: the logic-flow of this test can be a bit confusing. - # the override settings and attribute validation occur - # not when the request is made (above) since it does not - # occur inside a transaction. instead, the settings and - # validation are for the new transaction that is made - # asynchronously on the *server side* when the request - # is received and subsequently processed. that code is - # a fixture from conftest.py/_target_application.py - - @validate_analytics_catmap_data( - f"WebTransaction/Function/{metric_name}", - expected_attributes=expected_intrinsics, - non_expected_attributes=forgone_intrinsics, - ) - @override_application_settings(_custom_settings) - @record_aiohttp1_raw_headers(_raw_headers) - def _test(): - aiohttp_app.loop.run_until_complete(fetch()) - - _test() - - -account_id = "33" -primary_application_id = "2827902" - -inbound_payload = { - "v": [0, 1], - "d": { - "ac": account_id, - "ap": primary_application_id, - "id": "7d3efb1b173fecfa", - "tx": "e8b91a159289ff74", - "pr": 1.234567, - "sa": True, - "ti": 1518469636035, - "tr": "d6b4ba0c3a712ca", - "ty": "App", - }, -} - -expected_attributes = { - "agent": [], - "user": [], - "intrinsic": { - "traceId": "d6b4ba0c3a712ca", - "priority": 1.234567, - "sampled": True, - "parent.type": "App", - "parent.app": primary_application_id, - "parent.account": account_id, - "parent.transportType": "HTTP", - "parentId": "e8b91a159289ff74", - "parentSpanId": "7d3efb1b173fecfa", - }, -} - -# unexpected_attributes = { -# "agent": [], -# "user": [], -# "intrinsic": ["grandparentId", "cross_process_id", "nr.tripId", "nr.pathHash"], -# } - - -@pytest.mark.parametrize("uri,metric_name", test_uris) -def test_distributed_tracing_headers(uri, metric_name, aiohttp_app): - async def fetch(): - headers = {"newrelic": json.dumps(inbound_payload)} - resp = await aiohttp_app.client.request("GET", uri, headers=headers) - - # # better cat does not send a response in the 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 - - # NOTE: the logic-flow of this test can be a bit confusing. - # the override settings and attribute validation occur - # not when the request is made (above) since it does not - # occur inside a transaction. instead, the settings and - # validation are for the new transaction that is made - # asynchronously on the *server side* when the request - # is received and subsequently processed. that code is - # a fixture from conftest.py/_target_application.py - - @validate_transaction_event_attributes(expected_attributes) - # @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()) - - _test() diff --git a/tests/framework_aiohttp/test_server_dt.py b/tests/framework_aiohttp/test_server_dt.py new file mode 100644 index 0000000000..307eade547 --- /dev/null +++ b/tests/framework_aiohttp/test_server_dt.py @@ -0,0 +1,222 @@ +# 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 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.encoding_utils import deobfuscate +# from newrelic.common.object_wrapper import transient_function_wrapper + +# ENCODING_KEY = "1234567890123456789012345678901234567890" +test_uris = [ + ("/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 +# except ImportError: + +# def pass_through(function): +# return function + +# return pass_through + +# @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") + +# # This is the request, not the response +# if line.startswith("GET"): +# break + +# if ":" in line: +# key, value = line.split(":", maxsplit=1) +# raw_headers[key.strip()] = value.strip() + +# return wrapped(*args, **kwargs) + +# return recorder + + +# @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 +# ): +# _raw_headers = {} + +# async def fetch(): +# headers = make_cross_agent_headers(inbound_payload, ENCODING_KEY, cat_id) +# resp = await 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} + +# if expected_intrinsics: +# # test valid CAT response header +# assert "X-NewRelic-App-Data" in raw_headers + +# app_data = json.loads(deobfuscate(raw_headers["X-NewRelic-App-Data"], ENCODING_KEY)) +# assert app_data[0] == cat_id +# assert app_data[1] == f"WebTransaction/Function/{metric_name}" +# else: +# 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, +# } + +# # NOTE: the logic-flow of this test can be a bit confusing. +# # the override settings and attribute validation occur +# # not when the request is made (above) since it does not +# # occur inside a transaction. instead, the settings and +# # validation are for the new transaction that is made +# # asynchronously on the *server side* when the request +# # is received and subsequently processed. that code is +# # a fixture from conftest.py/_target_application.py + +# @validate_analytics_catmap_data( +# f"WebTransaction/Function/{metric_name}", +# expected_attributes=expected_intrinsics, +# non_expected_attributes=forgone_intrinsics, +# ) +# @override_application_settings(_custom_settings) +# @record_aiohttp1_raw_headers(_raw_headers) +# def _test(): +# aiohttp_app.loop.run_until_complete(fetch()) + +# _test() + + +account_id = "33" +primary_application_id = "2827902" + +inbound_payload = { + "v": [0, 1], + "d": { + "ac": account_id, + "ap": primary_application_id, + "id": "7d3efb1b173fecfa", + "tx": "e8b91a159289ff74", + "pr": 1.234567, + "sa": True, + "ti": 1518469636035, + "tr": "d6b4ba0c3a712ca", + "ty": "App", + }, +} + +expected_attributes = { + "agent": [], + "user": [], + "intrinsic": { + "traceId": "d6b4ba0c3a712ca", + "priority": 1.234567, + "sampled": True, + "parent.type": "App", + "parent.app": primary_application_id, + "parent.account": account_id, + "parent.transportType": "HTTP", + "parentId": "e8b91a159289ff74", + "parentSpanId": "7d3efb1b173fecfa", + }, +} + +# unexpected_attributes = { +# "agent": [], +# "user": [], +# "intrinsic": ["grandparentId", "cross_process_id", "nr.tripId", "nr.pathHash"], +# } + + +@pytest.mark.parametrize("uri,metric_name", test_uris) +def test_distributed_tracing_headers(uri, metric_name, aiohttp_app): + async def fetch(): + headers = {"newrelic": json.dumps(inbound_payload)} + resp = await aiohttp_app.client.request("GET", uri, headers=headers) + + # # better cat does not send a response in the 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 + + # NOTE: the logic-flow of this test can be a bit confusing. + # the override settings and attribute validation occur + # not when the request is made (above) since it does not + # occur inside a transaction. instead, the settings and + # validation are for the new transaction that is made + # asynchronously on the *server side* when the request + # is received and subsequently processed. that code is + # a fixture from conftest.py/_target_application.py + + @validate_transaction_event_attributes(expected_attributes) + # @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()) + + _test() From 01da681d1dedfc29ae847c6dfbc0c560409c964a Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Tue, 9 Sep 2025 17:54:47 -0700 Subject: [PATCH 07/95] Fix httpx tests --- tests/external_httpx/test_client.py | 112 +++++++++++++++------------- 1 file changed, 61 insertions(+), 51 deletions(-) diff --git a/tests/external_httpx/test_client.py b/tests/external_httpx/test_client.py index a3b1d080f9..178edd3dd7 100644 --- a/tests/external_httpx/test_client.py +++ b/tests/external_httpx/test_client.py @@ -32,33 +32,43 @@ SCOPED_METRICS = [] ROLLUP_METRICS = [("External/all", 2), ("External/allOther", 2)] -CAT_RESPONSE_CODE = None - - -def cat_response_handler(self): - if not CAT_RESPONSE_CODE: - raise ValueError("CAT_RESPONSE_CODE must be a valid status_code.") - - # payload - # ( - # u'1#1', u'WebTransaction/Function/app:beep', - # 0, 1.23, -1, - # 'dd4a810b7cb7f937', - # False, - # ) - cat_response_header = ( - "X-NewRelic-App-Data", - "ahACFwQUGxpuVVNmQVVbRVZbTVleXBxyQFhUTFBfXx1SREUMVV1cQBMeAxgEGAULFR0AHhFQUQJWAAgAUwVQVgJQDgsOEh1UUlhGU2o=", - ) - self.send_response(CAT_RESPONSE_CODE) - self.send_header(*cat_response_header) +DT_RESPONSE_CODE = None + + +# def cat_response_handler(self): +# if not DT_RESPONSE_CODE: +# raise ValueError("DT_RESPONSE_CODE must be a valid status_code.") + +# # payload +# # ( +# # u'1#1', u'WebTransaction/Function/app:beep', +# # 0, 1.23, -1, +# # 'dd4a810b7cb7f937', +# # False, +# # ) +# cat_response_header = ( +# "X-NewRelic-App-Data", +# "ahACFwQUGxpuVVNmQVVbRVZbTVleXBxyQFhUTFBfXx1SREUMVV1cQBMeAxgEGAULFR0AHhFQUQJWAAgAUwVQVgJQDgsOEh1UUlhGU2o=", +# ) +# self.send_response(DT_RESPONSE_CODE) +# self.send_header(*cat_response_header) +# self.end_headers() +# self.wfile.write(b"Example Data") + +def dt_response_handler(self): + if not DT_RESPONSE_CODE: + raise ValueError("DT_RESPONSE_CODE must be a valid status_code.") + + response = str(self.headers).encode("utf-8") # Might need to put headers here + self.send_response(DT_RESPONSE_CODE) self.end_headers() - self.wfile.write(b"Example Data") + self.wfile.write(response) @pytest.fixture(scope="session") def mock_server(): - external = MockExternalHTTPHResponseHeadersServer(handler=cat_response_handler) + # external = MockExternalHTTPHResponseHeadersServer(handler=cat_response_handler) + external = MockExternalHTTPHResponseHeadersServer(handler=dt_response_handler) with external: yield external @@ -85,8 +95,8 @@ def exercise_sync_client(server, client, method, protocol="http"): ) @background_task(name="test_sync_client") def test_sync_client(httpx, sync_client, mock_server, method): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = 200 + global DT_RESPONSE_CODE + DT_RESPONSE_CODE = 200 assert exercise_sync_client(mock_server, sync_client, method).status_code == 200 @@ -108,8 +118,8 @@ async def exercise_async_client(server, client, method, protocol="http"): ) @background_task(name="test_async_client") def test_async_client(httpx, async_client, mock_server, loop, method): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = 200 + global DT_RESPONSE_CODE + DT_RESPONSE_CODE = 200 responses = loop.run_until_complete(exercise_async_client(mock_server, async_client, method)) assert all(response.status_code == 200 for response in responses) @@ -117,8 +127,8 @@ def test_async_client(httpx, async_client, mock_server, loop, method): @pytest.mark.parametrize("distributed_tracing,span_events", ((True, True), (True, False), (False, False))) def test_sync_cross_process_request(httpx, sync_client, mock_server, distributed_tracing, span_events): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = 200 + global DT_RESPONSE_CODE + DT_RESPONSE_CODE = 200 @override_application_settings( { @@ -148,8 +158,8 @@ def _test(): @background_task(name="test_async_cross_process_request") @validate_cross_process_headers def test_async_cross_process_request(httpx, async_client, mock_server, loop, distributed_tracing, span_events): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = 200 + global DT_RESPONSE_CODE + DT_RESPONSE_CODE = 200 @override_application_settings( {"distributed_tracing.enabled": distributed_tracing, "span_events.enabled": span_events} @@ -168,13 +178,13 @@ async def _test(): @override_application_settings( - {"distributed_tracing.enabled": True, "span_events.enabled": True, "cross_application_tracer.enabled": True} + {"distributed_tracing.enabled": True, "span_events.enabled": True} #, "cross_application_tracer.enabled": True} ) @validate_transaction_errors(errors=[]) @background_task(name="test_sync_cross_process_override_headers") def test_sync_cross_process_override_headers(httpx, sync_client, mock_server, loop): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = 200 + global DT_RESPONSE_CODE + DT_RESPONSE_CODE = 200 transaction = current_transaction() @@ -191,8 +201,8 @@ def test_sync_cross_process_override_headers(httpx, sync_client, mock_server, lo @validate_transaction_errors(errors=[]) @background_task(name="test_async_cross_process_override_headers") def test_async_cross_process_override_headers(httpx, async_client, mock_server, loop): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = 200 + global DT_RESPONSE_CODE + DT_RESPONSE_CODE = 200 async def _test(): async with async_client: @@ -289,8 +299,8 @@ async def _test(): @dt_enabled def test_sync_client_event_hook_exception(httpx, mock_server): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = 500 + global DT_RESPONSE_CODE + DT_RESPONSE_CODE = 500 def exception_event_hook(response): if response.status_code >= 400: @@ -302,7 +312,7 @@ def empty_hook(response): @validate_span_events( count=1, exact_intrinsics={"name": f"External/localhost:{mock_server.port}/httpx/GET"}, - exact_agents={"http.statusCode": CAT_RESPONSE_CODE}, + exact_agents={"http.statusCode": DT_RESPONSE_CODE}, ) @background_task(name="test_sync_client_event_hook_exception") def make_request(client, exc_expected=True): @@ -335,8 +345,8 @@ def make_request(client, exc_expected=True): @override_application_settings({"distributed_tracing.enabled": True, "span_events.enabled": True}) def test_async_client_event_hook_exception(httpx, mock_server, loop): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = 500 + global DT_RESPONSE_CODE + DT_RESPONSE_CODE = 500 def exception_event_hook(response): if response.status_code >= 400: @@ -348,7 +358,7 @@ def empty_hook(response): @validate_span_events( count=1, exact_intrinsics={"name": f"External/localhost:{mock_server.port}/httpx/GET"}, - exact_agents={"http.statusCode": CAT_RESPONSE_CODE}, + exact_agents={"http.statusCode": DT_RESPONSE_CODE}, ) @background_task(name="test_sync_client_event_hook_exception") def make_request(client, exc_expected=True): @@ -385,8 +395,8 @@ def _test(): @override_generic_settings(global_settings(), {"enabled": False}) def test_sync_nr_disabled(httpx, mock_server): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = 200 + global DT_RESPONSE_CODE + DT_RESPONSE_CODE = 200 with httpx.Client() as client: trace = current_trace() @@ -398,8 +408,8 @@ def test_sync_nr_disabled(httpx, mock_server): @override_generic_settings(global_settings(), {"enabled": False}) def test_async_nr_disabled(httpx, mock_server, loop): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = 200 + global DT_RESPONSE_CODE + DT_RESPONSE_CODE = 200 async def _test(): async with httpx.AsyncClient() as client: @@ -415,8 +425,8 @@ async def _test(): @pytest.mark.parametrize("client", ("Client", "AsyncClient")) def test_invalid_import_order_client(monkeypatch, httpx, mock_server, loop, client): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = 200 + global DT_RESPONSE_CODE + DT_RESPONSE_CODE = 200 if "Async" in client: is_async = True @@ -447,8 +457,8 @@ def test_invalid_import_order_client(monkeypatch, httpx, mock_server, loop, clie ) @background_task(name="test_sync_client_http2") def test_sync_client_http2(httpx, real_server): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = 200 + global DT_RESPONSE_CODE + DT_RESPONSE_CODE = 200 client = httpx.Client(http1=False, http2=True, verify=False) response = exercise_sync_client(real_server, client, "get", protocol="https") @@ -462,8 +472,8 @@ def test_sync_client_http2(httpx, real_server): ) @background_task(name="test_async_client_http2") def test_async_client_http2(httpx, real_server, loop): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = 200 + global DT_RESPONSE_CODE + DT_RESPONSE_CODE = 200 client = httpx.AsyncClient(http1=False, http2=True, verify=False) From e3389f3e61ffaceab7ad846bf9e8ed03b3548521 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 12:35:02 -0700 Subject: [PATCH 08/95] Fix pika tests --- newrelic/api/cat_header_mixin.py | 8 +- newrelic/hooks/messagebroker_pika.py | 12 +- tests/messagebroker_pika/test_cat.py | 137 ------------------ .../test_distributed_tracing.py | 8 +- tests/messagebroker_pika/test_pika_produce.py | 2 +- 5 files changed, 15 insertions(+), 152 deletions(-) delete mode 100644 tests/messagebroker_pika/test_cat.py diff --git a/newrelic/api/cat_header_mixin.py b/newrelic/api/cat_header_mixin.py index 8008423778..a98441c7e2 100644 --- a/newrelic/api/cat_header_mixin.py +++ b/newrelic/api/cat_header_mixin.py @@ -106,10 +106,10 @@ def generate_request_headers(cls, transaction): # encoded_transaction = obfuscate(json_encode(transaction_data), settings.encoding_key) # nr_headers.append((cls.cat_transaction_key, encoded_transaction)) - if transaction.synthetics_header: - nr_headers.append((cls.cat_synthetics_key, transaction.synthetics_header)) - if transaction.synthetics_info_header: - nr_headers.append((cls.cat_synthetics_info_key, transaction.synthetics_info_header)) + # if transaction.synthetics_header: + # nr_headers.append((cls.cat_synthetics_key, transaction.synthetics_header)) + # if transaction.synthetics_info_header: + # nr_headers.append((cls.cat_synthetics_info_key, transaction.synthetics_info_header)) return nr_headers diff --git a/newrelic/hooks/messagebroker_pika.py b/newrelic/hooks/messagebroker_pika.py index 821d05a318..6e4f812c3e 100644 --- a/newrelic/hooks/messagebroker_pika.py +++ b/newrelic/hooks/messagebroker_pika.py @@ -62,9 +62,9 @@ def _add_consume_rabbitmq_trace(transaction, method, properties, nr_start_time, # Do not record dt headers in the segment parameters if headers: - headers.pop(MessageTrace.cat_id_key, None) - headers.pop(MessageTrace.cat_transaction_key, None) - headers.pop(MessageTrace.cat_distributed_trace_key, None) + # headers.pop(MessageTrace.cat_id_key, None) + # headers.pop(MessageTrace.cat_transaction_key, None) + # headers.pop(MessageTrace.cat_distributed_trace_key, None) headers.pop("traceparent", None) headers.pop("tracestate", None) @@ -124,9 +124,9 @@ def _nr_wrapper_basic_publish(wrapped, instance, args, kwargs): user_headers = properties.headers.copy() # Do not record dt headers in the segment parameters - user_headers.pop(MessageTrace.cat_id_key, None) - user_headers.pop(MessageTrace.cat_transaction_key, None) - user_headers.pop(MessageTrace.cat_distributed_trace_key, None) + # user_headers.pop(MessageTrace.cat_id_key, None) + # user_headers.pop(MessageTrace.cat_transaction_key, None) + # user_headers.pop(MessageTrace.cat_distributed_trace_key, None) user_headers.pop("traceparent", None) user_headers.pop("tracestate", None) diff --git a/tests/messagebroker_pika/test_cat.py b/tests/messagebroker_pika/test_cat.py deleted file mode 100644 index e4d9ea1c59..0000000000 --- a/tests/messagebroker_pika/test_cat.py +++ /dev/null @@ -1,137 +0,0 @@ -# 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 os -import random -import string - -import pika -from compat import basic_consume -from testing_support.db_settings import rabbitmq_settings -from testing_support.fixtures import override_application_settings -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 - -DB_SETTINGS = rabbitmq_settings()[0] - -ENCODING_KEY = "".join(random.choice(string.ascii_lowercase) for _ in range(40)) -_override_settings = { - "cross_process_id": "1#1", - "encoding_key": ENCODING_KEY, - "trusted_account_ids": [1], - "browser_monitoring.enabled": False, -} - - -@background_task() -def do_basic_publish(channel, QUEUE, properties=None): - channel.basic_publish(exchange="", routing_key=QUEUE, body="Testing CAT 123", properties=properties) - - -_test_cat_basic_consume_scoped_metrics = [ - ("MessageBroker/RabbitMQ/Exchange/Produce/Named/Default", None), - ("MessageBroker/RabbitMQ/Exchange/Consume/Named/Default", None), -] -_test_cat_basic_consume_rollup_metrics = list(_test_cat_basic_consume_scoped_metrics) -_test_cat_basic_consume_rollup_metrics.append(("ClientApplication/1#1/all", 1)) - - -@validate_transaction_metrics( - "test_cat:test_basic_consume_cat_headers..on_receive", - scoped_metrics=_test_cat_basic_consume_scoped_metrics, - rollup_metrics=_test_cat_basic_consume_rollup_metrics, - background_task=True, - group="Message/RabbitMQ/Exchange/Default", -) -def do_basic_consume(channel): - channel.start_consuming() - - -# @cat_enabled -@override_application_settings(_override_settings) -def test_basic_consume_cat_headers(): - def on_receive(ch, method, properties, msg): - headers = properties.headers - assert headers - assert "NewRelicID" not in headers - assert "NewRelicTransaction" not in headers - assert msg == b"Testing CAT 123" - txn = current_transaction() - assert txn.client_cross_process_id == "1#1" - assert txn.client_account_id == 1 - assert txn.client_application_id == 1 - ch.stop_consuming() - - with pika.BlockingConnection(pika.ConnectionParameters(DB_SETTINGS["host"])) as connection: - channel = connection.channel() - queue_name = f"TESTCAT-{os.getpid()}" - channel.queue_declare(queue_name, durable=False) - - properties = pika.BasicProperties() - properties.headers = {"Hello": "World"} - - try: - basic_consume(channel, queue_name, on_receive, auto_ack=False) - do_basic_publish(channel, queue_name, properties=properties) - do_basic_consume(channel) - - finally: - channel.queue_delete(queue_name) - - -_test_cat_basic_get_metrics = [ - ("MessageBroker/RabbitMQ/Exchange/Produce/Named/Default", None), - ("MessageBroker/RabbitMQ/Exchange/Consume/Named/Default", 1), - # Verify basic_get doesn't create a CAT metric - ("ClientApplication/1#1/all", None), -] - - -@validate_transaction_metrics( - "test_cat:do_basic_get", - scoped_metrics=_test_cat_basic_get_metrics, - rollup_metrics=_test_cat_basic_get_metrics, - background_task=True, -) -@background_task() -def do_basic_get(channel, QUEUE): - _, properties, msg = channel.basic_get(QUEUE) - headers = properties.headers - assert headers - assert "NewRelicID" not in headers - assert "NewRelicTransaction" not in headers - assert msg == b"Testing CAT 123" - txn = current_transaction() - assert txn.client_cross_process_id is None - assert txn.client_account_id is None - assert txn.client_application_id is None - - -@override_application_settings(_override_settings) -def test_basic_get_no_cat_headers(): - with pika.BlockingConnection(pika.ConnectionParameters(DB_SETTINGS["host"])) as connection: - channel = connection.channel() - queue_name = f"TESTCAT-{os.getpid()}" - channel.queue_declare(queue_name, durable=False) - - properties = pika.BasicProperties() - properties.headers = {"Hello": "World"} - - try: - do_basic_publish(channel, queue_name, properties=properties) - do_basic_get(channel, queue_name) - finally: - channel.queue_delete(queue_name) diff --git a/tests/messagebroker_pika/test_distributed_tracing.py b/tests/messagebroker_pika/test_distributed_tracing.py index ee8a643ced..f23e3e43a6 100644 --- a/tests/messagebroker_pika/test_distributed_tracing.py +++ b/tests/messagebroker_pika/test_distributed_tracing.py @@ -81,8 +81,8 @@ def test_basic_consume_distributed_tracing_headers(): def on_receive(ch, method, properties, msg): headers = properties.headers assert headers - assert "NewRelicID" not in headers - assert "NewRelicTransaction" not in headers + # assert "NewRelicID" not in headers + # assert "NewRelicTransaction" not in headers assert msg == b"Testing distributed_tracing 123" txn = current_transaction() @@ -134,8 +134,8 @@ def do_basic_get(channel, QUEUE): headers = properties.headers assert headers - assert "NewRelicID" not in headers - assert "NewRelicTransaction" not in headers + # assert "NewRelicID" not in headers + # assert "NewRelicTransaction" not in headers assert msg == b"Testing distributed_tracing 123" txn = current_transaction() diff --git a/tests/messagebroker_pika/test_pika_produce.py b/tests/messagebroker_pika/test_pika_produce.py index 1d8a01c6ec..ad6607de9c 100644 --- a/tests/messagebroker_pika/test_pika_produce.py +++ b/tests/messagebroker_pika/test_pika_produce.py @@ -164,7 +164,7 @@ def test_blocking_connection_reply_to(producer): _message_broker_tt_included_test_headers = _message_broker_tt_included_params.copy() -_message_broker_tt_included_test_headers.update({"headers": HEADERS.copy()}) +# _message_broker_tt_included_test_headers.update({"headers": HEADERS.copy()}) _message_broker_tt_forgone_test_headers = ["queue_name", "correlation_id", "reply_to"] From a32ca513e95b0f42ecf3aa1c134241594a13562e Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 13:23:41 -0700 Subject: [PATCH 09/95] Fix sanic tests --- tests/framework_sanic/conftest.py | 2 +- .../framework_sanic/test_cross_application.py | 141 ------------------ .../framework_sanic/test_distributed_trace.py | 141 ++++++++++++++++++ 3 files changed, 142 insertions(+), 142 deletions(-) delete mode 100644 tests/framework_sanic/test_cross_application.py create mode 100644 tests/framework_sanic/test_distributed_trace.py diff --git a/tests/framework_sanic/conftest.py b/tests/framework_sanic/conftest.py index 08c8bec3bb..8802638beb 100644 --- a/tests/framework_sanic/conftest.py +++ b/tests/framework_sanic/conftest.py @@ -17,7 +17,7 @@ import pytest from testing_support.fixtures import collector_agent_registration_fixture, collector_available_fixture -from newrelic.common.object_wrapper import transient_function_wrapper +# from newrelic.common.object_wrapper import transient_function_wrapper _default_settings = { "package_reporting.enabled": False, # Turn off package reporting for testing as it causes slow downs. diff --git a/tests/framework_sanic/test_cross_application.py b/tests/framework_sanic/test_cross_application.py deleted file mode 100644 index 60e1980533..0000000000 --- a/tests/framework_sanic/test_cross_application.py +++ /dev/null @@ -1,141 +0,0 @@ -# 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 json -import random - -# import re -import string - -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 newrelic.common.encoding_utils import deobfuscate - -BASE_METRICS = [("Function/_target_application:index", 1)] -DT_METRICS = [ - ("Supportability/DistributedTrace/AcceptPayload/Success", None), - ("Supportability/TraceContext/TraceParent/Accept/Success", 1), -] -BASE_ATTRS = ["response.status", "response.headers.contentType", "response.headers.contentLength"] - - -def raw_headers(response): - try: - # Manually encode into bytes - return " ".join(f"{k}: {v}" for k, v in response.processed_headers).encode() - except AttributeError: - try: - return response.get_headers() - except AttributeError: - return response.output() - - -@validate_transaction_metrics( - "_target_application:index", scoped_metrics=BASE_METRICS, rollup_metrics=BASE_METRICS + DT_METRICS -) -@override_application_settings({"distributed_tracing.enabled": True}) -@validate_transaction_event_attributes(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)) - assert response.status == 200 - - -ENCODING_KEY = "".join(random.choice(string.ascii_lowercase) for _ in range(40)) -_cat_response_header_urls_to_test = ( - ("/", "_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, -} - - -@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): - _base_metrics = [(f"Function/{metric_name}", 1)] - - @validate_transaction_metrics(metric_name, scoped_metrics=_base_metrics, rollup_metrics=_base_metrics) - @validate_analytics_catmap_data( - f"WebTransaction/Function/{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)) - if expected_intrinsics: - # test valid CAT response header - 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)) - assert app_data[0] == cat_id - assert app_data[1] == f"WebTransaction/Function/{metric_name}" - else: - 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", f"/custom-header/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_sanic/test_distributed_trace.py b/tests/framework_sanic/test_distributed_trace.py new file mode 100644 index 0000000000..3a92e84649 --- /dev/null +++ b/tests/framework_sanic/test_distributed_trace.py @@ -0,0 +1,141 @@ +# 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 json +# import random + +# import re +# import string + +# 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 newrelic.common.encoding_utils import deobfuscate + +BASE_METRICS = [("Function/_target_application:index", 1)] +DT_METRICS = [ + ("Supportability/DistributedTrace/AcceptPayload/Success", None), + ("Supportability/TraceContext/TraceParent/Accept/Success", 1), +] +BASE_ATTRS = ["response.status", "response.headers.contentType", "response.headers.contentLength"] + + +def raw_headers(response): + try: + # Manually encode into bytes + return " ".join(f"{k}: {v}" for k, v in response.processed_headers).encode() + except AttributeError: + try: + return response.get_headers() + except AttributeError: + return response.output() + + +@validate_transaction_metrics( + "_target_application:index", scoped_metrics=BASE_METRICS, rollup_metrics=BASE_METRICS + DT_METRICS +) +@override_application_settings({"distributed_tracing.enabled": True}) +@validate_transaction_event_attributes(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)) + assert response.status == 200 + + +# ENCODING_KEY = "".join(random.choice(string.ascii_lowercase) for _ in range(40)) +# _cat_response_header_urls_to_test = ( +# ("/", "_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, +# } + + +# @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): +# _base_metrics = [(f"Function/{metric_name}", 1)] + +# @validate_transaction_metrics(metric_name, scoped_metrics=_base_metrics, rollup_metrics=_base_metrics) +# @validate_analytics_catmap_data( +# f"WebTransaction/Function/{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)) +# if expected_intrinsics: +# # test valid CAT response header +# 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)) +# assert app_data[0] == cat_id +# assert app_data[1] == f"WebTransaction/Function/{metric_name}" +# else: +# 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", f"/custom-header/X-NewRelic-App-Data/{custom_header_value}", headers=dict(cat_headers)) +# assert custom_header_value in raw_headers(response), raw_headers(response) From 5b52a78536d013080aa5d1d88bafdbd2e5fdf33b Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 14:26:44 -0700 Subject: [PATCH 10/95] Remove more CAT tests --- tests/agent_features/test_error_events.py | 84 +++++++++++------------ tests/framework_tornado/test_externals.py | 4 +- 2 files changed, 42 insertions(+), 46 deletions(-) diff --git a/tests/agent_features/test_error_events.py b/tests/agent_features/test_error_events.py index 1e9a6116db..b96f4fe0f6 100644 --- a/tests/agent_features/test_error_events.py +++ b/tests/agent_features/test_error_events.py @@ -19,7 +19,7 @@ from testing_support.fixtures import ( # cat_enabled, # make_cross_agent_headers, - make_synthetics_headers, + # make_synthetics_headers, override_application_settings, reset_core_stats_engine, validate_error_event_sample_data, @@ -29,17 +29,17 @@ from testing_support.validators.validate_transaction_error_event_count import validate_transaction_error_event_count from newrelic.api.application import application_instance as application -from newrelic.api.application import application_settings +# from newrelic.api.application import application_settings from newrelic.api.time_trace import notice_error from newrelic.common.object_names import callable_name # Error in test app hard-coded as a ValueError -SYNTHETICS_RESOURCE_ID = "09845779-16ef-4fa7-b7f2-44da8e62931c" -SYNTHETICS_JOB_ID = "8c7dd3ba-4933-4cbb-b1ed-b62f511782f4" -SYNTHETICS_MONITOR_ID = "dc452ae9-1a93-4ab5-8a33-600521e9cd00" -SYNTHETICS_TYPE = "scheduled" -SYNTHETICS_INITIATOR = "graphql" -SYNTHETICS_ATTRIBUTES = {"exampleAttribute": "1"} +# SYNTHETICS_RESOURCE_ID = "09845779-16ef-4fa7-b7f2-44da8e62931c" +# SYNTHETICS_JOB_ID = "8c7dd3ba-4933-4cbb-b1ed-b62f511782f4" +# SYNTHETICS_MONITOR_ID = "dc452ae9-1a93-4ab5-8a33-600521e9cd00" +# SYNTHETICS_TYPE = "scheduled" +# SYNTHETICS_INITIATOR = "graphql" +# SYNTHETICS_ATTRIBUTES = {"exampleAttribute": "1"} ERR_MESSAGE = "Transaction had bad value" ERROR = ValueError(ERR_MESSAGE) @@ -108,50 +108,46 @@ def test_transaction_error_background_task(): "error.message": ERR_MESSAGE, "error.expected": False, "transactionName": "WebTransaction/Uri/", - "nr.referringTransactionGuid": 7, + # "nr.referringTransactionGuid": 7, } # @cat_enabled -# COMEBACK: Change to DT tests. @validate_error_event_sample_data(required_attrs=_intrinsic_attributes, required_user_attrs=True) -def test_transaction_error_cross_agent(): +def test_transaction_error_dt_headers(): test_environ = {"err_message": ERR_MESSAGE} - settings = application_settings() - transaction_data = [7, 1, 77, "/path-hash"] - # headers = make_cross_agent_headers(transaction_data, settings.encoding_key, settings.cross_process_id) - response = fully_featured_application.get("/", headers=headers, extra_environ=test_environ) - - -_intrinsic_attributes = { - "error.class": callable_name(ERROR), - "error.message": ERR_MESSAGE, - "error.expected": False, - "transactionName": "WebTransaction/Uri/", - "nr.syntheticsResourceId": SYNTHETICS_RESOURCE_ID, - "nr.syntheticsJobId": SYNTHETICS_JOB_ID, - "nr.syntheticsMonitorId": SYNTHETICS_MONITOR_ID, - "nr.syntheticsType": SYNTHETICS_TYPE, - "nr.syntheticsInitiator": SYNTHETICS_INITIATOR, - "nr.syntheticsExampleAttribute": "1", -} + response = fully_featured_application.get("/", extra_environ=test_environ) -@validate_error_event_sample_data(required_attrs=_intrinsic_attributes, required_user_attrs=True) -def test_transaction_error_with_synthetics(): - test_environ = {"err_message": ERR_MESSAGE} - settings = application_settings() - headers = make_synthetics_headers( - settings.encoding_key, - settings.trusted_account_ids[0], - SYNTHETICS_RESOURCE_ID, - SYNTHETICS_JOB_ID, - SYNTHETICS_MONITOR_ID, - SYNTHETICS_TYPE, - SYNTHETICS_INITIATOR, - SYNTHETICS_ATTRIBUTES, - ) - response = fully_featured_application.get("/", headers=headers, extra_environ=test_environ) +# _intrinsic_attributes = { +# "error.class": callable_name(ERROR), +# "error.message": ERR_MESSAGE, +# "error.expected": False, +# "transactionName": "WebTransaction/Uri/", +# "nr.syntheticsResourceId": SYNTHETICS_RESOURCE_ID, +# "nr.syntheticsJobId": SYNTHETICS_JOB_ID, +# "nr.syntheticsMonitorId": SYNTHETICS_MONITOR_ID, +# "nr.syntheticsType": SYNTHETICS_TYPE, +# "nr.syntheticsInitiator": SYNTHETICS_INITIATOR, +# "nr.syntheticsExampleAttribute": "1", +# } + + +# @validate_error_event_sample_data(required_attrs=_intrinsic_attributes, required_user_attrs=True) +# def test_transaction_error_with_synthetics(): +# test_environ = {"err_message": ERR_MESSAGE} +# settings = application_settings() +# headers = make_synthetics_headers( +# settings.encoding_key, +# settings.trusted_account_ids[0], +# SYNTHETICS_RESOURCE_ID, +# SYNTHETICS_JOB_ID, +# SYNTHETICS_MONITOR_ID, +# SYNTHETICS_TYPE, +# SYNTHETICS_INITIATOR, +# SYNTHETICS_ATTRIBUTES, +# ) +# response = fully_featured_application.get("/", headers=headers, extra_environ=test_environ) _intrinsic_attributes = { diff --git a/tests/framework_tornado/test_externals.py b/tests/framework_tornado/test_externals.py index 9553ca4140..5d79c0e46d 100644 --- a/tests/framework_tornado/test_externals.py +++ b/tests/framework_tornado/test_externals.py @@ -19,13 +19,13 @@ import pytest from testing_support.fixtures import override_application_settings from testing_support.mock_external_http_server import MockExternalHTTPHResponseHeadersServer, MockExternalHTTPServer -from testing_support.validators.validate_distributed_tracing_header import validate_distributed_tracing_header +# from testing_support.validators.validate_distributed_tracing_header import validate_distributed_tracing_header # from testing_support.validators.validate_outbound_headers import validate_outbound_headers 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 -from newrelic.api.transaction import current_transaction +# from newrelic.api.transaction import current_transaction ENCODING_KEY = "1234567890123456789012345678901234567890" From 931b1c6fddd8a3154596d1b04d5cc4d0a665937a Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 14:31:06 -0700 Subject: [PATCH 11/95] Remove nr.guid --- newrelic/core/transaction_node.py | 4 ++-- tests/testing_support/validators/validate_synthetics_event.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/newrelic/core/transaction_node.py b/newrelic/core/transaction_node.py index 5468065faf..d88690bed2 100644 --- a/newrelic/core/transaction_node.py +++ b/newrelic/core/transaction_node.py @@ -479,8 +479,8 @@ def _add_if_not_empty(key, value): # _add_if_not_empty("nr.alternatePathHashes", ",".join(self.alternate_path_hashes)) # _add_if_not_empty("nr.referringTransactionGuid", self.referring_transaction_guid) - if self.synthetics_resource_id: - intrinsics["nr.guid"] = self.guid + # if self.synthetics_resource_id: + # intrinsics["nr.guid"] = self.guid if self.parent_tx: intrinsics["parentId"] = self.parent_tx diff --git a/tests/testing_support/validators/validate_synthetics_event.py b/tests/testing_support/validators/validate_synthetics_event.py index 21cb062ba4..dd6fedbb86 100644 --- a/tests/testing_support/validators/validate_synthetics_event.py +++ b/tests/testing_support/validators/validate_synthetics_event.py @@ -42,7 +42,7 @@ def _flatten(event): flat_event = _flatten(event) - assert "nr.guid" in flat_event, f"name=nr.guid, event={flat_event!r}" + # assert "nr.guid" in flat_event, f"name=nr.guid, event={flat_event!r}" for name, value in required_attrs: assert name in flat_event, f"name={name!r}, event={flat_event!r}" From c9e727859cc53c52502e5bb4fbdd682f031ee15c Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 16:51:14 -0700 Subject: [PATCH 12/95] Rename synthetics in CatHeaderMixin --- newrelic/api/cat_header_mixin.py | 14 +++++++------- newrelic/api/message_trace.py | 10 +++++----- newrelic/core/transaction_node.py | 10 +++++----- newrelic/hooks/messagebroker_pika.py | 4 ++-- tests/agent_features/test_attributes_in_action.py | 2 +- tests/messagebroker_pika/test_pika_produce.py | 2 +- tests/testing_support/fixtures.py | 12 ++++++------ 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/newrelic/api/cat_header_mixin.py b/newrelic/api/cat_header_mixin.py index a98441c7e2..1d1055ed4e 100644 --- a/newrelic/api/cat_header_mixin.py +++ b/newrelic/api/cat_header_mixin.py @@ -27,10 +27,10 @@ class CatHeaderMixin: # cat_id_key = "X-NewRelic-ID" # cat_transaction_key = "X-NewRelic-Transaction" # cat_appdata_key = "X-NewRelic-App-Data" - # cat_synthetics_key = "X-NewRelic-Synthetics" - # cat_synthetics_info_key = "X-NewRelic-Synthetics-Info" + synthetics_key = "X-NewRelic-Synthetics" + synthetics_info_key = "X-NewRelic-Synthetics-Info" # cat_metadata_key = "x-newrelic-trace" - # cat_distributed_trace_key = "newrelic" + distributed_trace_key = "newrelic" settings = None def __enter__(self): @@ -106,10 +106,10 @@ def generate_request_headers(cls, transaction): # encoded_transaction = obfuscate(json_encode(transaction_data), settings.encoding_key) # nr_headers.append((cls.cat_transaction_key, encoded_transaction)) - # if transaction.synthetics_header: - # nr_headers.append((cls.cat_synthetics_key, transaction.synthetics_header)) - # if transaction.synthetics_info_header: - # nr_headers.append((cls.cat_synthetics_info_key, transaction.synthetics_info_header)) + if transaction.synthetics_header: + nr_headers.append((cls.synthetics_key, transaction.synthetics_header)) + if transaction.synthetics_info_header: + nr_headers.append((cls.synthetics_info_key, transaction.synthetics_info_header)) return nr_headers diff --git a/newrelic/api/message_trace.py b/newrelic/api/message_trace.py index 5f6f9a76d0..0514b2d941 100644 --- a/newrelic/api/message_trace.py +++ b/newrelic/api/message_trace.py @@ -22,11 +22,11 @@ class MessageTrace(CatHeaderMixin, TimeTrace): - cat_id_key = "NewRelicID" - cat_transaction_key = "NewRelicTransaction" - cat_appdata_key = "NewRelicAppData" - cat_synthetics_key = "NewRelicSynthetics" - cat_synthetics_info_key = "NewRelicSyntheticsInfo" + # cat_id_key = "NewRelicID" + # cat_transaction_key = "NewRelicTransaction" + # cat_appdata_key = "NewRelicAppData" + synthetics_key = "NewRelicSynthetics" + synthetics_info_key = "NewRelicSyntheticsInfo" def __init__(self, library, operation, destination_type, destination_name, params=None, terminal=True, **kwargs): parent = kwargs.pop("parent", None) diff --git a/newrelic/core/transaction_node.py b/newrelic/core/transaction_node.py index d88690bed2..020993e0c9 100644 --- a/newrelic/core/transaction_node.py +++ b/newrelic/core/transaction_node.py @@ -465,7 +465,7 @@ def _add_if_not_empty(key, value): apdex_perf_zone = self.apdex_perf_zone() _add_if_not_empty("apdexPerfZone", apdex_perf_zone) - _add_if_not_empty("nr.apdexPerfZone", apdex_perf_zone) + # _add_if_not_empty("nr.apdexPerfZone", apdex_perf_zone) if self.errors: intrinsics["error"] = True @@ -541,10 +541,10 @@ def error_event_intrinsics(self, error, stats_table): intrinsics["transactionName"] = self.path intrinsics["spanId"] = error.span_id - intrinsics["nr.transactionGuid"] = self.guid - if self.referring_transaction_guid: - guid = self.referring_transaction_guid - intrinsics["nr.referringTransactionGuid"] = guid + # intrinsics["nr.transactionGuid"] = self.guid + # if self.referring_transaction_guid: + # guid = self.referring_transaction_guid + # intrinsics["nr.referringTransactionGuid"] = guid return intrinsics diff --git a/newrelic/hooks/messagebroker_pika.py b/newrelic/hooks/messagebroker_pika.py index 6e4f812c3e..3e673f277a 100644 --- a/newrelic/hooks/messagebroker_pika.py +++ b/newrelic/hooks/messagebroker_pika.py @@ -64,7 +64,7 @@ def _add_consume_rabbitmq_trace(transaction, method, properties, nr_start_time, if headers: # headers.pop(MessageTrace.cat_id_key, None) # headers.pop(MessageTrace.cat_transaction_key, None) - # headers.pop(MessageTrace.cat_distributed_trace_key, None) + headers.pop(MessageTrace.distributed_trace_key, None) headers.pop("traceparent", None) headers.pop("tracestate", None) @@ -126,7 +126,7 @@ def _nr_wrapper_basic_publish(wrapped, instance, args, kwargs): # Do not record dt headers in the segment parameters # user_headers.pop(MessageTrace.cat_id_key, None) # user_headers.pop(MessageTrace.cat_transaction_key, None) - # user_headers.pop(MessageTrace.cat_distributed_trace_key, None) + user_headers.pop(MessageTrace.distributed_trace_key, None) user_headers.pop("traceparent", None) user_headers.pop("tracestate", None) diff --git a/tests/agent_features/test_attributes_in_action.py b/tests/agent_features/test_attributes_in_action.py index 954b477fda..318218a398 100644 --- a/tests/agent_features/test_attributes_in_action.py +++ b/tests/agent_features/test_attributes_in_action.py @@ -101,7 +101,7 @@ "timestamp", "totalTime", "error", - "nr.apdexPerfZone", + # "nr.apdexPerfZone", "apdexPerfZone", ) TRANS_EVENT_AGENT_KEYS = [ diff --git a/tests/messagebroker_pika/test_pika_produce.py b/tests/messagebroker_pika/test_pika_produce.py index ad6607de9c..1d8a01c6ec 100644 --- a/tests/messagebroker_pika/test_pika_produce.py +++ b/tests/messagebroker_pika/test_pika_produce.py @@ -164,7 +164,7 @@ def test_blocking_connection_reply_to(producer): _message_broker_tt_included_test_headers = _message_broker_tt_included_params.copy() -# _message_broker_tt_included_test_headers.update({"headers": HEADERS.copy()}) +_message_broker_tt_included_test_headers.update({"headers": HEADERS.copy()}) _message_broker_tt_forgone_test_headers = ["queue_name", "correlation_id", "reply_to"] diff --git a/tests/testing_support/fixtures.py b/tests/testing_support/fixtures.py index c25b2bb9a6..925469731c 100644 --- a/tests/testing_support/fixtures.py +++ b/tests/testing_support/fixtures.py @@ -790,7 +790,7 @@ def _bind_params(transaction, *args, **kwargs): assert intrinsics["error.class"] == required_attrs["error.class"] assert intrinsics["error.message"].startswith(required_attrs["error.message"]) assert intrinsics["error.expected"] == required_attrs["error.expected"] - assert intrinsics["nr.transactionGuid"] is not None + # assert intrinsics["nr.transactionGuid"] is not None assert intrinsics["spanId"] is not None # check that transaction event intrinsics haven't bled in @@ -853,11 +853,11 @@ def _validate_event_attributes(intrinsics, user_attributes, required_intrinsics, else: assert "queueDuration" not in intrinsics - if "nr.referringTransactionGuid" in required_intrinsics: - guid = required_intrinsics["nr.referringTransactionGuid"] - assert intrinsics["nr.referringTransactionGuid"] == guid - else: - assert "nr.referringTransactionGuid" not in intrinsics + # if "nr.referringTransactionGuid" in required_intrinsics: + # guid = required_intrinsics["nr.referringTransactionGuid"] + # assert intrinsics["nr.referringTransactionGuid"] == guid + # else: + # assert "nr.referringTransactionGuid" not in intrinsics if "nr.syntheticsResourceId" in required_intrinsics: res_id = required_intrinsics["nr.syntheticsResourceId"] From 3df9e14082c2b182ecde582950b333c26ee7aff7 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 17:26:27 -0700 Subject: [PATCH 13/95] Remove process_response_headers --- newrelic/api/cat_header_mixin.py | 38 ++++++++++---------- newrelic/api/external_trace.py | 2 +- newrelic/hooks/framework_aiohttp.py | 11 +++--- newrelic/hooks/framework_tornado.py | 5 +-- newrelic/hooks/messagebroker_pika.py | 4 +-- tests/agent_features/test_serverless_mode.py | 26 +++++++------- 6 files changed, 43 insertions(+), 43 deletions(-) diff --git a/newrelic/api/cat_header_mixin.py b/newrelic/api/cat_header_mixin.py index 1d1055ed4e..3ba43a5769 100644 --- a/newrelic/api/cat_header_mixin.py +++ b/newrelic/api/cat_header_mixin.py @@ -12,14 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. -from newrelic.common.encoding_utils import ( - base64_decode, - base64_encode, - deobfuscate, - json_decode, - json_encode, - obfuscate, -) +# from newrelic.common.encoding_utils import ( +# base64_decode, +# base64_encode, +# deobfuscate, +# json_decode, +# json_encode, +# obfuscate, +# ) # CatHeaderMixin assumes the mixin class also inherits from TimeTrace @@ -113,17 +113,17 @@ def generate_request_headers(cls, transaction): return nr_headers - @staticmethod - def _convert_to_cat_metadata_value(nr_headers): - payload = json_encode(nr_headers) - cat_linking_value = base64_encode(payload) - return cat_linking_value + # @staticmethod + # def _convert_to_cat_metadata_value(nr_headers): + # payload = json_encode(nr_headers) + # cat_linking_value = base64_encode(payload) + # return cat_linking_value - @classmethod - def get_request_metadata(cls, transaction): - nr_headers = dict(cls.generate_request_headers(transaction)) + # @classmethod + # def get_request_metadata(cls, transaction): + # nr_headers = dict(cls.generate_request_headers(transaction)) - if not nr_headers: - return None + # if not nr_headers: + # return None - return cls._convert_to_cat_metadata_value(nr_headers) + # return cls._convert_to_cat_metadata_value(nr_headers) diff --git a/newrelic/api/external_trace.py b/newrelic/api/external_trace.py index 32796ccd9f..6c0ef4df0f 100644 --- a/newrelic/api/external_trace.py +++ b/newrelic/api/external_trace.py @@ -38,7 +38,7 @@ def __init__(self, library, url, method=None, **kwargs): def __repr__(self): return f"<{self.__class__.__name__} object at 0x{id(self):x} { {'library': self.library, 'url': self.url, 'method': self.method} }>" - def process_response(self, status_code, headers): + def process_response(self, status_code, headers=None): self._add_agent_attribute("http.statusCode", status_code) # self.process_response_headers(headers) diff --git a/newrelic/hooks/framework_aiohttp.py b/newrelic/hooks/framework_aiohttp.py index 277b2fad4c..04d9f2484b 100644 --- a/newrelic/hooks/framework_aiohttp.py +++ b/newrelic/hooks/framework_aiohttp.py @@ -15,6 +15,7 @@ import inspect import itertools +from newrelic.api.time_trace import notice_error from newrelic.api.external_trace import ExternalTrace from newrelic.api.function_trace import function_trace from newrelic.api.transaction import current_transaction, ignore_transaction @@ -279,16 +280,14 @@ async def _coro(): response = await wrapped(*args, **kwargs) try: - trace.process_response_headers(response.headers.items()) + # trace.process_response_headers(response.headers.items()) + trace.process_response(status_code=response.status) except: pass return response - except Exception as e: - try: - trace.process_response_headers(e.headers.items()) - except: - pass + except Exception: + notice_error() raise diff --git a/newrelic/hooks/framework_tornado.py b/newrelic/hooks/framework_tornado.py index a88c66a1b0..92b6a84019 100644 --- a/newrelic/hooks/framework_tornado.py +++ b/newrelic/hooks/framework_tornado.py @@ -251,8 +251,9 @@ async def wrapper(req, raise_error): except Exception as e: response = getattr(e, "response", None) raise - # finally: - # if response: + finally: + if response: + trace.process_response(response.status_code) # trace.process_response_headers(response.headers.get_all()) return response diff --git a/newrelic/hooks/messagebroker_pika.py b/newrelic/hooks/messagebroker_pika.py index 3e673f277a..6a058d85ca 100644 --- a/newrelic/hooks/messagebroker_pika.py +++ b/newrelic/hooks/messagebroker_pika.py @@ -150,8 +150,8 @@ def _nr_wrapper_basic_publish(wrapped, instance, args, kwargs): params=params, source=wrapped, ) as trace: - cat_headers = MessageTrace.generate_request_headers(transaction) - properties.headers.update(cat_headers) + headers = MessageTrace.generate_request_headers(transaction) + properties.headers.update(headers) # Extract host from channel to add as an agent attribute host = instance_info(instance) diff --git a/tests/agent_features/test_serverless_mode.py b/tests/agent_features/test_serverless_mode.py index 8a05db6fe1..f77d739f75 100644 --- a/tests/agent_features/test_serverless_mode.py +++ b/tests/agent_features/test_serverless_mode.py @@ -17,7 +17,7 @@ import pytest from testing_support.fixtures import override_generic_settings from testing_support.validators.validate_serverless_data import validate_serverless_data -from testing_support.validators.validate_serverless_metadata import validate_serverless_metadata +# from testing_support.validators.validate_serverless_metadata import validate_serverless_metadata from testing_support.validators.validate_serverless_payload import validate_serverless_payload from newrelic.api.application import application_instance @@ -65,22 +65,22 @@ def _test(): payload = json.loads(out) -def test_no_cat_headers(serverless_application): - @background_task(application=serverless_application, name="test_cat_headers") - def _test_cat_headers(): - transaction = current_transaction() +# def test_no_cat_headers(serverless_application): +# @background_task(application=serverless_application, name="test_cat_headers") +# def _test_cat_headers(): +# transaction = current_transaction() - payload = ExternalTrace.generate_request_headers(transaction) - assert not payload +# payload = ExternalTrace.generate_request_headers(transaction) +# assert not payload - trace = ExternalTrace("testlib", "http://example.com") - response_headers = [("X-NewRelic-App-Data", "Cookies")] - with trace: - trace.process_response_headers(response_headers) +# trace = ExternalTrace("testlib", "http://example.com") +# response_headers = [("X-NewRelic-App-Data", "Cookies")] +# with trace: +# trace.process_response_headers(response_headers) - # assert transaction.settings.cross_application_tracer.enabled is False +# # assert transaction.settings.cross_application_tracer.enabled is False - _test_cat_headers() +# _test_cat_headers() @pytest.mark.parametrize("trusted_account_key", ("1", None), ids=("tk_set", "tk_unset")) From 89c9fb5eca6b0a91907c43002c95bbd44dfc0d33 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 17:33:07 -0700 Subject: [PATCH 14/95] Remove validate_external_node_params --- tests/external_http/test_http.py | 70 ++++----- tests/external_httplib/test_httplib.py | 132 ++++++++--------- tests/external_httplib/test_urllib.py | 134 +++++++++--------- tests/external_httplib/test_urllib2.py | 62 ++++---- tests/external_httplib2/test_httplib2.py | 74 +++++----- tests/external_requests/test_requests.py | 68 ++++----- tests/external_urllib3/test_urllib3.py | 66 ++++----- .../validate_external_node_params.py | 51 ------- 8 files changed, 303 insertions(+), 354 deletions(-) delete mode 100644 tests/testing_support/validators/validate_external_node_params.py diff --git a/tests/external_http/test_http.py b/tests/external_http/test_http.py index 74ab0833e6..10b353c88b 100644 --- a/tests/external_http/test_http.py +++ b/tests/external_http/test_http.py @@ -18,7 +18,7 @@ from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers -from testing_support.validators.validate_external_node_params import validate_external_node_params +# 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 @@ -95,37 +95,37 @@ def _test(): # @cat_enabled -def test_http_cross_process_response(server): - _test_http_cross_process_response_scoped_metrics = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] - - _test_http_cross_process_response_rollup_metrics = [ - ("External/all", 1), - ("External/allOther", 1), - (f"External/localhost:{server.port}/all", 1), - (f"ExternalApp/localhost:{server.port}/1#2/all", 1), - (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), - ] - - _test_http_cross_process_response_external_node_params = [ - ("cross_process_id", "1#2"), - ("external_txn_name", "test"), - ("transaction_guid", "0123456789012345"), - ] - - @validate_transaction_metrics( - "test_http:test_http_cross_process_response", - scoped_metrics=_test_http_cross_process_response_scoped_metrics, - rollup_metrics=_test_http_cross_process_response_rollup_metrics, - background_task=True, - ) - @insert_incoming_headers - @validate_external_node_params(params=_test_http_cross_process_response_external_node_params) - @background_task(name="test_http:test_http_cross_process_response") - def _test(): - connection = http.client.HTTPConnection("localhost", server.port) - connection.request("GET", "/") - response = connection.getresponse() - response.read() - connection.close() - - _test() +# def test_http_cross_process_response(server): +# _test_http_cross_process_response_scoped_metrics = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] + +# _test_http_cross_process_response_rollup_metrics = [ +# ("External/all", 1), +# ("External/allOther", 1), +# (f"External/localhost:{server.port}/all", 1), +# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), +# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), +# ] + +# _test_http_cross_process_response_external_node_params = [ +# ("cross_process_id", "1#2"), +# ("external_txn_name", "test"), +# ("transaction_guid", "0123456789012345"), +# ] + +# @validate_transaction_metrics( +# "test_http:test_http_cross_process_response", +# scoped_metrics=_test_http_cross_process_response_scoped_metrics, +# rollup_metrics=_test_http_cross_process_response_rollup_metrics, +# background_task=True, +# ) +# @insert_incoming_headers +# @validate_external_node_params(params=_test_http_cross_process_response_external_node_params) +# @background_task(name="test_http:test_http_cross_process_response") +# def _test(): +# connection = http.client.HTTPConnection("localhost", server.port) +# connection.request("GET", "/") +# response = connection.getresponse() +# response.read() +# connection.close() + +# _test() diff --git a/tests/external_httplib/test_httplib.py b/tests/external_httplib/test_httplib.py index 46372adb1c..53133e7cbf 100644 --- a/tests/external_httplib/test_httplib.py +++ b/tests/external_httplib/test_httplib.py @@ -18,7 +18,7 @@ from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers -from testing_support.validators.validate_external_node_params import validate_external_node_params +# from testing_support.validators.validate_external_node_params import validate_external_node_params 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_tt_segment_params import validate_tt_segment_params @@ -132,74 +132,74 @@ def _test(): _test() -_test_httplib_cross_process_response_external_node_params = [ - ("cross_process_id", "1#2"), - ("external_txn_name", "test"), - ("transaction_guid", "0123456789012345"), -] +# _test_httplib_cross_process_response_external_node_params = [ +# ("cross_process_id", "1#2"), +# ("external_txn_name", "test"), +# ("transaction_guid", "0123456789012345"), +# ] + + +# # @cat_enabled +# @insert_incoming_headers +# def test_httplib_cross_process_response(server): +# scoped = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] + +# rollup = [ +# ("External/all", 1), +# ("External/allOther", 1), +# (f"External/localhost:{server.port}/all", 1), +# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), +# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), +# ] + +# @validate_transaction_metrics( +# "test_httplib:test_httplib_cross_process_response", +# scoped_metrics=scoped, +# rollup_metrics=rollup, +# background_task=True, +# ) +# @validate_external_node_params(params=_test_httplib_cross_process_response_external_node_params) +# @background_task(name="test_httplib:test_httplib_cross_process_response") +# def _test(): +# connection = httplib.HTTPConnection("localhost", server.port) +# connection.request("GET", "/") +# response = connection.getresponse() +# response.read() +# connection.close() + +# _test() # @cat_enabled -@insert_incoming_headers -def test_httplib_cross_process_response(server): - scoped = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] - - rollup = [ - ("External/all", 1), - ("External/allOther", 1), - (f"External/localhost:{server.port}/all", 1), - (f"ExternalApp/localhost:{server.port}/1#2/all", 1), - (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), - ] - - @validate_transaction_metrics( - "test_httplib:test_httplib_cross_process_response", - scoped_metrics=scoped, - rollup_metrics=rollup, - background_task=True, - ) - @validate_external_node_params(params=_test_httplib_cross_process_response_external_node_params) - @background_task(name="test_httplib:test_httplib_cross_process_response") - def _test(): - connection = httplib.HTTPConnection("localhost", server.port) - connection.request("GET", "/") - response = connection.getresponse() - response.read() - connection.close() - - _test() - - -# @cat_enabled -def test_httplib_multiple_requests_cross_process_response(server): - connection = httplib.HTTPConnection("localhost", server.port) - - scoped = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] - - rollup = [ - ("External/all", 1), - ("External/allOther", 1), - (f"External/localhost:{server.port}/all", 1), - (f"ExternalApp/localhost:{server.port}/1#2/all", 1), - (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), - ] - - @validate_transaction_metrics( - "test_httplib:test_transaction", scoped_metrics=scoped, rollup_metrics=rollup, background_task=True - ) - @insert_incoming_headers - @validate_external_node_params(params=_test_httplib_cross_process_response_external_node_params) - @background_task(name="test_httplib:test_transaction") - def test_transaction(): - connection.request("GET", "/") - response = connection.getresponse() - response.read() - - # make multiple requests with the same connection - for _ in range(2): - test_transaction() - - connection.close() +# def test_httplib_multiple_requests_cross_process_response(server): +# connection = httplib.HTTPConnection("localhost", server.port) + +# scoped = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] + +# rollup = [ +# ("External/all", 1), +# ("External/allOther", 1), +# (f"External/localhost:{server.port}/all", 1), +# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), +# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), +# ] + +# @validate_transaction_metrics( +# "test_httplib:test_transaction", scoped_metrics=scoped, rollup_metrics=rollup, background_task=True +# ) +# @insert_incoming_headers +# @validate_external_node_params(params=_test_httplib_cross_process_response_external_node_params) +# @background_task(name="test_httplib:test_transaction") +# def test_transaction(): +# connection.request("GET", "/") +# response = connection.getresponse() +# response.read() + +# # make multiple requests with the same connection +# for _ in range(2): +# test_transaction() + +# connection.close() def process_response(response): diff --git a/tests/external_httplib/test_urllib.py b/tests/external_httplib/test_urllib.py index b0b9abb75b..32002452ed 100644 --- a/tests/external_httplib/test_urllib.py +++ b/tests/external_httplib/test_urllib.py @@ -24,7 +24,7 @@ from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers # from testing_support.fixtures import cat_enabled from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers -from testing_support.validators.validate_external_node_params import validate_external_node_params +# 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 @@ -131,40 +131,40 @@ def test_urlopener_cross_process_request(server): opener.open(f"http://localhost:{server.port}/") -# @cat_enabled -def test_urlopener_cross_process_response(server): - _test_urlopener_cross_process_response_scoped_metrics = [ - (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) - ] - - _test_urlopener_cross_process_response_rollup_metrics = [ - ("External/all", 1), - ("External/allOther", 1), - (f"External/localhost:{server.port}/all", 1), - (f"ExternalApp/localhost:{server.port}/1#2/all", 1), - (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), - ] - - _test_urlopener_cross_process_response_external_node_params = [ - ("cross_process_id", "1#2"), - ("external_txn_name", "test"), - ("transaction_guid", "0123456789012345"), - ] - - @validate_transaction_metrics( - "test_urllib:test_urlopener_cross_process_response", - scoped_metrics=_test_urlopener_cross_process_response_scoped_metrics, - rollup_metrics=_test_urlopener_cross_process_response_rollup_metrics, - background_task=True, - ) - @insert_incoming_headers - @validate_external_node_params(params=_test_urlopener_cross_process_response_external_node_params) - @background_task(name="test_urllib:test_urlopener_cross_process_response") - def _test(): - opener = urllib.URLopener() - opener.open(f"http://localhost:{server.port}/") - - _test() +# # @cat_enabled +# def test_urlopener_cross_process_response(server): +# _test_urlopener_cross_process_response_scoped_metrics = [ +# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) +# ] + +# _test_urlopener_cross_process_response_rollup_metrics = [ +# ("External/all", 1), +# ("External/allOther", 1), +# (f"External/localhost:{server.port}/all", 1), +# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), +# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), +# ] + +# _test_urlopener_cross_process_response_external_node_params = [ +# ("cross_process_id", "1#2"), +# ("external_txn_name", "test"), +# ("transaction_guid", "0123456789012345"), +# ] + +# @validate_transaction_metrics( +# "test_urllib:test_urlopener_cross_process_response", +# scoped_metrics=_test_urlopener_cross_process_response_scoped_metrics, +# rollup_metrics=_test_urlopener_cross_process_response_rollup_metrics, +# background_task=True, +# ) +# @insert_incoming_headers +# @validate_external_node_params(params=_test_urlopener_cross_process_response_external_node_params) +# @background_task(name="test_urllib:test_urlopener_cross_process_response") +# def _test(): +# opener = urllib.URLopener() +# opener.open(f"http://localhost:{server.port}/") + +# _test() def test_urlretrieve_http_request(server, metrics): @@ -206,35 +206,35 @@ def test_urlretrieve_cross_process_request(server): # @cat_enabled -def test_urlretrieve_cross_process_response(server): - _test_urlretrieve_cross_process_response_scoped_metrics = [ - (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) - ] - - _test_urlretrieve_cross_process_response_rollup_metrics = [ - ("External/all", 1), - ("External/allOther", 1), - (f"External/localhost:{server.port}/all", 1), - (f"ExternalApp/localhost:{server.port}/1#2/all", 1), - (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), - ] - - _test_urlretrieve_cross_process_response_external_node_params = [ - ("cross_process_id", "1#2"), - ("external_txn_name", "test"), - ("transaction_guid", "0123456789012345"), - ] - - @validate_transaction_metrics( - "test_urllib:test_urlretrieve_cross_process_response", - scoped_metrics=_test_urlretrieve_cross_process_response_scoped_metrics, - rollup_metrics=_test_urlretrieve_cross_process_response_rollup_metrics, - background_task=True, - ) - @insert_incoming_headers - @validate_external_node_params(params=_test_urlretrieve_cross_process_response_external_node_params) - @background_task(name="test_urllib:test_urlretrieve_cross_process_response") - def _test(): - urllib.urlretrieve(f"http://localhost:{server.port}/") - - _test() +# def test_urlretrieve_cross_process_response(server): +# _test_urlretrieve_cross_process_response_scoped_metrics = [ +# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) +# ] + +# _test_urlretrieve_cross_process_response_rollup_metrics = [ +# ("External/all", 1), +# ("External/allOther", 1), +# (f"External/localhost:{server.port}/all", 1), +# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), +# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), +# ] + +# _test_urlretrieve_cross_process_response_external_node_params = [ +# ("cross_process_id", "1#2"), +# ("external_txn_name", "test"), +# ("transaction_guid", "0123456789012345"), +# ] + +# @validate_transaction_metrics( +# "test_urllib:test_urlretrieve_cross_process_response", +# scoped_metrics=_test_urlretrieve_cross_process_response_scoped_metrics, +# rollup_metrics=_test_urlretrieve_cross_process_response_rollup_metrics, +# background_task=True, +# ) +# @insert_incoming_headers +# @validate_external_node_params(params=_test_urlretrieve_cross_process_response_external_node_params) +# @background_task(name="test_urllib:test_urlretrieve_cross_process_response") +# def _test(): +# urllib.urlretrieve(f"http://localhost:{server.port}/") + +# _test() diff --git a/tests/external_httplib/test_urllib2.py b/tests/external_httplib/test_urllib2.py index f18ca3de8c..ce0b3b3067 100644 --- a/tests/external_httplib/test_urllib2.py +++ b/tests/external_httplib/test_urllib2.py @@ -19,7 +19,7 @@ from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers # from testing_support.fixtures import cat_enabled from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers -from testing_support.validators.validate_external_node_params import validate_external_node_params +# 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 @@ -122,33 +122,33 @@ def test_urlopen_cross_process_request(server): # @cat_enabled -def test_urlopen_cross_process_response(server): - _test_urlopen_cross_process_response_scoped_metrics = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] - - _test_urlopen_cross_process_response_rollup_metrics = [ - ("External/all", 1), - ("External/allOther", 1), - (f"External/localhost:{server.port}/all", 1), - (f"ExternalApp/localhost:{server.port}/1#2/all", 1), - (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), - ] - - _test_urlopen_cross_process_response_external_node_params = [ - ("cross_process_id", "1#2"), - ("external_txn_name", "test"), - ("transaction_guid", "0123456789012345"), - ] - - @validate_transaction_metrics( - "test_urllib2:test_urlopen_cross_process_response", - scoped_metrics=_test_urlopen_cross_process_response_scoped_metrics, - rollup_metrics=_test_urlopen_cross_process_response_rollup_metrics, - background_task=True, - ) - @insert_incoming_headers - @validate_external_node_params(params=_test_urlopen_cross_process_response_external_node_params) - @background_task(name="test_urllib2:test_urlopen_cross_process_response") - def _test(): - urllib2.urlopen(f"http://localhost:{server.port}/") - - _test() +# def test_urlopen_cross_process_response(server): +# _test_urlopen_cross_process_response_scoped_metrics = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] + +# _test_urlopen_cross_process_response_rollup_metrics = [ +# ("External/all", 1), +# ("External/allOther", 1), +# (f"External/localhost:{server.port}/all", 1), +# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), +# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), +# ] + +# _test_urlopen_cross_process_response_external_node_params = [ +# ("cross_process_id", "1#2"), +# ("external_txn_name", "test"), +# ("transaction_guid", "0123456789012345"), +# ] + +# @validate_transaction_metrics( +# "test_urllib2:test_urlopen_cross_process_response", +# scoped_metrics=_test_urlopen_cross_process_response_scoped_metrics, +# rollup_metrics=_test_urlopen_cross_process_response_rollup_metrics, +# background_task=True, +# ) +# @insert_incoming_headers +# @validate_external_node_params(params=_test_urlopen_cross_process_response_external_node_params) +# @background_task(name="test_urllib2:test_urlopen_cross_process_response") +# def _test(): +# urllib2.urlopen(f"http://localhost:{server.port}/") + +# _test() diff --git a/tests/external_httplib2/test_httplib2.py b/tests/external_httplib2/test_httplib2.py index f4fa0e7c9b..52ddf40d60 100644 --- a/tests/external_httplib2/test_httplib2.py +++ b/tests/external_httplib2/test_httplib2.py @@ -17,7 +17,7 @@ from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers -from testing_support.validators.validate_external_node_params import validate_external_node_params +# 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 @@ -113,39 +113,39 @@ def _test(): # @cat_enabled -def test_httplib2_cross_process_response(server): - _test_httplib2_cross_process_response_scoped_metrics = [ - (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) - ] - - _test_httplib2_cross_process_response_rollup_metrics = [ - ("External/all", 1), - ("External/allOther", 1), - (f"External/localhost:{server.port}/all", 1), - (f"ExternalApp/localhost:{server.port}/1#2/all", 1), - (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), - ] - - _test_httplib2_cross_process_response_external_node_params = [ - ("cross_process_id", "1#2"), - ("external_txn_name", "test"), - ("transaction_guid", "0123456789012345"), - ] - - @validate_transaction_metrics( - "test_httplib2:test_httplib2_cross_process_response", - scoped_metrics=_test_httplib2_cross_process_response_scoped_metrics, - rollup_metrics=_test_httplib2_cross_process_response_rollup_metrics, - background_task=True, - ) - @insert_incoming_headers - @validate_external_node_params(params=_test_httplib2_cross_process_response_external_node_params) - @background_task(name="test_httplib2:test_httplib2_cross_process_response") - def _test(): - connection = httplib2.HTTPConnectionWithTimeout("localhost", server.port) - connection.request("GET", "/") - response = connection.getresponse() - response.read() - connection.close() - - _test() +# def test_httplib2_cross_process_response(server): +# _test_httplib2_cross_process_response_scoped_metrics = [ +# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) +# ] + +# _test_httplib2_cross_process_response_rollup_metrics = [ +# ("External/all", 1), +# ("External/allOther", 1), +# (f"External/localhost:{server.port}/all", 1), +# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), +# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), +# ] + +# _test_httplib2_cross_process_response_external_node_params = [ +# ("cross_process_id", "1#2"), +# ("external_txn_name", "test"), +# ("transaction_guid", "0123456789012345"), +# ] + +# @validate_transaction_metrics( +# "test_httplib2:test_httplib2_cross_process_response", +# scoped_metrics=_test_httplib2_cross_process_response_scoped_metrics, +# rollup_metrics=_test_httplib2_cross_process_response_rollup_metrics, +# background_task=True, +# ) +# @insert_incoming_headers +# @validate_external_node_params(params=_test_httplib2_cross_process_response_external_node_params) +# @background_task(name="test_httplib2:test_httplib2_cross_process_response") +# def _test(): +# connection = httplib2.HTTPConnectionWithTimeout("localhost", server.port) +# connection.request("GET", "/") +# response = connection.getresponse() +# response.read() +# connection.close() + +# _test() diff --git a/tests/external_requests/test_requests.py b/tests/external_requests/test_requests.py index b2d39e7289..95e6ac73de 100644 --- a/tests/external_requests/test_requests.py +++ b/tests/external_requests/test_requests.py @@ -18,7 +18,7 @@ from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers from testing_support.fixtures import override_application_settings, validate_tt_parenting from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers -from testing_support.validators.validate_external_node_params import validate_external_node_params +# 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 @@ -176,36 +176,36 @@ def _test(): # @cat_enabled -def test_requests_cross_process_response(server): - _test_requests_cross_process_response_scoped_metrics = [ - (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) - ] - - _test_requests_cross_process_response_rollup_metrics = [ - ("External/all", 1), - ("External/allOther", 1), - (f"External/localhost:{server.port}/all", 1), - (f"ExternalApp/localhost:{server.port}/1#2/all", 1), - (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), - ] - - _test_requests_cross_process_response_external_node_params = [ - ("cross_process_id", "1#2"), - ("external_txn_name", "test"), - ("transaction_guid", "0123456789012345"), - ] - - @validate_transaction_errors(errors=[]) - @validate_transaction_metrics( - "test_requests:test_requests_cross_process_response", - scoped_metrics=_test_requests_cross_process_response_scoped_metrics, - rollup_metrics=_test_requests_cross_process_response_rollup_metrics, - background_task=True, - ) - @insert_incoming_headers - @validate_external_node_params(params=_test_requests_cross_process_response_external_node_params) - @background_task(name="test_requests:test_requests_cross_process_response") - def _test(): - requests.get(f"http://localhost:{server.port}/") - - _test() +# def test_requests_cross_process_response(server): +# _test_requests_cross_process_response_scoped_metrics = [ +# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) +# ] + +# _test_requests_cross_process_response_rollup_metrics = [ +# ("External/all", 1), +# ("External/allOther", 1), +# (f"External/localhost:{server.port}/all", 1), +# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), +# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), +# ] + +# _test_requests_cross_process_response_external_node_params = [ +# ("cross_process_id", "1#2"), +# ("external_txn_name", "test"), +# ("transaction_guid", "0123456789012345"), +# ] + +# @validate_transaction_errors(errors=[]) +# @validate_transaction_metrics( +# "test_requests:test_requests_cross_process_response", +# scoped_metrics=_test_requests_cross_process_response_scoped_metrics, +# rollup_metrics=_test_requests_cross_process_response_rollup_metrics, +# background_task=True, +# ) +# @insert_incoming_headers +# @validate_external_node_params(params=_test_requests_cross_process_response_external_node_params) +# @background_task(name="test_requests:test_requests_cross_process_response") +# def _test(): +# requests.get(f"http://localhost:{server.port}/") + +# _test() diff --git a/tests/external_urllib3/test_urllib3.py b/tests/external_urllib3/test_urllib3.py index 0669ab1b9d..9cca2341d1 100644 --- a/tests/external_urllib3/test_urllib3.py +++ b/tests/external_urllib3/test_urllib3.py @@ -24,7 +24,7 @@ from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers -from testing_support.validators.validate_external_node_params import validate_external_node_params +# 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 @@ -225,35 +225,35 @@ def _test(): # @cat_enabled -def test_urlopen_cross_process_response(server): - _test_urlopen_cross_process_response_scoped_metrics = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] - - _test_urlopen_cross_process_response_rollup_metrics = [ - ("External/all", 1), - ("External/allOther", 1), - (f"External/localhost:{server.port}/all", 1), - (f"ExternalApp/localhost:{server.port}/1#2/all", 1), - (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), - ] - - _test_urlopen_cross_process_response_external_node_params = [ - ("cross_process_id", "1#2"), - ("external_txn_name", "test"), - ("transaction_guid", "0123456789012345"), - ] - - @validate_transaction_errors(errors=[]) - @validate_transaction_metrics( - "test_urllib3:test_urlopen_cross_process_response", - scoped_metrics=_test_urlopen_cross_process_response_scoped_metrics, - rollup_metrics=_test_urlopen_cross_process_response_rollup_metrics, - background_task=True, - ) - @insert_incoming_headers - @validate_external_node_params(params=_test_urlopen_cross_process_response_external_node_params) - @background_task(name="test_urllib3:test_urlopen_cross_process_response") - def _test(): - pool = urllib3.HTTPConnectionPool(f"localhost:{server.port}") - pool.urlopen("GET", "/") - - _test() +# def test_urlopen_cross_process_response(server): +# _test_urlopen_cross_process_response_scoped_metrics = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] + +# _test_urlopen_cross_process_response_rollup_metrics = [ +# ("External/all", 1), +# ("External/allOther", 1), +# (f"External/localhost:{server.port}/all", 1), +# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), +# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), +# ] + +# _test_urlopen_cross_process_response_external_node_params = [ +# ("cross_process_id", "1#2"), +# ("external_txn_name", "test"), +# ("transaction_guid", "0123456789012345"), +# ] + +# @validate_transaction_errors(errors=[]) +# @validate_transaction_metrics( +# "test_urllib3:test_urlopen_cross_process_response", +# scoped_metrics=_test_urlopen_cross_process_response_scoped_metrics, +# rollup_metrics=_test_urlopen_cross_process_response_rollup_metrics, +# background_task=True, +# ) +# @insert_incoming_headers +# @validate_external_node_params(params=_test_urlopen_cross_process_response_external_node_params) +# @background_task(name="test_urllib3:test_urlopen_cross_process_response") +# def _test(): +# pool = urllib3.HTTPConnectionPool(f"localhost:{server.port}") +# pool.urlopen("GET", "/") + +# _test() diff --git a/tests/testing_support/validators/validate_external_node_params.py b/tests/testing_support/validators/validate_external_node_params.py deleted file mode 100644 index 9ff5bd0c24..0000000000 --- a/tests/testing_support/validators/validate_external_node_params.py +++ /dev/null @@ -1,51 +0,0 @@ -# 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 - - -def validate_external_node_params(params=None, forgone_params=None): - """ - Validate the parameters on the external node. - - params: a list of tuples - forgone_params: a flat list - """ - - if forgone_params is None: - forgone_params = [] - if params is None: - params = [] - - @transient_function_wrapper("newrelic.api.external_trace", "ExternalTrace.process_response_headers") - def _validate_external_node_params(wrapped, instance, args, kwargs): - result = wrapped(*args, **kwargs) - - # This is only validating that logic to extract cross process - # header and update params in ExternalTrace is succeeding. This - # is actually done after the ExternalTrace __exit__() is called - # with the ExternalNode only being updated by virtue of the - # original params dictionary being aliased rather than copied. - # So isn't strictly validating that params ended up in the actual - # ExternalNode in the transaction trace. - - for name, value in params: - assert instance.params[name] == value - - for name in forgone_params: - assert name not in instance.params - - return result - - return _validate_external_node_params From 23ff187d12aed8209fb2cdb2dcaa1b1e83a77bec Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 17:36:24 -0700 Subject: [PATCH 15/95] Rename CatHeaderMixin to HeaderMixin --- newrelic/api/external_trace.py | 4 ++-- newrelic/api/{cat_header_mixin.py => header_mixin.py} | 4 ++-- newrelic/api/message_trace.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) rename newrelic/api/{cat_header_mixin.py => header_mixin.py} (98%) diff --git a/newrelic/api/external_trace.py b/newrelic/api/external_trace.py index 6c0ef4df0f..c73bba9383 100644 --- a/newrelic/api/external_trace.py +++ b/newrelic/api/external_trace.py @@ -14,14 +14,14 @@ import functools -from newrelic.api.cat_header_mixin import CatHeaderMixin +from newrelic.api.header_mixin import HeaderMixin from newrelic.api.time_trace import TimeTrace, current_trace from newrelic.common.async_wrapper import async_wrapper as get_async_wrapper from newrelic.common.object_wrapper import FunctionWrapper, wrap_object from newrelic.core.external_node import ExternalNode -class ExternalTrace(CatHeaderMixin, TimeTrace): +class ExternalTrace(HeaderMixin, TimeTrace): def __init__(self, library, url, method=None, **kwargs): parent = kwargs.pop("parent", None) source = kwargs.pop("source", None) diff --git a/newrelic/api/cat_header_mixin.py b/newrelic/api/header_mixin.py similarity index 98% rename from newrelic/api/cat_header_mixin.py rename to newrelic/api/header_mixin.py index 3ba43a5769..ca4114bf7f 100644 --- a/newrelic/api/cat_header_mixin.py +++ b/newrelic/api/header_mixin.py @@ -22,8 +22,8 @@ # ) -# CatHeaderMixin assumes the mixin class also inherits from TimeTrace -class CatHeaderMixin: +# HeaderMixin assumes the mixin class also inherits from TimeTrace +class HeaderMixin: # cat_id_key = "X-NewRelic-ID" # cat_transaction_key = "X-NewRelic-Transaction" # cat_appdata_key = "X-NewRelic-App-Data" diff --git a/newrelic/api/message_trace.py b/newrelic/api/message_trace.py index 0514b2d941..999434d786 100644 --- a/newrelic/api/message_trace.py +++ b/newrelic/api/message_trace.py @@ -14,14 +14,14 @@ import functools -from newrelic.api.cat_header_mixin import CatHeaderMixin +from newrelic.api.header_mixin import HeaderMixin from newrelic.api.time_trace import TimeTrace, current_trace from newrelic.common.async_wrapper import async_wrapper as get_async_wrapper from newrelic.common.object_wrapper import FunctionWrapper, wrap_object from newrelic.core.message_node import MessageNode -class MessageTrace(CatHeaderMixin, TimeTrace): +class MessageTrace(HeaderMixin, TimeTrace): # cat_id_key = "NewRelicID" # cat_transaction_key = "NewRelicTransaction" # cat_appdata_key = "NewRelicAppData" From 566d2504d4ffb00682114822b9a1744f419e5a50 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 18:02:13 -0700 Subject: [PATCH 16/95] Remove _generate_response_headers --- newrelic/api/transaction.py | 94 +++++++++++------------ newrelic/api/web_transaction.py | 12 +-- tests/framework_tornado/test_externals.py | 2 +- 3 files changed, 54 insertions(+), 54 deletions(-) diff --git a/newrelic/api/transaction.py b/newrelic/api/transaction.py index 4a79c91bbd..66e51f1d96 100644 --- a/newrelic/api/transaction.py +++ b/newrelic/api/transaction.py @@ -1405,55 +1405,55 @@ def accept_distributed_trace_headers(self, headers, transport_type="HTTP"): # except Exception: # pass - def _generate_response_headers(self, read_length=None): - nr_headers = [] - - # Generate metrics and response headers for inbound cross - # process web external calls. - - if self.client_cross_process_id is not None: - # Need to work out queueing time and duration up to this - # point for inclusion in metrics and response header. If the - # recording of the transaction had been prematurely stopped - # via an API call, only return time up until that call was - # made so it will match what is reported as duration for the - # transaction. - - if self.queue_start: - queue_time = self.start_time - self.queue_start - else: - queue_time = 0 - - if self.end_time: - duration = self.end_time - self.start_time - else: - duration = time.time() - self.start_time - - # Generate the additional response headers which provide - # information back to the caller. We need to freeze the - # transaction name before adding to the header. - - self._freeze_path() - - if read_length is None: - read_length = self._read_length - - read_length = read_length if read_length is not None else -1 - - payload = ( - self._settings.cross_process_id, - self.path, - queue_time, - duration, - read_length, - self.guid, - self.record_tt, - ) - app_data = json_encode(payload) + # def _generate_response_headers(self, read_length=None): + # nr_headers = [] + + # # Generate metrics and response headers for inbound cross + # # process web external calls. + + # if self.client_cross_process_id is not None: + # # Need to work out queueing time and duration up to this + # # point for inclusion in metrics and response header. If the + # # recording of the transaction had been prematurely stopped + # # via an API call, only return time up until that call was + # # made so it will match what is reported as duration for the + # # transaction. + + # if self.queue_start: + # queue_time = self.start_time - self.queue_start + # else: + # queue_time = 0 + + # if self.end_time: + # duration = self.end_time - self.start_time + # else: + # duration = time.time() - self.start_time + + # # Generate the additional response headers which provide + # # information back to the caller. We need to freeze the + # # transaction name before adding to the header. + + # self._freeze_path() + + # if read_length is None: + # read_length = self._read_length + + # read_length = read_length if read_length is not None else -1 + + # payload = ( + # self._settings.cross_process_id, + # self.path, + # queue_time, + # duration, + # read_length, + # self.guid, + # self.record_tt, + # ) + # app_data = json_encode(payload) - nr_headers.append(("X-NewRelic-App-Data", obfuscate(app_data, self._settings.encoding_key))) + # nr_headers.append(("X-NewRelic-App-Data", obfuscate(app_data, self._settings.encoding_key))) - return nr_headers + # return nr_headers # # This function is CAT related and has been deprecated. # # Eventually, this will be removed. Until then, coverage diff --git a/newrelic/api/web_transaction.py b/newrelic/api/web_transaction.py index 822ce25a4b..b8a6e4daad 100644 --- a/newrelic/api/web_transaction.py +++ b/newrelic/api/web_transaction.py @@ -324,13 +324,13 @@ def process_response(self, status_code, response_headers): if self.client_cross_process_id is None: return [] - # Generate CAT response headers - try: - read_length = int(self._request_headers.get("content-length")) - except Exception: - read_length = -1 + # # Generate CAT response headers + # try: + # read_length = int(self._request_headers.get("content-length")) + # except Exception: + # read_length = -1 - return self._generate_response_headers(read_length) + # return self._generate_response_headers(read_length) def _update_agent_attributes(self): if "accept" in self._request_headers: diff --git a/tests/framework_tornado/test_externals.py b/tests/framework_tornado/test_externals.py index 5d79c0e46d..42ae7e3321 100644 --- a/tests/framework_tornado/test_externals.py +++ b/tests/framework_tornado/test_externals.py @@ -197,7 +197,7 @@ def _test(): _test() -CAT_RESPONSE_CODE = None +# CAT_RESPONSE_CODE = None # def cat_response_handler(self): From 521496ca99c2705f6f2a0ce4734318fb757ce61d Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 18:03:50 -0700 Subject: [PATCH 17/95] Remove insert_incoming_headers --- tests/external_http/test_http.py | 2 +- tests/external_httplib/test_httplib.py | 2 +- tests/external_httplib/test_urllib.py | 2 +- tests/external_httplib/test_urllib2.py | 2 +- tests/external_httplib2/test_httplib2.py | 2 +- tests/external_requests/test_requests.py | 2 +- tests/external_urllib3/test_urllib3.py | 2 +- tests/testing_support/external_fixtures.py | 16 ++++++++-------- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/external_http/test_http.py b/tests/external_http/test_http.py index 10b353c88b..89fccac8f6 100644 --- a/tests/external_http/test_http.py +++ b/tests/external_http/test_http.py @@ -15,7 +15,7 @@ import http.client import pytest -from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers # from testing_support.validators.validate_external_node_params import validate_external_node_params diff --git a/tests/external_httplib/test_httplib.py b/tests/external_httplib/test_httplib.py index 53133e7cbf..7de8308724 100644 --- a/tests/external_httplib/test_httplib.py +++ b/tests/external_httplib/test_httplib.py @@ -15,7 +15,7 @@ import http.client as httplib import pytest -from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers # from testing_support.validators.validate_external_node_params import validate_external_node_params diff --git a/tests/external_httplib/test_urllib.py b/tests/external_httplib/test_urllib.py index 32002452ed..2f64201198 100644 --- a/tests/external_httplib/test_urllib.py +++ b/tests/external_httplib/test_urllib.py @@ -21,7 +21,7 @@ except: import urllib -from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers # from testing_support.fixtures import cat_enabled from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers # from testing_support.validators.validate_external_node_params import validate_external_node_params diff --git a/tests/external_httplib/test_urllib2.py b/tests/external_httplib/test_urllib2.py index ce0b3b3067..9c61abe3ca 100644 --- a/tests/external_httplib/test_urllib2.py +++ b/tests/external_httplib/test_urllib2.py @@ -16,7 +16,7 @@ import urllib.request as urllib2 import pytest -from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers # from testing_support.fixtures import cat_enabled from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers # from testing_support.validators.validate_external_node_params import validate_external_node_params diff --git a/tests/external_httplib2/test_httplib2.py b/tests/external_httplib2/test_httplib2.py index 52ddf40d60..3e4deaba76 100644 --- a/tests/external_httplib2/test_httplib2.py +++ b/tests/external_httplib2/test_httplib2.py @@ -14,7 +14,7 @@ import httplib2 import pytest -from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers # from testing_support.validators.validate_external_node_params import validate_external_node_params diff --git a/tests/external_requests/test_requests.py b/tests/external_requests/test_requests.py index 95e6ac73de..28f18b07d8 100644 --- a/tests/external_requests/test_requests.py +++ b/tests/external_requests/test_requests.py @@ -15,7 +15,7 @@ import pytest import requests import requests.exceptions -from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers from testing_support.fixtures import override_application_settings, validate_tt_parenting from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers # from testing_support.validators.validate_external_node_params import validate_external_node_params diff --git a/tests/external_urllib3/test_urllib3.py b/tests/external_urllib3/test_urllib3.py index 9cca2341d1..1ac8fa7e95 100644 --- a/tests/external_urllib3/test_urllib3.py +++ b/tests/external_urllib3/test_urllib3.py @@ -21,7 +21,7 @@ except ImportError: pass -from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers # from testing_support.validators.validate_external_node_params import validate_external_node_params diff --git a/tests/testing_support/external_fixtures.py b/tests/testing_support/external_fixtures.py index f0bd31be99..89e69cd92d 100644 --- a/tests/testing_support/external_fixtures.py +++ b/tests/testing_support/external_fixtures.py @@ -128,15 +128,15 @@ def _bind_params(header, *values): return wrapped(*args, **kwargs) -@transient_function_wrapper(httplib.__name__, "HTTPResponse.getheaders") -def insert_incoming_headers(wrapped, instance, args, kwargs): - transaction = current_transaction() +# @transient_function_wrapper(httplib.__name__, "HTTPResponse.getheaders") +# def insert_incoming_headers(wrapped, instance, args, kwargs): +# transaction = current_transaction() - if transaction is None: - return wrapped(*args, **kwargs) +# if transaction is None: +# return wrapped(*args, **kwargs) - headers = list(wrapped(*args, **kwargs)) +# headers = list(wrapped(*args, **kwargs)) - headers.extend(create_incoming_headers(transaction)) +# headers.extend(create_incoming_headers(transaction)) - return headers +# return headers From f7bd2ee2a4b1e92914f88a51f11f3fc1cf726c0a Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 18:04:35 -0700 Subject: [PATCH 18/95] Remove create_incoming_headers --- tests/testing_support/external_fixtures.py | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/testing_support/external_fixtures.py b/tests/testing_support/external_fixtures.py index 89e69cd92d..e0d72aad8a 100644 --- a/tests/testing_support/external_fixtures.py +++ b/tests/testing_support/external_fixtures.py @@ -20,30 +20,30 @@ from newrelic.common.object_wrapper import transient_function_wrapper -def create_incoming_headers(transaction): - settings = transaction.settings - encoding_key = settings.encoding_key +# def create_incoming_headers(transaction): +# settings = transaction.settings +# encoding_key = settings.encoding_key - headers = [] +# headers = [] - cross_process_id = "1#2" - path = "test" - queue_time = 1.0 - duration = 2.0 - read_length = 1024 - guid = "0123456789012345" - record_tt = False +# cross_process_id = "1#2" +# path = "test" +# queue_time = 1.0 +# duration = 2.0 +# read_length = 1024 +# guid = "0123456789012345" +# record_tt = False - payload = (cross_process_id, path, queue_time, duration, read_length, guid, record_tt) - app_data = json_encode(payload) +# payload = (cross_process_id, path, queue_time, duration, read_length, guid, record_tt) +# app_data = json_encode(payload) - value = obfuscate(app_data, encoding_key) +# value = obfuscate(app_data, encoding_key) - assert isinstance(value, str) +# assert isinstance(value, str) - headers.append(("X-NewRelic-App-Data", value)) +# headers.append(("X-NewRelic-App-Data", value)) - return headers +# return headers def validate_synthetics_external_trace_header(synthetics_header, synthetics_info_header): From 5ed70557ad4bc88dac3d6380e22fea1b5da03db6 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 18:06:54 -0700 Subject: [PATCH 19/95] Remove X-NewRelic-App-Data --- tests/agent_features/test_asgi_distributed_tracing.py | 2 +- tests/agent_features/test_distributed_tracing.py | 2 +- tests/cross_agent/test_distributed_tracing.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/agent_features/test_asgi_distributed_tracing.py b/tests/agent_features/test_asgi_distributed_tracing.py index ae50d45cf3..993ba7865c 100644 --- a/tests/agent_features/test_asgi_distributed_tracing.py +++ b/tests/agent_features/test_asgi_distributed_tracing.py @@ -104,7 +104,7 @@ async def target_asgi_application(scope, receive, send): def test_distributed_tracing_web_transaction(): headers = {"newrelic": json.dumps(payload)} response = test_application.make_request("GET", "/", headers=headers) - assert "X-NewRelic-App-Data" not in response.headers + # assert "X-NewRelic-App-Data" not in response.headers class TestAsgiRequest: diff --git a/tests/agent_features/test_distributed_tracing.py b/tests/agent_features/test_distributed_tracing.py index 36261d97e2..ed7183f40d 100644 --- a/tests/agent_features/test_distributed_tracing.py +++ b/tests/agent_features/test_distributed_tracing.py @@ -111,7 +111,7 @@ def target_wsgi_application(environ, start_response): def test_distributed_tracing_web_transaction(): headers = {"newrelic": json.dumps(payload)} response = test_application.get("/", headers=headers) - assert "X-NewRelic-App-Data" not in response.headers + # assert "X-NewRelic-App-Data" not in response.headers @pytest.mark.parametrize("span_events", (True, False)) diff --git a/tests/cross_agent/test_distributed_tracing.py b/tests/cross_agent/test_distributed_tracing.py index a3536fcce5..144dd57e3e 100644 --- a/tests/cross_agent/test_distributed_tracing.py +++ b/tests/cross_agent/test_distributed_tracing.py @@ -219,7 +219,7 @@ def test_distributed_tracing( @override_application_settings(override_settings) def _test(): response = test_application.get("/", headers=headers) - assert "X-NewRelic-App-Data" not in response.headers + # assert "X-NewRelic-App-Data" not in response.headers if "Span" in intrinsics: span_intrinsics = intrinsics.get("Span") From af451d64a1b856de4beb590c7e83394aeaf44ffe Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 18:34:38 -0700 Subject: [PATCH 20/95] Remove cross_process_id --- newrelic/api/transaction.py | 14 ++-- newrelic/api/web_transaction.py | 6 +- newrelic/common/agent_http.py | 2 +- newrelic/core/config.py | 24 +++--- newrelic/core/external_node.py | 36 ++++----- newrelic/core/transaction_node.py | 2 +- tests/agent_features/test_error_events.py | 74 +++++++++---------- tests/agent_unittests/test_harvest_loop.py | 2 +- .../test_distributed_tracing.py | 2 +- 9 files changed, 82 insertions(+), 80 deletions(-) diff --git a/newrelic/api/transaction.py b/newrelic/api/transaction.py index 66e51f1d96..334d7e0924 100644 --- a/newrelic/api/transaction.py +++ b/newrelic/api/transaction.py @@ -289,7 +289,7 @@ def __init__(self, application, enabled=None, source=None): self._distributed_trace_state = 0 - self.client_cross_process_id = None + # self.client_cross_process_id = None self.client_account_id = None self.client_application_id = None self.referring_transaction_guid = None @@ -541,9 +541,9 @@ def __exit__(self, exc, value, tb): # self.total_time += exclusive - if self.client_cross_process_id is not None: - metric_name = f"ClientApplication/{self.client_cross_process_id}/all" - self.record_custom_metric(metric_name, duration) + # if self.client_cross_process_id is not None: + # metric_name = f"ClientApplication/{self.client_cross_process_id}/all" + # self.record_custom_metric(metric_name, duration) # Record supportability metrics for api calls @@ -603,7 +603,7 @@ def __exit__(self, exc, value, tb): guid=self.guid, cpu_time=self._cpu_user_time_value, suppress_transaction_trace=self.suppress_transaction_trace, - client_cross_process_id=self.client_cross_process_id, + # client_cross_process_id=self.client_cross_process_id, referring_transaction_guid=self.referring_transaction_guid, record_tt=self.record_tt, synthetics_resource_id=self.synthetics_resource_id, @@ -841,8 +841,8 @@ def trace_intrinsics(self): if self.referring_transaction_guid: i_attrs["referring_transaction_guid"] = self.referring_transaction_guid - if self.client_cross_process_id: - i_attrs["client_cross_process_id"] = self.client_cross_process_id + # if self.client_cross_process_id: + # i_attrs["client_cross_process_id"] = self.client_cross_process_id if self.trip_id: i_attrs["trip_id"] = self.trip_id # if self.path_hash: diff --git a/newrelic/api/web_transaction.py b/newrelic/api/web_transaction.py index b8a6e4daad..dc50ca4157 100644 --- a/newrelic/api/web_transaction.py +++ b/newrelic/api/web_transaction.py @@ -321,8 +321,10 @@ def process_response(self, status_code, response_headers): except Exception: pass - if self.client_cross_process_id is None: - return [] + return [] + + # if self.client_cross_process_id is None: + # return [] # # Generate CAT response headers # try: diff --git a/newrelic/common/agent_http.py b/newrelic/common/agent_http.py index 5534142547..c5e54d4962 100644 --- a/newrelic/common/agent_http.py +++ b/newrelic/common/agent_http.py @@ -521,7 +521,7 @@ class DeveloperModeClient(SupportabilityMixin, BaseClient): "url_rules": [], "collect_errors": True, "account_id": "12345", - "cross_process_id": "12345#67890", + # "cross_process_id": "12345#67890", "messages": [{"message": "Reporting to fake collector", "level": "INFO"}], "sampling_rate": 0, "collect_traces": True, diff --git a/newrelic/core/config.py b/newrelic/core/config.py index 83e18bb250..dea073a1d1 100644 --- a/newrelic/core/config.py +++ b/newrelic/core/config.py @@ -792,7 +792,7 @@ def default_otlp_host(host): _settings.transaction_segment_terms = [] _settings.account_id = os.environ.get("NEW_RELIC_ACCOUNT_ID") -_settings.cross_process_id = None +# _settings.cross_process_id = None _settings.primary_application_id = os.environ.get("NEW_RELIC_PRIMARY_APPLICATION_ID", "Unknown") _settings.trusted_account_ids = [] _settings.trusted_account_key = os.environ.get("NEW_RELIC_TRUSTED_ACCOUNT_KEY") @@ -1338,19 +1338,19 @@ def apply_server_side_settings(server_side_config=None, settings=_settings): # Special case for account_id which will be sent instead of # cross_process_id in the future - if settings_snapshot.cross_process_id is not None: - vals = [settings_snapshot.account_id, settings_snapshot.application_id] - derived_vals = settings_snapshot.cross_process_id.split("#") + # if settings_snapshot.cross_process_id is not None: + # vals = [settings_snapshot.account_id, settings_snapshot.application_id] + # derived_vals = settings_snapshot.cross_process_id.split("#") - if len(derived_vals) == 2: - for idx, _val in enumerate(derived_vals): - # only override the value if the server side does not provide - # the value specifically - if vals[idx] is None: - vals[idx] = derived_vals[idx] + # if len(derived_vals) == 2: + # for idx, _val in enumerate(derived_vals): + # # only override the value if the server side does not provide + # # the value specifically + # if vals[idx] is None: + # vals[idx] = derived_vals[idx] - settings_snapshot.account_id = vals[0] - settings_snapshot.application_id = vals[1] + # settings_snapshot.account_id = vals[0] + # settings_snapshot.application_id = vals[1] # Reapply on top any local setting overrides. diff --git a/newrelic/core/external_node.py b/newrelic/core/external_node.py index 9165d2081f..0cfc804113 100644 --- a/newrelic/core/external_node.py +++ b/newrelic/core/external_node.py @@ -40,7 +40,7 @@ class ExternalNode(_ExternalNode, GenericNodeMixin): - cross_process_id = None + # cross_process_id = None external_txn_name = None @property @@ -111,45 +111,45 @@ def time_metrics(self, stats, root, parent): # Remove cross_process_id from the params dict otherwise it shows # up in the UI. - self.cross_process_id = self.params.pop("cross_process_id") + # self.cross_process_id = self.params.pop("cross_process_id") self.external_txn_name = self.params.pop("external_txn_name") except KeyError: - self.cross_process_id = None + # self.cross_process_id = None self.external_txn_name = None name = f"External/{netloc}/all" yield TimeMetric(name=name, scope="", duration=self.duration, exclusive=self.exclusive) - if self.cross_process_id is None: - method = self.method or "" + # if self.cross_process_id is None: + method = self.method or "" - name = f"External/{netloc}/{self.library}/{method}" + name = f"External/{netloc}/{self.library}/{method}" - yield TimeMetric(name=name, scope="", duration=self.duration, exclusive=self.exclusive) + yield TimeMetric(name=name, scope="", duration=self.duration, exclusive=self.exclusive) - yield TimeMetric(name=name, scope=root.path, duration=self.duration, exclusive=self.exclusive) + yield TimeMetric(name=name, scope=root.path, duration=self.duration, exclusive=self.exclusive) - else: - name = f"ExternalTransaction/{netloc}/{self.cross_process_id}/{self.external_txn_name}" + # else: + # name = f"ExternalTransaction/{netloc}/{self.cross_process_id}/{self.external_txn_name}" - yield TimeMetric(name=name, scope="", duration=self.duration, exclusive=self.exclusive) + # yield TimeMetric(name=name, scope="", duration=self.duration, exclusive=self.exclusive) - yield TimeMetric(name=name, scope=root.path, duration=self.duration, exclusive=self.exclusive) + # yield TimeMetric(name=name, scope=root.path, duration=self.duration, exclusive=self.exclusive) - name = f"ExternalApp/{netloc}/{self.cross_process_id}/all" + # name = f"ExternalApp/{netloc}/{self.cross_process_id}/all" - yield TimeMetric(name=name, scope="", duration=self.duration, exclusive=self.exclusive) + # yield TimeMetric(name=name, scope="", duration=self.duration, exclusive=self.exclusive) def trace_node(self, stats, root, connections): netloc = self.netloc method = self.method or "" - if self.cross_process_id is None: - name = f"External/{netloc}/{self.library}/{method}" - else: - name = f"ExternalTransaction/{netloc}/{self.cross_process_id}/{self.external_txn_name}" + # if self.cross_process_id is None: + name = f"External/{netloc}/{self.library}/{method}" + # else: + # name = f"ExternalTransaction/{netloc}/{self.cross_process_id}/{self.external_txn_name}" name = root.string_table.cache(name) diff --git a/newrelic/core/transaction_node.py b/newrelic/core/transaction_node.py index 020993e0c9..754f09598d 100644 --- a/newrelic/core/transaction_node.py +++ b/newrelic/core/transaction_node.py @@ -66,7 +66,7 @@ "guid", "cpu_time", "suppress_transaction_trace", - "client_cross_process_id", + # "client_cross_process_id", "referring_transaction_guid", "record_tt", "synthetics_resource_id", diff --git a/tests/agent_features/test_error_events.py b/tests/agent_features/test_error_events.py index b96f4fe0f6..5819b1656f 100644 --- a/tests/agent_features/test_error_events.py +++ b/tests/agent_features/test_error_events.py @@ -19,7 +19,7 @@ from testing_support.fixtures import ( # cat_enabled, # make_cross_agent_headers, - # make_synthetics_headers, + make_synthetics_headers, override_application_settings, reset_core_stats_engine, validate_error_event_sample_data, @@ -29,17 +29,17 @@ from testing_support.validators.validate_transaction_error_event_count import validate_transaction_error_event_count from newrelic.api.application import application_instance as application -# from newrelic.api.application import application_settings +from newrelic.api.application import application_settings from newrelic.api.time_trace import notice_error from newrelic.common.object_names import callable_name # Error in test app hard-coded as a ValueError -# SYNTHETICS_RESOURCE_ID = "09845779-16ef-4fa7-b7f2-44da8e62931c" -# SYNTHETICS_JOB_ID = "8c7dd3ba-4933-4cbb-b1ed-b62f511782f4" -# SYNTHETICS_MONITOR_ID = "dc452ae9-1a93-4ab5-8a33-600521e9cd00" -# SYNTHETICS_TYPE = "scheduled" -# SYNTHETICS_INITIATOR = "graphql" -# SYNTHETICS_ATTRIBUTES = {"exampleAttribute": "1"} +SYNTHETICS_RESOURCE_ID = "09845779-16ef-4fa7-b7f2-44da8e62931c" +SYNTHETICS_JOB_ID = "8c7dd3ba-4933-4cbb-b1ed-b62f511782f4" +SYNTHETICS_MONITOR_ID = "dc452ae9-1a93-4ab5-8a33-600521e9cd00" +SYNTHETICS_TYPE = "scheduled" +SYNTHETICS_INITIATOR = "graphql" +SYNTHETICS_ATTRIBUTES = {"exampleAttribute": "1"} ERR_MESSAGE = "Transaction had bad value" ERROR = ValueError(ERR_MESSAGE) @@ -119,35 +119,35 @@ def test_transaction_error_dt_headers(): response = fully_featured_application.get("/", extra_environ=test_environ) -# _intrinsic_attributes = { -# "error.class": callable_name(ERROR), -# "error.message": ERR_MESSAGE, -# "error.expected": False, -# "transactionName": "WebTransaction/Uri/", -# "nr.syntheticsResourceId": SYNTHETICS_RESOURCE_ID, -# "nr.syntheticsJobId": SYNTHETICS_JOB_ID, -# "nr.syntheticsMonitorId": SYNTHETICS_MONITOR_ID, -# "nr.syntheticsType": SYNTHETICS_TYPE, -# "nr.syntheticsInitiator": SYNTHETICS_INITIATOR, -# "nr.syntheticsExampleAttribute": "1", -# } - - -# @validate_error_event_sample_data(required_attrs=_intrinsic_attributes, required_user_attrs=True) -# def test_transaction_error_with_synthetics(): -# test_environ = {"err_message": ERR_MESSAGE} -# settings = application_settings() -# headers = make_synthetics_headers( -# settings.encoding_key, -# settings.trusted_account_ids[0], -# SYNTHETICS_RESOURCE_ID, -# SYNTHETICS_JOB_ID, -# SYNTHETICS_MONITOR_ID, -# SYNTHETICS_TYPE, -# SYNTHETICS_INITIATOR, -# SYNTHETICS_ATTRIBUTES, -# ) -# response = fully_featured_application.get("/", headers=headers, extra_environ=test_environ) +_intrinsic_attributes = { + "error.class": callable_name(ERROR), + "error.message": ERR_MESSAGE, + "error.expected": False, + "transactionName": "WebTransaction/Uri/", + "nr.syntheticsResourceId": SYNTHETICS_RESOURCE_ID, + "nr.syntheticsJobId": SYNTHETICS_JOB_ID, + "nr.syntheticsMonitorId": SYNTHETICS_MONITOR_ID, + "nr.syntheticsType": SYNTHETICS_TYPE, + "nr.syntheticsInitiator": SYNTHETICS_INITIATOR, + "nr.syntheticsExampleAttribute": "1", +} + + +@validate_error_event_sample_data(required_attrs=_intrinsic_attributes, required_user_attrs=True) +def test_transaction_error_with_synthetics(): + test_environ = {"err_message": ERR_MESSAGE} + settings = application_settings() + headers = make_synthetics_headers( + settings.encoding_key, + settings.trusted_account_ids[0], + SYNTHETICS_RESOURCE_ID, + SYNTHETICS_JOB_ID, + SYNTHETICS_MONITOR_ID, + SYNTHETICS_TYPE, + SYNTHETICS_INITIATOR, + SYNTHETICS_ATTRIBUTES, + ) + response = fully_featured_application.get("/", headers=headers, extra_environ=test_environ) _intrinsic_attributes = { diff --git a/tests/agent_unittests/test_harvest_loop.py b/tests/agent_unittests/test_harvest_loop.py index 9f78214575..bac9c5585d 100644 --- a/tests/agent_unittests/test_harvest_loop.py +++ b/tests/agent_unittests/test_harvest_loop.py @@ -134,7 +134,7 @@ def transaction_node(request): guid="4485b89db608aece", cpu_time=0.0, suppress_transaction_trace=False, - client_cross_process_id=None, + # client_cross_process_id=None, referring_transaction_guid=None, record_tt=False, synthetics_resource_id=None, diff --git a/tests/messagebroker_pika/test_distributed_tracing.py b/tests/messagebroker_pika/test_distributed_tracing.py index f23e3e43a6..75dfd17b08 100644 --- a/tests/messagebroker_pika/test_distributed_tracing.py +++ b/tests/messagebroker_pika/test_distributed_tracing.py @@ -140,7 +140,7 @@ def do_basic_get(channel, QUEUE): txn = current_transaction() - assert txn.client_cross_process_id is None + # assert txn.client_cross_process_id is None assert txn.client_account_id is None assert txn.client_application_id is None From 1adb30763be45a0548dee8e38cd4d31df4502d07 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 18:41:56 -0700 Subject: [PATCH 21/95] Remove external_txn_name --- newrelic/core/external_node.py | 20 ++++++++++---------- tests/testing_support/external_fixtures.py | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/newrelic/core/external_node.py b/newrelic/core/external_node.py index 0cfc804113..ceea3f0cac 100644 --- a/newrelic/core/external_node.py +++ b/newrelic/core/external_node.py @@ -41,7 +41,7 @@ class ExternalNode(_ExternalNode, GenericNodeMixin): # cross_process_id = None - external_txn_name = None + # external_txn_name = None @property def details(self): @@ -107,15 +107,15 @@ def time_metrics(self, stats, root, parent): netloc = self.netloc - try: - # Remove cross_process_id from the params dict otherwise it shows - # up in the UI. - - # self.cross_process_id = self.params.pop("cross_process_id") - self.external_txn_name = self.params.pop("external_txn_name") - except KeyError: - # self.cross_process_id = None - self.external_txn_name = None + # try: + # # Remove cross_process_id from the params dict otherwise it shows + # # up in the UI. + + # self.cross_process_id = self.params.pop("cross_process_id") + # self.external_txn_name = self.params.pop("external_txn_name") + # except KeyError: + # self.cross_process_id = None + # self.external_txn_name = None name = f"External/{netloc}/all" diff --git a/tests/testing_support/external_fixtures.py b/tests/testing_support/external_fixtures.py index e0d72aad8a..5bf7928dc5 100644 --- a/tests/testing_support/external_fixtures.py +++ b/tests/testing_support/external_fixtures.py @@ -16,7 +16,7 @@ from newrelic.api.external_trace import ExternalTrace from newrelic.api.transaction import current_transaction -from newrelic.common.encoding_utils import json_encode, obfuscate +# from newrelic.common.encoding_utils import json_encode, obfuscate from newrelic.common.object_wrapper import transient_function_wrapper From 46436eb7c560eab1e904e0cadf924e7a7fa71f05 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 18:47:18 -0700 Subject: [PATCH 22/95] Remove referring_transaction_guid --- newrelic/api/transaction.py | 8 ++++---- newrelic/core/transaction_node.py | 2 +- tests/agent_unittests/test_harvest_loop.py | 2 +- .../validators/validate_distributed_tracing_header.py | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/newrelic/api/transaction.py b/newrelic/api/transaction.py index 334d7e0924..57b2724660 100644 --- a/newrelic/api/transaction.py +++ b/newrelic/api/transaction.py @@ -292,7 +292,7 @@ def __init__(self, application, enabled=None, source=None): # self.client_cross_process_id = None self.client_account_id = None self.client_application_id = None - self.referring_transaction_guid = None + # self.referring_transaction_guid = None self.record_tt = False self._trip_id = None # self._referring_path_hash = None @@ -604,7 +604,7 @@ def __exit__(self, exc, value, tb): cpu_time=self._cpu_user_time_value, suppress_transaction_trace=self.suppress_transaction_trace, # client_cross_process_id=self.client_cross_process_id, - referring_transaction_guid=self.referring_transaction_guid, + # referring_transaction_guid=self.referring_transaction_guid, record_tt=self.record_tt, synthetics_resource_id=self.synthetics_resource_id, synthetics_job_id=self.synthetics_job_id, @@ -839,8 +839,8 @@ def trace_intrinsics(self): """Intrinsic attributes for transaction traces and error traces""" i_attrs = {} - if self.referring_transaction_guid: - i_attrs["referring_transaction_guid"] = self.referring_transaction_guid + # if self.referring_transaction_guid: + # i_attrs["referring_transaction_guid"] = self.referring_transaction_guid # if self.client_cross_process_id: # i_attrs["client_cross_process_id"] = self.client_cross_process_id if self.trip_id: diff --git a/newrelic/core/transaction_node.py b/newrelic/core/transaction_node.py index 754f09598d..2cf6713d2b 100644 --- a/newrelic/core/transaction_node.py +++ b/newrelic/core/transaction_node.py @@ -67,7 +67,7 @@ "cpu_time", "suppress_transaction_trace", # "client_cross_process_id", - "referring_transaction_guid", + # "referring_transaction_guid", "record_tt", "synthetics_resource_id", "synthetics_job_id", diff --git a/tests/agent_unittests/test_harvest_loop.py b/tests/agent_unittests/test_harvest_loop.py index bac9c5585d..1a86f551bf 100644 --- a/tests/agent_unittests/test_harvest_loop.py +++ b/tests/agent_unittests/test_harvest_loop.py @@ -135,7 +135,7 @@ def transaction_node(request): cpu_time=0.0, suppress_transaction_trace=False, # client_cross_process_id=None, - referring_transaction_guid=None, + # referring_transaction_guid=None, record_tt=False, synthetics_resource_id=None, synthetics_job_id=None, diff --git a/tests/testing_support/validators/validate_distributed_tracing_header.py b/tests/testing_support/validators/validate_distributed_tracing_header.py index 9034db6634..4015b819e2 100644 --- a/tests/testing_support/validators/validate_distributed_tracing_header.py +++ b/tests/testing_support/validators/validate_distributed_tracing_header.py @@ -65,10 +65,10 @@ def validate_distributed_tracing_header(header="newrelic"): # Verify referring transaction information assert len(data["tr"]) == 32 - if transaction.referring_transaction_guid is not None: - assert data["tr"] == transaction._trace_id - else: - assert data["tr"].startswith(transaction.guid) + # if transaction.referring_transaction_guid is not None: + # assert data["tr"] == transaction._trace_id + # else: + assert data["tr"].startswith(transaction.guid) assert "pa" not in data From 855d65e087db8c86c3a6d9341d3da0fae3e333e5 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 19:20:24 -0700 Subject: [PATCH 23/95] Remove trip_id --- newrelic/api/transaction.py | 16 +++---- newrelic/core/transaction_node.py | 2 +- tests/agent_features/test_attribute.py | 3 +- .../test_attributes_in_action.py | 45 ++++++++++--------- tests/agent_unittests/test_harvest_loop.py | 2 +- 5 files changed, 37 insertions(+), 31 deletions(-) diff --git a/newrelic/api/transaction.py b/newrelic/api/transaction.py index 57b2724660..4d09a60664 100644 --- a/newrelic/api/transaction.py +++ b/newrelic/api/transaction.py @@ -34,7 +34,7 @@ W3CTraceParent, W3CTraceState, base64_decode, - convert_to_cat_metadata_value, + # convert_to_cat_metadata_value, deobfuscate, ensure_str, # generate_path_hash, @@ -294,7 +294,7 @@ def __init__(self, application, enabled=None, source=None): self.client_application_id = None # self.referring_transaction_guid = None self.record_tt = False - self._trip_id = None + # self._trip_id = None # self._referring_path_hash = None # self._alternate_path_hashes = {} # self.is_part_of_cat = False @@ -615,7 +615,7 @@ def __exit__(self, exc, value, tb): synthetics_attributes=self.synthetics_attributes, synthetics_info_header=self.synthetics_info_header, # is_part_of_cat=self.is_part_of_cat, - trip_id=self.trip_id, + # trip_id=self.trip_id, # path_hash=self.path_hash, # referring_path_hash=self._referring_path_hash, # alternate_path_hashes=self.alternate_path_hashes, @@ -736,9 +736,9 @@ def path(self): return f"{self.type}/{self.name_for_metric}" - @property - def trip_id(self): - return self._trip_id or self.guid + # @property + # def trip_id(self): + # return self._trip_id or self.guid @property def trace_id(self): @@ -843,8 +843,8 @@ def trace_intrinsics(self): # i_attrs["referring_transaction_guid"] = self.referring_transaction_guid # if self.client_cross_process_id: # i_attrs["client_cross_process_id"] = self.client_cross_process_id - if self.trip_id: - i_attrs["trip_id"] = self.trip_id + # if self.trip_id: + # i_attrs["trip_id"] = self.trip_id # if self.path_hash: # i_attrs["path_hash"] = self.path_hash if self.synthetics_resource_id: diff --git a/newrelic/core/transaction_node.py b/newrelic/core/transaction_node.py index 2cf6713d2b..1c5364dda2 100644 --- a/newrelic/core/transaction_node.py +++ b/newrelic/core/transaction_node.py @@ -78,7 +78,7 @@ "synthetics_attributes", "synthetics_info_header", # "is_part_of_cat", - "trip_id", + # "trip_id", # "path_hash", # "referring_path_hash", # "alternate_path_hashes", diff --git a/tests/agent_features/test_attribute.py b/tests/agent_features/test_attribute.py index a8410eab6b..a22a42605d 100644 --- a/tests/agent_features/test_attribute.py +++ b/tests/agent_features/test_attribute.py @@ -56,7 +56,8 @@ def target_wsgi_application(environ, start_response): return [output] -_required_intrinsics = ["trip_id", "totalTime"] +_required_intrinsics = ["totalTime"] +# _required_intrinsics = ["trip_id", "totalTime"] _forgone_intrinsics = [] diff --git a/tests/agent_features/test_attributes_in_action.py b/tests/agent_features/test_attributes_in_action.py index 318218a398..2d1aeff782 100644 --- a/tests/agent_features/test_attributes_in_action.py +++ b/tests/agent_features/test_attributes_in_action.py @@ -101,7 +101,7 @@ "timestamp", "totalTime", "error", - # "nr.apdexPerfZone", + "nr.apdexPerfZone", "apdexPerfZone", ) TRANS_EVENT_AGENT_KEYS = [ @@ -175,7 +175,8 @@ def normal_application(request): # Tests for checking the presence and format of agent attributes. # Test default settings. -_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": ["trip_id"]} +# _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": []} _expected_attributes_event = { "agent": TRACE_ERROR_AGENT_KEYS, @@ -193,7 +194,8 @@ def test_error_in_transaction_default_settings(normal_application): normal_application.get(REQUEST_URL, headers=REQUEST_HEADERS) -_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} +# _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": []} # @cat_enabled @@ -240,7 +242,8 @@ def test_browser_default_attribute_settings(normal_application): _override_settings = {"error_collector.attributes.exclude": ["request.parameters.*"]} -_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": []} +# _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": ["trip_id"]} _expected_attributes_event = { "agent": TRACE_ERROR_AGENT_KEYS, @@ -260,7 +263,8 @@ def test_error_in_transaction_exclude_request_params(normal_application): _override_settings = {"transaction_tracer.attributes.exclude": ["request.parameters.*"]} -_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": []} +# _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} @validate_transaction_trace_attributes(_expected_attributes, _expected_absent_attributes) @@ -271,7 +275,8 @@ def test_transaction_trace_exclude_request_params(normal_application): _override_settings = {"capture_params": True, "error_collector.attributes.exclude": ["request.parameters.*"]} -_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": []} +# _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} _expected_absent_attributes = {"agent": REQ_PARAMS, "user": [], "intrinsic": []} @@ -295,7 +300,7 @@ def test_transaction_trace_capture_params_exclude_request_params(normal_applicat _override_settings = {"error_collector.attributes.include": ["request.parameters.*"]} -_expected_attributes = {"agent": AGENT_KEYS_ALL, "user": ERROR_USER_ATTRS, "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": AGENT_KEYS_ALL, "user": ERROR_USER_ATTRS, "intrinsic": []} _expected_attributes_event = {"agent": AGENT_KEYS_ALL, "user": ERROR_USER_ATTRS, "intrinsic": ERROR_EVENT_INTRINSICS} @@ -309,7 +314,7 @@ def test_error_in_transaction_include_request_params(normal_application): _override_settings = {"transaction_tracer.attributes.include": ["request.parameters.*"]} -_expected_attributes = {"agent": AGENT_KEYS_ALL, "user": USER_ATTRS, "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": AGENT_KEYS_ALL, "user": USER_ATTRS, "intrinsic": []} @validate_transaction_trace_attributes(_expected_attributes) @@ -362,7 +367,7 @@ def test_browser_include_request_params(normal_application): _expected_attributes = { "agent": [*TRACE_ERROR_AGENT_KEYS, f"request.parameters.{URL_PARAM}"], "user": ERROR_USER_ATTRS, - "intrinsic": ["trip_id"], + "intrinsic": [], } _expected_attributes_event = { @@ -389,7 +394,7 @@ def test_error_in_transaction_include_exclude(normal_application): _expected_attributes = { "agent": [*TRACE_ERROR_AGENT_KEYS, f"request.parameters.{URL_PARAM}"], "user": USER_ATTRS, - "intrinsic": ["trip_id"], + "intrinsic": [], } @@ -444,7 +449,7 @@ def test_browser_include_exclude_request_params(normal_application): _override_settings = {"error_collector.attributes.exclude": ["puppies"]} -_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ["sunshine", "ohnoes"], "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ["sunshine", "ohnoes"], "intrinsic": []} _expected_attributes_event = { "agent": TRACE_ERROR_AGENT_KEYS, @@ -464,7 +469,7 @@ def test_error_in_transaction_exclude_user_attribute(normal_application): _override_settings = {"transaction_tracer.attributes.exclude": ["puppies"]} -_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ["sunshine"], "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ["sunshine"], "intrinsic": []} @validate_transaction_trace_attributes(_expected_attributes, _expected_absent_attributes) @@ -519,7 +524,7 @@ def test_browser_exclude_user_attribute(normal_application): _expected_attributes = { "agent": ["response.status", "request.headers.contentType", "request.headers.contentLength"], "user": ERROR_USER_ATTRS, - "intrinsic": ["trip_id"], + "intrinsic": [], } _expected_attributes_event = { @@ -541,7 +546,7 @@ def test_error_in_transaction_exclude_agent_attribute(normal_application): _expected_attributes = { "agent": ["response.status", "request.headers.contentType", "request.headers.contentLength"], "user": USER_ATTRS, - "intrinsic": ["trip_id"], + "intrinsic": [], } @@ -693,9 +698,9 @@ def test_browser_deprecated_capture_params_false(normal_application): # Test attempt to exclude intrinsic. -_override_settings = {"error_collector.attributes.exclude": ["trip_id"]} +_override_settings = {"error_collector.attributes.exclude": []} -_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": []} _expected_attributes_event = { "agent": TRACE_ERROR_AGENT_KEYS, @@ -713,9 +718,9 @@ def test_error_in_transaction_exclude_intrinsic(normal_application): normal_application.get(REQUEST_URL, headers=REQUEST_HEADERS) -_override_settings = {"transaction_tracer.attributes.exclude": ["trip_id"]} +_override_settings = {"transaction_tracer.attributes.exclude": []} -_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": []} @validate_transaction_trace_attributes(_expected_attributes, _expected_absent_attributes) @@ -757,7 +762,7 @@ def test_browser_exclude_intrinsic(normal_application): _override_settings = {"error_collector.attributes.enabled": False} -_expected_attributes = {"user": [], "agent": [], "intrinsic": ["trip_id"]} +_expected_attributes = {"user": [], "agent": [], "intrinsic": []} _expected_attributes_event = {"user": [], "agent": [], "intrinsic": ERROR_EVENT_INTRINSICS} @@ -810,7 +815,7 @@ def test_browser_attributes_disabled(normal_application): _override_settings = {"error_collector.attributes.exclude": ERROR_PARAMS} -_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": []} _expected_attributes_event = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ERROR_EVENT_INTRINSICS} diff --git a/tests/agent_unittests/test_harvest_loop.py b/tests/agent_unittests/test_harvest_loop.py index 1a86f551bf..fb572814d3 100644 --- a/tests/agent_unittests/test_harvest_loop.py +++ b/tests/agent_unittests/test_harvest_loop.py @@ -146,7 +146,7 @@ def transaction_node(request): synthetics_attributes=None, synthetics_info_header=None, # is_part_of_cat=False, - trip_id="4485b89db608aece", + # trip_id="4485b89db608aece", # path_hash=None, # referring_path_hash=None, # alternate_path_hashes=[], From 954177d4ee3cf0d7d12376697d4424a9c6ca847b Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 19:20:54 -0700 Subject: [PATCH 24/95] Remove convert_to_cat_metadata_value --- newrelic/common/encoding_utils.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/newrelic/common/encoding_utils.py b/newrelic/common/encoding_utils.py index 38f81ea397..3a5d34c3d5 100644 --- a/newrelic/common/encoding_utils.py +++ b/newrelic/common/encoding_utils.py @@ -368,13 +368,13 @@ def decode_newrelic_header(encoded_header, encoding_key): return decoded_header -def convert_to_cat_metadata_value(nr_headers): - if not nr_headers: - return None +# def convert_to_cat_metadata_value(nr_headers): +# if not nr_headers: +# return None - payload = json_encode(nr_headers) - cat_linking_value = base64_encode(payload) - return cat_linking_value +# payload = json_encode(nr_headers) +# cat_linking_value = base64_encode(payload) +# return cat_linking_value class DistributedTracePayload(dict): From 0f29d92bbb5ed261f5934dd535eabd76aa53445a Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 19:21:15 -0700 Subject: [PATCH 25/95] Change names from cat_ to dt_ --- newrelic/hooks/framework_aiohttp.py | 22 +++++++++++----------- newrelic/hooks/framework_sanic.py | 12 ++++++------ newrelic/hooks/framework_tornado.py | 4 ++-- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/newrelic/hooks/framework_aiohttp.py b/newrelic/hooks/framework_aiohttp.py index 04d9f2484b..956f1bcc57 100644 --- a/newrelic/hooks/framework_aiohttp.py +++ b/newrelic/hooks/framework_aiohttp.py @@ -215,18 +215,18 @@ def items(self): return itertools.chain(self.__wrapped__.items(), nr_headers.items()) -def _nr_aiohttp_add_cat_headers_(wrapped, instance, args, kwargs): +def _nr_aiohttp_add_dt_headers_(wrapped, instance, args, kwargs): transaction = current_transaction() if transaction is None: return wrapped(*args, **kwargs) try: - cat_headers = ExternalTrace.generate_request_headers(transaction) + dt_headers = ExternalTrace.generate_request_headers(transaction) except: return wrapped(*args, **kwargs) tmp = instance.headers - instance.headers = HeaderProxy(tmp, cat_headers) + instance.headers = HeaderProxy(tmp, dt_headers) if is_coroutine_callable(wrapped): @@ -245,21 +245,21 @@ async def new_coro(): instance.headers = tmp -def _nr_aiohttp_add_cat_headers_simple_(wrapped, instance, args, kwargs): +def _nr_aiohttp_add_dt_headers_simple_(wrapped, instance, args, kwargs): transaction = current_transaction() if transaction is None: return wrapped(*args, **kwargs) try: - cat_headers = ExternalTrace.generate_request_headers(transaction) + dt_headers = ExternalTrace.generate_request_headers(transaction) except: return wrapped(*args, **kwargs) - for k, _ in cat_headers: + for k, _ in dt_headers: if k in instance.headers: return wrapped(*args, **kwargs) - instance.headers.update(cat_headers) + instance.headers.update(dt_headers) return wrapped(*args, **kwargs) @@ -304,15 +304,15 @@ def instrument_aiohttp_client_reqrep(module): if version_info >= (2, 0): # TODO: Verify that headers_preserve_casting is always True # if headers_preserve_casing(): - cat_wrapper = _nr_aiohttp_add_cat_headers_simple_ + dt_wrapper = _nr_aiohttp_add_dt_headers_simple_ # else: - # cat_wrapper = _nr_aiohttp_add_cat_headers_ + # dt_wrapper = _nr_aiohttp_add_dt_headers_ - wrap_function_wrapper(module, "ClientRequest.send", cat_wrapper) + wrap_function_wrapper(module, "ClientRequest.send", dt_wrapper) def instrument_aiohttp_protocol(module): - wrap_function_wrapper(module, "Request.send_headers", _nr_aiohttp_add_cat_headers_) + wrap_function_wrapper(module, "Request.send_headers", _nr_aiohttp_add_dt_headers_) def instrument_aiohttp_web_urldispatcher(module): diff --git a/newrelic/hooks/framework_sanic.py b/newrelic/hooks/framework_sanic.py index 14077eb6d9..a201cba5a0 100644 --- a/newrelic/hooks/framework_sanic.py +++ b/newrelic/hooks/framework_sanic.py @@ -170,9 +170,9 @@ def _nr_sanic_response_get_headers(wrapped, instance, args, kwargs): return result # instance is the response object - cat_headers = transaction.process_response(str(instance.status), instance.headers.items()) + dt_headers = transaction.process_response(str(instance.status), instance.headers.items()) - for header_name, header_value in cat_headers: + for header_name, header_value in dt_headers: if header_name not in instance.headers: instance.headers[header_name] = header_value @@ -189,9 +189,9 @@ async def _nr_sanic_response_send(wrapped, instance, args, kwargs): return result # instance is the response object - cat_headers = transaction.process_response(str(instance.status), instance.headers.items()) + dt_headers = transaction.process_response(str(instance.status), instance.headers.items()) - for header_name, header_value in cat_headers: + for header_name, header_value in dt_headers: if header_name not in instance.headers: instance.headers[header_name] = header_value @@ -205,9 +205,9 @@ def _nr_sanic_response_parse_headers(wrapped, instance, args, kwargs): return wrapped(*args, **kwargs) # instance is the response object - cat_headers = transaction.process_response(str(instance.status), instance.headers.items()) + dt_headers = transaction.process_response(str(instance.status), instance.headers.items()) - for header_name, header_value in cat_headers: + for header_name, header_value in dt_headers: if header_name not in instance.headers: instance.headers[header_name] = header_value diff --git a/newrelic/hooks/framework_tornado.py b/newrelic/hooks/framework_tornado.py index 92b6a84019..4b7c1cd523 100644 --- a/newrelic/hooks/framework_tornado.py +++ b/newrelic/hooks/framework_tornado.py @@ -132,9 +132,9 @@ def wrap_write_headers(wrapped, instance, args, kwargs): if transaction: http_status, headers = _bind_response_headers(*args, **kwargs) - cat_headers = transaction.process_response(http_status, headers) + dt_headers = transaction.process_response(http_status, headers) - for name, value in cat_headers: + for name, value in dt_headers: headers.add(name, value) return wrapped(*args, **kwargs) From e550a5c6f7fdc4b50f1bd3baedc003316a35cfae Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 20:02:04 -0700 Subject: [PATCH 26/95] Tweak test --- tests/agent_features/test_attributes_in_action.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/agent_features/test_attributes_in_action.py b/tests/agent_features/test_attributes_in_action.py index 2d1aeff782..3fdcd62817 100644 --- a/tests/agent_features/test_attributes_in_action.py +++ b/tests/agent_features/test_attributes_in_action.py @@ -101,7 +101,7 @@ "timestamp", "totalTime", "error", - "nr.apdexPerfZone", + # "nr.apdexPerfZone", "apdexPerfZone", ) TRANS_EVENT_AGENT_KEYS = [ @@ -184,7 +184,7 @@ def normal_application(request): "intrinsic": ERROR_EVENT_INTRINSICS, } -_expected_absent_attributes = {"agent": REQ_PARAMS, "user": [], "intrinsic": DISTRIBUTED_TRACE_ATTRS} +_expected_absent_attributes = {"agent": REQ_PARAMS, "user": [], "intrinsic": []} # @cat_enabled @@ -200,7 +200,7 @@ def test_error_in_transaction_default_settings(normal_application): # @cat_enabled @validate_transaction_trace_attributes(_expected_attributes, _expected_absent_attributes) -@override_application_settings({}) +# @override_application_settings({}) def test_transaction_trace_default_attribute_settings(normal_application): normal_application.get(REQUEST_URL, headers=REQUEST_HEADERS) From c120b3fcea2f882fafb9d5692db74ae05d26ae19 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Thu, 11 Sep 2025 19:13:31 -0700 Subject: [PATCH 27/95] Remove skip all test file --- tests/framework_aiohttp/test_client.py | 241 ------------------------- 1 file changed, 241 deletions(-) delete mode 100644 tests/framework_aiohttp/test_client.py diff --git a/tests/framework_aiohttp/test_client.py b/tests/framework_aiohttp/test_client.py deleted file mode 100644 index 751ad4c965..0000000000 --- a/tests/framework_aiohttp/test_client.py +++ /dev/null @@ -1,241 +0,0 @@ -# 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 asyncio - -import aiohttp -import pytest -from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics -from yarl import URL - -from newrelic.api.background_task import background_task -from newrelic.api.function_trace import function_trace - -version_info = tuple(int(_) for _ in aiohttp.__version__.split(".")[:2]) -skipif_aiohttp3 = pytest.mark.skipif( - version_info >= (3, 0), reason="This version of aiohttp does not support yield from syntax" -) - - -async def fetch(method, url): - with aiohttp.ClientSession() as session: - _method = getattr(session, method) - response = await asyncio.wait_for(_method(url), timeout=None) - response.raise_for_status() - await response.text() - - -@background_task(name="fetch_multiple") -async def fetch_multiple(method, url): - coros = [fetch(method, url) for _ in range(2)] - return asyncio.gather(*coros, return_exceptions=True) - - -if version_info < (2, 0): - _expected_error_class = aiohttp.errors.HttpProcessingError -else: - _expected_error_class = aiohttp.client_exceptions.ClientResponseError - - -def task(loop, method, exc_expected, url): - future = asyncio.ensure_future(fetch_multiple(method, url)) - text_list = loop.run_until_complete(future) - if exc_expected: - assert isinstance(text_list[0], _expected_error_class) - assert isinstance(text_list[1], _expected_error_class) - else: - assert text_list[0] == text_list[1] - - -test_matrix = ( - ("get", False), - ("post", True), - ("options", True), - ("head", True), - ("put", True), - ("patch", True), - ("delete", True), -) - - -@skipif_aiohttp3 -@pytest.mark.parametrize("method,exc_expected", test_matrix) -def test_client_yield_from(event_loop, local_server_info, method, exc_expected): - @validate_transaction_metrics( - "fetch_multiple", - background_task=True, - scoped_metrics=[(local_server_info.base_metric + method.upper(), 2)], - rollup_metrics=[(local_server_info.base_metric + method.upper(), 2)], - ) - def task_test(): - task(event_loop, method, exc_expected, local_server_info.url) - - task_test() - - -@skipif_aiohttp3 -def test_client_yarl_yield_from(event_loop, local_server_info): - method = "get" - - @validate_transaction_metrics( - "fetch_multiple", - background_task=True, - scoped_metrics=[(local_server_info.base_metric + method.upper(), 2)], - rollup_metrics=[(local_server_info.base_metric + method.upper(), 2)], - ) - def task_test(): - task(event_loop, method, False, URL(local_server_info.url)) - - task_test() - - -@skipif_aiohttp3 -@pytest.mark.parametrize("method,exc_expected", test_matrix) -def test_client_no_txn_yield_from(event_loop, local_server_info, method, exc_expected): - def task_test(): - task(event_loop, method, exc_expected, local_server_info.url) - - task_test() - - -@skipif_aiohttp3 -@pytest.mark.parametrize("method,exc_expected", test_matrix) -def test_client_throw_yield_from(event_loop, local_server_info, method, exc_expected): - class ThrowerException(ValueError): - pass - - @background_task(name="test_client_throw_yield_from") - async def self_driving_thrower(): - with aiohttp.ClientSession() as session: - coro = session._request(method.upper(), local_server_info.url) - - # activate the coroutine - coro.send(None) - - # inject error - coro.throw(ThrowerException()) - - @validate_transaction_metrics( - "test_client_throw_yield_from", - background_task=True, - scoped_metrics=[(local_server_info.base_metric + method.upper(), 1)], - rollup_metrics=[(local_server_info.base_metric + method.upper(), 1)], - ) - def task_test(): - with pytest.raises(ThrowerException): - event_loop.run_until_complete(self_driving_thrower()) - - task_test() - - -@skipif_aiohttp3 -@pytest.mark.parametrize("method,exc_expected", test_matrix) -def test_client_close_yield_from(event_loop, local_server_info, method, exc_expected): - @background_task(name="test_client_close_yield_from") - async def self_driving_closer(): - with aiohttp.ClientSession() as session: - coro = session._request(method.upper(), local_server_info.url) - - # activate the coroutine - coro.send(None) - - # force close - coro.close() - - @validate_transaction_metrics( - "test_client_close_yield_from", - background_task=True, - scoped_metrics=[(local_server_info.base_metric + method.upper(), 1)], - rollup_metrics=[(local_server_info.base_metric + method.upper(), 1)], - ) - def task_test(): - event_loop.run_until_complete(self_driving_closer()) - - task_test() - - -test_ws_matrix = ( - # the 127.0.0.1 server does not accept websocket requests, hence an - # exception is expected but a metric will still be created - ("ws_connect", True), -) - - -@skipif_aiohttp3 -@pytest.mark.parametrize("method,exc_expected", test_ws_matrix) -def test_ws_connect_yield_from(event_loop, local_server_info, method, exc_expected): - @validate_transaction_metrics( - "fetch_multiple", - background_task=True, - scoped_metrics=[(f"{local_server_info.base_metric}GET", 2)], - rollup_metrics=[(f"{local_server_info.base_metric}GET", 2)], - ) - def task_test(): - task(event_loop, method, exc_expected, local_server_info.url) - - task_test() - - -@skipif_aiohttp3 -@pytest.mark.parametrize("method,exc_expected", test_matrix) -def test_create_task_yield_from(event_loop, local_server_info, method, exc_expected): - # `loop.create_task` returns a Task object which uses the coroutine's - # `send` method, not `__next__` - - async def fetch_task(loop): - with aiohttp.ClientSession() as session: - coro = getattr(session, method) - resp = await loop.create_task(coro(local_server_info.url)) - resp.raise_for_status() - await resp.text() - - @background_task(name="test_create_task_yield_from") - async def fetch_multiple(loop): - coros = [fetch_task(loop) for _ in range(2)] - return asyncio.gather(*coros, return_exceptions=True) - - @validate_transaction_metrics( - "test_create_task_yield_from", - background_task=True, - scoped_metrics=[(local_server_info.base_metric + method.upper(), 2)], - rollup_metrics=[(local_server_info.base_metric + method.upper(), 2)], - ) - def task_test(): - result = event_loop.run_until_complete(fetch_multiple(event_loop)) - if exc_expected: - assert isinstance(result[0], _expected_error_class) - assert isinstance(result[1], _expected_error_class) - else: - assert result[0] == result[1] - - task_test() - - -@skipif_aiohttp3 -@pytest.mark.parametrize("method,exc_expected", test_matrix) -def test_terminal_node_yield_from(event_loop, local_server_info, method, exc_expected): - """ - This test injects a terminal node into a simple background task workflow. - It was added to validate a bug where our coro.send() wrapper would fail - when transaction's current node was terminal. - """ - - def task_test(): - @function_trace(terminal=True) - def execute_task(): - task(event_loop, method, exc_expected, local_server_info.url) - - execute_task() - - task_test() From 8d0db2c1d13200d5eae69dbcc915738225c0eea3 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Thu, 11 Sep 2025 19:14:44 -0700 Subject: [PATCH 28/95] Fix syntax from rebase --- newrelic/core/agent_protocol.py | 1 + newrelic/hooks/framework_tornado.py | 4 ++-- tests/agent_features/test_attributes_in_action.py | 12 ++++++++---- tests/framework_aiohttp/conftest.py | 5 +++-- tests/framework_aiohttp/test_client_async_await.py | 9 ++++++--- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/newrelic/core/agent_protocol.py b/newrelic/core/agent_protocol.py index 7570dd00e2..bc7727c6e1 100644 --- a/newrelic/core/agent_protocol.py +++ b/newrelic/core/agent_protocol.py @@ -522,6 +522,7 @@ def finalize(self): @classmethod def connect(cls, app_name, linked_applications, environment, settings, client_cls=ServerlessModeClient): aws_lambda_metadata = settings.aws_lambda_metadata + settings = finalize_application_settings() # settings = finalize_application_settings({"cross_application_tracer.enabled": False}, settings) # Metadata must come from the original settings object since it # can be modified later diff --git a/newrelic/hooks/framework_tornado.py b/newrelic/hooks/framework_tornado.py index 4b7c1cd523..1c865d139c 100644 --- a/newrelic/hooks/framework_tornado.py +++ b/newrelic/hooks/framework_tornado.py @@ -253,7 +253,7 @@ async def wrapper(req, raise_error): raise finally: if response: - trace.process_response(response.status_code) + trace.process_response(response.code) # trace.process_response_headers(response.headers.get_all()) return response @@ -270,7 +270,7 @@ def wrap_httpclient_fetch(wrapped, instance, args, kwargs): outgoing_headers = trace.generate_request_headers(current_transaction()) for header_name, header_value in outgoing_headers: - # User headers should override our CAT headers + # User headers should override our headers if header_name in req.headers: continue req.headers[header_name] = header_value diff --git a/tests/agent_features/test_attributes_in_action.py b/tests/agent_features/test_attributes_in_action.py index 3fdcd62817..8d60666b15 100644 --- a/tests/agent_features/test_attributes_in_action.py +++ b/tests/agent_features/test_attributes_in_action.py @@ -592,7 +592,8 @@ def test_span_event_exclude_agent_attribute(normal_application): _override_settings = {"capture_params": True} -_expected_attributes = {"agent": AGENT_KEYS_ALL, "user": ERROR_USER_ATTRS, "intrinsic": ["trip_id"]} +# _expected_attributes = {"agent": AGENT_KEYS_ALL, "user": ERROR_USER_ATTRS, "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": AGENT_KEYS_ALL, "user": ERROR_USER_ATTRS, "intrinsic": []} _expected_attributes_event = {"agent": AGENT_KEYS_ALL, "user": ERROR_USER_ATTRS, "intrinsic": ERROR_EVENT_INTRINSICS} @@ -604,7 +605,8 @@ def test_error_in_transaction_deprecated_capture_params_true(normal_application) normal_application.get(REQUEST_URL, headers=REQUEST_HEADERS) -_expected_attributes = {"agent": AGENT_KEYS_ALL, "user": USER_ATTRS, "intrinsic": ["trip_id"]} +# _expected_attributes = {"agent": AGENT_KEYS_ALL, "user": USER_ATTRS, "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": AGENT_KEYS_ALL, "user": USER_ATTRS, "intrinsic": []} @validate_transaction_trace_attributes(_expected_attributes) @@ -643,7 +645,8 @@ def test_browser_deprecated_capture_params_true(normal_application): _override_settings = {"capture_params": False} -_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": ["trip_id"]} +# _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": []} _expected_attributes_event = { "agent": TRACE_ERROR_AGENT_KEYS, @@ -661,7 +664,8 @@ def test_error_in_transaction_deprecated_capture_params_false(normal_application normal_application.get(REQUEST_URL, headers=REQUEST_HEADERS) -_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} +# _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": []} @validate_transaction_trace_attributes(_expected_attributes, _expected_absent_attributes) diff --git a/tests/framework_aiohttp/conftest.py b/tests/framework_aiohttp/conftest.py index cfcea49122..ea2688def3 100644 --- a/tests/framework_aiohttp/conftest.py +++ b/tests/framework_aiohttp/conftest.py @@ -115,7 +115,7 @@ def handler(self): def mock_external_http_server(): response_values = [] - def respond_with_cat_header(self): + def respond_with_dt_header(self): headers, response_code = response_values.pop() self.send_response(response_code) for header, value in headers: @@ -124,7 +124,8 @@ def respond_with_cat_header(self): self.wfile.write(b"") # with MockExternalHTTPServer(handler=respond_with_cat_header) as server: - with MockExternalHTTPServer() as server: + # with MockExternalHTTPServer() as server: + with MockExternalHTTPServer(handler=respond_with_dt_header) as server: yield (server, response_values) diff --git a/tests/framework_aiohttp/test_client_async_await.py b/tests/framework_aiohttp/test_client_async_await.py index 8e57305060..3b2856e969 100644 --- a/tests/framework_aiohttp/test_client_async_await.py +++ b/tests/framework_aiohttp/test_client_async_await.py @@ -52,7 +52,8 @@ def task(loop, method, exc_expected, url): assert isinstance(text_list[0], _expected_error_class), text_list[0].__class__ assert isinstance(text_list[1], _expected_error_class), text_list[1].__class__ else: - assert text_list[0] == text_list[1], text_list + assert text_list[0] + assert text_list[1] test_matrix = ( @@ -133,7 +134,8 @@ def task_test(): assert isinstance(text_list[0], _expected_error_class), text_list[0].__class__ assert isinstance(text_list[1], _expected_error_class), text_list[1].__class__ else: - assert text_list[0] == text_list[1], text_list + assert text_list[0] + assert text_list[1] task_test() @@ -189,7 +191,8 @@ def task_test(): assert isinstance(result[0], _expected_error_class), result[0].__class__ assert isinstance(result[1], _expected_error_class), result[1].__class__ else: - assert result[0] == result[1] + assert result[0] + assert result[1] task_test() From a315e5d66eb8ac507a974bbe35d4a7ce31eb24ca Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Fri, 12 Sep 2025 12:04:10 -0700 Subject: [PATCH 29/95] Fix httplib test --- tests/external_httplib/test_httplib.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/external_httplib/test_httplib.py b/tests/external_httplib/test_httplib.py index 7de8308724..e82ce9e58e 100644 --- a/tests/external_httplib/test_httplib.py +++ b/tests/external_httplib/test_httplib.py @@ -13,6 +13,8 @@ # limitations under the License. import http.client as httplib +import json +import base64 import pytest from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers @@ -239,7 +241,7 @@ def test_transaction(): def test_httplib_nr_headers_added(server): connection = httplib.HTTPConnection("localhost", server.port) - key = "newrelic" + key = "header_key" value = "testval" headers = [] @@ -256,7 +258,6 @@ def test_transaction(): )(test_transaction) test_transaction() connection.close() - # verify newrelic headers already added do not get overrode assert headers[0][key] == value From ea18200b6488049ee9d5c64a911da80c95a28d3e Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Fri, 12 Sep 2025 16:13:15 -0700 Subject: [PATCH 30/95] Fix Megalinter errors --- newrelic/api/message_transaction.py | 1 - newrelic/api/transaction.py | 8 +------- newrelic/api/web_transaction.py | 2 +- newrelic/common/encoding_utils.py | 3 +-- newrelic/hooks/framework_aiohttp.py | 5 ++--- tests/agent_features/test_serverless_mode.py | 1 + tests/external_http/test_http.py | 3 ++- tests/external_httplib/test_httplib.py | 5 +++-- tests/external_httplib/test_urllib.py | 4 +++- tests/external_httplib/test_urllib2.py | 4 +++- tests/external_httplib2/test_httplib2.py | 3 ++- tests/external_httpx/test_client.py | 7 ++++--- tests/external_requests/test_requests.py | 3 ++- tests/external_urllib3/test_urllib3.py | 3 ++- tests/framework_aiohttp/conftest.py | 2 +- tests/framework_aiohttp/test_client_async_await.py | 1 + tests/framework_sanic/test_distributed_trace.py | 1 + tests/framework_tornado/test_externals.py | 4 +++- tests/messagebroker_pika/test_pika_produce.py | 2 +- tests/testing_support/external_fixtures.py | 2 +- .../validators/validate_cross_process_headers.py | 1 + .../validators/validate_messagebroker_headers.py | 1 + 22 files changed, 37 insertions(+), 29 deletions(-) diff --git a/newrelic/api/message_transaction.py b/newrelic/api/message_transaction.py index f37bdf8070..a62a545482 100644 --- a/newrelic/api/message_transaction.py +++ b/newrelic/api/message_transaction.py @@ -16,7 +16,6 @@ from newrelic.api.application import Application, application_instance from newrelic.api.background_task import BackgroundTask -from newrelic.api.message_trace import MessageTrace from newrelic.api.transaction import current_transaction from newrelic.common.async_proxy import TransactionContext, async_proxy from newrelic.common.object_wrapper import FunctionWrapper, wrap_object diff --git a/newrelic/api/transaction.py b/newrelic/api/transaction.py index 4d09a60664..f6a148f27d 100644 --- a/newrelic/api/transaction.py +++ b/newrelic/api/transaction.py @@ -33,14 +33,8 @@ NrTraceState, W3CTraceParent, W3CTraceState, - base64_decode, - # convert_to_cat_metadata_value, - deobfuscate, ensure_str, # generate_path_hash, - json_decode, - json_encode, - obfuscate, snake_case, ) from newrelic.core.attribute import ( @@ -1351,7 +1345,7 @@ def accept_distributed_trace_headers(self, headers, transport_type="HTTP"): # if not self.enabled: # return - # If CAT is disabled, function will exit early. + # If CAT is disabled, function will exit early. # if not ( # settings.cross_application_tracer.enabled # and settings.cross_process_id diff --git a/newrelic/api/web_transaction.py b/newrelic/api/web_transaction.py index dc50ca4157..f6716c7ba6 100644 --- a/newrelic/api/web_transaction.py +++ b/newrelic/api/web_transaction.py @@ -322,7 +322,7 @@ def process_response(self, status_code, response_headers): pass return [] - + # if self.client_cross_process_id is None: # return [] diff --git a/newrelic/common/encoding_utils.py b/newrelic/common/encoding_utils.py index 3a5d34c3d5..8aa435af0b 100644 --- a/newrelic/common/encoding_utils.py +++ b/newrelic/common/encoding_utils.py @@ -19,7 +19,6 @@ import base64 import gzip -import hashlib import io import itertools import json @@ -245,7 +244,7 @@ def unpack_field(field): # if not isinstance(name, bytes): # name = name.encode("UTF-8") -# path_hash = rotated ^ int(hashlib.md5(name).hexdigest()[-8:], base=16) # noqa: S324 +# path_hash = rotated ^ int(hashlib.md5(name).hexdigest()[-8:], base=16) # return f"{path_hash:08x}" diff --git a/newrelic/hooks/framework_aiohttp.py b/newrelic/hooks/framework_aiohttp.py index 956f1bcc57..0636c39853 100644 --- a/newrelic/hooks/framework_aiohttp.py +++ b/newrelic/hooks/framework_aiohttp.py @@ -15,9 +15,9 @@ import inspect import itertools -from newrelic.api.time_trace import notice_error from newrelic.api.external_trace import ExternalTrace from newrelic.api.function_trace import function_trace +from newrelic.api.time_trace import notice_error from newrelic.api.transaction import current_transaction, ignore_transaction from newrelic.api.web_transaction import web_transaction from newrelic.common.async_wrapper import async_wrapper, is_coroutine_callable @@ -380,8 +380,7 @@ async def _coro(*_args, **_kwargs): def instrument_aiohttp_web(module): - global _nr_process_response - # TODO: Verify that this is correct/not always True + # global _nr_process_response # if not headers_preserve_casing(): # _nr_process_response = _nr_process_response_proxy diff --git a/tests/agent_features/test_serverless_mode.py b/tests/agent_features/test_serverless_mode.py index f77d739f75..6c4d5fa348 100644 --- a/tests/agent_features/test_serverless_mode.py +++ b/tests/agent_features/test_serverless_mode.py @@ -17,6 +17,7 @@ import pytest from testing_support.fixtures import override_generic_settings from testing_support.validators.validate_serverless_data import validate_serverless_data + # from testing_support.validators.validate_serverless_metadata import validate_serverless_metadata from testing_support.validators.validate_serverless_payload import validate_serverless_payload diff --git a/tests/external_http/test_http.py b/tests/external_http/test_http.py index 89fccac8f6..883c40dbd2 100644 --- a/tests/external_http/test_http.py +++ b/tests/external_http/test_http.py @@ -15,9 +15,10 @@ import http.client import pytest -from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers # , insert_incoming_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers + # from testing_support.validators.validate_external_node_params import validate_external_node_params from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics diff --git a/tests/external_httplib/test_httplib.py b/tests/external_httplib/test_httplib.py index e82ce9e58e..2db632a4ac 100644 --- a/tests/external_httplib/test_httplib.py +++ b/tests/external_httplib/test_httplib.py @@ -12,14 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. +import base64 import http.client as httplib import json -import base64 import pytest -from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers # , insert_incoming_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers + # from testing_support.validators.validate_external_node_params import validate_external_node_params from testing_support.validators.validate_span_events import validate_span_events from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics diff --git a/tests/external_httplib/test_urllib.py b/tests/external_httplib/test_urllib.py index 2f64201198..3c97b573a6 100644 --- a/tests/external_httplib/test_urllib.py +++ b/tests/external_httplib/test_urllib.py @@ -21,9 +21,11 @@ except: import urllib -from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers # , insert_incoming_headers + # from testing_support.fixtures import cat_enabled from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers + # from testing_support.validators.validate_external_node_params import validate_external_node_params from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics diff --git a/tests/external_httplib/test_urllib2.py b/tests/external_httplib/test_urllib2.py index 9c61abe3ca..7deb368359 100644 --- a/tests/external_httplib/test_urllib2.py +++ b/tests/external_httplib/test_urllib2.py @@ -16,9 +16,11 @@ import urllib.request as urllib2 import pytest -from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers # , insert_incoming_headers + # from testing_support.fixtures import cat_enabled from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers + # from testing_support.validators.validate_external_node_params import validate_external_node_params from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics diff --git a/tests/external_httplib2/test_httplib2.py b/tests/external_httplib2/test_httplib2.py index 3e4deaba76..55ca4c1c73 100644 --- a/tests/external_httplib2/test_httplib2.py +++ b/tests/external_httplib2/test_httplib2.py @@ -14,9 +14,10 @@ import httplib2 import pytest -from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers # , insert_incoming_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers + # from testing_support.validators.validate_external_node_params import validate_external_node_params from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics diff --git a/tests/external_httpx/test_client.py b/tests/external_httpx/test_client.py index 178edd3dd7..5b97105b79 100644 --- a/tests/external_httpx/test_client.py +++ b/tests/external_httpx/test_client.py @@ -55,11 +55,12 @@ # self.end_headers() # self.wfile.write(b"Example Data") + def dt_response_handler(self): if not DT_RESPONSE_CODE: raise ValueError("DT_RESPONSE_CODE must be a valid status_code.") - - response = str(self.headers).encode("utf-8") # Might need to put headers here + + response = str(self.headers).encode("utf-8") # Might need to put headers here self.send_response(DT_RESPONSE_CODE) self.end_headers() self.wfile.write(response) @@ -178,7 +179,7 @@ async def _test(): @override_application_settings( - {"distributed_tracing.enabled": True, "span_events.enabled": True} #, "cross_application_tracer.enabled": True} + {"distributed_tracing.enabled": True, "span_events.enabled": True} # , "cross_application_tracer.enabled": True} ) @validate_transaction_errors(errors=[]) @background_task(name="test_sync_cross_process_override_headers") diff --git a/tests/external_requests/test_requests.py b/tests/external_requests/test_requests.py index 28f18b07d8..f7f0c5220b 100644 --- a/tests/external_requests/test_requests.py +++ b/tests/external_requests/test_requests.py @@ -15,9 +15,10 @@ import pytest import requests import requests.exceptions -from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers # , insert_incoming_headers from testing_support.fixtures import override_application_settings, validate_tt_parenting from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers + # 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 diff --git a/tests/external_urllib3/test_urllib3.py b/tests/external_urllib3/test_urllib3.py index 1ac8fa7e95..f82c183225 100644 --- a/tests/external_urllib3/test_urllib3.py +++ b/tests/external_urllib3/test_urllib3.py @@ -21,9 +21,10 @@ except ImportError: pass -from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers # , insert_incoming_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers + # 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 diff --git a/tests/framework_aiohttp/conftest.py b/tests/framework_aiohttp/conftest.py index ea2688def3..0d295b3fff 100644 --- a/tests/framework_aiohttp/conftest.py +++ b/tests/framework_aiohttp/conftest.py @@ -125,7 +125,7 @@ def respond_with_dt_header(self): # with MockExternalHTTPServer(handler=respond_with_cat_header) as server: # with MockExternalHTTPServer() as server: - with MockExternalHTTPServer(handler=respond_with_dt_header) as server: + with MockExternalHTTPServer(handler=respond_with_dt_header) as server: yield (server, response_values) diff --git a/tests/framework_aiohttp/test_client_async_await.py b/tests/framework_aiohttp/test_client_async_await.py index 3b2856e969..a30cd830b6 100644 --- a/tests/framework_aiohttp/test_client_async_await.py +++ b/tests/framework_aiohttp/test_client_async_await.py @@ -16,6 +16,7 @@ import aiohttp import pytest + # from testing_support.fixtures import cat_enabled from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from yarl import URL diff --git a/tests/framework_sanic/test_distributed_trace.py b/tests/framework_sanic/test_distributed_trace.py index 3a92e84649..436bd0e68c 100644 --- a/tests/framework_sanic/test_distributed_trace.py +++ b/tests/framework_sanic/test_distributed_trace.py @@ -30,6 +30,7 @@ from newrelic.api.application import application_instance from newrelic.api.external_trace import ExternalTrace from newrelic.api.transaction import Transaction + # from newrelic.common.encoding_utils import deobfuscate BASE_METRICS = [("Function/_target_application:index", 1)] diff --git a/tests/framework_tornado/test_externals.py b/tests/framework_tornado/test_externals.py index 42ae7e3321..8d7ef80ab2 100644 --- a/tests/framework_tornado/test_externals.py +++ b/tests/framework_tornado/test_externals.py @@ -19,12 +19,14 @@ import pytest from testing_support.fixtures import override_application_settings from testing_support.mock_external_http_server import MockExternalHTTPHResponseHeadersServer, MockExternalHTTPServer + # from testing_support.validators.validate_distributed_tracing_header import validate_distributed_tracing_header # from testing_support.validators.validate_outbound_headers import validate_outbound_headers 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 + # from newrelic.api.transaction import current_transaction ENCODING_KEY = "1234567890123456789012345678901234567890" @@ -187,7 +189,7 @@ def _test(): # if distributed_tracing: # validate_distributed_tracing_header(header="Newrelic") # else: - # validate_outbound_headers() + # validate_outbound_headers() # else: # # new relic shouldn't add anything to the outgoing # assert "x-newrelic" not in body, body diff --git a/tests/messagebroker_pika/test_pika_produce.py b/tests/messagebroker_pika/test_pika_produce.py index 1d8a01c6ec..bda5635e89 100644 --- a/tests/messagebroker_pika/test_pika_produce.py +++ b/tests/messagebroker_pika/test_pika_produce.py @@ -172,7 +172,7 @@ def test_blocking_connection_reply_to(producer): @pytest.mark.parametrize("enable_distributed_tracing", [True, False]) def test_blocking_connection_headers(enable_distributed_tracing): override_settings = { - "distributed_tracing.enabled": enable_distributed_tracing, + "distributed_tracing.enabled": enable_distributed_tracing # "cross_application_tracer.enabled": not enable_distributed_tracing, } rollup_metrics = list(_test_blocking_connection_metrics) diff --git a/tests/testing_support/external_fixtures.py b/tests/testing_support/external_fixtures.py index 5bf7928dc5..5746cdbcad 100644 --- a/tests/testing_support/external_fixtures.py +++ b/tests/testing_support/external_fixtures.py @@ -16,10 +16,10 @@ from newrelic.api.external_trace import ExternalTrace from newrelic.api.transaction import current_transaction + # from newrelic.common.encoding_utils import json_encode, obfuscate from newrelic.common.object_wrapper import transient_function_wrapper - # def create_incoming_headers(transaction): # settings = transaction.settings # encoding_key = settings.encoding_key diff --git a/tests/testing_support/validators/validate_cross_process_headers.py b/tests/testing_support/validators/validate_cross_process_headers.py index 214d3c8db1..5f9f82f882 100644 --- a/tests/testing_support/validators/validate_cross_process_headers.py +++ b/tests/testing_support/validators/validate_cross_process_headers.py @@ -15,6 +15,7 @@ from newrelic.api.transaction import current_transaction from newrelic.common.object_wrapper import function_wrapper from testing_support.validators.validate_distributed_tracing_header import validate_distributed_tracing_header + # from testing_support.validators.validate_outbound_headers import validate_outbound_headers diff --git a/tests/testing_support/validators/validate_messagebroker_headers.py b/tests/testing_support/validators/validate_messagebroker_headers.py index e86e7188d0..f45a47adb4 100644 --- a/tests/testing_support/validators/validate_messagebroker_headers.py +++ b/tests/testing_support/validators/validate_messagebroker_headers.py @@ -15,6 +15,7 @@ from newrelic.api.transaction import current_transaction from newrelic.common.object_wrapper import function_wrapper from testing_support.validators.validate_distributed_tracing_header import validate_distributed_tracing_header + # from testing_support.validators.validate_outbound_headers import validate_outbound_headers From bcb5dbadcc04883f1320b883e19a5de5e7bb8e8d Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Fri, 12 Sep 2025 18:01:47 -0700 Subject: [PATCH 31/95] Remove commented out code --- newrelic/api/external_trace.py | 1 - newrelic/api/header_mixin.py | 77 ------ newrelic/api/message_trace.py | 3 - newrelic/api/message_transaction.py | 4 - newrelic/api/transaction.py | 225 ------------------ newrelic/api/web_transaction.py | 15 -- newrelic/common/agent_http.py | 1 - newrelic/common/encoding_utils.py | 26 -- newrelic/config.py | 9 - newrelic/core/agent_protocol.py | 1 - newrelic/core/config.py | 25 -- newrelic/core/external_node.py | 28 --- newrelic/core/transaction_node.py | 25 -- newrelic/hooks/application_celery.py | 10 - newrelic/hooks/external_httplib.py | 26 +- newrelic/hooks/framework_aiohttp.py | 20 -- newrelic/hooks/framework_tornado.py | 1 - newrelic/hooks/messagebroker_pika.py | 4 - .../test_asgi_distributed_tracing.py | 1 - tests/agent_features/test_attribute.py | 1 - .../test_attributes_in_action.py | 24 +- .../test_distributed_tracing.py | 1 - tests/agent_features/test_error_events.py | 4 - tests/agent_features/test_serverless_mode.py | 20 -- tests/agent_features/test_synthetics.py | 4 - tests/agent_unittests/test_agent_protocol.py | 3 - tests/agent_unittests/test_harvest_loop.py | 7 - tests/cross_agent/test_distributed_tracing.py | 1 - tests/external_http/test_http.py | 47 +--- tests/external_httplib/test_httplib.py | 83 +------ tests/external_httplib/test_urllib.py | 79 +----- tests/external_httplib/test_urllib2.py | 40 +--- tests/external_httplib2/test_httplib2.py | 49 +--- tests/external_httpx/test_client.py | 111 +-------- tests/external_requests/test_requests.py | 50 +--- tests/external_urllib3/test_urllib3.py | 46 +--- tests/framework_aiohttp/conftest.py | 2 - .../test_client_async_await.py | 8 - tests/framework_aiohttp/test_server_dt.py | 136 +---------- tests/framework_sanic/conftest.py | 2 - .../framework_sanic/test_distributed_trace.py | 92 +------ .../framework_tornado/_target_application.py | 32 --- tests/framework_tornado/test_externals.py | 119 +-------- tests/framework_tornado/test_inbound_dt.py | 70 ------ .../test_distributed_tracing.py | 6 - tests/messagebroker_pika/test_pika_produce.py | 5 +- tests/testing_support/external_fixtures.py | 41 ---- tests/testing_support/fixtures.py | 21 -- .../validate_cross_process_headers.py | 4 - .../validate_distributed_tracing_header.py | 3 - .../validate_messagebroker_headers.py | 4 - .../validators/validate_synthetics_event.py | 2 - 52 files changed, 37 insertions(+), 1582 deletions(-) diff --git a/newrelic/api/external_trace.py b/newrelic/api/external_trace.py index c73bba9383..f2fa11ccba 100644 --- a/newrelic/api/external_trace.py +++ b/newrelic/api/external_trace.py @@ -40,7 +40,6 @@ def __repr__(self): def process_response(self, status_code, headers=None): self._add_agent_attribute("http.statusCode", status_code) - # self.process_response_headers(headers) def terminal_node(self): return True diff --git a/newrelic/api/header_mixin.py b/newrelic/api/header_mixin.py index ca4114bf7f..22d7299be9 100644 --- a/newrelic/api/header_mixin.py +++ b/newrelic/api/header_mixin.py @@ -12,24 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -# from newrelic.common.encoding_utils import ( -# base64_decode, -# base64_encode, -# deobfuscate, -# json_decode, -# json_encode, -# obfuscate, -# ) - # HeaderMixin assumes the mixin class also inherits from TimeTrace class HeaderMixin: - # cat_id_key = "X-NewRelic-ID" - # cat_transaction_key = "X-NewRelic-Transaction" - # cat_appdata_key = "X-NewRelic-App-Data" synthetics_key = "X-NewRelic-Synthetics" synthetics_info_key = "X-NewRelic-Synthetics-Info" - # cat_metadata_key = "x-newrelic-trace" distributed_trace_key = "newrelic" settings = None @@ -39,41 +26,6 @@ def __enter__(self): self.settings = self.transaction.settings or None return result - # def process_response_headers(self, response_headers): - # """ - # Decode the response headers and create appropriate metrics based on the - # header values. The response_headers are passed in as a list of tuples. - # [(HEADER_NAME0, HEADER_VALUE0), (HEADER_NAME1, HEADER_VALUE1)] - - # """ - - # settings = self.settings - # if not settings: - # return - - # if not settings.cross_application_tracer.enabled: - # return - - # appdata = None - # try: - # for k, v in response_headers: - # if k.upper() == self.cat_appdata_key.upper(): - # appdata = json_decode(deobfuscate(v, settings.encoding_key)) - # break - - # if appdata: - # self.params["cross_process_id"] = appdata[0] - # self.params["external_txn_name"] = appdata[1] - # self.params["transaction_guid"] = appdata[5] - - # except Exception: - # pass - - # def process_response_metadata(self, cat_linking_value): - # payload = base64_decode(cat_linking_value) - # nr_headers = json_decode(payload) - # self.process_response_headers(nr_headers.items()) - @classmethod def generate_request_headers(cls, transaction): """ @@ -92,38 +44,9 @@ def generate_request_headers(cls, transaction): if settings.distributed_tracing.enabled: transaction.insert_distributed_trace_headers(nr_headers) - # elif settings.cross_application_tracer.enabled: - # transaction.is_part_of_cat = True - # path_hash = transaction.path_hash - # if path_hash is None: - # # Disable cat if path_hash fails to generate. - # transaction.is_part_of_cat = False - # else: - # encoded_cross_process_id = obfuscate(settings.cross_process_id, settings.encoding_key) - # nr_headers.append((cls.cat_id_key, encoded_cross_process_id)) - - # transaction_data = [transaction.guid, transaction.record_tt, transaction.trip_id, path_hash] - # encoded_transaction = obfuscate(json_encode(transaction_data), settings.encoding_key) - # nr_headers.append((cls.cat_transaction_key, encoded_transaction)) - if transaction.synthetics_header: nr_headers.append((cls.synthetics_key, transaction.synthetics_header)) if transaction.synthetics_info_header: nr_headers.append((cls.synthetics_info_key, transaction.synthetics_info_header)) return nr_headers - - # @staticmethod - # def _convert_to_cat_metadata_value(nr_headers): - # payload = json_encode(nr_headers) - # cat_linking_value = base64_encode(payload) - # return cat_linking_value - - # @classmethod - # def get_request_metadata(cls, transaction): - # nr_headers = dict(cls.generate_request_headers(transaction)) - - # if not nr_headers: - # return None - - # return cls._convert_to_cat_metadata_value(nr_headers) diff --git a/newrelic/api/message_trace.py b/newrelic/api/message_trace.py index 999434d786..560bdfa3b0 100644 --- a/newrelic/api/message_trace.py +++ b/newrelic/api/message_trace.py @@ -22,9 +22,6 @@ class MessageTrace(HeaderMixin, TimeTrace): - # cat_id_key = "NewRelicID" - # cat_transaction_key = "NewRelicTransaction" - # cat_appdata_key = "NewRelicAppData" synthetics_key = "NewRelicSynthetics" synthetics_info_key = "NewRelicSyntheticsInfo" diff --git a/newrelic/api/message_transaction.py b/newrelic/api/message_transaction.py index a62a545482..5383c72dca 100644 --- a/newrelic/api/message_transaction.py +++ b/newrelic/api/message_transaction.py @@ -46,10 +46,6 @@ def __init__( if headers is not None and self.settings is not None: if self.settings.distributed_tracing.enabled: self.accept_distributed_trace_headers(headers, transport_type=transport_type) - # elif self.settings.cross_application_tracer.enabled: - # self._process_incoming_cat_headers( - # headers.pop(MessageTrace.cat_id_key, None), headers.pop(MessageTrace.cat_transaction_key, None) - # ) self.routing_key = routing_key self.exchange_type = exchange_type diff --git a/newrelic/api/transaction.py b/newrelic/api/transaction.py index f6a148f27d..90eee5cd5d 100644 --- a/newrelic/api/transaction.py +++ b/newrelic/api/transaction.py @@ -34,7 +34,6 @@ W3CTraceParent, W3CTraceState, ensure_str, - # generate_path_hash, snake_case, ) from newrelic.core.attribute import ( @@ -283,15 +282,9 @@ def __init__(self, application, enabled=None, source=None): self._distributed_trace_state = 0 - # self.client_cross_process_id = None self.client_account_id = None self.client_application_id = None - # self.referring_transaction_guid = None self.record_tt = False - # self._trip_id = None - # self._referring_path_hash = None - # self._alternate_path_hashes = {} - # self.is_part_of_cat = False # Synthetics Header self.synthetics_resource_id = None @@ -532,13 +525,8 @@ def __exit__(self, exc, value, tb): ) # Add transaction exclusive time to total exclusive time - # self.total_time += exclusive - # if self.client_cross_process_id is not None: - # metric_name = f"ClientApplication/{self.client_cross_process_id}/all" - # self.record_custom_metric(metric_name, duration) - # Record supportability metrics for api calls for key, value in self._transaction_metrics.items(): @@ -597,8 +585,6 @@ def __exit__(self, exc, value, tb): guid=self.guid, cpu_time=self._cpu_user_time_value, suppress_transaction_trace=self.suppress_transaction_trace, - # client_cross_process_id=self.client_cross_process_id, - # referring_transaction_guid=self.referring_transaction_guid, record_tt=self.record_tt, synthetics_resource_id=self.synthetics_resource_id, synthetics_job_id=self.synthetics_job_id, @@ -608,11 +594,6 @@ def __exit__(self, exc, value, tb): synthetics_initiator=self.synthetics_initiator, synthetics_attributes=self.synthetics_attributes, synthetics_info_header=self.synthetics_info_header, - # is_part_of_cat=self.is_part_of_cat, - # trip_id=self.trip_id, - # path_hash=self.path_hash, - # referring_path_hash=self._referring_path_hash, - # alternate_path_hashes=self.alternate_path_hashes, trace_intrinsics=self.trace_intrinsics, distributed_trace_intrinsics=self.distributed_trace_intrinsics, agent_attributes=agent_attributes, @@ -730,72 +711,10 @@ def path(self): return f"{self.type}/{self.name_for_metric}" - # @property - # def trip_id(self): - # return self._trip_id or self.guid - @property def trace_id(self): return self._trace_id - # @property - # def alternate_path_hashes(self): - # """Return the alternate path hashes but not including the current path - # hash. - - # """ - # # return sorted(set(self._alternate_path_hashes.values()) - {self.path_hash}) - # return sorted(set(self._alternate_path_hashes.values()) - {None}) - - # @property - # def path_hash(self): - # """Path hash is a 32-bit digest of the string "appname;txn_name" - # XORed with the referring_path_hash. Since the txn_name can change - # during the course of a transaction, up to 10 path_hashes are stored - # in _alternate_path_hashes. Before generating the path hash, check the - # _alternate_path_hashes to determine if we've seen this identifier and - # return the value. - - # """ - - # # if not self.is_part_of_cat: - # # return None - # return None - - # identifier = f"{self.application.name};{self.path}" - - # # Check if identifier is already part of the _alternate_path_hashes and - # # return the value if available. - - # if self._alternate_path_hashes.get(identifier): - # return self._alternate_path_hashes[identifier] - - # # If the referring_path_hash is unavailable then we use '0' as the - # # seed. - - # try: - # seed = int((self._referring_path_hash or "0"), base=16) - # except Exception: - # seed = 0 - - # try: - # path_hash = generate_path_hash(identifier, seed) - # except ValueError: - # _logger.warning( - # "Unable to generate cross application tracer headers. " - # "MD5 hashing may not be available. (Is this system FIPS compliant?) " - # "We recommend enabling distributed tracing instead. For details and a transition guide see " - # "https://docs.newrelic.com/docs/agents/python-agent/configuration/python-agent-configuration#distributed-tracing-settings" - # ) - # return None - - # # Only store up to 10 alternate path hashes. - - # if len(self._alternate_path_hashes) < 10: - # self._alternate_path_hashes[identifier] = path_hash - - # return path_hash - @property def attribute_filter(self): return self._settings.attribute_filter @@ -833,14 +752,6 @@ def trace_intrinsics(self): """Intrinsic attributes for transaction traces and error traces""" i_attrs = {} - # if self.referring_transaction_guid: - # i_attrs["referring_transaction_guid"] = self.referring_transaction_guid - # if self.client_cross_process_id: - # i_attrs["client_cross_process_id"] = self.client_cross_process_id - # if self.trip_id: - # i_attrs["trip_id"] = self.trip_id - # if self.path_hash: - # i_attrs["path_hash"] = self.path_hash if self.synthetics_resource_id: i_attrs["synthetics_resource_id"] = self.synthetics_resource_id if self.synthetics_job_id: @@ -1339,142 +1250,6 @@ def accept_distributed_trace_headers(self, headers, transport_type="HTTP"): # metric for the lack of payload/distributed_header self._accept_distributed_trace_payload(distributed_header, transport_type) - # def _process_incoming_cat_headers(self, encoded_cross_process_id, encoded_txn_header): - # settings = self._settings - - # if not self.enabled: - # return - - # If CAT is disabled, function will exit early. - # if not ( - # settings.cross_application_tracer.enabled - # and settings.cross_process_id - # and settings.trusted_account_ids - # and settings.encoding_key - # ): - # return - - # if encoded_cross_process_id is None: - # return - - # try: - # client_cross_process_id = deobfuscate(encoded_cross_process_id, settings.encoding_key) - - # # The cross process ID consists of the client - # # account ID and the ID of the specific application - # # the client is recording requests against. We need - # # to validate that the client account ID is in the - # # list of trusted account IDs and ignore it if it - # # isn't. The trusted account IDs list has the - # # account IDs as integers, so save the client ones - # # away as integers here so easier to compare later. - - # client_account_id, client_application_id = map(int, client_cross_process_id.split("#")) - - # if client_account_id not in settings.trusted_account_ids: - # return - - # self.client_cross_process_id = client_cross_process_id - # self.client_account_id = client_account_id - # self.client_application_id = client_application_id - - # txn_header = json_decode(deobfuscate(encoded_txn_header, settings.encoding_key)) - - # if txn_header: - # self.is_part_of_cat = True - # self.referring_transaction_guid = txn_header[0] - - # # Incoming record_tt is OR'd with existing - # # record_tt. In the scenario where we make multiple - # # ext request, this will ensure we don't set the - # # record_tt to False by a later request if it was - # # set to True by an earlier request. - - # self.record_tt = self.record_tt or txn_header[1] - - # if isinstance(txn_header[2], str): - # self._trip_id = txn_header[2] - # if isinstance(txn_header[3], str): - # self._referring_path_hash = txn_header[3] - # except Exception: - # pass - - # def _generate_response_headers(self, read_length=None): - # nr_headers = [] - - # # Generate metrics and response headers for inbound cross - # # process web external calls. - - # if self.client_cross_process_id is not None: - # # Need to work out queueing time and duration up to this - # # point for inclusion in metrics and response header. If the - # # recording of the transaction had been prematurely stopped - # # via an API call, only return time up until that call was - # # made so it will match what is reported as duration for the - # # transaction. - - # if self.queue_start: - # queue_time = self.start_time - self.queue_start - # else: - # queue_time = 0 - - # if self.end_time: - # duration = self.end_time - self.start_time - # else: - # duration = time.time() - self.start_time - - # # Generate the additional response headers which provide - # # information back to the caller. We need to freeze the - # # transaction name before adding to the header. - - # self._freeze_path() - - # if read_length is None: - # read_length = self._read_length - - # read_length = read_length if read_length is not None else -1 - - # payload = ( - # self._settings.cross_process_id, - # self.path, - # queue_time, - # duration, - # read_length, - # self.guid, - # self.record_tt, - # ) - # app_data = json_encode(payload) - - # nr_headers.append(("X-NewRelic-App-Data", obfuscate(app_data, self._settings.encoding_key))) - - # return nr_headers - - # # This function is CAT related and has been deprecated. - # # Eventually, this will be removed. Until then, coverage - # # does not need to factor this function into its analysis. - # def get_response_metadata(self): # pragma: no cover - # nr_headers = dict(self._generate_response_headers()) - # return convert_to_cat_metadata_value(nr_headers) - - # # This function is CAT related and has been deprecated. - # # Eventually, this will be removed. Until then, coverage - # # does not need to factor this function into its analysis. - # def process_request_metadata(self, cat_linking_value): # pragma: no cover - # try: - # payload = base64_decode(cat_linking_value) - # except: - # # `cat_linking_value` should always be able to be base64_decoded. - # # If this is encountered, the data being sent is corrupt. No - # # exception should be raised. - # return - - # nr_headers = json_decode(payload) - # # TODO: All the external CAT APIs really need to - # # be refactored into the transaction class. - # encoded_cross_process_id = nr_headers.get("X-NewRelic-ID") - # encoded_txn_header = nr_headers.get("X-NewRelic-Transaction") - # return self._process_incoming_cat_headers(encoded_cross_process_id, encoded_txn_header) - def set_transaction_name(self, name, group=None, priority=None): # Always perform this operation even if the transaction # is not active at the time as will be called from diff --git a/newrelic/api/web_transaction.py b/newrelic/api/web_transaction.py index f6716c7ba6..d12acf8164 100644 --- a/newrelic/api/web_transaction.py +++ b/newrelic/api/web_transaction.py @@ -284,10 +284,6 @@ def _process_context_headers(self): # the relevant details. if self._settings.distributed_tracing.enabled: self.accept_distributed_trace_headers(self._request_headers) - # else: - # client_cross_process_id = self._request_headers.get("x-newrelic-id") - # txn_header = self._request_headers.get("x-newrelic-transaction") - # self._process_incoming_cat_headers(client_cross_process_id, txn_header) def process_response(self, status_code, response_headers): """Processes response status and headers, extracting any @@ -323,17 +319,6 @@ def process_response(self, status_code, response_headers): return [] - # if self.client_cross_process_id is None: - # return [] - - # # Generate CAT response headers - # try: - # read_length = int(self._request_headers.get("content-length")) - # except Exception: - # read_length = -1 - - # return self._generate_response_headers(read_length) - def _update_agent_attributes(self): if "accept" in self._request_headers: self._add_agent_attribute("request.headers.accept", self._request_headers["accept"]) diff --git a/newrelic/common/agent_http.py b/newrelic/common/agent_http.py index c5e54d4962..c85f7d060a 100644 --- a/newrelic/common/agent_http.py +++ b/newrelic/common/agent_http.py @@ -521,7 +521,6 @@ class DeveloperModeClient(SupportabilityMixin, BaseClient): "url_rules": [], "collect_errors": True, "account_id": "12345", - # "cross_process_id": "12345#67890", "messages": [{"message": "Reporting to fake collector", "level": "INFO"}], "sampling_rate": 0, "collect_traces": True, diff --git a/newrelic/common/encoding_utils.py b/newrelic/common/encoding_utils.py index 8aa435af0b..ddd6a5ddad 100644 --- a/newrelic/common/encoding_utils.py +++ b/newrelic/common/encoding_utils.py @@ -231,23 +231,6 @@ def unpack_field(field): return data -# def generate_path_hash(name, seed): -# """Algorithm for generating the path hash: -# * Rotate Left the seed value and truncate to 32-bits. -# * Compute the md5 digest of the name, take the last 4 bytes (32-bits). -# * XOR the 4 bytes of digest with the seed and return the result. - -# """ - -# rotated = ((seed << 1) | (seed >> 31)) & 0xFFFFFFFF - -# if not isinstance(name, bytes): -# name = name.encode("UTF-8") - -# path_hash = rotated ^ int(hashlib.md5(name).hexdigest()[-8:], base=16) -# return f"{path_hash:08x}" - - def base64_encode(text): """Base 64 encodes the UTF-8 encoded representation of the text. In Python 2 either a byte string or Unicode string can be provided for the text @@ -367,15 +350,6 @@ def decode_newrelic_header(encoded_header, encoding_key): return decoded_header -# def convert_to_cat_metadata_value(nr_headers): -# if not nr_headers: -# return None - -# payload = json_encode(nr_headers) -# cat_linking_value = base64_encode(payload) -# return cat_linking_value - - class DistributedTracePayload(dict): version = (0, 1) diff --git a/newrelic/config.py b/newrelic/config.py index 2d60f8df14..18bd54fc1f 100644 --- a/newrelic/config.py +++ b/newrelic/config.py @@ -701,15 +701,6 @@ def translate_deprecated_settings(settings, cached_settings): "attributes.exclude." ) - # if "cross_application_tracer.enabled" in cached: - # # CAT Deprecation Warning - # _logger.info( - # "Deprecated setting found: cross_application_tracer.enabled. Please replace Cross Application Tracing " - # "(CAT) with the newer Distributed Tracing by setting 'distributed_tracing.enabled' to True in your agent " - # "configuration. For further details on distributed tracing, please refer to our documentation: " - # "https://docs.newrelic.com/docs/distributed-tracing/concepts/distributed-tracing-planning-guide/#changes." - # ) - return settings diff --git a/newrelic/core/agent_protocol.py b/newrelic/core/agent_protocol.py index bc7727c6e1..347bdf5e2a 100644 --- a/newrelic/core/agent_protocol.py +++ b/newrelic/core/agent_protocol.py @@ -523,7 +523,6 @@ def finalize(self): def connect(cls, app_name, linked_applications, environment, settings, client_cls=ServerlessModeClient): aws_lambda_metadata = settings.aws_lambda_metadata settings = finalize_application_settings() - # settings = finalize_application_settings({"cross_application_tracer.enabled": False}, settings) # Metadata must come from the original settings object since it # can be modified later settings.aws_lambda_metadata = aws_lambda_metadata diff --git a/newrelic/core/config.py b/newrelic/core/config.py index dea073a1d1..7236eef335 100644 --- a/newrelic/core/config.py +++ b/newrelic/core/config.py @@ -256,10 +256,6 @@ class DebugSettings(Settings): pass -# class CrossApplicationTracerSettings(Settings): -# pass - - class TransactionEventsSettings(Settings): pass @@ -497,7 +493,6 @@ class EventHarvestConfigHarvestLimitSettings(Settings): _settings.browser_monitoring.attributes = BrowserMonitorAttributesSettings() _settings.code_level_metrics = CodeLevelMetricsSettings() _settings.console = ConsoleSettings() -# _settings.cross_application_tracer = CrossApplicationTracerSettings() _settings.custom_insights_events = CustomInsightsEventsSettings() _settings.ml_insights_events = MlInsightsEventsSettings() _settings.datastore_tracer = DatastoreTracerSettings() @@ -792,7 +787,6 @@ def default_otlp_host(host): _settings.transaction_segment_terms = [] _settings.account_id = os.environ.get("NEW_RELIC_ACCOUNT_ID") -# _settings.cross_process_id = None _settings.primary_application_id = os.environ.get("NEW_RELIC_PRIMARY_APPLICATION_ID", "Unknown") _settings.trusted_account_ids = [] _settings.trusted_account_key = os.environ.get("NEW_RELIC_TRUSTED_ACCOUNT_KEY") @@ -808,7 +802,6 @@ def default_otlp_host(host): _settings.attributes.include = [] _settings.thread_profiler.enabled = True -# _settings.cross_application_tracer.enabled = False _settings.gc_runtime_metrics.enabled = _environ_as_bool("NEW_RELIC_GC_RUNTIME_METRICS_ENABLED", default=False) _settings.gc_runtime_metrics.top_object_count_limit = 5 @@ -1334,24 +1327,6 @@ def apply_server_side_settings(server_side_config=None, settings=_settings): min(settings_snapshot.custom_insights_events.max_attribute_value, 4095), ) - # This will be removed at some future point - # Special case for account_id which will be sent instead of - # cross_process_id in the future - - # if settings_snapshot.cross_process_id is not None: - # vals = [settings_snapshot.account_id, settings_snapshot.application_id] - # derived_vals = settings_snapshot.cross_process_id.split("#") - - # if len(derived_vals) == 2: - # for idx, _val in enumerate(derived_vals): - # # only override the value if the server side does not provide - # # the value specifically - # if vals[idx] is None: - # vals[idx] = derived_vals[idx] - - # settings_snapshot.account_id = vals[0] - # settings_snapshot.application_id = vals[1] - # Reapply on top any local setting overrides. for name in _settings.debug.local_settings_overrides: diff --git a/newrelic/core/external_node.py b/newrelic/core/external_node.py index ceea3f0cac..5b80a2e7d7 100644 --- a/newrelic/core/external_node.py +++ b/newrelic/core/external_node.py @@ -40,9 +40,6 @@ class ExternalNode(_ExternalNode, GenericNodeMixin): - # cross_process_id = None - # external_txn_name = None - @property def details(self): if hasattr(self, "_details"): @@ -107,21 +104,10 @@ def time_metrics(self, stats, root, parent): netloc = self.netloc - # try: - # # Remove cross_process_id from the params dict otherwise it shows - # # up in the UI. - - # self.cross_process_id = self.params.pop("cross_process_id") - # self.external_txn_name = self.params.pop("external_txn_name") - # except KeyError: - # self.cross_process_id = None - # self.external_txn_name = None - name = f"External/{netloc}/all" yield TimeMetric(name=name, scope="", duration=self.duration, exclusive=self.exclusive) - # if self.cross_process_id is None: method = self.method or "" name = f"External/{netloc}/{self.library}/{method}" @@ -130,26 +116,12 @@ def time_metrics(self, stats, root, parent): yield TimeMetric(name=name, scope=root.path, duration=self.duration, exclusive=self.exclusive) - # else: - # name = f"ExternalTransaction/{netloc}/{self.cross_process_id}/{self.external_txn_name}" - - # yield TimeMetric(name=name, scope="", duration=self.duration, exclusive=self.exclusive) - - # yield TimeMetric(name=name, scope=root.path, duration=self.duration, exclusive=self.exclusive) - - # name = f"ExternalApp/{netloc}/{self.cross_process_id}/all" - - # yield TimeMetric(name=name, scope="", duration=self.duration, exclusive=self.exclusive) - def trace_node(self, stats, root, connections): netloc = self.netloc method = self.method or "" - # if self.cross_process_id is None: name = f"External/{netloc}/{self.library}/{method}" - # else: - # name = f"ExternalTransaction/{netloc}/{self.cross_process_id}/{self.external_txn_name}" name = root.string_table.cache(name) diff --git a/newrelic/core/transaction_node.py b/newrelic/core/transaction_node.py index 1c5364dda2..d125c36369 100644 --- a/newrelic/core/transaction_node.py +++ b/newrelic/core/transaction_node.py @@ -66,8 +66,6 @@ "guid", "cpu_time", "suppress_transaction_trace", - # "client_cross_process_id", - # "referring_transaction_guid", "record_tt", "synthetics_resource_id", "synthetics_job_id", @@ -77,11 +75,6 @@ "synthetics_initiator", "synthetics_attributes", "synthetics_info_header", - # "is_part_of_cat", - # "trip_id", - # "path_hash", - # "referring_path_hash", - # "alternate_path_hashes", "trace_intrinsics", "agent_attributes", "distributed_trace_intrinsics", @@ -465,23 +458,10 @@ def _add_if_not_empty(key, value): apdex_perf_zone = self.apdex_perf_zone() _add_if_not_empty("apdexPerfZone", apdex_perf_zone) - # _add_if_not_empty("nr.apdexPerfZone", apdex_perf_zone) if self.errors: intrinsics["error"] = True - # if self.path_hash: - # intrinsics["nr.guid"] = self.guid - # intrinsics["nr.tripId"] = self.trip_id - # intrinsics["nr.pathHash"] = self.path_hash - - # _add_if_not_empty("nr.referringPathHash", self.referring_path_hash) - # _add_if_not_empty("nr.alternatePathHashes", ",".join(self.alternate_path_hashes)) - # _add_if_not_empty("nr.referringTransactionGuid", self.referring_transaction_guid) - - # if self.synthetics_resource_id: - # intrinsics["nr.guid"] = self.guid - if self.parent_tx: intrinsics["parentId"] = self.parent_tx @@ -541,11 +521,6 @@ def error_event_intrinsics(self, error, stats_table): intrinsics["transactionName"] = self.path intrinsics["spanId"] = error.span_id - # intrinsics["nr.transactionGuid"] = self.guid - # if self.referring_transaction_guid: - # guid = self.referring_transaction_guid - # intrinsics["nr.referringTransactionGuid"] = guid - return intrinsics def _event_intrinsics(self, stats_table): diff --git a/newrelic/hooks/application_celery.py b/newrelic/hooks/application_celery.py index 6f25bbbf57..71e51a66e2 100644 --- a/newrelic/hooks/application_celery.py +++ b/newrelic/hooks/application_celery.py @@ -127,11 +127,6 @@ def wrapper(wrapped, instance, args, kwargs): headers.update(dict(dt_headers)) except Exception: pass - # elif transaction.settings.cross_application_tracer.enabled: - # transaction._process_incoming_cat_headers( - # headers.get(MessageTrace.cat_id_key, None), - # headers.get(MessageTrace.cat_transaction_key, None), - # ) except Exception: pass @@ -247,11 +242,6 @@ def wrap_task_call(wrapped, instance, args, kwargs): headers.update(dict(dt_headers)) except Exception: pass - # elif transaction.settings.cross_application_tracer.enabled: - # transaction._process_incoming_cat_headers( - # headers.get(MessageTrace.cat_id_key, None), - # headers.get(MessageTrace.cat_transaction_key, None), - # ) except Exception: pass diff --git a/newrelic/hooks/external_httplib.py b/newrelic/hooks/external_httplib.py index 94baa37790..48b1d080e4 100644 --- a/newrelic/hooks/external_httplib.py +++ b/newrelic/hooks/external_httplib.py @@ -93,24 +93,24 @@ def httplib_getresponse_wrapper(wrapped, instance, args, kwargs): return response -# def httplib_putheader_wrapper(wrapped, instance, args, kwargs): -# transaction = current_transaction() +def httplib_putheader_wrapper(wrapped, instance, args, kwargs): + transaction = current_transaction() -# if transaction is None: -# return wrapped(*args, **kwargs) + if transaction is None: + return wrapped(*args, **kwargs) -# # # Remember if we see any NR headers being set. This is only doing -# # # it if we see either, but they should always both be getting set. + # Remember if we see any NR headers being set. This is only doing + # it if we see either, but they should always both be getting set. -# # def nr_header(header, *args, **kwargs): -# # return header.upper() in ("NEWRELIC", "X-NEWRELIC-ID", "X-NEWRELIC-TRANSACTION") + def nr_header(header, *args, **kwargs): + return header.upper() == "NEWRELIC" -# # connection = instance + connection = instance -# # if nr_header(*args, **kwargs): -# # connection._nr_skip_headers = True + if nr_header(*args, **kwargs): + connection._nr_skip_headers = True -# return wrapped(*args, **kwargs) + return wrapped(*args, **kwargs) def instrument(module): @@ -125,4 +125,4 @@ def instrument(module): functools.partial(httplib_endheaders_wrapper, scheme="https", library="http"), ) wrap_function_wrapper(module, "HTTPConnection.getresponse", httplib_getresponse_wrapper) - # wrap_function_wrapper(module, "HTTPConnection.putheader", httplib_putheader_wrapper) + wrap_function_wrapper(module, "HTTPConnection.putheader", httplib_putheader_wrapper) diff --git a/newrelic/hooks/framework_aiohttp.py b/newrelic/hooks/framework_aiohttp.py index 0636c39853..da0b0029a5 100644 --- a/newrelic/hooks/framework_aiohttp.py +++ b/newrelic/hooks/framework_aiohttp.py @@ -34,17 +34,6 @@ def aiohttp_version_info(): return tuple(int(_) for _ in aiohttp.__version__.split(".")[:2]) -# def headers_preserve_casing(): -# try: -# from multidict import CIMultiDict -# except: -# return True - -# d = CIMultiDict() -# d.update({"X-NewRelic-ID": "value"}) -# return "X-NewRelic-ID" in dict(d.items()) - - def should_ignore(transaction): settings = transaction.settings @@ -280,7 +269,6 @@ async def _coro(): response = await wrapped(*args, **kwargs) try: - # trace.process_response_headers(response.headers.items()) trace.process_response(status_code=response.status) except: pass @@ -302,11 +290,7 @@ def instrument_aiohttp_client_reqrep(module): version_info = aiohttp_version_info() if version_info >= (2, 0): - # TODO: Verify that headers_preserve_casting is always True - # if headers_preserve_casing(): dt_wrapper = _nr_aiohttp_add_dt_headers_simple_ - # else: - # dt_wrapper = _nr_aiohttp_add_dt_headers_ wrap_function_wrapper(module, "ClientRequest.send", dt_wrapper) @@ -380,10 +364,6 @@ async def _coro(*_args, **_kwargs): def instrument_aiohttp_web(module): - # global _nr_process_response - # if not headers_preserve_casing(): - # _nr_process_response = _nr_process_response_proxy - wrap_function_wrapper(module, "Application._handle", _nr_request_wrapper) wrap_function_wrapper(module, "Application.__init__", _nr_aiohttp_wrap_application_init_) diff --git a/newrelic/hooks/framework_tornado.py b/newrelic/hooks/framework_tornado.py index 1c865d139c..7682bec75f 100644 --- a/newrelic/hooks/framework_tornado.py +++ b/newrelic/hooks/framework_tornado.py @@ -254,7 +254,6 @@ async def wrapper(req, raise_error): finally: if response: trace.process_response(response.code) - # trace.process_response_headers(response.headers.get_all()) return response return wrapper diff --git a/newrelic/hooks/messagebroker_pika.py b/newrelic/hooks/messagebroker_pika.py index 6a058d85ca..df7ae01f9e 100644 --- a/newrelic/hooks/messagebroker_pika.py +++ b/newrelic/hooks/messagebroker_pika.py @@ -62,8 +62,6 @@ def _add_consume_rabbitmq_trace(transaction, method, properties, nr_start_time, # Do not record dt headers in the segment parameters if headers: - # headers.pop(MessageTrace.cat_id_key, None) - # headers.pop(MessageTrace.cat_transaction_key, None) headers.pop(MessageTrace.distributed_trace_key, None) headers.pop("traceparent", None) headers.pop("tracestate", None) @@ -124,8 +122,6 @@ def _nr_wrapper_basic_publish(wrapped, instance, args, kwargs): user_headers = properties.headers.copy() # Do not record dt headers in the segment parameters - # user_headers.pop(MessageTrace.cat_id_key, None) - # user_headers.pop(MessageTrace.cat_transaction_key, None) user_headers.pop(MessageTrace.distributed_trace_key, None) user_headers.pop("traceparent", None) user_headers.pop("tracestate", None) diff --git a/tests/agent_features/test_asgi_distributed_tracing.py b/tests/agent_features/test_asgi_distributed_tracing.py index 993ba7865c..01140279f6 100644 --- a/tests/agent_features/test_asgi_distributed_tracing.py +++ b/tests/agent_features/test_asgi_distributed_tracing.py @@ -104,7 +104,6 @@ async def target_asgi_application(scope, receive, send): def test_distributed_tracing_web_transaction(): headers = {"newrelic": json.dumps(payload)} response = test_application.make_request("GET", "/", headers=headers) - # assert "X-NewRelic-App-Data" not in response.headers class TestAsgiRequest: diff --git a/tests/agent_features/test_attribute.py b/tests/agent_features/test_attribute.py index a22a42605d..4e6c0998be 100644 --- a/tests/agent_features/test_attribute.py +++ b/tests/agent_features/test_attribute.py @@ -57,7 +57,6 @@ def target_wsgi_application(environ, start_response): _required_intrinsics = ["totalTime"] -# _required_intrinsics = ["trip_id", "totalTime"] _forgone_intrinsics = [] diff --git a/tests/agent_features/test_attributes_in_action.py b/tests/agent_features/test_attributes_in_action.py index 8d60666b15..05d2c16ab2 100644 --- a/tests/agent_features/test_attributes_in_action.py +++ b/tests/agent_features/test_attributes_in_action.py @@ -15,7 +15,6 @@ import pytest import webtest from testing_support.fixtures import ( - # cat_enabled, dt_enabled, override_application_settings, reset_core_stats_engine, @@ -94,16 +93,7 @@ AGENT_KEYS_ALL = TRACE_ERROR_AGENT_KEYS + REQ_PARAMS -TRANS_EVENT_INTRINSICS = ( - "name", - "duration", - "type", - "timestamp", - "totalTime", - "error", - # "nr.apdexPerfZone", - "apdexPerfZone", -) +TRANS_EVENT_INTRINSICS = ("name", "duration", "type", "timestamp", "totalTime", "error", "apdexPerfZone") TRANS_EVENT_AGENT_KEYS = [ "response.status", "request.method", @@ -175,7 +165,6 @@ def normal_application(request): # Tests for checking the presence and format of agent attributes. # Test default settings. -# _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": ["trip_id"]} _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": []} _expected_attributes_event = { @@ -187,20 +176,16 @@ def normal_application(request): _expected_absent_attributes = {"agent": REQ_PARAMS, "user": [], "intrinsic": []} -# @cat_enabled @validate_error_event_attributes(_expected_attributes_event, _expected_absent_attributes) @validate_transaction_error_trace_attributes(_expected_attributes, _expected_absent_attributes) def test_error_in_transaction_default_settings(normal_application): normal_application.get(REQUEST_URL, headers=REQUEST_HEADERS) -# _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": []} -# @cat_enabled @validate_transaction_trace_attributes(_expected_attributes, _expected_absent_attributes) -# @override_application_settings({}) def test_transaction_trace_default_attribute_settings(normal_application): normal_application.get(REQUEST_URL, headers=REQUEST_HEADERS) @@ -243,7 +228,6 @@ def test_browser_default_attribute_settings(normal_application): _override_settings = {"error_collector.attributes.exclude": ["request.parameters.*"]} _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": []} -# _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": ["trip_id"]} _expected_attributes_event = { "agent": TRACE_ERROR_AGENT_KEYS, @@ -264,7 +248,6 @@ def test_error_in_transaction_exclude_request_params(normal_application): _override_settings = {"transaction_tracer.attributes.exclude": ["request.parameters.*"]} _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": []} -# _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} @validate_transaction_trace_attributes(_expected_attributes, _expected_absent_attributes) @@ -276,7 +259,6 @@ def test_transaction_trace_exclude_request_params(normal_application): _override_settings = {"capture_params": True, "error_collector.attributes.exclude": ["request.parameters.*"]} _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": []} -# _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} _expected_absent_attributes = {"agent": REQ_PARAMS, "user": [], "intrinsic": []} @@ -592,7 +574,6 @@ def test_span_event_exclude_agent_attribute(normal_application): _override_settings = {"capture_params": True} -# _expected_attributes = {"agent": AGENT_KEYS_ALL, "user": ERROR_USER_ATTRS, "intrinsic": ["trip_id"]} _expected_attributes = {"agent": AGENT_KEYS_ALL, "user": ERROR_USER_ATTRS, "intrinsic": []} _expected_attributes_event = {"agent": AGENT_KEYS_ALL, "user": ERROR_USER_ATTRS, "intrinsic": ERROR_EVENT_INTRINSICS} @@ -605,7 +586,6 @@ def test_error_in_transaction_deprecated_capture_params_true(normal_application) normal_application.get(REQUEST_URL, headers=REQUEST_HEADERS) -# _expected_attributes = {"agent": AGENT_KEYS_ALL, "user": USER_ATTRS, "intrinsic": ["trip_id"]} _expected_attributes = {"agent": AGENT_KEYS_ALL, "user": USER_ATTRS, "intrinsic": []} @@ -645,7 +625,6 @@ def test_browser_deprecated_capture_params_true(normal_application): _override_settings = {"capture_params": False} -# _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": ["trip_id"]} _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": []} _expected_attributes_event = { @@ -664,7 +643,6 @@ def test_error_in_transaction_deprecated_capture_params_false(normal_application normal_application.get(REQUEST_URL, headers=REQUEST_HEADERS) -# _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": []} diff --git a/tests/agent_features/test_distributed_tracing.py b/tests/agent_features/test_distributed_tracing.py index ed7183f40d..b6043c166a 100644 --- a/tests/agent_features/test_distributed_tracing.py +++ b/tests/agent_features/test_distributed_tracing.py @@ -111,7 +111,6 @@ def target_wsgi_application(environ, start_response): def test_distributed_tracing_web_transaction(): headers = {"newrelic": json.dumps(payload)} response = test_application.get("/", headers=headers) - # assert "X-NewRelic-App-Data" not in response.headers @pytest.mark.parametrize("span_events", (True, False)) diff --git a/tests/agent_features/test_error_events.py b/tests/agent_features/test_error_events.py index 5819b1656f..98219b8c4e 100644 --- a/tests/agent_features/test_error_events.py +++ b/tests/agent_features/test_error_events.py @@ -17,8 +17,6 @@ import webtest from testing_support.fixtures import ( - # cat_enabled, - # make_cross_agent_headers, make_synthetics_headers, override_application_settings, reset_core_stats_engine, @@ -108,11 +106,9 @@ def test_transaction_error_background_task(): "error.message": ERR_MESSAGE, "error.expected": False, "transactionName": "WebTransaction/Uri/", - # "nr.referringTransactionGuid": 7, } -# @cat_enabled @validate_error_event_sample_data(required_attrs=_intrinsic_attributes, required_user_attrs=True) def test_transaction_error_dt_headers(): test_environ = {"err_message": ERR_MESSAGE} diff --git a/tests/agent_features/test_serverless_mode.py b/tests/agent_features/test_serverless_mode.py index 6c4d5fa348..07b1c5219f 100644 --- a/tests/agent_features/test_serverless_mode.py +++ b/tests/agent_features/test_serverless_mode.py @@ -17,8 +17,6 @@ import pytest from testing_support.fixtures import override_generic_settings from testing_support.validators.validate_serverless_data import validate_serverless_data - -# from testing_support.validators.validate_serverless_metadata import validate_serverless_metadata from testing_support.validators.validate_serverless_payload import validate_serverless_payload from newrelic.api.application import application_instance @@ -66,24 +64,6 @@ def _test(): payload = json.loads(out) -# def test_no_cat_headers(serverless_application): -# @background_task(application=serverless_application, name="test_cat_headers") -# def _test_cat_headers(): -# transaction = current_transaction() - -# payload = ExternalTrace.generate_request_headers(transaction) -# assert not payload - -# trace = ExternalTrace("testlib", "http://example.com") -# response_headers = [("X-NewRelic-App-Data", "Cookies")] -# with trace: -# trace.process_response_headers(response_headers) - -# # assert transaction.settings.cross_application_tracer.enabled is False - -# _test_cat_headers() - - @pytest.mark.parametrize("trusted_account_key", ("1", None), ids=("tk_set", "tk_unset")) def test_outbound_dt_payload_generation(serverless_application, trusted_account_key): @override_generic_settings( diff --git a/tests/agent_features/test_synthetics.py b/tests/agent_features/test_synthetics.py index a5916f7a42..2b4c864509 100644 --- a/tests/agent_features/test_synthetics.py +++ b/tests/agent_features/test_synthetics.py @@ -187,7 +187,6 @@ def test_synthetics_event_mismatched_info_encoding_key(): } -# @cat_enabled @validate_synthetics_transaction_trace(_test_valid_synthetics_tt_required) @override_application_settings(_override_settings) def test_valid_synthetics_in_transaction_trace(): @@ -220,7 +219,6 @@ def test_synthetics_disabled(): _external_synthetics_info_header = _external_synthetics_headers["X-NewRelic-Synthetics-Info"] -# @cat_enabled @validate_synthetics_external_trace_header(_external_synthetics_header, _external_synthetics_info_header) @override_application_settings(_override_settings) def test_valid_synthetics_external_trace_header(): @@ -228,7 +226,6 @@ def test_valid_synthetics_external_trace_header(): response = target_application.get("/", headers=headers) -# @cat_enabled @validate_synthetics_external_trace_header(_external_synthetics_header, None) @override_application_settings(_override_settings) def test_valid_synthetics_external_trace_header_without_info(): @@ -236,7 +233,6 @@ def test_valid_synthetics_external_trace_header_without_info(): response = target_application.get("/", headers=headers) -# @cat_enabled @validate_synthetics_external_trace_header(_external_synthetics_header, _external_synthetics_info_header) @override_application_settings(_override_settings) def test_valid_external_trace_header_with_byte_inbound_header(): diff --git a/tests/agent_unittests/test_agent_protocol.py b/tests/agent_unittests/test_agent_protocol.py index 590cad66f8..d7c760c762 100644 --- a/tests/agent_unittests/test_agent_protocol.py +++ b/tests/agent_unittests/test_agent_protocol.py @@ -488,9 +488,6 @@ def test_serverless_protocol_connect(): # No client calls should be made assert len(HttpClientRecorder.SENT) == 0 - # # cross application tracing must be disabled - # assert not protocol.configuration.cross_application_tracer.enabled - def test_serverless_protocol_finalize(capsys): protocol = ServerlessModeProtocol( diff --git a/tests/agent_unittests/test_harvest_loop.py b/tests/agent_unittests/test_harvest_loop.py index fb572814d3..7173eeb92b 100644 --- a/tests/agent_unittests/test_harvest_loop.py +++ b/tests/agent_unittests/test_harvest_loop.py @@ -134,8 +134,6 @@ def transaction_node(request): guid="4485b89db608aece", cpu_time=0.0, suppress_transaction_trace=False, - # client_cross_process_id=None, - # referring_transaction_guid=None, record_tt=False, synthetics_resource_id=None, synthetics_job_id=None, @@ -145,11 +143,6 @@ def transaction_node(request): synthetics_initiator=None, synthetics_attributes=None, synthetics_info_header=None, - # is_part_of_cat=False, - # trip_id="4485b89db608aece", - # path_hash=None, - # referring_path_hash=None, - # alternate_path_hashes=[], trace_intrinsics={}, distributed_trace_intrinsics={}, agent_attributes=[], diff --git a/tests/cross_agent/test_distributed_tracing.py b/tests/cross_agent/test_distributed_tracing.py index 144dd57e3e..21baa9e45d 100644 --- a/tests/cross_agent/test_distributed_tracing.py +++ b/tests/cross_agent/test_distributed_tracing.py @@ -219,7 +219,6 @@ def test_distributed_tracing( @override_application_settings(override_settings) def _test(): response = test_application.get("/", headers=headers) - # assert "X-NewRelic-App-Data" not in response.headers if "Span" in intrinsics: span_intrinsics = intrinsics.get("Span") diff --git a/tests/external_http/test_http.py b/tests/external_http/test_http.py index 883c40dbd2..1d5f4f0e1c 100644 --- a/tests/external_http/test_http.py +++ b/tests/external_http/test_http.py @@ -15,11 +15,9 @@ import http.client import pytest -from testing_support.external_fixtures import cache_outgoing_headers # , insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers - -# 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 @@ -85,48 +83,7 @@ def _test(): connection.close() _test = override_application_settings( - { - "distributed_tracing.enabled": distributed_tracing, - # "cross_application_tracer.enabled": not distributed_tracing, - "span_events.enabled": span_events, - } + {"distributed_tracing.enabled": distributed_tracing, "span_events.enabled": span_events} )(_test) _test() - - -# @cat_enabled -# def test_http_cross_process_response(server): -# _test_http_cross_process_response_scoped_metrics = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] - -# _test_http_cross_process_response_rollup_metrics = [ -# ("External/all", 1), -# ("External/allOther", 1), -# (f"External/localhost:{server.port}/all", 1), -# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), -# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), -# ] - -# _test_http_cross_process_response_external_node_params = [ -# ("cross_process_id", "1#2"), -# ("external_txn_name", "test"), -# ("transaction_guid", "0123456789012345"), -# ] - -# @validate_transaction_metrics( -# "test_http:test_http_cross_process_response", -# scoped_metrics=_test_http_cross_process_response_scoped_metrics, -# rollup_metrics=_test_http_cross_process_response_rollup_metrics, -# background_task=True, -# ) -# @insert_incoming_headers -# @validate_external_node_params(params=_test_http_cross_process_response_external_node_params) -# @background_task(name="test_http:test_http_cross_process_response") -# def _test(): -# connection = http.client.HTTPConnection("localhost", server.port) -# connection.request("GET", "/") -# response = connection.getresponse() -# response.read() -# connection.close() - -# _test() diff --git a/tests/external_httplib/test_httplib.py b/tests/external_httplib/test_httplib.py index 2db632a4ac..1103072df4 100644 --- a/tests/external_httplib/test_httplib.py +++ b/tests/external_httplib/test_httplib.py @@ -17,11 +17,9 @@ import json import pytest -from testing_support.external_fixtures import cache_outgoing_headers # , insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers - -# from testing_support.validators.validate_external_node_params import validate_external_node_params 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_tt_segment_params import validate_tt_segment_params @@ -125,86 +123,12 @@ def _test(): connection.close() _test = override_application_settings( - { - "distributed_tracing.enabled": distributed_tracing, - # "cross_application_tracer.enabled": not distributed_tracing, - "span_events.enabled": span_events, - } + {"distributed_tracing.enabled": distributed_tracing, "span_events.enabled": span_events} )(_test) _test() -# _test_httplib_cross_process_response_external_node_params = [ -# ("cross_process_id", "1#2"), -# ("external_txn_name", "test"), -# ("transaction_guid", "0123456789012345"), -# ] - - -# # @cat_enabled -# @insert_incoming_headers -# def test_httplib_cross_process_response(server): -# scoped = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] - -# rollup = [ -# ("External/all", 1), -# ("External/allOther", 1), -# (f"External/localhost:{server.port}/all", 1), -# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), -# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), -# ] - -# @validate_transaction_metrics( -# "test_httplib:test_httplib_cross_process_response", -# scoped_metrics=scoped, -# rollup_metrics=rollup, -# background_task=True, -# ) -# @validate_external_node_params(params=_test_httplib_cross_process_response_external_node_params) -# @background_task(name="test_httplib:test_httplib_cross_process_response") -# def _test(): -# connection = httplib.HTTPConnection("localhost", server.port) -# connection.request("GET", "/") -# response = connection.getresponse() -# response.read() -# connection.close() - -# _test() - - -# @cat_enabled -# def test_httplib_multiple_requests_cross_process_response(server): -# connection = httplib.HTTPConnection("localhost", server.port) - -# scoped = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] - -# rollup = [ -# ("External/all", 1), -# ("External/allOther", 1), -# (f"External/localhost:{server.port}/all", 1), -# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), -# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), -# ] - -# @validate_transaction_metrics( -# "test_httplib:test_transaction", scoped_metrics=scoped, rollup_metrics=rollup, background_task=True -# ) -# @insert_incoming_headers -# @validate_external_node_params(params=_test_httplib_cross_process_response_external_node_params) -# @background_task(name="test_httplib:test_transaction") -# def test_transaction(): -# connection.request("GET", "/") -# response = connection.getresponse() -# response.read() - -# # make multiple requests with the same connection -# for _ in range(2): -# test_transaction() - -# connection.close() - - def process_response(response): response = response.decode("utf-8").strip() values = response.splitlines() @@ -242,7 +166,7 @@ def test_transaction(): def test_httplib_nr_headers_added(server): connection = httplib.HTTPConnection("localhost", server.port) - key = "header_key" + key = "newrelic" value = "testval" headers = [] @@ -259,6 +183,7 @@ def test_transaction(): )(test_transaction) test_transaction() connection.close() + # verify newrelic headers already added do not get overridden assert headers[0][key] == value diff --git a/tests/external_httplib/test_urllib.py b/tests/external_httplib/test_urllib.py index 3c97b573a6..5d6674686e 100644 --- a/tests/external_httplib/test_urllib.py +++ b/tests/external_httplib/test_urllib.py @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os - import pytest try: @@ -21,12 +19,8 @@ except: import urllib -from testing_support.external_fixtures import cache_outgoing_headers # , insert_incoming_headers - -# from testing_support.fixtures import cat_enabled +from testing_support.external_fixtures import cache_outgoing_headers from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers - -# 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 @@ -133,42 +127,6 @@ def test_urlopener_cross_process_request(server): opener.open(f"http://localhost:{server.port}/") -# # @cat_enabled -# def test_urlopener_cross_process_response(server): -# _test_urlopener_cross_process_response_scoped_metrics = [ -# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) -# ] - -# _test_urlopener_cross_process_response_rollup_metrics = [ -# ("External/all", 1), -# ("External/allOther", 1), -# (f"External/localhost:{server.port}/all", 1), -# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), -# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), -# ] - -# _test_urlopener_cross_process_response_external_node_params = [ -# ("cross_process_id", "1#2"), -# ("external_txn_name", "test"), -# ("transaction_guid", "0123456789012345"), -# ] - -# @validate_transaction_metrics( -# "test_urllib:test_urlopener_cross_process_response", -# scoped_metrics=_test_urlopener_cross_process_response_scoped_metrics, -# rollup_metrics=_test_urlopener_cross_process_response_rollup_metrics, -# background_task=True, -# ) -# @insert_incoming_headers -# @validate_external_node_params(params=_test_urlopener_cross_process_response_external_node_params) -# @background_task(name="test_urllib:test_urlopener_cross_process_response") -# def _test(): -# opener = urllib.URLopener() -# opener.open(f"http://localhost:{server.port}/") - -# _test() - - def test_urlretrieve_http_request(server, metrics): @validate_transaction_metrics( "test_urllib:test_urlretrieve_http_request", @@ -205,38 +163,3 @@ def _test(): @validate_cross_process_headers def test_urlretrieve_cross_process_request(server): urllib.urlretrieve(f"http://localhost:{server.port}/") - - -# @cat_enabled -# def test_urlretrieve_cross_process_response(server): -# _test_urlretrieve_cross_process_response_scoped_metrics = [ -# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) -# ] - -# _test_urlretrieve_cross_process_response_rollup_metrics = [ -# ("External/all", 1), -# ("External/allOther", 1), -# (f"External/localhost:{server.port}/all", 1), -# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), -# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), -# ] - -# _test_urlretrieve_cross_process_response_external_node_params = [ -# ("cross_process_id", "1#2"), -# ("external_txn_name", "test"), -# ("transaction_guid", "0123456789012345"), -# ] - -# @validate_transaction_metrics( -# "test_urllib:test_urlretrieve_cross_process_response", -# scoped_metrics=_test_urlretrieve_cross_process_response_scoped_metrics, -# rollup_metrics=_test_urlretrieve_cross_process_response_rollup_metrics, -# background_task=True, -# ) -# @insert_incoming_headers -# @validate_external_node_params(params=_test_urlretrieve_cross_process_response_external_node_params) -# @background_task(name="test_urllib:test_urlretrieve_cross_process_response") -# def _test(): -# urllib.urlretrieve(f"http://localhost:{server.port}/") - -# _test() diff --git a/tests/external_httplib/test_urllib2.py b/tests/external_httplib/test_urllib2.py index 7deb368359..c5478036af 100644 --- a/tests/external_httplib/test_urllib2.py +++ b/tests/external_httplib/test_urllib2.py @@ -12,16 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import urllib.request as urllib2 import pytest -from testing_support.external_fixtures import cache_outgoing_headers # , insert_incoming_headers - -# from testing_support.fixtures import cat_enabled +from testing_support.external_fixtures import cache_outgoing_headers from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers - -# 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 @@ -121,36 +116,3 @@ def test_urlopen_file_request(): @validate_cross_process_headers def test_urlopen_cross_process_request(server): urllib2.urlopen(f"http://localhost:{server.port}/") - - -# @cat_enabled -# def test_urlopen_cross_process_response(server): -# _test_urlopen_cross_process_response_scoped_metrics = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] - -# _test_urlopen_cross_process_response_rollup_metrics = [ -# ("External/all", 1), -# ("External/allOther", 1), -# (f"External/localhost:{server.port}/all", 1), -# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), -# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), -# ] - -# _test_urlopen_cross_process_response_external_node_params = [ -# ("cross_process_id", "1#2"), -# ("external_txn_name", "test"), -# ("transaction_guid", "0123456789012345"), -# ] - -# @validate_transaction_metrics( -# "test_urllib2:test_urlopen_cross_process_response", -# scoped_metrics=_test_urlopen_cross_process_response_scoped_metrics, -# rollup_metrics=_test_urlopen_cross_process_response_rollup_metrics, -# background_task=True, -# ) -# @insert_incoming_headers -# @validate_external_node_params(params=_test_urlopen_cross_process_response_external_node_params) -# @background_task(name="test_urllib2:test_urlopen_cross_process_response") -# def _test(): -# urllib2.urlopen(f"http://localhost:{server.port}/") - -# _test() diff --git a/tests/external_httplib2/test_httplib2.py b/tests/external_httplib2/test_httplib2.py index 55ca4c1c73..fe531a4b67 100644 --- a/tests/external_httplib2/test_httplib2.py +++ b/tests/external_httplib2/test_httplib2.py @@ -14,11 +14,9 @@ import httplib2 import pytest -from testing_support.external_fixtures import cache_outgoing_headers # , insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers - -# 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 @@ -103,50 +101,7 @@ def _test(): connection.close() _test = override_application_settings( - { - "distributed_tracing.enabled": distributed_tracing, - # "cross_application_tracer.enabled": not distributed_tracing, - "span_events.enabled": span_events, - } + {"distributed_tracing.enabled": distributed_tracing, "span_events.enabled": span_events} )(_test) _test() - - -# @cat_enabled -# def test_httplib2_cross_process_response(server): -# _test_httplib2_cross_process_response_scoped_metrics = [ -# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) -# ] - -# _test_httplib2_cross_process_response_rollup_metrics = [ -# ("External/all", 1), -# ("External/allOther", 1), -# (f"External/localhost:{server.port}/all", 1), -# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), -# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), -# ] - -# _test_httplib2_cross_process_response_external_node_params = [ -# ("cross_process_id", "1#2"), -# ("external_txn_name", "test"), -# ("transaction_guid", "0123456789012345"), -# ] - -# @validate_transaction_metrics( -# "test_httplib2:test_httplib2_cross_process_response", -# scoped_metrics=_test_httplib2_cross_process_response_scoped_metrics, -# rollup_metrics=_test_httplib2_cross_process_response_rollup_metrics, -# background_task=True, -# ) -# @insert_incoming_headers -# @validate_external_node_params(params=_test_httplib2_cross_process_response_external_node_params) -# @background_task(name="test_httplib2:test_httplib2_cross_process_response") -# def _test(): -# connection = httplib2.HTTPConnectionWithTimeout("localhost", server.port) -# connection.request("GET", "/") -# response = connection.getresponse() -# response.read() -# connection.close() - -# _test() diff --git a/tests/external_httpx/test_client.py b/tests/external_httpx/test_client.py index 5b97105b79..4347c49f59 100644 --- a/tests/external_httpx/test_client.py +++ b/tests/external_httpx/test_client.py @@ -21,41 +21,18 @@ 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 testing_support.validators.validate_tt_segment_params import validate_tt_segment_params from newrelic.api.background_task import background_task from newrelic.api.time_trace import current_trace from newrelic.api.transaction import current_transaction from newrelic.core.config import global_settings -ENCODING_KEY = "1234567890123456789012345678901234567890" SCOPED_METRICS = [] ROLLUP_METRICS = [("External/all", 2), ("External/allOther", 2)] DT_RESPONSE_CODE = None -# def cat_response_handler(self): -# if not DT_RESPONSE_CODE: -# raise ValueError("DT_RESPONSE_CODE must be a valid status_code.") - -# # payload -# # ( -# # u'1#1', u'WebTransaction/Function/app:beep', -# # 0, 1.23, -1, -# # 'dd4a810b7cb7f937', -# # False, -# # ) -# cat_response_header = ( -# "X-NewRelic-App-Data", -# "ahACFwQUGxpuVVNmQVVbRVZbTVleXBxyQFhUTFBfXx1SREUMVV1cQBMeAxgEGAULFR0AHhFQUQJWAAgAUwVQVgJQDgsOEh1UUlhGU2o=", -# ) -# self.send_response(DT_RESPONSE_CODE) -# self.send_header(*cat_response_header) -# self.end_headers() -# self.wfile.write(b"Example Data") - - def dt_response_handler(self): if not DT_RESPONSE_CODE: raise ValueError("DT_RESPONSE_CODE must be a valid status_code.") @@ -68,7 +45,6 @@ def dt_response_handler(self): @pytest.fixture(scope="session") def mock_server(): - # external = MockExternalHTTPHResponseHeadersServer(handler=cat_response_handler) external = MockExternalHTTPHResponseHeadersServer(handler=dt_response_handler) with external: yield external @@ -132,11 +108,7 @@ def test_sync_cross_process_request(httpx, sync_client, mock_server, distributed DT_RESPONSE_CODE = 200 @override_application_settings( - { - "distributed_tracing.enabled": distributed_tracing, - "span_events.enabled": span_events, - # "cross_application_tracer.enabled": not distributed_tracing, - } + {"distributed_tracing.enabled": distributed_tracing, "span_events.enabled": span_events} ) @validate_transaction_errors(errors=[]) @background_task(name="test_sync_cross_process_request") @@ -217,87 +189,6 @@ async def _test(): assert response.request.headers["newrelic"] == "1234" -# @pytest.mark.parametrize("cat_enabled", [True, False]) -# @pytest.mark.parametrize("response_code", [200, 500]) -# def test_sync_client_cat_response_processing(cat_enabled, response_code, sync_client, mock_server, httpx): -# global CAT_RESPONSE_CODE -# CAT_RESPONSE_CODE = response_code - -# _custom_settings = { -# "cross_process_id": "1#1", -# "encoding_key": ENCODING_KEY, -# "trusted_account_ids": [1], -# "cross_application_tracer.enabled": cat_enabled, -# "distributed_tracing.enabled": False, -# "transaction_tracer.transaction_threshold": 0.0, -# } - -# expected_metrics = [ -# ( -# f"ExternalTransaction/localhost:{mock_server.port}/1#1/WebTransaction/Function/app:beep", -# 1 if cat_enabled else None, -# ) -# ] - -# @validate_transaction_metrics( -# "test_sync_client_cat_response_processing", -# background_task=True, -# rollup_metrics=expected_metrics, -# scoped_metrics=expected_metrics, -# ) -# @validate_tt_segment_params(exact_params={"http.statusCode": response_code}) -# @override_application_settings(_custom_settings) -# @background_task(name="test_sync_client_cat_response_processing") -# def _test(): -# with sync_client: -# response = sync_client.get(f"http://localhost:{mock_server.port}") - -# _test() - - -# @pytest.mark.parametrize("cat_enabled", [True, False]) -# @pytest.mark.parametrize("response_code", [200, 500]) -# def test_async_client_cat_response_processing(cat_enabled, response_code, httpx, async_client, mock_server, loop): -# global CAT_RESPONSE_CODE -# CAT_RESPONSE_CODE = response_code - -# _custom_settings = { -# "cross_process_id": "1#1", -# "encoding_key": ENCODING_KEY, -# "trusted_account_ids": [1], -# "cross_application_tracer.enabled": cat_enabled, -# "distributed_tracing.enabled": False, -# "transaction_tracer.transaction_threshold": 0.0, -# } - -# expected_metrics = [ -# ( -# f"ExternalTransaction/localhost:{mock_server.port}/1#1/WebTransaction/Function/app:beep", -# 1 if cat_enabled else None, -# ) -# ] - -# @validate_transaction_metrics( -# "test_async_client_cat_response_processing", -# background_task=True, -# rollup_metrics=expected_metrics, -# scoped_metrics=expected_metrics, -# ) -# @validate_tt_segment_params(exact_params={"http.statusCode": response_code}) -# @override_application_settings(_custom_settings) -# @background_task(name="test_async_client_cat_response_processing") -# def _test(): -# async def coro(): -# async with async_client: -# response = await async_client.get(f"http://localhost:{mock_server.port}") - -# return response - -# response = loop.run_until_complete(coro()) - -# _test() - - @dt_enabled def test_sync_client_event_hook_exception(httpx, mock_server): global DT_RESPONSE_CODE diff --git a/tests/external_requests/test_requests.py b/tests/external_requests/test_requests.py index f7f0c5220b..5e4d8724ac 100644 --- a/tests/external_requests/test_requests.py +++ b/tests/external_requests/test_requests.py @@ -14,12 +14,9 @@ import pytest import requests -import requests.exceptions -from testing_support.external_fixtures import cache_outgoing_headers # , insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers from testing_support.fixtures import override_application_settings, validate_tt_parenting from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers - -# 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 @@ -123,9 +120,6 @@ def _test(): def test_none_url_get(): try: requests.get(None) - except requests.exceptions.MissingSchema: - # Python 2. - pass except TypeError: # Python 3. pass @@ -166,47 +160,7 @@ def _test(): requests.get(f"http://localhost:{server.port}/") _test = override_application_settings( - { - "distributed_tracing.enabled": distributed_tracing, - # "cross_application_tracer.enabled": not distributed_tracing, - "span_events.enabled": span_events, - } + {"distributed_tracing.enabled": distributed_tracing, "span_events.enabled": span_events} )(_test) _test() - - -# @cat_enabled -# def test_requests_cross_process_response(server): -# _test_requests_cross_process_response_scoped_metrics = [ -# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) -# ] - -# _test_requests_cross_process_response_rollup_metrics = [ -# ("External/all", 1), -# ("External/allOther", 1), -# (f"External/localhost:{server.port}/all", 1), -# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), -# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), -# ] - -# _test_requests_cross_process_response_external_node_params = [ -# ("cross_process_id", "1#2"), -# ("external_txn_name", "test"), -# ("transaction_guid", "0123456789012345"), -# ] - -# @validate_transaction_errors(errors=[]) -# @validate_transaction_metrics( -# "test_requests:test_requests_cross_process_response", -# scoped_metrics=_test_requests_cross_process_response_scoped_metrics, -# rollup_metrics=_test_requests_cross_process_response_rollup_metrics, -# background_task=True, -# ) -# @insert_incoming_headers -# @validate_external_node_params(params=_test_requests_cross_process_response_external_node_params) -# @background_task(name="test_requests:test_requests_cross_process_response") -# def _test(): -# requests.get(f"http://localhost:{server.port}/") - -# _test() diff --git a/tests/external_urllib3/test_urllib3.py b/tests/external_urllib3/test_urllib3.py index f82c183225..106f0b96ab 100644 --- a/tests/external_urllib3/test_urllib3.py +++ b/tests/external_urllib3/test_urllib3.py @@ -14,18 +14,15 @@ import pytest import urllib3 -import urllib3.connectionpool try: import urllib3.connection except ImportError: pass -from testing_support.external_fixtures import cache_outgoing_headers # , insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers - -# 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 @@ -215,46 +212,7 @@ def _test(): pool.urlopen("GET", "/") _test = override_application_settings( - { - "distributed_tracing.enabled": distributed_tracing, - # "cross_application_tracer.enabled": not distributed_tracing, - "span_events.enabled": span_events, - } + {"distributed_tracing.enabled": distributed_tracing, "span_events.enabled": span_events} )(_test) _test() - - -# @cat_enabled -# def test_urlopen_cross_process_response(server): -# _test_urlopen_cross_process_response_scoped_metrics = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] - -# _test_urlopen_cross_process_response_rollup_metrics = [ -# ("External/all", 1), -# ("External/allOther", 1), -# (f"External/localhost:{server.port}/all", 1), -# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), -# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), -# ] - -# _test_urlopen_cross_process_response_external_node_params = [ -# ("cross_process_id", "1#2"), -# ("external_txn_name", "test"), -# ("transaction_guid", "0123456789012345"), -# ] - -# @validate_transaction_errors(errors=[]) -# @validate_transaction_metrics( -# "test_urllib3:test_urlopen_cross_process_response", -# scoped_metrics=_test_urlopen_cross_process_response_scoped_metrics, -# rollup_metrics=_test_urlopen_cross_process_response_rollup_metrics, -# background_task=True, -# ) -# @insert_incoming_headers -# @validate_external_node_params(params=_test_urlopen_cross_process_response_external_node_params) -# @background_task(name="test_urllib3:test_urlopen_cross_process_response") -# def _test(): -# pool = urllib3.HTTPConnectionPool(f"localhost:{server.port}") -# pool.urlopen("GET", "/") - -# _test() diff --git a/tests/framework_aiohttp/conftest.py b/tests/framework_aiohttp/conftest.py index 0d295b3fff..1cdf4c607a 100644 --- a/tests/framework_aiohttp/conftest.py +++ b/tests/framework_aiohttp/conftest.py @@ -123,8 +123,6 @@ def respond_with_dt_header(self): self.end_headers() self.wfile.write(b"") - # with MockExternalHTTPServer(handler=respond_with_cat_header) as server: - # with MockExternalHTTPServer() as server: with MockExternalHTTPServer(handler=respond_with_dt_header) as server: yield (server, response_values) diff --git a/tests/framework_aiohttp/test_client_async_await.py b/tests/framework_aiohttp/test_client_async_await.py index a30cd830b6..0de1e083e6 100644 --- a/tests/framework_aiohttp/test_client_async_await.py +++ b/tests/framework_aiohttp/test_client_async_await.py @@ -16,8 +16,6 @@ import aiohttp import pytest - -# from testing_support.fixtures import cat_enabled from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from yarl import URL @@ -68,7 +66,6 @@ def task(loop, method, exc_expected, url): ) -# @cat_enabled @pytest.mark.parametrize("method,exc_expected", test_matrix) def test_client_async_await(event_loop, local_server_info, method, exc_expected): @validate_transaction_metrics( @@ -83,7 +80,6 @@ def task_test(): task_test() -# @cat_enabled def test_client_yarl_async_await(event_loop, local_server_info): method = "get" @@ -100,7 +96,6 @@ def task_test(): @pytest.mark.parametrize("method,exc_expected", test_matrix) -# @cat_enabled def test_client_no_txn_async_await(event_loop, local_server_info, method, exc_expected): def task_test(): task(event_loop, method, exc_expected, local_server_info.url) @@ -109,7 +104,6 @@ def task_test(): @pytest.mark.parametrize("method,exc_expected", test_matrix) -# @cat_enabled def test_await_request_async_await(event_loop, local_server_info, method, exc_expected): async def request_with_await(): async with aiohttp.ClientSession() as session: @@ -163,7 +157,6 @@ def task_test(): @pytest.mark.parametrize("method,exc_expected", test_matrix) -# @cat_enabled def test_create_task_async_await(event_loop, local_server_info, method, exc_expected): # `loop.create_task` returns a Task object which uses the coroutine's # `send` method, not `__next__` @@ -199,7 +192,6 @@ def task_test(): @pytest.mark.parametrize("method,exc_expected", test_matrix) -# @cat_enabled def test_terminal_parent_async_await(event_loop, local_server_info, method, exc_expected): """ This test injects a terminal node into a simple background task workflow. diff --git a/tests/framework_aiohttp/test_server_dt.py b/tests/framework_aiohttp/test_server_dt.py index 307eade547..0b9350d04c 100644 --- a/tests/framework_aiohttp/test_server_dt.py +++ b/tests/framework_aiohttp/test_server_dt.py @@ -15,135 +15,15 @@ import json import pytest -from testing_support.fixtures import ( - # make_cross_agent_headers, - override_application_settings, - # validate_analytics_catmap_data, -) +from testing_support.fixtures import override_application_settings from testing_support.validators.validate_transaction_event_attributes import validate_transaction_event_attributes -# from newrelic.common.encoding_utils import deobfuscate -# from newrelic.common.object_wrapper import transient_function_wrapper - -# ENCODING_KEY = "1234567890123456789012345678901234567890" test_uris = [ ("/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 -# except ImportError: - -# def pass_through(function): -# return function - -# return pass_through - -# @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") - -# # This is the request, not the response -# if line.startswith("GET"): -# break - -# if ":" in line: -# key, value = line.split(":", maxsplit=1) -# raw_headers[key.strip()] = value.strip() - -# return wrapped(*args, **kwargs) - -# return recorder - - -# @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 -# ): -# _raw_headers = {} - -# async def fetch(): -# headers = make_cross_agent_headers(inbound_payload, ENCODING_KEY, cat_id) -# resp = await 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} - -# if expected_intrinsics: -# # test valid CAT response header -# assert "X-NewRelic-App-Data" in raw_headers - -# app_data = json.loads(deobfuscate(raw_headers["X-NewRelic-App-Data"], ENCODING_KEY)) -# assert app_data[0] == cat_id -# assert app_data[1] == f"WebTransaction/Function/{metric_name}" -# else: -# 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, -# } - -# # NOTE: the logic-flow of this test can be a bit confusing. -# # the override settings and attribute validation occur -# # not when the request is made (above) since it does not -# # occur inside a transaction. instead, the settings and -# # validation are for the new transaction that is made -# # asynchronously on the *server side* when the request -# # is received and subsequently processed. that code is -# # a fixture from conftest.py/_target_application.py - -# @validate_analytics_catmap_data( -# f"WebTransaction/Function/{metric_name}", -# expected_attributes=expected_intrinsics, -# non_expected_attributes=forgone_intrinsics, -# ) -# @override_application_settings(_custom_settings) -# @record_aiohttp1_raw_headers(_raw_headers) -# def _test(): -# aiohttp_app.loop.run_until_complete(fetch()) - -# _test() - - account_id = "33" primary_application_id = "2827902" @@ -178,12 +58,6 @@ }, } -# unexpected_attributes = { -# "agent": [], -# "user": [], -# "intrinsic": ["grandparentId", "cross_process_id", "nr.tripId", "nr.pathHash"], -# } - @pytest.mark.parametrize("uri,metric_name", test_uris) def test_distributed_tracing_headers(uri, metric_name, aiohttp_app): @@ -191,11 +65,8 @@ async def fetch(): headers = {"newrelic": json.dumps(inbound_payload)} resp = await aiohttp_app.client.request("GET", uri, headers=headers) - # # better cat does not send a response in the 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 + # DT does not send a response in the headers + assert "newrelic" not in resp.headers # NOTE: the logic-flow of this test can be a bit confusing. # the override settings and attribute validation occur @@ -207,7 +78,6 @@ async def fetch(): # a fixture from conftest.py/_target_application.py @validate_transaction_event_attributes(expected_attributes) - # @validate_transaction_event_attributes(expected_attributes, unexpected_attributes) @override_application_settings( { "account_id": "33", diff --git a/tests/framework_sanic/conftest.py b/tests/framework_sanic/conftest.py index 8802638beb..f86a9cf10d 100644 --- a/tests/framework_sanic/conftest.py +++ b/tests/framework_sanic/conftest.py @@ -17,8 +17,6 @@ import pytest from testing_support.fixtures import collector_agent_registration_fixture, collector_available_fixture -# from newrelic.common.object_wrapper import transient_function_wrapper - _default_settings = { "package_reporting.enabled": False, # Turn off package reporting for testing as it causes slow downs. "transaction_tracer.explain_threshold": 0.0, diff --git a/tests/framework_sanic/test_distributed_trace.py b/tests/framework_sanic/test_distributed_trace.py index 436bd0e68c..d4f10abb72 100644 --- a/tests/framework_sanic/test_distributed_trace.py +++ b/tests/framework_sanic/test_distributed_trace.py @@ -12,18 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# import json -# import random - -# import re -# import string - -# import pytest -from testing_support.fixtures import ( - # make_cross_agent_headers, - override_application_settings, - # validate_analytics_catmap_data, -) +from testing_support.fixtures import override_application_settings from testing_support.validators.validate_transaction_event_attributes import validate_transaction_event_attributes from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics @@ -31,8 +20,6 @@ from newrelic.api.external_trace import ExternalTrace from newrelic.api.transaction import Transaction -# from newrelic.common.encoding_utils import deobfuscate - BASE_METRICS = [("Function/_target_application:index", 1)] DT_METRICS = [ ("Supportability/DistributedTrace/AcceptPayload/Success", None), @@ -63,80 +50,3 @@ def test_inbound_distributed_trace(app): response = app.fetch("get", "/", headers=dict(dt_headers)) assert response.status == 200 - - -# ENCODING_KEY = "".join(random.choice(string.ascii_lowercase) for _ in range(40)) -# _cat_response_header_urls_to_test = ( -# ("/", "_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, -# } - - -# @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): -# _base_metrics = [(f"Function/{metric_name}", 1)] - -# @validate_transaction_metrics(metric_name, scoped_metrics=_base_metrics, rollup_metrics=_base_metrics) -# @validate_analytics_catmap_data( -# f"WebTransaction/Function/{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)) -# if expected_intrinsics: -# # test valid CAT response header -# 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)) -# assert app_data[0] == cat_id -# assert app_data[1] == f"WebTransaction/Function/{metric_name}" -# else: -# 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", f"/custom-header/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/_target_application.py b/tests/framework_tornado/_target_application.py index 396f357570..49383b216b 100644 --- a/tests/framework_tornado/_target_application.py +++ b/tests/framework_tornado/_target_application.py @@ -15,7 +15,6 @@ import time import tornado.gen -import tornado.httpclient import tornado.httputil import tornado.ioloop import tornado.web @@ -35,35 +34,6 @@ def get_status(self, *args, **kwargs): raise ValueError("Bad Status") -# class ProcessCatHeadersHandler(tornado.web.RequestHandler): -# def __init__(self, application, request, response_code=200, **kwargs): -# super().__init__(application, request, **kwargs) -# self.response_code = response_code - -# def get(self, client_cross_process_id, txn_header, flush=None): -# import newrelic.api.transaction as _transaction - -# # txn = _transaction.current_transaction() -# # if txn: -# # txn._process_incoming_cat_headers(client_cross_process_id, txn_header) - -# if self.response_code != 200: -# self.set_status(self.response_code) -# return - -# self.write("Hello, world") - -# if flush == "flush": -# # Force a flush prior to calling finish -# # This causes the headers to get written immediately. The tests -# # which hit this endpoint will check that the response has been -# # properly processed even though we send the headers here. -# self.flush() - -# # change the headers to garbage -# self.set_header("Content-Type", "garbage") - - class EchoHeaderHandler(tornado.web.RequestHandler): def get(self): response = str(self.request.headers.__dict__).encode("utf-8") @@ -250,8 +220,6 @@ def make_app(custom=False): (r"/init", InitializeHandler), (r"/html-insertion", HTMLInsertionHandler), (r"/bad-get-status", BadGetStatusHandler), - # (r"/force-cat-response/(\S+)/(\S+)/(\S+)", ProcessCatHeadersHandler), - # (r"/304-cat-response/(\S+)/(\S+)", ProcessCatHeadersHandler, {"response_code": 304}), (r"/echo-headers", EchoHeaderHandler), (r"/native-simple", NativeSimpleHandler), (r"/multi-trace", MultiTraceHandler), diff --git a/tests/framework_tornado/test_externals.py b/tests/framework_tornado/test_externals.py index 8d7ef80ab2..e872b3bdfc 100644 --- a/tests/framework_tornado/test_externals.py +++ b/tests/framework_tornado/test_externals.py @@ -13,24 +13,16 @@ # limitations under the License. import io -import socket import sys import pytest from testing_support.fixtures import override_application_settings -from testing_support.mock_external_http_server import MockExternalHTTPHResponseHeadersServer, MockExternalHTTPServer - -# from testing_support.validators.validate_distributed_tracing_header import validate_distributed_tracing_header -# from testing_support.validators.validate_outbound_headers import validate_outbound_headers +from testing_support.mock_external_http_server import MockExternalHTTPHResponseHeadersServer 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 -# from newrelic.api.transaction import current_transaction - -ENCODING_KEY = "1234567890123456789012345678901234567890" - is_pypy = hasattr(sys, "pypy_version_info") @@ -128,26 +120,12 @@ def _make_request(): @pytest.mark.parametrize("span_events", [True, False]) @pytest.mark.parametrize("request_type", ["uri", "class"]) @pytest.mark.parametrize("num_requests", [1, 2]) -def test_httpclient( - # cat_enabled, - request_type, - client_class, - num_requests, - span_events, - external, - as_kwargs, -): +def test_httpclient(request_type, client_class, num_requests, span_events, external, as_kwargs): port = external.port expected_metrics = [(f"External/localhost:{port}/tornado/GET", num_requests)] - @override_application_settings( - { - "distributed_tracing.enabled": True, - "span_events.enabled": span_events, - # "cross_application_tracer.enabled": not distributed_tracing, - } - ) + @override_application_settings({"distributed_tracing.enabled": True, "span_events.enabled": span_events}) @validate_transaction_metrics( "test_externals:test_httpclient", background_task=True, @@ -157,8 +135,6 @@ def test_httpclient( @background_task(name="test_externals:test_httpclient") def _test(): headers = {} - # if user_header: - # headers = {user_header: "USER"} response = make_request( port, request_type, client_class, headers=headers, count=num_requests, as_kwargs=as_kwargs @@ -178,98 +154,9 @@ def _test(): header_val = header_val.strip() headers[header_key] = header_val - # User headers override all inserted NR headers - # if user_header: - # assert headers[user_header] == "USER" - # elif cat_enabled: - # t = current_transaction() - # assert t - # t._test_request_headers = headers - - # if distributed_tracing: - # validate_distributed_tracing_header(header="Newrelic") - # else: - # validate_outbound_headers() - # else: - # # new relic shouldn't add anything to the outgoing - # assert "x-newrelic" not in body, body - - # assert "X-NewRelic-App-Data" not in headers - _test() -# CAT_RESPONSE_CODE = None - - -# def cat_response_handler(self): -# # payload -# # ( -# # u'1#1', u'WebTransaction/Function/app:beep', -# # 0, 1.23, -1, -# # 'dd4a810b7cb7f937', -# # False, -# # ) -# cat_response_header = ( -# "X-NewRelic-App-Data", -# "ahACFwQUGxpuVVNmQVVbRVZbTVleXBxyQFhUTFBfXx1SREUMVV1cQBMeAxgEGAULFR0AHhFQUQJWAAgAUwVQVgJQDgsOEh1UUlhGU2o=", -# ) -# self.send_response(CAT_RESPONSE_CODE) -# self.send_header(*cat_response_header) -# self.end_headers() -# self.wfile.write(b"Example Data") - - -# @pytest.fixture(scope="module") -# def cat_response_server(): -# external = MockExternalHTTPServer(handler=cat_response_handler) -# with external: -# yield external - - -# @pytest.mark.parametrize("client_class", ["AsyncHTTPClient", "CurlAsyncHTTPClient", "HTTPClient"]) -# @pytest.mark.parametrize("dt_enabled", [True, False]) -# @pytest.mark.parametrize("request_type", ["uri", "class"]) -# @pytest.mark.parametrize("response_code,raise_error", [(500, True), (500, False), (200, False)]) -# def test_client_cat_response_processing( -# dt_enabled, request_type, client_class, raise_error, response_code, cat_response_server -# ): -# global CAT_RESPONSE_CODE -# CAT_RESPONSE_CODE = response_code - -# _custom_settings = { -# "cross_process_id": "1#1", -# "encoding_key": ENCODING_KEY, -# "trusted_account_ids": [1], -# # "cross_application_tracer.enabled": cat_enabled, -# "distributed_tracing.enabled": dt_enabled, -# "transaction_tracer.transaction_threshold": 0.0, -# } - -# port = cat_response_server.port -# expected_metrics = None - -# @validate_transaction_metrics( -# "make_request", background_task=True, rollup_metrics=expected_metrics, scoped_metrics=expected_metrics -# ) -# @override_application_settings(_custom_settings) -# def _test(): -# import tornado -# import tornado.httpclient - -# try: -# response = make_request(port, request_type, client_class, raise_error=raise_error) -# except tornado.httpclient.HTTPError as e: -# assert raise_error -# response = e.response -# else: -# assert not raise_error - -# assert response.code == response_code - -# _test() - - @pytest.mark.parametrize("client_class", ["AsyncHTTPClient", "CurlAsyncHTTPClient", "HTTPClient"]) @validate_transaction_metrics("make_request", background_task=True) def test_httpclient_invalid_method(client_class, external): diff --git a/tests/framework_tornado/test_inbound_dt.py b/tests/framework_tornado/test_inbound_dt.py index 319fc00229..f8358338c6 100644 --- a/tests/framework_tornado/test_inbound_dt.py +++ b/tests/framework_tornado/test_inbound_dt.py @@ -18,76 +18,6 @@ from testing_support.validators.validate_transaction_event_attributes import validate_transaction_event_attributes from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics -# ENCODING_KEY = "1234567890123456789012345678901234567890" - - -# _custom_settings = { -# "cross_process_id": "1#1", -# "encoding_key": ENCODING_KEY, -# "trusted_account_ids": [1], -# # "cross_application_tracer.enabled": True, -# "distributed_tracing.enabled": False, -# "transaction_tracer.transaction_threshold": 0.0, -# } - - -# @override_application_settings(_custom_settings) -# @validate_transaction_event_attributes( -# required_params={"agent": (), "user": (), "intrinsic": ()}, -# forgone_params={"agent": (), "user": (), "intrinsic": ()}, -# exact_attrs={ -# "agent": {"response.status": "200", "response.headers.contentType": "text/html; charset=UTF-8"}, -# "user": {}, -# "intrinsic": {}, -# }, -# ) -# @pytest.mark.parametrize("manual_flush", ["flush", "no-flush"]) -# def test_response_to_inbound_cat(app, manual_flush): -# payload = ("1#1", "WebTransaction/Function/app:beep", 0, 1.23, -1, "dd4a810b7cb7f937", False) -# headers = make_cross_agent_headers(payload, ENCODING_KEY, "1#1") - -# client_cross_process_id = headers["X-NewRelic-ID"] -# txn_header = headers["X-NewRelic-Transaction"] - -# response = app.fetch(f"/force-cat-response/{client_cross_process_id}/{txn_header}/{manual_flush}") -# assert response.code == 200 -# assert "X-NewRelic-App-Data" in list(response.headers.keys()) - - -# # @validate_transaction_event_attributes( -# # required_params={"agent": (), "user": (), "intrinsic": ()}, -# # forgone_params={"agent": ("response.headers",), "user": (), "intrinsic": ()}, -# # exact_attrs={"agent": {"request.method": "GET", "response.status": "304"}, "user": {}, "intrinsic": {}}, -# # ) -# # @override_application_settings(_custom_settings) -# # def test_cat_headers_not_inserted(app): -# # payload = ("1#1", "WebTransaction/Function/app:beep", 0, 1.23, -1, "dd4a810b7cb7f937", False) -# # headers = make_cross_agent_headers(payload, ENCODING_KEY, "1#1") - -# # client_cross_process_id = headers["X-NewRelic-ID"] -# # txn_header = headers["X-NewRelic-Transaction"] - -# # response = app.fetch(f"/304-cat-response/{client_cross_process_id}/{txn_header}") -# # assert response.code == 304 -# # assert "X-NewRelic-App-Data" not in list(response.headers.keys()) - - -# @override_application_settings(_custom_settings) -# @validate_transaction_metrics( -# "_target_application:SimpleHandler.get", rollup_metrics=[("ClientApplication/1#1/all", 1)] -# ) -# @validate_transaction_event_attributes( -# required_params={"agent": [], "user": [], "intrinsic": []}, -# forgone_params={"agent": [], "user": [], "intrinsic": []}, -# exact_attrs={"agent": {}, "user": {}, "intrinsic": {"nr.referringTransactionGuid": "b854df4feb2b1f06"}}, -# ) -# def test_inbound_cat_metrics_and_intrinsics(app): -# payload = ["b854df4feb2b1f06", False, "7e249074f277923d", "5d2957be"] -# headers = make_cross_agent_headers(payload, ENCODING_KEY, "1#1") - -# response = app.fetch("/simple", headers=headers) -# assert response.code == 200 - @validate_transaction_event_attributes( required_params={"agent": (), "user": (), "intrinsic": ()}, diff --git a/tests/messagebroker_pika/test_distributed_tracing.py b/tests/messagebroker_pika/test_distributed_tracing.py index 75dfd17b08..d940441f11 100644 --- a/tests/messagebroker_pika/test_distributed_tracing.py +++ b/tests/messagebroker_pika/test_distributed_tracing.py @@ -31,7 +31,6 @@ "primary_application_id": "12345", "account_id": "33", "trusted_account_key": "1", - # "cross_application_tracer.enabled": True, "distributed_tracing.enabled": True, } @@ -81,8 +80,6 @@ def test_basic_consume_distributed_tracing_headers(): def on_receive(ch, method, properties, msg): headers = properties.headers assert headers - # assert "NewRelicID" not in headers - # assert "NewRelicTransaction" not in headers assert msg == b"Testing distributed_tracing 123" txn = current_transaction() @@ -134,13 +131,10 @@ def do_basic_get(channel, QUEUE): headers = properties.headers assert headers - # assert "NewRelicID" not in headers - # assert "NewRelicTransaction" not in headers assert msg == b"Testing distributed_tracing 123" txn = current_transaction() - # assert txn.client_cross_process_id is None assert txn.client_account_id is None assert txn.client_application_id is None diff --git a/tests/messagebroker_pika/test_pika_produce.py b/tests/messagebroker_pika/test_pika_produce.py index bda5635e89..65495d19cb 100644 --- a/tests/messagebroker_pika/test_pika_produce.py +++ b/tests/messagebroker_pika/test_pika_produce.py @@ -171,10 +171,7 @@ def test_blocking_connection_reply_to(producer): @pytest.mark.parametrize("enable_distributed_tracing", [True, False]) def test_blocking_connection_headers(enable_distributed_tracing): - override_settings = { - "distributed_tracing.enabled": enable_distributed_tracing - # "cross_application_tracer.enabled": not enable_distributed_tracing, - } + override_settings = {"distributed_tracing.enabled": enable_distributed_tracing} rollup_metrics = list(_test_blocking_connection_metrics) if enable_distributed_tracing: rollup_metrics += [ diff --git a/tests/testing_support/external_fixtures.py b/tests/testing_support/external_fixtures.py index 5746cdbcad..62e0863373 100644 --- a/tests/testing_support/external_fixtures.py +++ b/tests/testing_support/external_fixtures.py @@ -16,35 +16,8 @@ from newrelic.api.external_trace import ExternalTrace from newrelic.api.transaction import current_transaction - -# from newrelic.common.encoding_utils import json_encode, obfuscate from newrelic.common.object_wrapper import transient_function_wrapper -# def create_incoming_headers(transaction): -# settings = transaction.settings -# encoding_key = settings.encoding_key - -# headers = [] - -# cross_process_id = "1#2" -# path = "test" -# queue_time = 1.0 -# duration = 2.0 -# read_length = 1024 -# guid = "0123456789012345" -# record_tt = False - -# payload = (cross_process_id, path, queue_time, duration, read_length, guid, record_tt) -# app_data = json_encode(payload) - -# value = obfuscate(app_data, encoding_key) - -# assert isinstance(value, str) - -# headers.append(("X-NewRelic-App-Data", value)) - -# return headers - def validate_synthetics_external_trace_header(synthetics_header, synthetics_info_header): @transient_function_wrapper("newrelic.core.stats_engine", "StatsEngine.record_transaction") @@ -126,17 +99,3 @@ def _bind_params(header, *values): cache[header] = list(values) return wrapped(*args, **kwargs) - - -# @transient_function_wrapper(httplib.__name__, "HTTPResponse.getheaders") -# def insert_incoming_headers(wrapped, instance, args, kwargs): -# transaction = current_transaction() - -# if transaction is None: -# return wrapped(*args, **kwargs) - -# headers = list(wrapped(*args, **kwargs)) - -# headers.extend(create_incoming_headers(transaction)) - -# return headers diff --git a/tests/testing_support/fixtures.py b/tests/testing_support/fixtures.py index 925469731c..8bd5be0b95 100644 --- a/tests/testing_support/fixtures.py +++ b/tests/testing_support/fixtures.py @@ -419,12 +419,6 @@ def catch_background_exceptions(wrapped, instance, args, kwargs): raise_background_exceptions.event.set() -# def make_cross_agent_headers(payload, encoding_key, cat_id): -# value = obfuscate(json_encode(payload), encoding_key) -# id_value = obfuscate(cat_id, encoding_key) -# return {"X-NewRelic-Transaction": value, "X-NewRelic-ID": id_value} - - def make_synthetics_headers( encoding_key, account_id, @@ -790,7 +784,6 @@ def _bind_params(transaction, *args, **kwargs): assert intrinsics["error.class"] == required_attrs["error.class"] assert intrinsics["error.message"].startswith(required_attrs["error.message"]) assert intrinsics["error.expected"] == required_attrs["error.expected"] - # assert intrinsics["nr.transactionGuid"] is not None assert intrinsics["spanId"] is not None # check that transaction event intrinsics haven't bled in @@ -853,12 +846,6 @@ def _validate_event_attributes(intrinsics, user_attributes, required_intrinsics, else: assert "queueDuration" not in intrinsics - # if "nr.referringTransactionGuid" in required_intrinsics: - # guid = required_intrinsics["nr.referringTransactionGuid"] - # assert intrinsics["nr.referringTransactionGuid"] == guid - # else: - # assert "nr.referringTransactionGuid" not in intrinsics - if "nr.syntheticsResourceId" in required_intrinsics: res_id = required_intrinsics["nr.syntheticsResourceId"] job_id = required_intrinsics["nr.syntheticsJobId"] @@ -1039,14 +1026,6 @@ def force_sampled(wrapped, instance, args, kwargs): return wrapped(*args, **kwargs) -# @function_wrapper -# def cat_enabled(wrapped, instance, args, kwargs): -# settings = {"cross_application_tracer.enabled": True, "distributed_tracing.enabled": False} -# wrapped = override_application_settings(settings)(wrapped) - -# return wrapped(*args, **kwargs) - - def override_application_settings(overrides): @function_wrapper def _override_application_settings(wrapped, instance, args, kwargs): diff --git a/tests/testing_support/validators/validate_cross_process_headers.py b/tests/testing_support/validators/validate_cross_process_headers.py index 5f9f82f882..8b64d5e464 100644 --- a/tests/testing_support/validators/validate_cross_process_headers.py +++ b/tests/testing_support/validators/validate_cross_process_headers.py @@ -16,8 +16,6 @@ from newrelic.common.object_wrapper import function_wrapper from testing_support.validators.validate_distributed_tracing_header import validate_distributed_tracing_header -# from testing_support.validators.validate_outbound_headers import validate_outbound_headers - @function_wrapper def validate_cross_process_headers(wrapped, instance, args, kwargs): @@ -28,7 +26,5 @@ def validate_cross_process_headers(wrapped, instance, args, kwargs): if settings.distributed_tracing.enabled: validate_distributed_tracing_header() - # else: - # validate_outbound_headers() return result diff --git a/tests/testing_support/validators/validate_distributed_tracing_header.py b/tests/testing_support/validators/validate_distributed_tracing_header.py index 4015b819e2..962dc63b9c 100644 --- a/tests/testing_support/validators/validate_distributed_tracing_header.py +++ b/tests/testing_support/validators/validate_distributed_tracing_header.py @@ -65,9 +65,6 @@ def validate_distributed_tracing_header(header="newrelic"): # Verify referring transaction information assert len(data["tr"]) == 32 - # if transaction.referring_transaction_guid is not None: - # assert data["tr"] == transaction._trace_id - # else: assert data["tr"].startswith(transaction.guid) assert "pa" not in data diff --git a/tests/testing_support/validators/validate_messagebroker_headers.py b/tests/testing_support/validators/validate_messagebroker_headers.py index f45a47adb4..160c8e9f09 100644 --- a/tests/testing_support/validators/validate_messagebroker_headers.py +++ b/tests/testing_support/validators/validate_messagebroker_headers.py @@ -16,8 +16,6 @@ from newrelic.common.object_wrapper import function_wrapper from testing_support.validators.validate_distributed_tracing_header import validate_distributed_tracing_header -# from testing_support.validators.validate_outbound_headers import validate_outbound_headers - @function_wrapper def validate_messagebroker_headers(wrapped, instance, args, kwargs): @@ -28,7 +26,5 @@ def validate_messagebroker_headers(wrapped, instance, args, kwargs): if settings.distributed_tracing.enabled: validate_distributed_tracing_header() - # else: - # validate_outbound_headers(header_id="NewRelicID", header_transaction="NewRelicTransaction") return result diff --git a/tests/testing_support/validators/validate_synthetics_event.py b/tests/testing_support/validators/validate_synthetics_event.py index dd6fedbb86..5780c34149 100644 --- a/tests/testing_support/validators/validate_synthetics_event.py +++ b/tests/testing_support/validators/validate_synthetics_event.py @@ -42,8 +42,6 @@ def _flatten(event): flat_event = _flatten(event) - # assert "nr.guid" in flat_event, f"name=nr.guid, event={flat_event!r}" - for name, value in required_attrs: assert name in flat_event, f"name={name!r}, event={flat_event!r}" assert flat_event[name] == value, f"name={name!r}, value={value!r}, event={flat_event!r}" From 9d1658721f7024bc54059866f87433f7cb2abdc2 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Fri, 12 Sep 2025 18:46:05 -0700 Subject: [PATCH 32/95] Fix requests test --- tests/external_requests/test_requests.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/external_requests/test_requests.py b/tests/external_requests/test_requests.py index 5e4d8724ac..fdd04db775 100644 --- a/tests/external_requests/test_requests.py +++ b/tests/external_requests/test_requests.py @@ -14,6 +14,7 @@ import pytest import requests +import requests.exceptions from testing_support.external_fixtures import cache_outgoing_headers from testing_support.fixtures import override_application_settings, validate_tt_parenting from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers @@ -120,8 +121,9 @@ def _test(): def test_none_url_get(): try: requests.get(None) + except requests.exceptions.MissingSchema: + pass except TypeError: - # Python 3. pass From f53c517deaeae5f31e4f01b2d841d4633f1ae1cb Mon Sep 17 00:00:00 2001 From: Tim Pansino Date: Mon, 22 Sep 2025 16:22:20 -0700 Subject: [PATCH 33/95] Rename cross_process_headers to distributed_tracing_headers --- tests/external_http/test_http.py | 8 +++---- tests/external_httplib/test_httplib.py | 8 +++---- tests/external_httplib/test_urllib.py | 10 ++++----- tests/external_httplib/test_urllib2.py | 6 ++--- tests/external_httplib2/test_httplib2.py | 8 +++---- tests/external_httpx/test_client.py | 22 +++++++++---------- tests/external_requests/test_requests.py | 8 +++---- tests/external_urllib3/test_urllib3.py | 8 +++---- ...> validate_distributed_tracing_headers.py} | 2 +- 9 files changed, 40 insertions(+), 40 deletions(-) rename tests/testing_support/validators/{validate_cross_process_headers.py => validate_distributed_tracing_headers.py} (93%) diff --git a/tests/external_http/test_http.py b/tests/external_http/test_http.py index 1d5f4f0e1c..0ba4c7d740 100644 --- a/tests/external_http/test_http.py +++ b/tests/external_http/test_http.py @@ -17,7 +17,7 @@ import pytest from testing_support.external_fixtures import cache_outgoing_headers from testing_support.fixtures import override_application_settings -from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers +from testing_support.validators.validate_distributed_tracing_headers import validate_distributed_tracing_headers from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task @@ -71,10 +71,10 @@ def _test(): @pytest.mark.parametrize("distributed_tracing,span_events", ((True, True), (True, False), (False, False))) -def test_http_cross_process_request(distributed_tracing, span_events, server): - @background_task(name="test_http:test_http_cross_process_request") +def test_http_distributed_tracing_request(distributed_tracing, span_events, server): + @background_task(name="test_http:test_http_distributed_tracing_request") @cache_outgoing_headers - @validate_cross_process_headers + @validate_distributed_tracing_headers def _test(): connection = http.client.HTTPConnection("localhost", server.port) connection.request("GET", "/") diff --git a/tests/external_httplib/test_httplib.py b/tests/external_httplib/test_httplib.py index 1103072df4..cf0d42f7b7 100644 --- a/tests/external_httplib/test_httplib.py +++ b/tests/external_httplib/test_httplib.py @@ -19,7 +19,7 @@ import pytest from testing_support.external_fixtures import cache_outgoing_headers from testing_support.fixtures import override_application_settings -from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers +from testing_support.validators.validate_distributed_tracing_headers import validate_distributed_tracing_headers 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_tt_segment_params import validate_tt_segment_params @@ -111,10 +111,10 @@ def _test(): @pytest.mark.parametrize("distributed_tracing,span_events", ((True, True), (True, False), (False, False))) -def test_httplib_cross_process_request(server, distributed_tracing, span_events): - @background_task(name="test_httplib:test_httplib_cross_process_request") +def test_httplib_distributed_tracing_request(server, distributed_tracing, span_events): + @background_task(name="test_httplib:test_httplib_distributed_tracing_request") @cache_outgoing_headers - @validate_cross_process_headers + @validate_distributed_tracing_headers def _test(): connection = httplib.HTTPConnection("localhost", server.port) connection.request("GET", "/") diff --git a/tests/external_httplib/test_urllib.py b/tests/external_httplib/test_urllib.py index aebc870c37..d6cec86e8f 100644 --- a/tests/external_httplib/test_urllib.py +++ b/tests/external_httplib/test_urllib.py @@ -22,7 +22,7 @@ import urllib from testing_support.external_fixtures import cache_outgoing_headers -from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers +from testing_support.validators.validate_distributed_tracing_headers import validate_distributed_tracing_headers from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task @@ -136,8 +136,8 @@ def test_urlopener_file_request(): @SKIP_IF_PYTHON_3_14_OR_ABOVE @background_task() @cache_outgoing_headers -@validate_cross_process_headers -def test_urlopener_cross_process_request(server): +@validate_distributed_tracing_headers +def test_urlopener_distributed_tracing_request(server): opener = urllib.URLopener() opener.open(f"http://localhost:{server.port}/") @@ -175,6 +175,6 @@ def _test(): @background_task() @cache_outgoing_headers -@validate_cross_process_headers -def test_urlretrieve_cross_process_request(server): +@validate_distributed_tracing_headers +def test_urlretrieve_distributed_tracing_request(server): urllib.urlretrieve(f"http://localhost:{server.port}/") diff --git a/tests/external_httplib/test_urllib2.py b/tests/external_httplib/test_urllib2.py index c5478036af..3e23bd7f9f 100644 --- a/tests/external_httplib/test_urllib2.py +++ b/tests/external_httplib/test_urllib2.py @@ -16,7 +16,7 @@ import pytest from testing_support.external_fixtures import cache_outgoing_headers -from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers +from testing_support.validators.validate_distributed_tracing_headers import validate_distributed_tracing_headers from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task @@ -113,6 +113,6 @@ def test_urlopen_file_request(): @background_task() @cache_outgoing_headers -@validate_cross_process_headers -def test_urlopen_cross_process_request(server): +@validate_distributed_tracing_headers +def test_urlopen_distributed_tracing_request(server): urllib2.urlopen(f"http://localhost:{server.port}/") diff --git a/tests/external_httplib2/test_httplib2.py b/tests/external_httplib2/test_httplib2.py index fe531a4b67..007c2dda7d 100644 --- a/tests/external_httplib2/test_httplib2.py +++ b/tests/external_httplib2/test_httplib2.py @@ -16,7 +16,7 @@ import pytest from testing_support.external_fixtures import cache_outgoing_headers from testing_support.fixtures import override_application_settings -from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers +from testing_support.validators.validate_distributed_tracing_headers import validate_distributed_tracing_headers from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task @@ -89,10 +89,10 @@ def _test(): @pytest.mark.parametrize("distributed_tracing,span_events", ((True, True), (True, False), (False, False))) -def test_httplib2_cross_process_request(distributed_tracing, span_events, server): - @background_task(name="test_httplib2:test_httplib2_cross_process_response") +def test_httplib2_distributed_tracing_request(distributed_tracing, span_events, server): + @background_task(name="test_httplib2:test_httplib2_distributed_tracing_response") @cache_outgoing_headers - @validate_cross_process_headers + @validate_distributed_tracing_headers def _test(): connection = httplib2.HTTPConnectionWithTimeout("localhost", server.port) connection.request("GET", "/") diff --git a/tests/external_httpx/test_client.py b/tests/external_httpx/test_client.py index 4347c49f59..54ae997571 100644 --- a/tests/external_httpx/test_client.py +++ b/tests/external_httpx/test_client.py @@ -17,7 +17,7 @@ import pytest from testing_support.fixtures import dt_enabled, override_application_settings, override_generic_settings from testing_support.mock_external_http_server import MockExternalHTTPHResponseHeadersServer -from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers +from testing_support.validators.validate_distributed_tracing_headers import validate_distributed_tracing_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 @@ -103,7 +103,7 @@ def test_async_client(httpx, async_client, mock_server, loop, method): @pytest.mark.parametrize("distributed_tracing,span_events", ((True, True), (True, False), (False, False))) -def test_sync_cross_process_request(httpx, sync_client, mock_server, distributed_tracing, span_events): +def test_sync_distributed_tracing_request(httpx, sync_client, mock_server, distributed_tracing, span_events): global DT_RESPONSE_CODE DT_RESPONSE_CODE = 200 @@ -111,8 +111,8 @@ def test_sync_cross_process_request(httpx, sync_client, mock_server, distributed {"distributed_tracing.enabled": distributed_tracing, "span_events.enabled": span_events} ) @validate_transaction_errors(errors=[]) - @background_task(name="test_sync_cross_process_request") - @validate_cross_process_headers + @background_task(name="test_sync_distributed_tracing_request") + @validate_distributed_tracing_headers def _test(): transaction = current_transaction() @@ -128,9 +128,9 @@ def _test(): @pytest.mark.parametrize("distributed_tracing,span_events", ((True, True), (True, False), (False, False))) @validate_transaction_errors(errors=[]) -@background_task(name="test_async_cross_process_request") -@validate_cross_process_headers -def test_async_cross_process_request(httpx, async_client, mock_server, loop, distributed_tracing, span_events): +@background_task(name="test_async_distributed_tracing_request") +@validate_distributed_tracing_headers +def test_async_distributed_tracing_request(httpx, async_client, mock_server, loop, distributed_tracing, span_events): global DT_RESPONSE_CODE DT_RESPONSE_CODE = 200 @@ -154,8 +154,8 @@ async def _test(): {"distributed_tracing.enabled": True, "span_events.enabled": True} # , "cross_application_tracer.enabled": True} ) @validate_transaction_errors(errors=[]) -@background_task(name="test_sync_cross_process_override_headers") -def test_sync_cross_process_override_headers(httpx, sync_client, mock_server, loop): +@background_task(name="test_sync_distributed_tracing_override_headers") +def test_sync_distributed_tracing_override_headers(httpx, sync_client, mock_server, loop): global DT_RESPONSE_CODE DT_RESPONSE_CODE = 200 @@ -172,8 +172,8 @@ def test_sync_cross_process_override_headers(httpx, sync_client, mock_server, lo @override_application_settings({"distributed_tracing.enabled": True, "span_events.enabled": True}) @validate_transaction_errors(errors=[]) -@background_task(name="test_async_cross_process_override_headers") -def test_async_cross_process_override_headers(httpx, async_client, mock_server, loop): +@background_task(name="test_async_distributed_tracing_override_headers") +def test_async_distributed_tracing_override_headers(httpx, async_client, mock_server, loop): global DT_RESPONSE_CODE DT_RESPONSE_CODE = 200 diff --git a/tests/external_requests/test_requests.py b/tests/external_requests/test_requests.py index fdd04db775..a5fe242077 100644 --- a/tests/external_requests/test_requests.py +++ b/tests/external_requests/test_requests.py @@ -17,7 +17,7 @@ import requests.exceptions from testing_support.external_fixtures import cache_outgoing_headers from testing_support.fixtures import override_application_settings, validate_tt_parenting -from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers +from testing_support.validators.validate_distributed_tracing_headers import validate_distributed_tracing_headers from testing_support.validators.validate_transaction_errors import validate_transaction_errors from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics @@ -153,11 +153,11 @@ def test_wrong_datatype_url_get(): @pytest.mark.parametrize("distributed_tracing,span_events", ((True, True), (True, False), (False, False))) -def test_requests_cross_process_request(distributed_tracing, span_events, server): +def test_requests_distributed_tracing_request(distributed_tracing, span_events, server): @validate_transaction_errors(errors=[]) - @background_task(name="test_requests:test_requests_cross_process_request") + @background_task(name="test_requests:test_requests_distributed_tracing_request") @cache_outgoing_headers - @validate_cross_process_headers + @validate_distributed_tracing_headers def _test(): requests.get(f"http://localhost:{server.port}/") diff --git a/tests/external_urllib3/test_urllib3.py b/tests/external_urllib3/test_urllib3.py index 106f0b96ab..b098296569 100644 --- a/tests/external_urllib3/test_urllib3.py +++ b/tests/external_urllib3/test_urllib3.py @@ -22,7 +22,7 @@ from testing_support.external_fixtures import cache_outgoing_headers from testing_support.fixtures import override_application_settings -from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers +from testing_support.validators.validate_distributed_tracing_headers import validate_distributed_tracing_headers from testing_support.validators.validate_transaction_errors import validate_transaction_errors from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics @@ -202,11 +202,11 @@ def _test(): @pytest.mark.parametrize("distributed_tracing,span_events", ((True, True), (True, False), (False, False))) -def test_urlopen_cross_process_request(distributed_tracing, span_events, server): +def test_urlopen_distributed_tracing_request(distributed_tracing, span_events, server): @validate_transaction_errors(errors=[]) - @background_task(name="test_urllib3:test_urlopen_cross_process_request") + @background_task(name="test_urllib3:test_urlopen_distributed_tracing_request") @cache_outgoing_headers - @validate_cross_process_headers + @validate_distributed_tracing_headers def _test(): pool = urllib3.HTTPConnectionPool(f"localhost:{server.port}") pool.urlopen("GET", "/") diff --git a/tests/testing_support/validators/validate_cross_process_headers.py b/tests/testing_support/validators/validate_distributed_tracing_headers.py similarity index 93% rename from tests/testing_support/validators/validate_cross_process_headers.py rename to tests/testing_support/validators/validate_distributed_tracing_headers.py index 8b64d5e464..08a75e02a7 100644 --- a/tests/testing_support/validators/validate_cross_process_headers.py +++ b/tests/testing_support/validators/validate_distributed_tracing_headers.py @@ -18,7 +18,7 @@ @function_wrapper -def validate_cross_process_headers(wrapped, instance, args, kwargs): +def validate_distributed_tracing_headers(wrapped, instance, args, kwargs): result = wrapped(*args, **kwargs) transaction = current_transaction() From 5a2523a00bb59301edf395eb47ce17e69194cf78 Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 24 Sep 2025 12:19:50 -0700 Subject: [PATCH 34/95] Remove cross agent cat fixtures --- tests/cross_agent/fixtures/cat_map.json | 597 ------------------------ 1 file changed, 597 deletions(-) delete mode 100644 tests/cross_agent/fixtures/cat_map.json diff --git a/tests/cross_agent/fixtures/cat_map.json b/tests/cross_agent/fixtures/cat_map.json deleted file mode 100644 index b91265f44f..0000000000 --- a/tests/cross_agent/fixtures/cat_map.json +++ /dev/null @@ -1,597 +0,0 @@ -[ - { - "name": "new_cat", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/testTxnName", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": [ - "b854df4feb2b1f06", - false, - "7e249074f277923d", - "5d2957be" - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "7e249074f277923d", - "nr.pathHash": "815b96d3", - "nr.referringTransactionGuid": "b854df4feb2b1f06", - "nr.referringPathHash": "5d2957be" - }, - "nonExpectedIntrinsicFields": [ - "nr.alternatePathHashes" - ] - }, - { - "name": "new_cat_path_hash_with_leading_zero", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/txn4", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": [ - "b854df4feb2b1f06", - false, - "7e249074f277923d", - "5d2957be" - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "7e249074f277923d", - "nr.pathHash": "0e258e4e", - "nr.referringTransactionGuid": "b854df4feb2b1f06", - "nr.referringPathHash": "5d2957be" - }, - "nonExpectedIntrinsicFields": [ - "nr.alternatePathHashes" - ] - }, - { - "name": "new_cat_path_hash_with_unicode_name", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/txn\u221a\u221a\u221a", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": [ - "b854df4feb2b1f06", - false, - "7e249074f277923d", - "5d2957be" - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "7e249074f277923d", - "nr.pathHash": "3d015d23", - "nr.referringTransactionGuid": "b854df4feb2b1f06", - "nr.referringPathHash": "5d2957be" - }, - "nonExpectedIntrinsicFields": [ - "nr.alternatePathHashes" - ] - }, - { - "name": "new_cat_no_referring_payload", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/testTxnName", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": null, - "expectedIntrinsicFields": {}, - "nonExpectedIntrinsicFields": [ - "nr.guid", - "nr.tripId", - "nr.pathHash", - "nr.referringTransactionGuid", - "nr.referringPathHash", - "nr.alternatePathHashes" - ] - }, - { - "name": "new_cat_with_call_out", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/testTxnName", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": null, - "outboundRequests": [ - { - "outboundTxnName": "WebTransaction/Custom/testTxnName", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "3b0939af" - ] - } - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "9323dc260548ed0e", - "nr.pathHash": "3b0939af" - }, - "nonExpectedIntrinsicFields": [ - "nr.referringTransactionGuid", - "nr.referringPathHash", - "nr.alternatePathHashes" - ] - }, - { - "name": "new_cat_with_multiple_calls_out", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/testTxnName", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": null, - "outboundRequests": [ - { - "outboundTxnName": "WebTransaction/Custom/otherTxnName", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "f1c8adf5" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/otherTxnName", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "f1c8adf5" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/moreOtherTxnName", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "ea19b61c" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/moreDifferentTxnName", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "e00736cc" - ] - } - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "9323dc260548ed0e", - "nr.pathHash": "3b0939af", - "nr.alternatePathHashes": "e00736cc,ea19b61c,f1c8adf5" - }, - "nonExpectedIntrinsicFields": [ - "nr.referringTransactionGuid", - "nr.referringPathHash" - ] - }, - { - "name": "new_cat_with_many_unique_calls_out", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/testTxnName", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": null, - "outboundRequests": [ - { - "outboundTxnName": "WebTransaction/Custom/txn1", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "93fb4310" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn2", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "a67c2da4" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn3", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "0d932b2b" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn4", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "b4772132" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn5", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "51a1a337" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn6", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "77b5cb70" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn7", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "8a842c7f" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn8", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "b968edb8" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn9", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "2691f90e" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn10", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "b46aec87" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn11", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "10bb3bf3" - ] - } - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "9323dc260548ed0e", - "nr.pathHash": "3b0939af", - "nr.alternatePathHashes": "0d932b2b,2691f90e,51a1a337,77b5cb70,8a842c7f,93fb4310,a67c2da4,b46aec87,b4772132,b968edb8" - }, - "nonExpectedIntrinsicFields": [ - "nr.referringTransactionGuid", - "nr.referringPathHash" - ] - }, - { - "name": "new_cat_with_many_calls_out", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/testTxnName", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": null, - "outboundRequests": [ - { - "outboundTxnName": "WebTransaction/Custom/txn1", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "93fb4310" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn1", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "93fb4310" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn1", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "93fb4310" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn1", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "93fb4310" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn1", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "93fb4310" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn1", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "93fb4310" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn1", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "93fb4310" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn1", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "93fb4310" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn1", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "93fb4310" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn1", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "93fb4310" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn1", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "93fb4310" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn2", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "a67c2da4" - ] - } - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "9323dc260548ed0e", - "nr.pathHash": "3b0939af", - "nr.alternatePathHashes": "93fb4310,a67c2da4" - }, - "nonExpectedIntrinsicFields": [ - "nr.referringTransactionGuid", - "nr.referringPathHash" - ] - }, - { - "name": "new_cat_with_referring_info_and_call_out", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/testTxnName", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": [ - "b854df4feb2b1f06", - false, - "7e249074f277923d", - "5d2957be" - ], - "outboundRequests": [ - { - "outboundTxnName": "WebTransaction/Custom/otherTxnName", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "7e249074f277923d", - "4b9a0289" - ] - } - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "7e249074f277923d", - "nr.pathHash": "815b96d3", - "nr.alternatePathHashes": "4b9a0289", - "nr.referringTransactionGuid": "b854df4feb2b1f06", - "nr.referringPathHash": "5d2957be" - }, - "nonExpectedIntrinsicFields": [] - }, - { - "name": "new_cat_missing_path_hash", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/testTxnName", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": [ - "b854df4feb2b1f06", - false, - "7e249074f277923d" - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "7e249074f277923d", - "nr.pathHash": "3b0939af", - "nr.referringTransactionGuid": "b854df4feb2b1f06" - }, - "nonExpectedIntrinsicFields": [ - "nr.alternatePathHashes", - "nr.referringPathHash" - ] - }, - { - "name": "new_cat_null_path_hash", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/testTxnName", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": [ - "b854df4feb2b1f06", - false, - "7e249074f277923d", - null - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "7e249074f277923d", - "nr.pathHash": "3b0939af", - "nr.referringTransactionGuid": "b854df4feb2b1f06" - }, - "nonExpectedIntrinsicFields": [ - "nr.alternatePathHashes", - "nr.referringPathHash" - ] - }, - { - "name": "new_cat_malformed_path_hash", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/testTxnName", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": [ - "b854df4feb2b1f06", - false, - "7e249074f277923d", - [ - "scrambled", - "eggs" - ] - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "7e249074f277923d", - "nr.pathHash": "3b0939af", - "nr.referringTransactionGuid": "b854df4feb2b1f06" - }, - "nonExpectedIntrinsicFields": [ - "nr.alternatePathHashes", - "nr.referringPathHash" - ] - }, - { - "name": "new_cat_corrupt_path_hash", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/testTxnName", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": [ - "b854df4feb2b1f06", - false, - "7e249074f277923d", - "ZXYQEDABC" - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "7e249074f277923d", - "nr.pathHash": "3b0939af", - "nr.referringTransactionGuid": "b854df4feb2b1f06", - "nr.referringPathHash": "ZXYQEDABC" - }, - "nonExpectedIntrinsicFields": [ - "nr.alternatePathHashes" - ] - }, - { - "name": "new_cat_malformed_trip_id", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/testTxnName", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": [ - "b854df4feb2b1f06", - false, - ["scrambled"], - "5d2957be" - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "9323dc260548ed0e", - "nr.pathHash": "815b96d3", - "nr.referringTransactionGuid": "b854df4feb2b1f06", - "nr.referringPathHash": "5d2957be" - }, - "nonExpectedIntrinsicFields": [ - "nr.alternatePathHashes" - ] - }, - { - "name": "new_cat_missing_trip_id", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/testTxnName", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": [ - "b854df4feb2b1f06", - false - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "9323dc260548ed0e", - "nr.pathHash": "3b0939af", - "nr.referringTransactionGuid": "b854df4feb2b1f06" - }, - "nonExpectedIntrinsicFields": [ - "nr.referringPathHash", - "nr.alternatePathHashes" - ] - }, - { - "name": "new_cat_null_trip_id", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/testTxnName", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": [ - "b854df4feb2b1f06", - false, - null - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "9323dc260548ed0e", - "nr.pathHash": "3b0939af", - "nr.referringTransactionGuid": "b854df4feb2b1f06" - }, - "nonExpectedIntrinsicFields": [ - "nr.alternatePathHashes", - "nr.referringPathHash" - ] - } -] From 6d0688febd214fab75970e9c82f31e70c4ad5e72 Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 24 Sep 2025 12:23:54 -0700 Subject: [PATCH 35/95] Add back tenr.apdexPerfZone as not CAT specific --- newrelic/core/transaction_node.py | 1 + tests/agent_features/test_attributes_in_action.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/newrelic/core/transaction_node.py b/newrelic/core/transaction_node.py index d125c36369..ed12a4e9a8 100644 --- a/newrelic/core/transaction_node.py +++ b/newrelic/core/transaction_node.py @@ -458,6 +458,7 @@ def _add_if_not_empty(key, value): apdex_perf_zone = self.apdex_perf_zone() _add_if_not_empty("apdexPerfZone", apdex_perf_zone) + _add_if_not_empty("nr.apdexPerfZone", apdex_perf_zone) if self.errors: intrinsics["error"] = True diff --git a/tests/agent_features/test_attributes_in_action.py b/tests/agent_features/test_attributes_in_action.py index 3981ef0cd9..da3768aaaa 100644 --- a/tests/agent_features/test_attributes_in_action.py +++ b/tests/agent_features/test_attributes_in_action.py @@ -88,7 +88,16 @@ AGENT_KEYS_ALL = TRACE_ERROR_AGENT_KEYS + REQ_PARAMS -TRANS_EVENT_INTRINSICS = ("name", "duration", "type", "timestamp", "totalTime", "error", "apdexPerfZone") +TRANS_EVENT_INTRINSICS = ( + "name", + "duration", + "type", + "timestamp", + "totalTime", + "error", + "nr.apdexPerfZone", + "apdexPerfZone", +) TRANS_EVENT_AGENT_KEYS = [ "response.status", "request.method", From 7b3623f3def834848f55f201e30003b1de020a49 Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 24 Sep 2025 12:27:28 -0700 Subject: [PATCH 36/95] Remove distributed_trace_key from header mixin --- newrelic/api/header_mixin.py | 1 - newrelic/hooks/messagebroker_pika.py | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/newrelic/api/header_mixin.py b/newrelic/api/header_mixin.py index 22d7299be9..0fdf777735 100644 --- a/newrelic/api/header_mixin.py +++ b/newrelic/api/header_mixin.py @@ -17,7 +17,6 @@ class HeaderMixin: synthetics_key = "X-NewRelic-Synthetics" synthetics_info_key = "X-NewRelic-Synthetics-Info" - distributed_trace_key = "newrelic" settings = None def __enter__(self): diff --git a/newrelic/hooks/messagebroker_pika.py b/newrelic/hooks/messagebroker_pika.py index df7ae01f9e..d246d2c46f 100644 --- a/newrelic/hooks/messagebroker_pika.py +++ b/newrelic/hooks/messagebroker_pika.py @@ -62,7 +62,7 @@ def _add_consume_rabbitmq_trace(transaction, method, properties, nr_start_time, # Do not record dt headers in the segment parameters if headers: - headers.pop(MessageTrace.distributed_trace_key, None) + headers.pop("newrelic", None) headers.pop("traceparent", None) headers.pop("tracestate", None) @@ -122,7 +122,7 @@ def _nr_wrapper_basic_publish(wrapped, instance, args, kwargs): user_headers = properties.headers.copy() # Do not record dt headers in the segment parameters - user_headers.pop(MessageTrace.distributed_trace_key, None) + user_headers.pop("newrelic", None) user_headers.pop("traceparent", None) user_headers.pop("tracestate", None) From 102249cbedf2ad7e701d78330543b10ae25d32cd Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 24 Sep 2025 12:28:47 -0700 Subject: [PATCH 37/95] Remove config instead of commenting out --- newrelic/config.py | 1 - 1 file changed, 1 deletion(-) diff --git a/newrelic/config.py b/newrelic/config.py index 024c97b3a1..50609186d5 100644 --- a/newrelic/config.py +++ b/newrelic/config.py @@ -453,7 +453,6 @@ def _process_configuration(section): _process_setting(section, "debug.disable_harvest_until_shutdown", "getboolean", None) _process_setting(section, "debug.connect_span_stream_in_developer_mode", "getboolean", None) _process_setting(section, "debug.otlp_content_encoding", "get", None) - # _process_setting(section, "cross_application_tracer.enabled", "getboolean", None) _process_setting(section, "message_tracer.segment_parameters_enabled", "getboolean", None) _process_setting(section, "process_host.display_name", "get", None) _process_setting(section, "utilization.detect_aws", "getboolean", None) From d6749079cc555376767415c7f2b14c5454589a71 Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 24 Sep 2025 12:31:15 -0700 Subject: [PATCH 38/95] Put back transactionGuid --- newrelic/core/transaction_node.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/newrelic/core/transaction_node.py b/newrelic/core/transaction_node.py index ed12a4e9a8..3824de9d00 100644 --- a/newrelic/core/transaction_node.py +++ b/newrelic/core/transaction_node.py @@ -522,6 +522,8 @@ def error_event_intrinsics(self, error, stats_table): intrinsics["transactionName"] = self.path intrinsics["spanId"] = error.span_id + intrinsics["nr.transactionGuid"] = self.guid + return intrinsics def _event_intrinsics(self, stats_table): From 0fa69ecf19476ea03f2d687f2ca27d6d8b2f0054 Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 24 Sep 2025 14:11:08 -0700 Subject: [PATCH 39/95] Return None in process_response --- newrelic/api/web_transaction.py | 6 ++-- newrelic/api/wsgi_application.py | 4 +-- newrelic/hooks/framework_aiohttp.py | 51 +++-------------------------- newrelic/hooks/framework_sanic.py | 21 ++---------- 4 files changed, 12 insertions(+), 70 deletions(-) diff --git a/newrelic/api/web_transaction.py b/newrelic/api/web_transaction.py index 71843c214c..4de3bf7c86 100644 --- a/newrelic/api/web_transaction.py +++ b/newrelic/api/web_transaction.py @@ -309,7 +309,7 @@ def process_response(self, status_code, response_headers): """ if not self.enabled: - return [] + return # Extract response headers if response_headers: @@ -329,11 +329,11 @@ def process_response(self, status_code, response_headers): # If response code is 304 do not insert CAT headers. See: # https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5 if self._response_code == 304: - return [] + return None except Exception: pass - return [] + return None def _update_agent_attributes(self): if "accept" in self._request_headers: diff --git a/newrelic/api/wsgi_application.py b/newrelic/api/wsgi_application.py index 2749be9ab5..e0cefc0bef 100644 --- a/newrelic/api/wsgi_application.py +++ b/newrelic/api/wsgi_application.py @@ -634,9 +634,9 @@ def _args(environ, start_response, *args, **kwargs): transaction.set_transaction_name(name, group, priority=1) def _start_response(status, response_headers, *args): - additional_headers = transaction.process_response(status, response_headers, *args) + transaction.process_response(status, response_headers, *args) - _write = start_response(status, response_headers + additional_headers, *args) + _write = start_response(status, response_headers, *args) def write(data): if not transaction._sent_start: diff --git a/newrelic/hooks/framework_aiohttp.py b/newrelic/hooks/framework_aiohttp.py index da0b0029a5..8819dea8f5 100644 --- a/newrelic/hooks/framework_aiohttp.py +++ b/newrelic/hooks/framework_aiohttp.py @@ -17,7 +17,6 @@ from newrelic.api.external_trace import ExternalTrace from newrelic.api.function_trace import function_trace -from newrelic.api.time_trace import notice_error from newrelic.api.transaction import current_transaction, ignore_transaction from newrelic.api.web_transaction import web_transaction from newrelic.common.async_wrapper import async_wrapper, is_coroutine_callable @@ -60,16 +59,8 @@ def _is_expected(exc, value, tb): return _is_expected -def _nr_process_response_proxy(response, transaction): - nr_headers = transaction.process_response(response.status, response.headers) - - response._headers = HeaderProxy(response.headers, nr_headers) - - def _nr_process_response(response, transaction): - nr_headers = transaction.process_response(response.status, response.headers) - - response._headers.update(nr_headers) + transaction.process_response(response.status, response.headers) @function_wrapper @@ -146,20 +137,6 @@ def __getattr__(self, name): return result -def _nr_aiohttp_response_prepare_(wrapped, instance, args, kwargs): - def _bind_params(request): - return request - - request = _bind_params(*args, **kwargs) - - nr_headers = getattr(request, "_nr_headers", None) - if nr_headers: - nr_headers.update(instance.headers) - instance._headers = nr_headers - - return wrapped(*args, **kwargs) - - @function_wrapper def _nr_aiohttp_wrap_middleware_(wrapped, instance, args, kwargs): async def _inner(): @@ -262,24 +239,8 @@ def _nr_aiohttp_request_wrapper_(wrapped, instance, args, kwargs): return wrapped(*args, **kwargs) method, url = _bind_request(*args, **kwargs) - trace = ExternalTrace("aiohttp", str(url), method) - - async def _coro(): - try: - response = await wrapped(*args, **kwargs) - - try: - trace.process_response(status_code=response.status) - except: - pass - - return response - except Exception: - notice_error() - - raise - - return async_wrapper(wrapped)(_coro, trace)() + with ExternalTrace("aiohttp", str(url), method): + return await wrapped(*args, **kwargs)) def instrument_aiohttp_client(module): @@ -346,8 +307,7 @@ async def _coro(*_args, **_kwargs): _nr_process_response(e, transaction) raise except Exception: - nr_headers = transaction.process_response(500, ()) - request._nr_headers = dict(nr_headers) + transaction.process_response(500, ()) raise _nr_process_response(response, transaction) @@ -371,6 +331,3 @@ def instrument_aiohttp_web(module): def instrument_aiohttp_wsgi(module): wrap_function_wrapper(module, "WsgiResponse.__init__", _nr_aiohttp_wrap_wsgi_response_) - -def instrument_aiohttp_web_response(module): - wrap_function_wrapper(module, "Response.prepare", _nr_aiohttp_response_prepare_) diff --git a/newrelic/hooks/framework_sanic.py b/newrelic/hooks/framework_sanic.py index a201cba5a0..3738bd6180 100644 --- a/newrelic/hooks/framework_sanic.py +++ b/newrelic/hooks/framework_sanic.py @@ -170,12 +170,7 @@ def _nr_sanic_response_get_headers(wrapped, instance, args, kwargs): return result # instance is the response object - dt_headers = transaction.process_response(str(instance.status), instance.headers.items()) - - for header_name, header_value in dt_headers: - if header_name not in instance.headers: - instance.headers[header_name] = header_value - + transaction.process_response(str(instance.status), instance.headers.items()) return wrapped(*args, **kwargs) @@ -189,12 +184,7 @@ async def _nr_sanic_response_send(wrapped, instance, args, kwargs): return result # instance is the response object - dt_headers = transaction.process_response(str(instance.status), instance.headers.items()) - - for header_name, header_value in dt_headers: - if header_name not in instance.headers: - instance.headers[header_name] = header_value - + transaction.process_response(str(instance.status), instance.headers.items()) return result @@ -205,12 +195,7 @@ def _nr_sanic_response_parse_headers(wrapped, instance, args, kwargs): return wrapped(*args, **kwargs) # instance is the response object - dt_headers = transaction.process_response(str(instance.status), instance.headers.items()) - - for header_name, header_value in dt_headers: - if header_name not in instance.headers: - instance.headers[header_name] = header_value - + transaction.process_response(str(instance.status), instance.headers.items()) return wrapped(*args, **kwargs) From 7f3fbd58bbeb7497728673ef04293aed032cf824 Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 24 Sep 2025 12:55:01 -0700 Subject: [PATCH 40/95] Still pass settings into finalize application settings call --- newrelic/core/agent_protocol.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/newrelic/core/agent_protocol.py b/newrelic/core/agent_protocol.py index 347bdf5e2a..3544fd0032 100644 --- a/newrelic/core/agent_protocol.py +++ b/newrelic/core/agent_protocol.py @@ -522,7 +522,7 @@ def finalize(self): @classmethod def connect(cls, app_name, linked_applications, environment, settings, client_cls=ServerlessModeClient): aws_lambda_metadata = settings.aws_lambda_metadata - settings = finalize_application_settings() + settings = finalize_application_settings(settings=settings) # Metadata must come from the original settings object since it # can be modified later settings.aws_lambda_metadata = aws_lambda_metadata From 14d514b7705593f3b72388676cc0a5ab757b0d35 Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 24 Sep 2025 14:28:50 -0700 Subject: [PATCH 41/95] DT_RESPONSE_CODE->RESPONSE_CODE --- tests/external_httpx/test_client.py | 64 ++++++++++++++--------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/tests/external_httpx/test_client.py b/tests/external_httpx/test_client.py index 54ae997571..994f1360b4 100644 --- a/tests/external_httpx/test_client.py +++ b/tests/external_httpx/test_client.py @@ -30,15 +30,15 @@ SCOPED_METRICS = [] ROLLUP_METRICS = [("External/all", 2), ("External/allOther", 2)] -DT_RESPONSE_CODE = None +RESPONSE_CODE = None def dt_response_handler(self): - if not DT_RESPONSE_CODE: - raise ValueError("DT_RESPONSE_CODE must be a valid status_code.") + if not RESPONSE_CODE: + raise ValueError("RESPONSE_CODE must be a valid status_code.") response = str(self.headers).encode("utf-8") # Might need to put headers here - self.send_response(DT_RESPONSE_CODE) + self.send_response(RESPONSE_CODE) self.end_headers() self.wfile.write(response) @@ -72,8 +72,8 @@ def exercise_sync_client(server, client, method, protocol="http"): ) @background_task(name="test_sync_client") def test_sync_client(httpx, sync_client, mock_server, method): - global DT_RESPONSE_CODE - DT_RESPONSE_CODE = 200 + global RESPONSE_CODE + RESPONSE_CODE = 200 assert exercise_sync_client(mock_server, sync_client, method).status_code == 200 @@ -95,8 +95,8 @@ async def exercise_async_client(server, client, method, protocol="http"): ) @background_task(name="test_async_client") def test_async_client(httpx, async_client, mock_server, loop, method): - global DT_RESPONSE_CODE - DT_RESPONSE_CODE = 200 + global RESPONSE_CODE + RESPONSE_CODE = 200 responses = loop.run_until_complete(exercise_async_client(mock_server, async_client, method)) assert all(response.status_code == 200 for response in responses) @@ -104,8 +104,8 @@ def test_async_client(httpx, async_client, mock_server, loop, method): @pytest.mark.parametrize("distributed_tracing,span_events", ((True, True), (True, False), (False, False))) def test_sync_distributed_tracing_request(httpx, sync_client, mock_server, distributed_tracing, span_events): - global DT_RESPONSE_CODE - DT_RESPONSE_CODE = 200 + global RESPONSE_CODE + RESPONSE_CODE = 200 @override_application_settings( {"distributed_tracing.enabled": distributed_tracing, "span_events.enabled": span_events} @@ -131,8 +131,8 @@ def _test(): @background_task(name="test_async_distributed_tracing_request") @validate_distributed_tracing_headers def test_async_distributed_tracing_request(httpx, async_client, mock_server, loop, distributed_tracing, span_events): - global DT_RESPONSE_CODE - DT_RESPONSE_CODE = 200 + global RESPONSE_CODE + RESPONSE_CODE = 200 @override_application_settings( {"distributed_tracing.enabled": distributed_tracing, "span_events.enabled": span_events} @@ -156,8 +156,8 @@ async def _test(): @validate_transaction_errors(errors=[]) @background_task(name="test_sync_distributed_tracing_override_headers") def test_sync_distributed_tracing_override_headers(httpx, sync_client, mock_server, loop): - global DT_RESPONSE_CODE - DT_RESPONSE_CODE = 200 + global RESPONSE_CODE + RESPONSE_CODE = 200 transaction = current_transaction() @@ -174,8 +174,8 @@ def test_sync_distributed_tracing_override_headers(httpx, sync_client, mock_serv @validate_transaction_errors(errors=[]) @background_task(name="test_async_distributed_tracing_override_headers") def test_async_distributed_tracing_override_headers(httpx, async_client, mock_server, loop): - global DT_RESPONSE_CODE - DT_RESPONSE_CODE = 200 + global RESPONSE_CODE + RESPONSE_CODE = 200 async def _test(): async with async_client: @@ -191,8 +191,8 @@ async def _test(): @dt_enabled def test_sync_client_event_hook_exception(httpx, mock_server): - global DT_RESPONSE_CODE - DT_RESPONSE_CODE = 500 + global RESPONSE_CODE + RESPONSE_CODE = 500 def exception_event_hook(response): if response.status_code >= 400: @@ -204,7 +204,7 @@ def empty_hook(response): @validate_span_events( count=1, exact_intrinsics={"name": f"External/localhost:{mock_server.port}/httpx/GET"}, - exact_agents={"http.statusCode": DT_RESPONSE_CODE}, + exact_agents={"http.statusCode": RESPONSE_CODE}, ) @background_task(name="test_sync_client_event_hook_exception") def make_request(client, exc_expected=True): @@ -237,8 +237,8 @@ def make_request(client, exc_expected=True): @override_application_settings({"distributed_tracing.enabled": True, "span_events.enabled": True}) def test_async_client_event_hook_exception(httpx, mock_server, loop): - global DT_RESPONSE_CODE - DT_RESPONSE_CODE = 500 + global RESPONSE_CODE + RESPONSE_CODE = 500 def exception_event_hook(response): if response.status_code >= 400: @@ -250,7 +250,7 @@ def empty_hook(response): @validate_span_events( count=1, exact_intrinsics={"name": f"External/localhost:{mock_server.port}/httpx/GET"}, - exact_agents={"http.statusCode": DT_RESPONSE_CODE}, + exact_agents={"http.statusCode": RESPONSE_CODE}, ) @background_task(name="test_sync_client_event_hook_exception") def make_request(client, exc_expected=True): @@ -287,8 +287,8 @@ def _test(): @override_generic_settings(global_settings(), {"enabled": False}) def test_sync_nr_disabled(httpx, mock_server): - global DT_RESPONSE_CODE - DT_RESPONSE_CODE = 200 + global RESPONSE_CODE + RESPONSE_CODE = 200 with httpx.Client() as client: trace = current_trace() @@ -300,8 +300,8 @@ def test_sync_nr_disabled(httpx, mock_server): @override_generic_settings(global_settings(), {"enabled": False}) def test_async_nr_disabled(httpx, mock_server, loop): - global DT_RESPONSE_CODE - DT_RESPONSE_CODE = 200 + global RESPONSE_CODE + RESPONSE_CODE = 200 async def _test(): async with httpx.AsyncClient() as client: @@ -317,8 +317,8 @@ async def _test(): @pytest.mark.parametrize("client", ("Client", "AsyncClient")) def test_invalid_import_order_client(monkeypatch, httpx, mock_server, loop, client): - global DT_RESPONSE_CODE - DT_RESPONSE_CODE = 200 + global RESPONSE_CODE + RESPONSE_CODE = 200 if "Async" in client: is_async = True @@ -349,8 +349,8 @@ def test_invalid_import_order_client(monkeypatch, httpx, mock_server, loop, clie ) @background_task(name="test_sync_client_http2") def test_sync_client_http2(httpx, real_server): - global DT_RESPONSE_CODE - DT_RESPONSE_CODE = 200 + global RESPONSE_CODE + RESPONSE_CODE = 200 client = httpx.Client(http1=False, http2=True, verify=False) response = exercise_sync_client(real_server, client, "get", protocol="https") @@ -364,8 +364,8 @@ def test_sync_client_http2(httpx, real_server): ) @background_task(name="test_async_client_http2") def test_async_client_http2(httpx, real_server, loop): - global DT_RESPONSE_CODE - DT_RESPONSE_CODE = 200 + global RESPONSE_CODE + RESPONSE_CODE = 200 client = httpx.AsyncClient(http1=False, http2=True, verify=False) From a68e823f486393691f0ab1fe93266aab58e9e2b6 Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 24 Sep 2025 14:32:29 -0700 Subject: [PATCH 42/95] respond_with_dt_header->response_handler --- tests/framework_aiohttp/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/framework_aiohttp/conftest.py b/tests/framework_aiohttp/conftest.py index 1cdf4c607a..108778b44b 100644 --- a/tests/framework_aiohttp/conftest.py +++ b/tests/framework_aiohttp/conftest.py @@ -115,7 +115,7 @@ def handler(self): def mock_external_http_server(): response_values = [] - def respond_with_dt_header(self): + def response_handler(self): headers, response_code = response_values.pop() self.send_response(response_code) for header, value in headers: @@ -123,7 +123,7 @@ def respond_with_dt_header(self): self.end_headers() self.wfile.write(b"") - with MockExternalHTTPServer(handler=respond_with_dt_header) as server: + with MockExternalHTTPServer(handler=response_handler) as server: yield (server, response_values) From 693de1740977c4c1c36094618cbc08e3b5d625de Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 24 Sep 2025 14:36:22 -0700 Subject: [PATCH 43/95] Fixup: syntax error --- newrelic/hooks/framework_aiohttp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/newrelic/hooks/framework_aiohttp.py b/newrelic/hooks/framework_aiohttp.py index 8819dea8f5..ee70aa258d 100644 --- a/newrelic/hooks/framework_aiohttp.py +++ b/newrelic/hooks/framework_aiohttp.py @@ -240,7 +240,7 @@ def _nr_aiohttp_request_wrapper_(wrapped, instance, args, kwargs): method, url = _bind_request(*args, **kwargs) with ExternalTrace("aiohttp", str(url), method): - return await wrapped(*args, **kwargs)) + return await wrapped(*args, **kwargs) def instrument_aiohttp_client(module): From 6510cc14d59ca2a021f4273fad96e8ab9e93389d Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 24 Sep 2025 14:41:34 -0700 Subject: [PATCH 44/95] Put back nr.guid if synthetics resource id --- newrelic/core/transaction_node.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/newrelic/core/transaction_node.py b/newrelic/core/transaction_node.py index 3824de9d00..11740465e3 100644 --- a/newrelic/core/transaction_node.py +++ b/newrelic/core/transaction_node.py @@ -463,6 +463,8 @@ def _add_if_not_empty(key, value): if self.errors: intrinsics["error"] = True + if self.synthetics_resource_id: + intrinsics["nr.guid"] = self.guid if self.parent_tx: intrinsics["parentId"] = self.parent_tx From ddd584e81a553173132dadfa83f7eb67e087a8ba Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Tue, 9 Sep 2025 12:53:56 -0700 Subject: [PATCH 45/95] Remove cross_application_tracer.enabled setting --- newrelic/api/cat_header_mixin.py | 74 +++--- newrelic/api/message_transaction.py | 8 +- newrelic/api/transaction.py | 117 +++++----- newrelic/config.py | 18 +- newrelic/core/agent_protocol.py | 2 +- newrelic/core/config.py | 8 +- newrelic/hooks/application_celery.py | 20 +- tests/agent_features/test_cat.py | 102 --------- tests/agent_features/test_serverless_mode.py | 2 +- tests/agent_unittests/test_agent_protocol.py | 4 +- tests/cross_agent/test_cat_map.py | 211 ------------------ 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 | 160 ++++++------- tests/external_requests/test_requests.py | 2 +- tests/external_urllib3/test_urllib3.py | 2 +- tests/framework_aiohttp/test_client_cat.py | 36 +-- tests/framework_aiohttp/test_server_cat.py | 2 +- .../framework_sanic/test_cross_application.py | 2 +- tests/framework_tornado/test_externals.py | 14 +- tests/framework_tornado/test_inbound_cat.py | 2 +- .../test_distributed_tracing.py | 2 +- tests/messagebroker_pika/test_pika_produce.py | 2 +- 24 files changed, 242 insertions(+), 554 deletions(-) delete mode 100644 tests/agent_features/test_cat.py delete mode 100644 tests/cross_agent/test_cat_map.py diff --git a/newrelic/api/cat_header_mixin.py b/newrelic/api/cat_header_mixin.py index f4a3e02bc9..b905f9dc80 100644 --- a/newrelic/api/cat_header_mixin.py +++ b/newrelic/api/cat_header_mixin.py @@ -15,7 +15,7 @@ from newrelic.common.encoding_utils import ( base64_decode, base64_encode, - deobfuscate, + # deobfuscate, json_decode, json_encode, obfuscate, @@ -39,35 +39,35 @@ def __enter__(self): self.settings = self.transaction.settings or None return result - def process_response_headers(self, response_headers): - """ - Decode the response headers and create appropriate metrics based on the - header values. The response_headers are passed in as a list of tuples. - [(HEADER_NAME0, HEADER_VALUE0), (HEADER_NAME1, HEADER_VALUE1)] + # def process_response_headers(self, response_headers): + # """ + # Decode the response headers and create appropriate metrics based on the + # header values. The response_headers are passed in as a list of tuples. + # [(HEADER_NAME0, HEADER_VALUE0), (HEADER_NAME1, HEADER_VALUE1)] - """ + # """ - settings = self.settings - if not settings: - return + # settings = self.settings + # if not settings: + # return - if not settings.cross_application_tracer.enabled: - return + # if not settings.cross_application_tracer.enabled: + # return - appdata = None - try: - for k, v in response_headers: - if k.upper() == self.cat_appdata_key.upper(): - appdata = json_decode(deobfuscate(v, settings.encoding_key)) - break + # appdata = None + # try: + # for k, v in response_headers: + # if k.upper() == self.cat_appdata_key.upper(): + # appdata = json_decode(deobfuscate(v, settings.encoding_key)) + # break - if appdata: - self.params["cross_process_id"] = appdata[0] - self.params["external_txn_name"] = appdata[1] - self.params["transaction_guid"] = appdata[5] + # if appdata: + # self.params["cross_process_id"] = appdata[0] + # self.params["external_txn_name"] = appdata[1] + # self.params["transaction_guid"] = appdata[5] - except Exception: - pass + # except Exception: + # pass def process_response_metadata(self, cat_linking_value): payload = base64_decode(cat_linking_value) @@ -92,19 +92,19 @@ def generate_request_headers(cls, transaction): if settings.distributed_tracing.enabled: transaction.insert_distributed_trace_headers(nr_headers) - elif settings.cross_application_tracer.enabled: - transaction.is_part_of_cat = True - path_hash = transaction.path_hash - if path_hash is None: - # Disable cat if path_hash fails to generate. - transaction.is_part_of_cat = False - else: - encoded_cross_process_id = obfuscate(settings.cross_process_id, settings.encoding_key) - nr_headers.append((cls.cat_id_key, encoded_cross_process_id)) - - transaction_data = [transaction.guid, transaction.record_tt, transaction.trip_id, path_hash] - encoded_transaction = obfuscate(json_encode(transaction_data), settings.encoding_key) - nr_headers.append((cls.cat_transaction_key, encoded_transaction)) + # elif settings.cross_application_tracer.enabled: + # transaction.is_part_of_cat = True + # path_hash = transaction.path_hash + # if path_hash is None: + # # Disable cat if path_hash fails to generate. + # transaction.is_part_of_cat = False + # else: + # encoded_cross_process_id = obfuscate(settings.cross_process_id, settings.encoding_key) + # nr_headers.append((cls.cat_id_key, encoded_cross_process_id)) + + # transaction_data = [transaction.guid, transaction.record_tt, transaction.trip_id, path_hash] + # encoded_transaction = obfuscate(json_encode(transaction_data), settings.encoding_key) + # nr_headers.append((cls.cat_transaction_key, encoded_transaction)) if transaction.synthetics_header: nr_headers.append((cls.cat_synthetics_key, transaction.synthetics_header)) diff --git a/newrelic/api/message_transaction.py b/newrelic/api/message_transaction.py index 0c94b83fbb..f37bdf8070 100644 --- a/newrelic/api/message_transaction.py +++ b/newrelic/api/message_transaction.py @@ -47,10 +47,10 @@ def __init__( if headers is not None and self.settings is not None: if self.settings.distributed_tracing.enabled: self.accept_distributed_trace_headers(headers, transport_type=transport_type) - elif self.settings.cross_application_tracer.enabled: - self._process_incoming_cat_headers( - headers.pop(MessageTrace.cat_id_key, None), headers.pop(MessageTrace.cat_transaction_key, None) - ) + # elif self.settings.cross_application_tracer.enabled: + # self._process_incoming_cat_headers( + # headers.pop(MessageTrace.cat_id_key, None), headers.pop(MessageTrace.cat_transaction_key, None) + # ) self.routing_key = routing_key self.exchange_type = exchange_type diff --git a/newrelic/api/transaction.py b/newrelic/api/transaction.py index d856982a1b..96fd181945 100644 --- a/newrelic/api/transaction.py +++ b/newrelic/api/transaction.py @@ -1339,64 +1339,65 @@ def accept_distributed_trace_headers(self, headers, transport_type="HTTP"): # metric for the lack of payload/distributed_header self._accept_distributed_trace_payload(distributed_header, transport_type) - def _process_incoming_cat_headers(self, encoded_cross_process_id, encoded_txn_header): - settings = self._settings - - if not self.enabled: - return - - if not ( - settings.cross_application_tracer.enabled - and settings.cross_process_id - and settings.trusted_account_ids - and settings.encoding_key - ): - return - - if encoded_cross_process_id is None: - return - - try: - client_cross_process_id = deobfuscate(encoded_cross_process_id, settings.encoding_key) - - # The cross process ID consists of the client - # account ID and the ID of the specific application - # the client is recording requests against. We need - # to validate that the client account ID is in the - # list of trusted account IDs and ignore it if it - # isn't. The trusted account IDs list has the - # account IDs as integers, so save the client ones - # away as integers here so easier to compare later. - - client_account_id, client_application_id = map(int, client_cross_process_id.split("#")) - - if client_account_id not in settings.trusted_account_ids: - return - - self.client_cross_process_id = client_cross_process_id - self.client_account_id = client_account_id - self.client_application_id = client_application_id - - txn_header = json_decode(deobfuscate(encoded_txn_header, settings.encoding_key)) - - if txn_header: - self.is_part_of_cat = True - self.referring_transaction_guid = txn_header[0] - - # Incoming record_tt is OR'd with existing - # record_tt. In the scenario where we make multiple - # ext request, this will ensure we don't set the - # record_tt to False by a later request if it was - # set to True by an earlier request. - - self.record_tt = self.record_tt or txn_header[1] - - if isinstance(txn_header[2], str): - self._trip_id = txn_header[2] - if isinstance(txn_header[3], str): - self._referring_path_hash = txn_header[3] - except Exception: - pass + # def _process_incoming_cat_headers(self, encoded_cross_process_id, encoded_txn_header): + # settings = self._settings + + # if not self.enabled: + # return + + # If CAT is disabled, function will exit early. + # if not ( + # settings.cross_application_tracer.enabled + # and settings.cross_process_id + # and settings.trusted_account_ids + # and settings.encoding_key + # ): + # return + + # if encoded_cross_process_id is None: + # return + + # try: + # client_cross_process_id = deobfuscate(encoded_cross_process_id, settings.encoding_key) + + # # The cross process ID consists of the client + # # account ID and the ID of the specific application + # # the client is recording requests against. We need + # # to validate that the client account ID is in the + # # list of trusted account IDs and ignore it if it + # # isn't. The trusted account IDs list has the + # # account IDs as integers, so save the client ones + # # away as integers here so easier to compare later. + + # client_account_id, client_application_id = map(int, client_cross_process_id.split("#")) + + # if client_account_id not in settings.trusted_account_ids: + # return + + # self.client_cross_process_id = client_cross_process_id + # self.client_account_id = client_account_id + # self.client_application_id = client_application_id + + # txn_header = json_decode(deobfuscate(encoded_txn_header, settings.encoding_key)) + + # if txn_header: + # self.is_part_of_cat = True + # self.referring_transaction_guid = txn_header[0] + + # # Incoming record_tt is OR'd with existing + # # record_tt. In the scenario where we make multiple + # # ext request, this will ensure we don't set the + # # record_tt to False by a later request if it was + # # set to True by an earlier request. + + # self.record_tt = self.record_tt or txn_header[1] + + # if isinstance(txn_header[2], str): + # self._trip_id = txn_header[2] + # if isinstance(txn_header[3], str): + # self._referring_path_hash = txn_header[3] + # except Exception: + # pass def _generate_response_headers(self, read_length=None): nr_headers = [] diff --git a/newrelic/config.py b/newrelic/config.py index efcfeb48b5..8246e10e78 100644 --- a/newrelic/config.py +++ b/newrelic/config.py @@ -453,7 +453,7 @@ def _process_configuration(section): _process_setting(section, "debug.disable_harvest_until_shutdown", "getboolean", None) _process_setting(section, "debug.connect_span_stream_in_developer_mode", "getboolean", None) _process_setting(section, "debug.otlp_content_encoding", "get", None) - _process_setting(section, "cross_application_tracer.enabled", "getboolean", None) + # _process_setting(section, "cross_application_tracer.enabled", "getboolean", None) _process_setting(section, "message_tracer.segment_parameters_enabled", "getboolean", None) _process_setting(section, "process_host.display_name", "get", None) _process_setting(section, "utilization.detect_aws", "getboolean", None) @@ -711,14 +711,14 @@ def translate_deprecated_settings(settings, cached_settings): "attributes.exclude." ) - if "cross_application_tracer.enabled" in cached: - # CAT Deprecation Warning - _logger.info( - "Deprecated setting found: cross_application_tracer.enabled. Please replace Cross Application Tracing " - "(CAT) with the newer Distributed Tracing by setting 'distributed_tracing.enabled' to True in your agent " - "configuration. For further details on distributed tracing, please refer to our documentation: " - "https://docs.newrelic.com/docs/distributed-tracing/concepts/distributed-tracing-planning-guide/#changes." - ) + # if "cross_application_tracer.enabled" in cached: + # # CAT Deprecation Warning + # _logger.info( + # "Deprecated setting found: cross_application_tracer.enabled. Please replace Cross Application Tracing " + # "(CAT) with the newer Distributed Tracing by setting 'distributed_tracing.enabled' to True in your agent " + # "configuration. For further details on distributed tracing, please refer to our documentation: " + # "https://docs.newrelic.com/docs/distributed-tracing/concepts/distributed-tracing-planning-guide/#changes." + # ) return settings diff --git a/newrelic/core/agent_protocol.py b/newrelic/core/agent_protocol.py index de0cab678b..7570dd00e2 100644 --- a/newrelic/core/agent_protocol.py +++ b/newrelic/core/agent_protocol.py @@ -522,7 +522,7 @@ def finalize(self): @classmethod def connect(cls, app_name, linked_applications, environment, settings, client_cls=ServerlessModeClient): aws_lambda_metadata = settings.aws_lambda_metadata - settings = finalize_application_settings({"cross_application_tracer.enabled": False}, settings) + # settings = finalize_application_settings({"cross_application_tracer.enabled": False}, settings) # Metadata must come from the original settings object since it # can be modified later settings.aws_lambda_metadata = aws_lambda_metadata diff --git a/newrelic/core/config.py b/newrelic/core/config.py index eebc598877..d2ad5be74e 100644 --- a/newrelic/core/config.py +++ b/newrelic/core/config.py @@ -256,8 +256,8 @@ class DebugSettings(Settings): pass -class CrossApplicationTracerSettings(Settings): - pass +# class CrossApplicationTracerSettings(Settings): +# pass class TransactionEventsSettings(Settings): @@ -497,7 +497,7 @@ class EventHarvestConfigHarvestLimitSettings(Settings): _settings.browser_monitoring.attributes = BrowserMonitorAttributesSettings() _settings.code_level_metrics = CodeLevelMetricsSettings() _settings.console = ConsoleSettings() -_settings.cross_application_tracer = CrossApplicationTracerSettings() +# _settings.cross_application_tracer = CrossApplicationTracerSettings() _settings.custom_insights_events = CustomInsightsEventsSettings() _settings.ml_insights_events = MlInsightsEventsSettings() _settings.datastore_tracer = DatastoreTracerSettings() @@ -808,7 +808,7 @@ def default_otlp_host(host): _settings.attributes.include = [] _settings.thread_profiler.enabled = True -_settings.cross_application_tracer.enabled = False +# _settings.cross_application_tracer.enabled = False _settings.gc_runtime_metrics.enabled = _environ_as_bool("NEW_RELIC_GC_RUNTIME_METRICS_ENABLED", default=False) _settings.gc_runtime_metrics.top_object_count_limit = 5 diff --git a/newrelic/hooks/application_celery.py b/newrelic/hooks/application_celery.py index e5856141f0..6f25bbbf57 100644 --- a/newrelic/hooks/application_celery.py +++ b/newrelic/hooks/application_celery.py @@ -127,11 +127,11 @@ def wrapper(wrapped, instance, args, kwargs): headers.update(dict(dt_headers)) except Exception: pass - elif transaction.settings.cross_application_tracer.enabled: - transaction._process_incoming_cat_headers( - headers.get(MessageTrace.cat_id_key, None), - headers.get(MessageTrace.cat_transaction_key, None), - ) + # elif transaction.settings.cross_application_tracer.enabled: + # transaction._process_incoming_cat_headers( + # headers.get(MessageTrace.cat_id_key, None), + # headers.get(MessageTrace.cat_transaction_key, None), + # ) except Exception: pass @@ -247,11 +247,11 @@ def wrap_task_call(wrapped, instance, args, kwargs): headers.update(dict(dt_headers)) except Exception: pass - elif transaction.settings.cross_application_tracer.enabled: - transaction._process_incoming_cat_headers( - headers.get(MessageTrace.cat_id_key, None), - headers.get(MessageTrace.cat_transaction_key, None), - ) + # elif transaction.settings.cross_application_tracer.enabled: + # transaction._process_incoming_cat_headers( + # headers.get(MessageTrace.cat_id_key, None), + # headers.get(MessageTrace.cat_transaction_key, None), + # ) except Exception: pass diff --git a/tests/agent_features/test_cat.py b/tests/agent_features/test_cat.py deleted file mode 100644 index 41c7b0d6ae..0000000000 --- a/tests/agent_features/test_cat.py +++ /dev/null @@ -1,102 +0,0 @@ -# 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. - -""" -This file contains a special case test for CAT. Most CAT testing is found at -`tests/cross_agent/test_cat_map.py` and -`newrelic/api/tests/test_cross_process.py`. This test does not fit either of -those spaces, the former being reserved for cross agent testing and the latter -being a unittest for the `process_response` method. Since this is a more end to -end style test, it does not fit as a unittest. -""" - -import pytest -import webtest -from testing_support.fixtures import cat_enabled, make_cross_agent_headers, override_application_settings - -from newrelic.api.background_task import background_task -from newrelic.api.external_trace import ExternalTrace -from newrelic.api.wsgi_application import wsgi_application - -ENCODING_KEY = "1234567890123456789012345678901234567890" - - -@wsgi_application() -def target_wsgi_application(environ, start_response): - status_code = int(environ["PATH_INFO"].strip("/")) - status = f"{status_code} STATUS" - - if status_code == 304: - output = b"" - response_headers = [] - else: - output = b"hello world" - response_headers = [("Content-type", "text/html; charset=utf-8"), ("Content-Length", str(len(output)))] - start_response(status, response_headers) - - return [output] - - -test_application = webtest.TestApp(target_wsgi_application) - -_override_settings = { - "cross_process_id": "1#1", - "encoding_key": ENCODING_KEY, - "trusted_account_ids": [1], - "browser_monitoring.enabled": False, -} - -payload = ["b854df4feb2b1f06", False, "7e249074f277923d", "5d2957be"] - - -@cat_enabled -@override_application_settings(_override_settings) -def test_cat_disabled_browser_monitoring(): - headers = make_cross_agent_headers(payload, ENCODING_KEY, "1#1") - response = test_application.get("/200", headers=headers) - assert "X-NewRelic-App-Data" in response.headers - - -@override_application_settings(_override_settings) -def test_cat_insertion_disabled_on_304(): - headers = make_cross_agent_headers(payload, ENCODING_KEY, "1#1") - response = test_application.get("/304", headers=headers) - assert "X-NewRelic-App-Data" not in response.headers - - -_override_settings = {"cross_application_tracer.enabled": True, "distributed_tracing.enabled": False} - - -@cat_enabled -@override_application_settings(_override_settings) -@pytest.mark.parametrize("fips_enabled", (False, True)) -@background_task() -def test_cat_fips_compliance(monkeypatch, fips_enabled): - # Set md5 to raise a ValueError to simulate FIPS compliance issues. - def md5_crash(*args, **kwargs): - raise ValueError - - if fips_enabled: - # monkeypatch.setattr("hashlib.md5", md5_crash) - import hashlib - - monkeypatch.setattr(hashlib, "md5", md5_crash) - - # Generate and send request using actual transaction api instead of fixture. - # Otherwise the proper code paths are not exercised. - with ExternalTrace("cat_test", "http://localhost/200") as tracer: - headers = tracer.generate_request_headers(tracer.transaction) - - expected = not fips_enabled # Invert to make more human readable - assert ("X-NewRelic-Transaction" in dict(headers)) == expected diff --git a/tests/agent_features/test_serverless_mode.py b/tests/agent_features/test_serverless_mode.py index 9c705c5c24..8a05db6fe1 100644 --- a/tests/agent_features/test_serverless_mode.py +++ b/tests/agent_features/test_serverless_mode.py @@ -78,7 +78,7 @@ def _test_cat_headers(): with trace: trace.process_response_headers(response_headers) - assert transaction.settings.cross_application_tracer.enabled is False + # assert transaction.settings.cross_application_tracer.enabled is False _test_cat_headers() diff --git a/tests/agent_unittests/test_agent_protocol.py b/tests/agent_unittests/test_agent_protocol.py index f87f48f7f6..590cad66f8 100644 --- a/tests/agent_unittests/test_agent_protocol.py +++ b/tests/agent_unittests/test_agent_protocol.py @@ -488,8 +488,8 @@ def test_serverless_protocol_connect(): # No client calls should be made assert len(HttpClientRecorder.SENT) == 0 - # cross application tracing must be disabled - assert not protocol.configuration.cross_application_tracer.enabled + # # cross application tracing must be disabled + # assert not protocol.configuration.cross_application_tracer.enabled def test_serverless_protocol_finalize(capsys): diff --git a/tests/cross_agent/test_cat_map.py b/tests/cross_agent/test_cat_map.py deleted file mode 100644 index 01ede0b19a..0000000000 --- a/tests/cross_agent/test_cat_map.py +++ /dev/null @@ -1,211 +0,0 @@ -# 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. - -""" -This is an implementation of the cross agent tests for cat map using a wsgi -application. Another implementation of these tests using a tornado application -can be found in test/framework_tornado_r3/test_cat_map.py -""" - -import json -from pathlib import Path -from urllib.request import urlopen - -import pytest -import webtest -from testing_support.fixtures import ( - make_cross_agent_headers, - override_application_name, - override_application_settings, - validate_analytics_catmap_data, -) -from testing_support.mock_external_http_server import MockExternalHTTPHResponseHeadersServer -from testing_support.validators.validate_tt_parameters import validate_tt_parameters - -from newrelic.api.external_trace import ExternalTrace -from newrelic.api.transaction import ( - current_transaction, - get_browser_timing_header, - set_background_task, - set_transaction_name, -) -from newrelic.api.wsgi_application import wsgi_application -from newrelic.common.encoding_utils import json_encode, obfuscate - -ENCODING_KEY = "1234567890123456789012345678901234567890" -FIXTURE = Path(__file__).parent / "fixtures" / "cat_map.json" -OUTBOUD_REQUESTS = {} - -_parameters_list = [ - "name", - "appName", - "transactionName", - "transactionGuid", - "inboundPayload", - "outboundRequests", - "expectedIntrinsicFields", - "nonExpectedIntrinsicFields", -] - - -@pytest.fixture(scope="module") -def server(): - with MockExternalHTTPHResponseHeadersServer() as _server: - yield _server - - -def load_tests(): - result = [] - with FIXTURE.open() as fh: - tests = json.load(fh) - - for test in tests: - values = tuple([test.get(param, None) for param in _parameters_list]) - result.append(values) - - return result - - -_parameters = ",".join(_parameters_list) - - -@wsgi_application() -def target_wsgi_application(environ, start_response): - status = "200 OK" - - txn_name = environ.get("txn").split("/", 3) - - guid = environ.get("guid") - old_cat = environ.get("old_cat") == "True" - txn = current_transaction() - - txn.guid = guid - for req in OUTBOUD_REQUESTS: - # Change the transaction name before making an outbound call. - outgoing_name = req["outboundTxnName"].split("/", 3) - if outgoing_name[0] != "WebTransaction": - set_background_task(True) - - set_transaction_name(outgoing_name[2], group=outgoing_name[1]) - - expected_outbound_header = obfuscate(json_encode(req["expectedOutboundPayload"]), ENCODING_KEY) - generated_outbound_header = dict(ExternalTrace.generate_request_headers(txn)) - - # A 500 error is returned because 'assert' statements in the wsgi app - # are ignored. - - if old_cat: - if expected_outbound_header != generated_outbound_header["X-NewRelic-Transaction"]: - status = "500 Outbound Headers Check Failed." - else: - if "X-NewRelic-Transaction" in generated_outbound_header: - status = "500 Outbound Headers Check Failed." - r = urlopen(environ["server_url"]) - r.read(10) - - # Set the final transaction name. - - if txn_name[0] != "WebTransaction": - set_background_task(True) - set_transaction_name(txn_name[2], group=txn_name[1]) - - text = "%s

RESPONSE

" - - output = (text % get_browser_timing_header()).encode("UTF-8") - - response_headers = [("Content-type", "text/html; charset=utf-8"), ("Content-Length", str(len(output)))] - start_response(status, response_headers) - - return [output] - - -target_application = webtest.TestApp(target_wsgi_application) - - -@pytest.mark.parametrize(_parameters, load_tests()) -@pytest.mark.parametrize("old_cat", (True, False)) -def test_cat_map( - name, - appName, - transactionName, - transactionGuid, - inboundPayload, - outboundRequests, - expectedIntrinsicFields, - nonExpectedIntrinsicFields, - old_cat, - server, -): - global OUTBOUD_REQUESTS - OUTBOUD_REQUESTS = outboundRequests or {} - - _custom_settings = { - "cross_process_id": "1#1", - "encoding_key": ENCODING_KEY, - "trusted_account_ids": [1], - "cross_application_tracer.enabled": True, - "distributed_tracing.enabled": not old_cat, - "transaction_tracer.transaction_threshold": 0.0, - } - - if expectedIntrinsicFields and old_cat: - _external_node_params = { - "path_hash": expectedIntrinsicFields["nr.pathHash"], - "trip_id": expectedIntrinsicFields["nr.tripId"], - } - else: - _external_node_params = [] - - if not old_cat: - # since no better cat headers will be generated, no intrinsics should - # be added - expectedIntrinsicFields = {} - - @validate_tt_parameters(required_params=_external_node_params) - @validate_analytics_catmap_data( - transactionName, expected_attributes=expectedIntrinsicFields, non_expected_attributes=nonExpectedIntrinsicFields - ) - @override_application_settings(_custom_settings) - @override_application_name(appName) - def run_cat_test(): - txn_name = transactionName - guid = transactionGuid - - # Only generate old cat style headers. This will test to make sure we - # are properly ignoring these headers when the agent is using better - # cat. - - headers = make_cross_agent_headers(inboundPayload, ENCODING_KEY, "1#1") - response = target_application.get( - "/", - headers=headers, - extra_environ={ - "txn": txn_name, - "guid": guid, - "old_cat": str(old_cat), - "server_url": f"http://localhost:{server.port}", - }, - ) - - # Validation of analytic data happens in the decorator. - - assert response.status == "200 OK" - - content = response.html.html.body.p.string - - # Validate actual body content as sanity check. - - assert content == "RESPONSE" - - run_cat_test() diff --git a/tests/external_http/test_http.py b/tests/external_http/test_http.py index 590e659600..f7c43343fc 100644 --- a/tests/external_http/test_http.py +++ b/tests/external_http/test_http.py @@ -86,7 +86,7 @@ def _test(): _test = override_application_settings( { "distributed_tracing.enabled": distributed_tracing, - "cross_application_tracer.enabled": not distributed_tracing, + # "cross_application_tracer.enabled": not distributed_tracing, "span_events.enabled": span_events, } )(_test) diff --git a/tests/external_httplib/test_httplib.py b/tests/external_httplib/test_httplib.py index 64b7c94f77..8afd178bd9 100644 --- a/tests/external_httplib/test_httplib.py +++ b/tests/external_httplib/test_httplib.py @@ -124,7 +124,7 @@ def _test(): _test = override_application_settings( { "distributed_tracing.enabled": distributed_tracing, - "cross_application_tracer.enabled": not distributed_tracing, + # "cross_application_tracer.enabled": not distributed_tracing, "span_events.enabled": span_events, } )(_test) diff --git a/tests/external_httplib2/test_httplib2.py b/tests/external_httplib2/test_httplib2.py index 19edf44028..e3dc7d3fa6 100644 --- a/tests/external_httplib2/test_httplib2.py +++ b/tests/external_httplib2/test_httplib2.py @@ -104,7 +104,7 @@ def _test(): _test = override_application_settings( { "distributed_tracing.enabled": distributed_tracing, - "cross_application_tracer.enabled": not distributed_tracing, + # "cross_application_tracer.enabled": not distributed_tracing, "span_events.enabled": span_events, } )(_test) diff --git a/tests/external_httpx/test_client.py b/tests/external_httpx/test_client.py index 6f442fb87d..a3b1d080f9 100644 --- a/tests/external_httpx/test_client.py +++ b/tests/external_httpx/test_client.py @@ -124,7 +124,7 @@ def test_sync_cross_process_request(httpx, sync_client, mock_server, distributed { "distributed_tracing.enabled": distributed_tracing, "span_events.enabled": span_events, - "cross_application_tracer.enabled": not distributed_tracing, + # "cross_application_tracer.enabled": not distributed_tracing, } ) @validate_transaction_errors(errors=[]) @@ -206,85 +206,85 @@ async def _test(): assert response.request.headers["newrelic"] == "1234" -@pytest.mark.parametrize("cat_enabled", [True, False]) -@pytest.mark.parametrize("response_code", [200, 500]) -def test_sync_client_cat_response_processing(cat_enabled, response_code, sync_client, mock_server, httpx): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = response_code - - _custom_settings = { - "cross_process_id": "1#1", - "encoding_key": ENCODING_KEY, - "trusted_account_ids": [1], - "cross_application_tracer.enabled": cat_enabled, - "distributed_tracing.enabled": False, - "transaction_tracer.transaction_threshold": 0.0, - } - - expected_metrics = [ - ( - f"ExternalTransaction/localhost:{mock_server.port}/1#1/WebTransaction/Function/app:beep", - 1 if cat_enabled else None, - ) - ] - - @validate_transaction_metrics( - "test_sync_client_cat_response_processing", - background_task=True, - rollup_metrics=expected_metrics, - scoped_metrics=expected_metrics, - ) - @validate_tt_segment_params(exact_params={"http.statusCode": response_code}) - @override_application_settings(_custom_settings) - @background_task(name="test_sync_client_cat_response_processing") - def _test(): - with sync_client: - response = sync_client.get(f"http://localhost:{mock_server.port}") - - _test() - - -@pytest.mark.parametrize("cat_enabled", [True, False]) -@pytest.mark.parametrize("response_code", [200, 500]) -def test_async_client_cat_response_processing(cat_enabled, response_code, httpx, async_client, mock_server, loop): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = response_code - - _custom_settings = { - "cross_process_id": "1#1", - "encoding_key": ENCODING_KEY, - "trusted_account_ids": [1], - "cross_application_tracer.enabled": cat_enabled, - "distributed_tracing.enabled": False, - "transaction_tracer.transaction_threshold": 0.0, - } - - expected_metrics = [ - ( - f"ExternalTransaction/localhost:{mock_server.port}/1#1/WebTransaction/Function/app:beep", - 1 if cat_enabled else None, - ) - ] - - @validate_transaction_metrics( - "test_async_client_cat_response_processing", - background_task=True, - rollup_metrics=expected_metrics, - scoped_metrics=expected_metrics, - ) - @validate_tt_segment_params(exact_params={"http.statusCode": response_code}) - @override_application_settings(_custom_settings) - @background_task(name="test_async_client_cat_response_processing") - def _test(): - async def coro(): - async with async_client: - response = await async_client.get(f"http://localhost:{mock_server.port}") - - return response - - response = loop.run_until_complete(coro()) - - _test() +# @pytest.mark.parametrize("cat_enabled", [True, False]) +# @pytest.mark.parametrize("response_code", [200, 500]) +# def test_sync_client_cat_response_processing(cat_enabled, response_code, sync_client, mock_server, httpx): +# global CAT_RESPONSE_CODE +# CAT_RESPONSE_CODE = response_code + +# _custom_settings = { +# "cross_process_id": "1#1", +# "encoding_key": ENCODING_KEY, +# "trusted_account_ids": [1], +# "cross_application_tracer.enabled": cat_enabled, +# "distributed_tracing.enabled": False, +# "transaction_tracer.transaction_threshold": 0.0, +# } + +# expected_metrics = [ +# ( +# f"ExternalTransaction/localhost:{mock_server.port}/1#1/WebTransaction/Function/app:beep", +# 1 if cat_enabled else None, +# ) +# ] + +# @validate_transaction_metrics( +# "test_sync_client_cat_response_processing", +# background_task=True, +# rollup_metrics=expected_metrics, +# scoped_metrics=expected_metrics, +# ) +# @validate_tt_segment_params(exact_params={"http.statusCode": response_code}) +# @override_application_settings(_custom_settings) +# @background_task(name="test_sync_client_cat_response_processing") +# def _test(): +# with sync_client: +# response = sync_client.get(f"http://localhost:{mock_server.port}") + +# _test() + + +# @pytest.mark.parametrize("cat_enabled", [True, False]) +# @pytest.mark.parametrize("response_code", [200, 500]) +# def test_async_client_cat_response_processing(cat_enabled, response_code, httpx, async_client, mock_server, loop): +# global CAT_RESPONSE_CODE +# CAT_RESPONSE_CODE = response_code + +# _custom_settings = { +# "cross_process_id": "1#1", +# "encoding_key": ENCODING_KEY, +# "trusted_account_ids": [1], +# "cross_application_tracer.enabled": cat_enabled, +# "distributed_tracing.enabled": False, +# "transaction_tracer.transaction_threshold": 0.0, +# } + +# expected_metrics = [ +# ( +# f"ExternalTransaction/localhost:{mock_server.port}/1#1/WebTransaction/Function/app:beep", +# 1 if cat_enabled else None, +# ) +# ] + +# @validate_transaction_metrics( +# "test_async_client_cat_response_processing", +# background_task=True, +# rollup_metrics=expected_metrics, +# scoped_metrics=expected_metrics, +# ) +# @validate_tt_segment_params(exact_params={"http.statusCode": response_code}) +# @override_application_settings(_custom_settings) +# @background_task(name="test_async_client_cat_response_processing") +# def _test(): +# async def coro(): +# async with async_client: +# response = await async_client.get(f"http://localhost:{mock_server.port}") + +# return response + +# response = loop.run_until_complete(coro()) + +# _test() @dt_enabled diff --git a/tests/external_requests/test_requests.py b/tests/external_requests/test_requests.py index bb67691451..e98d37fec2 100644 --- a/tests/external_requests/test_requests.py +++ b/tests/external_requests/test_requests.py @@ -167,7 +167,7 @@ def _test(): _test = override_application_settings( { "distributed_tracing.enabled": distributed_tracing, - "cross_application_tracer.enabled": not distributed_tracing, + # "cross_application_tracer.enabled": not distributed_tracing, "span_events.enabled": span_events, } )(_test) diff --git a/tests/external_urllib3/test_urllib3.py b/tests/external_urllib3/test_urllib3.py index 6827fcf4cc..6328a2510f 100644 --- a/tests/external_urllib3/test_urllib3.py +++ b/tests/external_urllib3/test_urllib3.py @@ -216,7 +216,7 @@ def _test(): _test = override_application_settings( { "distributed_tracing.enabled": distributed_tracing, - "cross_application_tracer.enabled": not distributed_tracing, + # "cross_application_tracer.enabled": not distributed_tracing, "span_events.enabled": span_events, } )(_test) diff --git a/tests/framework_aiohttp/test_client_cat.py b/tests/framework_aiohttp/test_client_cat.py index bbba2f88b9..61a73d96aa 100644 --- a/tests/framework_aiohttp/test_client_cat.py +++ b/tests/framework_aiohttp/test_client_cat.py @@ -18,7 +18,7 @@ import pytest from testing_support.external_fixtures import create_incoming_headers from testing_support.fixtures import override_application_settings -from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers +# from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers from testing_support.validators.validate_external_node_params import validate_external_node_params from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics @@ -64,10 +64,11 @@ async def fetch(url, headers=None, raise_for_status=False, connector=None): return headers -@pytest.mark.parametrize("cat_enabled", (True, False)) +# @pytest.mark.parametrize("cat_enabled", (True, False)) @pytest.mark.parametrize("distributed_tracing", (True, False)) @pytest.mark.parametrize("span_events", (True, False)) -def test_outbound_cross_process_headers(event_loop, cat_enabled, distributed_tracing, span_events, mock_header_server): +def test_outbound_cross_process_headers(event_loop, distributed_tracing, span_events, mock_header_server): +# def test_outbound_cross_process_headers(event_loop, cat_enabled, distributed_tracing, span_events, mock_header_server): @background_task(name="test_outbound_cross_process_headers") async def _test(): headers = await fetch(f"http://127.0.0.1:{mock_header_server.port}") @@ -77,9 +78,9 @@ async def _test(): if distributed_tracing: assert "newrelic" in headers - elif cat_enabled: - assert ExternalTrace.cat_id_key in headers - assert ExternalTrace.cat_transaction_key in headers + # elif cat_enabled: + # assert ExternalTrace.cat_id_key in headers + # assert ExternalTrace.cat_transaction_key in headers else: assert "newrelic" not in headers assert ExternalTrace.cat_id_key not in headers @@ -88,14 +89,14 @@ async def _test(): def _validate(): pass - if cat_enabled or distributed_tracing: - _validate = validate_cross_process_headers(_validate) + # if cat_enabled or distributed_tracing: + # _validate = validate_cross_process_headers(_validate) _validate() @override_application_settings( { - "cross_application_tracer.enabled": cat_enabled, + # "cross_application_tracer.enabled": cat_enabled, "distributed_tracing.enabled": distributed_tracing, "span_events.enabled": span_events, } @@ -155,12 +156,13 @@ async def _resolve_host(self, host, port, *args, **kwargs): return res -@pytest.mark.parametrize("cat_enabled", [True, False]) +# @pytest.mark.parametrize("cat_enabled", [True, False]) @pytest.mark.parametrize("response_code", [200, 404]) @pytest.mark.parametrize("raise_for_status", [True, False]) @pytest.mark.parametrize("connector_class", [None, PoorResolvingConnector]) # None will use default def test_process_incoming_headers( - event_loop, cat_enabled, response_code, raise_for_status, connector_class, mock_external_http_server + event_loop, response_code, raise_for_status, connector_class, mock_external_http_server + # event_loop, cat_enabled, response_code, raise_for_status, connector_class, mock_external_http_server ): # It was discovered via packnsend that the `throw` method of the `_request` # coroutine is used in the case of poorly resolved hosts. An older version @@ -174,15 +176,15 @@ def test_process_incoming_headers( port = server.port _test_cross_process_response_scoped_metrics = [ - (f"ExternalTransaction/127.0.0.1:{port}/1#2/test", 1 if cat_enabled else None) + (f"ExternalTransaction/127.0.0.1:{port}/1#2/test", None) ] _test_cross_process_response_rollup_metrics = [ ("External/all", 1), ("External/allOther", 1), (f"External/127.0.0.1:{port}/all", 1), - (f"ExternalApp/127.0.0.1:{port}/1#2/all", 1 if cat_enabled else None), - (f"ExternalTransaction/127.0.0.1:{port}/1#2/test", 1 if cat_enabled else None), + (f"ExternalApp/127.0.0.1:{port}/1#2/all", None), + (f"ExternalTransaction/127.0.0.1:{port}/1#2/test", None), ] _test_cross_process_response_external_node_params = [ @@ -207,7 +209,7 @@ async def _test(): await fetch(address, raise_for_status=raise_for_status, connector=connector) @override_application_settings( - {"cross_application_tracer.enabled": cat_enabled, "distributed_tracing.enabled": False} + {"distributed_tracing.enabled": False} ) @validate_transaction_metrics( "test_process_incoming_headers", @@ -216,8 +218,8 @@ async def _test(): background_task=True, ) @validate_external_node_params( - params=(_test_cross_process_response_external_node_params if cat_enabled else []), - forgone_params=([] if cat_enabled else _test_cross_process_response_external_node_forgone_params), + params=[], + forgone_params=_test_cross_process_response_external_node_forgone_params, ) def test(): event_loop.run_until_complete(_test()) diff --git a/tests/framework_aiohttp/test_server_cat.py b/tests/framework_aiohttp/test_server_cat.py index 5af4933ca3..3fc651ad19 100644 --- a/tests/framework_aiohttp/test_server_cat.py +++ b/tests/framework_aiohttp/test_server_cat.py @@ -118,7 +118,7 @@ async def fetch(): "cross_process_id": "1#1", "encoding_key": ENCODING_KEY, "trusted_account_ids": [1], - "cross_application_tracer.enabled": True, + # "cross_application_tracer.enabled": True, "distributed_tracing.enabled": False, } diff --git a/tests/framework_sanic/test_cross_application.py b/tests/framework_sanic/test_cross_application.py index a327166419..60e1980533 100644 --- a/tests/framework_sanic/test_cross_application.py +++ b/tests/framework_sanic/test_cross_application.py @@ -74,7 +74,7 @@ def test_inbound_distributed_trace(app): "cross_process_id": "1#1", "encoding_key": ENCODING_KEY, "trusted_account_ids": [1], - "cross_application_tracer.enabled": True, + # "cross_application_tracer.enabled": True, "distributed_tracing.enabled": False, } diff --git a/tests/framework_tornado/test_externals.py b/tests/framework_tornado/test_externals.py index fd40b9423f..40d71e9ab8 100644 --- a/tests/framework_tornado/test_externals.py +++ b/tests/framework_tornado/test_externals.py @@ -160,7 +160,7 @@ def test_httpclient( { "distributed_tracing.enabled": distributed_tracing, "span_events.enabled": span_events, - "cross_application_tracer.enabled": not distributed_tracing, + # "cross_application_tracer.enabled": not distributed_tracing, } ) @validate_transaction_metrics( @@ -243,11 +243,11 @@ def cat_response_server(): @pytest.mark.parametrize("client_class", ["AsyncHTTPClient", "CurlAsyncHTTPClient", "HTTPClient"]) -@pytest.mark.parametrize("cat_enabled", [True, False]) +@pytest.mark.parametrize("dt_enabled", [True, False]) @pytest.mark.parametrize("request_type", ["uri", "class"]) @pytest.mark.parametrize("response_code,raise_error", [(500, True), (500, False), (200, False)]) def test_client_cat_response_processing( - cat_enabled, request_type, client_class, raise_error, response_code, cat_response_server + dt_enabled, request_type, client_class, raise_error, response_code, cat_response_server ): global CAT_RESPONSE_CODE CAT_RESPONSE_CODE = response_code @@ -256,15 +256,13 @@ def test_client_cat_response_processing( "cross_process_id": "1#1", "encoding_key": ENCODING_KEY, "trusted_account_ids": [1], - "cross_application_tracer.enabled": cat_enabled, - "distributed_tracing.enabled": not cat_enabled, + # "cross_application_tracer.enabled": cat_enabled, + "distributed_tracing.enabled": dt_enabled, "transaction_tracer.transaction_threshold": 0.0, } port = cat_response_server.port - expected_metrics = [ - (f"ExternalTransaction/localhost:{port}/1#1/WebTransaction/Function/app:beep", 1 if cat_enabled else None) - ] + expected_metrics = None @validate_transaction_metrics( "make_request", background_task=True, rollup_metrics=expected_metrics, scoped_metrics=expected_metrics diff --git a/tests/framework_tornado/test_inbound_cat.py b/tests/framework_tornado/test_inbound_cat.py index a0773dcb5d..fb935f174a 100644 --- a/tests/framework_tornado/test_inbound_cat.py +++ b/tests/framework_tornado/test_inbound_cat.py @@ -26,7 +26,7 @@ "cross_process_id": "1#1", "encoding_key": ENCODING_KEY, "trusted_account_ids": [1], - "cross_application_tracer.enabled": True, + # "cross_application_tracer.enabled": True, "distributed_tracing.enabled": False, "transaction_tracer.transaction_threshold": 0.0, } diff --git a/tests/messagebroker_pika/test_distributed_tracing.py b/tests/messagebroker_pika/test_distributed_tracing.py index 472db1c0b2..ee8a643ced 100644 --- a/tests/messagebroker_pika/test_distributed_tracing.py +++ b/tests/messagebroker_pika/test_distributed_tracing.py @@ -31,7 +31,7 @@ "primary_application_id": "12345", "account_id": "33", "trusted_account_key": "1", - "cross_application_tracer.enabled": True, + # "cross_application_tracer.enabled": True, "distributed_tracing.enabled": True, } diff --git a/tests/messagebroker_pika/test_pika_produce.py b/tests/messagebroker_pika/test_pika_produce.py index 57605c6539..1d8a01c6ec 100644 --- a/tests/messagebroker_pika/test_pika_produce.py +++ b/tests/messagebroker_pika/test_pika_produce.py @@ -173,7 +173,7 @@ def test_blocking_connection_reply_to(producer): def test_blocking_connection_headers(enable_distributed_tracing): override_settings = { "distributed_tracing.enabled": enable_distributed_tracing, - "cross_application_tracer.enabled": not enable_distributed_tracing, + # "cross_application_tracer.enabled": not enable_distributed_tracing, } rollup_metrics = list(_test_blocking_connection_metrics) if enable_distributed_tracing: From d177cb75f0847e002fa32e33190a735b1bb9683a Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Tue, 9 Sep 2025 13:00:22 -0700 Subject: [PATCH 46/95] Remove cat_enabled fixture --- .../test_attributes_in_action.py | 6 +-- tests/agent_features/test_error_events.py | 4 +- tests/agent_features/test_synthetics.py | 10 ++--- tests/external_http/test_http.py | 4 +- tests/external_httplib/test_httplib.py | 6 +-- tests/external_httplib/test_urllib.py | 5 +-- tests/external_httplib/test_urllib2.py | 4 +- tests/external_httplib2/test_httplib2.py | 4 +- tests/external_requests/test_requests.py | 4 +- tests/external_urllib3/test_urllib3.py | 4 +- .../test_client_async_await.py | 14 +++---- tests/framework_tornado/test_externals.py | 39 +++++++++---------- tests/messagebroker_pika/test_cat.py | 4 +- tests/testing_support/fixtures.py | 10 ++--- 14 files changed, 57 insertions(+), 61 deletions(-) diff --git a/tests/agent_features/test_attributes_in_action.py b/tests/agent_features/test_attributes_in_action.py index 4d12e8b059..c6f1128009 100644 --- a/tests/agent_features/test_attributes_in_action.py +++ b/tests/agent_features/test_attributes_in_action.py @@ -16,7 +16,7 @@ import webtest from testing_support.asgi_testing import AsgiTest from testing_support.fixtures import ( - cat_enabled, + # cat_enabled, dt_enabled, override_application_settings, reset_core_stats_engine, @@ -176,7 +176,7 @@ def normal_application(request): _expected_absent_attributes = {"agent": REQ_PARAMS, "user": [], "intrinsic": DISTRIBUTED_TRACE_ATTRS} -@cat_enabled +# @cat_enabled @validate_error_event_attributes(_expected_attributes_event, _expected_absent_attributes) @validate_transaction_error_trace_attributes(_expected_attributes, _expected_absent_attributes) def test_error_in_transaction_default_settings(normal_application): @@ -186,7 +186,7 @@ def test_error_in_transaction_default_settings(normal_application): _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} -@cat_enabled +# @cat_enabled @validate_transaction_trace_attributes(_expected_attributes, _expected_absent_attributes) @override_application_settings({}) def test_transaction_trace_default_attribute_settings(normal_application): diff --git a/tests/agent_features/test_error_events.py b/tests/agent_features/test_error_events.py index 30a89c9044..08195cf991 100644 --- a/tests/agent_features/test_error_events.py +++ b/tests/agent_features/test_error_events.py @@ -17,7 +17,7 @@ import webtest from testing_support.fixtures import ( - cat_enabled, + # cat_enabled, make_cross_agent_headers, make_synthetics_headers, override_application_settings, @@ -112,7 +112,7 @@ def test_transaction_error_background_task(): } -@cat_enabled +# @cat_enabled @validate_error_event_sample_data(required_attrs=_intrinsic_attributes, required_user_attrs=True) def test_transaction_error_cross_agent(): test_environ = {"err_message": ERR_MESSAGE} diff --git a/tests/agent_features/test_synthetics.py b/tests/agent_features/test_synthetics.py index f584a12237..a5916f7a42 100644 --- a/tests/agent_features/test_synthetics.py +++ b/tests/agent_features/test_synthetics.py @@ -15,7 +15,7 @@ import pytest import webtest from testing_support.external_fixtures import validate_synthetics_external_trace_header -from testing_support.fixtures import cat_enabled, make_synthetics_headers, override_application_settings +from testing_support.fixtures import make_synthetics_headers, override_application_settings from testing_support.validators.validate_synthetics_event import validate_synthetics_event from testing_support.validators.validate_synthetics_transaction_trace import validate_synthetics_transaction_trace @@ -187,7 +187,7 @@ def test_synthetics_event_mismatched_info_encoding_key(): } -@cat_enabled +# @cat_enabled @validate_synthetics_transaction_trace(_test_valid_synthetics_tt_required) @override_application_settings(_override_settings) def test_valid_synthetics_in_transaction_trace(): @@ -220,7 +220,7 @@ def test_synthetics_disabled(): _external_synthetics_info_header = _external_synthetics_headers["X-NewRelic-Synthetics-Info"] -@cat_enabled +# @cat_enabled @validate_synthetics_external_trace_header(_external_synthetics_header, _external_synthetics_info_header) @override_application_settings(_override_settings) def test_valid_synthetics_external_trace_header(): @@ -228,7 +228,7 @@ def test_valid_synthetics_external_trace_header(): response = target_application.get("/", headers=headers) -@cat_enabled +# @cat_enabled @validate_synthetics_external_trace_header(_external_synthetics_header, None) @override_application_settings(_override_settings) def test_valid_synthetics_external_trace_header_without_info(): @@ -236,7 +236,7 @@ def test_valid_synthetics_external_trace_header_without_info(): response = target_application.get("/", headers=headers) -@cat_enabled +# @cat_enabled @validate_synthetics_external_trace_header(_external_synthetics_header, _external_synthetics_info_header) @override_application_settings(_override_settings) def test_valid_external_trace_header_with_byte_inbound_header(): diff --git a/tests/external_http/test_http.py b/tests/external_http/test_http.py index f7c43343fc..74ab0833e6 100644 --- a/tests/external_http/test_http.py +++ b/tests/external_http/test_http.py @@ -16,7 +16,7 @@ import pytest from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers -from testing_support.fixtures import cat_enabled, override_application_settings +from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers from testing_support.validators.validate_external_node_params import validate_external_node_params from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics @@ -94,7 +94,7 @@ def _test(): _test() -@cat_enabled +# @cat_enabled def test_http_cross_process_response(server): _test_http_cross_process_response_scoped_metrics = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] diff --git a/tests/external_httplib/test_httplib.py b/tests/external_httplib/test_httplib.py index 8afd178bd9..46372adb1c 100644 --- a/tests/external_httplib/test_httplib.py +++ b/tests/external_httplib/test_httplib.py @@ -16,7 +16,7 @@ import pytest from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers -from testing_support.fixtures import cat_enabled, override_application_settings +from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers from testing_support.validators.validate_external_node_params import validate_external_node_params from testing_support.validators.validate_span_events import validate_span_events @@ -139,7 +139,7 @@ def _test(): ] -@cat_enabled +# @cat_enabled @insert_incoming_headers def test_httplib_cross_process_response(server): scoped = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] @@ -170,7 +170,7 @@ def _test(): _test() -@cat_enabled +# @cat_enabled def test_httplib_multiple_requests_cross_process_response(server): connection = httplib.HTTPConnection("localhost", server.port) diff --git a/tests/external_httplib/test_urllib.py b/tests/external_httplib/test_urllib.py index 9b2fde3500..ddff60d8af 100644 --- a/tests/external_httplib/test_urllib.py +++ b/tests/external_httplib/test_urllib.py @@ -22,7 +22,7 @@ import urllib from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers -from testing_support.fixtures import cat_enabled +# from testing_support.fixtures import cat_enabled from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers from testing_support.validators.validate_external_node_params import validate_external_node_params from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics @@ -145,7 +145,6 @@ def test_urlopener_cross_process_request(server): @SKIP_IF_PYTHON_3_14_OR_ABOVE -@cat_enabled def test_urlopener_cross_process_response(server): _test_urlopener_cross_process_response_scoped_metrics = [ (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) @@ -219,7 +218,7 @@ def test_urlretrieve_cross_process_request(server): urllib.urlretrieve(f"http://localhost:{server.port}/") -@cat_enabled +# @cat_enabled def test_urlretrieve_cross_process_response(server): _test_urlretrieve_cross_process_response_scoped_metrics = [ (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) diff --git a/tests/external_httplib/test_urllib2.py b/tests/external_httplib/test_urllib2.py index c744614be8..2eb74c93a0 100644 --- a/tests/external_httplib/test_urllib2.py +++ b/tests/external_httplib/test_urllib2.py @@ -16,7 +16,7 @@ import pytest from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers -from testing_support.fixtures import cat_enabled +# from testing_support.fixtures import cat_enabled from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers from testing_support.validators.validate_external_node_params import validate_external_node_params from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics @@ -120,7 +120,7 @@ def test_urlopen_cross_process_request(server): urllib2.urlopen(f"http://localhost:{server.port}/") -@cat_enabled +# @cat_enabled def test_urlopen_cross_process_response(server): _test_urlopen_cross_process_response_scoped_metrics = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] diff --git a/tests/external_httplib2/test_httplib2.py b/tests/external_httplib2/test_httplib2.py index e3dc7d3fa6..f4fa0e7c9b 100644 --- a/tests/external_httplib2/test_httplib2.py +++ b/tests/external_httplib2/test_httplib2.py @@ -15,7 +15,7 @@ import httplib2 import pytest from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers -from testing_support.fixtures import cat_enabled, override_application_settings +from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers from testing_support.validators.validate_external_node_params import validate_external_node_params from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics @@ -112,7 +112,7 @@ def _test(): _test() -@cat_enabled +# @cat_enabled def test_httplib2_cross_process_response(server): _test_httplib2_cross_process_response_scoped_metrics = [ (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) diff --git a/tests/external_requests/test_requests.py b/tests/external_requests/test_requests.py index e98d37fec2..b2d39e7289 100644 --- a/tests/external_requests/test_requests.py +++ b/tests/external_requests/test_requests.py @@ -16,7 +16,7 @@ import requests import requests.exceptions from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers -from testing_support.fixtures import cat_enabled, override_application_settings, validate_tt_parenting +from testing_support.fixtures import override_application_settings, validate_tt_parenting from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers from testing_support.validators.validate_external_node_params import validate_external_node_params from testing_support.validators.validate_transaction_errors import validate_transaction_errors @@ -175,7 +175,7 @@ def _test(): _test() -@cat_enabled +# @cat_enabled def test_requests_cross_process_response(server): _test_requests_cross_process_response_scoped_metrics = [ (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) diff --git a/tests/external_urllib3/test_urllib3.py b/tests/external_urllib3/test_urllib3.py index 6328a2510f..0669ab1b9d 100644 --- a/tests/external_urllib3/test_urllib3.py +++ b/tests/external_urllib3/test_urllib3.py @@ -22,7 +22,7 @@ pass from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers -from testing_support.fixtures import cat_enabled, override_application_settings +from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers from testing_support.validators.validate_external_node_params import validate_external_node_params from testing_support.validators.validate_transaction_errors import validate_transaction_errors @@ -224,7 +224,7 @@ def _test(): _test() -@cat_enabled +# @cat_enabled def test_urlopen_cross_process_response(server): _test_urlopen_cross_process_response_scoped_metrics = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] diff --git a/tests/framework_aiohttp/test_client_async_await.py b/tests/framework_aiohttp/test_client_async_await.py index 4ca83b9432..8e57305060 100644 --- a/tests/framework_aiohttp/test_client_async_await.py +++ b/tests/framework_aiohttp/test_client_async_await.py @@ -16,7 +16,7 @@ import aiohttp import pytest -from testing_support.fixtures import cat_enabled +# from testing_support.fixtures import cat_enabled from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from yarl import URL @@ -66,7 +66,7 @@ def task(loop, method, exc_expected, url): ) -@cat_enabled +# @cat_enabled @pytest.mark.parametrize("method,exc_expected", test_matrix) def test_client_async_await(event_loop, local_server_info, method, exc_expected): @validate_transaction_metrics( @@ -81,7 +81,7 @@ def task_test(): task_test() -@cat_enabled +# @cat_enabled def test_client_yarl_async_await(event_loop, local_server_info): method = "get" @@ -98,7 +98,7 @@ def task_test(): @pytest.mark.parametrize("method,exc_expected", test_matrix) -@cat_enabled +# @cat_enabled def test_client_no_txn_async_await(event_loop, local_server_info, method, exc_expected): def task_test(): task(event_loop, method, exc_expected, local_server_info.url) @@ -107,7 +107,7 @@ def task_test(): @pytest.mark.parametrize("method,exc_expected", test_matrix) -@cat_enabled +# @cat_enabled def test_await_request_async_await(event_loop, local_server_info, method, exc_expected): async def request_with_await(): async with aiohttp.ClientSession() as session: @@ -160,7 +160,7 @@ def task_test(): @pytest.mark.parametrize("method,exc_expected", test_matrix) -@cat_enabled +# @cat_enabled def test_create_task_async_await(event_loop, local_server_info, method, exc_expected): # `loop.create_task` returns a Task object which uses the coroutine's # `send` method, not `__next__` @@ -195,7 +195,7 @@ def task_test(): @pytest.mark.parametrize("method,exc_expected", test_matrix) -@cat_enabled +# @cat_enabled def test_terminal_parent_async_await(event_loop, local_server_info, method, exc_expected): """ This test injects a terminal node into a simple background task workflow. diff --git a/tests/framework_tornado/test_externals.py b/tests/framework_tornado/test_externals.py index 40d71e9ab8..1f00db5b6b 100644 --- a/tests/framework_tornado/test_externals.py +++ b/tests/framework_tornado/test_externals.py @@ -124,13 +124,10 @@ def _make_request(): ], ) @pytest.mark.parametrize( - "cat_enabled,user_header,span_events,distributed_tracing", + "user_header,span_events,distributed_tracing", [ - (True, None, False, False), - (True, "X-NewRelic-ID", False, False), - (True, "X-NewRelic-Transaction", False, False), - (False, None, True, True), - (False, None, False, True), + (None, True, True), + (None, False, True), ], ) # @pytest.mark.parametrize('cat_enabled,user_header', [ @@ -142,10 +139,10 @@ def _make_request(): @pytest.mark.parametrize("request_type", ["uri", "class"]) @pytest.mark.parametrize("num_requests", [1, 2]) def test_httpclient( - cat_enabled, + # cat_enabled, request_type, client_class, - user_header, + # user_header, num_requests, distributed_tracing, span_events, @@ -172,8 +169,8 @@ def test_httpclient( @background_task(name="test_externals:test_httpclient") def _test(): headers = {} - if user_header: - headers = {user_header: "USER"} + # if user_header: + # headers = {user_header: "USER"} response = make_request( port, request_type, client_class, headers=headers, count=num_requests, as_kwargs=as_kwargs @@ -194,17 +191,17 @@ def _test(): headers[header_key] = header_val # User headers override all inserted NR headers - if user_header: - assert headers[user_header] == "USER" - elif cat_enabled: - t = current_transaction() - assert t - t._test_request_headers = headers - - if distributed_tracing: - validate_distributed_tracing_header(header="Newrelic") - else: - validate_outbound_headers() + # if user_header: + # assert headers[user_header] == "USER" + # elif cat_enabled: + # t = current_transaction() + # assert t + # t._test_request_headers = headers + + # if distributed_tracing: + # validate_distributed_tracing_header(header="Newrelic") + # else: + validate_outbound_headers() else: # new relic shouldn't add anything to the outgoing assert "x-newrelic" not in body, body diff --git a/tests/messagebroker_pika/test_cat.py b/tests/messagebroker_pika/test_cat.py index 295d988aa3..e4d9ea1c59 100644 --- a/tests/messagebroker_pika/test_cat.py +++ b/tests/messagebroker_pika/test_cat.py @@ -19,7 +19,7 @@ import pika from compat import basic_consume from testing_support.db_settings import rabbitmq_settings -from testing_support.fixtures import cat_enabled, override_application_settings +from testing_support.fixtures import override_application_settings from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task @@ -60,7 +60,7 @@ def do_basic_consume(channel): channel.start_consuming() -@cat_enabled +# @cat_enabled @override_application_settings(_override_settings) def test_basic_consume_cat_headers(): def on_receive(ch, method, properties, msg): diff --git a/tests/testing_support/fixtures.py b/tests/testing_support/fixtures.py index d12311f9cd..48291e8e99 100644 --- a/tests/testing_support/fixtures.py +++ b/tests/testing_support/fixtures.py @@ -1046,12 +1046,12 @@ def force_sampled(wrapped, instance, args, kwargs): return wrapped(*args, **kwargs) -@function_wrapper -def cat_enabled(wrapped, instance, args, kwargs): - settings = {"cross_application_tracer.enabled": True, "distributed_tracing.enabled": False} - wrapped = override_application_settings(settings)(wrapped) +# @function_wrapper +# def cat_enabled(wrapped, instance, args, kwargs): +# settings = {"cross_application_tracer.enabled": True, "distributed_tracing.enabled": False} +# wrapped = override_application_settings(settings)(wrapped) - return wrapped(*args, **kwargs) +# return wrapped(*args, **kwargs) def override_application_settings(overrides): From 74f922ac9ff0dcdd1f346752c9dd18617dbcf137 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Tue, 9 Sep 2025 14:09:51 -0700 Subject: [PATCH 47/95] Remove validate_outbound_headers, make_cross_agent_headers --- newrelic/api/cat_header_mixin.py | 22 ++-- newrelic/api/external_trace.py | 2 +- newrelic/api/transaction.py | 124 +++++++++--------- newrelic/api/web_transaction.py | 8 +- newrelic/core/transaction_node.py | 2 +- newrelic/hooks/external_httplib.py | 26 ++-- newrelic/hooks/framework_aiohttp.py | 30 +++-- tests/agent_features/test_error_events.py | 5 +- tests/agent_unittests/test_harvest_loop.py | 2 +- .../framework_tornado/_target_application.py | 6 +- tests/framework_tornado/test_externals.py | 4 +- tests/testing_support/fixtures.py | 8 +- .../validate_cross_process_headers.py | 6 +- .../validate_messagebroker_headers.py | 6 +- .../validators/validate_outbound_headers.py | 55 -------- 15 files changed, 127 insertions(+), 179 deletions(-) delete mode 100644 tests/testing_support/validators/validate_outbound_headers.py diff --git a/newrelic/api/cat_header_mixin.py b/newrelic/api/cat_header_mixin.py index b905f9dc80..a6675ab3a5 100644 --- a/newrelic/api/cat_header_mixin.py +++ b/newrelic/api/cat_header_mixin.py @@ -24,13 +24,13 @@ # CatHeaderMixin assumes the mixin class also inherits from TimeTrace class CatHeaderMixin: - cat_id_key = "X-NewRelic-ID" - cat_transaction_key = "X-NewRelic-Transaction" - cat_appdata_key = "X-NewRelic-App-Data" - cat_synthetics_key = "X-NewRelic-Synthetics" - cat_synthetics_info_key = "X-NewRelic-Synthetics-Info" - cat_metadata_key = "x-newrelic-trace" - cat_distributed_trace_key = "newrelic" + # cat_id_key = "X-NewRelic-ID" + # cat_transaction_key = "X-NewRelic-Transaction" + # cat_appdata_key = "X-NewRelic-App-Data" + # cat_synthetics_key = "X-NewRelic-Synthetics" + # cat_synthetics_info_key = "X-NewRelic-Synthetics-Info" + # cat_metadata_key = "x-newrelic-trace" + # cat_distributed_trace_key = "newrelic" settings = None def __enter__(self): @@ -69,10 +69,10 @@ def __enter__(self): # except Exception: # pass - def process_response_metadata(self, cat_linking_value): - payload = base64_decode(cat_linking_value) - nr_headers = json_decode(payload) - self.process_response_headers(nr_headers.items()) + # def process_response_metadata(self, cat_linking_value): + # payload = base64_decode(cat_linking_value) + # nr_headers = json_decode(payload) + # self.process_response_headers(nr_headers.items()) @classmethod def generate_request_headers(cls, transaction): diff --git a/newrelic/api/external_trace.py b/newrelic/api/external_trace.py index 372eb2ca09..32796ccd9f 100644 --- a/newrelic/api/external_trace.py +++ b/newrelic/api/external_trace.py @@ -40,7 +40,7 @@ def __repr__(self): def process_response(self, status_code, headers): self._add_agent_attribute("http.statusCode", status_code) - self.process_response_headers(headers) + # self.process_response_headers(headers) def terminal_node(self): return True diff --git a/newrelic/api/transaction.py b/newrelic/api/transaction.py index 96fd181945..ec24076b2e 100644 --- a/newrelic/api/transaction.py +++ b/newrelic/api/transaction.py @@ -297,7 +297,7 @@ def __init__(self, application, enabled=None, source=None): self._trip_id = None self._referring_path_hash = None self._alternate_path_hashes = {} - self.is_part_of_cat = False + # self.is_part_of_cat = False # Synthetics Header self.synthetics_resource_id = None @@ -610,7 +610,7 @@ def __exit__(self, exc, value, tb): synthetics_initiator=self.synthetics_initiator, synthetics_attributes=self.synthetics_attributes, synthetics_info_header=self.synthetics_info_header, - is_part_of_cat=self.is_part_of_cat, + # is_part_of_cat=self.is_part_of_cat, trip_id=self.trip_id, path_hash=self.path_hash, referring_path_hash=self._referring_path_hash, @@ -748,53 +748,53 @@ def alternate_path_hashes(self): """ return sorted(set(self._alternate_path_hashes.values()) - {self.path_hash}) - @property - def path_hash(self): - """Path hash is a 32-bit digest of the string "appname;txn_name" - XORed with the referring_path_hash. Since the txn_name can change - during the course of a transaction, up to 10 path_hashes are stored - in _alternate_path_hashes. Before generating the path hash, check the - _alternate_path_hashes to determine if we've seen this identifier and - return the value. + # @property + # def path_hash(self): + # """Path hash is a 32-bit digest of the string "appname;txn_name" + # XORed with the referring_path_hash. Since the txn_name can change + # during the course of a transaction, up to 10 path_hashes are stored + # in _alternate_path_hashes. Before generating the path hash, check the + # _alternate_path_hashes to determine if we've seen this identifier and + # return the value. - """ + # """ - if not self.is_part_of_cat: - return None + # if not self.is_part_of_cat: + # return None - identifier = f"{self.application.name};{self.path}" + # identifier = f"{self.application.name};{self.path}" - # Check if identifier is already part of the _alternate_path_hashes and - # return the value if available. + # # Check if identifier is already part of the _alternate_path_hashes and + # # return the value if available. - if self._alternate_path_hashes.get(identifier): - return self._alternate_path_hashes[identifier] + # if self._alternate_path_hashes.get(identifier): + # return self._alternate_path_hashes[identifier] - # If the referring_path_hash is unavailable then we use '0' as the - # seed. + # # If the referring_path_hash is unavailable then we use '0' as the + # # seed. - try: - seed = int((self._referring_path_hash or "0"), base=16) - except Exception: - seed = 0 + # try: + # seed = int((self._referring_path_hash or "0"), base=16) + # except Exception: + # seed = 0 - try: - path_hash = generate_path_hash(identifier, seed) - except ValueError: - _logger.warning( - "Unable to generate cross application tracer headers. " - "MD5 hashing may not be available. (Is this system FIPS compliant?) " - "We recommend enabling distributed tracing instead. For details and a transition guide see " - "https://docs.newrelic.com/docs/agents/python-agent/configuration/python-agent-configuration#distributed-tracing-settings" - ) - return None + # try: + # path_hash = generate_path_hash(identifier, seed) + # except ValueError: + # _logger.warning( + # "Unable to generate cross application tracer headers. " + # "MD5 hashing may not be available. (Is this system FIPS compliant?) " + # "We recommend enabling distributed tracing instead. For details and a transition guide see " + # "https://docs.newrelic.com/docs/agents/python-agent/configuration/python-agent-configuration#distributed-tracing-settings" + # ) + # return None - # Only store up to 10 alternate path hashes. + # # Only store up to 10 alternate path hashes. - if len(self._alternate_path_hashes) < 10: - self._alternate_path_hashes[identifier] = path_hash + # if len(self._alternate_path_hashes) < 10: + # self._alternate_path_hashes[identifier] = path_hash - return path_hash + # return path_hash @property def attribute_filter(self): @@ -1449,31 +1449,31 @@ def _generate_response_headers(self, read_length=None): return nr_headers - # This function is CAT related and has been deprecated. - # Eventually, this will be removed. Until then, coverage - # does not need to factor this function into its analysis. - def get_response_metadata(self): # pragma: no cover - nr_headers = dict(self._generate_response_headers()) - return convert_to_cat_metadata_value(nr_headers) - - # This function is CAT related and has been deprecated. - # Eventually, this will be removed. Until then, coverage - # does not need to factor this function into its analysis. - def process_request_metadata(self, cat_linking_value): # pragma: no cover - try: - payload = base64_decode(cat_linking_value) - except: - # `cat_linking_value` should always be able to be base64_decoded. - # If this is encountered, the data being sent is corrupt. No - # exception should be raised. - return + # # This function is CAT related and has been deprecated. + # # Eventually, this will be removed. Until then, coverage + # # does not need to factor this function into its analysis. + # def get_response_metadata(self): # pragma: no cover + # nr_headers = dict(self._generate_response_headers()) + # return convert_to_cat_metadata_value(nr_headers) + + # # This function is CAT related and has been deprecated. + # # Eventually, this will be removed. Until then, coverage + # # does not need to factor this function into its analysis. + # def process_request_metadata(self, cat_linking_value): # pragma: no cover + # try: + # payload = base64_decode(cat_linking_value) + # except: + # # `cat_linking_value` should always be able to be base64_decoded. + # # If this is encountered, the data being sent is corrupt. No + # # exception should be raised. + # return - nr_headers = json_decode(payload) - # TODO: All the external CAT APIs really need to - # be refactored into the transaction class. - encoded_cross_process_id = nr_headers.get("X-NewRelic-ID") - encoded_txn_header = nr_headers.get("X-NewRelic-Transaction") - return self._process_incoming_cat_headers(encoded_cross_process_id, encoded_txn_header) + # nr_headers = json_decode(payload) + # # TODO: All the external CAT APIs really need to + # # be refactored into the transaction class. + # encoded_cross_process_id = nr_headers.get("X-NewRelic-ID") + # encoded_txn_header = nr_headers.get("X-NewRelic-Transaction") + # return self._process_incoming_cat_headers(encoded_cross_process_id, encoded_txn_header) def set_transaction_name(self, name, group=None, priority=None): # Always perform this operation even if the transaction diff --git a/newrelic/api/web_transaction.py b/newrelic/api/web_transaction.py index c305663273..2325b18784 100644 --- a/newrelic/api/web_transaction.py +++ b/newrelic/api/web_transaction.py @@ -300,10 +300,10 @@ def _process_context_headers(self): # the relevant details. if self._settings.distributed_tracing.enabled: self.accept_distributed_trace_headers(self._request_headers) - else: - client_cross_process_id = self._request_headers.get("x-newrelic-id") - txn_header = self._request_headers.get("x-newrelic-transaction") - self._process_incoming_cat_headers(client_cross_process_id, txn_header) + # else: + # client_cross_process_id = self._request_headers.get("x-newrelic-id") + # txn_header = self._request_headers.get("x-newrelic-transaction") + # self._process_incoming_cat_headers(client_cross_process_id, txn_header) def process_response(self, status_code, response_headers): """Processes response status and headers, extracting any diff --git a/newrelic/core/transaction_node.py b/newrelic/core/transaction_node.py index 34871d8b21..4a60e46356 100644 --- a/newrelic/core/transaction_node.py +++ b/newrelic/core/transaction_node.py @@ -77,7 +77,7 @@ "synthetics_initiator", "synthetics_attributes", "synthetics_info_header", - "is_part_of_cat", + # "is_part_of_cat", "trip_id", "path_hash", "referring_path_hash", diff --git a/newrelic/hooks/external_httplib.py b/newrelic/hooks/external_httplib.py index f9f5621287..94baa37790 100644 --- a/newrelic/hooks/external_httplib.py +++ b/newrelic/hooks/external_httplib.py @@ -93,24 +93,24 @@ def httplib_getresponse_wrapper(wrapped, instance, args, kwargs): return response -def httplib_putheader_wrapper(wrapped, instance, args, kwargs): - transaction = current_transaction() +# def httplib_putheader_wrapper(wrapped, instance, args, kwargs): +# transaction = current_transaction() - if transaction is None: - return wrapped(*args, **kwargs) +# if transaction is None: +# return wrapped(*args, **kwargs) - # Remember if we see any NR headers being set. This is only doing - # it if we see either, but they should always both be getting set. +# # # Remember if we see any NR headers being set. This is only doing +# # # it if we see either, but they should always both be getting set. - def nr_header(header, *args, **kwargs): - return header.upper() in ("NEWRELIC", "X-NEWRELIC-ID", "X-NEWRELIC-TRANSACTION") +# # def nr_header(header, *args, **kwargs): +# # return header.upper() in ("NEWRELIC", "X-NEWRELIC-ID", "X-NEWRELIC-TRANSACTION") - connection = instance +# # connection = instance - if nr_header(*args, **kwargs): - connection._nr_skip_headers = True +# # if nr_header(*args, **kwargs): +# # connection._nr_skip_headers = True - return wrapped(*args, **kwargs) +# return wrapped(*args, **kwargs) def instrument(module): @@ -125,4 +125,4 @@ def instrument(module): functools.partial(httplib_endheaders_wrapper, scheme="https", library="http"), ) wrap_function_wrapper(module, "HTTPConnection.getresponse", httplib_getresponse_wrapper) - wrap_function_wrapper(module, "HTTPConnection.putheader", httplib_putheader_wrapper) + # wrap_function_wrapper(module, "HTTPConnection.putheader", httplib_putheader_wrapper) diff --git a/newrelic/hooks/framework_aiohttp.py b/newrelic/hooks/framework_aiohttp.py index e43ffaddef..277b2fad4c 100644 --- a/newrelic/hooks/framework_aiohttp.py +++ b/newrelic/hooks/framework_aiohttp.py @@ -33,15 +33,15 @@ def aiohttp_version_info(): return tuple(int(_) for _ in aiohttp.__version__.split(".")[:2]) -def headers_preserve_casing(): - try: - from multidict import CIMultiDict - except: - return True +# def headers_preserve_casing(): +# try: +# from multidict import CIMultiDict +# except: +# return True - d = CIMultiDict() - d.update({"X-NewRelic-ID": "value"}) - return "X-NewRelic-ID" in dict(d.items()) +# d = CIMultiDict() +# d.update({"X-NewRelic-ID": "value"}) +# return "X-NewRelic-ID" in dict(d.items()) def should_ignore(transaction): @@ -303,10 +303,11 @@ def instrument_aiohttp_client_reqrep(module): version_info = aiohttp_version_info() if version_info >= (2, 0): - if headers_preserve_casing(): - cat_wrapper = _nr_aiohttp_add_cat_headers_simple_ - else: - cat_wrapper = _nr_aiohttp_add_cat_headers_ + # TODO: Verify that headers_preserve_casting is always True + # if headers_preserve_casing(): + cat_wrapper = _nr_aiohttp_add_cat_headers_simple_ + # else: + # cat_wrapper = _nr_aiohttp_add_cat_headers_ wrap_function_wrapper(module, "ClientRequest.send", cat_wrapper) @@ -381,8 +382,9 @@ async def _coro(*_args, **_kwargs): def instrument_aiohttp_web(module): global _nr_process_response - if not headers_preserve_casing(): - _nr_process_response = _nr_process_response_proxy + # TODO: Verify that this is correct/not always True + # if not headers_preserve_casing(): + # _nr_process_response = _nr_process_response_proxy wrap_function_wrapper(module, "Application._handle", _nr_request_wrapper) wrap_function_wrapper(module, "Application.__init__", _nr_aiohttp_wrap_application_init_) diff --git a/tests/agent_features/test_error_events.py b/tests/agent_features/test_error_events.py index 08195cf991..1e9a6116db 100644 --- a/tests/agent_features/test_error_events.py +++ b/tests/agent_features/test_error_events.py @@ -18,7 +18,7 @@ import webtest from testing_support.fixtures import ( # cat_enabled, - make_cross_agent_headers, + # make_cross_agent_headers, make_synthetics_headers, override_application_settings, reset_core_stats_engine, @@ -113,12 +113,13 @@ def test_transaction_error_background_task(): # @cat_enabled +# COMEBACK: Change to DT tests. @validate_error_event_sample_data(required_attrs=_intrinsic_attributes, required_user_attrs=True) def test_transaction_error_cross_agent(): test_environ = {"err_message": ERR_MESSAGE} settings = application_settings() transaction_data = [7, 1, 77, "/path-hash"] - headers = make_cross_agent_headers(transaction_data, settings.encoding_key, settings.cross_process_id) + # headers = make_cross_agent_headers(transaction_data, settings.encoding_key, settings.cross_process_id) response = fully_featured_application.get("/", headers=headers, extra_environ=test_environ) diff --git a/tests/agent_unittests/test_harvest_loop.py b/tests/agent_unittests/test_harvest_loop.py index b9c1ea25b8..109fc65360 100644 --- a/tests/agent_unittests/test_harvest_loop.py +++ b/tests/agent_unittests/test_harvest_loop.py @@ -145,7 +145,7 @@ def transaction_node(request): synthetics_initiator=None, synthetics_attributes=None, synthetics_info_header=None, - is_part_of_cat=False, + # is_part_of_cat=False, trip_id="4485b89db608aece", path_hash=None, referring_path_hash=None, diff --git a/tests/framework_tornado/_target_application.py b/tests/framework_tornado/_target_application.py index 2570b72d0e..78161e1aaa 100644 --- a/tests/framework_tornado/_target_application.py +++ b/tests/framework_tornado/_target_application.py @@ -43,9 +43,9 @@ def __init__(self, application, request, response_code=200, **kwargs): def get(self, client_cross_process_id, txn_header, flush=None): import newrelic.api.transaction as _transaction - txn = _transaction.current_transaction() - if txn: - txn._process_incoming_cat_headers(client_cross_process_id, txn_header) + # txn = _transaction.current_transaction() + # if txn: + # txn._process_incoming_cat_headers(client_cross_process_id, txn_header) if self.response_code != 200: self.set_status(self.response_code) diff --git a/tests/framework_tornado/test_externals.py b/tests/framework_tornado/test_externals.py index 1f00db5b6b..4b6733f100 100644 --- a/tests/framework_tornado/test_externals.py +++ b/tests/framework_tornado/test_externals.py @@ -20,7 +20,7 @@ from testing_support.fixtures import override_application_settings from testing_support.mock_external_http_server import MockExternalHTTPHResponseHeadersServer, MockExternalHTTPServer from testing_support.validators.validate_distributed_tracing_header import validate_distributed_tracing_header -from testing_support.validators.validate_outbound_headers import validate_outbound_headers +# from testing_support.validators.validate_outbound_headers import validate_outbound_headers from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task @@ -201,7 +201,7 @@ def _test(): # if distributed_tracing: # validate_distributed_tracing_header(header="Newrelic") # else: - validate_outbound_headers() + # validate_outbound_headers() else: # new relic shouldn't add anything to the outgoing assert "x-newrelic" not in body, body diff --git a/tests/testing_support/fixtures.py b/tests/testing_support/fixtures.py index 48291e8e99..0410085ddf 100644 --- a/tests/testing_support/fixtures.py +++ b/tests/testing_support/fixtures.py @@ -426,10 +426,10 @@ def catch_background_exceptions(wrapped, instance, args, kwargs): raise_background_exceptions.event.set() -def make_cross_agent_headers(payload, encoding_key, cat_id): - value = obfuscate(json_encode(payload), encoding_key) - id_value = obfuscate(cat_id, encoding_key) - return {"X-NewRelic-Transaction": value, "X-NewRelic-ID": id_value} +# def make_cross_agent_headers(payload, encoding_key, cat_id): +# value = obfuscate(json_encode(payload), encoding_key) +# id_value = obfuscate(cat_id, encoding_key) +# return {"X-NewRelic-Transaction": value, "X-NewRelic-ID": id_value} def make_synthetics_headers( diff --git a/tests/testing_support/validators/validate_cross_process_headers.py b/tests/testing_support/validators/validate_cross_process_headers.py index 2668fb665b..214d3c8db1 100644 --- a/tests/testing_support/validators/validate_cross_process_headers.py +++ b/tests/testing_support/validators/validate_cross_process_headers.py @@ -15,7 +15,7 @@ from newrelic.api.transaction import current_transaction from newrelic.common.object_wrapper import function_wrapper from testing_support.validators.validate_distributed_tracing_header import validate_distributed_tracing_header -from testing_support.validators.validate_outbound_headers import validate_outbound_headers +# from testing_support.validators.validate_outbound_headers import validate_outbound_headers @function_wrapper @@ -27,7 +27,7 @@ def validate_cross_process_headers(wrapped, instance, args, kwargs): if settings.distributed_tracing.enabled: validate_distributed_tracing_header() - else: - validate_outbound_headers() + # else: + # validate_outbound_headers() return result diff --git a/tests/testing_support/validators/validate_messagebroker_headers.py b/tests/testing_support/validators/validate_messagebroker_headers.py index 78f5fb7a62..e86e7188d0 100644 --- a/tests/testing_support/validators/validate_messagebroker_headers.py +++ b/tests/testing_support/validators/validate_messagebroker_headers.py @@ -15,7 +15,7 @@ from newrelic.api.transaction import current_transaction from newrelic.common.object_wrapper import function_wrapper from testing_support.validators.validate_distributed_tracing_header import validate_distributed_tracing_header -from testing_support.validators.validate_outbound_headers import validate_outbound_headers +# from testing_support.validators.validate_outbound_headers import validate_outbound_headers @function_wrapper @@ -27,7 +27,7 @@ def validate_messagebroker_headers(wrapped, instance, args, kwargs): if settings.distributed_tracing.enabled: validate_distributed_tracing_header() - else: - validate_outbound_headers(header_id="NewRelicID", header_transaction="NewRelicTransaction") + # else: + # validate_outbound_headers(header_id="NewRelicID", header_transaction="NewRelicTransaction") return result diff --git a/tests/testing_support/validators/validate_outbound_headers.py b/tests/testing_support/validators/validate_outbound_headers.py deleted file mode 100644 index 8ddb2d5cbc..0000000000 --- a/tests/testing_support/validators/validate_outbound_headers.py +++ /dev/null @@ -1,55 +0,0 @@ -# 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.api.transaction import current_transaction -from newrelic.common.encoding_utils import deobfuscate, json_decode - -OUTBOUND_TRACE_KEYS_REQUIRED = ("ty", "ac", "ap", "tr", "pr", "sa", "ti") - - -def validate_outbound_headers(header_id="X-NewRelic-ID", header_transaction="X-NewRelic-Transaction"): - transaction = current_transaction() - headers = transaction._test_request_headers - settings = transaction.settings - encoding_key = settings.encoding_key - - assert header_id in headers - - values = headers[header_id] - if isinstance(values, list): - assert len(values) == 1, headers - assert isinstance(values[0], str) - value = values[0] - else: - value = values - - cross_process_id = deobfuscate(value, encoding_key) - assert cross_process_id == settings.cross_process_id - - assert header_transaction in headers - - values = headers[header_transaction] - if isinstance(values, list): - assert len(values) == 1, headers - assert isinstance(values[0], str) - value = values[0] - else: - value = values - - (guid, record_tt, trip_id, path_hash) = json_decode(deobfuscate(value, encoding_key)) - - assert guid == transaction.guid - assert record_tt == transaction.record_tt - assert trip_id == transaction.trip_id - assert path_hash == transaction.path_hash From 695d2b973fe639fbedffbe7fc80edf91a93eb263 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Tue, 9 Sep 2025 15:28:44 -0700 Subject: [PATCH 48/95] Remove path_hash --- newrelic/api/cat_header_mixin.py | 2 +- newrelic/api/transaction.py | 34 ++++++++++++---------- newrelic/common/encoding_utils.py | 22 +++++++------- newrelic/core/transaction_node.py | 20 ++++++------- newrelic/hooks/framework_tornado.py | 6 ++-- tests/agent_unittests/test_harvest_loop.py | 6 ++-- tests/framework_aiohttp/test_server_cat.py | 21 ++++++------- 7 files changed, 57 insertions(+), 54 deletions(-) diff --git a/newrelic/api/cat_header_mixin.py b/newrelic/api/cat_header_mixin.py index a6675ab3a5..8008423778 100644 --- a/newrelic/api/cat_header_mixin.py +++ b/newrelic/api/cat_header_mixin.py @@ -15,7 +15,7 @@ from newrelic.common.encoding_utils import ( base64_decode, base64_encode, - # deobfuscate, + deobfuscate, json_decode, json_encode, obfuscate, diff --git a/newrelic/api/transaction.py b/newrelic/api/transaction.py index ec24076b2e..21d4dceace 100644 --- a/newrelic/api/transaction.py +++ b/newrelic/api/transaction.py @@ -37,7 +37,7 @@ convert_to_cat_metadata_value, deobfuscate, ensure_str, - generate_path_hash, + # generate_path_hash, json_decode, json_encode, obfuscate, @@ -295,8 +295,8 @@ def __init__(self, application, enabled=None, source=None): self.referring_transaction_guid = None self.record_tt = False self._trip_id = None - self._referring_path_hash = None - self._alternate_path_hashes = {} + # self._referring_path_hash = None + # self._alternate_path_hashes = {} # self.is_part_of_cat = False # Synthetics Header @@ -612,9 +612,9 @@ def __exit__(self, exc, value, tb): synthetics_info_header=self.synthetics_info_header, # is_part_of_cat=self.is_part_of_cat, trip_id=self.trip_id, - path_hash=self.path_hash, - referring_path_hash=self._referring_path_hash, - alternate_path_hashes=self.alternate_path_hashes, + # path_hash=self.path_hash, + # referring_path_hash=self._referring_path_hash, + # alternate_path_hashes=self.alternate_path_hashes, trace_intrinsics=self.trace_intrinsics, distributed_trace_intrinsics=self.distributed_trace_intrinsics, agent_attributes=agent_attributes, @@ -740,13 +740,14 @@ def trip_id(self): def trace_id(self): return self._trace_id - @property - def alternate_path_hashes(self): - """Return the alternate path hashes but not including the current path - hash. + # @property + # def alternate_path_hashes(self): + # """Return the alternate path hashes but not including the current path + # hash. - """ - return sorted(set(self._alternate_path_hashes.values()) - {self.path_hash}) + # """ + # # return sorted(set(self._alternate_path_hashes.values()) - {self.path_hash}) + # return sorted(set(self._alternate_path_hashes.values()) - {None}) # @property # def path_hash(self): @@ -759,8 +760,9 @@ def alternate_path_hashes(self): # """ - # if not self.is_part_of_cat: - # return None + # # if not self.is_part_of_cat: + # # return None + # return None # identifier = f"{self.application.name};{self.path}" @@ -839,8 +841,8 @@ def trace_intrinsics(self): i_attrs["client_cross_process_id"] = self.client_cross_process_id if self.trip_id: i_attrs["trip_id"] = self.trip_id - if self.path_hash: - i_attrs["path_hash"] = self.path_hash + # if self.path_hash: + # i_attrs["path_hash"] = self.path_hash if self.synthetics_resource_id: i_attrs["synthetics_resource_id"] = self.synthetics_resource_id if self.synthetics_job_id: diff --git a/newrelic/common/encoding_utils.py b/newrelic/common/encoding_utils.py index 6f7e9d199f..38f81ea397 100644 --- a/newrelic/common/encoding_utils.py +++ b/newrelic/common/encoding_utils.py @@ -232,21 +232,21 @@ def unpack_field(field): return data -def generate_path_hash(name, seed): - """Algorithm for generating the path hash: - * Rotate Left the seed value and truncate to 32-bits. - * Compute the md5 digest of the name, take the last 4 bytes (32-bits). - * XOR the 4 bytes of digest with the seed and return the result. +# def generate_path_hash(name, seed): +# """Algorithm for generating the path hash: +# * Rotate Left the seed value and truncate to 32-bits. +# * Compute the md5 digest of the name, take the last 4 bytes (32-bits). +# * XOR the 4 bytes of digest with the seed and return the result. - """ +# """ - rotated = ((seed << 1) | (seed >> 31)) & 0xFFFFFFFF +# rotated = ((seed << 1) | (seed >> 31)) & 0xFFFFFFFF - if not isinstance(name, bytes): - name = name.encode("UTF-8") +# if not isinstance(name, bytes): +# name = name.encode("UTF-8") - path_hash = rotated ^ int(hashlib.md5(name).hexdigest()[-8:], base=16) # noqa: S324 - return f"{path_hash:08x}" +# path_hash = rotated ^ int(hashlib.md5(name).hexdigest()[-8:], base=16) # noqa: S324 +# return f"{path_hash:08x}" def base64_encode(text): diff --git a/newrelic/core/transaction_node.py b/newrelic/core/transaction_node.py index 4a60e46356..5468065faf 100644 --- a/newrelic/core/transaction_node.py +++ b/newrelic/core/transaction_node.py @@ -79,9 +79,9 @@ "synthetics_info_header", # "is_part_of_cat", "trip_id", - "path_hash", - "referring_path_hash", - "alternate_path_hashes", + # "path_hash", + # "referring_path_hash", + # "alternate_path_hashes", "trace_intrinsics", "agent_attributes", "distributed_trace_intrinsics", @@ -470,14 +470,14 @@ def _add_if_not_empty(key, value): if self.errors: intrinsics["error"] = True - if self.path_hash: - intrinsics["nr.guid"] = self.guid - intrinsics["nr.tripId"] = self.trip_id - intrinsics["nr.pathHash"] = self.path_hash + # if self.path_hash: + # intrinsics["nr.guid"] = self.guid + # intrinsics["nr.tripId"] = self.trip_id + # intrinsics["nr.pathHash"] = self.path_hash - _add_if_not_empty("nr.referringPathHash", self.referring_path_hash) - _add_if_not_empty("nr.alternatePathHashes", ",".join(self.alternate_path_hashes)) - _add_if_not_empty("nr.referringTransactionGuid", self.referring_transaction_guid) + # _add_if_not_empty("nr.referringPathHash", self.referring_path_hash) + # _add_if_not_empty("nr.alternatePathHashes", ",".join(self.alternate_path_hashes)) + # _add_if_not_empty("nr.referringTransactionGuid", self.referring_transaction_guid) if self.synthetics_resource_id: intrinsics["nr.guid"] = self.guid diff --git a/newrelic/hooks/framework_tornado.py b/newrelic/hooks/framework_tornado.py index c80a45a585..a88c66a1b0 100644 --- a/newrelic/hooks/framework_tornado.py +++ b/newrelic/hooks/framework_tornado.py @@ -251,9 +251,9 @@ async def wrapper(req, raise_error): except Exception as e: response = getattr(e, "response", None) raise - finally: - if response: - trace.process_response_headers(response.headers.get_all()) + # finally: + # if response: + # trace.process_response_headers(response.headers.get_all()) return response return wrapper diff --git a/tests/agent_unittests/test_harvest_loop.py b/tests/agent_unittests/test_harvest_loop.py index 109fc65360..fb1fa0d5a1 100644 --- a/tests/agent_unittests/test_harvest_loop.py +++ b/tests/agent_unittests/test_harvest_loop.py @@ -147,9 +147,9 @@ def transaction_node(request): synthetics_info_header=None, # is_part_of_cat=False, trip_id="4485b89db608aece", - path_hash=None, - referring_path_hash=None, - alternate_path_hashes=[], + # path_hash=None, + # referring_path_hash=None, + # alternate_path_hashes=[], trace_intrinsics={}, distributed_trace_intrinsics={}, agent_attributes=[], diff --git a/tests/framework_aiohttp/test_server_cat.py b/tests/framework_aiohttp/test_server_cat.py index 3fc651ad19..9d4cf581ce 100644 --- a/tests/framework_aiohttp/test_server_cat.py +++ b/tests/framework_aiohttp/test_server_cat.py @@ -178,11 +178,11 @@ def _test(): }, } -unexpected_attributes = { - "agent": [], - "user": [], - "intrinsic": ["grandparentId", "cross_process_id", "nr.tripId", "nr.pathHash"], -} +# unexpected_attributes = { +# "agent": [], +# "user": [], +# "intrinsic": ["grandparentId", "cross_process_id", "nr.tripId", "nr.pathHash"], +# } @pytest.mark.parametrize("uri,metric_name", test_uris) @@ -191,11 +191,11 @@ async def fetch(): headers = {"newrelic": json.dumps(inbound_payload)} resp = await aiohttp_app.client.request("GET", uri, headers=headers) - # better cat does not send a response in the headers - assert "newrelic" not in resp.headers + # # better cat does not send a response in the 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 + # # old-cat headers should not be in the response + # 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 @@ -206,7 +206,8 @@ async 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) + @validate_transaction_event_attributes(expected_attributes) + # @validate_transaction_event_attributes(expected_attributes, unexpected_attributes) @override_application_settings( { "account_id": "33", From c4b6037c02d1c9744e08eca05054ea560d96f576 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Tue, 9 Sep 2025 15:54:26 -0700 Subject: [PATCH 49/95] Fix tornado tests --- .../framework_tornado/_target_application.py | 46 ++--- tests/framework_tornado/test_externals.py | 158 ++++++++---------- tests/framework_tornado/test_inbound_cat.py | 117 ------------- tests/framework_tornado/test_inbound_dt.py | 125 ++++++++++++++ 4 files changed, 220 insertions(+), 226 deletions(-) delete mode 100644 tests/framework_tornado/test_inbound_cat.py create mode 100644 tests/framework_tornado/test_inbound_dt.py diff --git a/tests/framework_tornado/_target_application.py b/tests/framework_tornado/_target_application.py index 78161e1aaa..396f357570 100644 --- a/tests/framework_tornado/_target_application.py +++ b/tests/framework_tornado/_target_application.py @@ -35,33 +35,33 @@ def get_status(self, *args, **kwargs): raise ValueError("Bad Status") -class ProcessCatHeadersHandler(tornado.web.RequestHandler): - def __init__(self, application, request, response_code=200, **kwargs): - super().__init__(application, request, **kwargs) - self.response_code = response_code +# class ProcessCatHeadersHandler(tornado.web.RequestHandler): +# def __init__(self, application, request, response_code=200, **kwargs): +# super().__init__(application, request, **kwargs) +# self.response_code = response_code - def get(self, client_cross_process_id, txn_header, flush=None): - import newrelic.api.transaction as _transaction +# def get(self, client_cross_process_id, txn_header, flush=None): +# import newrelic.api.transaction as _transaction - # txn = _transaction.current_transaction() - # if txn: - # txn._process_incoming_cat_headers(client_cross_process_id, txn_header) +# # txn = _transaction.current_transaction() +# # if txn: +# # txn._process_incoming_cat_headers(client_cross_process_id, txn_header) - if self.response_code != 200: - self.set_status(self.response_code) - return +# if self.response_code != 200: +# self.set_status(self.response_code) +# return - self.write("Hello, world") +# self.write("Hello, world") - if flush == "flush": - # Force a flush prior to calling finish - # This causes the headers to get written immediately. The tests - # which hit this endpoint will check that the response has been - # properly processed even though we send the headers here. - self.flush() +# if flush == "flush": +# # Force a flush prior to calling finish +# # This causes the headers to get written immediately. The tests +# # which hit this endpoint will check that the response has been +# # properly processed even though we send the headers here. +# self.flush() - # change the headers to garbage - self.set_header("Content-Type", "garbage") +# # change the headers to garbage +# self.set_header("Content-Type", "garbage") class EchoHeaderHandler(tornado.web.RequestHandler): @@ -250,8 +250,8 @@ def make_app(custom=False): (r"/init", InitializeHandler), (r"/html-insertion", HTMLInsertionHandler), (r"/bad-get-status", BadGetStatusHandler), - (r"/force-cat-response/(\S+)/(\S+)/(\S+)", ProcessCatHeadersHandler), - (r"/304-cat-response/(\S+)/(\S+)", ProcessCatHeadersHandler, {"response_code": 304}), + # (r"/force-cat-response/(\S+)/(\S+)/(\S+)", ProcessCatHeadersHandler), + # (r"/304-cat-response/(\S+)/(\S+)", ProcessCatHeadersHandler, {"response_code": 304}), (r"/echo-headers", EchoHeaderHandler), (r"/native-simple", NativeSimpleHandler), (r"/multi-trace", MultiTraceHandler), diff --git a/tests/framework_tornado/test_externals.py b/tests/framework_tornado/test_externals.py index 4b6733f100..9553ca4140 100644 --- a/tests/framework_tornado/test_externals.py +++ b/tests/framework_tornado/test_externals.py @@ -123,28 +123,14 @@ def _make_request(): ("HTTPClient", True), ], ) -@pytest.mark.parametrize( - "user_header,span_events,distributed_tracing", - [ - (None, True, True), - (None, False, True), - ], -) -# @pytest.mark.parametrize('cat_enabled,user_header', [ -# (True, None), -# (True, 'X-NewRelic-ID'), -# (True, 'X-NewRelic-Transaction'), -# (False, None), -# ]) +@pytest.mark.parametrize("span_events", [True, False]) @pytest.mark.parametrize("request_type", ["uri", "class"]) @pytest.mark.parametrize("num_requests", [1, 2]) def test_httpclient( # cat_enabled, request_type, client_class, - # user_header, num_requests, - distributed_tracing, span_events, external, as_kwargs, @@ -155,7 +141,7 @@ def test_httpclient( @override_application_settings( { - "distributed_tracing.enabled": distributed_tracing, + "distributed_tracing.enabled": True, "span_events.enabled": span_events, # "cross_application_tracer.enabled": not distributed_tracing, } @@ -202,11 +188,11 @@ def _test(): # validate_distributed_tracing_header(header="Newrelic") # else: # validate_outbound_headers() - else: - # new relic shouldn't add anything to the outgoing - assert "x-newrelic" not in body, body + # else: + # # new relic shouldn't add anything to the outgoing + # assert "x-newrelic" not in body, body - assert "X-NewRelic-App-Data" not in headers + # assert "X-NewRelic-App-Data" not in headers _test() @@ -214,72 +200,72 @@ def _test(): CAT_RESPONSE_CODE = None -def cat_response_handler(self): - # payload - # ( - # u'1#1', u'WebTransaction/Function/app:beep', - # 0, 1.23, -1, - # 'dd4a810b7cb7f937', - # False, - # ) - cat_response_header = ( - "X-NewRelic-App-Data", - "ahACFwQUGxpuVVNmQVVbRVZbTVleXBxyQFhUTFBfXx1SREUMVV1cQBMeAxgEGAULFR0AHhFQUQJWAAgAUwVQVgJQDgsOEh1UUlhGU2o=", - ) - self.send_response(CAT_RESPONSE_CODE) - self.send_header(*cat_response_header) - self.end_headers() - self.wfile.write(b"Example Data") - - -@pytest.fixture(scope="module") -def cat_response_server(): - external = MockExternalHTTPServer(handler=cat_response_handler) - with external: - yield external - - -@pytest.mark.parametrize("client_class", ["AsyncHTTPClient", "CurlAsyncHTTPClient", "HTTPClient"]) -@pytest.mark.parametrize("dt_enabled", [True, False]) -@pytest.mark.parametrize("request_type", ["uri", "class"]) -@pytest.mark.parametrize("response_code,raise_error", [(500, True), (500, False), (200, False)]) -def test_client_cat_response_processing( - dt_enabled, request_type, client_class, raise_error, response_code, cat_response_server -): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = response_code - - _custom_settings = { - "cross_process_id": "1#1", - "encoding_key": ENCODING_KEY, - "trusted_account_ids": [1], - # "cross_application_tracer.enabled": cat_enabled, - "distributed_tracing.enabled": dt_enabled, - "transaction_tracer.transaction_threshold": 0.0, - } - - port = cat_response_server.port - expected_metrics = None - - @validate_transaction_metrics( - "make_request", background_task=True, rollup_metrics=expected_metrics, scoped_metrics=expected_metrics - ) - @override_application_settings(_custom_settings) - def _test(): - import tornado - import tornado.httpclient - - try: - response = make_request(port, request_type, client_class, raise_error=raise_error) - except tornado.httpclient.HTTPError as e: - assert raise_error - response = e.response - else: - assert not raise_error - - assert response.code == response_code - - _test() +# def cat_response_handler(self): +# # payload +# # ( +# # u'1#1', u'WebTransaction/Function/app:beep', +# # 0, 1.23, -1, +# # 'dd4a810b7cb7f937', +# # False, +# # ) +# cat_response_header = ( +# "X-NewRelic-App-Data", +# "ahACFwQUGxpuVVNmQVVbRVZbTVleXBxyQFhUTFBfXx1SREUMVV1cQBMeAxgEGAULFR0AHhFQUQJWAAgAUwVQVgJQDgsOEh1UUlhGU2o=", +# ) +# self.send_response(CAT_RESPONSE_CODE) +# self.send_header(*cat_response_header) +# self.end_headers() +# self.wfile.write(b"Example Data") + + +# @pytest.fixture(scope="module") +# def cat_response_server(): +# external = MockExternalHTTPServer(handler=cat_response_handler) +# with external: +# yield external + + +# @pytest.mark.parametrize("client_class", ["AsyncHTTPClient", "CurlAsyncHTTPClient", "HTTPClient"]) +# @pytest.mark.parametrize("dt_enabled", [True, False]) +# @pytest.mark.parametrize("request_type", ["uri", "class"]) +# @pytest.mark.parametrize("response_code,raise_error", [(500, True), (500, False), (200, False)]) +# def test_client_cat_response_processing( +# dt_enabled, request_type, client_class, raise_error, response_code, cat_response_server +# ): +# global CAT_RESPONSE_CODE +# CAT_RESPONSE_CODE = response_code + +# _custom_settings = { +# "cross_process_id": "1#1", +# "encoding_key": ENCODING_KEY, +# "trusted_account_ids": [1], +# # "cross_application_tracer.enabled": cat_enabled, +# "distributed_tracing.enabled": dt_enabled, +# "transaction_tracer.transaction_threshold": 0.0, +# } + +# port = cat_response_server.port +# expected_metrics = None + +# @validate_transaction_metrics( +# "make_request", background_task=True, rollup_metrics=expected_metrics, scoped_metrics=expected_metrics +# ) +# @override_application_settings(_custom_settings) +# def _test(): +# import tornado +# import tornado.httpclient + +# try: +# response = make_request(port, request_type, client_class, raise_error=raise_error) +# except tornado.httpclient.HTTPError as e: +# assert raise_error +# response = e.response +# else: +# assert not raise_error + +# assert response.code == response_code + +# _test() @pytest.mark.parametrize("client_class", ["AsyncHTTPClient", "CurlAsyncHTTPClient", "HTTPClient"]) diff --git a/tests/framework_tornado/test_inbound_cat.py b/tests/framework_tornado/test_inbound_cat.py deleted file mode 100644 index fb935f174a..0000000000 --- a/tests/framework_tornado/test_inbound_cat.py +++ /dev/null @@ -1,117 +0,0 @@ -# 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 json - -import pytest -from testing_support.fixtures import make_cross_agent_headers, override_application_settings -from testing_support.validators.validate_transaction_event_attributes import validate_transaction_event_attributes -from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics - -ENCODING_KEY = "1234567890123456789012345678901234567890" - - -_custom_settings = { - "cross_process_id": "1#1", - "encoding_key": ENCODING_KEY, - "trusted_account_ids": [1], - # "cross_application_tracer.enabled": True, - "distributed_tracing.enabled": False, - "transaction_tracer.transaction_threshold": 0.0, -} - - -@override_application_settings(_custom_settings) -@validate_transaction_event_attributes( - required_params={"agent": (), "user": (), "intrinsic": ()}, - forgone_params={"agent": (), "user": (), "intrinsic": ()}, - exact_attrs={ - "agent": {"response.status": "200", "response.headers.contentType": "text/html; charset=UTF-8"}, - "user": {}, - "intrinsic": {}, - }, -) -@pytest.mark.parametrize("manual_flush", ["flush", "no-flush"]) -def test_response_to_inbound_cat(app, manual_flush): - payload = ("1#1", "WebTransaction/Function/app:beep", 0, 1.23, -1, "dd4a810b7cb7f937", False) - headers = make_cross_agent_headers(payload, ENCODING_KEY, "1#1") - - client_cross_process_id = headers["X-NewRelic-ID"] - txn_header = headers["X-NewRelic-Transaction"] - - response = app.fetch(f"/force-cat-response/{client_cross_process_id}/{txn_header}/{manual_flush}") - assert response.code == 200 - assert "X-NewRelic-App-Data" in list(response.headers.keys()) - - -@validate_transaction_event_attributes( - required_params={"agent": (), "user": (), "intrinsic": ()}, - forgone_params={"agent": ("response.headers",), "user": (), "intrinsic": ()}, - exact_attrs={"agent": {"request.method": "GET", "response.status": "304"}, "user": {}, "intrinsic": {}}, -) -@override_application_settings(_custom_settings) -def test_cat_headers_not_inserted(app): - payload = ("1#1", "WebTransaction/Function/app:beep", 0, 1.23, -1, "dd4a810b7cb7f937", False) - headers = make_cross_agent_headers(payload, ENCODING_KEY, "1#1") - - client_cross_process_id = headers["X-NewRelic-ID"] - txn_header = headers["X-NewRelic-Transaction"] - - response = app.fetch(f"/304-cat-response/{client_cross_process_id}/{txn_header}") - assert response.code == 304 - assert "X-NewRelic-App-Data" not in list(response.headers.keys()) - - -@override_application_settings(_custom_settings) -@validate_transaction_metrics( - "_target_application:SimpleHandler.get", rollup_metrics=[("ClientApplication/1#1/all", 1)] -) -@validate_transaction_event_attributes( - required_params={"agent": [], "user": [], "intrinsic": []}, - forgone_params={"agent": [], "user": [], "intrinsic": []}, - exact_attrs={"agent": {}, "user": {}, "intrinsic": {"nr.referringTransactionGuid": "b854df4feb2b1f06"}}, -) -def test_inbound_cat_metrics_and_intrinsics(app): - payload = ["b854df4feb2b1f06", False, "7e249074f277923d", "5d2957be"] - headers = make_cross_agent_headers(payload, ENCODING_KEY, "1#1") - - response = app.fetch("/simple", headers=headers) - assert response.code == 200 - - -@override_application_settings( - {"account_id": 1, "trusted_account_key": 1, "primary_application_id": 1, "distributed_tracing.enabled": True} -) -@validate_transaction_metrics( - "_target_application:SimpleHandler.get", - rollup_metrics=(("Supportability/DistributedTrace/AcceptPayload/Success", 1),), -) -def test_inbound_dt(app): - PAYLOAD = { - "v": [0, 1], - "d": { - "ac": 1, - "ap": 1, - "id": "7d3efb1b173fecfa", - "tx": "e8b91a159289ff74", - "pr": 1.234567, - "sa": True, - "ti": 1518469636035, - "tr": "d6b4ba0c3a712ca", - "ty": "App", - }, - } - headers = {"newrelic": json.dumps(PAYLOAD)} - response = app.fetch("/simple", headers=headers) - assert response.code == 200 diff --git a/tests/framework_tornado/test_inbound_dt.py b/tests/framework_tornado/test_inbound_dt.py new file mode 100644 index 0000000000..319fc00229 --- /dev/null +++ b/tests/framework_tornado/test_inbound_dt.py @@ -0,0 +1,125 @@ +# 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 json + +from testing_support.fixtures import override_application_settings +from testing_support.validators.validate_transaction_event_attributes import validate_transaction_event_attributes +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics + +# ENCODING_KEY = "1234567890123456789012345678901234567890" + + +# _custom_settings = { +# "cross_process_id": "1#1", +# "encoding_key": ENCODING_KEY, +# "trusted_account_ids": [1], +# # "cross_application_tracer.enabled": True, +# "distributed_tracing.enabled": False, +# "transaction_tracer.transaction_threshold": 0.0, +# } + + +# @override_application_settings(_custom_settings) +# @validate_transaction_event_attributes( +# required_params={"agent": (), "user": (), "intrinsic": ()}, +# forgone_params={"agent": (), "user": (), "intrinsic": ()}, +# exact_attrs={ +# "agent": {"response.status": "200", "response.headers.contentType": "text/html; charset=UTF-8"}, +# "user": {}, +# "intrinsic": {}, +# }, +# ) +# @pytest.mark.parametrize("manual_flush", ["flush", "no-flush"]) +# def test_response_to_inbound_cat(app, manual_flush): +# payload = ("1#1", "WebTransaction/Function/app:beep", 0, 1.23, -1, "dd4a810b7cb7f937", False) +# headers = make_cross_agent_headers(payload, ENCODING_KEY, "1#1") + +# client_cross_process_id = headers["X-NewRelic-ID"] +# txn_header = headers["X-NewRelic-Transaction"] + +# response = app.fetch(f"/force-cat-response/{client_cross_process_id}/{txn_header}/{manual_flush}") +# assert response.code == 200 +# assert "X-NewRelic-App-Data" in list(response.headers.keys()) + + +# # @validate_transaction_event_attributes( +# # required_params={"agent": (), "user": (), "intrinsic": ()}, +# # forgone_params={"agent": ("response.headers",), "user": (), "intrinsic": ()}, +# # exact_attrs={"agent": {"request.method": "GET", "response.status": "304"}, "user": {}, "intrinsic": {}}, +# # ) +# # @override_application_settings(_custom_settings) +# # def test_cat_headers_not_inserted(app): +# # payload = ("1#1", "WebTransaction/Function/app:beep", 0, 1.23, -1, "dd4a810b7cb7f937", False) +# # headers = make_cross_agent_headers(payload, ENCODING_KEY, "1#1") + +# # client_cross_process_id = headers["X-NewRelic-ID"] +# # txn_header = headers["X-NewRelic-Transaction"] + +# # response = app.fetch(f"/304-cat-response/{client_cross_process_id}/{txn_header}") +# # assert response.code == 304 +# # assert "X-NewRelic-App-Data" not in list(response.headers.keys()) + + +# @override_application_settings(_custom_settings) +# @validate_transaction_metrics( +# "_target_application:SimpleHandler.get", rollup_metrics=[("ClientApplication/1#1/all", 1)] +# ) +# @validate_transaction_event_attributes( +# required_params={"agent": [], "user": [], "intrinsic": []}, +# forgone_params={"agent": [], "user": [], "intrinsic": []}, +# exact_attrs={"agent": {}, "user": {}, "intrinsic": {"nr.referringTransactionGuid": "b854df4feb2b1f06"}}, +# ) +# def test_inbound_cat_metrics_and_intrinsics(app): +# payload = ["b854df4feb2b1f06", False, "7e249074f277923d", "5d2957be"] +# headers = make_cross_agent_headers(payload, ENCODING_KEY, "1#1") + +# response = app.fetch("/simple", headers=headers) +# assert response.code == 200 + + +@validate_transaction_event_attributes( + required_params={"agent": (), "user": (), "intrinsic": ()}, + forgone_params={"agent": (), "user": (), "intrinsic": ()}, + exact_attrs={ + "agent": {"response.status": "200", "response.headers.contentType": "text/html; charset=UTF-8"}, + "user": {}, + "intrinsic": {}, + }, +) +@override_application_settings( + {"account_id": 1, "trusted_account_key": 1, "primary_application_id": 1, "distributed_tracing.enabled": True} +) +@validate_transaction_metrics( + "_target_application:SimpleHandler.get", + rollup_metrics=(("Supportability/DistributedTrace/AcceptPayload/Success", 1),), +) +def test_inbound_dt(app): + PAYLOAD = { + "v": [0, 1], + "d": { + "ac": 1, + "ap": 1, + "id": "7d3efb1b173fecfa", + "tx": "e8b91a159289ff74", + "pr": 1.234567, + "sa": True, + "ti": 1518469636035, + "tr": "d6b4ba0c3a712ca", + "ty": "App", + }, + } + headers = {"newrelic": json.dumps(PAYLOAD)} + response = app.fetch("/simple", headers=headers) + assert response.code == 200 From aaac4cbf7515ce57cee573a0cf5e98844f288b83 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Tue, 9 Sep 2025 17:08:49 -0700 Subject: [PATCH 50/95] Fix aiohttp tests --- tests/framework_aiohttp/conftest.py | 3 +- tests/framework_aiohttp/test_client_cat.py | 227 --------------------- tests/framework_aiohttp/test_server_cat.py | 222 -------------------- tests/framework_aiohttp/test_server_dt.py | 222 ++++++++++++++++++++ 4 files changed, 224 insertions(+), 450 deletions(-) delete mode 100644 tests/framework_aiohttp/test_client_cat.py delete mode 100644 tests/framework_aiohttp/test_server_cat.py create mode 100644 tests/framework_aiohttp/test_server_dt.py diff --git a/tests/framework_aiohttp/conftest.py b/tests/framework_aiohttp/conftest.py index 3c2a783b24..cfcea49122 100644 --- a/tests/framework_aiohttp/conftest.py +++ b/tests/framework_aiohttp/conftest.py @@ -123,7 +123,8 @@ def respond_with_cat_header(self): self.end_headers() self.wfile.write(b"") - with MockExternalHTTPServer(handler=respond_with_cat_header) as server: + # with MockExternalHTTPServer(handler=respond_with_cat_header) as server: + with MockExternalHTTPServer() as server: yield (server, response_values) diff --git a/tests/framework_aiohttp/test_client_cat.py b/tests/framework_aiohttp/test_client_cat.py deleted file mode 100644 index 61a73d96aa..0000000000 --- a/tests/framework_aiohttp/test_client_cat.py +++ /dev/null @@ -1,227 +0,0 @@ -# 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 asyncio - -import aiohttp -import pytest -from testing_support.external_fixtures import create_incoming_headers -from testing_support.fixtures import override_application_settings -# from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers -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 -from newrelic.api.external_trace import ExternalTrace -from newrelic.api.transaction import current_transaction - -version_info = tuple(int(_) for _ in aiohttp.__version__.split(".")[:2]) - -if version_info < (2, 0): - _expected_error_class = aiohttp.errors.HttpProcessingError -else: - _expected_error_class = aiohttp.client_exceptions.ClientResponseError - - -async def fetch(url, headers=None, raise_for_status=False, connector=None): - kwargs = {} - if version_info >= (2, 0): - kwargs = {"raise_for_status": raise_for_status} - - session = aiohttp.ClientSession(connector=connector, **kwargs) - request = session._request("GET", url, headers=headers) - headers = {} - - try: - response = await request - if raise_for_status and version_info < (2, 0): - response.raise_for_status() - except _expected_error_class: - return headers - - response_text = await response.text() - for header in response_text.split("\n"): - if not header: - continue - try: - h, v = header.split(":", 1) - except ValueError: - continue - headers[h.strip()] = v.strip() - f = session.close() - await asyncio.ensure_future(f) - return headers - - -# @pytest.mark.parametrize("cat_enabled", (True, False)) -@pytest.mark.parametrize("distributed_tracing", (True, False)) -@pytest.mark.parametrize("span_events", (True, False)) -def test_outbound_cross_process_headers(event_loop, distributed_tracing, span_events, mock_header_server): -# def test_outbound_cross_process_headers(event_loop, cat_enabled, distributed_tracing, span_events, mock_header_server): - @background_task(name="test_outbound_cross_process_headers") - async def _test(): - headers = await fetch(f"http://127.0.0.1:{mock_header_server.port}") - - transaction = current_transaction() - transaction._test_request_headers = headers - - if distributed_tracing: - assert "newrelic" in headers - # elif cat_enabled: - # assert ExternalTrace.cat_id_key in headers - # assert ExternalTrace.cat_transaction_key in headers - else: - assert "newrelic" not in headers - assert ExternalTrace.cat_id_key not in headers - assert ExternalTrace.cat_transaction_key not in headers - - def _validate(): - pass - - # if cat_enabled or distributed_tracing: - # _validate = validate_cross_process_headers(_validate) - - _validate() - - @override_application_settings( - { - # "cross_application_tracer.enabled": cat_enabled, - "distributed_tracing.enabled": distributed_tracing, - "span_events.enabled": span_events, - } - ) - def test(): - event_loop.run_until_complete(_test()) - - test() - - -_nr_key = ExternalTrace.cat_id_key -_customer_headers_tests = [{"Test-Header": "Test Data 1"}, {_nr_key.title(): "Test Data 2"}] - - -@pytest.mark.parametrize("customer_headers", _customer_headers_tests) -def test_outbound_cross_process_headers_custom_headers(event_loop, customer_headers, mock_header_server): - headers = event_loop.run_until_complete( - background_task()(fetch)(f"http://127.0.0.1:{mock_header_server.port}", customer_headers.copy()) - ) - - # always honor customer headers - for expected_header, expected_value in customer_headers.items(): - assert headers.get(expected_header) == expected_value - - -def test_outbound_cross_process_headers_no_txn(event_loop, mock_header_server): - headers = event_loop.run_until_complete(fetch(f"http://127.0.0.1:{mock_header_server.port}")) - - assert not headers.get(ExternalTrace.cat_id_key) - assert not headers.get(ExternalTrace.cat_transaction_key) - - -def test_outbound_cross_process_headers_exception(event_loop, mock_header_server): - @background_task(name="test_outbound_cross_process_headers_exception") - async def test(): - # corrupt the transaction object to force an error - transaction = current_transaction() - guid = transaction.guid - delattr(transaction, "guid") - - try: - headers = await fetch(f"http://127.0.0.1:{mock_header_server.port}") - - assert not headers.get(ExternalTrace.cat_id_key) - assert not headers.get(ExternalTrace.cat_transaction_key) - finally: - transaction.guid = guid - - event_loop.run_until_complete(test()) - - -class PoorResolvingConnector(aiohttp.TCPConnector): - async def _resolve_host(self, host, port, *args, **kwargs): - res = [{"hostname": host, "host": host, "port": 1234, "family": self._family, "proto": 0, "flags": 0}] - hosts = await super()._resolve_host(host, port, *args, **kwargs) - res.extend(hosts) - return res - - -# @pytest.mark.parametrize("cat_enabled", [True, False]) -@pytest.mark.parametrize("response_code", [200, 404]) -@pytest.mark.parametrize("raise_for_status", [True, False]) -@pytest.mark.parametrize("connector_class", [None, PoorResolvingConnector]) # None will use default -def test_process_incoming_headers( - event_loop, response_code, raise_for_status, connector_class, mock_external_http_server - # event_loop, cat_enabled, response_code, raise_for_status, connector_class, mock_external_http_server -): - # It was discovered via packnsend that the `throw` method of the `_request` - # coroutine is used in the case of poorly resolved hosts. An older version - # of the instrumentation ended the ExternalTrace anytime `throw` was called - # which meant that incoming CAT headers were never processed. The - # `PoorResolvingConnector` connector in this test ensures that `throw` is - # always called and thus makes sure the trace is not ended before - # StopIteration is called. - server, response_values = mock_external_http_server - address = f"http://127.0.0.1:{server.port}" - port = server.port - - _test_cross_process_response_scoped_metrics = [ - (f"ExternalTransaction/127.0.0.1:{port}/1#2/test", None) - ] - - _test_cross_process_response_rollup_metrics = [ - ("External/all", 1), - ("External/allOther", 1), - (f"External/127.0.0.1:{port}/all", 1), - (f"ExternalApp/127.0.0.1:{port}/1#2/all", None), - (f"ExternalTransaction/127.0.0.1:{port}/1#2/test", None), - ] - - _test_cross_process_response_external_node_params = [ - ("cross_process_id", "1#2"), - ("external_txn_name", "test"), - ("transaction_guid", "0123456789012345"), - ] - - _test_cross_process_response_external_node_forgone_params = [ - k for k, v in _test_cross_process_response_external_node_params - ] - - @background_task(name="test_process_incoming_headers") - async def _test(): - transaction = current_transaction() - headers = create_incoming_headers(transaction) - - response_values.append((headers, response_code)) - - connector = connector_class() if connector_class else None - - await fetch(address, raise_for_status=raise_for_status, connector=connector) - - @override_application_settings( - {"distributed_tracing.enabled": False} - ) - @validate_transaction_metrics( - "test_process_incoming_headers", - scoped_metrics=_test_cross_process_response_scoped_metrics, - rollup_metrics=_test_cross_process_response_rollup_metrics, - background_task=True, - ) - @validate_external_node_params( - params=[], - forgone_params=_test_cross_process_response_external_node_forgone_params, - ) - def test(): - event_loop.run_until_complete(_test()) - - test() diff --git a/tests/framework_aiohttp/test_server_cat.py b/tests/framework_aiohttp/test_server_cat.py deleted file mode 100644 index 9d4cf581ce..0000000000 --- a/tests/framework_aiohttp/test_server_cat.py +++ /dev/null @@ -1,222 +0,0 @@ -# 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 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.encoding_utils import deobfuscate -from newrelic.common.object_wrapper import transient_function_wrapper - -ENCODING_KEY = "1234567890123456789012345678901234567890" -test_uris = [ - ("/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 - except ImportError: - - def pass_through(function): - return function - - return pass_through - - @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") - - # This is the request, not the response - if line.startswith("GET"): - break - - if ":" in line: - key, value = line.split(":", maxsplit=1) - raw_headers[key.strip()] = value.strip() - - return wrapped(*args, **kwargs) - - return recorder - - -@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 -): - _raw_headers = {} - - async def fetch(): - headers = make_cross_agent_headers(inbound_payload, ENCODING_KEY, cat_id) - resp = await 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} - - if expected_intrinsics: - # test valid CAT response header - assert "X-NewRelic-App-Data" in raw_headers - - app_data = json.loads(deobfuscate(raw_headers["X-NewRelic-App-Data"], ENCODING_KEY)) - assert app_data[0] == cat_id - assert app_data[1] == f"WebTransaction/Function/{metric_name}" - else: - 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, - } - - # NOTE: the logic-flow of this test can be a bit confusing. - # the override settings and attribute validation occur - # not when the request is made (above) since it does not - # occur inside a transaction. instead, the settings and - # validation are for the new transaction that is made - # asynchronously on the *server side* when the request - # is received and subsequently processed. that code is - # a fixture from conftest.py/_target_application.py - - @validate_analytics_catmap_data( - f"WebTransaction/Function/{metric_name}", - expected_attributes=expected_intrinsics, - non_expected_attributes=forgone_intrinsics, - ) - @override_application_settings(_custom_settings) - @record_aiohttp1_raw_headers(_raw_headers) - def _test(): - aiohttp_app.loop.run_until_complete(fetch()) - - _test() - - -account_id = "33" -primary_application_id = "2827902" - -inbound_payload = { - "v": [0, 1], - "d": { - "ac": account_id, - "ap": primary_application_id, - "id": "7d3efb1b173fecfa", - "tx": "e8b91a159289ff74", - "pr": 1.234567, - "sa": True, - "ti": 1518469636035, - "tr": "d6b4ba0c3a712ca", - "ty": "App", - }, -} - -expected_attributes = { - "agent": [], - "user": [], - "intrinsic": { - "traceId": "d6b4ba0c3a712ca", - "priority": 1.234567, - "sampled": True, - "parent.type": "App", - "parent.app": primary_application_id, - "parent.account": account_id, - "parent.transportType": "HTTP", - "parentId": "e8b91a159289ff74", - "parentSpanId": "7d3efb1b173fecfa", - }, -} - -# unexpected_attributes = { -# "agent": [], -# "user": [], -# "intrinsic": ["grandparentId", "cross_process_id", "nr.tripId", "nr.pathHash"], -# } - - -@pytest.mark.parametrize("uri,metric_name", test_uris) -def test_distributed_tracing_headers(uri, metric_name, aiohttp_app): - async def fetch(): - headers = {"newrelic": json.dumps(inbound_payload)} - resp = await aiohttp_app.client.request("GET", uri, headers=headers) - - # # better cat does not send a response in the 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 - - # NOTE: the logic-flow of this test can be a bit confusing. - # the override settings and attribute validation occur - # not when the request is made (above) since it does not - # occur inside a transaction. instead, the settings and - # validation are for the new transaction that is made - # asynchronously on the *server side* when the request - # is received and subsequently processed. that code is - # a fixture from conftest.py/_target_application.py - - @validate_transaction_event_attributes(expected_attributes) - # @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()) - - _test() diff --git a/tests/framework_aiohttp/test_server_dt.py b/tests/framework_aiohttp/test_server_dt.py new file mode 100644 index 0000000000..307eade547 --- /dev/null +++ b/tests/framework_aiohttp/test_server_dt.py @@ -0,0 +1,222 @@ +# 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 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.encoding_utils import deobfuscate +# from newrelic.common.object_wrapper import transient_function_wrapper + +# ENCODING_KEY = "1234567890123456789012345678901234567890" +test_uris = [ + ("/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 +# except ImportError: + +# def pass_through(function): +# return function + +# return pass_through + +# @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") + +# # This is the request, not the response +# if line.startswith("GET"): +# break + +# if ":" in line: +# key, value = line.split(":", maxsplit=1) +# raw_headers[key.strip()] = value.strip() + +# return wrapped(*args, **kwargs) + +# return recorder + + +# @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 +# ): +# _raw_headers = {} + +# async def fetch(): +# headers = make_cross_agent_headers(inbound_payload, ENCODING_KEY, cat_id) +# resp = await 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} + +# if expected_intrinsics: +# # test valid CAT response header +# assert "X-NewRelic-App-Data" in raw_headers + +# app_data = json.loads(deobfuscate(raw_headers["X-NewRelic-App-Data"], ENCODING_KEY)) +# assert app_data[0] == cat_id +# assert app_data[1] == f"WebTransaction/Function/{metric_name}" +# else: +# 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, +# } + +# # NOTE: the logic-flow of this test can be a bit confusing. +# # the override settings and attribute validation occur +# # not when the request is made (above) since it does not +# # occur inside a transaction. instead, the settings and +# # validation are for the new transaction that is made +# # asynchronously on the *server side* when the request +# # is received and subsequently processed. that code is +# # a fixture from conftest.py/_target_application.py + +# @validate_analytics_catmap_data( +# f"WebTransaction/Function/{metric_name}", +# expected_attributes=expected_intrinsics, +# non_expected_attributes=forgone_intrinsics, +# ) +# @override_application_settings(_custom_settings) +# @record_aiohttp1_raw_headers(_raw_headers) +# def _test(): +# aiohttp_app.loop.run_until_complete(fetch()) + +# _test() + + +account_id = "33" +primary_application_id = "2827902" + +inbound_payload = { + "v": [0, 1], + "d": { + "ac": account_id, + "ap": primary_application_id, + "id": "7d3efb1b173fecfa", + "tx": "e8b91a159289ff74", + "pr": 1.234567, + "sa": True, + "ti": 1518469636035, + "tr": "d6b4ba0c3a712ca", + "ty": "App", + }, +} + +expected_attributes = { + "agent": [], + "user": [], + "intrinsic": { + "traceId": "d6b4ba0c3a712ca", + "priority": 1.234567, + "sampled": True, + "parent.type": "App", + "parent.app": primary_application_id, + "parent.account": account_id, + "parent.transportType": "HTTP", + "parentId": "e8b91a159289ff74", + "parentSpanId": "7d3efb1b173fecfa", + }, +} + +# unexpected_attributes = { +# "agent": [], +# "user": [], +# "intrinsic": ["grandparentId", "cross_process_id", "nr.tripId", "nr.pathHash"], +# } + + +@pytest.mark.parametrize("uri,metric_name", test_uris) +def test_distributed_tracing_headers(uri, metric_name, aiohttp_app): + async def fetch(): + headers = {"newrelic": json.dumps(inbound_payload)} + resp = await aiohttp_app.client.request("GET", uri, headers=headers) + + # # better cat does not send a response in the 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 + + # NOTE: the logic-flow of this test can be a bit confusing. + # the override settings and attribute validation occur + # not when the request is made (above) since it does not + # occur inside a transaction. instead, the settings and + # validation are for the new transaction that is made + # asynchronously on the *server side* when the request + # is received and subsequently processed. that code is + # a fixture from conftest.py/_target_application.py + + @validate_transaction_event_attributes(expected_attributes) + # @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()) + + _test() From 1d36f99a57195eb6a1bfbbcaf8909f080b550b88 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Tue, 9 Sep 2025 17:54:47 -0700 Subject: [PATCH 51/95] Fix httpx tests --- tests/external_httpx/test_client.py | 112 +++++++++++++++------------- 1 file changed, 61 insertions(+), 51 deletions(-) diff --git a/tests/external_httpx/test_client.py b/tests/external_httpx/test_client.py index a3b1d080f9..178edd3dd7 100644 --- a/tests/external_httpx/test_client.py +++ b/tests/external_httpx/test_client.py @@ -32,33 +32,43 @@ SCOPED_METRICS = [] ROLLUP_METRICS = [("External/all", 2), ("External/allOther", 2)] -CAT_RESPONSE_CODE = None - - -def cat_response_handler(self): - if not CAT_RESPONSE_CODE: - raise ValueError("CAT_RESPONSE_CODE must be a valid status_code.") - - # payload - # ( - # u'1#1', u'WebTransaction/Function/app:beep', - # 0, 1.23, -1, - # 'dd4a810b7cb7f937', - # False, - # ) - cat_response_header = ( - "X-NewRelic-App-Data", - "ahACFwQUGxpuVVNmQVVbRVZbTVleXBxyQFhUTFBfXx1SREUMVV1cQBMeAxgEGAULFR0AHhFQUQJWAAgAUwVQVgJQDgsOEh1UUlhGU2o=", - ) - self.send_response(CAT_RESPONSE_CODE) - self.send_header(*cat_response_header) +DT_RESPONSE_CODE = None + + +# def cat_response_handler(self): +# if not DT_RESPONSE_CODE: +# raise ValueError("DT_RESPONSE_CODE must be a valid status_code.") + +# # payload +# # ( +# # u'1#1', u'WebTransaction/Function/app:beep', +# # 0, 1.23, -1, +# # 'dd4a810b7cb7f937', +# # False, +# # ) +# cat_response_header = ( +# "X-NewRelic-App-Data", +# "ahACFwQUGxpuVVNmQVVbRVZbTVleXBxyQFhUTFBfXx1SREUMVV1cQBMeAxgEGAULFR0AHhFQUQJWAAgAUwVQVgJQDgsOEh1UUlhGU2o=", +# ) +# self.send_response(DT_RESPONSE_CODE) +# self.send_header(*cat_response_header) +# self.end_headers() +# self.wfile.write(b"Example Data") + +def dt_response_handler(self): + if not DT_RESPONSE_CODE: + raise ValueError("DT_RESPONSE_CODE must be a valid status_code.") + + response = str(self.headers).encode("utf-8") # Might need to put headers here + self.send_response(DT_RESPONSE_CODE) self.end_headers() - self.wfile.write(b"Example Data") + self.wfile.write(response) @pytest.fixture(scope="session") def mock_server(): - external = MockExternalHTTPHResponseHeadersServer(handler=cat_response_handler) + # external = MockExternalHTTPHResponseHeadersServer(handler=cat_response_handler) + external = MockExternalHTTPHResponseHeadersServer(handler=dt_response_handler) with external: yield external @@ -85,8 +95,8 @@ def exercise_sync_client(server, client, method, protocol="http"): ) @background_task(name="test_sync_client") def test_sync_client(httpx, sync_client, mock_server, method): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = 200 + global DT_RESPONSE_CODE + DT_RESPONSE_CODE = 200 assert exercise_sync_client(mock_server, sync_client, method).status_code == 200 @@ -108,8 +118,8 @@ async def exercise_async_client(server, client, method, protocol="http"): ) @background_task(name="test_async_client") def test_async_client(httpx, async_client, mock_server, loop, method): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = 200 + global DT_RESPONSE_CODE + DT_RESPONSE_CODE = 200 responses = loop.run_until_complete(exercise_async_client(mock_server, async_client, method)) assert all(response.status_code == 200 for response in responses) @@ -117,8 +127,8 @@ def test_async_client(httpx, async_client, mock_server, loop, method): @pytest.mark.parametrize("distributed_tracing,span_events", ((True, True), (True, False), (False, False))) def test_sync_cross_process_request(httpx, sync_client, mock_server, distributed_tracing, span_events): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = 200 + global DT_RESPONSE_CODE + DT_RESPONSE_CODE = 200 @override_application_settings( { @@ -148,8 +158,8 @@ def _test(): @background_task(name="test_async_cross_process_request") @validate_cross_process_headers def test_async_cross_process_request(httpx, async_client, mock_server, loop, distributed_tracing, span_events): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = 200 + global DT_RESPONSE_CODE + DT_RESPONSE_CODE = 200 @override_application_settings( {"distributed_tracing.enabled": distributed_tracing, "span_events.enabled": span_events} @@ -168,13 +178,13 @@ async def _test(): @override_application_settings( - {"distributed_tracing.enabled": True, "span_events.enabled": True, "cross_application_tracer.enabled": True} + {"distributed_tracing.enabled": True, "span_events.enabled": True} #, "cross_application_tracer.enabled": True} ) @validate_transaction_errors(errors=[]) @background_task(name="test_sync_cross_process_override_headers") def test_sync_cross_process_override_headers(httpx, sync_client, mock_server, loop): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = 200 + global DT_RESPONSE_CODE + DT_RESPONSE_CODE = 200 transaction = current_transaction() @@ -191,8 +201,8 @@ def test_sync_cross_process_override_headers(httpx, sync_client, mock_server, lo @validate_transaction_errors(errors=[]) @background_task(name="test_async_cross_process_override_headers") def test_async_cross_process_override_headers(httpx, async_client, mock_server, loop): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = 200 + global DT_RESPONSE_CODE + DT_RESPONSE_CODE = 200 async def _test(): async with async_client: @@ -289,8 +299,8 @@ async def _test(): @dt_enabled def test_sync_client_event_hook_exception(httpx, mock_server): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = 500 + global DT_RESPONSE_CODE + DT_RESPONSE_CODE = 500 def exception_event_hook(response): if response.status_code >= 400: @@ -302,7 +312,7 @@ def empty_hook(response): @validate_span_events( count=1, exact_intrinsics={"name": f"External/localhost:{mock_server.port}/httpx/GET"}, - exact_agents={"http.statusCode": CAT_RESPONSE_CODE}, + exact_agents={"http.statusCode": DT_RESPONSE_CODE}, ) @background_task(name="test_sync_client_event_hook_exception") def make_request(client, exc_expected=True): @@ -335,8 +345,8 @@ def make_request(client, exc_expected=True): @override_application_settings({"distributed_tracing.enabled": True, "span_events.enabled": True}) def test_async_client_event_hook_exception(httpx, mock_server, loop): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = 500 + global DT_RESPONSE_CODE + DT_RESPONSE_CODE = 500 def exception_event_hook(response): if response.status_code >= 400: @@ -348,7 +358,7 @@ def empty_hook(response): @validate_span_events( count=1, exact_intrinsics={"name": f"External/localhost:{mock_server.port}/httpx/GET"}, - exact_agents={"http.statusCode": CAT_RESPONSE_CODE}, + exact_agents={"http.statusCode": DT_RESPONSE_CODE}, ) @background_task(name="test_sync_client_event_hook_exception") def make_request(client, exc_expected=True): @@ -385,8 +395,8 @@ def _test(): @override_generic_settings(global_settings(), {"enabled": False}) def test_sync_nr_disabled(httpx, mock_server): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = 200 + global DT_RESPONSE_CODE + DT_RESPONSE_CODE = 200 with httpx.Client() as client: trace = current_trace() @@ -398,8 +408,8 @@ def test_sync_nr_disabled(httpx, mock_server): @override_generic_settings(global_settings(), {"enabled": False}) def test_async_nr_disabled(httpx, mock_server, loop): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = 200 + global DT_RESPONSE_CODE + DT_RESPONSE_CODE = 200 async def _test(): async with httpx.AsyncClient() as client: @@ -415,8 +425,8 @@ async def _test(): @pytest.mark.parametrize("client", ("Client", "AsyncClient")) def test_invalid_import_order_client(monkeypatch, httpx, mock_server, loop, client): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = 200 + global DT_RESPONSE_CODE + DT_RESPONSE_CODE = 200 if "Async" in client: is_async = True @@ -447,8 +457,8 @@ def test_invalid_import_order_client(monkeypatch, httpx, mock_server, loop, clie ) @background_task(name="test_sync_client_http2") def test_sync_client_http2(httpx, real_server): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = 200 + global DT_RESPONSE_CODE + DT_RESPONSE_CODE = 200 client = httpx.Client(http1=False, http2=True, verify=False) response = exercise_sync_client(real_server, client, "get", protocol="https") @@ -462,8 +472,8 @@ def test_sync_client_http2(httpx, real_server): ) @background_task(name="test_async_client_http2") def test_async_client_http2(httpx, real_server, loop): - global CAT_RESPONSE_CODE - CAT_RESPONSE_CODE = 200 + global DT_RESPONSE_CODE + DT_RESPONSE_CODE = 200 client = httpx.AsyncClient(http1=False, http2=True, verify=False) From 71099faae6e2e60efc4db7ff45c4266dd2d88ed6 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 12:35:02 -0700 Subject: [PATCH 52/95] Fix pika tests --- newrelic/api/cat_header_mixin.py | 8 +- newrelic/hooks/messagebroker_pika.py | 12 +- tests/messagebroker_pika/test_cat.py | 137 ------------------ .../test_distributed_tracing.py | 8 +- tests/messagebroker_pika/test_pika_produce.py | 2 +- 5 files changed, 15 insertions(+), 152 deletions(-) delete mode 100644 tests/messagebroker_pika/test_cat.py diff --git a/newrelic/api/cat_header_mixin.py b/newrelic/api/cat_header_mixin.py index 8008423778..a98441c7e2 100644 --- a/newrelic/api/cat_header_mixin.py +++ b/newrelic/api/cat_header_mixin.py @@ -106,10 +106,10 @@ def generate_request_headers(cls, transaction): # encoded_transaction = obfuscate(json_encode(transaction_data), settings.encoding_key) # nr_headers.append((cls.cat_transaction_key, encoded_transaction)) - if transaction.synthetics_header: - nr_headers.append((cls.cat_synthetics_key, transaction.synthetics_header)) - if transaction.synthetics_info_header: - nr_headers.append((cls.cat_synthetics_info_key, transaction.synthetics_info_header)) + # if transaction.synthetics_header: + # nr_headers.append((cls.cat_synthetics_key, transaction.synthetics_header)) + # if transaction.synthetics_info_header: + # nr_headers.append((cls.cat_synthetics_info_key, transaction.synthetics_info_header)) return nr_headers diff --git a/newrelic/hooks/messagebroker_pika.py b/newrelic/hooks/messagebroker_pika.py index 821d05a318..6e4f812c3e 100644 --- a/newrelic/hooks/messagebroker_pika.py +++ b/newrelic/hooks/messagebroker_pika.py @@ -62,9 +62,9 @@ def _add_consume_rabbitmq_trace(transaction, method, properties, nr_start_time, # Do not record dt headers in the segment parameters if headers: - headers.pop(MessageTrace.cat_id_key, None) - headers.pop(MessageTrace.cat_transaction_key, None) - headers.pop(MessageTrace.cat_distributed_trace_key, None) + # headers.pop(MessageTrace.cat_id_key, None) + # headers.pop(MessageTrace.cat_transaction_key, None) + # headers.pop(MessageTrace.cat_distributed_trace_key, None) headers.pop("traceparent", None) headers.pop("tracestate", None) @@ -124,9 +124,9 @@ def _nr_wrapper_basic_publish(wrapped, instance, args, kwargs): user_headers = properties.headers.copy() # Do not record dt headers in the segment parameters - user_headers.pop(MessageTrace.cat_id_key, None) - user_headers.pop(MessageTrace.cat_transaction_key, None) - user_headers.pop(MessageTrace.cat_distributed_trace_key, None) + # user_headers.pop(MessageTrace.cat_id_key, None) + # user_headers.pop(MessageTrace.cat_transaction_key, None) + # user_headers.pop(MessageTrace.cat_distributed_trace_key, None) user_headers.pop("traceparent", None) user_headers.pop("tracestate", None) diff --git a/tests/messagebroker_pika/test_cat.py b/tests/messagebroker_pika/test_cat.py deleted file mode 100644 index e4d9ea1c59..0000000000 --- a/tests/messagebroker_pika/test_cat.py +++ /dev/null @@ -1,137 +0,0 @@ -# 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 os -import random -import string - -import pika -from compat import basic_consume -from testing_support.db_settings import rabbitmq_settings -from testing_support.fixtures import override_application_settings -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 - -DB_SETTINGS = rabbitmq_settings()[0] - -ENCODING_KEY = "".join(random.choice(string.ascii_lowercase) for _ in range(40)) -_override_settings = { - "cross_process_id": "1#1", - "encoding_key": ENCODING_KEY, - "trusted_account_ids": [1], - "browser_monitoring.enabled": False, -} - - -@background_task() -def do_basic_publish(channel, QUEUE, properties=None): - channel.basic_publish(exchange="", routing_key=QUEUE, body="Testing CAT 123", properties=properties) - - -_test_cat_basic_consume_scoped_metrics = [ - ("MessageBroker/RabbitMQ/Exchange/Produce/Named/Default", None), - ("MessageBroker/RabbitMQ/Exchange/Consume/Named/Default", None), -] -_test_cat_basic_consume_rollup_metrics = list(_test_cat_basic_consume_scoped_metrics) -_test_cat_basic_consume_rollup_metrics.append(("ClientApplication/1#1/all", 1)) - - -@validate_transaction_metrics( - "test_cat:test_basic_consume_cat_headers..on_receive", - scoped_metrics=_test_cat_basic_consume_scoped_metrics, - rollup_metrics=_test_cat_basic_consume_rollup_metrics, - background_task=True, - group="Message/RabbitMQ/Exchange/Default", -) -def do_basic_consume(channel): - channel.start_consuming() - - -# @cat_enabled -@override_application_settings(_override_settings) -def test_basic_consume_cat_headers(): - def on_receive(ch, method, properties, msg): - headers = properties.headers - assert headers - assert "NewRelicID" not in headers - assert "NewRelicTransaction" not in headers - assert msg == b"Testing CAT 123" - txn = current_transaction() - assert txn.client_cross_process_id == "1#1" - assert txn.client_account_id == 1 - assert txn.client_application_id == 1 - ch.stop_consuming() - - with pika.BlockingConnection(pika.ConnectionParameters(DB_SETTINGS["host"])) as connection: - channel = connection.channel() - queue_name = f"TESTCAT-{os.getpid()}" - channel.queue_declare(queue_name, durable=False) - - properties = pika.BasicProperties() - properties.headers = {"Hello": "World"} - - try: - basic_consume(channel, queue_name, on_receive, auto_ack=False) - do_basic_publish(channel, queue_name, properties=properties) - do_basic_consume(channel) - - finally: - channel.queue_delete(queue_name) - - -_test_cat_basic_get_metrics = [ - ("MessageBroker/RabbitMQ/Exchange/Produce/Named/Default", None), - ("MessageBroker/RabbitMQ/Exchange/Consume/Named/Default", 1), - # Verify basic_get doesn't create a CAT metric - ("ClientApplication/1#1/all", None), -] - - -@validate_transaction_metrics( - "test_cat:do_basic_get", - scoped_metrics=_test_cat_basic_get_metrics, - rollup_metrics=_test_cat_basic_get_metrics, - background_task=True, -) -@background_task() -def do_basic_get(channel, QUEUE): - _, properties, msg = channel.basic_get(QUEUE) - headers = properties.headers - assert headers - assert "NewRelicID" not in headers - assert "NewRelicTransaction" not in headers - assert msg == b"Testing CAT 123" - txn = current_transaction() - assert txn.client_cross_process_id is None - assert txn.client_account_id is None - assert txn.client_application_id is None - - -@override_application_settings(_override_settings) -def test_basic_get_no_cat_headers(): - with pika.BlockingConnection(pika.ConnectionParameters(DB_SETTINGS["host"])) as connection: - channel = connection.channel() - queue_name = f"TESTCAT-{os.getpid()}" - channel.queue_declare(queue_name, durable=False) - - properties = pika.BasicProperties() - properties.headers = {"Hello": "World"} - - try: - do_basic_publish(channel, queue_name, properties=properties) - do_basic_get(channel, queue_name) - finally: - channel.queue_delete(queue_name) diff --git a/tests/messagebroker_pika/test_distributed_tracing.py b/tests/messagebroker_pika/test_distributed_tracing.py index ee8a643ced..f23e3e43a6 100644 --- a/tests/messagebroker_pika/test_distributed_tracing.py +++ b/tests/messagebroker_pika/test_distributed_tracing.py @@ -81,8 +81,8 @@ def test_basic_consume_distributed_tracing_headers(): def on_receive(ch, method, properties, msg): headers = properties.headers assert headers - assert "NewRelicID" not in headers - assert "NewRelicTransaction" not in headers + # assert "NewRelicID" not in headers + # assert "NewRelicTransaction" not in headers assert msg == b"Testing distributed_tracing 123" txn = current_transaction() @@ -134,8 +134,8 @@ def do_basic_get(channel, QUEUE): headers = properties.headers assert headers - assert "NewRelicID" not in headers - assert "NewRelicTransaction" not in headers + # assert "NewRelicID" not in headers + # assert "NewRelicTransaction" not in headers assert msg == b"Testing distributed_tracing 123" txn = current_transaction() diff --git a/tests/messagebroker_pika/test_pika_produce.py b/tests/messagebroker_pika/test_pika_produce.py index 1d8a01c6ec..ad6607de9c 100644 --- a/tests/messagebroker_pika/test_pika_produce.py +++ b/tests/messagebroker_pika/test_pika_produce.py @@ -164,7 +164,7 @@ def test_blocking_connection_reply_to(producer): _message_broker_tt_included_test_headers = _message_broker_tt_included_params.copy() -_message_broker_tt_included_test_headers.update({"headers": HEADERS.copy()}) +# _message_broker_tt_included_test_headers.update({"headers": HEADERS.copy()}) _message_broker_tt_forgone_test_headers = ["queue_name", "correlation_id", "reply_to"] From 49c59cbfd7f9542998c5533d4792cc9d5119c777 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 13:23:41 -0700 Subject: [PATCH 53/95] Fix sanic tests --- tests/framework_sanic/conftest.py | 2 +- .../framework_sanic/test_cross_application.py | 141 ------------------ .../framework_sanic/test_distributed_trace.py | 141 ++++++++++++++++++ 3 files changed, 142 insertions(+), 142 deletions(-) delete mode 100644 tests/framework_sanic/test_cross_application.py create mode 100644 tests/framework_sanic/test_distributed_trace.py diff --git a/tests/framework_sanic/conftest.py b/tests/framework_sanic/conftest.py index 08c8bec3bb..8802638beb 100644 --- a/tests/framework_sanic/conftest.py +++ b/tests/framework_sanic/conftest.py @@ -17,7 +17,7 @@ import pytest from testing_support.fixtures import collector_agent_registration_fixture, collector_available_fixture -from newrelic.common.object_wrapper import transient_function_wrapper +# from newrelic.common.object_wrapper import transient_function_wrapper _default_settings = { "package_reporting.enabled": False, # Turn off package reporting for testing as it causes slow downs. diff --git a/tests/framework_sanic/test_cross_application.py b/tests/framework_sanic/test_cross_application.py deleted file mode 100644 index 60e1980533..0000000000 --- a/tests/framework_sanic/test_cross_application.py +++ /dev/null @@ -1,141 +0,0 @@ -# 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 json -import random - -# import re -import string - -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 newrelic.common.encoding_utils import deobfuscate - -BASE_METRICS = [("Function/_target_application:index", 1)] -DT_METRICS = [ - ("Supportability/DistributedTrace/AcceptPayload/Success", None), - ("Supportability/TraceContext/TraceParent/Accept/Success", 1), -] -BASE_ATTRS = ["response.status", "response.headers.contentType", "response.headers.contentLength"] - - -def raw_headers(response): - try: - # Manually encode into bytes - return " ".join(f"{k}: {v}" for k, v in response.processed_headers).encode() - except AttributeError: - try: - return response.get_headers() - except AttributeError: - return response.output() - - -@validate_transaction_metrics( - "_target_application:index", scoped_metrics=BASE_METRICS, rollup_metrics=BASE_METRICS + DT_METRICS -) -@override_application_settings({"distributed_tracing.enabled": True}) -@validate_transaction_event_attributes(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)) - assert response.status == 200 - - -ENCODING_KEY = "".join(random.choice(string.ascii_lowercase) for _ in range(40)) -_cat_response_header_urls_to_test = ( - ("/", "_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, -} - - -@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): - _base_metrics = [(f"Function/{metric_name}", 1)] - - @validate_transaction_metrics(metric_name, scoped_metrics=_base_metrics, rollup_metrics=_base_metrics) - @validate_analytics_catmap_data( - f"WebTransaction/Function/{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)) - if expected_intrinsics: - # test valid CAT response header - 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)) - assert app_data[0] == cat_id - assert app_data[1] == f"WebTransaction/Function/{metric_name}" - else: - 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", f"/custom-header/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_sanic/test_distributed_trace.py b/tests/framework_sanic/test_distributed_trace.py new file mode 100644 index 0000000000..3a92e84649 --- /dev/null +++ b/tests/framework_sanic/test_distributed_trace.py @@ -0,0 +1,141 @@ +# 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 json +# import random + +# import re +# import string + +# 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 newrelic.common.encoding_utils import deobfuscate + +BASE_METRICS = [("Function/_target_application:index", 1)] +DT_METRICS = [ + ("Supportability/DistributedTrace/AcceptPayload/Success", None), + ("Supportability/TraceContext/TraceParent/Accept/Success", 1), +] +BASE_ATTRS = ["response.status", "response.headers.contentType", "response.headers.contentLength"] + + +def raw_headers(response): + try: + # Manually encode into bytes + return " ".join(f"{k}: {v}" for k, v in response.processed_headers).encode() + except AttributeError: + try: + return response.get_headers() + except AttributeError: + return response.output() + + +@validate_transaction_metrics( + "_target_application:index", scoped_metrics=BASE_METRICS, rollup_metrics=BASE_METRICS + DT_METRICS +) +@override_application_settings({"distributed_tracing.enabled": True}) +@validate_transaction_event_attributes(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)) + assert response.status == 200 + + +# ENCODING_KEY = "".join(random.choice(string.ascii_lowercase) for _ in range(40)) +# _cat_response_header_urls_to_test = ( +# ("/", "_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, +# } + + +# @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): +# _base_metrics = [(f"Function/{metric_name}", 1)] + +# @validate_transaction_metrics(metric_name, scoped_metrics=_base_metrics, rollup_metrics=_base_metrics) +# @validate_analytics_catmap_data( +# f"WebTransaction/Function/{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)) +# if expected_intrinsics: +# # test valid CAT response header +# 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)) +# assert app_data[0] == cat_id +# assert app_data[1] == f"WebTransaction/Function/{metric_name}" +# else: +# 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", f"/custom-header/X-NewRelic-App-Data/{custom_header_value}", headers=dict(cat_headers)) +# assert custom_header_value in raw_headers(response), raw_headers(response) From af418d7605fd3a82e6ef2b713a490add91499e51 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 14:26:44 -0700 Subject: [PATCH 54/95] Remove more CAT tests --- tests/agent_features/test_error_events.py | 84 +++++++++++------------ tests/framework_tornado/test_externals.py | 4 +- 2 files changed, 42 insertions(+), 46 deletions(-) diff --git a/tests/agent_features/test_error_events.py b/tests/agent_features/test_error_events.py index 1e9a6116db..b96f4fe0f6 100644 --- a/tests/agent_features/test_error_events.py +++ b/tests/agent_features/test_error_events.py @@ -19,7 +19,7 @@ from testing_support.fixtures import ( # cat_enabled, # make_cross_agent_headers, - make_synthetics_headers, + # make_synthetics_headers, override_application_settings, reset_core_stats_engine, validate_error_event_sample_data, @@ -29,17 +29,17 @@ from testing_support.validators.validate_transaction_error_event_count import validate_transaction_error_event_count from newrelic.api.application import application_instance as application -from newrelic.api.application import application_settings +# from newrelic.api.application import application_settings from newrelic.api.time_trace import notice_error from newrelic.common.object_names import callable_name # Error in test app hard-coded as a ValueError -SYNTHETICS_RESOURCE_ID = "09845779-16ef-4fa7-b7f2-44da8e62931c" -SYNTHETICS_JOB_ID = "8c7dd3ba-4933-4cbb-b1ed-b62f511782f4" -SYNTHETICS_MONITOR_ID = "dc452ae9-1a93-4ab5-8a33-600521e9cd00" -SYNTHETICS_TYPE = "scheduled" -SYNTHETICS_INITIATOR = "graphql" -SYNTHETICS_ATTRIBUTES = {"exampleAttribute": "1"} +# SYNTHETICS_RESOURCE_ID = "09845779-16ef-4fa7-b7f2-44da8e62931c" +# SYNTHETICS_JOB_ID = "8c7dd3ba-4933-4cbb-b1ed-b62f511782f4" +# SYNTHETICS_MONITOR_ID = "dc452ae9-1a93-4ab5-8a33-600521e9cd00" +# SYNTHETICS_TYPE = "scheduled" +# SYNTHETICS_INITIATOR = "graphql" +# SYNTHETICS_ATTRIBUTES = {"exampleAttribute": "1"} ERR_MESSAGE = "Transaction had bad value" ERROR = ValueError(ERR_MESSAGE) @@ -108,50 +108,46 @@ def test_transaction_error_background_task(): "error.message": ERR_MESSAGE, "error.expected": False, "transactionName": "WebTransaction/Uri/", - "nr.referringTransactionGuid": 7, + # "nr.referringTransactionGuid": 7, } # @cat_enabled -# COMEBACK: Change to DT tests. @validate_error_event_sample_data(required_attrs=_intrinsic_attributes, required_user_attrs=True) -def test_transaction_error_cross_agent(): +def test_transaction_error_dt_headers(): test_environ = {"err_message": ERR_MESSAGE} - settings = application_settings() - transaction_data = [7, 1, 77, "/path-hash"] - # headers = make_cross_agent_headers(transaction_data, settings.encoding_key, settings.cross_process_id) - response = fully_featured_application.get("/", headers=headers, extra_environ=test_environ) - - -_intrinsic_attributes = { - "error.class": callable_name(ERROR), - "error.message": ERR_MESSAGE, - "error.expected": False, - "transactionName": "WebTransaction/Uri/", - "nr.syntheticsResourceId": SYNTHETICS_RESOURCE_ID, - "nr.syntheticsJobId": SYNTHETICS_JOB_ID, - "nr.syntheticsMonitorId": SYNTHETICS_MONITOR_ID, - "nr.syntheticsType": SYNTHETICS_TYPE, - "nr.syntheticsInitiator": SYNTHETICS_INITIATOR, - "nr.syntheticsExampleAttribute": "1", -} + response = fully_featured_application.get("/", extra_environ=test_environ) -@validate_error_event_sample_data(required_attrs=_intrinsic_attributes, required_user_attrs=True) -def test_transaction_error_with_synthetics(): - test_environ = {"err_message": ERR_MESSAGE} - settings = application_settings() - headers = make_synthetics_headers( - settings.encoding_key, - settings.trusted_account_ids[0], - SYNTHETICS_RESOURCE_ID, - SYNTHETICS_JOB_ID, - SYNTHETICS_MONITOR_ID, - SYNTHETICS_TYPE, - SYNTHETICS_INITIATOR, - SYNTHETICS_ATTRIBUTES, - ) - response = fully_featured_application.get("/", headers=headers, extra_environ=test_environ) +# _intrinsic_attributes = { +# "error.class": callable_name(ERROR), +# "error.message": ERR_MESSAGE, +# "error.expected": False, +# "transactionName": "WebTransaction/Uri/", +# "nr.syntheticsResourceId": SYNTHETICS_RESOURCE_ID, +# "nr.syntheticsJobId": SYNTHETICS_JOB_ID, +# "nr.syntheticsMonitorId": SYNTHETICS_MONITOR_ID, +# "nr.syntheticsType": SYNTHETICS_TYPE, +# "nr.syntheticsInitiator": SYNTHETICS_INITIATOR, +# "nr.syntheticsExampleAttribute": "1", +# } + + +# @validate_error_event_sample_data(required_attrs=_intrinsic_attributes, required_user_attrs=True) +# def test_transaction_error_with_synthetics(): +# test_environ = {"err_message": ERR_MESSAGE} +# settings = application_settings() +# headers = make_synthetics_headers( +# settings.encoding_key, +# settings.trusted_account_ids[0], +# SYNTHETICS_RESOURCE_ID, +# SYNTHETICS_JOB_ID, +# SYNTHETICS_MONITOR_ID, +# SYNTHETICS_TYPE, +# SYNTHETICS_INITIATOR, +# SYNTHETICS_ATTRIBUTES, +# ) +# response = fully_featured_application.get("/", headers=headers, extra_environ=test_environ) _intrinsic_attributes = { diff --git a/tests/framework_tornado/test_externals.py b/tests/framework_tornado/test_externals.py index 9553ca4140..5d79c0e46d 100644 --- a/tests/framework_tornado/test_externals.py +++ b/tests/framework_tornado/test_externals.py @@ -19,13 +19,13 @@ import pytest from testing_support.fixtures import override_application_settings from testing_support.mock_external_http_server import MockExternalHTTPHResponseHeadersServer, MockExternalHTTPServer -from testing_support.validators.validate_distributed_tracing_header import validate_distributed_tracing_header +# from testing_support.validators.validate_distributed_tracing_header import validate_distributed_tracing_header # from testing_support.validators.validate_outbound_headers import validate_outbound_headers 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 -from newrelic.api.transaction import current_transaction +# from newrelic.api.transaction import current_transaction ENCODING_KEY = "1234567890123456789012345678901234567890" From 0b945ad570e836bcafaaef36f7b884e719cfbeb1 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 14:31:06 -0700 Subject: [PATCH 55/95] Remove nr.guid --- newrelic/core/transaction_node.py | 4 ++-- tests/testing_support/validators/validate_synthetics_event.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/newrelic/core/transaction_node.py b/newrelic/core/transaction_node.py index 5468065faf..d88690bed2 100644 --- a/newrelic/core/transaction_node.py +++ b/newrelic/core/transaction_node.py @@ -479,8 +479,8 @@ def _add_if_not_empty(key, value): # _add_if_not_empty("nr.alternatePathHashes", ",".join(self.alternate_path_hashes)) # _add_if_not_empty("nr.referringTransactionGuid", self.referring_transaction_guid) - if self.synthetics_resource_id: - intrinsics["nr.guid"] = self.guid + # if self.synthetics_resource_id: + # intrinsics["nr.guid"] = self.guid if self.parent_tx: intrinsics["parentId"] = self.parent_tx diff --git a/tests/testing_support/validators/validate_synthetics_event.py b/tests/testing_support/validators/validate_synthetics_event.py index 21cb062ba4..dd6fedbb86 100644 --- a/tests/testing_support/validators/validate_synthetics_event.py +++ b/tests/testing_support/validators/validate_synthetics_event.py @@ -42,7 +42,7 @@ def _flatten(event): flat_event = _flatten(event) - assert "nr.guid" in flat_event, f"name=nr.guid, event={flat_event!r}" + # assert "nr.guid" in flat_event, f"name=nr.guid, event={flat_event!r}" for name, value in required_attrs: assert name in flat_event, f"name={name!r}, event={flat_event!r}" From 72f5cf19f6307327ed9e09800dfc0cc42afc1bae Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 16:51:14 -0700 Subject: [PATCH 56/95] Rename synthetics in CatHeaderMixin --- newrelic/api/cat_header_mixin.py | 14 +++++++------- newrelic/api/message_trace.py | 10 +++++----- newrelic/core/transaction_node.py | 10 +++++----- newrelic/hooks/messagebroker_pika.py | 4 ++-- tests/agent_features/test_attributes_in_action.py | 2 +- tests/messagebroker_pika/test_pika_produce.py | 2 +- tests/testing_support/fixtures.py | 12 ++++++------ 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/newrelic/api/cat_header_mixin.py b/newrelic/api/cat_header_mixin.py index a98441c7e2..1d1055ed4e 100644 --- a/newrelic/api/cat_header_mixin.py +++ b/newrelic/api/cat_header_mixin.py @@ -27,10 +27,10 @@ class CatHeaderMixin: # cat_id_key = "X-NewRelic-ID" # cat_transaction_key = "X-NewRelic-Transaction" # cat_appdata_key = "X-NewRelic-App-Data" - # cat_synthetics_key = "X-NewRelic-Synthetics" - # cat_synthetics_info_key = "X-NewRelic-Synthetics-Info" + synthetics_key = "X-NewRelic-Synthetics" + synthetics_info_key = "X-NewRelic-Synthetics-Info" # cat_metadata_key = "x-newrelic-trace" - # cat_distributed_trace_key = "newrelic" + distributed_trace_key = "newrelic" settings = None def __enter__(self): @@ -106,10 +106,10 @@ def generate_request_headers(cls, transaction): # encoded_transaction = obfuscate(json_encode(transaction_data), settings.encoding_key) # nr_headers.append((cls.cat_transaction_key, encoded_transaction)) - # if transaction.synthetics_header: - # nr_headers.append((cls.cat_synthetics_key, transaction.synthetics_header)) - # if transaction.synthetics_info_header: - # nr_headers.append((cls.cat_synthetics_info_key, transaction.synthetics_info_header)) + if transaction.synthetics_header: + nr_headers.append((cls.synthetics_key, transaction.synthetics_header)) + if transaction.synthetics_info_header: + nr_headers.append((cls.synthetics_info_key, transaction.synthetics_info_header)) return nr_headers diff --git a/newrelic/api/message_trace.py b/newrelic/api/message_trace.py index 5f6f9a76d0..0514b2d941 100644 --- a/newrelic/api/message_trace.py +++ b/newrelic/api/message_trace.py @@ -22,11 +22,11 @@ class MessageTrace(CatHeaderMixin, TimeTrace): - cat_id_key = "NewRelicID" - cat_transaction_key = "NewRelicTransaction" - cat_appdata_key = "NewRelicAppData" - cat_synthetics_key = "NewRelicSynthetics" - cat_synthetics_info_key = "NewRelicSyntheticsInfo" + # cat_id_key = "NewRelicID" + # cat_transaction_key = "NewRelicTransaction" + # cat_appdata_key = "NewRelicAppData" + synthetics_key = "NewRelicSynthetics" + synthetics_info_key = "NewRelicSyntheticsInfo" def __init__(self, library, operation, destination_type, destination_name, params=None, terminal=True, **kwargs): parent = kwargs.pop("parent", None) diff --git a/newrelic/core/transaction_node.py b/newrelic/core/transaction_node.py index d88690bed2..020993e0c9 100644 --- a/newrelic/core/transaction_node.py +++ b/newrelic/core/transaction_node.py @@ -465,7 +465,7 @@ def _add_if_not_empty(key, value): apdex_perf_zone = self.apdex_perf_zone() _add_if_not_empty("apdexPerfZone", apdex_perf_zone) - _add_if_not_empty("nr.apdexPerfZone", apdex_perf_zone) + # _add_if_not_empty("nr.apdexPerfZone", apdex_perf_zone) if self.errors: intrinsics["error"] = True @@ -541,10 +541,10 @@ def error_event_intrinsics(self, error, stats_table): intrinsics["transactionName"] = self.path intrinsics["spanId"] = error.span_id - intrinsics["nr.transactionGuid"] = self.guid - if self.referring_transaction_guid: - guid = self.referring_transaction_guid - intrinsics["nr.referringTransactionGuid"] = guid + # intrinsics["nr.transactionGuid"] = self.guid + # if self.referring_transaction_guid: + # guid = self.referring_transaction_guid + # intrinsics["nr.referringTransactionGuid"] = guid return intrinsics diff --git a/newrelic/hooks/messagebroker_pika.py b/newrelic/hooks/messagebroker_pika.py index 6e4f812c3e..3e673f277a 100644 --- a/newrelic/hooks/messagebroker_pika.py +++ b/newrelic/hooks/messagebroker_pika.py @@ -64,7 +64,7 @@ def _add_consume_rabbitmq_trace(transaction, method, properties, nr_start_time, if headers: # headers.pop(MessageTrace.cat_id_key, None) # headers.pop(MessageTrace.cat_transaction_key, None) - # headers.pop(MessageTrace.cat_distributed_trace_key, None) + headers.pop(MessageTrace.distributed_trace_key, None) headers.pop("traceparent", None) headers.pop("tracestate", None) @@ -126,7 +126,7 @@ def _nr_wrapper_basic_publish(wrapped, instance, args, kwargs): # Do not record dt headers in the segment parameters # user_headers.pop(MessageTrace.cat_id_key, None) # user_headers.pop(MessageTrace.cat_transaction_key, None) - # user_headers.pop(MessageTrace.cat_distributed_trace_key, None) + user_headers.pop(MessageTrace.distributed_trace_key, None) user_headers.pop("traceparent", None) user_headers.pop("tracestate", None) diff --git a/tests/agent_features/test_attributes_in_action.py b/tests/agent_features/test_attributes_in_action.py index c6f1128009..4d0e601c1d 100644 --- a/tests/agent_features/test_attributes_in_action.py +++ b/tests/agent_features/test_attributes_in_action.py @@ -96,7 +96,7 @@ "timestamp", "totalTime", "error", - "nr.apdexPerfZone", + # "nr.apdexPerfZone", "apdexPerfZone", ) TRANS_EVENT_AGENT_KEYS = [ diff --git a/tests/messagebroker_pika/test_pika_produce.py b/tests/messagebroker_pika/test_pika_produce.py index ad6607de9c..1d8a01c6ec 100644 --- a/tests/messagebroker_pika/test_pika_produce.py +++ b/tests/messagebroker_pika/test_pika_produce.py @@ -164,7 +164,7 @@ def test_blocking_connection_reply_to(producer): _message_broker_tt_included_test_headers = _message_broker_tt_included_params.copy() -# _message_broker_tt_included_test_headers.update({"headers": HEADERS.copy()}) +_message_broker_tt_included_test_headers.update({"headers": HEADERS.copy()}) _message_broker_tt_forgone_test_headers = ["queue_name", "correlation_id", "reply_to"] diff --git a/tests/testing_support/fixtures.py b/tests/testing_support/fixtures.py index 0410085ddf..e0d88833e7 100644 --- a/tests/testing_support/fixtures.py +++ b/tests/testing_support/fixtures.py @@ -797,7 +797,7 @@ def _bind_params(transaction, *args, **kwargs): assert intrinsics["error.class"] == required_attrs["error.class"] assert intrinsics["error.message"].startswith(required_attrs["error.message"]) assert intrinsics["error.expected"] == required_attrs["error.expected"] - assert intrinsics["nr.transactionGuid"] is not None + # assert intrinsics["nr.transactionGuid"] is not None assert intrinsics["spanId"] is not None # check that transaction event intrinsics haven't bled in @@ -860,11 +860,11 @@ def _validate_event_attributes(intrinsics, user_attributes, required_intrinsics, else: assert "queueDuration" not in intrinsics - if "nr.referringTransactionGuid" in required_intrinsics: - guid = required_intrinsics["nr.referringTransactionGuid"] - assert intrinsics["nr.referringTransactionGuid"] == guid - else: - assert "nr.referringTransactionGuid" not in intrinsics + # if "nr.referringTransactionGuid" in required_intrinsics: + # guid = required_intrinsics["nr.referringTransactionGuid"] + # assert intrinsics["nr.referringTransactionGuid"] == guid + # else: + # assert "nr.referringTransactionGuid" not in intrinsics if "nr.syntheticsResourceId" in required_intrinsics: res_id = required_intrinsics["nr.syntheticsResourceId"] From bb5215ec5d495945e6a79ca03737409ca9d0ce87 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 17:26:27 -0700 Subject: [PATCH 57/95] Remove process_response_headers --- newrelic/api/cat_header_mixin.py | 38 ++++++++++---------- newrelic/api/external_trace.py | 2 +- newrelic/hooks/framework_aiohttp.py | 11 +++--- newrelic/hooks/framework_tornado.py | 5 +-- newrelic/hooks/messagebroker_pika.py | 4 +-- tests/agent_features/test_serverless_mode.py | 26 +++++++------- 6 files changed, 43 insertions(+), 43 deletions(-) diff --git a/newrelic/api/cat_header_mixin.py b/newrelic/api/cat_header_mixin.py index 1d1055ed4e..3ba43a5769 100644 --- a/newrelic/api/cat_header_mixin.py +++ b/newrelic/api/cat_header_mixin.py @@ -12,14 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. -from newrelic.common.encoding_utils import ( - base64_decode, - base64_encode, - deobfuscate, - json_decode, - json_encode, - obfuscate, -) +# from newrelic.common.encoding_utils import ( +# base64_decode, +# base64_encode, +# deobfuscate, +# json_decode, +# json_encode, +# obfuscate, +# ) # CatHeaderMixin assumes the mixin class also inherits from TimeTrace @@ -113,17 +113,17 @@ def generate_request_headers(cls, transaction): return nr_headers - @staticmethod - def _convert_to_cat_metadata_value(nr_headers): - payload = json_encode(nr_headers) - cat_linking_value = base64_encode(payload) - return cat_linking_value + # @staticmethod + # def _convert_to_cat_metadata_value(nr_headers): + # payload = json_encode(nr_headers) + # cat_linking_value = base64_encode(payload) + # return cat_linking_value - @classmethod - def get_request_metadata(cls, transaction): - nr_headers = dict(cls.generate_request_headers(transaction)) + # @classmethod + # def get_request_metadata(cls, transaction): + # nr_headers = dict(cls.generate_request_headers(transaction)) - if not nr_headers: - return None + # if not nr_headers: + # return None - return cls._convert_to_cat_metadata_value(nr_headers) + # return cls._convert_to_cat_metadata_value(nr_headers) diff --git a/newrelic/api/external_trace.py b/newrelic/api/external_trace.py index 32796ccd9f..6c0ef4df0f 100644 --- a/newrelic/api/external_trace.py +++ b/newrelic/api/external_trace.py @@ -38,7 +38,7 @@ def __init__(self, library, url, method=None, **kwargs): def __repr__(self): return f"<{self.__class__.__name__} object at 0x{id(self):x} { {'library': self.library, 'url': self.url, 'method': self.method} }>" - def process_response(self, status_code, headers): + def process_response(self, status_code, headers=None): self._add_agent_attribute("http.statusCode", status_code) # self.process_response_headers(headers) diff --git a/newrelic/hooks/framework_aiohttp.py b/newrelic/hooks/framework_aiohttp.py index 277b2fad4c..04d9f2484b 100644 --- a/newrelic/hooks/framework_aiohttp.py +++ b/newrelic/hooks/framework_aiohttp.py @@ -15,6 +15,7 @@ import inspect import itertools +from newrelic.api.time_trace import notice_error from newrelic.api.external_trace import ExternalTrace from newrelic.api.function_trace import function_trace from newrelic.api.transaction import current_transaction, ignore_transaction @@ -279,16 +280,14 @@ async def _coro(): response = await wrapped(*args, **kwargs) try: - trace.process_response_headers(response.headers.items()) + # trace.process_response_headers(response.headers.items()) + trace.process_response(status_code=response.status) except: pass return response - except Exception as e: - try: - trace.process_response_headers(e.headers.items()) - except: - pass + except Exception: + notice_error() raise diff --git a/newrelic/hooks/framework_tornado.py b/newrelic/hooks/framework_tornado.py index a88c66a1b0..92b6a84019 100644 --- a/newrelic/hooks/framework_tornado.py +++ b/newrelic/hooks/framework_tornado.py @@ -251,8 +251,9 @@ async def wrapper(req, raise_error): except Exception as e: response = getattr(e, "response", None) raise - # finally: - # if response: + finally: + if response: + trace.process_response(response.status_code) # trace.process_response_headers(response.headers.get_all()) return response diff --git a/newrelic/hooks/messagebroker_pika.py b/newrelic/hooks/messagebroker_pika.py index 3e673f277a..6a058d85ca 100644 --- a/newrelic/hooks/messagebroker_pika.py +++ b/newrelic/hooks/messagebroker_pika.py @@ -150,8 +150,8 @@ def _nr_wrapper_basic_publish(wrapped, instance, args, kwargs): params=params, source=wrapped, ) as trace: - cat_headers = MessageTrace.generate_request_headers(transaction) - properties.headers.update(cat_headers) + headers = MessageTrace.generate_request_headers(transaction) + properties.headers.update(headers) # Extract host from channel to add as an agent attribute host = instance_info(instance) diff --git a/tests/agent_features/test_serverless_mode.py b/tests/agent_features/test_serverless_mode.py index 8a05db6fe1..f77d739f75 100644 --- a/tests/agent_features/test_serverless_mode.py +++ b/tests/agent_features/test_serverless_mode.py @@ -17,7 +17,7 @@ import pytest from testing_support.fixtures import override_generic_settings from testing_support.validators.validate_serverless_data import validate_serverless_data -from testing_support.validators.validate_serverless_metadata import validate_serverless_metadata +# from testing_support.validators.validate_serverless_metadata import validate_serverless_metadata from testing_support.validators.validate_serverless_payload import validate_serverless_payload from newrelic.api.application import application_instance @@ -65,22 +65,22 @@ def _test(): payload = json.loads(out) -def test_no_cat_headers(serverless_application): - @background_task(application=serverless_application, name="test_cat_headers") - def _test_cat_headers(): - transaction = current_transaction() +# def test_no_cat_headers(serverless_application): +# @background_task(application=serverless_application, name="test_cat_headers") +# def _test_cat_headers(): +# transaction = current_transaction() - payload = ExternalTrace.generate_request_headers(transaction) - assert not payload +# payload = ExternalTrace.generate_request_headers(transaction) +# assert not payload - trace = ExternalTrace("testlib", "http://example.com") - response_headers = [("X-NewRelic-App-Data", "Cookies")] - with trace: - trace.process_response_headers(response_headers) +# trace = ExternalTrace("testlib", "http://example.com") +# response_headers = [("X-NewRelic-App-Data", "Cookies")] +# with trace: +# trace.process_response_headers(response_headers) - # assert transaction.settings.cross_application_tracer.enabled is False +# # assert transaction.settings.cross_application_tracer.enabled is False - _test_cat_headers() +# _test_cat_headers() @pytest.mark.parametrize("trusted_account_key", ("1", None), ids=("tk_set", "tk_unset")) From 4658a32ebe126b32f7d3dde8de946e5658c23d8f Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 17:33:07 -0700 Subject: [PATCH 58/95] Remove validate_external_node_params --- tests/external_http/test_http.py | 70 +++++----- tests/external_httplib/test_httplib.py | 132 +++++++++--------- tests/external_httplib/test_urllib.py | 102 +++++--------- tests/external_httplib/test_urllib2.py | 62 ++++---- tests/external_httplib2/test_httplib2.py | 74 +++++----- tests/external_requests/test_requests.py | 68 ++++----- tests/external_urllib3/test_urllib3.py | 66 ++++----- .../validate_external_node_params.py | 51 ------- 8 files changed, 269 insertions(+), 356 deletions(-) delete mode 100644 tests/testing_support/validators/validate_external_node_params.py diff --git a/tests/external_http/test_http.py b/tests/external_http/test_http.py index 74ab0833e6..10b353c88b 100644 --- a/tests/external_http/test_http.py +++ b/tests/external_http/test_http.py @@ -18,7 +18,7 @@ from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers -from testing_support.validators.validate_external_node_params import validate_external_node_params +# 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 @@ -95,37 +95,37 @@ def _test(): # @cat_enabled -def test_http_cross_process_response(server): - _test_http_cross_process_response_scoped_metrics = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] - - _test_http_cross_process_response_rollup_metrics = [ - ("External/all", 1), - ("External/allOther", 1), - (f"External/localhost:{server.port}/all", 1), - (f"ExternalApp/localhost:{server.port}/1#2/all", 1), - (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), - ] - - _test_http_cross_process_response_external_node_params = [ - ("cross_process_id", "1#2"), - ("external_txn_name", "test"), - ("transaction_guid", "0123456789012345"), - ] - - @validate_transaction_metrics( - "test_http:test_http_cross_process_response", - scoped_metrics=_test_http_cross_process_response_scoped_metrics, - rollup_metrics=_test_http_cross_process_response_rollup_metrics, - background_task=True, - ) - @insert_incoming_headers - @validate_external_node_params(params=_test_http_cross_process_response_external_node_params) - @background_task(name="test_http:test_http_cross_process_response") - def _test(): - connection = http.client.HTTPConnection("localhost", server.port) - connection.request("GET", "/") - response = connection.getresponse() - response.read() - connection.close() - - _test() +# def test_http_cross_process_response(server): +# _test_http_cross_process_response_scoped_metrics = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] + +# _test_http_cross_process_response_rollup_metrics = [ +# ("External/all", 1), +# ("External/allOther", 1), +# (f"External/localhost:{server.port}/all", 1), +# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), +# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), +# ] + +# _test_http_cross_process_response_external_node_params = [ +# ("cross_process_id", "1#2"), +# ("external_txn_name", "test"), +# ("transaction_guid", "0123456789012345"), +# ] + +# @validate_transaction_metrics( +# "test_http:test_http_cross_process_response", +# scoped_metrics=_test_http_cross_process_response_scoped_metrics, +# rollup_metrics=_test_http_cross_process_response_rollup_metrics, +# background_task=True, +# ) +# @insert_incoming_headers +# @validate_external_node_params(params=_test_http_cross_process_response_external_node_params) +# @background_task(name="test_http:test_http_cross_process_response") +# def _test(): +# connection = http.client.HTTPConnection("localhost", server.port) +# connection.request("GET", "/") +# response = connection.getresponse() +# response.read() +# connection.close() + +# _test() diff --git a/tests/external_httplib/test_httplib.py b/tests/external_httplib/test_httplib.py index 46372adb1c..53133e7cbf 100644 --- a/tests/external_httplib/test_httplib.py +++ b/tests/external_httplib/test_httplib.py @@ -18,7 +18,7 @@ from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers -from testing_support.validators.validate_external_node_params import validate_external_node_params +# from testing_support.validators.validate_external_node_params import validate_external_node_params 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_tt_segment_params import validate_tt_segment_params @@ -132,74 +132,74 @@ def _test(): _test() -_test_httplib_cross_process_response_external_node_params = [ - ("cross_process_id", "1#2"), - ("external_txn_name", "test"), - ("transaction_guid", "0123456789012345"), -] +# _test_httplib_cross_process_response_external_node_params = [ +# ("cross_process_id", "1#2"), +# ("external_txn_name", "test"), +# ("transaction_guid", "0123456789012345"), +# ] + + +# # @cat_enabled +# @insert_incoming_headers +# def test_httplib_cross_process_response(server): +# scoped = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] + +# rollup = [ +# ("External/all", 1), +# ("External/allOther", 1), +# (f"External/localhost:{server.port}/all", 1), +# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), +# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), +# ] + +# @validate_transaction_metrics( +# "test_httplib:test_httplib_cross_process_response", +# scoped_metrics=scoped, +# rollup_metrics=rollup, +# background_task=True, +# ) +# @validate_external_node_params(params=_test_httplib_cross_process_response_external_node_params) +# @background_task(name="test_httplib:test_httplib_cross_process_response") +# def _test(): +# connection = httplib.HTTPConnection("localhost", server.port) +# connection.request("GET", "/") +# response = connection.getresponse() +# response.read() +# connection.close() + +# _test() # @cat_enabled -@insert_incoming_headers -def test_httplib_cross_process_response(server): - scoped = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] - - rollup = [ - ("External/all", 1), - ("External/allOther", 1), - (f"External/localhost:{server.port}/all", 1), - (f"ExternalApp/localhost:{server.port}/1#2/all", 1), - (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), - ] - - @validate_transaction_metrics( - "test_httplib:test_httplib_cross_process_response", - scoped_metrics=scoped, - rollup_metrics=rollup, - background_task=True, - ) - @validate_external_node_params(params=_test_httplib_cross_process_response_external_node_params) - @background_task(name="test_httplib:test_httplib_cross_process_response") - def _test(): - connection = httplib.HTTPConnection("localhost", server.port) - connection.request("GET", "/") - response = connection.getresponse() - response.read() - connection.close() - - _test() - - -# @cat_enabled -def test_httplib_multiple_requests_cross_process_response(server): - connection = httplib.HTTPConnection("localhost", server.port) - - scoped = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] - - rollup = [ - ("External/all", 1), - ("External/allOther", 1), - (f"External/localhost:{server.port}/all", 1), - (f"ExternalApp/localhost:{server.port}/1#2/all", 1), - (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), - ] - - @validate_transaction_metrics( - "test_httplib:test_transaction", scoped_metrics=scoped, rollup_metrics=rollup, background_task=True - ) - @insert_incoming_headers - @validate_external_node_params(params=_test_httplib_cross_process_response_external_node_params) - @background_task(name="test_httplib:test_transaction") - def test_transaction(): - connection.request("GET", "/") - response = connection.getresponse() - response.read() - - # make multiple requests with the same connection - for _ in range(2): - test_transaction() - - connection.close() +# def test_httplib_multiple_requests_cross_process_response(server): +# connection = httplib.HTTPConnection("localhost", server.port) + +# scoped = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] + +# rollup = [ +# ("External/all", 1), +# ("External/allOther", 1), +# (f"External/localhost:{server.port}/all", 1), +# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), +# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), +# ] + +# @validate_transaction_metrics( +# "test_httplib:test_transaction", scoped_metrics=scoped, rollup_metrics=rollup, background_task=True +# ) +# @insert_incoming_headers +# @validate_external_node_params(params=_test_httplib_cross_process_response_external_node_params) +# @background_task(name="test_httplib:test_transaction") +# def test_transaction(): +# connection.request("GET", "/") +# response = connection.getresponse() +# response.read() + +# # make multiple requests with the same connection +# for _ in range(2): +# test_transaction() + +# connection.close() def process_response(response): diff --git a/tests/external_httplib/test_urllib.py b/tests/external_httplib/test_urllib.py index ddff60d8af..3681462805 100644 --- a/tests/external_httplib/test_urllib.py +++ b/tests/external_httplib/test_urllib.py @@ -24,7 +24,7 @@ from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers # from testing_support.fixtures import cat_enabled from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers -from testing_support.validators.validate_external_node_params import validate_external_node_params +# 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 @@ -144,42 +144,6 @@ def test_urlopener_cross_process_request(server): opener.open(f"http://localhost:{server.port}/") -@SKIP_IF_PYTHON_3_14_OR_ABOVE -def test_urlopener_cross_process_response(server): - _test_urlopener_cross_process_response_scoped_metrics = [ - (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) - ] - - _test_urlopener_cross_process_response_rollup_metrics = [ - ("External/all", 1), - ("External/allOther", 1), - (f"External/localhost:{server.port}/all", 1), - (f"ExternalApp/localhost:{server.port}/1#2/all", 1), - (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), - ] - - _test_urlopener_cross_process_response_external_node_params = [ - ("cross_process_id", "1#2"), - ("external_txn_name", "test"), - ("transaction_guid", "0123456789012345"), - ] - - @validate_transaction_metrics( - "test_urllib:test_urlopener_cross_process_response", - scoped_metrics=_test_urlopener_cross_process_response_scoped_metrics, - rollup_metrics=_test_urlopener_cross_process_response_rollup_metrics, - background_task=True, - ) - @insert_incoming_headers - @validate_external_node_params(params=_test_urlopener_cross_process_response_external_node_params) - @background_task(name="test_urllib:test_urlopener_cross_process_response") - def _test(): - opener = urllib.URLopener() - opener.open(f"http://localhost:{server.port}/") - - _test() - - def test_urlretrieve_http_request(server, metrics): @validate_transaction_metrics( "test_urllib:test_urlretrieve_http_request", @@ -219,35 +183,35 @@ def test_urlretrieve_cross_process_request(server): # @cat_enabled -def test_urlretrieve_cross_process_response(server): - _test_urlretrieve_cross_process_response_scoped_metrics = [ - (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) - ] - - _test_urlretrieve_cross_process_response_rollup_metrics = [ - ("External/all", 1), - ("External/allOther", 1), - (f"External/localhost:{server.port}/all", 1), - (f"ExternalApp/localhost:{server.port}/1#2/all", 1), - (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), - ] - - _test_urlretrieve_cross_process_response_external_node_params = [ - ("cross_process_id", "1#2"), - ("external_txn_name", "test"), - ("transaction_guid", "0123456789012345"), - ] - - @validate_transaction_metrics( - "test_urllib:test_urlretrieve_cross_process_response", - scoped_metrics=_test_urlretrieve_cross_process_response_scoped_metrics, - rollup_metrics=_test_urlretrieve_cross_process_response_rollup_metrics, - background_task=True, - ) - @insert_incoming_headers - @validate_external_node_params(params=_test_urlretrieve_cross_process_response_external_node_params) - @background_task(name="test_urllib:test_urlretrieve_cross_process_response") - def _test(): - urllib.urlretrieve(f"http://localhost:{server.port}/") - - _test() +# def test_urlretrieve_cross_process_response(server): +# _test_urlretrieve_cross_process_response_scoped_metrics = [ +# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) +# ] + +# _test_urlretrieve_cross_process_response_rollup_metrics = [ +# ("External/all", 1), +# ("External/allOther", 1), +# (f"External/localhost:{server.port}/all", 1), +# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), +# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), +# ] + +# _test_urlretrieve_cross_process_response_external_node_params = [ +# ("cross_process_id", "1#2"), +# ("external_txn_name", "test"), +# ("transaction_guid", "0123456789012345"), +# ] + +# @validate_transaction_metrics( +# "test_urllib:test_urlretrieve_cross_process_response", +# scoped_metrics=_test_urlretrieve_cross_process_response_scoped_metrics, +# rollup_metrics=_test_urlretrieve_cross_process_response_rollup_metrics, +# background_task=True, +# ) +# @insert_incoming_headers +# @validate_external_node_params(params=_test_urlretrieve_cross_process_response_external_node_params) +# @background_task(name="test_urllib:test_urlretrieve_cross_process_response") +# def _test(): +# urllib.urlretrieve(f"http://localhost:{server.port}/") + +# _test() diff --git a/tests/external_httplib/test_urllib2.py b/tests/external_httplib/test_urllib2.py index 2eb74c93a0..788c47d887 100644 --- a/tests/external_httplib/test_urllib2.py +++ b/tests/external_httplib/test_urllib2.py @@ -18,7 +18,7 @@ from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers # from testing_support.fixtures import cat_enabled from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers -from testing_support.validators.validate_external_node_params import validate_external_node_params +# 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 @@ -121,33 +121,33 @@ def test_urlopen_cross_process_request(server): # @cat_enabled -def test_urlopen_cross_process_response(server): - _test_urlopen_cross_process_response_scoped_metrics = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] - - _test_urlopen_cross_process_response_rollup_metrics = [ - ("External/all", 1), - ("External/allOther", 1), - (f"External/localhost:{server.port}/all", 1), - (f"ExternalApp/localhost:{server.port}/1#2/all", 1), - (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), - ] - - _test_urlopen_cross_process_response_external_node_params = [ - ("cross_process_id", "1#2"), - ("external_txn_name", "test"), - ("transaction_guid", "0123456789012345"), - ] - - @validate_transaction_metrics( - "test_urllib2:test_urlopen_cross_process_response", - scoped_metrics=_test_urlopen_cross_process_response_scoped_metrics, - rollup_metrics=_test_urlopen_cross_process_response_rollup_metrics, - background_task=True, - ) - @insert_incoming_headers - @validate_external_node_params(params=_test_urlopen_cross_process_response_external_node_params) - @background_task(name="test_urllib2:test_urlopen_cross_process_response") - def _test(): - urllib2.urlopen(f"http://localhost:{server.port}/") - - _test() +# def test_urlopen_cross_process_response(server): +# _test_urlopen_cross_process_response_scoped_metrics = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] + +# _test_urlopen_cross_process_response_rollup_metrics = [ +# ("External/all", 1), +# ("External/allOther", 1), +# (f"External/localhost:{server.port}/all", 1), +# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), +# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), +# ] + +# _test_urlopen_cross_process_response_external_node_params = [ +# ("cross_process_id", "1#2"), +# ("external_txn_name", "test"), +# ("transaction_guid", "0123456789012345"), +# ] + +# @validate_transaction_metrics( +# "test_urllib2:test_urlopen_cross_process_response", +# scoped_metrics=_test_urlopen_cross_process_response_scoped_metrics, +# rollup_metrics=_test_urlopen_cross_process_response_rollup_metrics, +# background_task=True, +# ) +# @insert_incoming_headers +# @validate_external_node_params(params=_test_urlopen_cross_process_response_external_node_params) +# @background_task(name="test_urllib2:test_urlopen_cross_process_response") +# def _test(): +# urllib2.urlopen(f"http://localhost:{server.port}/") + +# _test() diff --git a/tests/external_httplib2/test_httplib2.py b/tests/external_httplib2/test_httplib2.py index f4fa0e7c9b..52ddf40d60 100644 --- a/tests/external_httplib2/test_httplib2.py +++ b/tests/external_httplib2/test_httplib2.py @@ -17,7 +17,7 @@ from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers -from testing_support.validators.validate_external_node_params import validate_external_node_params +# 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 @@ -113,39 +113,39 @@ def _test(): # @cat_enabled -def test_httplib2_cross_process_response(server): - _test_httplib2_cross_process_response_scoped_metrics = [ - (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) - ] - - _test_httplib2_cross_process_response_rollup_metrics = [ - ("External/all", 1), - ("External/allOther", 1), - (f"External/localhost:{server.port}/all", 1), - (f"ExternalApp/localhost:{server.port}/1#2/all", 1), - (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), - ] - - _test_httplib2_cross_process_response_external_node_params = [ - ("cross_process_id", "1#2"), - ("external_txn_name", "test"), - ("transaction_guid", "0123456789012345"), - ] - - @validate_transaction_metrics( - "test_httplib2:test_httplib2_cross_process_response", - scoped_metrics=_test_httplib2_cross_process_response_scoped_metrics, - rollup_metrics=_test_httplib2_cross_process_response_rollup_metrics, - background_task=True, - ) - @insert_incoming_headers - @validate_external_node_params(params=_test_httplib2_cross_process_response_external_node_params) - @background_task(name="test_httplib2:test_httplib2_cross_process_response") - def _test(): - connection = httplib2.HTTPConnectionWithTimeout("localhost", server.port) - connection.request("GET", "/") - response = connection.getresponse() - response.read() - connection.close() - - _test() +# def test_httplib2_cross_process_response(server): +# _test_httplib2_cross_process_response_scoped_metrics = [ +# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) +# ] + +# _test_httplib2_cross_process_response_rollup_metrics = [ +# ("External/all", 1), +# ("External/allOther", 1), +# (f"External/localhost:{server.port}/all", 1), +# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), +# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), +# ] + +# _test_httplib2_cross_process_response_external_node_params = [ +# ("cross_process_id", "1#2"), +# ("external_txn_name", "test"), +# ("transaction_guid", "0123456789012345"), +# ] + +# @validate_transaction_metrics( +# "test_httplib2:test_httplib2_cross_process_response", +# scoped_metrics=_test_httplib2_cross_process_response_scoped_metrics, +# rollup_metrics=_test_httplib2_cross_process_response_rollup_metrics, +# background_task=True, +# ) +# @insert_incoming_headers +# @validate_external_node_params(params=_test_httplib2_cross_process_response_external_node_params) +# @background_task(name="test_httplib2:test_httplib2_cross_process_response") +# def _test(): +# connection = httplib2.HTTPConnectionWithTimeout("localhost", server.port) +# connection.request("GET", "/") +# response = connection.getresponse() +# response.read() +# connection.close() + +# _test() diff --git a/tests/external_requests/test_requests.py b/tests/external_requests/test_requests.py index b2d39e7289..95e6ac73de 100644 --- a/tests/external_requests/test_requests.py +++ b/tests/external_requests/test_requests.py @@ -18,7 +18,7 @@ from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers from testing_support.fixtures import override_application_settings, validate_tt_parenting from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers -from testing_support.validators.validate_external_node_params import validate_external_node_params +# 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 @@ -176,36 +176,36 @@ def _test(): # @cat_enabled -def test_requests_cross_process_response(server): - _test_requests_cross_process_response_scoped_metrics = [ - (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) - ] - - _test_requests_cross_process_response_rollup_metrics = [ - ("External/all", 1), - ("External/allOther", 1), - (f"External/localhost:{server.port}/all", 1), - (f"ExternalApp/localhost:{server.port}/1#2/all", 1), - (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), - ] - - _test_requests_cross_process_response_external_node_params = [ - ("cross_process_id", "1#2"), - ("external_txn_name", "test"), - ("transaction_guid", "0123456789012345"), - ] - - @validate_transaction_errors(errors=[]) - @validate_transaction_metrics( - "test_requests:test_requests_cross_process_response", - scoped_metrics=_test_requests_cross_process_response_scoped_metrics, - rollup_metrics=_test_requests_cross_process_response_rollup_metrics, - background_task=True, - ) - @insert_incoming_headers - @validate_external_node_params(params=_test_requests_cross_process_response_external_node_params) - @background_task(name="test_requests:test_requests_cross_process_response") - def _test(): - requests.get(f"http://localhost:{server.port}/") - - _test() +# def test_requests_cross_process_response(server): +# _test_requests_cross_process_response_scoped_metrics = [ +# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) +# ] + +# _test_requests_cross_process_response_rollup_metrics = [ +# ("External/all", 1), +# ("External/allOther", 1), +# (f"External/localhost:{server.port}/all", 1), +# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), +# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), +# ] + +# _test_requests_cross_process_response_external_node_params = [ +# ("cross_process_id", "1#2"), +# ("external_txn_name", "test"), +# ("transaction_guid", "0123456789012345"), +# ] + +# @validate_transaction_errors(errors=[]) +# @validate_transaction_metrics( +# "test_requests:test_requests_cross_process_response", +# scoped_metrics=_test_requests_cross_process_response_scoped_metrics, +# rollup_metrics=_test_requests_cross_process_response_rollup_metrics, +# background_task=True, +# ) +# @insert_incoming_headers +# @validate_external_node_params(params=_test_requests_cross_process_response_external_node_params) +# @background_task(name="test_requests:test_requests_cross_process_response") +# def _test(): +# requests.get(f"http://localhost:{server.port}/") + +# _test() diff --git a/tests/external_urllib3/test_urllib3.py b/tests/external_urllib3/test_urllib3.py index 0669ab1b9d..9cca2341d1 100644 --- a/tests/external_urllib3/test_urllib3.py +++ b/tests/external_urllib3/test_urllib3.py @@ -24,7 +24,7 @@ from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers -from testing_support.validators.validate_external_node_params import validate_external_node_params +# 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 @@ -225,35 +225,35 @@ def _test(): # @cat_enabled -def test_urlopen_cross_process_response(server): - _test_urlopen_cross_process_response_scoped_metrics = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] - - _test_urlopen_cross_process_response_rollup_metrics = [ - ("External/all", 1), - ("External/allOther", 1), - (f"External/localhost:{server.port}/all", 1), - (f"ExternalApp/localhost:{server.port}/1#2/all", 1), - (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), - ] - - _test_urlopen_cross_process_response_external_node_params = [ - ("cross_process_id", "1#2"), - ("external_txn_name", "test"), - ("transaction_guid", "0123456789012345"), - ] - - @validate_transaction_errors(errors=[]) - @validate_transaction_metrics( - "test_urllib3:test_urlopen_cross_process_response", - scoped_metrics=_test_urlopen_cross_process_response_scoped_metrics, - rollup_metrics=_test_urlopen_cross_process_response_rollup_metrics, - background_task=True, - ) - @insert_incoming_headers - @validate_external_node_params(params=_test_urlopen_cross_process_response_external_node_params) - @background_task(name="test_urllib3:test_urlopen_cross_process_response") - def _test(): - pool = urllib3.HTTPConnectionPool(f"localhost:{server.port}") - pool.urlopen("GET", "/") - - _test() +# def test_urlopen_cross_process_response(server): +# _test_urlopen_cross_process_response_scoped_metrics = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] + +# _test_urlopen_cross_process_response_rollup_metrics = [ +# ("External/all", 1), +# ("External/allOther", 1), +# (f"External/localhost:{server.port}/all", 1), +# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), +# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), +# ] + +# _test_urlopen_cross_process_response_external_node_params = [ +# ("cross_process_id", "1#2"), +# ("external_txn_name", "test"), +# ("transaction_guid", "0123456789012345"), +# ] + +# @validate_transaction_errors(errors=[]) +# @validate_transaction_metrics( +# "test_urllib3:test_urlopen_cross_process_response", +# scoped_metrics=_test_urlopen_cross_process_response_scoped_metrics, +# rollup_metrics=_test_urlopen_cross_process_response_rollup_metrics, +# background_task=True, +# ) +# @insert_incoming_headers +# @validate_external_node_params(params=_test_urlopen_cross_process_response_external_node_params) +# @background_task(name="test_urllib3:test_urlopen_cross_process_response") +# def _test(): +# pool = urllib3.HTTPConnectionPool(f"localhost:{server.port}") +# pool.urlopen("GET", "/") + +# _test() diff --git a/tests/testing_support/validators/validate_external_node_params.py b/tests/testing_support/validators/validate_external_node_params.py deleted file mode 100644 index 9ff5bd0c24..0000000000 --- a/tests/testing_support/validators/validate_external_node_params.py +++ /dev/null @@ -1,51 +0,0 @@ -# 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 - - -def validate_external_node_params(params=None, forgone_params=None): - """ - Validate the parameters on the external node. - - params: a list of tuples - forgone_params: a flat list - """ - - if forgone_params is None: - forgone_params = [] - if params is None: - params = [] - - @transient_function_wrapper("newrelic.api.external_trace", "ExternalTrace.process_response_headers") - def _validate_external_node_params(wrapped, instance, args, kwargs): - result = wrapped(*args, **kwargs) - - # This is only validating that logic to extract cross process - # header and update params in ExternalTrace is succeeding. This - # is actually done after the ExternalTrace __exit__() is called - # with the ExternalNode only being updated by virtue of the - # original params dictionary being aliased rather than copied. - # So isn't strictly validating that params ended up in the actual - # ExternalNode in the transaction trace. - - for name, value in params: - assert instance.params[name] == value - - for name in forgone_params: - assert name not in instance.params - - return result - - return _validate_external_node_params From 80ab24a5f150fd1eff69ee13ab27b12893f76282 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 17:36:24 -0700 Subject: [PATCH 59/95] Rename CatHeaderMixin to HeaderMixin --- newrelic/api/external_trace.py | 4 ++-- newrelic/api/{cat_header_mixin.py => header_mixin.py} | 4 ++-- newrelic/api/message_trace.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) rename newrelic/api/{cat_header_mixin.py => header_mixin.py} (98%) diff --git a/newrelic/api/external_trace.py b/newrelic/api/external_trace.py index 6c0ef4df0f..c73bba9383 100644 --- a/newrelic/api/external_trace.py +++ b/newrelic/api/external_trace.py @@ -14,14 +14,14 @@ import functools -from newrelic.api.cat_header_mixin import CatHeaderMixin +from newrelic.api.header_mixin import HeaderMixin from newrelic.api.time_trace import TimeTrace, current_trace from newrelic.common.async_wrapper import async_wrapper as get_async_wrapper from newrelic.common.object_wrapper import FunctionWrapper, wrap_object from newrelic.core.external_node import ExternalNode -class ExternalTrace(CatHeaderMixin, TimeTrace): +class ExternalTrace(HeaderMixin, TimeTrace): def __init__(self, library, url, method=None, **kwargs): parent = kwargs.pop("parent", None) source = kwargs.pop("source", None) diff --git a/newrelic/api/cat_header_mixin.py b/newrelic/api/header_mixin.py similarity index 98% rename from newrelic/api/cat_header_mixin.py rename to newrelic/api/header_mixin.py index 3ba43a5769..ca4114bf7f 100644 --- a/newrelic/api/cat_header_mixin.py +++ b/newrelic/api/header_mixin.py @@ -22,8 +22,8 @@ # ) -# CatHeaderMixin assumes the mixin class also inherits from TimeTrace -class CatHeaderMixin: +# HeaderMixin assumes the mixin class also inherits from TimeTrace +class HeaderMixin: # cat_id_key = "X-NewRelic-ID" # cat_transaction_key = "X-NewRelic-Transaction" # cat_appdata_key = "X-NewRelic-App-Data" diff --git a/newrelic/api/message_trace.py b/newrelic/api/message_trace.py index 0514b2d941..999434d786 100644 --- a/newrelic/api/message_trace.py +++ b/newrelic/api/message_trace.py @@ -14,14 +14,14 @@ import functools -from newrelic.api.cat_header_mixin import CatHeaderMixin +from newrelic.api.header_mixin import HeaderMixin from newrelic.api.time_trace import TimeTrace, current_trace from newrelic.common.async_wrapper import async_wrapper as get_async_wrapper from newrelic.common.object_wrapper import FunctionWrapper, wrap_object from newrelic.core.message_node import MessageNode -class MessageTrace(CatHeaderMixin, TimeTrace): +class MessageTrace(HeaderMixin, TimeTrace): # cat_id_key = "NewRelicID" # cat_transaction_key = "NewRelicTransaction" # cat_appdata_key = "NewRelicAppData" From ddcee7e9f178d77fa1deda2afe47b3df89b25e6b Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 18:02:13 -0700 Subject: [PATCH 60/95] Remove _generate_response_headers --- newrelic/api/transaction.py | 94 +++++++++++------------ newrelic/api/web_transaction.py | 12 +-- tests/framework_tornado/test_externals.py | 2 +- 3 files changed, 54 insertions(+), 54 deletions(-) diff --git a/newrelic/api/transaction.py b/newrelic/api/transaction.py index 21d4dceace..3da9f73f7f 100644 --- a/newrelic/api/transaction.py +++ b/newrelic/api/transaction.py @@ -1401,55 +1401,55 @@ def accept_distributed_trace_headers(self, headers, transport_type="HTTP"): # except Exception: # pass - def _generate_response_headers(self, read_length=None): - nr_headers = [] - - # Generate metrics and response headers for inbound cross - # process web external calls. - - if self.client_cross_process_id is not None: - # Need to work out queueing time and duration up to this - # point for inclusion in metrics and response header. If the - # recording of the transaction had been prematurely stopped - # via an API call, only return time up until that call was - # made so it will match what is reported as duration for the - # transaction. - - if self.queue_start: - queue_time = self.start_time - self.queue_start - else: - queue_time = 0 - - if self.end_time: - duration = self.end_time - self.start_time - else: - duration = time.time() - self.start_time - - # Generate the additional response headers which provide - # information back to the caller. We need to freeze the - # transaction name before adding to the header. - - self._freeze_path() - - if read_length is None: - read_length = self._read_length - - read_length = read_length if read_length is not None else -1 - - payload = ( - self._settings.cross_process_id, - self.path, - queue_time, - duration, - read_length, - self.guid, - self.record_tt, - ) - app_data = json_encode(payload) + # def _generate_response_headers(self, read_length=None): + # nr_headers = [] + + # # Generate metrics and response headers for inbound cross + # # process web external calls. + + # if self.client_cross_process_id is not None: + # # Need to work out queueing time and duration up to this + # # point for inclusion in metrics and response header. If the + # # recording of the transaction had been prematurely stopped + # # via an API call, only return time up until that call was + # # made so it will match what is reported as duration for the + # # transaction. + + # if self.queue_start: + # queue_time = self.start_time - self.queue_start + # else: + # queue_time = 0 + + # if self.end_time: + # duration = self.end_time - self.start_time + # else: + # duration = time.time() - self.start_time + + # # Generate the additional response headers which provide + # # information back to the caller. We need to freeze the + # # transaction name before adding to the header. + + # self._freeze_path() + + # if read_length is None: + # read_length = self._read_length + + # read_length = read_length if read_length is not None else -1 + + # payload = ( + # self._settings.cross_process_id, + # self.path, + # queue_time, + # duration, + # read_length, + # self.guid, + # self.record_tt, + # ) + # app_data = json_encode(payload) - nr_headers.append(("X-NewRelic-App-Data", obfuscate(app_data, self._settings.encoding_key))) + # nr_headers.append(("X-NewRelic-App-Data", obfuscate(app_data, self._settings.encoding_key))) - return nr_headers + # return nr_headers # # This function is CAT related and has been deprecated. # # Eventually, this will be removed. Until then, coverage diff --git a/newrelic/api/web_transaction.py b/newrelic/api/web_transaction.py index 2325b18784..224adde913 100644 --- a/newrelic/api/web_transaction.py +++ b/newrelic/api/web_transaction.py @@ -340,13 +340,13 @@ def process_response(self, status_code, response_headers): if self.client_cross_process_id is None: return [] - # Generate CAT response headers - try: - read_length = int(self._request_headers.get("content-length")) - except Exception: - read_length = -1 + # # Generate CAT response headers + # try: + # read_length = int(self._request_headers.get("content-length")) + # except Exception: + # read_length = -1 - return self._generate_response_headers(read_length) + # return self._generate_response_headers(read_length) def _update_agent_attributes(self): if "accept" in self._request_headers: diff --git a/tests/framework_tornado/test_externals.py b/tests/framework_tornado/test_externals.py index 5d79c0e46d..42ae7e3321 100644 --- a/tests/framework_tornado/test_externals.py +++ b/tests/framework_tornado/test_externals.py @@ -197,7 +197,7 @@ def _test(): _test() -CAT_RESPONSE_CODE = None +# CAT_RESPONSE_CODE = None # def cat_response_handler(self): From 84a22e53ffb66567414511a15ec93449bde1d198 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 18:03:50 -0700 Subject: [PATCH 61/95] Remove insert_incoming_headers --- tests/external_http/test_http.py | 2 +- tests/external_httplib/test_httplib.py | 2 +- tests/external_httplib/test_urllib.py | 2 +- tests/external_httplib/test_urllib2.py | 2 +- tests/external_httplib2/test_httplib2.py | 2 +- tests/external_requests/test_requests.py | 2 +- tests/external_urllib3/test_urllib3.py | 2 +- tests/testing_support/external_fixtures.py | 16 ++++++++-------- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/external_http/test_http.py b/tests/external_http/test_http.py index 10b353c88b..89fccac8f6 100644 --- a/tests/external_http/test_http.py +++ b/tests/external_http/test_http.py @@ -15,7 +15,7 @@ import http.client import pytest -from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers # from testing_support.validators.validate_external_node_params import validate_external_node_params diff --git a/tests/external_httplib/test_httplib.py b/tests/external_httplib/test_httplib.py index 53133e7cbf..7de8308724 100644 --- a/tests/external_httplib/test_httplib.py +++ b/tests/external_httplib/test_httplib.py @@ -15,7 +15,7 @@ import http.client as httplib import pytest -from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers # from testing_support.validators.validate_external_node_params import validate_external_node_params diff --git a/tests/external_httplib/test_urllib.py b/tests/external_httplib/test_urllib.py index 3681462805..57879faa00 100644 --- a/tests/external_httplib/test_urllib.py +++ b/tests/external_httplib/test_urllib.py @@ -21,7 +21,7 @@ except ImportError: import urllib -from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers # from testing_support.fixtures import cat_enabled from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers # from testing_support.validators.validate_external_node_params import validate_external_node_params diff --git a/tests/external_httplib/test_urllib2.py b/tests/external_httplib/test_urllib2.py index 788c47d887..56e06a1bb1 100644 --- a/tests/external_httplib/test_urllib2.py +++ b/tests/external_httplib/test_urllib2.py @@ -15,7 +15,7 @@ import urllib.request as urllib2 import pytest -from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers # from testing_support.fixtures import cat_enabled from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers # from testing_support.validators.validate_external_node_params import validate_external_node_params diff --git a/tests/external_httplib2/test_httplib2.py b/tests/external_httplib2/test_httplib2.py index 52ddf40d60..3e4deaba76 100644 --- a/tests/external_httplib2/test_httplib2.py +++ b/tests/external_httplib2/test_httplib2.py @@ -14,7 +14,7 @@ import httplib2 import pytest -from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers # from testing_support.validators.validate_external_node_params import validate_external_node_params diff --git a/tests/external_requests/test_requests.py b/tests/external_requests/test_requests.py index 95e6ac73de..28f18b07d8 100644 --- a/tests/external_requests/test_requests.py +++ b/tests/external_requests/test_requests.py @@ -15,7 +15,7 @@ import pytest import requests import requests.exceptions -from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers from testing_support.fixtures import override_application_settings, validate_tt_parenting from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers # from testing_support.validators.validate_external_node_params import validate_external_node_params diff --git a/tests/external_urllib3/test_urllib3.py b/tests/external_urllib3/test_urllib3.py index 9cca2341d1..1ac8fa7e95 100644 --- a/tests/external_urllib3/test_urllib3.py +++ b/tests/external_urllib3/test_urllib3.py @@ -21,7 +21,7 @@ except ImportError: pass -from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers # from testing_support.validators.validate_external_node_params import validate_external_node_params diff --git a/tests/testing_support/external_fixtures.py b/tests/testing_support/external_fixtures.py index f0bd31be99..89e69cd92d 100644 --- a/tests/testing_support/external_fixtures.py +++ b/tests/testing_support/external_fixtures.py @@ -128,15 +128,15 @@ def _bind_params(header, *values): return wrapped(*args, **kwargs) -@transient_function_wrapper(httplib.__name__, "HTTPResponse.getheaders") -def insert_incoming_headers(wrapped, instance, args, kwargs): - transaction = current_transaction() +# @transient_function_wrapper(httplib.__name__, "HTTPResponse.getheaders") +# def insert_incoming_headers(wrapped, instance, args, kwargs): +# transaction = current_transaction() - if transaction is None: - return wrapped(*args, **kwargs) +# if transaction is None: +# return wrapped(*args, **kwargs) - headers = list(wrapped(*args, **kwargs)) +# headers = list(wrapped(*args, **kwargs)) - headers.extend(create_incoming_headers(transaction)) +# headers.extend(create_incoming_headers(transaction)) - return headers +# return headers From 840ec5a79f61e0654c60308a010abc500a61ffb4 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 18:04:35 -0700 Subject: [PATCH 62/95] Remove create_incoming_headers --- tests/testing_support/external_fixtures.py | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/testing_support/external_fixtures.py b/tests/testing_support/external_fixtures.py index 89e69cd92d..e0d72aad8a 100644 --- a/tests/testing_support/external_fixtures.py +++ b/tests/testing_support/external_fixtures.py @@ -20,30 +20,30 @@ from newrelic.common.object_wrapper import transient_function_wrapper -def create_incoming_headers(transaction): - settings = transaction.settings - encoding_key = settings.encoding_key +# def create_incoming_headers(transaction): +# settings = transaction.settings +# encoding_key = settings.encoding_key - headers = [] +# headers = [] - cross_process_id = "1#2" - path = "test" - queue_time = 1.0 - duration = 2.0 - read_length = 1024 - guid = "0123456789012345" - record_tt = False +# cross_process_id = "1#2" +# path = "test" +# queue_time = 1.0 +# duration = 2.0 +# read_length = 1024 +# guid = "0123456789012345" +# record_tt = False - payload = (cross_process_id, path, queue_time, duration, read_length, guid, record_tt) - app_data = json_encode(payload) +# payload = (cross_process_id, path, queue_time, duration, read_length, guid, record_tt) +# app_data = json_encode(payload) - value = obfuscate(app_data, encoding_key) +# value = obfuscate(app_data, encoding_key) - assert isinstance(value, str) +# assert isinstance(value, str) - headers.append(("X-NewRelic-App-Data", value)) +# headers.append(("X-NewRelic-App-Data", value)) - return headers +# return headers def validate_synthetics_external_trace_header(synthetics_header, synthetics_info_header): From c2bb71aeb2c3fd2e871099cd6f2fbbdaaf9c94c2 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 18:06:54 -0700 Subject: [PATCH 63/95] Remove X-NewRelic-App-Data --- tests/agent_features/test_asgi_distributed_tracing.py | 2 +- tests/agent_features/test_distributed_tracing.py | 2 +- tests/cross_agent/test_distributed_tracing.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/agent_features/test_asgi_distributed_tracing.py b/tests/agent_features/test_asgi_distributed_tracing.py index ae50d45cf3..993ba7865c 100644 --- a/tests/agent_features/test_asgi_distributed_tracing.py +++ b/tests/agent_features/test_asgi_distributed_tracing.py @@ -104,7 +104,7 @@ async def target_asgi_application(scope, receive, send): def test_distributed_tracing_web_transaction(): headers = {"newrelic": json.dumps(payload)} response = test_application.make_request("GET", "/", headers=headers) - assert "X-NewRelic-App-Data" not in response.headers + # assert "X-NewRelic-App-Data" not in response.headers class TestAsgiRequest: diff --git a/tests/agent_features/test_distributed_tracing.py b/tests/agent_features/test_distributed_tracing.py index 36261d97e2..ed7183f40d 100644 --- a/tests/agent_features/test_distributed_tracing.py +++ b/tests/agent_features/test_distributed_tracing.py @@ -111,7 +111,7 @@ def target_wsgi_application(environ, start_response): def test_distributed_tracing_web_transaction(): headers = {"newrelic": json.dumps(payload)} response = test_application.get("/", headers=headers) - assert "X-NewRelic-App-Data" not in response.headers + # assert "X-NewRelic-App-Data" not in response.headers @pytest.mark.parametrize("span_events", (True, False)) diff --git a/tests/cross_agent/test_distributed_tracing.py b/tests/cross_agent/test_distributed_tracing.py index a3536fcce5..144dd57e3e 100644 --- a/tests/cross_agent/test_distributed_tracing.py +++ b/tests/cross_agent/test_distributed_tracing.py @@ -219,7 +219,7 @@ def test_distributed_tracing( @override_application_settings(override_settings) def _test(): response = test_application.get("/", headers=headers) - assert "X-NewRelic-App-Data" not in response.headers + # assert "X-NewRelic-App-Data" not in response.headers if "Span" in intrinsics: span_intrinsics = intrinsics.get("Span") From f4d1182cb1ac65a4a8aa7e3acd2c7c2a9fa649f8 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 18:34:38 -0700 Subject: [PATCH 64/95] Remove cross_process_id --- newrelic/api/transaction.py | 14 ++-- newrelic/api/web_transaction.py | 6 +- newrelic/common/agent_http.py | 2 +- newrelic/core/config.py | 24 +++--- newrelic/core/external_node.py | 36 ++++----- newrelic/core/transaction_node.py | 2 +- tests/agent_features/test_error_events.py | 74 +++++++++---------- tests/agent_unittests/test_harvest_loop.py | 2 +- .../test_distributed_tracing.py | 2 +- 9 files changed, 82 insertions(+), 80 deletions(-) diff --git a/newrelic/api/transaction.py b/newrelic/api/transaction.py index 3da9f73f7f..64ba0e9ef4 100644 --- a/newrelic/api/transaction.py +++ b/newrelic/api/transaction.py @@ -289,7 +289,7 @@ def __init__(self, application, enabled=None, source=None): self._distributed_trace_state = 0 - self.client_cross_process_id = None + # self.client_cross_process_id = None self.client_account_id = None self.client_application_id = None self.referring_transaction_guid = None @@ -537,9 +537,9 @@ def __exit__(self, exc, value, tb): # self.total_time += exclusive - if self.client_cross_process_id is not None: - metric_name = f"ClientApplication/{self.client_cross_process_id}/all" - self.record_custom_metric(metric_name, duration) + # if self.client_cross_process_id is not None: + # metric_name = f"ClientApplication/{self.client_cross_process_id}/all" + # self.record_custom_metric(metric_name, duration) # Record supportability metrics for api calls @@ -599,7 +599,7 @@ def __exit__(self, exc, value, tb): guid=self.guid, cpu_time=self._cpu_user_time_value, suppress_transaction_trace=self.suppress_transaction_trace, - client_cross_process_id=self.client_cross_process_id, + # client_cross_process_id=self.client_cross_process_id, referring_transaction_guid=self.referring_transaction_guid, record_tt=self.record_tt, synthetics_resource_id=self.synthetics_resource_id, @@ -837,8 +837,8 @@ def trace_intrinsics(self): if self.referring_transaction_guid: i_attrs["referring_transaction_guid"] = self.referring_transaction_guid - if self.client_cross_process_id: - i_attrs["client_cross_process_id"] = self.client_cross_process_id + # if self.client_cross_process_id: + # i_attrs["client_cross_process_id"] = self.client_cross_process_id if self.trip_id: i_attrs["trip_id"] = self.trip_id # if self.path_hash: diff --git a/newrelic/api/web_transaction.py b/newrelic/api/web_transaction.py index 224adde913..754b357f4e 100644 --- a/newrelic/api/web_transaction.py +++ b/newrelic/api/web_transaction.py @@ -337,8 +337,10 @@ def process_response(self, status_code, response_headers): except Exception: pass - if self.client_cross_process_id is None: - return [] + return [] + + # if self.client_cross_process_id is None: + # return [] # # Generate CAT response headers # try: diff --git a/newrelic/common/agent_http.py b/newrelic/common/agent_http.py index 5534142547..c5e54d4962 100644 --- a/newrelic/common/agent_http.py +++ b/newrelic/common/agent_http.py @@ -521,7 +521,7 @@ class DeveloperModeClient(SupportabilityMixin, BaseClient): "url_rules": [], "collect_errors": True, "account_id": "12345", - "cross_process_id": "12345#67890", + # "cross_process_id": "12345#67890", "messages": [{"message": "Reporting to fake collector", "level": "INFO"}], "sampling_rate": 0, "collect_traces": True, diff --git a/newrelic/core/config.py b/newrelic/core/config.py index d2ad5be74e..8dfb25281c 100644 --- a/newrelic/core/config.py +++ b/newrelic/core/config.py @@ -792,7 +792,7 @@ def default_otlp_host(host): _settings.transaction_segment_terms = [] _settings.account_id = os.environ.get("NEW_RELIC_ACCOUNT_ID") -_settings.cross_process_id = None +# _settings.cross_process_id = None _settings.primary_application_id = os.environ.get("NEW_RELIC_PRIMARY_APPLICATION_ID", "Unknown") _settings.trusted_account_ids = [] _settings.trusted_account_key = os.environ.get("NEW_RELIC_TRUSTED_ACCOUNT_KEY") @@ -1351,19 +1351,19 @@ def apply_server_side_settings(server_side_config=None, settings=_settings): # Special case for account_id which will be sent instead of # cross_process_id in the future - if settings_snapshot.cross_process_id is not None: - vals = [settings_snapshot.account_id, settings_snapshot.application_id] - derived_vals = settings_snapshot.cross_process_id.split("#") + # if settings_snapshot.cross_process_id is not None: + # vals = [settings_snapshot.account_id, settings_snapshot.application_id] + # derived_vals = settings_snapshot.cross_process_id.split("#") - if len(derived_vals) == 2: - for idx, _val in enumerate(derived_vals): - # only override the value if the server side does not provide - # the value specifically - if vals[idx] is None: - vals[idx] = derived_vals[idx] + # if len(derived_vals) == 2: + # for idx, _val in enumerate(derived_vals): + # # only override the value if the server side does not provide + # # the value specifically + # if vals[idx] is None: + # vals[idx] = derived_vals[idx] - settings_snapshot.account_id = vals[0] - settings_snapshot.application_id = vals[1] + # settings_snapshot.account_id = vals[0] + # settings_snapshot.application_id = vals[1] # Reapply on top any local setting overrides. diff --git a/newrelic/core/external_node.py b/newrelic/core/external_node.py index 9165d2081f..0cfc804113 100644 --- a/newrelic/core/external_node.py +++ b/newrelic/core/external_node.py @@ -40,7 +40,7 @@ class ExternalNode(_ExternalNode, GenericNodeMixin): - cross_process_id = None + # cross_process_id = None external_txn_name = None @property @@ -111,45 +111,45 @@ def time_metrics(self, stats, root, parent): # Remove cross_process_id from the params dict otherwise it shows # up in the UI. - self.cross_process_id = self.params.pop("cross_process_id") + # self.cross_process_id = self.params.pop("cross_process_id") self.external_txn_name = self.params.pop("external_txn_name") except KeyError: - self.cross_process_id = None + # self.cross_process_id = None self.external_txn_name = None name = f"External/{netloc}/all" yield TimeMetric(name=name, scope="", duration=self.duration, exclusive=self.exclusive) - if self.cross_process_id is None: - method = self.method or "" + # if self.cross_process_id is None: + method = self.method or "" - name = f"External/{netloc}/{self.library}/{method}" + name = f"External/{netloc}/{self.library}/{method}" - yield TimeMetric(name=name, scope="", duration=self.duration, exclusive=self.exclusive) + yield TimeMetric(name=name, scope="", duration=self.duration, exclusive=self.exclusive) - yield TimeMetric(name=name, scope=root.path, duration=self.duration, exclusive=self.exclusive) + yield TimeMetric(name=name, scope=root.path, duration=self.duration, exclusive=self.exclusive) - else: - name = f"ExternalTransaction/{netloc}/{self.cross_process_id}/{self.external_txn_name}" + # else: + # name = f"ExternalTransaction/{netloc}/{self.cross_process_id}/{self.external_txn_name}" - yield TimeMetric(name=name, scope="", duration=self.duration, exclusive=self.exclusive) + # yield TimeMetric(name=name, scope="", duration=self.duration, exclusive=self.exclusive) - yield TimeMetric(name=name, scope=root.path, duration=self.duration, exclusive=self.exclusive) + # yield TimeMetric(name=name, scope=root.path, duration=self.duration, exclusive=self.exclusive) - name = f"ExternalApp/{netloc}/{self.cross_process_id}/all" + # name = f"ExternalApp/{netloc}/{self.cross_process_id}/all" - yield TimeMetric(name=name, scope="", duration=self.duration, exclusive=self.exclusive) + # yield TimeMetric(name=name, scope="", duration=self.duration, exclusive=self.exclusive) def trace_node(self, stats, root, connections): netloc = self.netloc method = self.method or "" - if self.cross_process_id is None: - name = f"External/{netloc}/{self.library}/{method}" - else: - name = f"ExternalTransaction/{netloc}/{self.cross_process_id}/{self.external_txn_name}" + # if self.cross_process_id is None: + name = f"External/{netloc}/{self.library}/{method}" + # else: + # name = f"ExternalTransaction/{netloc}/{self.cross_process_id}/{self.external_txn_name}" name = root.string_table.cache(name) diff --git a/newrelic/core/transaction_node.py b/newrelic/core/transaction_node.py index 020993e0c9..754f09598d 100644 --- a/newrelic/core/transaction_node.py +++ b/newrelic/core/transaction_node.py @@ -66,7 +66,7 @@ "guid", "cpu_time", "suppress_transaction_trace", - "client_cross_process_id", + # "client_cross_process_id", "referring_transaction_guid", "record_tt", "synthetics_resource_id", diff --git a/tests/agent_features/test_error_events.py b/tests/agent_features/test_error_events.py index b96f4fe0f6..5819b1656f 100644 --- a/tests/agent_features/test_error_events.py +++ b/tests/agent_features/test_error_events.py @@ -19,7 +19,7 @@ from testing_support.fixtures import ( # cat_enabled, # make_cross_agent_headers, - # make_synthetics_headers, + make_synthetics_headers, override_application_settings, reset_core_stats_engine, validate_error_event_sample_data, @@ -29,17 +29,17 @@ from testing_support.validators.validate_transaction_error_event_count import validate_transaction_error_event_count from newrelic.api.application import application_instance as application -# from newrelic.api.application import application_settings +from newrelic.api.application import application_settings from newrelic.api.time_trace import notice_error from newrelic.common.object_names import callable_name # Error in test app hard-coded as a ValueError -# SYNTHETICS_RESOURCE_ID = "09845779-16ef-4fa7-b7f2-44da8e62931c" -# SYNTHETICS_JOB_ID = "8c7dd3ba-4933-4cbb-b1ed-b62f511782f4" -# SYNTHETICS_MONITOR_ID = "dc452ae9-1a93-4ab5-8a33-600521e9cd00" -# SYNTHETICS_TYPE = "scheduled" -# SYNTHETICS_INITIATOR = "graphql" -# SYNTHETICS_ATTRIBUTES = {"exampleAttribute": "1"} +SYNTHETICS_RESOURCE_ID = "09845779-16ef-4fa7-b7f2-44da8e62931c" +SYNTHETICS_JOB_ID = "8c7dd3ba-4933-4cbb-b1ed-b62f511782f4" +SYNTHETICS_MONITOR_ID = "dc452ae9-1a93-4ab5-8a33-600521e9cd00" +SYNTHETICS_TYPE = "scheduled" +SYNTHETICS_INITIATOR = "graphql" +SYNTHETICS_ATTRIBUTES = {"exampleAttribute": "1"} ERR_MESSAGE = "Transaction had bad value" ERROR = ValueError(ERR_MESSAGE) @@ -119,35 +119,35 @@ def test_transaction_error_dt_headers(): response = fully_featured_application.get("/", extra_environ=test_environ) -# _intrinsic_attributes = { -# "error.class": callable_name(ERROR), -# "error.message": ERR_MESSAGE, -# "error.expected": False, -# "transactionName": "WebTransaction/Uri/", -# "nr.syntheticsResourceId": SYNTHETICS_RESOURCE_ID, -# "nr.syntheticsJobId": SYNTHETICS_JOB_ID, -# "nr.syntheticsMonitorId": SYNTHETICS_MONITOR_ID, -# "nr.syntheticsType": SYNTHETICS_TYPE, -# "nr.syntheticsInitiator": SYNTHETICS_INITIATOR, -# "nr.syntheticsExampleAttribute": "1", -# } - - -# @validate_error_event_sample_data(required_attrs=_intrinsic_attributes, required_user_attrs=True) -# def test_transaction_error_with_synthetics(): -# test_environ = {"err_message": ERR_MESSAGE} -# settings = application_settings() -# headers = make_synthetics_headers( -# settings.encoding_key, -# settings.trusted_account_ids[0], -# SYNTHETICS_RESOURCE_ID, -# SYNTHETICS_JOB_ID, -# SYNTHETICS_MONITOR_ID, -# SYNTHETICS_TYPE, -# SYNTHETICS_INITIATOR, -# SYNTHETICS_ATTRIBUTES, -# ) -# response = fully_featured_application.get("/", headers=headers, extra_environ=test_environ) +_intrinsic_attributes = { + "error.class": callable_name(ERROR), + "error.message": ERR_MESSAGE, + "error.expected": False, + "transactionName": "WebTransaction/Uri/", + "nr.syntheticsResourceId": SYNTHETICS_RESOURCE_ID, + "nr.syntheticsJobId": SYNTHETICS_JOB_ID, + "nr.syntheticsMonitorId": SYNTHETICS_MONITOR_ID, + "nr.syntheticsType": SYNTHETICS_TYPE, + "nr.syntheticsInitiator": SYNTHETICS_INITIATOR, + "nr.syntheticsExampleAttribute": "1", +} + + +@validate_error_event_sample_data(required_attrs=_intrinsic_attributes, required_user_attrs=True) +def test_transaction_error_with_synthetics(): + test_environ = {"err_message": ERR_MESSAGE} + settings = application_settings() + headers = make_synthetics_headers( + settings.encoding_key, + settings.trusted_account_ids[0], + SYNTHETICS_RESOURCE_ID, + SYNTHETICS_JOB_ID, + SYNTHETICS_MONITOR_ID, + SYNTHETICS_TYPE, + SYNTHETICS_INITIATOR, + SYNTHETICS_ATTRIBUTES, + ) + response = fully_featured_application.get("/", headers=headers, extra_environ=test_environ) _intrinsic_attributes = { diff --git a/tests/agent_unittests/test_harvest_loop.py b/tests/agent_unittests/test_harvest_loop.py index fb1fa0d5a1..13868c5afd 100644 --- a/tests/agent_unittests/test_harvest_loop.py +++ b/tests/agent_unittests/test_harvest_loop.py @@ -134,7 +134,7 @@ def transaction_node(request): guid="4485b89db608aece", cpu_time=0.0, suppress_transaction_trace=False, - client_cross_process_id=None, + # client_cross_process_id=None, referring_transaction_guid=None, record_tt=False, synthetics_resource_id=None, diff --git a/tests/messagebroker_pika/test_distributed_tracing.py b/tests/messagebroker_pika/test_distributed_tracing.py index f23e3e43a6..75dfd17b08 100644 --- a/tests/messagebroker_pika/test_distributed_tracing.py +++ b/tests/messagebroker_pika/test_distributed_tracing.py @@ -140,7 +140,7 @@ def do_basic_get(channel, QUEUE): txn = current_transaction() - assert txn.client_cross_process_id is None + # assert txn.client_cross_process_id is None assert txn.client_account_id is None assert txn.client_application_id is None From c19488c282e109adebcf274e482f82c7f75a7701 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 18:41:56 -0700 Subject: [PATCH 65/95] Remove external_txn_name --- newrelic/core/external_node.py | 20 ++++++++++---------- tests/testing_support/external_fixtures.py | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/newrelic/core/external_node.py b/newrelic/core/external_node.py index 0cfc804113..ceea3f0cac 100644 --- a/newrelic/core/external_node.py +++ b/newrelic/core/external_node.py @@ -41,7 +41,7 @@ class ExternalNode(_ExternalNode, GenericNodeMixin): # cross_process_id = None - external_txn_name = None + # external_txn_name = None @property def details(self): @@ -107,15 +107,15 @@ def time_metrics(self, stats, root, parent): netloc = self.netloc - try: - # Remove cross_process_id from the params dict otherwise it shows - # up in the UI. - - # self.cross_process_id = self.params.pop("cross_process_id") - self.external_txn_name = self.params.pop("external_txn_name") - except KeyError: - # self.cross_process_id = None - self.external_txn_name = None + # try: + # # Remove cross_process_id from the params dict otherwise it shows + # # up in the UI. + + # self.cross_process_id = self.params.pop("cross_process_id") + # self.external_txn_name = self.params.pop("external_txn_name") + # except KeyError: + # self.cross_process_id = None + # self.external_txn_name = None name = f"External/{netloc}/all" diff --git a/tests/testing_support/external_fixtures.py b/tests/testing_support/external_fixtures.py index e0d72aad8a..5bf7928dc5 100644 --- a/tests/testing_support/external_fixtures.py +++ b/tests/testing_support/external_fixtures.py @@ -16,7 +16,7 @@ from newrelic.api.external_trace import ExternalTrace from newrelic.api.transaction import current_transaction -from newrelic.common.encoding_utils import json_encode, obfuscate +# from newrelic.common.encoding_utils import json_encode, obfuscate from newrelic.common.object_wrapper import transient_function_wrapper From 17e43590cff538b3be3a4c4ea95cdd45a8b7ee27 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 18:47:18 -0700 Subject: [PATCH 66/95] Remove referring_transaction_guid --- newrelic/api/transaction.py | 8 ++++---- newrelic/core/transaction_node.py | 2 +- tests/agent_unittests/test_harvest_loop.py | 2 +- .../validators/validate_distributed_tracing_header.py | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/newrelic/api/transaction.py b/newrelic/api/transaction.py index 64ba0e9ef4..0747356a46 100644 --- a/newrelic/api/transaction.py +++ b/newrelic/api/transaction.py @@ -292,7 +292,7 @@ def __init__(self, application, enabled=None, source=None): # self.client_cross_process_id = None self.client_account_id = None self.client_application_id = None - self.referring_transaction_guid = None + # self.referring_transaction_guid = None self.record_tt = False self._trip_id = None # self._referring_path_hash = None @@ -600,7 +600,7 @@ def __exit__(self, exc, value, tb): cpu_time=self._cpu_user_time_value, suppress_transaction_trace=self.suppress_transaction_trace, # client_cross_process_id=self.client_cross_process_id, - referring_transaction_guid=self.referring_transaction_guid, + # referring_transaction_guid=self.referring_transaction_guid, record_tt=self.record_tt, synthetics_resource_id=self.synthetics_resource_id, synthetics_job_id=self.synthetics_job_id, @@ -835,8 +835,8 @@ def trace_intrinsics(self): """Intrinsic attributes for transaction traces and error traces""" i_attrs = {} - if self.referring_transaction_guid: - i_attrs["referring_transaction_guid"] = self.referring_transaction_guid + # if self.referring_transaction_guid: + # i_attrs["referring_transaction_guid"] = self.referring_transaction_guid # if self.client_cross_process_id: # i_attrs["client_cross_process_id"] = self.client_cross_process_id if self.trip_id: diff --git a/newrelic/core/transaction_node.py b/newrelic/core/transaction_node.py index 754f09598d..2cf6713d2b 100644 --- a/newrelic/core/transaction_node.py +++ b/newrelic/core/transaction_node.py @@ -67,7 +67,7 @@ "cpu_time", "suppress_transaction_trace", # "client_cross_process_id", - "referring_transaction_guid", + # "referring_transaction_guid", "record_tt", "synthetics_resource_id", "synthetics_job_id", diff --git a/tests/agent_unittests/test_harvest_loop.py b/tests/agent_unittests/test_harvest_loop.py index 13868c5afd..a86f2bf5da 100644 --- a/tests/agent_unittests/test_harvest_loop.py +++ b/tests/agent_unittests/test_harvest_loop.py @@ -135,7 +135,7 @@ def transaction_node(request): cpu_time=0.0, suppress_transaction_trace=False, # client_cross_process_id=None, - referring_transaction_guid=None, + # referring_transaction_guid=None, record_tt=False, synthetics_resource_id=None, synthetics_job_id=None, diff --git a/tests/testing_support/validators/validate_distributed_tracing_header.py b/tests/testing_support/validators/validate_distributed_tracing_header.py index 9034db6634..4015b819e2 100644 --- a/tests/testing_support/validators/validate_distributed_tracing_header.py +++ b/tests/testing_support/validators/validate_distributed_tracing_header.py @@ -65,10 +65,10 @@ def validate_distributed_tracing_header(header="newrelic"): # Verify referring transaction information assert len(data["tr"]) == 32 - if transaction.referring_transaction_guid is not None: - assert data["tr"] == transaction._trace_id - else: - assert data["tr"].startswith(transaction.guid) + # if transaction.referring_transaction_guid is not None: + # assert data["tr"] == transaction._trace_id + # else: + assert data["tr"].startswith(transaction.guid) assert "pa" not in data From 217063b9e7813f8d4313120f0fa8f5f7bf971092 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 19:20:24 -0700 Subject: [PATCH 67/95] Remove trip_id --- newrelic/api/transaction.py | 16 +++---- newrelic/core/transaction_node.py | 2 +- tests/agent_features/test_attribute.py | 3 +- .../test_attributes_in_action.py | 45 ++++++++++--------- tests/agent_unittests/test_harvest_loop.py | 2 +- 5 files changed, 37 insertions(+), 31 deletions(-) diff --git a/newrelic/api/transaction.py b/newrelic/api/transaction.py index 0747356a46..6bb0720109 100644 --- a/newrelic/api/transaction.py +++ b/newrelic/api/transaction.py @@ -34,7 +34,7 @@ W3CTraceParent, W3CTraceState, base64_decode, - convert_to_cat_metadata_value, + # convert_to_cat_metadata_value, deobfuscate, ensure_str, # generate_path_hash, @@ -294,7 +294,7 @@ def __init__(self, application, enabled=None, source=None): self.client_application_id = None # self.referring_transaction_guid = None self.record_tt = False - self._trip_id = None + # self._trip_id = None # self._referring_path_hash = None # self._alternate_path_hashes = {} # self.is_part_of_cat = False @@ -611,7 +611,7 @@ def __exit__(self, exc, value, tb): synthetics_attributes=self.synthetics_attributes, synthetics_info_header=self.synthetics_info_header, # is_part_of_cat=self.is_part_of_cat, - trip_id=self.trip_id, + # trip_id=self.trip_id, # path_hash=self.path_hash, # referring_path_hash=self._referring_path_hash, # alternate_path_hashes=self.alternate_path_hashes, @@ -732,9 +732,9 @@ def path(self): return f"{self.type}/{self.name_for_metric}" - @property - def trip_id(self): - return self._trip_id or self.guid + # @property + # def trip_id(self): + # return self._trip_id or self.guid @property def trace_id(self): @@ -839,8 +839,8 @@ def trace_intrinsics(self): # i_attrs["referring_transaction_guid"] = self.referring_transaction_guid # if self.client_cross_process_id: # i_attrs["client_cross_process_id"] = self.client_cross_process_id - if self.trip_id: - i_attrs["trip_id"] = self.trip_id + # if self.trip_id: + # i_attrs["trip_id"] = self.trip_id # if self.path_hash: # i_attrs["path_hash"] = self.path_hash if self.synthetics_resource_id: diff --git a/newrelic/core/transaction_node.py b/newrelic/core/transaction_node.py index 2cf6713d2b..1c5364dda2 100644 --- a/newrelic/core/transaction_node.py +++ b/newrelic/core/transaction_node.py @@ -78,7 +78,7 @@ "synthetics_attributes", "synthetics_info_header", # "is_part_of_cat", - "trip_id", + # "trip_id", # "path_hash", # "referring_path_hash", # "alternate_path_hashes", diff --git a/tests/agent_features/test_attribute.py b/tests/agent_features/test_attribute.py index a8410eab6b..a22a42605d 100644 --- a/tests/agent_features/test_attribute.py +++ b/tests/agent_features/test_attribute.py @@ -56,7 +56,8 @@ def target_wsgi_application(environ, start_response): return [output] -_required_intrinsics = ["trip_id", "totalTime"] +_required_intrinsics = ["totalTime"] +# _required_intrinsics = ["trip_id", "totalTime"] _forgone_intrinsics = [] diff --git a/tests/agent_features/test_attributes_in_action.py b/tests/agent_features/test_attributes_in_action.py index 4d0e601c1d..3bb378ac61 100644 --- a/tests/agent_features/test_attributes_in_action.py +++ b/tests/agent_features/test_attributes_in_action.py @@ -96,7 +96,7 @@ "timestamp", "totalTime", "error", - # "nr.apdexPerfZone", + "nr.apdexPerfZone", "apdexPerfZone", ) TRANS_EVENT_AGENT_KEYS = [ @@ -165,7 +165,8 @@ def normal_application(request): # Tests for checking the presence and format of agent attributes. # Test default settings. -_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": ["trip_id"]} +# _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": []} _expected_attributes_event = { "agent": TRACE_ERROR_AGENT_KEYS, @@ -183,7 +184,8 @@ def test_error_in_transaction_default_settings(normal_application): normal_application.get(REQUEST_URL, headers=REQUEST_HEADERS) -_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} +# _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": []} # @cat_enabled @@ -230,7 +232,8 @@ def test_browser_default_attribute_settings(normal_application): _override_settings = {"error_collector.attributes.exclude": ["request.parameters.*"]} -_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": []} +# _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": ["trip_id"]} _expected_attributes_event = { "agent": TRACE_ERROR_AGENT_KEYS, @@ -250,7 +253,8 @@ def test_error_in_transaction_exclude_request_params(normal_application): _override_settings = {"transaction_tracer.attributes.exclude": ["request.parameters.*"]} -_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": []} +# _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} @validate_transaction_trace_attributes(_expected_attributes, _expected_absent_attributes) @@ -261,7 +265,8 @@ def test_transaction_trace_exclude_request_params(normal_application): _override_settings = {"capture_params": True, "error_collector.attributes.exclude": ["request.parameters.*"]} -_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": []} +# _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} _expected_absent_attributes = {"agent": REQ_PARAMS, "user": [], "intrinsic": []} @@ -285,7 +290,7 @@ def test_transaction_trace_capture_params_exclude_request_params(normal_applicat _override_settings = {"error_collector.attributes.include": ["request.parameters.*"]} -_expected_attributes = {"agent": AGENT_KEYS_ALL, "user": ERROR_USER_ATTRS, "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": AGENT_KEYS_ALL, "user": ERROR_USER_ATTRS, "intrinsic": []} _expected_attributes_event = {"agent": AGENT_KEYS_ALL, "user": ERROR_USER_ATTRS, "intrinsic": ERROR_EVENT_INTRINSICS} @@ -299,7 +304,7 @@ def test_error_in_transaction_include_request_params(normal_application): _override_settings = {"transaction_tracer.attributes.include": ["request.parameters.*"]} -_expected_attributes = {"agent": AGENT_KEYS_ALL, "user": USER_ATTRS, "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": AGENT_KEYS_ALL, "user": USER_ATTRS, "intrinsic": []} @validate_transaction_trace_attributes(_expected_attributes) @@ -352,7 +357,7 @@ def test_browser_include_request_params(normal_application): _expected_attributes = { "agent": [*TRACE_ERROR_AGENT_KEYS, f"request.parameters.{URL_PARAM}"], "user": ERROR_USER_ATTRS, - "intrinsic": ["trip_id"], + "intrinsic": [], } _expected_attributes_event = { @@ -379,7 +384,7 @@ def test_error_in_transaction_include_exclude(normal_application): _expected_attributes = { "agent": [*TRACE_ERROR_AGENT_KEYS, f"request.parameters.{URL_PARAM}"], "user": USER_ATTRS, - "intrinsic": ["trip_id"], + "intrinsic": [], } @@ -434,7 +439,7 @@ def test_browser_include_exclude_request_params(normal_application): _override_settings = {"error_collector.attributes.exclude": ["puppies"]} -_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ["sunshine", "ohnoes"], "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ["sunshine", "ohnoes"], "intrinsic": []} _expected_attributes_event = { "agent": TRACE_ERROR_AGENT_KEYS, @@ -454,7 +459,7 @@ def test_error_in_transaction_exclude_user_attribute(normal_application): _override_settings = {"transaction_tracer.attributes.exclude": ["puppies"]} -_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ["sunshine"], "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ["sunshine"], "intrinsic": []} @validate_transaction_trace_attributes(_expected_attributes, _expected_absent_attributes) @@ -509,7 +514,7 @@ def test_browser_exclude_user_attribute(normal_application): _expected_attributes = { "agent": ["response.status", "request.headers.contentType", "request.headers.contentLength"], "user": ERROR_USER_ATTRS, - "intrinsic": ["trip_id"], + "intrinsic": [], } _expected_attributes_event = { @@ -531,7 +536,7 @@ def test_error_in_transaction_exclude_agent_attribute(normal_application): _expected_attributes = { "agent": ["response.status", "request.headers.contentType", "request.headers.contentLength"], "user": USER_ATTRS, - "intrinsic": ["trip_id"], + "intrinsic": [], } @@ -683,9 +688,9 @@ def test_browser_deprecated_capture_params_false(normal_application): # Test attempt to exclude intrinsic. -_override_settings = {"error_collector.attributes.exclude": ["trip_id"]} +_override_settings = {"error_collector.attributes.exclude": []} -_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": []} _expected_attributes_event = { "agent": TRACE_ERROR_AGENT_KEYS, @@ -703,9 +708,9 @@ def test_error_in_transaction_exclude_intrinsic(normal_application): normal_application.get(REQUEST_URL, headers=REQUEST_HEADERS) -_override_settings = {"transaction_tracer.attributes.exclude": ["trip_id"]} +_override_settings = {"transaction_tracer.attributes.exclude": []} -_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": []} @validate_transaction_trace_attributes(_expected_attributes, _expected_absent_attributes) @@ -747,7 +752,7 @@ def test_browser_exclude_intrinsic(normal_application): _override_settings = {"error_collector.attributes.enabled": False} -_expected_attributes = {"user": [], "agent": [], "intrinsic": ["trip_id"]} +_expected_attributes = {"user": [], "agent": [], "intrinsic": []} _expected_attributes_event = {"user": [], "agent": [], "intrinsic": ERROR_EVENT_INTRINSICS} @@ -800,7 +805,7 @@ def test_browser_attributes_disabled(normal_application): _override_settings = {"error_collector.attributes.exclude": ERROR_PARAMS} -_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": []} _expected_attributes_event = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ERROR_EVENT_INTRINSICS} diff --git a/tests/agent_unittests/test_harvest_loop.py b/tests/agent_unittests/test_harvest_loop.py index a86f2bf5da..2ca2fe5511 100644 --- a/tests/agent_unittests/test_harvest_loop.py +++ b/tests/agent_unittests/test_harvest_loop.py @@ -146,7 +146,7 @@ def transaction_node(request): synthetics_attributes=None, synthetics_info_header=None, # is_part_of_cat=False, - trip_id="4485b89db608aece", + # trip_id="4485b89db608aece", # path_hash=None, # referring_path_hash=None, # alternate_path_hashes=[], From 4907b1314a04864913d973673bd6c4aa673198dc Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 19:20:54 -0700 Subject: [PATCH 68/95] Remove convert_to_cat_metadata_value --- newrelic/common/encoding_utils.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/newrelic/common/encoding_utils.py b/newrelic/common/encoding_utils.py index 38f81ea397..3a5d34c3d5 100644 --- a/newrelic/common/encoding_utils.py +++ b/newrelic/common/encoding_utils.py @@ -368,13 +368,13 @@ def decode_newrelic_header(encoded_header, encoding_key): return decoded_header -def convert_to_cat_metadata_value(nr_headers): - if not nr_headers: - return None +# def convert_to_cat_metadata_value(nr_headers): +# if not nr_headers: +# return None - payload = json_encode(nr_headers) - cat_linking_value = base64_encode(payload) - return cat_linking_value +# payload = json_encode(nr_headers) +# cat_linking_value = base64_encode(payload) +# return cat_linking_value class DistributedTracePayload(dict): From c7b0584c7d0e1ec97cde724f089a8dc14abe08e4 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 19:21:15 -0700 Subject: [PATCH 69/95] Change names from cat_ to dt_ --- newrelic/hooks/framework_aiohttp.py | 22 +++++++++++----------- newrelic/hooks/framework_sanic.py | 12 ++++++------ newrelic/hooks/framework_tornado.py | 4 ++-- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/newrelic/hooks/framework_aiohttp.py b/newrelic/hooks/framework_aiohttp.py index 04d9f2484b..956f1bcc57 100644 --- a/newrelic/hooks/framework_aiohttp.py +++ b/newrelic/hooks/framework_aiohttp.py @@ -215,18 +215,18 @@ def items(self): return itertools.chain(self.__wrapped__.items(), nr_headers.items()) -def _nr_aiohttp_add_cat_headers_(wrapped, instance, args, kwargs): +def _nr_aiohttp_add_dt_headers_(wrapped, instance, args, kwargs): transaction = current_transaction() if transaction is None: return wrapped(*args, **kwargs) try: - cat_headers = ExternalTrace.generate_request_headers(transaction) + dt_headers = ExternalTrace.generate_request_headers(transaction) except: return wrapped(*args, **kwargs) tmp = instance.headers - instance.headers = HeaderProxy(tmp, cat_headers) + instance.headers = HeaderProxy(tmp, dt_headers) if is_coroutine_callable(wrapped): @@ -245,21 +245,21 @@ async def new_coro(): instance.headers = tmp -def _nr_aiohttp_add_cat_headers_simple_(wrapped, instance, args, kwargs): +def _nr_aiohttp_add_dt_headers_simple_(wrapped, instance, args, kwargs): transaction = current_transaction() if transaction is None: return wrapped(*args, **kwargs) try: - cat_headers = ExternalTrace.generate_request_headers(transaction) + dt_headers = ExternalTrace.generate_request_headers(transaction) except: return wrapped(*args, **kwargs) - for k, _ in cat_headers: + for k, _ in dt_headers: if k in instance.headers: return wrapped(*args, **kwargs) - instance.headers.update(cat_headers) + instance.headers.update(dt_headers) return wrapped(*args, **kwargs) @@ -304,15 +304,15 @@ def instrument_aiohttp_client_reqrep(module): if version_info >= (2, 0): # TODO: Verify that headers_preserve_casting is always True # if headers_preserve_casing(): - cat_wrapper = _nr_aiohttp_add_cat_headers_simple_ + dt_wrapper = _nr_aiohttp_add_dt_headers_simple_ # else: - # cat_wrapper = _nr_aiohttp_add_cat_headers_ + # dt_wrapper = _nr_aiohttp_add_dt_headers_ - wrap_function_wrapper(module, "ClientRequest.send", cat_wrapper) + wrap_function_wrapper(module, "ClientRequest.send", dt_wrapper) def instrument_aiohttp_protocol(module): - wrap_function_wrapper(module, "Request.send_headers", _nr_aiohttp_add_cat_headers_) + wrap_function_wrapper(module, "Request.send_headers", _nr_aiohttp_add_dt_headers_) def instrument_aiohttp_web_urldispatcher(module): diff --git a/newrelic/hooks/framework_sanic.py b/newrelic/hooks/framework_sanic.py index 14077eb6d9..a201cba5a0 100644 --- a/newrelic/hooks/framework_sanic.py +++ b/newrelic/hooks/framework_sanic.py @@ -170,9 +170,9 @@ def _nr_sanic_response_get_headers(wrapped, instance, args, kwargs): return result # instance is the response object - cat_headers = transaction.process_response(str(instance.status), instance.headers.items()) + dt_headers = transaction.process_response(str(instance.status), instance.headers.items()) - for header_name, header_value in cat_headers: + for header_name, header_value in dt_headers: if header_name not in instance.headers: instance.headers[header_name] = header_value @@ -189,9 +189,9 @@ async def _nr_sanic_response_send(wrapped, instance, args, kwargs): return result # instance is the response object - cat_headers = transaction.process_response(str(instance.status), instance.headers.items()) + dt_headers = transaction.process_response(str(instance.status), instance.headers.items()) - for header_name, header_value in cat_headers: + for header_name, header_value in dt_headers: if header_name not in instance.headers: instance.headers[header_name] = header_value @@ -205,9 +205,9 @@ def _nr_sanic_response_parse_headers(wrapped, instance, args, kwargs): return wrapped(*args, **kwargs) # instance is the response object - cat_headers = transaction.process_response(str(instance.status), instance.headers.items()) + dt_headers = transaction.process_response(str(instance.status), instance.headers.items()) - for header_name, header_value in cat_headers: + for header_name, header_value in dt_headers: if header_name not in instance.headers: instance.headers[header_name] = header_value diff --git a/newrelic/hooks/framework_tornado.py b/newrelic/hooks/framework_tornado.py index 92b6a84019..4b7c1cd523 100644 --- a/newrelic/hooks/framework_tornado.py +++ b/newrelic/hooks/framework_tornado.py @@ -132,9 +132,9 @@ def wrap_write_headers(wrapped, instance, args, kwargs): if transaction: http_status, headers = _bind_response_headers(*args, **kwargs) - cat_headers = transaction.process_response(http_status, headers) + dt_headers = transaction.process_response(http_status, headers) - for name, value in cat_headers: + for name, value in dt_headers: headers.add(name, value) return wrapped(*args, **kwargs) From 624c8f21d8035d3114a28843b4859c8a85399e33 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 10 Sep 2025 20:02:04 -0700 Subject: [PATCH 70/95] Tweak test --- tests/agent_features/test_attributes_in_action.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/agent_features/test_attributes_in_action.py b/tests/agent_features/test_attributes_in_action.py index 3bb378ac61..dd5df5d7ce 100644 --- a/tests/agent_features/test_attributes_in_action.py +++ b/tests/agent_features/test_attributes_in_action.py @@ -96,7 +96,7 @@ "timestamp", "totalTime", "error", - "nr.apdexPerfZone", + # "nr.apdexPerfZone", "apdexPerfZone", ) TRANS_EVENT_AGENT_KEYS = [ @@ -174,7 +174,7 @@ def normal_application(request): "intrinsic": ERROR_EVENT_INTRINSICS, } -_expected_absent_attributes = {"agent": REQ_PARAMS, "user": [], "intrinsic": DISTRIBUTED_TRACE_ATTRS} +_expected_absent_attributes = {"agent": REQ_PARAMS, "user": [], "intrinsic": []} # @cat_enabled @@ -190,7 +190,7 @@ def test_error_in_transaction_default_settings(normal_application): # @cat_enabled @validate_transaction_trace_attributes(_expected_attributes, _expected_absent_attributes) -@override_application_settings({}) +# @override_application_settings({}) def test_transaction_trace_default_attribute_settings(normal_application): normal_application.get(REQUEST_URL, headers=REQUEST_HEADERS) From d4ebb133e1483286375a2701c6ef068104a10038 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Thu, 11 Sep 2025 19:13:31 -0700 Subject: [PATCH 71/95] Remove skip all test file --- tests/framework_aiohttp/test_client.py | 241 ------------------------- 1 file changed, 241 deletions(-) delete mode 100644 tests/framework_aiohttp/test_client.py diff --git a/tests/framework_aiohttp/test_client.py b/tests/framework_aiohttp/test_client.py deleted file mode 100644 index 751ad4c965..0000000000 --- a/tests/framework_aiohttp/test_client.py +++ /dev/null @@ -1,241 +0,0 @@ -# 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 asyncio - -import aiohttp -import pytest -from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics -from yarl import URL - -from newrelic.api.background_task import background_task -from newrelic.api.function_trace import function_trace - -version_info = tuple(int(_) for _ in aiohttp.__version__.split(".")[:2]) -skipif_aiohttp3 = pytest.mark.skipif( - version_info >= (3, 0), reason="This version of aiohttp does not support yield from syntax" -) - - -async def fetch(method, url): - with aiohttp.ClientSession() as session: - _method = getattr(session, method) - response = await asyncio.wait_for(_method(url), timeout=None) - response.raise_for_status() - await response.text() - - -@background_task(name="fetch_multiple") -async def fetch_multiple(method, url): - coros = [fetch(method, url) for _ in range(2)] - return asyncio.gather(*coros, return_exceptions=True) - - -if version_info < (2, 0): - _expected_error_class = aiohttp.errors.HttpProcessingError -else: - _expected_error_class = aiohttp.client_exceptions.ClientResponseError - - -def task(loop, method, exc_expected, url): - future = asyncio.ensure_future(fetch_multiple(method, url)) - text_list = loop.run_until_complete(future) - if exc_expected: - assert isinstance(text_list[0], _expected_error_class) - assert isinstance(text_list[1], _expected_error_class) - else: - assert text_list[0] == text_list[1] - - -test_matrix = ( - ("get", False), - ("post", True), - ("options", True), - ("head", True), - ("put", True), - ("patch", True), - ("delete", True), -) - - -@skipif_aiohttp3 -@pytest.mark.parametrize("method,exc_expected", test_matrix) -def test_client_yield_from(event_loop, local_server_info, method, exc_expected): - @validate_transaction_metrics( - "fetch_multiple", - background_task=True, - scoped_metrics=[(local_server_info.base_metric + method.upper(), 2)], - rollup_metrics=[(local_server_info.base_metric + method.upper(), 2)], - ) - def task_test(): - task(event_loop, method, exc_expected, local_server_info.url) - - task_test() - - -@skipif_aiohttp3 -def test_client_yarl_yield_from(event_loop, local_server_info): - method = "get" - - @validate_transaction_metrics( - "fetch_multiple", - background_task=True, - scoped_metrics=[(local_server_info.base_metric + method.upper(), 2)], - rollup_metrics=[(local_server_info.base_metric + method.upper(), 2)], - ) - def task_test(): - task(event_loop, method, False, URL(local_server_info.url)) - - task_test() - - -@skipif_aiohttp3 -@pytest.mark.parametrize("method,exc_expected", test_matrix) -def test_client_no_txn_yield_from(event_loop, local_server_info, method, exc_expected): - def task_test(): - task(event_loop, method, exc_expected, local_server_info.url) - - task_test() - - -@skipif_aiohttp3 -@pytest.mark.parametrize("method,exc_expected", test_matrix) -def test_client_throw_yield_from(event_loop, local_server_info, method, exc_expected): - class ThrowerException(ValueError): - pass - - @background_task(name="test_client_throw_yield_from") - async def self_driving_thrower(): - with aiohttp.ClientSession() as session: - coro = session._request(method.upper(), local_server_info.url) - - # activate the coroutine - coro.send(None) - - # inject error - coro.throw(ThrowerException()) - - @validate_transaction_metrics( - "test_client_throw_yield_from", - background_task=True, - scoped_metrics=[(local_server_info.base_metric + method.upper(), 1)], - rollup_metrics=[(local_server_info.base_metric + method.upper(), 1)], - ) - def task_test(): - with pytest.raises(ThrowerException): - event_loop.run_until_complete(self_driving_thrower()) - - task_test() - - -@skipif_aiohttp3 -@pytest.mark.parametrize("method,exc_expected", test_matrix) -def test_client_close_yield_from(event_loop, local_server_info, method, exc_expected): - @background_task(name="test_client_close_yield_from") - async def self_driving_closer(): - with aiohttp.ClientSession() as session: - coro = session._request(method.upper(), local_server_info.url) - - # activate the coroutine - coro.send(None) - - # force close - coro.close() - - @validate_transaction_metrics( - "test_client_close_yield_from", - background_task=True, - scoped_metrics=[(local_server_info.base_metric + method.upper(), 1)], - rollup_metrics=[(local_server_info.base_metric + method.upper(), 1)], - ) - def task_test(): - event_loop.run_until_complete(self_driving_closer()) - - task_test() - - -test_ws_matrix = ( - # the 127.0.0.1 server does not accept websocket requests, hence an - # exception is expected but a metric will still be created - ("ws_connect", True), -) - - -@skipif_aiohttp3 -@pytest.mark.parametrize("method,exc_expected", test_ws_matrix) -def test_ws_connect_yield_from(event_loop, local_server_info, method, exc_expected): - @validate_transaction_metrics( - "fetch_multiple", - background_task=True, - scoped_metrics=[(f"{local_server_info.base_metric}GET", 2)], - rollup_metrics=[(f"{local_server_info.base_metric}GET", 2)], - ) - def task_test(): - task(event_loop, method, exc_expected, local_server_info.url) - - task_test() - - -@skipif_aiohttp3 -@pytest.mark.parametrize("method,exc_expected", test_matrix) -def test_create_task_yield_from(event_loop, local_server_info, method, exc_expected): - # `loop.create_task` returns a Task object which uses the coroutine's - # `send` method, not `__next__` - - async def fetch_task(loop): - with aiohttp.ClientSession() as session: - coro = getattr(session, method) - resp = await loop.create_task(coro(local_server_info.url)) - resp.raise_for_status() - await resp.text() - - @background_task(name="test_create_task_yield_from") - async def fetch_multiple(loop): - coros = [fetch_task(loop) for _ in range(2)] - return asyncio.gather(*coros, return_exceptions=True) - - @validate_transaction_metrics( - "test_create_task_yield_from", - background_task=True, - scoped_metrics=[(local_server_info.base_metric + method.upper(), 2)], - rollup_metrics=[(local_server_info.base_metric + method.upper(), 2)], - ) - def task_test(): - result = event_loop.run_until_complete(fetch_multiple(event_loop)) - if exc_expected: - assert isinstance(result[0], _expected_error_class) - assert isinstance(result[1], _expected_error_class) - else: - assert result[0] == result[1] - - task_test() - - -@skipif_aiohttp3 -@pytest.mark.parametrize("method,exc_expected", test_matrix) -def test_terminal_node_yield_from(event_loop, local_server_info, method, exc_expected): - """ - This test injects a terminal node into a simple background task workflow. - It was added to validate a bug where our coro.send() wrapper would fail - when transaction's current node was terminal. - """ - - def task_test(): - @function_trace(terminal=True) - def execute_task(): - task(event_loop, method, exc_expected, local_server_info.url) - - execute_task() - - task_test() From 693c8c61a3f53031de65837e31cb0854ffbc9ef0 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Thu, 11 Sep 2025 19:14:44 -0700 Subject: [PATCH 72/95] Fix syntax from rebase --- newrelic/core/agent_protocol.py | 1 + newrelic/hooks/framework_tornado.py | 4 ++-- tests/agent_features/test_attributes_in_action.py | 12 ++++++++---- tests/framework_aiohttp/conftest.py | 5 +++-- tests/framework_aiohttp/test_client_async_await.py | 9 ++++++--- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/newrelic/core/agent_protocol.py b/newrelic/core/agent_protocol.py index 7570dd00e2..bc7727c6e1 100644 --- a/newrelic/core/agent_protocol.py +++ b/newrelic/core/agent_protocol.py @@ -522,6 +522,7 @@ def finalize(self): @classmethod def connect(cls, app_name, linked_applications, environment, settings, client_cls=ServerlessModeClient): aws_lambda_metadata = settings.aws_lambda_metadata + settings = finalize_application_settings() # settings = finalize_application_settings({"cross_application_tracer.enabled": False}, settings) # Metadata must come from the original settings object since it # can be modified later diff --git a/newrelic/hooks/framework_tornado.py b/newrelic/hooks/framework_tornado.py index 4b7c1cd523..1c865d139c 100644 --- a/newrelic/hooks/framework_tornado.py +++ b/newrelic/hooks/framework_tornado.py @@ -253,7 +253,7 @@ async def wrapper(req, raise_error): raise finally: if response: - trace.process_response(response.status_code) + trace.process_response(response.code) # trace.process_response_headers(response.headers.get_all()) return response @@ -270,7 +270,7 @@ def wrap_httpclient_fetch(wrapped, instance, args, kwargs): outgoing_headers = trace.generate_request_headers(current_transaction()) for header_name, header_value in outgoing_headers: - # User headers should override our CAT headers + # User headers should override our headers if header_name in req.headers: continue req.headers[header_name] = header_value diff --git a/tests/agent_features/test_attributes_in_action.py b/tests/agent_features/test_attributes_in_action.py index dd5df5d7ce..3db3d4dc88 100644 --- a/tests/agent_features/test_attributes_in_action.py +++ b/tests/agent_features/test_attributes_in_action.py @@ -582,7 +582,8 @@ def test_span_event_exclude_agent_attribute(normal_application): _override_settings = {"capture_params": True} -_expected_attributes = {"agent": AGENT_KEYS_ALL, "user": ERROR_USER_ATTRS, "intrinsic": ["trip_id"]} +# _expected_attributes = {"agent": AGENT_KEYS_ALL, "user": ERROR_USER_ATTRS, "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": AGENT_KEYS_ALL, "user": ERROR_USER_ATTRS, "intrinsic": []} _expected_attributes_event = {"agent": AGENT_KEYS_ALL, "user": ERROR_USER_ATTRS, "intrinsic": ERROR_EVENT_INTRINSICS} @@ -594,7 +595,8 @@ def test_error_in_transaction_deprecated_capture_params_true(normal_application) normal_application.get(REQUEST_URL, headers=REQUEST_HEADERS) -_expected_attributes = {"agent": AGENT_KEYS_ALL, "user": USER_ATTRS, "intrinsic": ["trip_id"]} +# _expected_attributes = {"agent": AGENT_KEYS_ALL, "user": USER_ATTRS, "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": AGENT_KEYS_ALL, "user": USER_ATTRS, "intrinsic": []} @validate_transaction_trace_attributes(_expected_attributes) @@ -633,7 +635,8 @@ def test_browser_deprecated_capture_params_true(normal_application): _override_settings = {"capture_params": False} -_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": ["trip_id"]} +# _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": []} _expected_attributes_event = { "agent": TRACE_ERROR_AGENT_KEYS, @@ -651,7 +654,8 @@ def test_error_in_transaction_deprecated_capture_params_false(normal_application normal_application.get(REQUEST_URL, headers=REQUEST_HEADERS) -_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} +# _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} +_expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": []} @validate_transaction_trace_attributes(_expected_attributes, _expected_absent_attributes) diff --git a/tests/framework_aiohttp/conftest.py b/tests/framework_aiohttp/conftest.py index cfcea49122..ea2688def3 100644 --- a/tests/framework_aiohttp/conftest.py +++ b/tests/framework_aiohttp/conftest.py @@ -115,7 +115,7 @@ def handler(self): def mock_external_http_server(): response_values = [] - def respond_with_cat_header(self): + def respond_with_dt_header(self): headers, response_code = response_values.pop() self.send_response(response_code) for header, value in headers: @@ -124,7 +124,8 @@ def respond_with_cat_header(self): self.wfile.write(b"") # with MockExternalHTTPServer(handler=respond_with_cat_header) as server: - with MockExternalHTTPServer() as server: + # with MockExternalHTTPServer() as server: + with MockExternalHTTPServer(handler=respond_with_dt_header) as server: yield (server, response_values) diff --git a/tests/framework_aiohttp/test_client_async_await.py b/tests/framework_aiohttp/test_client_async_await.py index 8e57305060..3b2856e969 100644 --- a/tests/framework_aiohttp/test_client_async_await.py +++ b/tests/framework_aiohttp/test_client_async_await.py @@ -52,7 +52,8 @@ def task(loop, method, exc_expected, url): assert isinstance(text_list[0], _expected_error_class), text_list[0].__class__ assert isinstance(text_list[1], _expected_error_class), text_list[1].__class__ else: - assert text_list[0] == text_list[1], text_list + assert text_list[0] + assert text_list[1] test_matrix = ( @@ -133,7 +134,8 @@ def task_test(): assert isinstance(text_list[0], _expected_error_class), text_list[0].__class__ assert isinstance(text_list[1], _expected_error_class), text_list[1].__class__ else: - assert text_list[0] == text_list[1], text_list + assert text_list[0] + assert text_list[1] task_test() @@ -189,7 +191,8 @@ def task_test(): assert isinstance(result[0], _expected_error_class), result[0].__class__ assert isinstance(result[1], _expected_error_class), result[1].__class__ else: - assert result[0] == result[1] + assert result[0] + assert result[1] task_test() From b7c8aae28a90bb1d0184d375027055c8bac258c5 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Fri, 12 Sep 2025 12:04:10 -0700 Subject: [PATCH 73/95] Fix httplib test --- tests/external_httplib/test_httplib.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/external_httplib/test_httplib.py b/tests/external_httplib/test_httplib.py index 7de8308724..e82ce9e58e 100644 --- a/tests/external_httplib/test_httplib.py +++ b/tests/external_httplib/test_httplib.py @@ -13,6 +13,8 @@ # limitations under the License. import http.client as httplib +import json +import base64 import pytest from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers @@ -239,7 +241,7 @@ def test_transaction(): def test_httplib_nr_headers_added(server): connection = httplib.HTTPConnection("localhost", server.port) - key = "newrelic" + key = "header_key" value = "testval" headers = [] @@ -256,7 +258,6 @@ def test_transaction(): )(test_transaction) test_transaction() connection.close() - # verify newrelic headers already added do not get overrode assert headers[0][key] == value From 0f174539da79e6c229a953486f6349fc75a08029 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Fri, 12 Sep 2025 16:13:15 -0700 Subject: [PATCH 74/95] Fix Megalinter errors --- newrelic/api/message_transaction.py | 1 - newrelic/api/transaction.py | 8 +------- newrelic/api/web_transaction.py | 2 +- newrelic/common/encoding_utils.py | 3 +-- newrelic/hooks/framework_aiohttp.py | 5 ++--- tests/agent_features/test_serverless_mode.py | 1 + tests/external_http/test_http.py | 3 ++- tests/external_httplib/test_httplib.py | 5 +++-- tests/external_httplib/test_urllib.py | 4 +++- tests/external_httplib/test_urllib2.py | 4 +++- tests/external_httplib2/test_httplib2.py | 3 ++- tests/external_httpx/test_client.py | 7 ++++--- tests/external_requests/test_requests.py | 3 ++- tests/external_urllib3/test_urllib3.py | 3 ++- tests/framework_aiohttp/conftest.py | 2 +- tests/framework_aiohttp/test_client_async_await.py | 1 + tests/framework_sanic/test_distributed_trace.py | 1 + tests/framework_tornado/test_externals.py | 4 +++- tests/messagebroker_pika/test_pika_produce.py | 2 +- tests/testing_support/external_fixtures.py | 2 +- .../validators/validate_cross_process_headers.py | 1 + .../validators/validate_messagebroker_headers.py | 1 + 22 files changed, 37 insertions(+), 29 deletions(-) diff --git a/newrelic/api/message_transaction.py b/newrelic/api/message_transaction.py index f37bdf8070..a62a545482 100644 --- a/newrelic/api/message_transaction.py +++ b/newrelic/api/message_transaction.py @@ -16,7 +16,6 @@ from newrelic.api.application import Application, application_instance from newrelic.api.background_task import BackgroundTask -from newrelic.api.message_trace import MessageTrace from newrelic.api.transaction import current_transaction from newrelic.common.async_proxy import TransactionContext, async_proxy from newrelic.common.object_wrapper import FunctionWrapper, wrap_object diff --git a/newrelic/api/transaction.py b/newrelic/api/transaction.py index 6bb0720109..0b1bbca1c0 100644 --- a/newrelic/api/transaction.py +++ b/newrelic/api/transaction.py @@ -33,14 +33,8 @@ NrTraceState, W3CTraceParent, W3CTraceState, - base64_decode, - # convert_to_cat_metadata_value, - deobfuscate, ensure_str, # generate_path_hash, - json_decode, - json_encode, - obfuscate, snake_case, ) from newrelic.core.attribute import ( @@ -1347,7 +1341,7 @@ def accept_distributed_trace_headers(self, headers, transport_type="HTTP"): # if not self.enabled: # return - # If CAT is disabled, function will exit early. + # If CAT is disabled, function will exit early. # if not ( # settings.cross_application_tracer.enabled # and settings.cross_process_id diff --git a/newrelic/api/web_transaction.py b/newrelic/api/web_transaction.py index 754b357f4e..6659829702 100644 --- a/newrelic/api/web_transaction.py +++ b/newrelic/api/web_transaction.py @@ -338,7 +338,7 @@ def process_response(self, status_code, response_headers): pass return [] - + # if self.client_cross_process_id is None: # return [] diff --git a/newrelic/common/encoding_utils.py b/newrelic/common/encoding_utils.py index 3a5d34c3d5..8aa435af0b 100644 --- a/newrelic/common/encoding_utils.py +++ b/newrelic/common/encoding_utils.py @@ -19,7 +19,6 @@ import base64 import gzip -import hashlib import io import itertools import json @@ -245,7 +244,7 @@ def unpack_field(field): # if not isinstance(name, bytes): # name = name.encode("UTF-8") -# path_hash = rotated ^ int(hashlib.md5(name).hexdigest()[-8:], base=16) # noqa: S324 +# path_hash = rotated ^ int(hashlib.md5(name).hexdigest()[-8:], base=16) # return f"{path_hash:08x}" diff --git a/newrelic/hooks/framework_aiohttp.py b/newrelic/hooks/framework_aiohttp.py index 956f1bcc57..0636c39853 100644 --- a/newrelic/hooks/framework_aiohttp.py +++ b/newrelic/hooks/framework_aiohttp.py @@ -15,9 +15,9 @@ import inspect import itertools -from newrelic.api.time_trace import notice_error from newrelic.api.external_trace import ExternalTrace from newrelic.api.function_trace import function_trace +from newrelic.api.time_trace import notice_error from newrelic.api.transaction import current_transaction, ignore_transaction from newrelic.api.web_transaction import web_transaction from newrelic.common.async_wrapper import async_wrapper, is_coroutine_callable @@ -380,8 +380,7 @@ async def _coro(*_args, **_kwargs): def instrument_aiohttp_web(module): - global _nr_process_response - # TODO: Verify that this is correct/not always True + # global _nr_process_response # if not headers_preserve_casing(): # _nr_process_response = _nr_process_response_proxy diff --git a/tests/agent_features/test_serverless_mode.py b/tests/agent_features/test_serverless_mode.py index f77d739f75..6c4d5fa348 100644 --- a/tests/agent_features/test_serverless_mode.py +++ b/tests/agent_features/test_serverless_mode.py @@ -17,6 +17,7 @@ import pytest from testing_support.fixtures import override_generic_settings from testing_support.validators.validate_serverless_data import validate_serverless_data + # from testing_support.validators.validate_serverless_metadata import validate_serverless_metadata from testing_support.validators.validate_serverless_payload import validate_serverless_payload diff --git a/tests/external_http/test_http.py b/tests/external_http/test_http.py index 89fccac8f6..883c40dbd2 100644 --- a/tests/external_http/test_http.py +++ b/tests/external_http/test_http.py @@ -15,9 +15,10 @@ import http.client import pytest -from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers # , insert_incoming_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers + # from testing_support.validators.validate_external_node_params import validate_external_node_params from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics diff --git a/tests/external_httplib/test_httplib.py b/tests/external_httplib/test_httplib.py index e82ce9e58e..2db632a4ac 100644 --- a/tests/external_httplib/test_httplib.py +++ b/tests/external_httplib/test_httplib.py @@ -12,14 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. +import base64 import http.client as httplib import json -import base64 import pytest -from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers # , insert_incoming_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers + # from testing_support.validators.validate_external_node_params import validate_external_node_params from testing_support.validators.validate_span_events import validate_span_events from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics diff --git a/tests/external_httplib/test_urllib.py b/tests/external_httplib/test_urllib.py index 57879faa00..5f966dd1ad 100644 --- a/tests/external_httplib/test_urllib.py +++ b/tests/external_httplib/test_urllib.py @@ -21,9 +21,11 @@ except ImportError: import urllib -from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers # , insert_incoming_headers + # from testing_support.fixtures import cat_enabled from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers + # from testing_support.validators.validate_external_node_params import validate_external_node_params from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics diff --git a/tests/external_httplib/test_urllib2.py b/tests/external_httplib/test_urllib2.py index 56e06a1bb1..16aa056ca7 100644 --- a/tests/external_httplib/test_urllib2.py +++ b/tests/external_httplib/test_urllib2.py @@ -15,9 +15,11 @@ import urllib.request as urllib2 import pytest -from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers # , insert_incoming_headers + # from testing_support.fixtures import cat_enabled from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers + # from testing_support.validators.validate_external_node_params import validate_external_node_params from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics diff --git a/tests/external_httplib2/test_httplib2.py b/tests/external_httplib2/test_httplib2.py index 3e4deaba76..55ca4c1c73 100644 --- a/tests/external_httplib2/test_httplib2.py +++ b/tests/external_httplib2/test_httplib2.py @@ -14,9 +14,10 @@ import httplib2 import pytest -from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers # , insert_incoming_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers + # from testing_support.validators.validate_external_node_params import validate_external_node_params from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics diff --git a/tests/external_httpx/test_client.py b/tests/external_httpx/test_client.py index 178edd3dd7..5b97105b79 100644 --- a/tests/external_httpx/test_client.py +++ b/tests/external_httpx/test_client.py @@ -55,11 +55,12 @@ # self.end_headers() # self.wfile.write(b"Example Data") + def dt_response_handler(self): if not DT_RESPONSE_CODE: raise ValueError("DT_RESPONSE_CODE must be a valid status_code.") - - response = str(self.headers).encode("utf-8") # Might need to put headers here + + response = str(self.headers).encode("utf-8") # Might need to put headers here self.send_response(DT_RESPONSE_CODE) self.end_headers() self.wfile.write(response) @@ -178,7 +179,7 @@ async def _test(): @override_application_settings( - {"distributed_tracing.enabled": True, "span_events.enabled": True} #, "cross_application_tracer.enabled": True} + {"distributed_tracing.enabled": True, "span_events.enabled": True} # , "cross_application_tracer.enabled": True} ) @validate_transaction_errors(errors=[]) @background_task(name="test_sync_cross_process_override_headers") diff --git a/tests/external_requests/test_requests.py b/tests/external_requests/test_requests.py index 28f18b07d8..f7f0c5220b 100644 --- a/tests/external_requests/test_requests.py +++ b/tests/external_requests/test_requests.py @@ -15,9 +15,10 @@ import pytest import requests import requests.exceptions -from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers # , insert_incoming_headers from testing_support.fixtures import override_application_settings, validate_tt_parenting from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers + # 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 diff --git a/tests/external_urllib3/test_urllib3.py b/tests/external_urllib3/test_urllib3.py index 1ac8fa7e95..f82c183225 100644 --- a/tests/external_urllib3/test_urllib3.py +++ b/tests/external_urllib3/test_urllib3.py @@ -21,9 +21,10 @@ except ImportError: pass -from testing_support.external_fixtures import cache_outgoing_headers #, insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers # , insert_incoming_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers + # 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 diff --git a/tests/framework_aiohttp/conftest.py b/tests/framework_aiohttp/conftest.py index ea2688def3..0d295b3fff 100644 --- a/tests/framework_aiohttp/conftest.py +++ b/tests/framework_aiohttp/conftest.py @@ -125,7 +125,7 @@ def respond_with_dt_header(self): # with MockExternalHTTPServer(handler=respond_with_cat_header) as server: # with MockExternalHTTPServer() as server: - with MockExternalHTTPServer(handler=respond_with_dt_header) as server: + with MockExternalHTTPServer(handler=respond_with_dt_header) as server: yield (server, response_values) diff --git a/tests/framework_aiohttp/test_client_async_await.py b/tests/framework_aiohttp/test_client_async_await.py index 3b2856e969..a30cd830b6 100644 --- a/tests/framework_aiohttp/test_client_async_await.py +++ b/tests/framework_aiohttp/test_client_async_await.py @@ -16,6 +16,7 @@ import aiohttp import pytest + # from testing_support.fixtures import cat_enabled from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from yarl import URL diff --git a/tests/framework_sanic/test_distributed_trace.py b/tests/framework_sanic/test_distributed_trace.py index 3a92e84649..436bd0e68c 100644 --- a/tests/framework_sanic/test_distributed_trace.py +++ b/tests/framework_sanic/test_distributed_trace.py @@ -30,6 +30,7 @@ from newrelic.api.application import application_instance from newrelic.api.external_trace import ExternalTrace from newrelic.api.transaction import Transaction + # from newrelic.common.encoding_utils import deobfuscate BASE_METRICS = [("Function/_target_application:index", 1)] diff --git a/tests/framework_tornado/test_externals.py b/tests/framework_tornado/test_externals.py index 42ae7e3321..8d7ef80ab2 100644 --- a/tests/framework_tornado/test_externals.py +++ b/tests/framework_tornado/test_externals.py @@ -19,12 +19,14 @@ import pytest from testing_support.fixtures import override_application_settings from testing_support.mock_external_http_server import MockExternalHTTPHResponseHeadersServer, MockExternalHTTPServer + # from testing_support.validators.validate_distributed_tracing_header import validate_distributed_tracing_header # from testing_support.validators.validate_outbound_headers import validate_outbound_headers 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 + # from newrelic.api.transaction import current_transaction ENCODING_KEY = "1234567890123456789012345678901234567890" @@ -187,7 +189,7 @@ def _test(): # if distributed_tracing: # validate_distributed_tracing_header(header="Newrelic") # else: - # validate_outbound_headers() + # validate_outbound_headers() # else: # # new relic shouldn't add anything to the outgoing # assert "x-newrelic" not in body, body diff --git a/tests/messagebroker_pika/test_pika_produce.py b/tests/messagebroker_pika/test_pika_produce.py index 1d8a01c6ec..bda5635e89 100644 --- a/tests/messagebroker_pika/test_pika_produce.py +++ b/tests/messagebroker_pika/test_pika_produce.py @@ -172,7 +172,7 @@ def test_blocking_connection_reply_to(producer): @pytest.mark.parametrize("enable_distributed_tracing", [True, False]) def test_blocking_connection_headers(enable_distributed_tracing): override_settings = { - "distributed_tracing.enabled": enable_distributed_tracing, + "distributed_tracing.enabled": enable_distributed_tracing # "cross_application_tracer.enabled": not enable_distributed_tracing, } rollup_metrics = list(_test_blocking_connection_metrics) diff --git a/tests/testing_support/external_fixtures.py b/tests/testing_support/external_fixtures.py index 5bf7928dc5..5746cdbcad 100644 --- a/tests/testing_support/external_fixtures.py +++ b/tests/testing_support/external_fixtures.py @@ -16,10 +16,10 @@ from newrelic.api.external_trace import ExternalTrace from newrelic.api.transaction import current_transaction + # from newrelic.common.encoding_utils import json_encode, obfuscate from newrelic.common.object_wrapper import transient_function_wrapper - # def create_incoming_headers(transaction): # settings = transaction.settings # encoding_key = settings.encoding_key diff --git a/tests/testing_support/validators/validate_cross_process_headers.py b/tests/testing_support/validators/validate_cross_process_headers.py index 214d3c8db1..5f9f82f882 100644 --- a/tests/testing_support/validators/validate_cross_process_headers.py +++ b/tests/testing_support/validators/validate_cross_process_headers.py @@ -15,6 +15,7 @@ from newrelic.api.transaction import current_transaction from newrelic.common.object_wrapper import function_wrapper from testing_support.validators.validate_distributed_tracing_header import validate_distributed_tracing_header + # from testing_support.validators.validate_outbound_headers import validate_outbound_headers diff --git a/tests/testing_support/validators/validate_messagebroker_headers.py b/tests/testing_support/validators/validate_messagebroker_headers.py index e86e7188d0..f45a47adb4 100644 --- a/tests/testing_support/validators/validate_messagebroker_headers.py +++ b/tests/testing_support/validators/validate_messagebroker_headers.py @@ -15,6 +15,7 @@ from newrelic.api.transaction import current_transaction from newrelic.common.object_wrapper import function_wrapper from testing_support.validators.validate_distributed_tracing_header import validate_distributed_tracing_header + # from testing_support.validators.validate_outbound_headers import validate_outbound_headers From 36c4fa9d23548007eb50e8bc196367944ba6832a Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Fri, 12 Sep 2025 18:01:47 -0700 Subject: [PATCH 75/95] Remove commented out code --- newrelic/api/external_trace.py | 1 - newrelic/api/header_mixin.py | 77 ------ newrelic/api/message_trace.py | 3 - newrelic/api/message_transaction.py | 4 - newrelic/api/transaction.py | 225 ------------------ newrelic/api/web_transaction.py | 15 -- newrelic/common/agent_http.py | 1 - newrelic/common/encoding_utils.py | 26 -- newrelic/config.py | 9 - newrelic/core/agent_protocol.py | 1 - newrelic/core/config.py | 25 -- newrelic/core/external_node.py | 28 --- newrelic/core/transaction_node.py | 25 -- newrelic/hooks/application_celery.py | 10 - newrelic/hooks/external_httplib.py | 26 +- newrelic/hooks/framework_aiohttp.py | 20 -- newrelic/hooks/framework_tornado.py | 1 - newrelic/hooks/messagebroker_pika.py | 4 - .../test_asgi_distributed_tracing.py | 1 - tests/agent_features/test_attribute.py | 1 - .../test_attributes_in_action.py | 24 +- .../test_distributed_tracing.py | 1 - tests/agent_features/test_error_events.py | 4 - tests/agent_features/test_serverless_mode.py | 20 -- tests/agent_features/test_synthetics.py | 4 - tests/agent_unittests/test_agent_protocol.py | 3 - tests/agent_unittests/test_harvest_loop.py | 7 - tests/cross_agent/test_distributed_tracing.py | 1 - tests/external_http/test_http.py | 47 +--- tests/external_httplib/test_httplib.py | 83 +------ tests/external_httplib/test_urllib.py | 41 +--- tests/external_httplib/test_urllib2.py | 39 +-- tests/external_httplib2/test_httplib2.py | 49 +--- tests/external_httpx/test_client.py | 111 +-------- tests/external_requests/test_requests.py | 50 +--- tests/external_urllib3/test_urllib3.py | 46 +--- tests/framework_aiohttp/conftest.py | 2 - .../test_client_async_await.py | 8 - tests/framework_aiohttp/test_server_dt.py | 136 +---------- tests/framework_sanic/conftest.py | 2 - .../framework_sanic/test_distributed_trace.py | 92 +------ .../framework_tornado/_target_application.py | 32 --- tests/framework_tornado/test_externals.py | 119 +-------- tests/framework_tornado/test_inbound_dt.py | 70 ------ .../test_distributed_tracing.py | 6 - tests/messagebroker_pika/test_pika_produce.py | 5 +- tests/testing_support/external_fixtures.py | 41 ---- tests/testing_support/fixtures.py | 21 -- .../validate_cross_process_headers.py | 4 - .../validate_distributed_tracing_header.py | 3 - .../validate_messagebroker_headers.py | 4 - .../validators/validate_synthetics_event.py | 2 - 52 files changed, 37 insertions(+), 1543 deletions(-) diff --git a/newrelic/api/external_trace.py b/newrelic/api/external_trace.py index c73bba9383..f2fa11ccba 100644 --- a/newrelic/api/external_trace.py +++ b/newrelic/api/external_trace.py @@ -40,7 +40,6 @@ def __repr__(self): def process_response(self, status_code, headers=None): self._add_agent_attribute("http.statusCode", status_code) - # self.process_response_headers(headers) def terminal_node(self): return True diff --git a/newrelic/api/header_mixin.py b/newrelic/api/header_mixin.py index ca4114bf7f..22d7299be9 100644 --- a/newrelic/api/header_mixin.py +++ b/newrelic/api/header_mixin.py @@ -12,24 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -# from newrelic.common.encoding_utils import ( -# base64_decode, -# base64_encode, -# deobfuscate, -# json_decode, -# json_encode, -# obfuscate, -# ) - # HeaderMixin assumes the mixin class also inherits from TimeTrace class HeaderMixin: - # cat_id_key = "X-NewRelic-ID" - # cat_transaction_key = "X-NewRelic-Transaction" - # cat_appdata_key = "X-NewRelic-App-Data" synthetics_key = "X-NewRelic-Synthetics" synthetics_info_key = "X-NewRelic-Synthetics-Info" - # cat_metadata_key = "x-newrelic-trace" distributed_trace_key = "newrelic" settings = None @@ -39,41 +26,6 @@ def __enter__(self): self.settings = self.transaction.settings or None return result - # def process_response_headers(self, response_headers): - # """ - # Decode the response headers and create appropriate metrics based on the - # header values. The response_headers are passed in as a list of tuples. - # [(HEADER_NAME0, HEADER_VALUE0), (HEADER_NAME1, HEADER_VALUE1)] - - # """ - - # settings = self.settings - # if not settings: - # return - - # if not settings.cross_application_tracer.enabled: - # return - - # appdata = None - # try: - # for k, v in response_headers: - # if k.upper() == self.cat_appdata_key.upper(): - # appdata = json_decode(deobfuscate(v, settings.encoding_key)) - # break - - # if appdata: - # self.params["cross_process_id"] = appdata[0] - # self.params["external_txn_name"] = appdata[1] - # self.params["transaction_guid"] = appdata[5] - - # except Exception: - # pass - - # def process_response_metadata(self, cat_linking_value): - # payload = base64_decode(cat_linking_value) - # nr_headers = json_decode(payload) - # self.process_response_headers(nr_headers.items()) - @classmethod def generate_request_headers(cls, transaction): """ @@ -92,38 +44,9 @@ def generate_request_headers(cls, transaction): if settings.distributed_tracing.enabled: transaction.insert_distributed_trace_headers(nr_headers) - # elif settings.cross_application_tracer.enabled: - # transaction.is_part_of_cat = True - # path_hash = transaction.path_hash - # if path_hash is None: - # # Disable cat if path_hash fails to generate. - # transaction.is_part_of_cat = False - # else: - # encoded_cross_process_id = obfuscate(settings.cross_process_id, settings.encoding_key) - # nr_headers.append((cls.cat_id_key, encoded_cross_process_id)) - - # transaction_data = [transaction.guid, transaction.record_tt, transaction.trip_id, path_hash] - # encoded_transaction = obfuscate(json_encode(transaction_data), settings.encoding_key) - # nr_headers.append((cls.cat_transaction_key, encoded_transaction)) - if transaction.synthetics_header: nr_headers.append((cls.synthetics_key, transaction.synthetics_header)) if transaction.synthetics_info_header: nr_headers.append((cls.synthetics_info_key, transaction.synthetics_info_header)) return nr_headers - - # @staticmethod - # def _convert_to_cat_metadata_value(nr_headers): - # payload = json_encode(nr_headers) - # cat_linking_value = base64_encode(payload) - # return cat_linking_value - - # @classmethod - # def get_request_metadata(cls, transaction): - # nr_headers = dict(cls.generate_request_headers(transaction)) - - # if not nr_headers: - # return None - - # return cls._convert_to_cat_metadata_value(nr_headers) diff --git a/newrelic/api/message_trace.py b/newrelic/api/message_trace.py index 999434d786..560bdfa3b0 100644 --- a/newrelic/api/message_trace.py +++ b/newrelic/api/message_trace.py @@ -22,9 +22,6 @@ class MessageTrace(HeaderMixin, TimeTrace): - # cat_id_key = "NewRelicID" - # cat_transaction_key = "NewRelicTransaction" - # cat_appdata_key = "NewRelicAppData" synthetics_key = "NewRelicSynthetics" synthetics_info_key = "NewRelicSyntheticsInfo" diff --git a/newrelic/api/message_transaction.py b/newrelic/api/message_transaction.py index a62a545482..5383c72dca 100644 --- a/newrelic/api/message_transaction.py +++ b/newrelic/api/message_transaction.py @@ -46,10 +46,6 @@ def __init__( if headers is not None and self.settings is not None: if self.settings.distributed_tracing.enabled: self.accept_distributed_trace_headers(headers, transport_type=transport_type) - # elif self.settings.cross_application_tracer.enabled: - # self._process_incoming_cat_headers( - # headers.pop(MessageTrace.cat_id_key, None), headers.pop(MessageTrace.cat_transaction_key, None) - # ) self.routing_key = routing_key self.exchange_type = exchange_type diff --git a/newrelic/api/transaction.py b/newrelic/api/transaction.py index 0b1bbca1c0..aa456e4ab8 100644 --- a/newrelic/api/transaction.py +++ b/newrelic/api/transaction.py @@ -34,7 +34,6 @@ W3CTraceParent, W3CTraceState, ensure_str, - # generate_path_hash, snake_case, ) from newrelic.core.attribute import ( @@ -283,15 +282,9 @@ def __init__(self, application, enabled=None, source=None): self._distributed_trace_state = 0 - # self.client_cross_process_id = None self.client_account_id = None self.client_application_id = None - # self.referring_transaction_guid = None self.record_tt = False - # self._trip_id = None - # self._referring_path_hash = None - # self._alternate_path_hashes = {} - # self.is_part_of_cat = False # Synthetics Header self.synthetics_resource_id = None @@ -528,13 +521,8 @@ def __exit__(self, exc, value, tb): ) # Add transaction exclusive time to total exclusive time - # self.total_time += exclusive - # if self.client_cross_process_id is not None: - # metric_name = f"ClientApplication/{self.client_cross_process_id}/all" - # self.record_custom_metric(metric_name, duration) - # Record supportability metrics for api calls for key, value in self._transaction_metrics.items(): @@ -593,8 +581,6 @@ def __exit__(self, exc, value, tb): guid=self.guid, cpu_time=self._cpu_user_time_value, suppress_transaction_trace=self.suppress_transaction_trace, - # client_cross_process_id=self.client_cross_process_id, - # referring_transaction_guid=self.referring_transaction_guid, record_tt=self.record_tt, synthetics_resource_id=self.synthetics_resource_id, synthetics_job_id=self.synthetics_job_id, @@ -604,11 +590,6 @@ def __exit__(self, exc, value, tb): synthetics_initiator=self.synthetics_initiator, synthetics_attributes=self.synthetics_attributes, synthetics_info_header=self.synthetics_info_header, - # is_part_of_cat=self.is_part_of_cat, - # trip_id=self.trip_id, - # path_hash=self.path_hash, - # referring_path_hash=self._referring_path_hash, - # alternate_path_hashes=self.alternate_path_hashes, trace_intrinsics=self.trace_intrinsics, distributed_trace_intrinsics=self.distributed_trace_intrinsics, agent_attributes=agent_attributes, @@ -726,72 +707,10 @@ def path(self): return f"{self.type}/{self.name_for_metric}" - # @property - # def trip_id(self): - # return self._trip_id or self.guid - @property def trace_id(self): return self._trace_id - # @property - # def alternate_path_hashes(self): - # """Return the alternate path hashes but not including the current path - # hash. - - # """ - # # return sorted(set(self._alternate_path_hashes.values()) - {self.path_hash}) - # return sorted(set(self._alternate_path_hashes.values()) - {None}) - - # @property - # def path_hash(self): - # """Path hash is a 32-bit digest of the string "appname;txn_name" - # XORed with the referring_path_hash. Since the txn_name can change - # during the course of a transaction, up to 10 path_hashes are stored - # in _alternate_path_hashes. Before generating the path hash, check the - # _alternate_path_hashes to determine if we've seen this identifier and - # return the value. - - # """ - - # # if not self.is_part_of_cat: - # # return None - # return None - - # identifier = f"{self.application.name};{self.path}" - - # # Check if identifier is already part of the _alternate_path_hashes and - # # return the value if available. - - # if self._alternate_path_hashes.get(identifier): - # return self._alternate_path_hashes[identifier] - - # # If the referring_path_hash is unavailable then we use '0' as the - # # seed. - - # try: - # seed = int((self._referring_path_hash or "0"), base=16) - # except Exception: - # seed = 0 - - # try: - # path_hash = generate_path_hash(identifier, seed) - # except ValueError: - # _logger.warning( - # "Unable to generate cross application tracer headers. " - # "MD5 hashing may not be available. (Is this system FIPS compliant?) " - # "We recommend enabling distributed tracing instead. For details and a transition guide see " - # "https://docs.newrelic.com/docs/agents/python-agent/configuration/python-agent-configuration#distributed-tracing-settings" - # ) - # return None - - # # Only store up to 10 alternate path hashes. - - # if len(self._alternate_path_hashes) < 10: - # self._alternate_path_hashes[identifier] = path_hash - - # return path_hash - @property def attribute_filter(self): return self._settings.attribute_filter @@ -829,14 +748,6 @@ def trace_intrinsics(self): """Intrinsic attributes for transaction traces and error traces""" i_attrs = {} - # if self.referring_transaction_guid: - # i_attrs["referring_transaction_guid"] = self.referring_transaction_guid - # if self.client_cross_process_id: - # i_attrs["client_cross_process_id"] = self.client_cross_process_id - # if self.trip_id: - # i_attrs["trip_id"] = self.trip_id - # if self.path_hash: - # i_attrs["path_hash"] = self.path_hash if self.synthetics_resource_id: i_attrs["synthetics_resource_id"] = self.synthetics_resource_id if self.synthetics_job_id: @@ -1335,142 +1246,6 @@ def accept_distributed_trace_headers(self, headers, transport_type="HTTP"): # metric for the lack of payload/distributed_header self._accept_distributed_trace_payload(distributed_header, transport_type) - # def _process_incoming_cat_headers(self, encoded_cross_process_id, encoded_txn_header): - # settings = self._settings - - # if not self.enabled: - # return - - # If CAT is disabled, function will exit early. - # if not ( - # settings.cross_application_tracer.enabled - # and settings.cross_process_id - # and settings.trusted_account_ids - # and settings.encoding_key - # ): - # return - - # if encoded_cross_process_id is None: - # return - - # try: - # client_cross_process_id = deobfuscate(encoded_cross_process_id, settings.encoding_key) - - # # The cross process ID consists of the client - # # account ID and the ID of the specific application - # # the client is recording requests against. We need - # # to validate that the client account ID is in the - # # list of trusted account IDs and ignore it if it - # # isn't. The trusted account IDs list has the - # # account IDs as integers, so save the client ones - # # away as integers here so easier to compare later. - - # client_account_id, client_application_id = map(int, client_cross_process_id.split("#")) - - # if client_account_id not in settings.trusted_account_ids: - # return - - # self.client_cross_process_id = client_cross_process_id - # self.client_account_id = client_account_id - # self.client_application_id = client_application_id - - # txn_header = json_decode(deobfuscate(encoded_txn_header, settings.encoding_key)) - - # if txn_header: - # self.is_part_of_cat = True - # self.referring_transaction_guid = txn_header[0] - - # # Incoming record_tt is OR'd with existing - # # record_tt. In the scenario where we make multiple - # # ext request, this will ensure we don't set the - # # record_tt to False by a later request if it was - # # set to True by an earlier request. - - # self.record_tt = self.record_tt or txn_header[1] - - # if isinstance(txn_header[2], str): - # self._trip_id = txn_header[2] - # if isinstance(txn_header[3], str): - # self._referring_path_hash = txn_header[3] - # except Exception: - # pass - - # def _generate_response_headers(self, read_length=None): - # nr_headers = [] - - # # Generate metrics and response headers for inbound cross - # # process web external calls. - - # if self.client_cross_process_id is not None: - # # Need to work out queueing time and duration up to this - # # point for inclusion in metrics and response header. If the - # # recording of the transaction had been prematurely stopped - # # via an API call, only return time up until that call was - # # made so it will match what is reported as duration for the - # # transaction. - - # if self.queue_start: - # queue_time = self.start_time - self.queue_start - # else: - # queue_time = 0 - - # if self.end_time: - # duration = self.end_time - self.start_time - # else: - # duration = time.time() - self.start_time - - # # Generate the additional response headers which provide - # # information back to the caller. We need to freeze the - # # transaction name before adding to the header. - - # self._freeze_path() - - # if read_length is None: - # read_length = self._read_length - - # read_length = read_length if read_length is not None else -1 - - # payload = ( - # self._settings.cross_process_id, - # self.path, - # queue_time, - # duration, - # read_length, - # self.guid, - # self.record_tt, - # ) - # app_data = json_encode(payload) - - # nr_headers.append(("X-NewRelic-App-Data", obfuscate(app_data, self._settings.encoding_key))) - - # return nr_headers - - # # This function is CAT related and has been deprecated. - # # Eventually, this will be removed. Until then, coverage - # # does not need to factor this function into its analysis. - # def get_response_metadata(self): # pragma: no cover - # nr_headers = dict(self._generate_response_headers()) - # return convert_to_cat_metadata_value(nr_headers) - - # # This function is CAT related and has been deprecated. - # # Eventually, this will be removed. Until then, coverage - # # does not need to factor this function into its analysis. - # def process_request_metadata(self, cat_linking_value): # pragma: no cover - # try: - # payload = base64_decode(cat_linking_value) - # except: - # # `cat_linking_value` should always be able to be base64_decoded. - # # If this is encountered, the data being sent is corrupt. No - # # exception should be raised. - # return - - # nr_headers = json_decode(payload) - # # TODO: All the external CAT APIs really need to - # # be refactored into the transaction class. - # encoded_cross_process_id = nr_headers.get("X-NewRelic-ID") - # encoded_txn_header = nr_headers.get("X-NewRelic-Transaction") - # return self._process_incoming_cat_headers(encoded_cross_process_id, encoded_txn_header) - def set_transaction_name(self, name, group=None, priority=None): # Always perform this operation even if the transaction # is not active at the time as will be called from diff --git a/newrelic/api/web_transaction.py b/newrelic/api/web_transaction.py index 6659829702..71843c214c 100644 --- a/newrelic/api/web_transaction.py +++ b/newrelic/api/web_transaction.py @@ -300,10 +300,6 @@ def _process_context_headers(self): # the relevant details. if self._settings.distributed_tracing.enabled: self.accept_distributed_trace_headers(self._request_headers) - # else: - # client_cross_process_id = self._request_headers.get("x-newrelic-id") - # txn_header = self._request_headers.get("x-newrelic-transaction") - # self._process_incoming_cat_headers(client_cross_process_id, txn_header) def process_response(self, status_code, response_headers): """Processes response status and headers, extracting any @@ -339,17 +335,6 @@ def process_response(self, status_code, response_headers): return [] - # if self.client_cross_process_id is None: - # return [] - - # # Generate CAT response headers - # try: - # read_length = int(self._request_headers.get("content-length")) - # except Exception: - # read_length = -1 - - # return self._generate_response_headers(read_length) - def _update_agent_attributes(self): if "accept" in self._request_headers: self._add_agent_attribute("request.headers.accept", self._request_headers["accept"]) diff --git a/newrelic/common/agent_http.py b/newrelic/common/agent_http.py index c5e54d4962..c85f7d060a 100644 --- a/newrelic/common/agent_http.py +++ b/newrelic/common/agent_http.py @@ -521,7 +521,6 @@ class DeveloperModeClient(SupportabilityMixin, BaseClient): "url_rules": [], "collect_errors": True, "account_id": "12345", - # "cross_process_id": "12345#67890", "messages": [{"message": "Reporting to fake collector", "level": "INFO"}], "sampling_rate": 0, "collect_traces": True, diff --git a/newrelic/common/encoding_utils.py b/newrelic/common/encoding_utils.py index 8aa435af0b..ddd6a5ddad 100644 --- a/newrelic/common/encoding_utils.py +++ b/newrelic/common/encoding_utils.py @@ -231,23 +231,6 @@ def unpack_field(field): return data -# def generate_path_hash(name, seed): -# """Algorithm for generating the path hash: -# * Rotate Left the seed value and truncate to 32-bits. -# * Compute the md5 digest of the name, take the last 4 bytes (32-bits). -# * XOR the 4 bytes of digest with the seed and return the result. - -# """ - -# rotated = ((seed << 1) | (seed >> 31)) & 0xFFFFFFFF - -# if not isinstance(name, bytes): -# name = name.encode("UTF-8") - -# path_hash = rotated ^ int(hashlib.md5(name).hexdigest()[-8:], base=16) -# return f"{path_hash:08x}" - - def base64_encode(text): """Base 64 encodes the UTF-8 encoded representation of the text. In Python 2 either a byte string or Unicode string can be provided for the text @@ -367,15 +350,6 @@ def decode_newrelic_header(encoded_header, encoding_key): return decoded_header -# def convert_to_cat_metadata_value(nr_headers): -# if not nr_headers: -# return None - -# payload = json_encode(nr_headers) -# cat_linking_value = base64_encode(payload) -# return cat_linking_value - - class DistributedTracePayload(dict): version = (0, 1) diff --git a/newrelic/config.py b/newrelic/config.py index 8246e10e78..024c97b3a1 100644 --- a/newrelic/config.py +++ b/newrelic/config.py @@ -711,15 +711,6 @@ def translate_deprecated_settings(settings, cached_settings): "attributes.exclude." ) - # if "cross_application_tracer.enabled" in cached: - # # CAT Deprecation Warning - # _logger.info( - # "Deprecated setting found: cross_application_tracer.enabled. Please replace Cross Application Tracing " - # "(CAT) with the newer Distributed Tracing by setting 'distributed_tracing.enabled' to True in your agent " - # "configuration. For further details on distributed tracing, please refer to our documentation: " - # "https://docs.newrelic.com/docs/distributed-tracing/concepts/distributed-tracing-planning-guide/#changes." - # ) - return settings diff --git a/newrelic/core/agent_protocol.py b/newrelic/core/agent_protocol.py index bc7727c6e1..347bdf5e2a 100644 --- a/newrelic/core/agent_protocol.py +++ b/newrelic/core/agent_protocol.py @@ -523,7 +523,6 @@ def finalize(self): def connect(cls, app_name, linked_applications, environment, settings, client_cls=ServerlessModeClient): aws_lambda_metadata = settings.aws_lambda_metadata settings = finalize_application_settings() - # settings = finalize_application_settings({"cross_application_tracer.enabled": False}, settings) # Metadata must come from the original settings object since it # can be modified later settings.aws_lambda_metadata = aws_lambda_metadata diff --git a/newrelic/core/config.py b/newrelic/core/config.py index 8dfb25281c..ae7f855617 100644 --- a/newrelic/core/config.py +++ b/newrelic/core/config.py @@ -256,10 +256,6 @@ class DebugSettings(Settings): pass -# class CrossApplicationTracerSettings(Settings): -# pass - - class TransactionEventsSettings(Settings): pass @@ -497,7 +493,6 @@ class EventHarvestConfigHarvestLimitSettings(Settings): _settings.browser_monitoring.attributes = BrowserMonitorAttributesSettings() _settings.code_level_metrics = CodeLevelMetricsSettings() _settings.console = ConsoleSettings() -# _settings.cross_application_tracer = CrossApplicationTracerSettings() _settings.custom_insights_events = CustomInsightsEventsSettings() _settings.ml_insights_events = MlInsightsEventsSettings() _settings.datastore_tracer = DatastoreTracerSettings() @@ -792,7 +787,6 @@ def default_otlp_host(host): _settings.transaction_segment_terms = [] _settings.account_id = os.environ.get("NEW_RELIC_ACCOUNT_ID") -# _settings.cross_process_id = None _settings.primary_application_id = os.environ.get("NEW_RELIC_PRIMARY_APPLICATION_ID", "Unknown") _settings.trusted_account_ids = [] _settings.trusted_account_key = os.environ.get("NEW_RELIC_TRUSTED_ACCOUNT_KEY") @@ -808,7 +802,6 @@ def default_otlp_host(host): _settings.attributes.include = [] _settings.thread_profiler.enabled = True -# _settings.cross_application_tracer.enabled = False _settings.gc_runtime_metrics.enabled = _environ_as_bool("NEW_RELIC_GC_RUNTIME_METRICS_ENABLED", default=False) _settings.gc_runtime_metrics.top_object_count_limit = 5 @@ -1347,24 +1340,6 @@ def apply_server_side_settings(server_side_config=None, settings=_settings): min(settings_snapshot.custom_insights_events.max_attribute_value, 4095), ) - # This will be removed at some future point - # Special case for account_id which will be sent instead of - # cross_process_id in the future - - # if settings_snapshot.cross_process_id is not None: - # vals = [settings_snapshot.account_id, settings_snapshot.application_id] - # derived_vals = settings_snapshot.cross_process_id.split("#") - - # if len(derived_vals) == 2: - # for idx, _val in enumerate(derived_vals): - # # only override the value if the server side does not provide - # # the value specifically - # if vals[idx] is None: - # vals[idx] = derived_vals[idx] - - # settings_snapshot.account_id = vals[0] - # settings_snapshot.application_id = vals[1] - # Reapply on top any local setting overrides. for name in _settings.debug.local_settings_overrides: diff --git a/newrelic/core/external_node.py b/newrelic/core/external_node.py index ceea3f0cac..5b80a2e7d7 100644 --- a/newrelic/core/external_node.py +++ b/newrelic/core/external_node.py @@ -40,9 +40,6 @@ class ExternalNode(_ExternalNode, GenericNodeMixin): - # cross_process_id = None - # external_txn_name = None - @property def details(self): if hasattr(self, "_details"): @@ -107,21 +104,10 @@ def time_metrics(self, stats, root, parent): netloc = self.netloc - # try: - # # Remove cross_process_id from the params dict otherwise it shows - # # up in the UI. - - # self.cross_process_id = self.params.pop("cross_process_id") - # self.external_txn_name = self.params.pop("external_txn_name") - # except KeyError: - # self.cross_process_id = None - # self.external_txn_name = None - name = f"External/{netloc}/all" yield TimeMetric(name=name, scope="", duration=self.duration, exclusive=self.exclusive) - # if self.cross_process_id is None: method = self.method or "" name = f"External/{netloc}/{self.library}/{method}" @@ -130,26 +116,12 @@ def time_metrics(self, stats, root, parent): yield TimeMetric(name=name, scope=root.path, duration=self.duration, exclusive=self.exclusive) - # else: - # name = f"ExternalTransaction/{netloc}/{self.cross_process_id}/{self.external_txn_name}" - - # yield TimeMetric(name=name, scope="", duration=self.duration, exclusive=self.exclusive) - - # yield TimeMetric(name=name, scope=root.path, duration=self.duration, exclusive=self.exclusive) - - # name = f"ExternalApp/{netloc}/{self.cross_process_id}/all" - - # yield TimeMetric(name=name, scope="", duration=self.duration, exclusive=self.exclusive) - def trace_node(self, stats, root, connections): netloc = self.netloc method = self.method or "" - # if self.cross_process_id is None: name = f"External/{netloc}/{self.library}/{method}" - # else: - # name = f"ExternalTransaction/{netloc}/{self.cross_process_id}/{self.external_txn_name}" name = root.string_table.cache(name) diff --git a/newrelic/core/transaction_node.py b/newrelic/core/transaction_node.py index 1c5364dda2..d125c36369 100644 --- a/newrelic/core/transaction_node.py +++ b/newrelic/core/transaction_node.py @@ -66,8 +66,6 @@ "guid", "cpu_time", "suppress_transaction_trace", - # "client_cross_process_id", - # "referring_transaction_guid", "record_tt", "synthetics_resource_id", "synthetics_job_id", @@ -77,11 +75,6 @@ "synthetics_initiator", "synthetics_attributes", "synthetics_info_header", - # "is_part_of_cat", - # "trip_id", - # "path_hash", - # "referring_path_hash", - # "alternate_path_hashes", "trace_intrinsics", "agent_attributes", "distributed_trace_intrinsics", @@ -465,23 +458,10 @@ def _add_if_not_empty(key, value): apdex_perf_zone = self.apdex_perf_zone() _add_if_not_empty("apdexPerfZone", apdex_perf_zone) - # _add_if_not_empty("nr.apdexPerfZone", apdex_perf_zone) if self.errors: intrinsics["error"] = True - # if self.path_hash: - # intrinsics["nr.guid"] = self.guid - # intrinsics["nr.tripId"] = self.trip_id - # intrinsics["nr.pathHash"] = self.path_hash - - # _add_if_not_empty("nr.referringPathHash", self.referring_path_hash) - # _add_if_not_empty("nr.alternatePathHashes", ",".join(self.alternate_path_hashes)) - # _add_if_not_empty("nr.referringTransactionGuid", self.referring_transaction_guid) - - # if self.synthetics_resource_id: - # intrinsics["nr.guid"] = self.guid - if self.parent_tx: intrinsics["parentId"] = self.parent_tx @@ -541,11 +521,6 @@ def error_event_intrinsics(self, error, stats_table): intrinsics["transactionName"] = self.path intrinsics["spanId"] = error.span_id - # intrinsics["nr.transactionGuid"] = self.guid - # if self.referring_transaction_guid: - # guid = self.referring_transaction_guid - # intrinsics["nr.referringTransactionGuid"] = guid - return intrinsics def _event_intrinsics(self, stats_table): diff --git a/newrelic/hooks/application_celery.py b/newrelic/hooks/application_celery.py index 6f25bbbf57..71e51a66e2 100644 --- a/newrelic/hooks/application_celery.py +++ b/newrelic/hooks/application_celery.py @@ -127,11 +127,6 @@ def wrapper(wrapped, instance, args, kwargs): headers.update(dict(dt_headers)) except Exception: pass - # elif transaction.settings.cross_application_tracer.enabled: - # transaction._process_incoming_cat_headers( - # headers.get(MessageTrace.cat_id_key, None), - # headers.get(MessageTrace.cat_transaction_key, None), - # ) except Exception: pass @@ -247,11 +242,6 @@ def wrap_task_call(wrapped, instance, args, kwargs): headers.update(dict(dt_headers)) except Exception: pass - # elif transaction.settings.cross_application_tracer.enabled: - # transaction._process_incoming_cat_headers( - # headers.get(MessageTrace.cat_id_key, None), - # headers.get(MessageTrace.cat_transaction_key, None), - # ) except Exception: pass diff --git a/newrelic/hooks/external_httplib.py b/newrelic/hooks/external_httplib.py index 94baa37790..48b1d080e4 100644 --- a/newrelic/hooks/external_httplib.py +++ b/newrelic/hooks/external_httplib.py @@ -93,24 +93,24 @@ def httplib_getresponse_wrapper(wrapped, instance, args, kwargs): return response -# def httplib_putheader_wrapper(wrapped, instance, args, kwargs): -# transaction = current_transaction() +def httplib_putheader_wrapper(wrapped, instance, args, kwargs): + transaction = current_transaction() -# if transaction is None: -# return wrapped(*args, **kwargs) + if transaction is None: + return wrapped(*args, **kwargs) -# # # Remember if we see any NR headers being set. This is only doing -# # # it if we see either, but they should always both be getting set. + # Remember if we see any NR headers being set. This is only doing + # it if we see either, but they should always both be getting set. -# # def nr_header(header, *args, **kwargs): -# # return header.upper() in ("NEWRELIC", "X-NEWRELIC-ID", "X-NEWRELIC-TRANSACTION") + def nr_header(header, *args, **kwargs): + return header.upper() == "NEWRELIC" -# # connection = instance + connection = instance -# # if nr_header(*args, **kwargs): -# # connection._nr_skip_headers = True + if nr_header(*args, **kwargs): + connection._nr_skip_headers = True -# return wrapped(*args, **kwargs) + return wrapped(*args, **kwargs) def instrument(module): @@ -125,4 +125,4 @@ def instrument(module): functools.partial(httplib_endheaders_wrapper, scheme="https", library="http"), ) wrap_function_wrapper(module, "HTTPConnection.getresponse", httplib_getresponse_wrapper) - # wrap_function_wrapper(module, "HTTPConnection.putheader", httplib_putheader_wrapper) + wrap_function_wrapper(module, "HTTPConnection.putheader", httplib_putheader_wrapper) diff --git a/newrelic/hooks/framework_aiohttp.py b/newrelic/hooks/framework_aiohttp.py index 0636c39853..da0b0029a5 100644 --- a/newrelic/hooks/framework_aiohttp.py +++ b/newrelic/hooks/framework_aiohttp.py @@ -34,17 +34,6 @@ def aiohttp_version_info(): return tuple(int(_) for _ in aiohttp.__version__.split(".")[:2]) -# def headers_preserve_casing(): -# try: -# from multidict import CIMultiDict -# except: -# return True - -# d = CIMultiDict() -# d.update({"X-NewRelic-ID": "value"}) -# return "X-NewRelic-ID" in dict(d.items()) - - def should_ignore(transaction): settings = transaction.settings @@ -280,7 +269,6 @@ async def _coro(): response = await wrapped(*args, **kwargs) try: - # trace.process_response_headers(response.headers.items()) trace.process_response(status_code=response.status) except: pass @@ -302,11 +290,7 @@ def instrument_aiohttp_client_reqrep(module): version_info = aiohttp_version_info() if version_info >= (2, 0): - # TODO: Verify that headers_preserve_casting is always True - # if headers_preserve_casing(): dt_wrapper = _nr_aiohttp_add_dt_headers_simple_ - # else: - # dt_wrapper = _nr_aiohttp_add_dt_headers_ wrap_function_wrapper(module, "ClientRequest.send", dt_wrapper) @@ -380,10 +364,6 @@ async def _coro(*_args, **_kwargs): def instrument_aiohttp_web(module): - # global _nr_process_response - # if not headers_preserve_casing(): - # _nr_process_response = _nr_process_response_proxy - wrap_function_wrapper(module, "Application._handle", _nr_request_wrapper) wrap_function_wrapper(module, "Application.__init__", _nr_aiohttp_wrap_application_init_) diff --git a/newrelic/hooks/framework_tornado.py b/newrelic/hooks/framework_tornado.py index 1c865d139c..7682bec75f 100644 --- a/newrelic/hooks/framework_tornado.py +++ b/newrelic/hooks/framework_tornado.py @@ -254,7 +254,6 @@ async def wrapper(req, raise_error): finally: if response: trace.process_response(response.code) - # trace.process_response_headers(response.headers.get_all()) return response return wrapper diff --git a/newrelic/hooks/messagebroker_pika.py b/newrelic/hooks/messagebroker_pika.py index 6a058d85ca..df7ae01f9e 100644 --- a/newrelic/hooks/messagebroker_pika.py +++ b/newrelic/hooks/messagebroker_pika.py @@ -62,8 +62,6 @@ def _add_consume_rabbitmq_trace(transaction, method, properties, nr_start_time, # Do not record dt headers in the segment parameters if headers: - # headers.pop(MessageTrace.cat_id_key, None) - # headers.pop(MessageTrace.cat_transaction_key, None) headers.pop(MessageTrace.distributed_trace_key, None) headers.pop("traceparent", None) headers.pop("tracestate", None) @@ -124,8 +122,6 @@ def _nr_wrapper_basic_publish(wrapped, instance, args, kwargs): user_headers = properties.headers.copy() # Do not record dt headers in the segment parameters - # user_headers.pop(MessageTrace.cat_id_key, None) - # user_headers.pop(MessageTrace.cat_transaction_key, None) user_headers.pop(MessageTrace.distributed_trace_key, None) user_headers.pop("traceparent", None) user_headers.pop("tracestate", None) diff --git a/tests/agent_features/test_asgi_distributed_tracing.py b/tests/agent_features/test_asgi_distributed_tracing.py index 993ba7865c..01140279f6 100644 --- a/tests/agent_features/test_asgi_distributed_tracing.py +++ b/tests/agent_features/test_asgi_distributed_tracing.py @@ -104,7 +104,6 @@ async def target_asgi_application(scope, receive, send): def test_distributed_tracing_web_transaction(): headers = {"newrelic": json.dumps(payload)} response = test_application.make_request("GET", "/", headers=headers) - # assert "X-NewRelic-App-Data" not in response.headers class TestAsgiRequest: diff --git a/tests/agent_features/test_attribute.py b/tests/agent_features/test_attribute.py index a22a42605d..4e6c0998be 100644 --- a/tests/agent_features/test_attribute.py +++ b/tests/agent_features/test_attribute.py @@ -57,7 +57,6 @@ def target_wsgi_application(environ, start_response): _required_intrinsics = ["totalTime"] -# _required_intrinsics = ["trip_id", "totalTime"] _forgone_intrinsics = [] diff --git a/tests/agent_features/test_attributes_in_action.py b/tests/agent_features/test_attributes_in_action.py index 3db3d4dc88..3981ef0cd9 100644 --- a/tests/agent_features/test_attributes_in_action.py +++ b/tests/agent_features/test_attributes_in_action.py @@ -16,7 +16,6 @@ import webtest from testing_support.asgi_testing import AsgiTest from testing_support.fixtures import ( - # cat_enabled, dt_enabled, override_application_settings, reset_core_stats_engine, @@ -89,16 +88,7 @@ AGENT_KEYS_ALL = TRACE_ERROR_AGENT_KEYS + REQ_PARAMS -TRANS_EVENT_INTRINSICS = ( - "name", - "duration", - "type", - "timestamp", - "totalTime", - "error", - # "nr.apdexPerfZone", - "apdexPerfZone", -) +TRANS_EVENT_INTRINSICS = ("name", "duration", "type", "timestamp", "totalTime", "error", "apdexPerfZone") TRANS_EVENT_AGENT_KEYS = [ "response.status", "request.method", @@ -165,7 +155,6 @@ def normal_application(request): # Tests for checking the presence and format of agent attributes. # Test default settings. -# _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": ["trip_id"]} _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": []} _expected_attributes_event = { @@ -177,20 +166,16 @@ def normal_application(request): _expected_absent_attributes = {"agent": REQ_PARAMS, "user": [], "intrinsic": []} -# @cat_enabled @validate_error_event_attributes(_expected_attributes_event, _expected_absent_attributes) @validate_transaction_error_trace_attributes(_expected_attributes, _expected_absent_attributes) def test_error_in_transaction_default_settings(normal_application): normal_application.get(REQUEST_URL, headers=REQUEST_HEADERS) -# _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": []} -# @cat_enabled @validate_transaction_trace_attributes(_expected_attributes, _expected_absent_attributes) -# @override_application_settings({}) def test_transaction_trace_default_attribute_settings(normal_application): normal_application.get(REQUEST_URL, headers=REQUEST_HEADERS) @@ -233,7 +218,6 @@ def test_browser_default_attribute_settings(normal_application): _override_settings = {"error_collector.attributes.exclude": ["request.parameters.*"]} _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": []} -# _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": ["trip_id"]} _expected_attributes_event = { "agent": TRACE_ERROR_AGENT_KEYS, @@ -254,7 +238,6 @@ def test_error_in_transaction_exclude_request_params(normal_application): _override_settings = {"transaction_tracer.attributes.exclude": ["request.parameters.*"]} _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": []} -# _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} @validate_transaction_trace_attributes(_expected_attributes, _expected_absent_attributes) @@ -266,7 +249,6 @@ def test_transaction_trace_exclude_request_params(normal_application): _override_settings = {"capture_params": True, "error_collector.attributes.exclude": ["request.parameters.*"]} _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": []} -# _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} _expected_absent_attributes = {"agent": REQ_PARAMS, "user": [], "intrinsic": []} @@ -582,7 +564,6 @@ def test_span_event_exclude_agent_attribute(normal_application): _override_settings = {"capture_params": True} -# _expected_attributes = {"agent": AGENT_KEYS_ALL, "user": ERROR_USER_ATTRS, "intrinsic": ["trip_id"]} _expected_attributes = {"agent": AGENT_KEYS_ALL, "user": ERROR_USER_ATTRS, "intrinsic": []} _expected_attributes_event = {"agent": AGENT_KEYS_ALL, "user": ERROR_USER_ATTRS, "intrinsic": ERROR_EVENT_INTRINSICS} @@ -595,7 +576,6 @@ def test_error_in_transaction_deprecated_capture_params_true(normal_application) normal_application.get(REQUEST_URL, headers=REQUEST_HEADERS) -# _expected_attributes = {"agent": AGENT_KEYS_ALL, "user": USER_ATTRS, "intrinsic": ["trip_id"]} _expected_attributes = {"agent": AGENT_KEYS_ALL, "user": USER_ATTRS, "intrinsic": []} @@ -635,7 +615,6 @@ def test_browser_deprecated_capture_params_true(normal_application): _override_settings = {"capture_params": False} -# _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": ["trip_id"]} _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": ERROR_USER_ATTRS, "intrinsic": []} _expected_attributes_event = { @@ -654,7 +633,6 @@ def test_error_in_transaction_deprecated_capture_params_false(normal_application normal_application.get(REQUEST_URL, headers=REQUEST_HEADERS) -# _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": ["trip_id"]} _expected_attributes = {"agent": TRACE_ERROR_AGENT_KEYS, "user": USER_ATTRS, "intrinsic": []} diff --git a/tests/agent_features/test_distributed_tracing.py b/tests/agent_features/test_distributed_tracing.py index ed7183f40d..b6043c166a 100644 --- a/tests/agent_features/test_distributed_tracing.py +++ b/tests/agent_features/test_distributed_tracing.py @@ -111,7 +111,6 @@ def target_wsgi_application(environ, start_response): def test_distributed_tracing_web_transaction(): headers = {"newrelic": json.dumps(payload)} response = test_application.get("/", headers=headers) - # assert "X-NewRelic-App-Data" not in response.headers @pytest.mark.parametrize("span_events", (True, False)) diff --git a/tests/agent_features/test_error_events.py b/tests/agent_features/test_error_events.py index 5819b1656f..98219b8c4e 100644 --- a/tests/agent_features/test_error_events.py +++ b/tests/agent_features/test_error_events.py @@ -17,8 +17,6 @@ import webtest from testing_support.fixtures import ( - # cat_enabled, - # make_cross_agent_headers, make_synthetics_headers, override_application_settings, reset_core_stats_engine, @@ -108,11 +106,9 @@ def test_transaction_error_background_task(): "error.message": ERR_MESSAGE, "error.expected": False, "transactionName": "WebTransaction/Uri/", - # "nr.referringTransactionGuid": 7, } -# @cat_enabled @validate_error_event_sample_data(required_attrs=_intrinsic_attributes, required_user_attrs=True) def test_transaction_error_dt_headers(): test_environ = {"err_message": ERR_MESSAGE} diff --git a/tests/agent_features/test_serverless_mode.py b/tests/agent_features/test_serverless_mode.py index 6c4d5fa348..07b1c5219f 100644 --- a/tests/agent_features/test_serverless_mode.py +++ b/tests/agent_features/test_serverless_mode.py @@ -17,8 +17,6 @@ import pytest from testing_support.fixtures import override_generic_settings from testing_support.validators.validate_serverless_data import validate_serverless_data - -# from testing_support.validators.validate_serverless_metadata import validate_serverless_metadata from testing_support.validators.validate_serverless_payload import validate_serverless_payload from newrelic.api.application import application_instance @@ -66,24 +64,6 @@ def _test(): payload = json.loads(out) -# def test_no_cat_headers(serverless_application): -# @background_task(application=serverless_application, name="test_cat_headers") -# def _test_cat_headers(): -# transaction = current_transaction() - -# payload = ExternalTrace.generate_request_headers(transaction) -# assert not payload - -# trace = ExternalTrace("testlib", "http://example.com") -# response_headers = [("X-NewRelic-App-Data", "Cookies")] -# with trace: -# trace.process_response_headers(response_headers) - -# # assert transaction.settings.cross_application_tracer.enabled is False - -# _test_cat_headers() - - @pytest.mark.parametrize("trusted_account_key", ("1", None), ids=("tk_set", "tk_unset")) def test_outbound_dt_payload_generation(serverless_application, trusted_account_key): @override_generic_settings( diff --git a/tests/agent_features/test_synthetics.py b/tests/agent_features/test_synthetics.py index a5916f7a42..2b4c864509 100644 --- a/tests/agent_features/test_synthetics.py +++ b/tests/agent_features/test_synthetics.py @@ -187,7 +187,6 @@ def test_synthetics_event_mismatched_info_encoding_key(): } -# @cat_enabled @validate_synthetics_transaction_trace(_test_valid_synthetics_tt_required) @override_application_settings(_override_settings) def test_valid_synthetics_in_transaction_trace(): @@ -220,7 +219,6 @@ def test_synthetics_disabled(): _external_synthetics_info_header = _external_synthetics_headers["X-NewRelic-Synthetics-Info"] -# @cat_enabled @validate_synthetics_external_trace_header(_external_synthetics_header, _external_synthetics_info_header) @override_application_settings(_override_settings) def test_valid_synthetics_external_trace_header(): @@ -228,7 +226,6 @@ def test_valid_synthetics_external_trace_header(): response = target_application.get("/", headers=headers) -# @cat_enabled @validate_synthetics_external_trace_header(_external_synthetics_header, None) @override_application_settings(_override_settings) def test_valid_synthetics_external_trace_header_without_info(): @@ -236,7 +233,6 @@ def test_valid_synthetics_external_trace_header_without_info(): response = target_application.get("/", headers=headers) -# @cat_enabled @validate_synthetics_external_trace_header(_external_synthetics_header, _external_synthetics_info_header) @override_application_settings(_override_settings) def test_valid_external_trace_header_with_byte_inbound_header(): diff --git a/tests/agent_unittests/test_agent_protocol.py b/tests/agent_unittests/test_agent_protocol.py index 590cad66f8..d7c760c762 100644 --- a/tests/agent_unittests/test_agent_protocol.py +++ b/tests/agent_unittests/test_agent_protocol.py @@ -488,9 +488,6 @@ def test_serverless_protocol_connect(): # No client calls should be made assert len(HttpClientRecorder.SENT) == 0 - # # cross application tracing must be disabled - # assert not protocol.configuration.cross_application_tracer.enabled - def test_serverless_protocol_finalize(capsys): protocol = ServerlessModeProtocol( diff --git a/tests/agent_unittests/test_harvest_loop.py b/tests/agent_unittests/test_harvest_loop.py index 2ca2fe5511..813e642d4e 100644 --- a/tests/agent_unittests/test_harvest_loop.py +++ b/tests/agent_unittests/test_harvest_loop.py @@ -134,8 +134,6 @@ def transaction_node(request): guid="4485b89db608aece", cpu_time=0.0, suppress_transaction_trace=False, - # client_cross_process_id=None, - # referring_transaction_guid=None, record_tt=False, synthetics_resource_id=None, synthetics_job_id=None, @@ -145,11 +143,6 @@ def transaction_node(request): synthetics_initiator=None, synthetics_attributes=None, synthetics_info_header=None, - # is_part_of_cat=False, - # trip_id="4485b89db608aece", - # path_hash=None, - # referring_path_hash=None, - # alternate_path_hashes=[], trace_intrinsics={}, distributed_trace_intrinsics={}, agent_attributes=[], diff --git a/tests/cross_agent/test_distributed_tracing.py b/tests/cross_agent/test_distributed_tracing.py index 144dd57e3e..21baa9e45d 100644 --- a/tests/cross_agent/test_distributed_tracing.py +++ b/tests/cross_agent/test_distributed_tracing.py @@ -219,7 +219,6 @@ def test_distributed_tracing( @override_application_settings(override_settings) def _test(): response = test_application.get("/", headers=headers) - # assert "X-NewRelic-App-Data" not in response.headers if "Span" in intrinsics: span_intrinsics = intrinsics.get("Span") diff --git a/tests/external_http/test_http.py b/tests/external_http/test_http.py index 883c40dbd2..1d5f4f0e1c 100644 --- a/tests/external_http/test_http.py +++ b/tests/external_http/test_http.py @@ -15,11 +15,9 @@ import http.client import pytest -from testing_support.external_fixtures import cache_outgoing_headers # , insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers - -# 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 @@ -85,48 +83,7 @@ def _test(): connection.close() _test = override_application_settings( - { - "distributed_tracing.enabled": distributed_tracing, - # "cross_application_tracer.enabled": not distributed_tracing, - "span_events.enabled": span_events, - } + {"distributed_tracing.enabled": distributed_tracing, "span_events.enabled": span_events} )(_test) _test() - - -# @cat_enabled -# def test_http_cross_process_response(server): -# _test_http_cross_process_response_scoped_metrics = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] - -# _test_http_cross_process_response_rollup_metrics = [ -# ("External/all", 1), -# ("External/allOther", 1), -# (f"External/localhost:{server.port}/all", 1), -# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), -# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), -# ] - -# _test_http_cross_process_response_external_node_params = [ -# ("cross_process_id", "1#2"), -# ("external_txn_name", "test"), -# ("transaction_guid", "0123456789012345"), -# ] - -# @validate_transaction_metrics( -# "test_http:test_http_cross_process_response", -# scoped_metrics=_test_http_cross_process_response_scoped_metrics, -# rollup_metrics=_test_http_cross_process_response_rollup_metrics, -# background_task=True, -# ) -# @insert_incoming_headers -# @validate_external_node_params(params=_test_http_cross_process_response_external_node_params) -# @background_task(name="test_http:test_http_cross_process_response") -# def _test(): -# connection = http.client.HTTPConnection("localhost", server.port) -# connection.request("GET", "/") -# response = connection.getresponse() -# response.read() -# connection.close() - -# _test() diff --git a/tests/external_httplib/test_httplib.py b/tests/external_httplib/test_httplib.py index 2db632a4ac..1103072df4 100644 --- a/tests/external_httplib/test_httplib.py +++ b/tests/external_httplib/test_httplib.py @@ -17,11 +17,9 @@ import json import pytest -from testing_support.external_fixtures import cache_outgoing_headers # , insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers - -# from testing_support.validators.validate_external_node_params import validate_external_node_params 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_tt_segment_params import validate_tt_segment_params @@ -125,86 +123,12 @@ def _test(): connection.close() _test = override_application_settings( - { - "distributed_tracing.enabled": distributed_tracing, - # "cross_application_tracer.enabled": not distributed_tracing, - "span_events.enabled": span_events, - } + {"distributed_tracing.enabled": distributed_tracing, "span_events.enabled": span_events} )(_test) _test() -# _test_httplib_cross_process_response_external_node_params = [ -# ("cross_process_id", "1#2"), -# ("external_txn_name", "test"), -# ("transaction_guid", "0123456789012345"), -# ] - - -# # @cat_enabled -# @insert_incoming_headers -# def test_httplib_cross_process_response(server): -# scoped = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] - -# rollup = [ -# ("External/all", 1), -# ("External/allOther", 1), -# (f"External/localhost:{server.port}/all", 1), -# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), -# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), -# ] - -# @validate_transaction_metrics( -# "test_httplib:test_httplib_cross_process_response", -# scoped_metrics=scoped, -# rollup_metrics=rollup, -# background_task=True, -# ) -# @validate_external_node_params(params=_test_httplib_cross_process_response_external_node_params) -# @background_task(name="test_httplib:test_httplib_cross_process_response") -# def _test(): -# connection = httplib.HTTPConnection("localhost", server.port) -# connection.request("GET", "/") -# response = connection.getresponse() -# response.read() -# connection.close() - -# _test() - - -# @cat_enabled -# def test_httplib_multiple_requests_cross_process_response(server): -# connection = httplib.HTTPConnection("localhost", server.port) - -# scoped = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] - -# rollup = [ -# ("External/all", 1), -# ("External/allOther", 1), -# (f"External/localhost:{server.port}/all", 1), -# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), -# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), -# ] - -# @validate_transaction_metrics( -# "test_httplib:test_transaction", scoped_metrics=scoped, rollup_metrics=rollup, background_task=True -# ) -# @insert_incoming_headers -# @validate_external_node_params(params=_test_httplib_cross_process_response_external_node_params) -# @background_task(name="test_httplib:test_transaction") -# def test_transaction(): -# connection.request("GET", "/") -# response = connection.getresponse() -# response.read() - -# # make multiple requests with the same connection -# for _ in range(2): -# test_transaction() - -# connection.close() - - def process_response(response): response = response.decode("utf-8").strip() values = response.splitlines() @@ -242,7 +166,7 @@ def test_transaction(): def test_httplib_nr_headers_added(server): connection = httplib.HTTPConnection("localhost", server.port) - key = "header_key" + key = "newrelic" value = "testval" headers = [] @@ -259,6 +183,7 @@ def test_transaction(): )(test_transaction) test_transaction() connection.close() + # verify newrelic headers already added do not get overridden assert headers[0][key] == value diff --git a/tests/external_httplib/test_urllib.py b/tests/external_httplib/test_urllib.py index 5f966dd1ad..aebc870c37 100644 --- a/tests/external_httplib/test_urllib.py +++ b/tests/external_httplib/test_urllib.py @@ -21,12 +21,8 @@ except ImportError: import urllib -from testing_support.external_fixtures import cache_outgoing_headers # , insert_incoming_headers - -# from testing_support.fixtures import cat_enabled +from testing_support.external_fixtures import cache_outgoing_headers from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers - -# 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 @@ -182,38 +178,3 @@ def _test(): @validate_cross_process_headers def test_urlretrieve_cross_process_request(server): urllib.urlretrieve(f"http://localhost:{server.port}/") - - -# @cat_enabled -# def test_urlretrieve_cross_process_response(server): -# _test_urlretrieve_cross_process_response_scoped_metrics = [ -# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) -# ] - -# _test_urlretrieve_cross_process_response_rollup_metrics = [ -# ("External/all", 1), -# ("External/allOther", 1), -# (f"External/localhost:{server.port}/all", 1), -# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), -# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), -# ] - -# _test_urlretrieve_cross_process_response_external_node_params = [ -# ("cross_process_id", "1#2"), -# ("external_txn_name", "test"), -# ("transaction_guid", "0123456789012345"), -# ] - -# @validate_transaction_metrics( -# "test_urllib:test_urlretrieve_cross_process_response", -# scoped_metrics=_test_urlretrieve_cross_process_response_scoped_metrics, -# rollup_metrics=_test_urlretrieve_cross_process_response_rollup_metrics, -# background_task=True, -# ) -# @insert_incoming_headers -# @validate_external_node_params(params=_test_urlretrieve_cross_process_response_external_node_params) -# @background_task(name="test_urllib:test_urlretrieve_cross_process_response") -# def _test(): -# urllib.urlretrieve(f"http://localhost:{server.port}/") - -# _test() diff --git a/tests/external_httplib/test_urllib2.py b/tests/external_httplib/test_urllib2.py index 16aa056ca7..c5478036af 100644 --- a/tests/external_httplib/test_urllib2.py +++ b/tests/external_httplib/test_urllib2.py @@ -15,12 +15,8 @@ import urllib.request as urllib2 import pytest -from testing_support.external_fixtures import cache_outgoing_headers # , insert_incoming_headers - -# from testing_support.fixtures import cat_enabled +from testing_support.external_fixtures import cache_outgoing_headers from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers - -# 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 @@ -120,36 +116,3 @@ def test_urlopen_file_request(): @validate_cross_process_headers def test_urlopen_cross_process_request(server): urllib2.urlopen(f"http://localhost:{server.port}/") - - -# @cat_enabled -# def test_urlopen_cross_process_response(server): -# _test_urlopen_cross_process_response_scoped_metrics = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] - -# _test_urlopen_cross_process_response_rollup_metrics = [ -# ("External/all", 1), -# ("External/allOther", 1), -# (f"External/localhost:{server.port}/all", 1), -# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), -# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), -# ] - -# _test_urlopen_cross_process_response_external_node_params = [ -# ("cross_process_id", "1#2"), -# ("external_txn_name", "test"), -# ("transaction_guid", "0123456789012345"), -# ] - -# @validate_transaction_metrics( -# "test_urllib2:test_urlopen_cross_process_response", -# scoped_metrics=_test_urlopen_cross_process_response_scoped_metrics, -# rollup_metrics=_test_urlopen_cross_process_response_rollup_metrics, -# background_task=True, -# ) -# @insert_incoming_headers -# @validate_external_node_params(params=_test_urlopen_cross_process_response_external_node_params) -# @background_task(name="test_urllib2:test_urlopen_cross_process_response") -# def _test(): -# urllib2.urlopen(f"http://localhost:{server.port}/") - -# _test() diff --git a/tests/external_httplib2/test_httplib2.py b/tests/external_httplib2/test_httplib2.py index 55ca4c1c73..fe531a4b67 100644 --- a/tests/external_httplib2/test_httplib2.py +++ b/tests/external_httplib2/test_httplib2.py @@ -14,11 +14,9 @@ import httplib2 import pytest -from testing_support.external_fixtures import cache_outgoing_headers # , insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers - -# 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 @@ -103,50 +101,7 @@ def _test(): connection.close() _test = override_application_settings( - { - "distributed_tracing.enabled": distributed_tracing, - # "cross_application_tracer.enabled": not distributed_tracing, - "span_events.enabled": span_events, - } + {"distributed_tracing.enabled": distributed_tracing, "span_events.enabled": span_events} )(_test) _test() - - -# @cat_enabled -# def test_httplib2_cross_process_response(server): -# _test_httplib2_cross_process_response_scoped_metrics = [ -# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) -# ] - -# _test_httplib2_cross_process_response_rollup_metrics = [ -# ("External/all", 1), -# ("External/allOther", 1), -# (f"External/localhost:{server.port}/all", 1), -# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), -# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), -# ] - -# _test_httplib2_cross_process_response_external_node_params = [ -# ("cross_process_id", "1#2"), -# ("external_txn_name", "test"), -# ("transaction_guid", "0123456789012345"), -# ] - -# @validate_transaction_metrics( -# "test_httplib2:test_httplib2_cross_process_response", -# scoped_metrics=_test_httplib2_cross_process_response_scoped_metrics, -# rollup_metrics=_test_httplib2_cross_process_response_rollup_metrics, -# background_task=True, -# ) -# @insert_incoming_headers -# @validate_external_node_params(params=_test_httplib2_cross_process_response_external_node_params) -# @background_task(name="test_httplib2:test_httplib2_cross_process_response") -# def _test(): -# connection = httplib2.HTTPConnectionWithTimeout("localhost", server.port) -# connection.request("GET", "/") -# response = connection.getresponse() -# response.read() -# connection.close() - -# _test() diff --git a/tests/external_httpx/test_client.py b/tests/external_httpx/test_client.py index 5b97105b79..4347c49f59 100644 --- a/tests/external_httpx/test_client.py +++ b/tests/external_httpx/test_client.py @@ -21,41 +21,18 @@ 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 testing_support.validators.validate_tt_segment_params import validate_tt_segment_params from newrelic.api.background_task import background_task from newrelic.api.time_trace import current_trace from newrelic.api.transaction import current_transaction from newrelic.core.config import global_settings -ENCODING_KEY = "1234567890123456789012345678901234567890" SCOPED_METRICS = [] ROLLUP_METRICS = [("External/all", 2), ("External/allOther", 2)] DT_RESPONSE_CODE = None -# def cat_response_handler(self): -# if not DT_RESPONSE_CODE: -# raise ValueError("DT_RESPONSE_CODE must be a valid status_code.") - -# # payload -# # ( -# # u'1#1', u'WebTransaction/Function/app:beep', -# # 0, 1.23, -1, -# # 'dd4a810b7cb7f937', -# # False, -# # ) -# cat_response_header = ( -# "X-NewRelic-App-Data", -# "ahACFwQUGxpuVVNmQVVbRVZbTVleXBxyQFhUTFBfXx1SREUMVV1cQBMeAxgEGAULFR0AHhFQUQJWAAgAUwVQVgJQDgsOEh1UUlhGU2o=", -# ) -# self.send_response(DT_RESPONSE_CODE) -# self.send_header(*cat_response_header) -# self.end_headers() -# self.wfile.write(b"Example Data") - - def dt_response_handler(self): if not DT_RESPONSE_CODE: raise ValueError("DT_RESPONSE_CODE must be a valid status_code.") @@ -68,7 +45,6 @@ def dt_response_handler(self): @pytest.fixture(scope="session") def mock_server(): - # external = MockExternalHTTPHResponseHeadersServer(handler=cat_response_handler) external = MockExternalHTTPHResponseHeadersServer(handler=dt_response_handler) with external: yield external @@ -132,11 +108,7 @@ def test_sync_cross_process_request(httpx, sync_client, mock_server, distributed DT_RESPONSE_CODE = 200 @override_application_settings( - { - "distributed_tracing.enabled": distributed_tracing, - "span_events.enabled": span_events, - # "cross_application_tracer.enabled": not distributed_tracing, - } + {"distributed_tracing.enabled": distributed_tracing, "span_events.enabled": span_events} ) @validate_transaction_errors(errors=[]) @background_task(name="test_sync_cross_process_request") @@ -217,87 +189,6 @@ async def _test(): assert response.request.headers["newrelic"] == "1234" -# @pytest.mark.parametrize("cat_enabled", [True, False]) -# @pytest.mark.parametrize("response_code", [200, 500]) -# def test_sync_client_cat_response_processing(cat_enabled, response_code, sync_client, mock_server, httpx): -# global CAT_RESPONSE_CODE -# CAT_RESPONSE_CODE = response_code - -# _custom_settings = { -# "cross_process_id": "1#1", -# "encoding_key": ENCODING_KEY, -# "trusted_account_ids": [1], -# "cross_application_tracer.enabled": cat_enabled, -# "distributed_tracing.enabled": False, -# "transaction_tracer.transaction_threshold": 0.0, -# } - -# expected_metrics = [ -# ( -# f"ExternalTransaction/localhost:{mock_server.port}/1#1/WebTransaction/Function/app:beep", -# 1 if cat_enabled else None, -# ) -# ] - -# @validate_transaction_metrics( -# "test_sync_client_cat_response_processing", -# background_task=True, -# rollup_metrics=expected_metrics, -# scoped_metrics=expected_metrics, -# ) -# @validate_tt_segment_params(exact_params={"http.statusCode": response_code}) -# @override_application_settings(_custom_settings) -# @background_task(name="test_sync_client_cat_response_processing") -# def _test(): -# with sync_client: -# response = sync_client.get(f"http://localhost:{mock_server.port}") - -# _test() - - -# @pytest.mark.parametrize("cat_enabled", [True, False]) -# @pytest.mark.parametrize("response_code", [200, 500]) -# def test_async_client_cat_response_processing(cat_enabled, response_code, httpx, async_client, mock_server, loop): -# global CAT_RESPONSE_CODE -# CAT_RESPONSE_CODE = response_code - -# _custom_settings = { -# "cross_process_id": "1#1", -# "encoding_key": ENCODING_KEY, -# "trusted_account_ids": [1], -# "cross_application_tracer.enabled": cat_enabled, -# "distributed_tracing.enabled": False, -# "transaction_tracer.transaction_threshold": 0.0, -# } - -# expected_metrics = [ -# ( -# f"ExternalTransaction/localhost:{mock_server.port}/1#1/WebTransaction/Function/app:beep", -# 1 if cat_enabled else None, -# ) -# ] - -# @validate_transaction_metrics( -# "test_async_client_cat_response_processing", -# background_task=True, -# rollup_metrics=expected_metrics, -# scoped_metrics=expected_metrics, -# ) -# @validate_tt_segment_params(exact_params={"http.statusCode": response_code}) -# @override_application_settings(_custom_settings) -# @background_task(name="test_async_client_cat_response_processing") -# def _test(): -# async def coro(): -# async with async_client: -# response = await async_client.get(f"http://localhost:{mock_server.port}") - -# return response - -# response = loop.run_until_complete(coro()) - -# _test() - - @dt_enabled def test_sync_client_event_hook_exception(httpx, mock_server): global DT_RESPONSE_CODE diff --git a/tests/external_requests/test_requests.py b/tests/external_requests/test_requests.py index f7f0c5220b..5e4d8724ac 100644 --- a/tests/external_requests/test_requests.py +++ b/tests/external_requests/test_requests.py @@ -14,12 +14,9 @@ import pytest import requests -import requests.exceptions -from testing_support.external_fixtures import cache_outgoing_headers # , insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers from testing_support.fixtures import override_application_settings, validate_tt_parenting from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers - -# 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 @@ -123,9 +120,6 @@ def _test(): def test_none_url_get(): try: requests.get(None) - except requests.exceptions.MissingSchema: - # Python 2. - pass except TypeError: # Python 3. pass @@ -166,47 +160,7 @@ def _test(): requests.get(f"http://localhost:{server.port}/") _test = override_application_settings( - { - "distributed_tracing.enabled": distributed_tracing, - # "cross_application_tracer.enabled": not distributed_tracing, - "span_events.enabled": span_events, - } + {"distributed_tracing.enabled": distributed_tracing, "span_events.enabled": span_events} )(_test) _test() - - -# @cat_enabled -# def test_requests_cross_process_response(server): -# _test_requests_cross_process_response_scoped_metrics = [ -# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1) -# ] - -# _test_requests_cross_process_response_rollup_metrics = [ -# ("External/all", 1), -# ("External/allOther", 1), -# (f"External/localhost:{server.port}/all", 1), -# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), -# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), -# ] - -# _test_requests_cross_process_response_external_node_params = [ -# ("cross_process_id", "1#2"), -# ("external_txn_name", "test"), -# ("transaction_guid", "0123456789012345"), -# ] - -# @validate_transaction_errors(errors=[]) -# @validate_transaction_metrics( -# "test_requests:test_requests_cross_process_response", -# scoped_metrics=_test_requests_cross_process_response_scoped_metrics, -# rollup_metrics=_test_requests_cross_process_response_rollup_metrics, -# background_task=True, -# ) -# @insert_incoming_headers -# @validate_external_node_params(params=_test_requests_cross_process_response_external_node_params) -# @background_task(name="test_requests:test_requests_cross_process_response") -# def _test(): -# requests.get(f"http://localhost:{server.port}/") - -# _test() diff --git a/tests/external_urllib3/test_urllib3.py b/tests/external_urllib3/test_urllib3.py index f82c183225..106f0b96ab 100644 --- a/tests/external_urllib3/test_urllib3.py +++ b/tests/external_urllib3/test_urllib3.py @@ -14,18 +14,15 @@ import pytest import urllib3 -import urllib3.connectionpool try: import urllib3.connection except ImportError: pass -from testing_support.external_fixtures import cache_outgoing_headers # , insert_incoming_headers +from testing_support.external_fixtures import cache_outgoing_headers from testing_support.fixtures import override_application_settings from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers - -# 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 @@ -215,46 +212,7 @@ def _test(): pool.urlopen("GET", "/") _test = override_application_settings( - { - "distributed_tracing.enabled": distributed_tracing, - # "cross_application_tracer.enabled": not distributed_tracing, - "span_events.enabled": span_events, - } + {"distributed_tracing.enabled": distributed_tracing, "span_events.enabled": span_events} )(_test) _test() - - -# @cat_enabled -# def test_urlopen_cross_process_response(server): -# _test_urlopen_cross_process_response_scoped_metrics = [(f"ExternalTransaction/localhost:{server.port}/1#2/test", 1)] - -# _test_urlopen_cross_process_response_rollup_metrics = [ -# ("External/all", 1), -# ("External/allOther", 1), -# (f"External/localhost:{server.port}/all", 1), -# (f"ExternalApp/localhost:{server.port}/1#2/all", 1), -# (f"ExternalTransaction/localhost:{server.port}/1#2/test", 1), -# ] - -# _test_urlopen_cross_process_response_external_node_params = [ -# ("cross_process_id", "1#2"), -# ("external_txn_name", "test"), -# ("transaction_guid", "0123456789012345"), -# ] - -# @validate_transaction_errors(errors=[]) -# @validate_transaction_metrics( -# "test_urllib3:test_urlopen_cross_process_response", -# scoped_metrics=_test_urlopen_cross_process_response_scoped_metrics, -# rollup_metrics=_test_urlopen_cross_process_response_rollup_metrics, -# background_task=True, -# ) -# @insert_incoming_headers -# @validate_external_node_params(params=_test_urlopen_cross_process_response_external_node_params) -# @background_task(name="test_urllib3:test_urlopen_cross_process_response") -# def _test(): -# pool = urllib3.HTTPConnectionPool(f"localhost:{server.port}") -# pool.urlopen("GET", "/") - -# _test() diff --git a/tests/framework_aiohttp/conftest.py b/tests/framework_aiohttp/conftest.py index 0d295b3fff..1cdf4c607a 100644 --- a/tests/framework_aiohttp/conftest.py +++ b/tests/framework_aiohttp/conftest.py @@ -123,8 +123,6 @@ def respond_with_dt_header(self): self.end_headers() self.wfile.write(b"") - # with MockExternalHTTPServer(handler=respond_with_cat_header) as server: - # with MockExternalHTTPServer() as server: with MockExternalHTTPServer(handler=respond_with_dt_header) as server: yield (server, response_values) diff --git a/tests/framework_aiohttp/test_client_async_await.py b/tests/framework_aiohttp/test_client_async_await.py index a30cd830b6..0de1e083e6 100644 --- a/tests/framework_aiohttp/test_client_async_await.py +++ b/tests/framework_aiohttp/test_client_async_await.py @@ -16,8 +16,6 @@ import aiohttp import pytest - -# from testing_support.fixtures import cat_enabled from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from yarl import URL @@ -68,7 +66,6 @@ def task(loop, method, exc_expected, url): ) -# @cat_enabled @pytest.mark.parametrize("method,exc_expected", test_matrix) def test_client_async_await(event_loop, local_server_info, method, exc_expected): @validate_transaction_metrics( @@ -83,7 +80,6 @@ def task_test(): task_test() -# @cat_enabled def test_client_yarl_async_await(event_loop, local_server_info): method = "get" @@ -100,7 +96,6 @@ def task_test(): @pytest.mark.parametrize("method,exc_expected", test_matrix) -# @cat_enabled def test_client_no_txn_async_await(event_loop, local_server_info, method, exc_expected): def task_test(): task(event_loop, method, exc_expected, local_server_info.url) @@ -109,7 +104,6 @@ def task_test(): @pytest.mark.parametrize("method,exc_expected", test_matrix) -# @cat_enabled def test_await_request_async_await(event_loop, local_server_info, method, exc_expected): async def request_with_await(): async with aiohttp.ClientSession() as session: @@ -163,7 +157,6 @@ def task_test(): @pytest.mark.parametrize("method,exc_expected", test_matrix) -# @cat_enabled def test_create_task_async_await(event_loop, local_server_info, method, exc_expected): # `loop.create_task` returns a Task object which uses the coroutine's # `send` method, not `__next__` @@ -199,7 +192,6 @@ def task_test(): @pytest.mark.parametrize("method,exc_expected", test_matrix) -# @cat_enabled def test_terminal_parent_async_await(event_loop, local_server_info, method, exc_expected): """ This test injects a terminal node into a simple background task workflow. diff --git a/tests/framework_aiohttp/test_server_dt.py b/tests/framework_aiohttp/test_server_dt.py index 307eade547..0b9350d04c 100644 --- a/tests/framework_aiohttp/test_server_dt.py +++ b/tests/framework_aiohttp/test_server_dt.py @@ -15,135 +15,15 @@ import json import pytest -from testing_support.fixtures import ( - # make_cross_agent_headers, - override_application_settings, - # validate_analytics_catmap_data, -) +from testing_support.fixtures import override_application_settings from testing_support.validators.validate_transaction_event_attributes import validate_transaction_event_attributes -# from newrelic.common.encoding_utils import deobfuscate -# from newrelic.common.object_wrapper import transient_function_wrapper - -# ENCODING_KEY = "1234567890123456789012345678901234567890" test_uris = [ ("/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 -# except ImportError: - -# def pass_through(function): -# return function - -# return pass_through - -# @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") - -# # This is the request, not the response -# if line.startswith("GET"): -# break - -# if ":" in line: -# key, value = line.split(":", maxsplit=1) -# raw_headers[key.strip()] = value.strip() - -# return wrapped(*args, **kwargs) - -# return recorder - - -# @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 -# ): -# _raw_headers = {} - -# async def fetch(): -# headers = make_cross_agent_headers(inbound_payload, ENCODING_KEY, cat_id) -# resp = await 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} - -# if expected_intrinsics: -# # test valid CAT response header -# assert "X-NewRelic-App-Data" in raw_headers - -# app_data = json.loads(deobfuscate(raw_headers["X-NewRelic-App-Data"], ENCODING_KEY)) -# assert app_data[0] == cat_id -# assert app_data[1] == f"WebTransaction/Function/{metric_name}" -# else: -# 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, -# } - -# # NOTE: the logic-flow of this test can be a bit confusing. -# # the override settings and attribute validation occur -# # not when the request is made (above) since it does not -# # occur inside a transaction. instead, the settings and -# # validation are for the new transaction that is made -# # asynchronously on the *server side* when the request -# # is received and subsequently processed. that code is -# # a fixture from conftest.py/_target_application.py - -# @validate_analytics_catmap_data( -# f"WebTransaction/Function/{metric_name}", -# expected_attributes=expected_intrinsics, -# non_expected_attributes=forgone_intrinsics, -# ) -# @override_application_settings(_custom_settings) -# @record_aiohttp1_raw_headers(_raw_headers) -# def _test(): -# aiohttp_app.loop.run_until_complete(fetch()) - -# _test() - - account_id = "33" primary_application_id = "2827902" @@ -178,12 +58,6 @@ }, } -# unexpected_attributes = { -# "agent": [], -# "user": [], -# "intrinsic": ["grandparentId", "cross_process_id", "nr.tripId", "nr.pathHash"], -# } - @pytest.mark.parametrize("uri,metric_name", test_uris) def test_distributed_tracing_headers(uri, metric_name, aiohttp_app): @@ -191,11 +65,8 @@ async def fetch(): headers = {"newrelic": json.dumps(inbound_payload)} resp = await aiohttp_app.client.request("GET", uri, headers=headers) - # # better cat does not send a response in the 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 + # DT does not send a response in the headers + assert "newrelic" not in resp.headers # NOTE: the logic-flow of this test can be a bit confusing. # the override settings and attribute validation occur @@ -207,7 +78,6 @@ async def fetch(): # a fixture from conftest.py/_target_application.py @validate_transaction_event_attributes(expected_attributes) - # @validate_transaction_event_attributes(expected_attributes, unexpected_attributes) @override_application_settings( { "account_id": "33", diff --git a/tests/framework_sanic/conftest.py b/tests/framework_sanic/conftest.py index 8802638beb..f86a9cf10d 100644 --- a/tests/framework_sanic/conftest.py +++ b/tests/framework_sanic/conftest.py @@ -17,8 +17,6 @@ import pytest from testing_support.fixtures import collector_agent_registration_fixture, collector_available_fixture -# from newrelic.common.object_wrapper import transient_function_wrapper - _default_settings = { "package_reporting.enabled": False, # Turn off package reporting for testing as it causes slow downs. "transaction_tracer.explain_threshold": 0.0, diff --git a/tests/framework_sanic/test_distributed_trace.py b/tests/framework_sanic/test_distributed_trace.py index 436bd0e68c..d4f10abb72 100644 --- a/tests/framework_sanic/test_distributed_trace.py +++ b/tests/framework_sanic/test_distributed_trace.py @@ -12,18 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# import json -# import random - -# import re -# import string - -# import pytest -from testing_support.fixtures import ( - # make_cross_agent_headers, - override_application_settings, - # validate_analytics_catmap_data, -) +from testing_support.fixtures import override_application_settings from testing_support.validators.validate_transaction_event_attributes import validate_transaction_event_attributes from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics @@ -31,8 +20,6 @@ from newrelic.api.external_trace import ExternalTrace from newrelic.api.transaction import Transaction -# from newrelic.common.encoding_utils import deobfuscate - BASE_METRICS = [("Function/_target_application:index", 1)] DT_METRICS = [ ("Supportability/DistributedTrace/AcceptPayload/Success", None), @@ -63,80 +50,3 @@ def test_inbound_distributed_trace(app): response = app.fetch("get", "/", headers=dict(dt_headers)) assert response.status == 200 - - -# ENCODING_KEY = "".join(random.choice(string.ascii_lowercase) for _ in range(40)) -# _cat_response_header_urls_to_test = ( -# ("/", "_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, -# } - - -# @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): -# _base_metrics = [(f"Function/{metric_name}", 1)] - -# @validate_transaction_metrics(metric_name, scoped_metrics=_base_metrics, rollup_metrics=_base_metrics) -# @validate_analytics_catmap_data( -# f"WebTransaction/Function/{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)) -# if expected_intrinsics: -# # test valid CAT response header -# 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)) -# assert app_data[0] == cat_id -# assert app_data[1] == f"WebTransaction/Function/{metric_name}" -# else: -# 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", f"/custom-header/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/_target_application.py b/tests/framework_tornado/_target_application.py index 396f357570..49383b216b 100644 --- a/tests/framework_tornado/_target_application.py +++ b/tests/framework_tornado/_target_application.py @@ -15,7 +15,6 @@ import time import tornado.gen -import tornado.httpclient import tornado.httputil import tornado.ioloop import tornado.web @@ -35,35 +34,6 @@ def get_status(self, *args, **kwargs): raise ValueError("Bad Status") -# class ProcessCatHeadersHandler(tornado.web.RequestHandler): -# def __init__(self, application, request, response_code=200, **kwargs): -# super().__init__(application, request, **kwargs) -# self.response_code = response_code - -# def get(self, client_cross_process_id, txn_header, flush=None): -# import newrelic.api.transaction as _transaction - -# # txn = _transaction.current_transaction() -# # if txn: -# # txn._process_incoming_cat_headers(client_cross_process_id, txn_header) - -# if self.response_code != 200: -# self.set_status(self.response_code) -# return - -# self.write("Hello, world") - -# if flush == "flush": -# # Force a flush prior to calling finish -# # This causes the headers to get written immediately. The tests -# # which hit this endpoint will check that the response has been -# # properly processed even though we send the headers here. -# self.flush() - -# # change the headers to garbage -# self.set_header("Content-Type", "garbage") - - class EchoHeaderHandler(tornado.web.RequestHandler): def get(self): response = str(self.request.headers.__dict__).encode("utf-8") @@ -250,8 +220,6 @@ def make_app(custom=False): (r"/init", InitializeHandler), (r"/html-insertion", HTMLInsertionHandler), (r"/bad-get-status", BadGetStatusHandler), - # (r"/force-cat-response/(\S+)/(\S+)/(\S+)", ProcessCatHeadersHandler), - # (r"/304-cat-response/(\S+)/(\S+)", ProcessCatHeadersHandler, {"response_code": 304}), (r"/echo-headers", EchoHeaderHandler), (r"/native-simple", NativeSimpleHandler), (r"/multi-trace", MultiTraceHandler), diff --git a/tests/framework_tornado/test_externals.py b/tests/framework_tornado/test_externals.py index 8d7ef80ab2..e872b3bdfc 100644 --- a/tests/framework_tornado/test_externals.py +++ b/tests/framework_tornado/test_externals.py @@ -13,24 +13,16 @@ # limitations under the License. import io -import socket import sys import pytest from testing_support.fixtures import override_application_settings -from testing_support.mock_external_http_server import MockExternalHTTPHResponseHeadersServer, MockExternalHTTPServer - -# from testing_support.validators.validate_distributed_tracing_header import validate_distributed_tracing_header -# from testing_support.validators.validate_outbound_headers import validate_outbound_headers +from testing_support.mock_external_http_server import MockExternalHTTPHResponseHeadersServer 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 -# from newrelic.api.transaction import current_transaction - -ENCODING_KEY = "1234567890123456789012345678901234567890" - is_pypy = hasattr(sys, "pypy_version_info") @@ -128,26 +120,12 @@ def _make_request(): @pytest.mark.parametrize("span_events", [True, False]) @pytest.mark.parametrize("request_type", ["uri", "class"]) @pytest.mark.parametrize("num_requests", [1, 2]) -def test_httpclient( - # cat_enabled, - request_type, - client_class, - num_requests, - span_events, - external, - as_kwargs, -): +def test_httpclient(request_type, client_class, num_requests, span_events, external, as_kwargs): port = external.port expected_metrics = [(f"External/localhost:{port}/tornado/GET", num_requests)] - @override_application_settings( - { - "distributed_tracing.enabled": True, - "span_events.enabled": span_events, - # "cross_application_tracer.enabled": not distributed_tracing, - } - ) + @override_application_settings({"distributed_tracing.enabled": True, "span_events.enabled": span_events}) @validate_transaction_metrics( "test_externals:test_httpclient", background_task=True, @@ -157,8 +135,6 @@ def test_httpclient( @background_task(name="test_externals:test_httpclient") def _test(): headers = {} - # if user_header: - # headers = {user_header: "USER"} response = make_request( port, request_type, client_class, headers=headers, count=num_requests, as_kwargs=as_kwargs @@ -178,98 +154,9 @@ def _test(): header_val = header_val.strip() headers[header_key] = header_val - # User headers override all inserted NR headers - # if user_header: - # assert headers[user_header] == "USER" - # elif cat_enabled: - # t = current_transaction() - # assert t - # t._test_request_headers = headers - - # if distributed_tracing: - # validate_distributed_tracing_header(header="Newrelic") - # else: - # validate_outbound_headers() - # else: - # # new relic shouldn't add anything to the outgoing - # assert "x-newrelic" not in body, body - - # assert "X-NewRelic-App-Data" not in headers - _test() -# CAT_RESPONSE_CODE = None - - -# def cat_response_handler(self): -# # payload -# # ( -# # u'1#1', u'WebTransaction/Function/app:beep', -# # 0, 1.23, -1, -# # 'dd4a810b7cb7f937', -# # False, -# # ) -# cat_response_header = ( -# "X-NewRelic-App-Data", -# "ahACFwQUGxpuVVNmQVVbRVZbTVleXBxyQFhUTFBfXx1SREUMVV1cQBMeAxgEGAULFR0AHhFQUQJWAAgAUwVQVgJQDgsOEh1UUlhGU2o=", -# ) -# self.send_response(CAT_RESPONSE_CODE) -# self.send_header(*cat_response_header) -# self.end_headers() -# self.wfile.write(b"Example Data") - - -# @pytest.fixture(scope="module") -# def cat_response_server(): -# external = MockExternalHTTPServer(handler=cat_response_handler) -# with external: -# yield external - - -# @pytest.mark.parametrize("client_class", ["AsyncHTTPClient", "CurlAsyncHTTPClient", "HTTPClient"]) -# @pytest.mark.parametrize("dt_enabled", [True, False]) -# @pytest.mark.parametrize("request_type", ["uri", "class"]) -# @pytest.mark.parametrize("response_code,raise_error", [(500, True), (500, False), (200, False)]) -# def test_client_cat_response_processing( -# dt_enabled, request_type, client_class, raise_error, response_code, cat_response_server -# ): -# global CAT_RESPONSE_CODE -# CAT_RESPONSE_CODE = response_code - -# _custom_settings = { -# "cross_process_id": "1#1", -# "encoding_key": ENCODING_KEY, -# "trusted_account_ids": [1], -# # "cross_application_tracer.enabled": cat_enabled, -# "distributed_tracing.enabled": dt_enabled, -# "transaction_tracer.transaction_threshold": 0.0, -# } - -# port = cat_response_server.port -# expected_metrics = None - -# @validate_transaction_metrics( -# "make_request", background_task=True, rollup_metrics=expected_metrics, scoped_metrics=expected_metrics -# ) -# @override_application_settings(_custom_settings) -# def _test(): -# import tornado -# import tornado.httpclient - -# try: -# response = make_request(port, request_type, client_class, raise_error=raise_error) -# except tornado.httpclient.HTTPError as e: -# assert raise_error -# response = e.response -# else: -# assert not raise_error - -# assert response.code == response_code - -# _test() - - @pytest.mark.parametrize("client_class", ["AsyncHTTPClient", "CurlAsyncHTTPClient", "HTTPClient"]) @validate_transaction_metrics("make_request", background_task=True) def test_httpclient_invalid_method(client_class, external): diff --git a/tests/framework_tornado/test_inbound_dt.py b/tests/framework_tornado/test_inbound_dt.py index 319fc00229..f8358338c6 100644 --- a/tests/framework_tornado/test_inbound_dt.py +++ b/tests/framework_tornado/test_inbound_dt.py @@ -18,76 +18,6 @@ from testing_support.validators.validate_transaction_event_attributes import validate_transaction_event_attributes from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics -# ENCODING_KEY = "1234567890123456789012345678901234567890" - - -# _custom_settings = { -# "cross_process_id": "1#1", -# "encoding_key": ENCODING_KEY, -# "trusted_account_ids": [1], -# # "cross_application_tracer.enabled": True, -# "distributed_tracing.enabled": False, -# "transaction_tracer.transaction_threshold": 0.0, -# } - - -# @override_application_settings(_custom_settings) -# @validate_transaction_event_attributes( -# required_params={"agent": (), "user": (), "intrinsic": ()}, -# forgone_params={"agent": (), "user": (), "intrinsic": ()}, -# exact_attrs={ -# "agent": {"response.status": "200", "response.headers.contentType": "text/html; charset=UTF-8"}, -# "user": {}, -# "intrinsic": {}, -# }, -# ) -# @pytest.mark.parametrize("manual_flush", ["flush", "no-flush"]) -# def test_response_to_inbound_cat(app, manual_flush): -# payload = ("1#1", "WebTransaction/Function/app:beep", 0, 1.23, -1, "dd4a810b7cb7f937", False) -# headers = make_cross_agent_headers(payload, ENCODING_KEY, "1#1") - -# client_cross_process_id = headers["X-NewRelic-ID"] -# txn_header = headers["X-NewRelic-Transaction"] - -# response = app.fetch(f"/force-cat-response/{client_cross_process_id}/{txn_header}/{manual_flush}") -# assert response.code == 200 -# assert "X-NewRelic-App-Data" in list(response.headers.keys()) - - -# # @validate_transaction_event_attributes( -# # required_params={"agent": (), "user": (), "intrinsic": ()}, -# # forgone_params={"agent": ("response.headers",), "user": (), "intrinsic": ()}, -# # exact_attrs={"agent": {"request.method": "GET", "response.status": "304"}, "user": {}, "intrinsic": {}}, -# # ) -# # @override_application_settings(_custom_settings) -# # def test_cat_headers_not_inserted(app): -# # payload = ("1#1", "WebTransaction/Function/app:beep", 0, 1.23, -1, "dd4a810b7cb7f937", False) -# # headers = make_cross_agent_headers(payload, ENCODING_KEY, "1#1") - -# # client_cross_process_id = headers["X-NewRelic-ID"] -# # txn_header = headers["X-NewRelic-Transaction"] - -# # response = app.fetch(f"/304-cat-response/{client_cross_process_id}/{txn_header}") -# # assert response.code == 304 -# # assert "X-NewRelic-App-Data" not in list(response.headers.keys()) - - -# @override_application_settings(_custom_settings) -# @validate_transaction_metrics( -# "_target_application:SimpleHandler.get", rollup_metrics=[("ClientApplication/1#1/all", 1)] -# ) -# @validate_transaction_event_attributes( -# required_params={"agent": [], "user": [], "intrinsic": []}, -# forgone_params={"agent": [], "user": [], "intrinsic": []}, -# exact_attrs={"agent": {}, "user": {}, "intrinsic": {"nr.referringTransactionGuid": "b854df4feb2b1f06"}}, -# ) -# def test_inbound_cat_metrics_and_intrinsics(app): -# payload = ["b854df4feb2b1f06", False, "7e249074f277923d", "5d2957be"] -# headers = make_cross_agent_headers(payload, ENCODING_KEY, "1#1") - -# response = app.fetch("/simple", headers=headers) -# assert response.code == 200 - @validate_transaction_event_attributes( required_params={"agent": (), "user": (), "intrinsic": ()}, diff --git a/tests/messagebroker_pika/test_distributed_tracing.py b/tests/messagebroker_pika/test_distributed_tracing.py index 75dfd17b08..d940441f11 100644 --- a/tests/messagebroker_pika/test_distributed_tracing.py +++ b/tests/messagebroker_pika/test_distributed_tracing.py @@ -31,7 +31,6 @@ "primary_application_id": "12345", "account_id": "33", "trusted_account_key": "1", - # "cross_application_tracer.enabled": True, "distributed_tracing.enabled": True, } @@ -81,8 +80,6 @@ def test_basic_consume_distributed_tracing_headers(): def on_receive(ch, method, properties, msg): headers = properties.headers assert headers - # assert "NewRelicID" not in headers - # assert "NewRelicTransaction" not in headers assert msg == b"Testing distributed_tracing 123" txn = current_transaction() @@ -134,13 +131,10 @@ def do_basic_get(channel, QUEUE): headers = properties.headers assert headers - # assert "NewRelicID" not in headers - # assert "NewRelicTransaction" not in headers assert msg == b"Testing distributed_tracing 123" txn = current_transaction() - # assert txn.client_cross_process_id is None assert txn.client_account_id is None assert txn.client_application_id is None diff --git a/tests/messagebroker_pika/test_pika_produce.py b/tests/messagebroker_pika/test_pika_produce.py index bda5635e89..65495d19cb 100644 --- a/tests/messagebroker_pika/test_pika_produce.py +++ b/tests/messagebroker_pika/test_pika_produce.py @@ -171,10 +171,7 @@ def test_blocking_connection_reply_to(producer): @pytest.mark.parametrize("enable_distributed_tracing", [True, False]) def test_blocking_connection_headers(enable_distributed_tracing): - override_settings = { - "distributed_tracing.enabled": enable_distributed_tracing - # "cross_application_tracer.enabled": not enable_distributed_tracing, - } + override_settings = {"distributed_tracing.enabled": enable_distributed_tracing} rollup_metrics = list(_test_blocking_connection_metrics) if enable_distributed_tracing: rollup_metrics += [ diff --git a/tests/testing_support/external_fixtures.py b/tests/testing_support/external_fixtures.py index 5746cdbcad..62e0863373 100644 --- a/tests/testing_support/external_fixtures.py +++ b/tests/testing_support/external_fixtures.py @@ -16,35 +16,8 @@ from newrelic.api.external_trace import ExternalTrace from newrelic.api.transaction import current_transaction - -# from newrelic.common.encoding_utils import json_encode, obfuscate from newrelic.common.object_wrapper import transient_function_wrapper -# def create_incoming_headers(transaction): -# settings = transaction.settings -# encoding_key = settings.encoding_key - -# headers = [] - -# cross_process_id = "1#2" -# path = "test" -# queue_time = 1.0 -# duration = 2.0 -# read_length = 1024 -# guid = "0123456789012345" -# record_tt = False - -# payload = (cross_process_id, path, queue_time, duration, read_length, guid, record_tt) -# app_data = json_encode(payload) - -# value = obfuscate(app_data, encoding_key) - -# assert isinstance(value, str) - -# headers.append(("X-NewRelic-App-Data", value)) - -# return headers - def validate_synthetics_external_trace_header(synthetics_header, synthetics_info_header): @transient_function_wrapper("newrelic.core.stats_engine", "StatsEngine.record_transaction") @@ -126,17 +99,3 @@ def _bind_params(header, *values): cache[header] = list(values) return wrapped(*args, **kwargs) - - -# @transient_function_wrapper(httplib.__name__, "HTTPResponse.getheaders") -# def insert_incoming_headers(wrapped, instance, args, kwargs): -# transaction = current_transaction() - -# if transaction is None: -# return wrapped(*args, **kwargs) - -# headers = list(wrapped(*args, **kwargs)) - -# headers.extend(create_incoming_headers(transaction)) - -# return headers diff --git a/tests/testing_support/fixtures.py b/tests/testing_support/fixtures.py index e0d88833e7..16d39f8ca0 100644 --- a/tests/testing_support/fixtures.py +++ b/tests/testing_support/fixtures.py @@ -426,12 +426,6 @@ def catch_background_exceptions(wrapped, instance, args, kwargs): raise_background_exceptions.event.set() -# def make_cross_agent_headers(payload, encoding_key, cat_id): -# value = obfuscate(json_encode(payload), encoding_key) -# id_value = obfuscate(cat_id, encoding_key) -# return {"X-NewRelic-Transaction": value, "X-NewRelic-ID": id_value} - - def make_synthetics_headers( encoding_key, account_id, @@ -797,7 +791,6 @@ def _bind_params(transaction, *args, **kwargs): assert intrinsics["error.class"] == required_attrs["error.class"] assert intrinsics["error.message"].startswith(required_attrs["error.message"]) assert intrinsics["error.expected"] == required_attrs["error.expected"] - # assert intrinsics["nr.transactionGuid"] is not None assert intrinsics["spanId"] is not None # check that transaction event intrinsics haven't bled in @@ -860,12 +853,6 @@ def _validate_event_attributes(intrinsics, user_attributes, required_intrinsics, else: assert "queueDuration" not in intrinsics - # if "nr.referringTransactionGuid" in required_intrinsics: - # guid = required_intrinsics["nr.referringTransactionGuid"] - # assert intrinsics["nr.referringTransactionGuid"] == guid - # else: - # assert "nr.referringTransactionGuid" not in intrinsics - if "nr.syntheticsResourceId" in required_intrinsics: res_id = required_intrinsics["nr.syntheticsResourceId"] job_id = required_intrinsics["nr.syntheticsJobId"] @@ -1046,14 +1033,6 @@ def force_sampled(wrapped, instance, args, kwargs): return wrapped(*args, **kwargs) -# @function_wrapper -# def cat_enabled(wrapped, instance, args, kwargs): -# settings = {"cross_application_tracer.enabled": True, "distributed_tracing.enabled": False} -# wrapped = override_application_settings(settings)(wrapped) - -# return wrapped(*args, **kwargs) - - def override_application_settings(overrides): @function_wrapper def _override_application_settings(wrapped, instance, args, kwargs): diff --git a/tests/testing_support/validators/validate_cross_process_headers.py b/tests/testing_support/validators/validate_cross_process_headers.py index 5f9f82f882..8b64d5e464 100644 --- a/tests/testing_support/validators/validate_cross_process_headers.py +++ b/tests/testing_support/validators/validate_cross_process_headers.py @@ -16,8 +16,6 @@ from newrelic.common.object_wrapper import function_wrapper from testing_support.validators.validate_distributed_tracing_header import validate_distributed_tracing_header -# from testing_support.validators.validate_outbound_headers import validate_outbound_headers - @function_wrapper def validate_cross_process_headers(wrapped, instance, args, kwargs): @@ -28,7 +26,5 @@ def validate_cross_process_headers(wrapped, instance, args, kwargs): if settings.distributed_tracing.enabled: validate_distributed_tracing_header() - # else: - # validate_outbound_headers() return result diff --git a/tests/testing_support/validators/validate_distributed_tracing_header.py b/tests/testing_support/validators/validate_distributed_tracing_header.py index 4015b819e2..962dc63b9c 100644 --- a/tests/testing_support/validators/validate_distributed_tracing_header.py +++ b/tests/testing_support/validators/validate_distributed_tracing_header.py @@ -65,9 +65,6 @@ def validate_distributed_tracing_header(header="newrelic"): # Verify referring transaction information assert len(data["tr"]) == 32 - # if transaction.referring_transaction_guid is not None: - # assert data["tr"] == transaction._trace_id - # else: assert data["tr"].startswith(transaction.guid) assert "pa" not in data diff --git a/tests/testing_support/validators/validate_messagebroker_headers.py b/tests/testing_support/validators/validate_messagebroker_headers.py index f45a47adb4..160c8e9f09 100644 --- a/tests/testing_support/validators/validate_messagebroker_headers.py +++ b/tests/testing_support/validators/validate_messagebroker_headers.py @@ -16,8 +16,6 @@ from newrelic.common.object_wrapper import function_wrapper from testing_support.validators.validate_distributed_tracing_header import validate_distributed_tracing_header -# from testing_support.validators.validate_outbound_headers import validate_outbound_headers - @function_wrapper def validate_messagebroker_headers(wrapped, instance, args, kwargs): @@ -28,7 +26,5 @@ def validate_messagebroker_headers(wrapped, instance, args, kwargs): if settings.distributed_tracing.enabled: validate_distributed_tracing_header() - # else: - # validate_outbound_headers(header_id="NewRelicID", header_transaction="NewRelicTransaction") return result diff --git a/tests/testing_support/validators/validate_synthetics_event.py b/tests/testing_support/validators/validate_synthetics_event.py index dd6fedbb86..5780c34149 100644 --- a/tests/testing_support/validators/validate_synthetics_event.py +++ b/tests/testing_support/validators/validate_synthetics_event.py @@ -42,8 +42,6 @@ def _flatten(event): flat_event = _flatten(event) - # assert "nr.guid" in flat_event, f"name=nr.guid, event={flat_event!r}" - for name, value in required_attrs: assert name in flat_event, f"name={name!r}, event={flat_event!r}" assert flat_event[name] == value, f"name={name!r}, value={value!r}, event={flat_event!r}" From 6fbfac40e044ae0e4452cf0fa7ef9fba9e583af8 Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Fri, 12 Sep 2025 18:46:05 -0700 Subject: [PATCH 76/95] Fix requests test --- tests/external_requests/test_requests.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/external_requests/test_requests.py b/tests/external_requests/test_requests.py index 5e4d8724ac..fdd04db775 100644 --- a/tests/external_requests/test_requests.py +++ b/tests/external_requests/test_requests.py @@ -14,6 +14,7 @@ import pytest import requests +import requests.exceptions from testing_support.external_fixtures import cache_outgoing_headers from testing_support.fixtures import override_application_settings, validate_tt_parenting from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers @@ -120,8 +121,9 @@ def _test(): def test_none_url_get(): try: requests.get(None) + except requests.exceptions.MissingSchema: + pass except TypeError: - # Python 3. pass From 125cf1cd242e909eff0bb5951464a4d81fd1e901 Mon Sep 17 00:00:00 2001 From: Tim Pansino Date: Mon, 22 Sep 2025 16:22:20 -0700 Subject: [PATCH 77/95] Rename cross_process_headers to distributed_tracing_headers --- tests/external_http/test_http.py | 8 +++---- tests/external_httplib/test_httplib.py | 8 +++---- tests/external_httplib/test_urllib.py | 10 ++++----- tests/external_httplib/test_urllib2.py | 6 ++--- tests/external_httplib2/test_httplib2.py | 8 +++---- tests/external_httpx/test_client.py | 22 +++++++++---------- tests/external_requests/test_requests.py | 8 +++---- tests/external_urllib3/test_urllib3.py | 8 +++---- ...> validate_distributed_tracing_headers.py} | 2 +- 9 files changed, 40 insertions(+), 40 deletions(-) rename tests/testing_support/validators/{validate_cross_process_headers.py => validate_distributed_tracing_headers.py} (93%) diff --git a/tests/external_http/test_http.py b/tests/external_http/test_http.py index 1d5f4f0e1c..0ba4c7d740 100644 --- a/tests/external_http/test_http.py +++ b/tests/external_http/test_http.py @@ -17,7 +17,7 @@ import pytest from testing_support.external_fixtures import cache_outgoing_headers from testing_support.fixtures import override_application_settings -from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers +from testing_support.validators.validate_distributed_tracing_headers import validate_distributed_tracing_headers from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task @@ -71,10 +71,10 @@ def _test(): @pytest.mark.parametrize("distributed_tracing,span_events", ((True, True), (True, False), (False, False))) -def test_http_cross_process_request(distributed_tracing, span_events, server): - @background_task(name="test_http:test_http_cross_process_request") +def test_http_distributed_tracing_request(distributed_tracing, span_events, server): + @background_task(name="test_http:test_http_distributed_tracing_request") @cache_outgoing_headers - @validate_cross_process_headers + @validate_distributed_tracing_headers def _test(): connection = http.client.HTTPConnection("localhost", server.port) connection.request("GET", "/") diff --git a/tests/external_httplib/test_httplib.py b/tests/external_httplib/test_httplib.py index 1103072df4..cf0d42f7b7 100644 --- a/tests/external_httplib/test_httplib.py +++ b/tests/external_httplib/test_httplib.py @@ -19,7 +19,7 @@ import pytest from testing_support.external_fixtures import cache_outgoing_headers from testing_support.fixtures import override_application_settings -from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers +from testing_support.validators.validate_distributed_tracing_headers import validate_distributed_tracing_headers 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_tt_segment_params import validate_tt_segment_params @@ -111,10 +111,10 @@ def _test(): @pytest.mark.parametrize("distributed_tracing,span_events", ((True, True), (True, False), (False, False))) -def test_httplib_cross_process_request(server, distributed_tracing, span_events): - @background_task(name="test_httplib:test_httplib_cross_process_request") +def test_httplib_distributed_tracing_request(server, distributed_tracing, span_events): + @background_task(name="test_httplib:test_httplib_distributed_tracing_request") @cache_outgoing_headers - @validate_cross_process_headers + @validate_distributed_tracing_headers def _test(): connection = httplib.HTTPConnection("localhost", server.port) connection.request("GET", "/") diff --git a/tests/external_httplib/test_urllib.py b/tests/external_httplib/test_urllib.py index aebc870c37..d6cec86e8f 100644 --- a/tests/external_httplib/test_urllib.py +++ b/tests/external_httplib/test_urllib.py @@ -22,7 +22,7 @@ import urllib from testing_support.external_fixtures import cache_outgoing_headers -from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers +from testing_support.validators.validate_distributed_tracing_headers import validate_distributed_tracing_headers from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task @@ -136,8 +136,8 @@ def test_urlopener_file_request(): @SKIP_IF_PYTHON_3_14_OR_ABOVE @background_task() @cache_outgoing_headers -@validate_cross_process_headers -def test_urlopener_cross_process_request(server): +@validate_distributed_tracing_headers +def test_urlopener_distributed_tracing_request(server): opener = urllib.URLopener() opener.open(f"http://localhost:{server.port}/") @@ -175,6 +175,6 @@ def _test(): @background_task() @cache_outgoing_headers -@validate_cross_process_headers -def test_urlretrieve_cross_process_request(server): +@validate_distributed_tracing_headers +def test_urlretrieve_distributed_tracing_request(server): urllib.urlretrieve(f"http://localhost:{server.port}/") diff --git a/tests/external_httplib/test_urllib2.py b/tests/external_httplib/test_urllib2.py index c5478036af..3e23bd7f9f 100644 --- a/tests/external_httplib/test_urllib2.py +++ b/tests/external_httplib/test_urllib2.py @@ -16,7 +16,7 @@ import pytest from testing_support.external_fixtures import cache_outgoing_headers -from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers +from testing_support.validators.validate_distributed_tracing_headers import validate_distributed_tracing_headers from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task @@ -113,6 +113,6 @@ def test_urlopen_file_request(): @background_task() @cache_outgoing_headers -@validate_cross_process_headers -def test_urlopen_cross_process_request(server): +@validate_distributed_tracing_headers +def test_urlopen_distributed_tracing_request(server): urllib2.urlopen(f"http://localhost:{server.port}/") diff --git a/tests/external_httplib2/test_httplib2.py b/tests/external_httplib2/test_httplib2.py index fe531a4b67..007c2dda7d 100644 --- a/tests/external_httplib2/test_httplib2.py +++ b/tests/external_httplib2/test_httplib2.py @@ -16,7 +16,7 @@ import pytest from testing_support.external_fixtures import cache_outgoing_headers from testing_support.fixtures import override_application_settings -from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers +from testing_support.validators.validate_distributed_tracing_headers import validate_distributed_tracing_headers from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics from newrelic.api.background_task import background_task @@ -89,10 +89,10 @@ def _test(): @pytest.mark.parametrize("distributed_tracing,span_events", ((True, True), (True, False), (False, False))) -def test_httplib2_cross_process_request(distributed_tracing, span_events, server): - @background_task(name="test_httplib2:test_httplib2_cross_process_response") +def test_httplib2_distributed_tracing_request(distributed_tracing, span_events, server): + @background_task(name="test_httplib2:test_httplib2_distributed_tracing_response") @cache_outgoing_headers - @validate_cross_process_headers + @validate_distributed_tracing_headers def _test(): connection = httplib2.HTTPConnectionWithTimeout("localhost", server.port) connection.request("GET", "/") diff --git a/tests/external_httpx/test_client.py b/tests/external_httpx/test_client.py index 4347c49f59..54ae997571 100644 --- a/tests/external_httpx/test_client.py +++ b/tests/external_httpx/test_client.py @@ -17,7 +17,7 @@ import pytest from testing_support.fixtures import dt_enabled, override_application_settings, override_generic_settings from testing_support.mock_external_http_server import MockExternalHTTPHResponseHeadersServer -from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers +from testing_support.validators.validate_distributed_tracing_headers import validate_distributed_tracing_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 @@ -103,7 +103,7 @@ def test_async_client(httpx, async_client, mock_server, loop, method): @pytest.mark.parametrize("distributed_tracing,span_events", ((True, True), (True, False), (False, False))) -def test_sync_cross_process_request(httpx, sync_client, mock_server, distributed_tracing, span_events): +def test_sync_distributed_tracing_request(httpx, sync_client, mock_server, distributed_tracing, span_events): global DT_RESPONSE_CODE DT_RESPONSE_CODE = 200 @@ -111,8 +111,8 @@ def test_sync_cross_process_request(httpx, sync_client, mock_server, distributed {"distributed_tracing.enabled": distributed_tracing, "span_events.enabled": span_events} ) @validate_transaction_errors(errors=[]) - @background_task(name="test_sync_cross_process_request") - @validate_cross_process_headers + @background_task(name="test_sync_distributed_tracing_request") + @validate_distributed_tracing_headers def _test(): transaction = current_transaction() @@ -128,9 +128,9 @@ def _test(): @pytest.mark.parametrize("distributed_tracing,span_events", ((True, True), (True, False), (False, False))) @validate_transaction_errors(errors=[]) -@background_task(name="test_async_cross_process_request") -@validate_cross_process_headers -def test_async_cross_process_request(httpx, async_client, mock_server, loop, distributed_tracing, span_events): +@background_task(name="test_async_distributed_tracing_request") +@validate_distributed_tracing_headers +def test_async_distributed_tracing_request(httpx, async_client, mock_server, loop, distributed_tracing, span_events): global DT_RESPONSE_CODE DT_RESPONSE_CODE = 200 @@ -154,8 +154,8 @@ async def _test(): {"distributed_tracing.enabled": True, "span_events.enabled": True} # , "cross_application_tracer.enabled": True} ) @validate_transaction_errors(errors=[]) -@background_task(name="test_sync_cross_process_override_headers") -def test_sync_cross_process_override_headers(httpx, sync_client, mock_server, loop): +@background_task(name="test_sync_distributed_tracing_override_headers") +def test_sync_distributed_tracing_override_headers(httpx, sync_client, mock_server, loop): global DT_RESPONSE_CODE DT_RESPONSE_CODE = 200 @@ -172,8 +172,8 @@ def test_sync_cross_process_override_headers(httpx, sync_client, mock_server, lo @override_application_settings({"distributed_tracing.enabled": True, "span_events.enabled": True}) @validate_transaction_errors(errors=[]) -@background_task(name="test_async_cross_process_override_headers") -def test_async_cross_process_override_headers(httpx, async_client, mock_server, loop): +@background_task(name="test_async_distributed_tracing_override_headers") +def test_async_distributed_tracing_override_headers(httpx, async_client, mock_server, loop): global DT_RESPONSE_CODE DT_RESPONSE_CODE = 200 diff --git a/tests/external_requests/test_requests.py b/tests/external_requests/test_requests.py index fdd04db775..a5fe242077 100644 --- a/tests/external_requests/test_requests.py +++ b/tests/external_requests/test_requests.py @@ -17,7 +17,7 @@ import requests.exceptions from testing_support.external_fixtures import cache_outgoing_headers from testing_support.fixtures import override_application_settings, validate_tt_parenting -from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers +from testing_support.validators.validate_distributed_tracing_headers import validate_distributed_tracing_headers from testing_support.validators.validate_transaction_errors import validate_transaction_errors from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics @@ -153,11 +153,11 @@ def test_wrong_datatype_url_get(): @pytest.mark.parametrize("distributed_tracing,span_events", ((True, True), (True, False), (False, False))) -def test_requests_cross_process_request(distributed_tracing, span_events, server): +def test_requests_distributed_tracing_request(distributed_tracing, span_events, server): @validate_transaction_errors(errors=[]) - @background_task(name="test_requests:test_requests_cross_process_request") + @background_task(name="test_requests:test_requests_distributed_tracing_request") @cache_outgoing_headers - @validate_cross_process_headers + @validate_distributed_tracing_headers def _test(): requests.get(f"http://localhost:{server.port}/") diff --git a/tests/external_urllib3/test_urllib3.py b/tests/external_urllib3/test_urllib3.py index 106f0b96ab..b098296569 100644 --- a/tests/external_urllib3/test_urllib3.py +++ b/tests/external_urllib3/test_urllib3.py @@ -22,7 +22,7 @@ from testing_support.external_fixtures import cache_outgoing_headers from testing_support.fixtures import override_application_settings -from testing_support.validators.validate_cross_process_headers import validate_cross_process_headers +from testing_support.validators.validate_distributed_tracing_headers import validate_distributed_tracing_headers from testing_support.validators.validate_transaction_errors import validate_transaction_errors from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics @@ -202,11 +202,11 @@ def _test(): @pytest.mark.parametrize("distributed_tracing,span_events", ((True, True), (True, False), (False, False))) -def test_urlopen_cross_process_request(distributed_tracing, span_events, server): +def test_urlopen_distributed_tracing_request(distributed_tracing, span_events, server): @validate_transaction_errors(errors=[]) - @background_task(name="test_urllib3:test_urlopen_cross_process_request") + @background_task(name="test_urllib3:test_urlopen_distributed_tracing_request") @cache_outgoing_headers - @validate_cross_process_headers + @validate_distributed_tracing_headers def _test(): pool = urllib3.HTTPConnectionPool(f"localhost:{server.port}") pool.urlopen("GET", "/") diff --git a/tests/testing_support/validators/validate_cross_process_headers.py b/tests/testing_support/validators/validate_distributed_tracing_headers.py similarity index 93% rename from tests/testing_support/validators/validate_cross_process_headers.py rename to tests/testing_support/validators/validate_distributed_tracing_headers.py index 8b64d5e464..08a75e02a7 100644 --- a/tests/testing_support/validators/validate_cross_process_headers.py +++ b/tests/testing_support/validators/validate_distributed_tracing_headers.py @@ -18,7 +18,7 @@ @function_wrapper -def validate_cross_process_headers(wrapped, instance, args, kwargs): +def validate_distributed_tracing_headers(wrapped, instance, args, kwargs): result = wrapped(*args, **kwargs) transaction = current_transaction() From b0a503220cf59eeca548371a2589d96b827e4e08 Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 24 Sep 2025 12:19:50 -0700 Subject: [PATCH 78/95] Remove cross agent cat fixtures --- tests/cross_agent/fixtures/cat_map.json | 597 ------------------------ 1 file changed, 597 deletions(-) delete mode 100644 tests/cross_agent/fixtures/cat_map.json diff --git a/tests/cross_agent/fixtures/cat_map.json b/tests/cross_agent/fixtures/cat_map.json deleted file mode 100644 index b91265f44f..0000000000 --- a/tests/cross_agent/fixtures/cat_map.json +++ /dev/null @@ -1,597 +0,0 @@ -[ - { - "name": "new_cat", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/testTxnName", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": [ - "b854df4feb2b1f06", - false, - "7e249074f277923d", - "5d2957be" - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "7e249074f277923d", - "nr.pathHash": "815b96d3", - "nr.referringTransactionGuid": "b854df4feb2b1f06", - "nr.referringPathHash": "5d2957be" - }, - "nonExpectedIntrinsicFields": [ - "nr.alternatePathHashes" - ] - }, - { - "name": "new_cat_path_hash_with_leading_zero", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/txn4", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": [ - "b854df4feb2b1f06", - false, - "7e249074f277923d", - "5d2957be" - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "7e249074f277923d", - "nr.pathHash": "0e258e4e", - "nr.referringTransactionGuid": "b854df4feb2b1f06", - "nr.referringPathHash": "5d2957be" - }, - "nonExpectedIntrinsicFields": [ - "nr.alternatePathHashes" - ] - }, - { - "name": "new_cat_path_hash_with_unicode_name", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/txn\u221a\u221a\u221a", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": [ - "b854df4feb2b1f06", - false, - "7e249074f277923d", - "5d2957be" - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "7e249074f277923d", - "nr.pathHash": "3d015d23", - "nr.referringTransactionGuid": "b854df4feb2b1f06", - "nr.referringPathHash": "5d2957be" - }, - "nonExpectedIntrinsicFields": [ - "nr.alternatePathHashes" - ] - }, - { - "name": "new_cat_no_referring_payload", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/testTxnName", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": null, - "expectedIntrinsicFields": {}, - "nonExpectedIntrinsicFields": [ - "nr.guid", - "nr.tripId", - "nr.pathHash", - "nr.referringTransactionGuid", - "nr.referringPathHash", - "nr.alternatePathHashes" - ] - }, - { - "name": "new_cat_with_call_out", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/testTxnName", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": null, - "outboundRequests": [ - { - "outboundTxnName": "WebTransaction/Custom/testTxnName", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "3b0939af" - ] - } - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "9323dc260548ed0e", - "nr.pathHash": "3b0939af" - }, - "nonExpectedIntrinsicFields": [ - "nr.referringTransactionGuid", - "nr.referringPathHash", - "nr.alternatePathHashes" - ] - }, - { - "name": "new_cat_with_multiple_calls_out", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/testTxnName", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": null, - "outboundRequests": [ - { - "outboundTxnName": "WebTransaction/Custom/otherTxnName", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "f1c8adf5" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/otherTxnName", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "f1c8adf5" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/moreOtherTxnName", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "ea19b61c" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/moreDifferentTxnName", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "e00736cc" - ] - } - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "9323dc260548ed0e", - "nr.pathHash": "3b0939af", - "nr.alternatePathHashes": "e00736cc,ea19b61c,f1c8adf5" - }, - "nonExpectedIntrinsicFields": [ - "nr.referringTransactionGuid", - "nr.referringPathHash" - ] - }, - { - "name": "new_cat_with_many_unique_calls_out", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/testTxnName", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": null, - "outboundRequests": [ - { - "outboundTxnName": "WebTransaction/Custom/txn1", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "93fb4310" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn2", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "a67c2da4" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn3", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "0d932b2b" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn4", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "b4772132" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn5", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "51a1a337" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn6", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "77b5cb70" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn7", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "8a842c7f" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn8", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "b968edb8" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn9", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "2691f90e" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn10", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "b46aec87" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn11", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "10bb3bf3" - ] - } - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "9323dc260548ed0e", - "nr.pathHash": "3b0939af", - "nr.alternatePathHashes": "0d932b2b,2691f90e,51a1a337,77b5cb70,8a842c7f,93fb4310,a67c2da4,b46aec87,b4772132,b968edb8" - }, - "nonExpectedIntrinsicFields": [ - "nr.referringTransactionGuid", - "nr.referringPathHash" - ] - }, - { - "name": "new_cat_with_many_calls_out", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/testTxnName", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": null, - "outboundRequests": [ - { - "outboundTxnName": "WebTransaction/Custom/txn1", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "93fb4310" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn1", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "93fb4310" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn1", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "93fb4310" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn1", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "93fb4310" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn1", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "93fb4310" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn1", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "93fb4310" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn1", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "93fb4310" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn1", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "93fb4310" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn1", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "93fb4310" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn1", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "93fb4310" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn1", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "93fb4310" - ] - }, - { - "outboundTxnName": "WebTransaction/Custom/txn2", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "9323dc260548ed0e", - "a67c2da4" - ] - } - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "9323dc260548ed0e", - "nr.pathHash": "3b0939af", - "nr.alternatePathHashes": "93fb4310,a67c2da4" - }, - "nonExpectedIntrinsicFields": [ - "nr.referringTransactionGuid", - "nr.referringPathHash" - ] - }, - { - "name": "new_cat_with_referring_info_and_call_out", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/testTxnName", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": [ - "b854df4feb2b1f06", - false, - "7e249074f277923d", - "5d2957be" - ], - "outboundRequests": [ - { - "outboundTxnName": "WebTransaction/Custom/otherTxnName", - "expectedOutboundPayload": [ - "9323dc260548ed0e", - false, - "7e249074f277923d", - "4b9a0289" - ] - } - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "7e249074f277923d", - "nr.pathHash": "815b96d3", - "nr.alternatePathHashes": "4b9a0289", - "nr.referringTransactionGuid": "b854df4feb2b1f06", - "nr.referringPathHash": "5d2957be" - }, - "nonExpectedIntrinsicFields": [] - }, - { - "name": "new_cat_missing_path_hash", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/testTxnName", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": [ - "b854df4feb2b1f06", - false, - "7e249074f277923d" - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "7e249074f277923d", - "nr.pathHash": "3b0939af", - "nr.referringTransactionGuid": "b854df4feb2b1f06" - }, - "nonExpectedIntrinsicFields": [ - "nr.alternatePathHashes", - "nr.referringPathHash" - ] - }, - { - "name": "new_cat_null_path_hash", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/testTxnName", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": [ - "b854df4feb2b1f06", - false, - "7e249074f277923d", - null - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "7e249074f277923d", - "nr.pathHash": "3b0939af", - "nr.referringTransactionGuid": "b854df4feb2b1f06" - }, - "nonExpectedIntrinsicFields": [ - "nr.alternatePathHashes", - "nr.referringPathHash" - ] - }, - { - "name": "new_cat_malformed_path_hash", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/testTxnName", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": [ - "b854df4feb2b1f06", - false, - "7e249074f277923d", - [ - "scrambled", - "eggs" - ] - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "7e249074f277923d", - "nr.pathHash": "3b0939af", - "nr.referringTransactionGuid": "b854df4feb2b1f06" - }, - "nonExpectedIntrinsicFields": [ - "nr.alternatePathHashes", - "nr.referringPathHash" - ] - }, - { - "name": "new_cat_corrupt_path_hash", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/testTxnName", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": [ - "b854df4feb2b1f06", - false, - "7e249074f277923d", - "ZXYQEDABC" - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "7e249074f277923d", - "nr.pathHash": "3b0939af", - "nr.referringTransactionGuid": "b854df4feb2b1f06", - "nr.referringPathHash": "ZXYQEDABC" - }, - "nonExpectedIntrinsicFields": [ - "nr.alternatePathHashes" - ] - }, - { - "name": "new_cat_malformed_trip_id", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/testTxnName", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": [ - "b854df4feb2b1f06", - false, - ["scrambled"], - "5d2957be" - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "9323dc260548ed0e", - "nr.pathHash": "815b96d3", - "nr.referringTransactionGuid": "b854df4feb2b1f06", - "nr.referringPathHash": "5d2957be" - }, - "nonExpectedIntrinsicFields": [ - "nr.alternatePathHashes" - ] - }, - { - "name": "new_cat_missing_trip_id", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/testTxnName", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": [ - "b854df4feb2b1f06", - false - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "9323dc260548ed0e", - "nr.pathHash": "3b0939af", - "nr.referringTransactionGuid": "b854df4feb2b1f06" - }, - "nonExpectedIntrinsicFields": [ - "nr.referringPathHash", - "nr.alternatePathHashes" - ] - }, - { - "name": "new_cat_null_trip_id", - "appName": "testAppName", - "transactionName": "WebTransaction/Custom/testTxnName", - "transactionGuid": "9323dc260548ed0e", - "inboundPayload": [ - "b854df4feb2b1f06", - false, - null - ], - "expectedIntrinsicFields": { - "nr.guid": "9323dc260548ed0e", - "nr.tripId": "9323dc260548ed0e", - "nr.pathHash": "3b0939af", - "nr.referringTransactionGuid": "b854df4feb2b1f06" - }, - "nonExpectedIntrinsicFields": [ - "nr.alternatePathHashes", - "nr.referringPathHash" - ] - } -] From 1a42b17e1374d36aa9259e7b6b87f2ec84e600ba Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 24 Sep 2025 12:23:54 -0700 Subject: [PATCH 79/95] Add back tenr.apdexPerfZone as not CAT specific --- newrelic/core/transaction_node.py | 1 + tests/agent_features/test_attributes_in_action.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/newrelic/core/transaction_node.py b/newrelic/core/transaction_node.py index d125c36369..ed12a4e9a8 100644 --- a/newrelic/core/transaction_node.py +++ b/newrelic/core/transaction_node.py @@ -458,6 +458,7 @@ def _add_if_not_empty(key, value): apdex_perf_zone = self.apdex_perf_zone() _add_if_not_empty("apdexPerfZone", apdex_perf_zone) + _add_if_not_empty("nr.apdexPerfZone", apdex_perf_zone) if self.errors: intrinsics["error"] = True diff --git a/tests/agent_features/test_attributes_in_action.py b/tests/agent_features/test_attributes_in_action.py index 3981ef0cd9..da3768aaaa 100644 --- a/tests/agent_features/test_attributes_in_action.py +++ b/tests/agent_features/test_attributes_in_action.py @@ -88,7 +88,16 @@ AGENT_KEYS_ALL = TRACE_ERROR_AGENT_KEYS + REQ_PARAMS -TRANS_EVENT_INTRINSICS = ("name", "duration", "type", "timestamp", "totalTime", "error", "apdexPerfZone") +TRANS_EVENT_INTRINSICS = ( + "name", + "duration", + "type", + "timestamp", + "totalTime", + "error", + "nr.apdexPerfZone", + "apdexPerfZone", +) TRANS_EVENT_AGENT_KEYS = [ "response.status", "request.method", From 58b748b385c014e9ff168fc54411ebe9e8902bd8 Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 24 Sep 2025 12:27:28 -0700 Subject: [PATCH 80/95] Remove distributed_trace_key from header mixin --- newrelic/api/header_mixin.py | 1 - newrelic/hooks/messagebroker_pika.py | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/newrelic/api/header_mixin.py b/newrelic/api/header_mixin.py index 22d7299be9..0fdf777735 100644 --- a/newrelic/api/header_mixin.py +++ b/newrelic/api/header_mixin.py @@ -17,7 +17,6 @@ class HeaderMixin: synthetics_key = "X-NewRelic-Synthetics" synthetics_info_key = "X-NewRelic-Synthetics-Info" - distributed_trace_key = "newrelic" settings = None def __enter__(self): diff --git a/newrelic/hooks/messagebroker_pika.py b/newrelic/hooks/messagebroker_pika.py index df7ae01f9e..d246d2c46f 100644 --- a/newrelic/hooks/messagebroker_pika.py +++ b/newrelic/hooks/messagebroker_pika.py @@ -62,7 +62,7 @@ def _add_consume_rabbitmq_trace(transaction, method, properties, nr_start_time, # Do not record dt headers in the segment parameters if headers: - headers.pop(MessageTrace.distributed_trace_key, None) + headers.pop("newrelic", None) headers.pop("traceparent", None) headers.pop("tracestate", None) @@ -122,7 +122,7 @@ def _nr_wrapper_basic_publish(wrapped, instance, args, kwargs): user_headers = properties.headers.copy() # Do not record dt headers in the segment parameters - user_headers.pop(MessageTrace.distributed_trace_key, None) + user_headers.pop("newrelic", None) user_headers.pop("traceparent", None) user_headers.pop("tracestate", None) From 46180584596c127e142abb1f404ab2978bb03834 Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 24 Sep 2025 12:28:47 -0700 Subject: [PATCH 81/95] Remove config instead of commenting out --- newrelic/config.py | 1 - 1 file changed, 1 deletion(-) diff --git a/newrelic/config.py b/newrelic/config.py index 024c97b3a1..50609186d5 100644 --- a/newrelic/config.py +++ b/newrelic/config.py @@ -453,7 +453,6 @@ def _process_configuration(section): _process_setting(section, "debug.disable_harvest_until_shutdown", "getboolean", None) _process_setting(section, "debug.connect_span_stream_in_developer_mode", "getboolean", None) _process_setting(section, "debug.otlp_content_encoding", "get", None) - # _process_setting(section, "cross_application_tracer.enabled", "getboolean", None) _process_setting(section, "message_tracer.segment_parameters_enabled", "getboolean", None) _process_setting(section, "process_host.display_name", "get", None) _process_setting(section, "utilization.detect_aws", "getboolean", None) From 0175faa10c7ce42c9a37de2859511713ec1061cf Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 24 Sep 2025 12:31:15 -0700 Subject: [PATCH 82/95] Put back transactionGuid --- newrelic/core/transaction_node.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/newrelic/core/transaction_node.py b/newrelic/core/transaction_node.py index ed12a4e9a8..3824de9d00 100644 --- a/newrelic/core/transaction_node.py +++ b/newrelic/core/transaction_node.py @@ -522,6 +522,8 @@ def error_event_intrinsics(self, error, stats_table): intrinsics["transactionName"] = self.path intrinsics["spanId"] = error.span_id + intrinsics["nr.transactionGuid"] = self.guid + return intrinsics def _event_intrinsics(self, stats_table): From dd197f10bf96d624f72f1d2c1dfa313775087498 Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 24 Sep 2025 14:11:08 -0700 Subject: [PATCH 83/95] Return None in process_response --- newrelic/api/web_transaction.py | 6 ++-- newrelic/api/wsgi_application.py | 4 +-- newrelic/hooks/framework_aiohttp.py | 51 +++-------------------------- newrelic/hooks/framework_sanic.py | 21 ++---------- newrelic/hooks/framework_tornado.py | 5 +-- 5 files changed, 13 insertions(+), 74 deletions(-) diff --git a/newrelic/api/web_transaction.py b/newrelic/api/web_transaction.py index 71843c214c..4de3bf7c86 100644 --- a/newrelic/api/web_transaction.py +++ b/newrelic/api/web_transaction.py @@ -309,7 +309,7 @@ def process_response(self, status_code, response_headers): """ if not self.enabled: - return [] + return # Extract response headers if response_headers: @@ -329,11 +329,11 @@ def process_response(self, status_code, response_headers): # If response code is 304 do not insert CAT headers. See: # https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5 if self._response_code == 304: - return [] + return None except Exception: pass - return [] + return None def _update_agent_attributes(self): if "accept" in self._request_headers: diff --git a/newrelic/api/wsgi_application.py b/newrelic/api/wsgi_application.py index 2749be9ab5..e0cefc0bef 100644 --- a/newrelic/api/wsgi_application.py +++ b/newrelic/api/wsgi_application.py @@ -634,9 +634,9 @@ def _args(environ, start_response, *args, **kwargs): transaction.set_transaction_name(name, group, priority=1) def _start_response(status, response_headers, *args): - additional_headers = transaction.process_response(status, response_headers, *args) + transaction.process_response(status, response_headers, *args) - _write = start_response(status, response_headers + additional_headers, *args) + _write = start_response(status, response_headers, *args) def write(data): if not transaction._sent_start: diff --git a/newrelic/hooks/framework_aiohttp.py b/newrelic/hooks/framework_aiohttp.py index da0b0029a5..8819dea8f5 100644 --- a/newrelic/hooks/framework_aiohttp.py +++ b/newrelic/hooks/framework_aiohttp.py @@ -17,7 +17,6 @@ from newrelic.api.external_trace import ExternalTrace from newrelic.api.function_trace import function_trace -from newrelic.api.time_trace import notice_error from newrelic.api.transaction import current_transaction, ignore_transaction from newrelic.api.web_transaction import web_transaction from newrelic.common.async_wrapper import async_wrapper, is_coroutine_callable @@ -60,16 +59,8 @@ def _is_expected(exc, value, tb): return _is_expected -def _nr_process_response_proxy(response, transaction): - nr_headers = transaction.process_response(response.status, response.headers) - - response._headers = HeaderProxy(response.headers, nr_headers) - - def _nr_process_response(response, transaction): - nr_headers = transaction.process_response(response.status, response.headers) - - response._headers.update(nr_headers) + transaction.process_response(response.status, response.headers) @function_wrapper @@ -146,20 +137,6 @@ def __getattr__(self, name): return result -def _nr_aiohttp_response_prepare_(wrapped, instance, args, kwargs): - def _bind_params(request): - return request - - request = _bind_params(*args, **kwargs) - - nr_headers = getattr(request, "_nr_headers", None) - if nr_headers: - nr_headers.update(instance.headers) - instance._headers = nr_headers - - return wrapped(*args, **kwargs) - - @function_wrapper def _nr_aiohttp_wrap_middleware_(wrapped, instance, args, kwargs): async def _inner(): @@ -262,24 +239,8 @@ def _nr_aiohttp_request_wrapper_(wrapped, instance, args, kwargs): return wrapped(*args, **kwargs) method, url = _bind_request(*args, **kwargs) - trace = ExternalTrace("aiohttp", str(url), method) - - async def _coro(): - try: - response = await wrapped(*args, **kwargs) - - try: - trace.process_response(status_code=response.status) - except: - pass - - return response - except Exception: - notice_error() - - raise - - return async_wrapper(wrapped)(_coro, trace)() + with ExternalTrace("aiohttp", str(url), method): + return await wrapped(*args, **kwargs)) def instrument_aiohttp_client(module): @@ -346,8 +307,7 @@ async def _coro(*_args, **_kwargs): _nr_process_response(e, transaction) raise except Exception: - nr_headers = transaction.process_response(500, ()) - request._nr_headers = dict(nr_headers) + transaction.process_response(500, ()) raise _nr_process_response(response, transaction) @@ -371,6 +331,3 @@ def instrument_aiohttp_web(module): def instrument_aiohttp_wsgi(module): wrap_function_wrapper(module, "WsgiResponse.__init__", _nr_aiohttp_wrap_wsgi_response_) - -def instrument_aiohttp_web_response(module): - wrap_function_wrapper(module, "Response.prepare", _nr_aiohttp_response_prepare_) diff --git a/newrelic/hooks/framework_sanic.py b/newrelic/hooks/framework_sanic.py index a201cba5a0..3738bd6180 100644 --- a/newrelic/hooks/framework_sanic.py +++ b/newrelic/hooks/framework_sanic.py @@ -170,12 +170,7 @@ def _nr_sanic_response_get_headers(wrapped, instance, args, kwargs): return result # instance is the response object - dt_headers = transaction.process_response(str(instance.status), instance.headers.items()) - - for header_name, header_value in dt_headers: - if header_name not in instance.headers: - instance.headers[header_name] = header_value - + transaction.process_response(str(instance.status), instance.headers.items()) return wrapped(*args, **kwargs) @@ -189,12 +184,7 @@ async def _nr_sanic_response_send(wrapped, instance, args, kwargs): return result # instance is the response object - dt_headers = transaction.process_response(str(instance.status), instance.headers.items()) - - for header_name, header_value in dt_headers: - if header_name not in instance.headers: - instance.headers[header_name] = header_value - + transaction.process_response(str(instance.status), instance.headers.items()) return result @@ -205,12 +195,7 @@ def _nr_sanic_response_parse_headers(wrapped, instance, args, kwargs): return wrapped(*args, **kwargs) # instance is the response object - dt_headers = transaction.process_response(str(instance.status), instance.headers.items()) - - for header_name, header_value in dt_headers: - if header_name not in instance.headers: - instance.headers[header_name] = header_value - + transaction.process_response(str(instance.status), instance.headers.items()) return wrapped(*args, **kwargs) diff --git a/newrelic/hooks/framework_tornado.py b/newrelic/hooks/framework_tornado.py index 7682bec75f..792d254803 100644 --- a/newrelic/hooks/framework_tornado.py +++ b/newrelic/hooks/framework_tornado.py @@ -132,10 +132,7 @@ def wrap_write_headers(wrapped, instance, args, kwargs): if transaction: http_status, headers = _bind_response_headers(*args, **kwargs) - dt_headers = transaction.process_response(http_status, headers) - - for name, value in dt_headers: - headers.add(name, value) + transaction.process_response(http_status, headers) return wrapped(*args, **kwargs) From 088a9ffcdf775325530bea978b1a054c290596eb Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 24 Sep 2025 12:55:01 -0700 Subject: [PATCH 84/95] Still pass settings into finalize application settings call --- newrelic/core/agent_protocol.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/newrelic/core/agent_protocol.py b/newrelic/core/agent_protocol.py index 347bdf5e2a..3544fd0032 100644 --- a/newrelic/core/agent_protocol.py +++ b/newrelic/core/agent_protocol.py @@ -522,7 +522,7 @@ def finalize(self): @classmethod def connect(cls, app_name, linked_applications, environment, settings, client_cls=ServerlessModeClient): aws_lambda_metadata = settings.aws_lambda_metadata - settings = finalize_application_settings() + settings = finalize_application_settings(settings=settings) # Metadata must come from the original settings object since it # can be modified later settings.aws_lambda_metadata = aws_lambda_metadata From 05fc6ea6da69a422fbf5963393bd666d77312c5c Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 24 Sep 2025 14:28:50 -0700 Subject: [PATCH 85/95] DT_RESPONSE_CODE->RESPONSE_CODE --- tests/external_httpx/test_client.py | 64 ++++++++++++++--------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/tests/external_httpx/test_client.py b/tests/external_httpx/test_client.py index 54ae997571..994f1360b4 100644 --- a/tests/external_httpx/test_client.py +++ b/tests/external_httpx/test_client.py @@ -30,15 +30,15 @@ SCOPED_METRICS = [] ROLLUP_METRICS = [("External/all", 2), ("External/allOther", 2)] -DT_RESPONSE_CODE = None +RESPONSE_CODE = None def dt_response_handler(self): - if not DT_RESPONSE_CODE: - raise ValueError("DT_RESPONSE_CODE must be a valid status_code.") + if not RESPONSE_CODE: + raise ValueError("RESPONSE_CODE must be a valid status_code.") response = str(self.headers).encode("utf-8") # Might need to put headers here - self.send_response(DT_RESPONSE_CODE) + self.send_response(RESPONSE_CODE) self.end_headers() self.wfile.write(response) @@ -72,8 +72,8 @@ def exercise_sync_client(server, client, method, protocol="http"): ) @background_task(name="test_sync_client") def test_sync_client(httpx, sync_client, mock_server, method): - global DT_RESPONSE_CODE - DT_RESPONSE_CODE = 200 + global RESPONSE_CODE + RESPONSE_CODE = 200 assert exercise_sync_client(mock_server, sync_client, method).status_code == 200 @@ -95,8 +95,8 @@ async def exercise_async_client(server, client, method, protocol="http"): ) @background_task(name="test_async_client") def test_async_client(httpx, async_client, mock_server, loop, method): - global DT_RESPONSE_CODE - DT_RESPONSE_CODE = 200 + global RESPONSE_CODE + RESPONSE_CODE = 200 responses = loop.run_until_complete(exercise_async_client(mock_server, async_client, method)) assert all(response.status_code == 200 for response in responses) @@ -104,8 +104,8 @@ def test_async_client(httpx, async_client, mock_server, loop, method): @pytest.mark.parametrize("distributed_tracing,span_events", ((True, True), (True, False), (False, False))) def test_sync_distributed_tracing_request(httpx, sync_client, mock_server, distributed_tracing, span_events): - global DT_RESPONSE_CODE - DT_RESPONSE_CODE = 200 + global RESPONSE_CODE + RESPONSE_CODE = 200 @override_application_settings( {"distributed_tracing.enabled": distributed_tracing, "span_events.enabled": span_events} @@ -131,8 +131,8 @@ def _test(): @background_task(name="test_async_distributed_tracing_request") @validate_distributed_tracing_headers def test_async_distributed_tracing_request(httpx, async_client, mock_server, loop, distributed_tracing, span_events): - global DT_RESPONSE_CODE - DT_RESPONSE_CODE = 200 + global RESPONSE_CODE + RESPONSE_CODE = 200 @override_application_settings( {"distributed_tracing.enabled": distributed_tracing, "span_events.enabled": span_events} @@ -156,8 +156,8 @@ async def _test(): @validate_transaction_errors(errors=[]) @background_task(name="test_sync_distributed_tracing_override_headers") def test_sync_distributed_tracing_override_headers(httpx, sync_client, mock_server, loop): - global DT_RESPONSE_CODE - DT_RESPONSE_CODE = 200 + global RESPONSE_CODE + RESPONSE_CODE = 200 transaction = current_transaction() @@ -174,8 +174,8 @@ def test_sync_distributed_tracing_override_headers(httpx, sync_client, mock_serv @validate_transaction_errors(errors=[]) @background_task(name="test_async_distributed_tracing_override_headers") def test_async_distributed_tracing_override_headers(httpx, async_client, mock_server, loop): - global DT_RESPONSE_CODE - DT_RESPONSE_CODE = 200 + global RESPONSE_CODE + RESPONSE_CODE = 200 async def _test(): async with async_client: @@ -191,8 +191,8 @@ async def _test(): @dt_enabled def test_sync_client_event_hook_exception(httpx, mock_server): - global DT_RESPONSE_CODE - DT_RESPONSE_CODE = 500 + global RESPONSE_CODE + RESPONSE_CODE = 500 def exception_event_hook(response): if response.status_code >= 400: @@ -204,7 +204,7 @@ def empty_hook(response): @validate_span_events( count=1, exact_intrinsics={"name": f"External/localhost:{mock_server.port}/httpx/GET"}, - exact_agents={"http.statusCode": DT_RESPONSE_CODE}, + exact_agents={"http.statusCode": RESPONSE_CODE}, ) @background_task(name="test_sync_client_event_hook_exception") def make_request(client, exc_expected=True): @@ -237,8 +237,8 @@ def make_request(client, exc_expected=True): @override_application_settings({"distributed_tracing.enabled": True, "span_events.enabled": True}) def test_async_client_event_hook_exception(httpx, mock_server, loop): - global DT_RESPONSE_CODE - DT_RESPONSE_CODE = 500 + global RESPONSE_CODE + RESPONSE_CODE = 500 def exception_event_hook(response): if response.status_code >= 400: @@ -250,7 +250,7 @@ def empty_hook(response): @validate_span_events( count=1, exact_intrinsics={"name": f"External/localhost:{mock_server.port}/httpx/GET"}, - exact_agents={"http.statusCode": DT_RESPONSE_CODE}, + exact_agents={"http.statusCode": RESPONSE_CODE}, ) @background_task(name="test_sync_client_event_hook_exception") def make_request(client, exc_expected=True): @@ -287,8 +287,8 @@ def _test(): @override_generic_settings(global_settings(), {"enabled": False}) def test_sync_nr_disabled(httpx, mock_server): - global DT_RESPONSE_CODE - DT_RESPONSE_CODE = 200 + global RESPONSE_CODE + RESPONSE_CODE = 200 with httpx.Client() as client: trace = current_trace() @@ -300,8 +300,8 @@ def test_sync_nr_disabled(httpx, mock_server): @override_generic_settings(global_settings(), {"enabled": False}) def test_async_nr_disabled(httpx, mock_server, loop): - global DT_RESPONSE_CODE - DT_RESPONSE_CODE = 200 + global RESPONSE_CODE + RESPONSE_CODE = 200 async def _test(): async with httpx.AsyncClient() as client: @@ -317,8 +317,8 @@ async def _test(): @pytest.mark.parametrize("client", ("Client", "AsyncClient")) def test_invalid_import_order_client(monkeypatch, httpx, mock_server, loop, client): - global DT_RESPONSE_CODE - DT_RESPONSE_CODE = 200 + global RESPONSE_CODE + RESPONSE_CODE = 200 if "Async" in client: is_async = True @@ -349,8 +349,8 @@ def test_invalid_import_order_client(monkeypatch, httpx, mock_server, loop, clie ) @background_task(name="test_sync_client_http2") def test_sync_client_http2(httpx, real_server): - global DT_RESPONSE_CODE - DT_RESPONSE_CODE = 200 + global RESPONSE_CODE + RESPONSE_CODE = 200 client = httpx.Client(http1=False, http2=True, verify=False) response = exercise_sync_client(real_server, client, "get", protocol="https") @@ -364,8 +364,8 @@ def test_sync_client_http2(httpx, real_server): ) @background_task(name="test_async_client_http2") def test_async_client_http2(httpx, real_server, loop): - global DT_RESPONSE_CODE - DT_RESPONSE_CODE = 200 + global RESPONSE_CODE + RESPONSE_CODE = 200 client = httpx.AsyncClient(http1=False, http2=True, verify=False) From 2821057cda4e8909e55ad20f065cacd6e7a69a71 Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 24 Sep 2025 14:32:29 -0700 Subject: [PATCH 86/95] respond_with_dt_header->response_handler --- tests/framework_aiohttp/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/framework_aiohttp/conftest.py b/tests/framework_aiohttp/conftest.py index 1cdf4c607a..108778b44b 100644 --- a/tests/framework_aiohttp/conftest.py +++ b/tests/framework_aiohttp/conftest.py @@ -115,7 +115,7 @@ def handler(self): def mock_external_http_server(): response_values = [] - def respond_with_dt_header(self): + def response_handler(self): headers, response_code = response_values.pop() self.send_response(response_code) for header, value in headers: @@ -123,7 +123,7 @@ def respond_with_dt_header(self): self.end_headers() self.wfile.write(b"") - with MockExternalHTTPServer(handler=respond_with_dt_header) as server: + with MockExternalHTTPServer(handler=response_handler) as server: yield (server, response_values) From 500e2d0d16fd6cafb4ab08cde411c03c6e5ee70f Mon Sep 17 00:00:00 2001 From: Timothy Pansino <11214426+TimPansino@users.noreply.github.com> Date: Wed, 24 Sep 2025 14:30:18 -0700 Subject: [PATCH 87/95] Move codecov.yml file to .github folder (#1516) --- codecov.yml => .github/codecov.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename codecov.yml => .github/codecov.yml (100%) diff --git a/codecov.yml b/.github/codecov.yml similarity index 100% rename from codecov.yml rename to .github/codecov.yml From 58b1f12dcfb0e0ceefdcff90f347e9ef920e5c73 Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 24 Sep 2025 14:36:22 -0700 Subject: [PATCH 88/95] Fixup: syntax error --- newrelic/hooks/framework_aiohttp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/newrelic/hooks/framework_aiohttp.py b/newrelic/hooks/framework_aiohttp.py index 8819dea8f5..ee70aa258d 100644 --- a/newrelic/hooks/framework_aiohttp.py +++ b/newrelic/hooks/framework_aiohttp.py @@ -240,7 +240,7 @@ def _nr_aiohttp_request_wrapper_(wrapped, instance, args, kwargs): method, url = _bind_request(*args, **kwargs) with ExternalTrace("aiohttp", str(url), method): - return await wrapped(*args, **kwargs)) + return await wrapped(*args, **kwargs) def instrument_aiohttp_client(module): From 6e5cb42eab0d028e7ea91290b7e4d15e9e7f3fb0 Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 24 Sep 2025 14:41:34 -0700 Subject: [PATCH 89/95] Put back nr.guid if synthetics resource id --- newrelic/core/transaction_node.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/newrelic/core/transaction_node.py b/newrelic/core/transaction_node.py index 3824de9d00..11740465e3 100644 --- a/newrelic/core/transaction_node.py +++ b/newrelic/core/transaction_node.py @@ -463,6 +463,8 @@ def _add_if_not_empty(key, value): if self.errors: intrinsics["error"] = True + if self.synthetics_resource_id: + intrinsics["nr.guid"] = self.guid if self.parent_tx: intrinsics["parentId"] = self.parent_tx From f0677f643323d770a947ec2072c1d403f333e2e9 Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 24 Sep 2025 15:03:26 -0700 Subject: [PATCH 90/95] Trigger tests From a0879f50be2f589fc185ca5593e8983690d17260 Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 24 Sep 2025 15:43:44 -0700 Subject: [PATCH 91/95] Remove corresponding config call --- newrelic/config.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/newrelic/config.py b/newrelic/config.py index 50609186d5..e8d4d7d560 100644 --- a/newrelic/config.py +++ b/newrelic/config.py @@ -2997,12 +2997,6 @@ def _process_module_builtin_defaults(): _process_module_definition("aiohttp.wsgi", "newrelic.hooks.framework_aiohttp", "instrument_aiohttp_wsgi") _process_module_definition("aiohttp.web", "newrelic.hooks.framework_aiohttp", "instrument_aiohttp_web") - _process_module_definition( - "aiohttp.web_reqrep", "newrelic.hooks.framework_aiohttp", "instrument_aiohttp_web_response" - ) - _process_module_definition( - "aiohttp.web_response", "newrelic.hooks.framework_aiohttp", "instrument_aiohttp_web_response" - ) _process_module_definition( "aiohttp.web_urldispatcher", "newrelic.hooks.framework_aiohttp", "instrument_aiohttp_web_urldispatcher" ) From 144e52ecb3e392daf6e4b5b6a6b51da64fe20158 Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 24 Sep 2025 15:46:20 -0700 Subject: [PATCH 92/95] Fixup: spacing --- newrelic/hooks/framework_aiohttp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/newrelic/hooks/framework_aiohttp.py b/newrelic/hooks/framework_aiohttp.py index ee70aa258d..6ec13b0178 100644 --- a/newrelic/hooks/framework_aiohttp.py +++ b/newrelic/hooks/framework_aiohttp.py @@ -240,7 +240,7 @@ def _nr_aiohttp_request_wrapper_(wrapped, instance, args, kwargs): method, url = _bind_request(*args, **kwargs) with ExternalTrace("aiohttp", str(url), method): - return await wrapped(*args, **kwargs) + return await wrapped(*args, **kwargs) def instrument_aiohttp_client(module): From 1812a9eae621697d4c2773a5fa44b0524322c7c0 Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 24 Sep 2025 16:13:16 -0700 Subject: [PATCH 93/95] Fixup --- newrelic/hooks/framework_aiohttp.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/newrelic/hooks/framework_aiohttp.py b/newrelic/hooks/framework_aiohttp.py index 6ec13b0178..37b88e3b7b 100644 --- a/newrelic/hooks/framework_aiohttp.py +++ b/newrelic/hooks/framework_aiohttp.py @@ -239,8 +239,9 @@ def _nr_aiohttp_request_wrapper_(wrapped, instance, args, kwargs): return wrapped(*args, **kwargs) method, url = _bind_request(*args, **kwargs) - with ExternalTrace("aiohttp", str(url), method): - return await wrapped(*args, **kwargs) + trace = ExternalTrace("aiohttp", str(url), method) + with trace: + return wrapped(*args, **kwargs) def instrument_aiohttp_client(module): @@ -251,9 +252,7 @@ def instrument_aiohttp_client_reqrep(module): version_info = aiohttp_version_info() if version_info >= (2, 0): - dt_wrapper = _nr_aiohttp_add_dt_headers_simple_ - - wrap_function_wrapper(module, "ClientRequest.send", dt_wrapper) + wrap_function_wrapper(module, "ClientRequest.send", _nr_aiohttp_add_dt_headers_simple_) def instrument_aiohttp_protocol(module): From 9e94916c039a81a69605902c0fefb53f0bc0cbd1 Mon Sep 17 00:00:00 2001 From: Hannah Stepanek Date: Wed, 24 Sep 2025 16:18:27 -0700 Subject: [PATCH 94/95] Trigger tests From 2882b03f8e3f3e095b2c08e80ee8fe34f4f70a28 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 25 Sep 2025 19:12:06 +0000 Subject: [PATCH 95/95] [MegaLinter] Apply linters fixes --- newrelic/hooks/framework_aiohttp.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/newrelic/hooks/framework_aiohttp.py b/newrelic/hooks/framework_aiohttp.py index 37b88e3b7b..05db1d9d76 100644 --- a/newrelic/hooks/framework_aiohttp.py +++ b/newrelic/hooks/framework_aiohttp.py @@ -19,7 +19,7 @@ from newrelic.api.function_trace import function_trace from newrelic.api.transaction import current_transaction, ignore_transaction from newrelic.api.web_transaction import web_transaction -from newrelic.common.async_wrapper import async_wrapper, is_coroutine_callable +from newrelic.common.async_wrapper import is_coroutine_callable from newrelic.common.object_names import callable_name from newrelic.common.object_wrapper import ObjectProxy, function_wrapper, wrap_function_wrapper from newrelic.core.config import is_expected_error, should_ignore_error @@ -329,4 +329,3 @@ def instrument_aiohttp_web(module): def instrument_aiohttp_wsgi(module): wrap_function_wrapper(module, "WsgiResponse.__init__", _nr_aiohttp_wrap_wsgi_response_) -