17
17
18
18
19
19
class GenericNodeMixin :
20
+ def __init__ (self , * args , ** kwargs ):
21
+ self .ids = []
22
+
20
23
@property
21
24
def processed_user_attributes (self ):
22
25
if hasattr (self , "_processed_user_attributes" ):
@@ -49,7 +52,9 @@ def get_trace_segment_params(self, settings, params=None):
49
52
_params ["exclusive_duration_millis" ] = 1000.0 * self .exclusive
50
53
return _params
51
54
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 = {}
53
58
i_attrs = base_attrs and base_attrs .copy () or attr_class ()
54
59
i_attrs ["type" ] = "Span"
55
60
i_attrs ["name" ] = self .name
@@ -74,85 +79,85 @@ def span_event(self, settings, base_attrs=None, parent_guid=None, attr_class=dic
74
79
exit_span_attrs_present = attribute .SPAN_ENTITY_RELATIONSHIP_ATTRIBUTES & set (a_attrs )
75
80
if settings .core_tracing .drop_inprocess_spans or settings .core_tracing .enabled :
76
81
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 = {}
77
86
return [i_attrs , u_attrs , a_attrs , exit_span_attrs_present ]
78
87
if not exit_span_attrs_present :
79
88
return None
80
89
if settings .core_tracing .enabled :
81
90
start_time = time .time ()
82
- i_attrs ["ids" ] = [] # This is the list of span guids that share this unqiue exit span.
83
91
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
99
105
return [i_attrs , u_attrs , a_attrs , exit_span_attrs_present ]
100
106
101
107
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 )
146
151
start_time = time .time ()
147
152
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 .
149
154
yield span
150
155
parent_id = self .guid
151
156
for child in self .children :
152
157
for event in child .span_events ( # noqa: UP028
153
158
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
154
159
):
155
- if event :
160
+ if event : # event will be None if the span is an inprocess span or repeated exit span.
156
161
yield event
157
162
else :
158
163
yield self .span_event (settings , base_attrs = base_attrs , parent_guid = parent_guid , attr_class = attr_class )
0 commit comments