Skip to content

Commit 41bd7d5

Browse files
committed
Fixup-working
1 parent 557a020 commit 41bd7d5

File tree

2 files changed

+70
-65
lines changed

2 files changed

+70
-65
lines changed

newrelic/core/node_mixin.py

Lines changed: 68 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818

1919
class GenericNodeMixin:
20+
def __init__(self, *args, **kwargs):
21+
self.ids = []
22+
2023
@property
2124
def processed_user_attributes(self):
2225
if hasattr(self, "_processed_user_attributes"):
@@ -49,7 +52,9 @@ def get_trace_segment_params(self, settings, params=None):
4952
_params["exclusive_duration_millis"] = 1000.0 * self.exclusive
5053
return _params
5154

52-
def span_event(self, settings, base_attrs=None, parent_guid=None, attr_class=dict):
55+
def span_event(self, settings, base_attrs=None, parent_guid=None, attr_class=dict, ct_exit_spans=None, ct_processing_time=0):
56+
if ct_exit_spans is None:
57+
ct_exit_spans = {}
5358
i_attrs = base_attrs and base_attrs.copy() or attr_class()
5459
i_attrs["type"] = "Span"
5560
i_attrs["name"] = self.name
@@ -74,85 +79,85 @@ def span_event(self, settings, base_attrs=None, parent_guid=None, attr_class=dic
7479
exit_span_attrs_present = attribute.SPAN_ENTITY_RELATIONSHIP_ATTRIBUTES & set(a_attrs)
7580
if settings.core_tracing.drop_inprocess_spans or settings.core_tracing.enabled:
7681
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 = {}
7786
return [i_attrs, u_attrs, a_attrs, exit_span_attrs_present]
7887
if not exit_span_attrs_present:
7988
return None
8089
if settings.core_tracing.enabled:
8190
start_time = time.time()
82-
i_attrs["ids"] = [] # This is the list of span guids that share this unqiue exit span.
8391
parent_id = parent_guid
84-
if span: # span will be None if the span is an inprocess span.
85-
span_attrs = "".join([span[2][key] for key in exit_spans])
86-
new_exit_span = span_attrs not in ct_exit_spans
87-
if parent_id: # If this is not the entry span.
88-
if new_exit_span:
89-
ct_exit_spans[span_attrs] = span
90-
else:
91-
ct_exit_spans[span_attrs][0]["ids"].append(span[0]["guid"])
92-
ct_processing_time += (time.time() - start_time)
93-
#print(f"parent {span[0]['traceId']} {parent_id} {span[0]['name']} {new_exit_span}")
94-
if not parent_id or new_exit_span:
95-
#print(f"{span}")
96-
import traceback
97-
traceback.print_stack()
98-
yield span
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])
95+
new_exit_span = span_attrs not in ct_exit_spans
96+
if new_exit_span:
97+
ct_exit_spans[span_attrs] = self.ids
98+
else:
99+
# For now add ids to user attributes list
100+
ct_exit_spans[span_attrs].append(self.guid)
101+
ct_processing_time += (time.time() - start_time)
102+
if new_exit_span:
103+
return span
104+
return None
99105
return [i_attrs, u_attrs, a_attrs, exit_span_attrs_present]
100106

101107
def span_events(self, settings, base_attrs=None, parent_guid=None, attr_class=dict, ct_exit_spans=None, ct_processing_time=0):
102-
if settings.core_tracing.enabled:
103-
if ct_exit_spans is None:
104-
ct_exit_spans = {}
105-
span = self.span_event(settings, base_attrs=base_attrs, parent_guid=parent_guid, attr_class=attr_class)
106-
start_time = time.time()
107-
parent_id = parent_guid
108-
if span: # span will be None if the span is an inprocess span.
109-
span_attrs = "".join([span[2][key] for key in span[3]])
110-
new_exit_span = span_attrs not in ct_exit_spans
111-
if parent_id: # If this is not the entry span.
112-
if new_exit_span:
113-
ct_exit_spans[span_attrs] = span
114-
else:
115-
ct_exit_spans[span_attrs][0]["ids"].append(span[0]["guid"])
116-
ct_processing_time += (time.time() - start_time)
117-
#print(f"parent {span[0]['traceId']} {parent_id} {span[0]['name']} {new_exit_span}")
118-
if not parent_id or new_exit_span:
119-
#print(f"{span}")
120-
import traceback
121-
traceback.print_stack()
122-
yield span
123-
parent_id = self.guid
124-
for child in self.children:
125-
for event in child.span_events( # noqa: UP028
126-
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
127-
):
128-
if event:
129-
start_time = time.time()
130-
span_attrs = "".join([event[2][key] for key in event[3]])
131-
new_exit_span = span_attrs not in ct_exit_spans
132-
if new_exit_span:
133-
ct_exit_spans[span_attrs] = event
134-
else:
135-
ct_exit_spans[span_attrs][0]["ids"].append(event[0]["guid"])
136-
ct_processing_time += (time.time() - start_time)
137-
#print(f"child {event[0]['traceId']} {parent_id} {event[0]['name']} {new_exit_span}")
138-
if new_exit_span:
139-
#print(f"{event}")
140-
import traceback
141-
traceback.print_stack()
142-
yield event
143-
elif settings.core_tracing.drop_inprocess_spans:
144-
ct_exit_spans = ct_exit_spans or {}
145-
span = self.span_event(settings, base_attrs=base_attrs, parent_guid=parent_guid, attr_class=attr_class)
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
149+
if settings.core_tracing.drop_inprocess_spans or settings.core_tracing.enabled:
150+
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)
146151
start_time = time.time()
147152
parent_id = parent_guid
148-
if span: # span will be None if the span is an inprocess span.
153+
if span: # span will be None if the span is an inprocess span or repeated exit span.
149154
yield span
150155
parent_id = self.guid
151156
for child in self.children:
152157
for event in child.span_events( # noqa: UP028
153158
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
154159
):
155-
if event:
160+
if event: # event will be None if the span is an inprocess span or repeated exit span.
156161
yield event
157162
else:
158163
yield self.span_event(settings, base_attrs=base_attrs, parent_guid=parent_guid, attr_class=attr_class)

newrelic/core/transaction_node.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,5 +633,5 @@ def span_events(self, settings, attr_class=dict, ct_processing_time=0):
633633
("priority", self.priority),
634634
)
635635
)
636-
637-
yield from self.root.span_events(settings, base_attrs, parent_guid=self.parent_span, attr_class=attr_class, ct_processing_time=ct_processing_time)
636+
ct_exit_spans = {}
637+
yield from self.root.span_events(settings, base_attrs, parent_guid=self.parent_span, attr_class=attr_class, ct_exit_spans=ct_exit_spans, ct_processing_time=ct_processing_time)

0 commit comments

Comments
 (0)