From 807ec1c5c40fe421300ccdcd6fedd81f288dce2c Mon Sep 17 00:00:00 2001 From: Lalleh Rafeei Date: Wed, 12 Oct 2022 13:44:29 -0700 Subject: [PATCH] Fix more pylint errors --- newrelic/admin/validate_config.py | 2 +- newrelic/api/transaction.py | 15 ++++++++------- newrelic/core/attribute.py | 14 ++++++-------- tests/agent_features/test_span_events.py | 9 +++++---- tests/testing_support/sample_asgi_applications.py | 4 ++-- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/newrelic/admin/validate_config.py b/newrelic/admin/validate_config.py index ac25b715e1..52b73110f1 100644 --- a/newrelic/admin/validate_config.py +++ b/newrelic/admin/validate_config.py @@ -212,7 +212,7 @@ def validate_config(args): if not _application.active: _logger.error( - "Unable to register application for test, " "connection could not be established within %s seconds.", + "Unable to register application for test, connection could not be established within %s seconds.", _timeout, ) return diff --git a/newrelic/api/transaction.py b/newrelic/api/transaction.py index d828535b98..6177d401cd 100644 --- a/newrelic/api/transaction.py +++ b/newrelic/api/transaction.py @@ -26,7 +26,6 @@ from collections import OrderedDict import newrelic.core.database_node -import newrelic.core.error_node import newrelic.core.root_node import newrelic.core.transaction_node from newrelic.api.application import application_instance @@ -61,6 +60,7 @@ ) from newrelic.core.config import DEFAULT_RESERVOIR_SIZE, LOG_EVENT_RESERVOIR_SIZE from newrelic.core.custom_event import create_custom_event +from newrelic.core.error_node import ErrorNode from newrelic.core.log_event_node import LogEventNode from newrelic.core.stack_trace import exception_stack from newrelic.core.stats_engine import CustomMetrics, SampledDataSet @@ -1558,7 +1558,7 @@ def _create_error_node(self, settings, fullname, message, expected, custom_param if error.type == fullname and error.message == message: return - node = newrelic.core.error_node.ErrorNode( + node = ErrorNode( timestamp=time.time(), type=fullname, message=message, @@ -1609,7 +1609,8 @@ def _process_node(self, node): node.node_count = self._trace_node_count self.total_time += node.exclusive - if type(node) is newrelic.core.database_node.DatabaseNode: + # if type(node) is newrelic.core.database_node.DatabaseNode: + if isinstance(newrelic.core.database_node.DatabaseNode, ErrorNode): settings = self._settings if not settings: return @@ -1675,7 +1676,7 @@ def add_custom_attributes(self, items): def add_custom_parameter(self, name, value): # Deprecation warning warnings.warn( - ("The add_custom_parameter API has been deprecated. " "Please use the add_custom_attribute API."), + ("The add_custom_parameter API has been deprecated. Please use the add_custom_attribute API."), DeprecationWarning, ) return self.add_custom_attribute(name, value) @@ -1683,7 +1684,7 @@ def add_custom_parameter(self, name, value): def add_custom_parameters(self, items): # Deprecation warning warnings.warn( - ("The add_custom_parameters API has been deprecated. " "Please use the add_custom_attributes API."), + ("The add_custom_parameters API has been deprecated. Please use the add_custom_attributes API."), DeprecationWarning, ) return self.add_custom_attributes(items) @@ -1779,7 +1780,7 @@ def add_custom_attributes(items): def add_custom_parameter(key, value): # Deprecation warning warnings.warn( - ("The add_custom_parameter API has been deprecated. " "Please use the add_custom_attribute API."), + ("The add_custom_parameter API has been deprecated. Please use the add_custom_attribute API."), DeprecationWarning, ) return add_custom_attribute(key, value) @@ -1788,7 +1789,7 @@ def add_custom_parameter(key, value): def add_custom_parameters(items): # Deprecation warning warnings.warn( - ("The add_custom_parameter API has been deprecated. " "Please use the add_custom_attribute API."), + ("The add_custom_parameter API has been deprecated. Please use the add_custom_attribute API."), DeprecationWarning, ) return add_custom_attributes(items) diff --git a/newrelic/core/attribute.py b/newrelic/core/attribute.py index c5f19e4c06..e72ab071ec 100644 --- a/newrelic/core/attribute.py +++ b/newrelic/core/attribute.py @@ -243,19 +243,19 @@ def process_user_attribute(name, value, max_length=MAX_ATTRIBUTE_LENGTH, ending= value = sanitize(value) except NameIsNotStringException: - _logger.debug("Attribute name must be a string. Dropping " "attribute: %r=%r", name, value) + _logger.debug("Attribute name must be a string. Dropping attribute: %r=%r", name, value) return FAILED_RESULT except NameTooLongException: - _logger.debug("Attribute name exceeds maximum length. Dropping " "attribute: %r=%r", name, value) + _logger.debug("Attribute name exceeds maximum length. Dropping attribute: %r=%r", name, value) return FAILED_RESULT except IntTooLargeException: - _logger.debug("Attribute value exceeds maximum integer value. " "Dropping attribute: %r=%r", name, value) + _logger.debug("Attribute value exceeds maximum integer value. Dropping attribute: %r=%r", name, value) return FAILED_RESULT except CastingFailureException: - _logger.debug("Attribute value cannot be cast to a string. " "Dropping attribute: %r=%r", name, value) + _logger.debug("Attribute value cannot be cast to a string. Dropping attribute: %r=%r", name, value) return FAILED_RESULT else: @@ -268,7 +268,7 @@ def process_user_attribute(name, value, max_length=MAX_ATTRIBUTE_LENGTH, ending= trunc_value = truncate(value, maxsize=max_length, ending=ending) if value != trunc_value: _logger.debug( - "Attribute value exceeds maximum length " "(%r bytes). Truncating value: %r=%r.", + "Attribute value exceeds maximum length (%r bytes). Truncating value: %r=%r.", max_length, name, trunc_value, @@ -296,8 +296,6 @@ def sanitize(value): except Exception: raise CastingFailureException() else: - _logger.debug( - "Attribute value is of type: %r. Casting %r to " "string: %s", type(original), original, value - ) + _logger.debug("Attribute value is of type: %r. Casting %r to string: %s", type(original), original, value) return value diff --git a/tests/agent_features/test_span_events.py b/tests/agent_features/test_span_events.py index 4656131696..3faa73a0c8 100644 --- a/tests/agent_features/test_span_events.py +++ b/tests/agent_features/test_span_events.py @@ -413,10 +413,11 @@ def _test(): @pytest.mark.parametrize("span_events_enabled", (False, True)) def test_collect_span_events_override(collect_span_events, span_events_enabled): - if collect_span_events and span_events_enabled: - spans_expected = True - else: - spans_expected = False + # if collect_span_events and span_events_enabled: + # spans_expected = True + # else: + # spans_expected = False + spans_expected = collect_span_events and span_events_enabled span_count = 2 if spans_expected else 0 diff --git a/tests/testing_support/sample_asgi_applications.py b/tests/testing_support/sample_asgi_applications.py index 9118883b09..62cd5330c3 100644 --- a/tests/testing_support/sample_asgi_applications.py +++ b/tests/testing_support/sample_asgi_applications.py @@ -34,7 +34,7 @@ async def __call__(self, receive, send): if self.scope["path"] == "/exc": raise ValueError("whoopsies") - elif self.scope["path"] == "/ignored": + if self.scope["path"] == "/ignored": ignore_transaction() await send({"type": "http.response.start", "status": 200}) @@ -57,7 +57,7 @@ async def simple_app_v3_raw(scope, receive, send): if scope["path"] == "/exc": raise ValueError("whoopsies") - elif scope["path"] == "/ignored": + if scope["path"] == "/ignored": ignore_transaction() await send({"type": "http.response.start", "status": 200})