Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion newrelic/api/database_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def _nr_database_trace_wrapper_(wrapped, instance, args, kwargs):

trace = DatabaseTrace(_sql, dbapi2_module, parent=parent, source=wrapped)

if wrapper: # pylint: disable=W0125,W0126
if wrapper:
return wrapper(wrapped, trace)(*args, **kwargs)

with trace:
Expand Down
2 changes: 1 addition & 1 deletion newrelic/api/datastore_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def _nr_datastore_trace_wrapper_(wrapped, instance, args, kwargs):
_product, _target, _operation, _host, _port_path_or_id, _database_name, parent=parent, source=wrapped
)

if wrapper: # pylint: disable=W0125,W0126
if wrapper:
return wrapper(wrapped, trace)(*args, **kwargs)

with trace:
Expand Down
4 changes: 2 additions & 2 deletions newrelic/api/external_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def dynamic_wrapper(wrapped, instance, args, kwargs):

trace = ExternalTrace(library, _url, _method, parent=parent, source=wrapped)

if wrapper: # pylint: disable=W0125,W0126
if wrapper:
return wrapper(wrapped, trace)(*args, **kwargs)

with trace:
Expand All @@ -109,7 +109,7 @@ def literal_wrapper(wrapped, instance, args, kwargs):

trace = ExternalTrace(library, url, method, parent=parent, source=wrapped)

if wrapper: # pylint: disable=W0125,W0126
if wrapper:
return wrapper(wrapped, trace)(*args, **kwargs)

with trace:
Expand Down
4 changes: 2 additions & 2 deletions newrelic/api/function_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def dynamic_wrapper(wrapped, instance, args, kwargs):

trace = FunctionTrace(_name, _group, _label, _params, terminal, rollup, parent=parent, source=wrapped)

if wrapper: # pylint: disable=W0125,W0126
if wrapper:
return wrapper(wrapped, trace)(*args, **kwargs)

with trace:
Expand All @@ -150,7 +150,7 @@ def literal_wrapper(wrapped, instance, args, kwargs):

trace = FunctionTrace(_name, group, label, params, terminal, rollup, parent=parent, source=wrapped)

if wrapper: # pylint: disable=W0125,W0126
if wrapper:
return wrapper(wrapped, trace)(*args, **kwargs)

with trace:
Expand Down
4 changes: 2 additions & 2 deletions newrelic/api/graphql_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def _nr_graphql_trace_wrapper_(wrapped, instance, args, kwargs):

trace = GraphQLOperationTrace(parent=parent, source=wrapped)

if wrapper: # pylint: disable=W0125,W0126
if wrapper:
return wrapper(wrapped, trace)(*args, **kwargs)

with trace:
Expand Down Expand Up @@ -202,7 +202,7 @@ def _nr_graphql_trace_wrapper_(wrapped, instance, args, kwargs):

trace = GraphQLResolverTrace(parent=parent, source=wrapped)

if wrapper: # pylint: disable=W0125,W0126
if wrapper:
return wrapper(wrapped, trace)(*args, **kwargs)

with trace:
Expand Down
2 changes: 1 addition & 1 deletion newrelic/api/memcache_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _nr_wrapper_memcache_trace_(wrapped, instance, args, kwargs):

trace = MemcacheTrace(_command, parent=parent, source=wrapped)

if wrapper: # pylint: disable=W0125,W0126
if wrapper:
return wrapper(wrapped, trace)(*args, **kwargs)

with trace:
Expand Down
2 changes: 1 addition & 1 deletion newrelic/api/message_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _nr_message_trace_wrapper_(wrapped, instance, args, kwargs):
source=wrapped,
)

if wrapper: # pylint: disable=W0125,W0126
if wrapper:
return wrapper(wrapped, trace)(*args, **kwargs)

with trace:
Expand Down
2 changes: 1 addition & 1 deletion newrelic/api/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def complete_root(self):
self.exited = True

@staticmethod
def complete_trace(): # pylint: disable=arguments-differ
def complete_trace():
pass

@property
Expand Down
2 changes: 1 addition & 1 deletion newrelic/api/web_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ def browser_timing_header(self, nonce=None):

except UnicodeError:
if not WebTransaction.unicode_error_reported:
_logger.error("ASCII encoding of js-agent-header failed.", header)
_logger.error("ASCII encoding of js-agent-header failed: %s", header)
WebTransaction.unicode_error_reported = True

header = ""
Expand Down
4 changes: 2 additions & 2 deletions newrelic/common/agent_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
import zlib
from pprint import pprint

import newrelic.packages.urllib3 as urllib3
from newrelic import version
from newrelic.common import certs
from newrelic.common.encoding_utils import json_decode, json_encode, obfuscate_license_key
from newrelic.common.object_names import callable_name
from newrelic.common.object_wrapper import patch_function_wrapper
from newrelic.core.internal_metrics import internal_count_metric, internal_metric
from newrelic.network.exceptions import NetworkInterfaceException
from newrelic.packages import urllib3

try:
from ssl import get_default_verify_paths
Expand Down Expand Up @@ -239,7 +239,7 @@ def __init__(
default_content_encoding_header="Identity",
):
self._host = host
port = self._port = port
self._port = port
self._compression_threshold = compression_threshold
self._compression_level = compression_level
self._compression_method = compression_method
Expand Down
7 changes: 1 addition & 6 deletions newrelic/common/object_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@
from newrelic.packages.wrapt import CallableObjectProxy as _CallableObjectProxy
from newrelic.packages.wrapt import FunctionWrapper as _FunctionWrapper
from newrelic.packages.wrapt import ObjectProxy as _ObjectProxy
from newrelic.packages.wrapt import ( # noqa: F401; pylint: disable=W0611
apply_patch,
resolve_path,
wrap_object,
wrap_object_attribute,
)
from newrelic.packages.wrapt import apply_patch, resolve_path, wrap_object, wrap_object_attribute # noqa: F401

# We previously had our own pure Python implementation of the generic
# object wrapper but we now defer to using the wrapt module as its C
Expand Down
6 changes: 3 additions & 3 deletions newrelic/common/package_version_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ def _get_package_version(name):
if "importlib" in sys.modules and hasattr(sys.modules["importlib"], "metadata"):
try:
# In Python3.10+ packages_distribution can be checked for as well
if hasattr(sys.modules["importlib"].metadata, "packages_distributions"): # pylint: disable=E1101
distributions = sys.modules["importlib"].metadata.packages_distributions() # pylint: disable=E1101
if hasattr(sys.modules["importlib"].metadata, "packages_distributions"):
distributions = sys.modules["importlib"].metadata.packages_distributions()
distribution_name = distributions.get(name, name)
distribution_name = distribution_name[0] if isinstance(distribution_name, list) else distribution_name
else:
distribution_name = name

version = sys.modules["importlib"].metadata.version(distribution_name) # pylint: disable=E1101
version = sys.modules["importlib"].metadata.version(distribution_name)
if version not in NULL_VERSIONS:
return version
except Exception:
Expand Down
4 changes: 2 additions & 2 deletions newrelic/common/streaming_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ def __init__(self, *args, **kwargs):
for k, v in arg:
self[k] = v

for k in kwargs:
self[k] = kwargs[k]
for k, v in kwargs.items():
self[k] = v

def __setitem__(self, key, value):
super(SpanProtoAttrs, self).__setitem__(key, SpanProtoAttrs.get_attribute_value(value))
Expand Down
2 changes: 0 additions & 2 deletions newrelic/common/system_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ def gethostname(use_dyno_names=False, dyno_shorten_prefixes=()):
"""

global _nr_cached_hostname
global _nr_cached_hostname_lock
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PLW0602 - global-variable-not-assigned

There's no need to make this variable global when it's never assigned to. It already reads the globally scoped variable when attempting to use the lock.


if _nr_cached_hostname:
return _nr_cached_hostname
Expand All @@ -371,7 +370,6 @@ def getips():
"""

global _nr_cached_ip_address
global _nr_cached_ipaddress_lock

if _nr_cached_ip_address is not None:
return _nr_cached_ip_address
Expand Down
2 changes: 1 addition & 1 deletion newrelic/common/utilization.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import socket
import string

import newrelic.packages.urllib3 as urllib3
from newrelic.common.agent_http import InsecureHttpClient
from newrelic.common.encoding_utils import json_decode
from newrelic.core.internal_metrics import internal_count_metric
from newrelic.packages import urllib3

_logger = logging.getLogger(__name__)
VALID_CHARS_RE = re.compile(r"[0-9a-zA-Z_ ./-]")
Expand Down
2 changes: 1 addition & 1 deletion newrelic/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def wrapper(self, line):
prototype = f"{wrapper.__name__[3:]} {doc_signature(wrapped)}"

if hasattr(wrapper, "__doc__") and wrapper.__doc__ is not None:
wrapper.__doc__ = "\n".join((prototype, wrapper.__doc__.lstrip("\n"))) # noqa: flynt
wrapper.__doc__ = "\n".join((prototype, wrapper.__doc__.lstrip("\n")))

return wrapper

Expand Down
6 changes: 3 additions & 3 deletions newrelic/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
try:
import grpc

from newrelic.core.infinite_tracing_pb2 import Span # pylint: disable=W0611,C0412 # noqa: F401
from newrelic.core.infinite_tracing_pb2 import Span # noqa: F401
except Exception:
grpc = None

Expand Down Expand Up @@ -892,8 +892,8 @@ def default_otlp_host(host):
_settings.infinite_tracing.ssl = True
_settings.infinite_tracing.span_queue_size = _environ_as_int("NEW_RELIC_INFINITE_TRACING_SPAN_QUEUE_SIZE", 10000)

_settings.instrumentation.graphql.capture_introspection_queries = os.environ.get(
"NEW_RELIC_INSTRUMENTATION_GRAPHQL_CAPTURE_INTROSPECTION_QUERIES", False
_settings.instrumentation.graphql.capture_introspection_queries = _environ_as_bool(
"NEW_RELIC_INSTRUMENTATION_GRAPHQL_CAPTURE_INTROSPECTION_QUERIES", default=False
)

# celeryev is the monitoring queue for rabbitmq which we do not need to monitor-it just makes a lot of noise.
Expand Down
2 changes: 1 addition & 1 deletion newrelic/core/database_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

from collections import namedtuple

import newrelic.core.attribute as attribute
import newrelic.core.trace_node
from newrelic.common import system_info
from newrelic.core import attribute
from newrelic.core.database_utils import explain_plan, sql_statement
from newrelic.core.metric import TimeMetric
from newrelic.core.node_mixin import DatastoreNodeMixin
Expand Down
2 changes: 1 addition & 1 deletion newrelic/core/external_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import urllib.parse as urlparse
from collections import namedtuple

import newrelic.core.attribute as attribute
import newrelic.core.trace_node
from newrelic.core import attribute
from newrelic.core.metric import TimeMetric
from newrelic.core.node_mixin import GenericNodeMixin

Expand Down
21 changes: 3 additions & 18 deletions newrelic/core/infinite_tracing_pb2.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,8 @@

# Import appropriate generated pb2 file for protobuf version
if PROTOBUF_VERSION >= (5,):
from newrelic.core.infinite_tracing_v5_pb2 import ( # noqa: F401; pylint: disable=W0611
AttributeValue,
RecordStatus,
Span,
SpanBatch,
)
from newrelic.core.infinite_tracing_v5_pb2 import AttributeValue, RecordStatus, Span, SpanBatch # noqa: F401
elif PROTOBUF_VERSION >= (4,):
from newrelic.core.infinite_tracing_v4_pb2 import ( # noqa: F401; pylint: disable=W0611
AttributeValue,
RecordStatus,
Span,
SpanBatch,
)
from newrelic.core.infinite_tracing_v4_pb2 import AttributeValue, RecordStatus, Span, SpanBatch # noqa: F401
else:
from newrelic.core.infinite_tracing_v3_pb2 import ( # noqa: F401; pylint: disable=W0611
AttributeValue,
RecordStatus,
Span,
SpanBatch,
)
from newrelic.core.infinite_tracing_v3_pb2 import AttributeValue, RecordStatus, Span, SpanBatch # noqa: F401
2 changes: 1 addition & 1 deletion newrelic/core/node_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import newrelic.core.attribute as attribute
from newrelic.core import attribute
from newrelic.core.attribute_filter import DST_SPAN_EVENTS, DST_TRANSACTION_SEGMENTS


Expand Down
10 changes: 5 additions & 5 deletions newrelic/core/otlp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@


def otlp_encode(payload):
if type(payload) is dict: # pylint: disable=C0123
if type(payload) is dict:
_logger.warning(
"Using OTLP integration while protobuf is not installed. This may result in larger payload sizes and data loss."
)
Expand Down Expand Up @@ -159,7 +159,7 @@ def stats_to_otlp_metrics(metric_data, start_time, end_time):
for name, metric_container in metric_data:
# Types are checked here using type() instead of isinstance, as CountStats is a subclass of TimeStats.
# Imporperly checking with isinstance will lead to count metrics being encoded and reported twice.
if any(type(metric) is CountStats for metric in metric_container.values()): # pylint: disable=C0123
if any(type(metric) is CountStats for metric in metric_container.values()):
# Metric contains Sum metric data points.
yield Metric(
name=name,
Expand All @@ -174,11 +174,11 @@ def stats_to_otlp_metrics(metric_data, start_time, end_time):
attributes=create_key_values_from_iterable(tags),
)
for tags, value in metric_container.items()
if type(value) is CountStats # pylint: disable=C0123
if type(value) is CountStats
],
),
)
if any(type(metric) is TimeStats for metric in metric_container.values()): # pylint: disable=C0123
if any(type(metric) is TimeStats for metric in metric_container.values()):
# Metric contains Summary metric data points.
yield Metric(
name=name,
Expand All @@ -191,7 +191,7 @@ def stats_to_otlp_metrics(metric_data, start_time, end_time):
attributes=create_key_values_from_iterable(tags),
)
for tags, value in metric_container.items()
if type(value) is TimeStats # pylint: disable=C0123
if type(value) is TimeStats
]
),
)
Expand Down
4 changes: 2 additions & 2 deletions newrelic/core/stats_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def should_sample(self, priority):
# Always sample if under capacity
return True

def add(self, sample, priority=None): # pylint: disable=E0202
def add(self, sample, priority=None):
self.num_seen += 1

if priority is None:
Expand Down Expand Up @@ -479,7 +479,7 @@ def reset(self):
self.clear()
self.num_seen = 0

def add(self, sample): # pylint: disable=E0202
def add(self, sample):
if self.should_sample():
self.append(sample)
self.num_seen += 1
Expand Down
1 change: 1 addition & 0 deletions newrelic/hooks/external_aiobotocore.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ async def wrap_client__make_api_call(wrapped, instance, args, kwargs):
handle_bedrock_exception(
exc, is_embedding, model, span_id, trace_id, request_extractor, request_body, ft, transaction
)
raise

if not response or response_streaming and not settings.ai_monitoring.streaming.enabled:
if ft:
Expand Down
Loading
Loading