Skip to content

Commit 54e2a43

Browse files
committed
Fixup
1 parent 41bd7d5 commit 54e2a43

File tree

6 files changed

+31
-136
lines changed

6 files changed

+31
-136
lines changed

newrelic/common/streaming_utils.py

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,8 @@ def __init__(self, maxlen, batching=False):
3333
self._shutdown = False
3434
self._seen = 0
3535
self._dropped = 0
36-
self._ft_seen = 0
37-
self._ft_dropped = 0
3836
self._bytes = 0
39-
self._ft_bytes = 0
40-
self._ct_bytes = 0
41-
self.ct_processing_time = 0
37+
self._ct_processing_time = 0
4238
self._settings = None
4339

4440
self.batching = batching
@@ -52,30 +48,13 @@ def shutdown(self):
5248
self._shutdown = True
5349
self._notify.notify_all()
5450

55-
def is_ft(self, sample, entity_relationship_attrs):
56-
# It's a FT span if it's an exit or entry span.
57-
return entity_relationship_attrs or not sample.intrinsics.get("parentId")
58-
5951
def put(self, item):
6052
with self._notify:
6153
if self._shutdown:
6254
return
6355

64-
entity_relationship_attrs = item[1]
65-
item = item[0]
6656
self._seen += 1
67-
# The last index contains the set of entity synthesis attrs in the span.
68-
self._bytes += objsize.get_deep_size([item.intrinsics, item.user_attributes, item.agent_attributes])
69-
if self.is_ft(item, entity_relationship_attrs):
70-
self._ft_seen += 1
71-
# The last index contains the set of entity synthesis attrs in the span.
72-
self._ft_bytes += objsize.get_deep_size([item.intrinsics, item.user_attributes, item.agent_attributes])
73-
74-
i_ct_attrs = {"type", "name", "guid", "parentId", "transaction.name", "traceId", "nr.entryPoint", "transactionId"}
75-
i_attrs = {attr: value for attr, value in item.intrinsics.items() if attr in i_ct_attrs}
76-
u_attrs = {}
77-
a_attrs = {attr: value for attr, value in item.agent_attributes.items() if attr in entity_relationship_attrs}
78-
self._ct_bytes += objsize.get_deep_size([i_attrs, u_attrs, a_attrs])
57+
self._bytes += objsize.get_deep_size(item)
7958

8059
# NOTE: dropped can be over-counted as the queue approaches
8160
# capacity while data is still being transmitted.
@@ -84,25 +63,21 @@ def put(self, item):
8463
# being measured.
8564
if len(self._queue) >= self._queue.maxlen:
8665
self._dropped += 1
87-
if self.is_ft(item, entity_relationship_attrs):
88-
self._ft_dropped += 1
66+
print(f"dropped: {self._dropped}")
8967

90-
# Drop last index that contains the entity relationship attrs present on the span.
9168
self._queue.append(item)
9269
self._notify.notify_all()
70+
print(f"seen: {self._seen}")
71+
print(f"bytes: {self._bytes}")
9372

9473
def stats(self):
9574
with self._notify:
9675
seen, dropped = self._seen, self._dropped
9776
self._seen, self._dropped = 0, 0
98-
ft_seen, ft_dropped = self._ft_seen, self._ft_dropped
99-
self._ft_seen, self._ft_dropped = 0, 0
100-
_bytes, ft_bytes, ct_bytes = self._bytes, self._ft_bytes, self._ct_bytes
101-
self._bytes, self._ft_bytes, self._ct_bytes = 0, 0, 0
102-
ct_processing_time = self._ct_processing_time
103-
self._ct_processing_time = 0
104-
105-
return seen, dropped, ft_seen, ft_dropped, _bytes, ft_bytes, ct_byte, ct_processing_times
77+
_bytes, ct_processing_time = self._bytes, self._ct_processing_time
78+
self._bytes, self._ct_processing_time = 0, 0
79+
80+
return seen, dropped, _bytes, ct_processing_time
10681

10782
def __bool__(self):
10883
return bool(self._queue)

newrelic/core/application.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,6 @@ def harvest(self, shutdown=False, flexible=False):
13531353

13541354
# Send span events
13551355

1356-
print(f"\n\r\n\r\n\r{configuration.span_events.enabled} {configuration.collect_span_events} {configuration.distributed_tracing.enabled} {configuration.infinite_tracing.enabled} \n\r\n\r\n\r")
13571356
if (
13581357
configuration.span_events.enabled
13591358
and configuration.collect_span_events
@@ -1363,18 +1362,12 @@ def harvest(self, shutdown=False, flexible=False):
13631362
span_stream = stats.span_stream
13641363
# Only merge stats as part of default harvest
13651364
if span_stream is not None and not flexible:
1366-
print("\n\r\n\r\n\rSending Supportability metrics for inifinte tracing\n\r\n\r\n\r")
1367-
spans_seen, spans_dropped, spans_ft_seen, spans_ft_dropped, _bytes, ft_bytes, ct_bytes, ct_processing_time = span_stream.stats()
1365+
spans_seen, spans_dropped, _bytes, ct_processing_time = span_stream.stats()
13681366
spans_sent = spans_seen - spans_dropped
1369-
spans_ft_sent = spans_ft_seen - spans_ft_dropped
13701367

13711368
internal_count_metric("Supportability/InfiniteTracing/Span/Seen", spans_seen)
13721369
internal_count_metric("Supportability/InfiniteTracing/Span/Sent", spans_sent)
1373-
internal_count_metric("Supportability/FullTracing/Span/Seen", spans_ft_seen)
1374-
internal_count_metric("Supportability/FullTracing/Span/Sent", spans_ft_sent)
13751370
internal_count_metric("Supportability/InfiniteTracing/Bytes/Seen", _bytes)
1376-
internal_count_metric("Supportability/FullTracing/Bytes/Seen", ft_bytes)
1377-
internal_count_metric("Supportability/CoreTracing/Bytes/Seen", ct_bytes)
13781371
internal_count_metric("Supportability/CoreTracing/TotalTime", ct_processing_time*1000) # Time in ms.
13791372
else:
13801373
spans = stats.span_events
@@ -1392,11 +1385,7 @@ def harvest(self, shutdown=False, flexible=False):
13921385
spans_sampled = spans.num_samples
13931386
internal_count_metric("Supportability/SpanEvent/TotalEventsSeen", spans_seen)
13941387
internal_count_metric("Supportability/SpanEvent/TotalEventsSent", spans_sampled)
1395-
internal_count_metric("Supportability/SpanEvent/FullTracing/TotalEventsSeen", spans.ft_seen)
1396-
internal_count_metric("Supportability/SpanEvent/FullTracing/TotalEventsSent", spans.ft_sent)
13971388
internal_count_metric("Supportability/DistributedTracing/Bytes/Seen", spans.bytes)
1398-
internal_count_metric("Supportability/FullTracing/Bytes/Seen", spans.ft_bytes)
1399-
internal_count_metric("Supportability/CoreTracing/Bytes/Seen", spans.ct_bytes)
14001389
internal_count_metric("Supportability/SpanEvent/TotalCoreTracingTime", spans.ct_processing_time*1000) # Time in ms.
14011390

14021391
stats.reset_span_events()

newrelic/core/node_mixin.py

Lines changed: 14 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -62,36 +62,35 @@ def span_event(self, settings, base_attrs=None, parent_guid=None, attr_class=dic
6262
i_attrs["timestamp"] = int(self.start_time * 1000)
6363
i_attrs["duration"] = self.duration
6464
i_attrs["category"] = "generic"
65+
#if settings.core_tracing.enabled:
66+
#i_ct_attrs = {"type", "name", "guid", "parentId", "transaction.name", "traceId", "nr.entryPoint", "transactionId"}
67+
#i_attrs = {key: value for key, value in i_attrs.items() if key in i_ct_attrs}
6568

6669
if parent_guid:
6770
i_attrs["parentId"] = parent_guid
6871

6972
a_attrs = attribute.resolve_agent_attributes(
7073
self.agent_attributes, settings.attribute_filter, DST_SPAN_EVENTS, attr_class=attr_class
7174
)
75+
u_attrs = self.processed_user_attributes
76+
if settings.core_tracing.enabled:
77+
# ids is the list of span guids that share this unqiue exit span.
78+
u_attrs = {"ids": self.ids}
7279

7380
u_attrs = attribute.resolve_user_attributes(
74-
self.processed_user_attributes, settings.attribute_filter, DST_SPAN_EVENTS, attr_class=attr_class
81+
u_attrs, settings.attribute_filter, DST_SPAN_EVENTS, attr_class=attr_class
7582
)
7683

77-
# intrinsics, user attrs, agent attrs
78-
79-
exit_span_attrs_present = attribute.SPAN_ENTITY_RELATIONSHIP_ATTRIBUTES & set(a_attrs)
8084
if settings.core_tracing.drop_inprocess_spans or settings.core_tracing.enabled:
85+
exit_span_attrs_present = attribute.SPAN_ENTITY_RELATIONSHIP_ATTRIBUTES & set(a_attrs)
8186
if self.__class__.__name__ == "RootNode":
82-
if settings.core_tracing.enabled:
83-
#i_ct_attrs = {"type", "name", "guid", "parentId", "transaction.name", "traceId", "nr.entryPoint", "transactionId"}
84-
#i_attrs = {key: value for key, value in i_attrs.items() if key in i_ct_attrs}
85-
u_attrs = {}
86-
return [i_attrs, u_attrs, a_attrs, exit_span_attrs_present]
87+
return [i_attrs, u_attrs, a_attrs]
8788
if not exit_span_attrs_present:
8889
return None
8990
if settings.core_tracing.enabled:
9091
start_time = time.time()
91-
parent_id = parent_guid
92-
# ids is the list of span guids that share this unqiue exit span.
93-
span = [i_attrs, {"ids": self.ids}, a_attrs, exit_span_attrs_present]
94-
span_attrs = "".join([span[2][key] for key in exit_span_attrs_present])
92+
# TODO: use attr value name rather than str casting.
93+
span_attrs = "".join([str(a_attrs[key]) for key in exit_span_attrs_present])
9594
new_exit_span = span_attrs not in ct_exit_spans
9695
if new_exit_span:
9796
ct_exit_spans[span_attrs] = self.ids
@@ -100,52 +99,11 @@ def span_event(self, settings, base_attrs=None, parent_guid=None, attr_class=dic
10099
ct_exit_spans[span_attrs].append(self.guid)
101100
ct_processing_time += (time.time() - start_time)
102101
if new_exit_span:
103-
return span
102+
return [i_attrs, u_attrs, a_attrs]
104103
return None
105-
return [i_attrs, u_attrs, a_attrs, exit_span_attrs_present]
104+
return [i_attrs, u_attrs, a_attrs]
106105

107106
def span_events(self, settings, base_attrs=None, parent_guid=None, attr_class=dict, ct_exit_spans=None, ct_processing_time=0):
108-
#if settings.core_tracing.enabled:
109-
# if ct_exit_spans is None:
110-
# ct_exit_spans = {}
111-
# span = self.span_event(settings, base_attrs=base_attrs, parent_guid=parent_guid, attr_class=attr_class)
112-
# start_time = time.time()
113-
# parent_id = parent_guid
114-
# if span: # span will be None if the span is an inprocess span.
115-
# span_attrs = "".join([span[2][key] for key in span[3]])
116-
# new_exit_span = span_attrs not in ct_exit_spans
117-
# if parent_id: # If this is not the entry span.
118-
# if new_exit_span:
119-
# ct_exit_spans[span_attrs] = span
120-
# else:
121-
# ct_exit_spans[span_attrs][0]["ids"].append(span[0]["guid"])
122-
# ct_processing_time += (time.time() - start_time)
123-
# #print(f"parent {span[0]['traceId']} {parent_id} {span[0]['name']} {new_exit_span}")
124-
# if not parent_id or new_exit_span:
125-
# #print(f"{span}")
126-
# import traceback
127-
# traceback.print_stack()
128-
# yield span
129-
# parent_id = self.guid
130-
# for child in self.children:
131-
# for event in child.span_events( # noqa: UP028
132-
# 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
133-
# ):
134-
# if event:
135-
# start_time = time.time()
136-
# span_attrs = "".join([event[2][key] for key in event[3]])
137-
# new_exit_span = span_attrs not in ct_exit_spans
138-
# if new_exit_span:
139-
# ct_exit_spans[span_attrs] = event
140-
# else:
141-
# ct_exit_spans[span_attrs][0]["ids"].append(event[0]["guid"])
142-
# ct_processing_time += (time.time() - start_time)
143-
# #print(f"child {event[0]['traceId']} {parent_id} {event[0]['name']} {new_exit_span}")
144-
# if new_exit_span:
145-
# #print(f"{event}")
146-
# import traceback
147-
# traceback.print_stack()
148-
# yield event
149107
if settings.core_tracing.drop_inprocess_spans or settings.core_tracing.enabled:
150108
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)
151109
start_time = time.time()

newrelic/core/root_node.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
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
42+
#if not span:
43+
# return None
4444
i_attrs = span[0]
4545
i_attrs["transaction.name"] = self.path
4646
i_attrs["nr.entryPoint"] = True

newrelic/core/stats_engine.py

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -453,11 +453,7 @@ def __init__(self, capacity=100):
453453
self.heap = False
454454
self.capacity = capacity
455455
self.num_seen = 0
456-
self.ft_seen = 0
457-
self.ft_sent = 0
458456
self.bytes = 0
459-
self.ft_bytes = 0
460-
self.ct_bytes = 0
461457
self.ct_processing_time = 0
462458

463459
if capacity <= 0:
@@ -467,29 +463,9 @@ def add(*args, **kwargs):
467463

468464
self.add = add
469465

470-
@property
471-
def ft_samples(self):
472-
return (x[-1] for x in self.pq if is_ft(x[-1]))
473-
474-
def is_ft(self, sample):
475-
# It's a FT span if it's an exit or entry span.
476-
return (len(sample) > 3 and sample[3]) or not sample[0].get("parentId")
477-
478466
def add(self, sample, priority=None):
479467
self.num_seen += 1
480468
self.bytes += objsize.get_deep_size(sample[:-1])
481-
is_ft = self.is_ft(sample)
482-
entity_relationship_attrs = sample[3] if len(sample) > 3 else {}
483-
if is_ft:
484-
self.ft_seen += 1
485-
# The last index contains the set of entity synthesis attrs in the span.
486-
self.ft_bytes += objsize.get_deep_size([sample[0], sample[1], sample[2]])
487-
488-
i_ct_attrs = {"type", "name", "guid", "parentId", "transaction.name", "traceId", "nr.entryPoint", "transactionId"}
489-
i_attrs = {attr: value for attr, value in sample[0].items() if attr in sample[0]}
490-
u_attrs = {}
491-
a_attrs = {attr: value for attr, value in sample[2].items() if attr in entity_relationship_attrs}
492-
self.ct_bytes += objsize.get_deep_size([i_attrs, u_attrs, a_attrs])
493469

494470
if priority is None:
495471
priority = random.random() # noqa: S311
@@ -498,12 +474,8 @@ def add(self, sample, priority=None):
498474
if self.num_seen == self.capacity:
499475
self.pq.append(entry)
500476
self.heap = self.heap or heapify(self.pq) or True
501-
if is_ft:
502-
self.ft_sent += 1
503477
elif not self.heap:
504478
self.pq.append(entry)
505-
if is_ft:
506-
self.ft_sent += 1
507479
else:
508480
sampled = self.should_sample(priority)
509481
if not sampled:
@@ -1265,12 +1237,13 @@ def record_transaction(self, transaction):
12651237
if settings.infinite_tracing.enabled:
12661238
ct_processing_time = 0
12671239
for event in transaction.span_protos(settings, ct_processing_time=ct_processing_time):
1240+
print(event.intrinsics["name"])
12681241
self._span_stream.put(event)
12691242
self._span_stream._ct_processing_time += ct_processing_time
12701243
elif transaction.sampled:
12711244
ct_processing_time = 0
12721245
for event in transaction.span_events(self.__settings, ct_processing_time=ct_processing_time):
1273-
print(event)
1246+
print(event[0]["name"])
12741247
self._span_events.add(event, priority=transaction.priority)
12751248
self._span_events.ct_processing_time += ct_processing_time
12761249

newrelic/core/transaction_node.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -620,9 +620,9 @@ def _add_call_count(source, target):
620620

621621
return intrinsics
622622

623-
def span_protos(self, settings, ct_process_time=0):
624-
for span in self.span_events(settings, attr_class=SpanProtoAttrs, ct_process_time=ct_process_time):
625-
yield Span(trace_id=self.trace_id, intrinsics=span[0], user_attributes=span[1], agent_attributes=span[2]), span[3]
623+
def span_protos(self, settings, ct_processing_time=0):
624+
for span in self.span_events(settings, attr_class=SpanProtoAttrs, ct_processing_time=ct_processing_time):
625+
yield Span(trace_id=self.trace_id, intrinsics=span[0], user_attributes=span[1], agent_attributes=span[2])
626626

627627
def span_events(self, settings, attr_class=dict, ct_processing_time=0):
628628
base_attrs = attr_class(

0 commit comments

Comments
 (0)