Skip to content

Commit 03e092f

Browse files
committed
Fixup
1 parent 0c4c355 commit 03e092f

File tree

8 files changed

+36
-723
lines changed

8 files changed

+36
-723
lines changed

newrelic/common/streaming_utils.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import collections
1616
import logging
1717
import threading
18-
from newrelic.packages import objsize
1918

2019
try:
2120
from newrelic.core.infinite_tracing_pb2 import AttributeValue, SpanBatch
@@ -26,6 +25,27 @@
2625
_logger = logging.getLogger(__name__)
2726

2827

28+
def get_deep_size(obj, seen=None):
29+
"""Recursively calculates the size of an object including nested lists and dicts."""
30+
if seen is None:
31+
seen = set()
32+
33+
# Avoid recursion for already seen objects (handle circular references)
34+
obj_id = id(obj)
35+
if obj_id in seen:
36+
return 0
37+
seen.add(obj_id)
38+
39+
size = sys.getsizeof(obj)
40+
41+
if isinstance(obj, dict):
42+
size += sum(get_deep_size(k, seen) + get_deep_size(v, seen) for k, v in obj.items())
43+
elif isinstance(obj, (list, tuple, set, frozenset)):
44+
size += sum(get_deep_size(i, seen) for i in obj)
45+
46+
return size
47+
48+
2949
class StreamBuffer:
3050
def __init__(self, maxlen, batching=False):
3151
self._queue = collections.deque(maxlen=maxlen)
@@ -54,7 +74,7 @@ def put(self, item):
5474
return
5575

5676
self._seen += 1
57-
self._bytes += objsize.get_deep_size(item)
77+
self._bytes += get_deep_size(item)
5878

5979
# NOTE: dropped can be over-counted as the queue approaches
6080
# capacity while data is still being transmitted.

newrelic/core/application.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,13 +1384,9 @@ def harvest(self, shutdown=False, flexible=False):
13841384
spans_seen = spans.num_seen
13851385
spans_sampled = spans.num_samples
13861386
internal_count_metric("Supportability/SpanEvent/TotalEventsSeen", spans_seen)
1387-
print(f"Supportability/SpanEvent/TotalEventsSeen: {spans_seen}")
13881387
internal_count_metric("Supportability/SpanEvent/TotalEventsSent", spans_sampled)
1389-
print(f"Supportability/SpanEvent/TotalEventsSent: {spans_sampled}")
13901388
internal_count_metric("Supportability/DistributedTracing/Bytes/Seen", spans.bytes)
1391-
print(f"Supportability/DistributedTracing/Bytes/Seen: {spans.bytes}")
13921389
internal_count_metric("Supportability/SpanEvent/TotalCoreTracingTime", spans.ct_processing_time*1000) # Time in ms.
1393-
print(f"Supportability/SpanEvent/TotalCoreTracingTime: {spans.ct_processing_time*1000}") # Time in ms.
13941390

13951391
stats.reset_span_events()
13961392

newrelic/core/node_mixin.py

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,8 @@ def span_event(self, settings, base_attrs=None, parent_guid=None, attr_class=dic
8686
if settings.core_tracing.drop_inprocess_spans or settings.core_tracing.enabled:
8787
exit_span_attrs_present = attribute.SPAN_ENTITY_RELATIONSHIP_ATTRIBUTES & set(a_attrs)
8888
if self.__class__.__name__ == "RootNode":
89-
if settings.core_tracing.enabled:
90-
ct_processing_time[0] += (time.time() - start_time)
91-
return [i_attrs, {}, {}]
92-
else:
93-
ct_processing_time[0] += (time.time() - start_time)
94-
return [i_attrs, u_attrs, a_attrs]
89+
ct_processing_time[0] += (time.time() - start_time)
90+
return [i_attrs, {}, {}] if settings.core_tracing.enabled else [i_attrs, u_attrs, a_attrs]
9591
if not exit_span_attrs_present:
9692
ct_processing_time[0] += (time.time() - start_time)
9793
return None
@@ -114,26 +110,16 @@ def span_event(self, settings, base_attrs=None, parent_guid=None, attr_class=dic
114110
return [i_attrs, u_attrs, a_attrs]
115111

116112
def span_events(self, settings, base_attrs=None, parent_guid=None, attr_class=dict, ct_exit_spans=None, ct_processing_time=None):
117-
if settings.core_tracing.drop_inprocess_spans or settings.core_tracing.enabled:
118-
span = self.span_event(settings, base_attrs=base_attrs, parent_guid=parent_guid, attr_class=attr_class, ct_exit_spans=ct_exit_spans, ct_processing_time=ct_processing_time)
119-
parent_id = parent_guid
120-
if span: # span will be None if the span is an inprocess span or repeated exit span.
121-
yield span
122-
parent_id = self.guid
123-
for child in self.children:
124-
for event in child.span_events( # noqa: UP028
125-
settings, base_attrs=base_attrs, parent_guid=parent_id, attr_class=attr_class, ct_exit_spans=ct_exit_spans, ct_processing_time=ct_processing_time
126-
):
127-
if event: # event will be None if the span is an inprocess span or repeated exit span.
128-
yield event
129-
else:
130-
span = self.span_event(settings, base_attrs=base_attrs, parent_guid=parent_guid, attr_class=attr_class, ct_processing_time=ct_processing_time)
113+
span = self.span_event(settings, base_attrs=base_attrs, parent_guid=parent_guid, attr_class=attr_class, ct_exit_spans=ct_exit_spans, ct_processing_time=ct_processing_time)
114+
parent_id = parent_guid
115+
if span: # span will be None if the span is an inprocess span or repeated exit span.
131116
yield span
132-
133-
for child in self.children:
134-
for event in child.span_events( # noqa: UP028
135-
settings, base_attrs=base_attrs, parent_guid=self.guid, attr_class=attr_class, ct_processing_time=ct_processing_time
136-
):
117+
parent_id = self.guid
118+
for child in self.children:
119+
for event in child.span_events( # noqa: UP028
120+
settings, base_attrs=base_attrs, parent_guid=parent_id, attr_class=attr_class, ct_exit_spans=ct_exit_spans, ct_processing_time=ct_processing_time
121+
):
122+
if event: # event will be None if the span is an inprocess span or repeated exit span.
137123
yield event
138124

139125

newrelic/core/root_node.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
class RootNode(_RootNode, GenericNodeMixin):
4040
def span_event(self, *args, **kwargs):
4141
span = super().span_event(*args, **kwargs)
42-
#if not span:
43-
# return None
4442
i_attrs = span[0]
4543
i_attrs["transaction.name"] = self.path
4644
i_attrs["nr.entryPoint"] = True

newrelic/core/stats_engine.py

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,12 @@
3131
import zlib
3232
from heapq import heapify, heapreplace
3333

34-
from newrelic.packages import objsize
3534
from newrelic.api.settings import STRIP_EXCEPTION_MESSAGE
3635
from newrelic.api.time_trace import get_linking_metadata
3736
from newrelic.common.encoding_utils import json_encode
3837
from newrelic.common.metric_utils import create_metric_identity
3938
from newrelic.common.object_names import parse_exc_info
40-
from newrelic.common.streaming_utils import StreamBuffer
39+
from newrelic.common.streaming_utils import StreamBuffer, get_deep_size
4140
from newrelic.core.attribute import (
4241
MAX_LOG_MESSAGE_LENGTH,
4342
create_agent_attributes,
@@ -55,26 +54,6 @@
5554
from newrelic.core.metric import TimeMetric
5655
from newrelic.core.stack_trace import exception_stack
5756

58-
def get_deep_size(obj, seen=None):
59-
"""Recursively calculates the size of an object including nested lists and dicts."""
60-
if seen is None:
61-
seen = set()
62-
63-
# Avoid recursion for already seen objects (handle circular references)
64-
obj_id = id(obj)
65-
if obj_id in seen:
66-
return 0
67-
seen.add(obj_id)
68-
69-
size = sys.getsizeof(obj)
70-
71-
if isinstance(obj, dict):
72-
size += sum(get_deep_size(k, seen) + get_deep_size(v, seen) for k, v in obj.items())
73-
elif isinstance(obj, (list, tuple, set, frozenset)):
74-
size += sum(get_deep_size(i, seen) for i in obj)
75-
76-
return size
77-
7857
_logger = logging.getLogger(__name__)
7958

8059
EVENT_HARVEST_METHODS = {
@@ -1236,12 +1215,12 @@ def record_transaction(self, transaction):
12361215

12371216
if settings.distributed_tracing.enabled and settings.span_events.enabled and settings.collect_span_events:
12381217
if settings.infinite_tracing.enabled:
1239-
ct_processing_time = [0]
1218+
ct_processing_time = [0] # Hack for getting Python to create a non mutable number.
12401219
for event in transaction.span_protos(settings, ct_processing_time=ct_processing_time):
12411220
self._span_stream.put(event)
12421221
self._span_stream._ct_processing_time += ct_processing_time[0]
12431222
elif transaction.sampled:
1244-
ct_processing_time = [0]
1223+
ct_processing_time = [0] # Hack for getting Python to create a non mutable number.
12451224
for event in transaction.span_events(self.__settings, ct_processing_time=ct_processing_time):
12461225
self._span_events.add(event, priority=transaction.priority)
12471226
self._span_events.ct_processing_time += ct_processing_time[0]

newrelic/packages/objsize/LICENSE

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)