|
11 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
14 |
| - |
| 14 | +import time |
15 | 15 | from newrelic.core import attribute
|
16 | 16 | from newrelic.core.attribute_filter import DST_SPAN_EVENTS, DST_TRANSACTION_SEGMENTS
|
17 | 17 |
|
@@ -70,69 +70,90 @@ def span_event(self, settings, base_attrs=None, parent_guid=None, attr_class=dic
|
70 | 70 | )
|
71 | 71 |
|
72 | 72 | # intrinsics, user attrs, agent attrs
|
| 73 | + |
| 74 | + exit_span_attrs_present = attribute.SPAN_ENTITY_RELATIONSHIP_ATTRIBUTES & set(a_attrs) |
73 | 75 | if settings.core_tracing.drop_inprocess_spans or settings.core_tracing.enabled:
|
74 |
| - if not parent_guid: |
75 |
| - return [i_attrs, u_attrs, a_attrs] |
76 |
| - set_inprocess_attrs = attribute.SPAN_ENTITY_RELATIONSHIP_ATTRIBUTES |
77 |
| - set_a_attrs = set(a_attrs) |
78 |
| - exit_span_attrs_present = set_inprocess_attrs & set_a_attrs |
| 76 | + if self.__class__.__name__ == "RootNode": |
| 77 | + return [i_attrs, u_attrs, a_attrs, exit_span_attrs_present] |
79 | 78 | if not exit_span_attrs_present:
|
80 | 79 | return None
|
81 | 80 | if settings.core_tracing.enabled:
|
82 |
| - a_attrs["ids"] = [] # This is the list of span guids that share this unqiue exit span. |
83 |
| - |
84 |
| - set_inprocess_attrs = set(attribute.SPAN_ENTITY_RELATIONSHIP_ATTRIBUTES) |
85 |
| - set_a_attrs = set(a_attrs) |
86 |
| - exit_span_attrs_present = set_inprocess_attrs & set_a_attrs |
87 |
| - return [i_attrs, u_attrs, a_attrs, exit_span_attrs_present] |
88 |
| - |
89 |
| - def span_events(self, settings, base_attrs=None, parent_guid=None, attr_class=dict, ct_exit_spans=None, ct_processing_time=0): |
90 |
| - if settings.core_tracing.drop_inprocess_spans: |
91 |
| - ct_exit_spans = ct_exit_spans or {} |
92 |
| - span = self.span_event(settings, base_attrs=base_attrs, parent_guid=parent_guid, attr_class=attr_class) |
93 | 81 | start_time = time.time()
|
| 82 | + i_attrs["ids"] = [] # This is the list of span guids that share this unqiue exit span. |
94 | 83 | parent_id = parent_guid
|
95 | 84 | if span: # span will be None if the span is an inprocess span.
|
96 |
| - yield span |
97 |
| - parent_id = self.guid |
98 |
| - for child in self.children: |
99 |
| - for event in child.span_events( # noqa: UP028 |
100 |
| - 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 |
101 |
| - ): |
102 |
| - if event: |
103 |
| - yield event |
104 |
| - elif settings.core_tracing.enabled: |
105 |
| - ct_exit_spans = ct_exit_spans or {} |
| 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 |
| 99 | + return [i_attrs, u_attrs, a_attrs, exit_span_attrs_present] |
| 100 | + |
| 101 | + 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 = {} |
106 | 105 | span = self.span_event(settings, base_attrs=base_attrs, parent_guid=parent_guid, attr_class=attr_class)
|
107 | 106 | start_time = time.time()
|
108 | 107 | parent_id = parent_guid
|
109 | 108 | if span: # span will be None if the span is an inprocess span.
|
110 |
| - span_attrs = "".join([value for key, value in span[2].items() if key in attribute.SPAN_ENTITY_RELATIONSHIP_ATTRIBUTES]) |
| 109 | + span_attrs = "".join([span[2][key] for key in span[3]]) |
111 | 110 | new_exit_span = span_attrs not in ct_exit_spans
|
112 | 111 | if parent_id: # If this is not the entry span.
|
113 | 112 | if new_exit_span:
|
114 | 113 | ct_exit_spans[span_attrs] = span
|
115 | 114 | else:
|
116 |
| - ct_exit_spans[span_attrs][2]["ids"] = event[2]["guid"] |
| 115 | + ct_exit_spans[span_attrs][0]["ids"].append(span[0]["guid"]) |
117 | 116 | ct_processing_time += (time.time() - start_time)
|
| 117 | + #print(f"parent {span[0]['traceId']} {parent_id} {span[0]['name']} {new_exit_span}") |
118 | 118 | if not parent_id or new_exit_span:
|
| 119 | + #print(f"{span}") |
| 120 | + import traceback |
| 121 | + traceback.print_stack() |
119 | 122 | yield span
|
120 |
| - parent_id = self.guid |
| 123 | + parent_id = self.guid |
121 | 124 | for child in self.children:
|
122 | 125 | for event in child.span_events( # noqa: UP028
|
123 | 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
|
124 | 127 | ):
|
125 | 128 | if event:
|
126 | 129 | start_time = time.time()
|
127 |
| - span_attrs = "".join([value for key, value in event[2].items() if key in attribute.SPAN_ENTITY_RELATIONSHIP_ATTRIBUTES]) |
| 130 | + span_attrs = "".join([event[2][key] for key in event[3]]) |
128 | 131 | new_exit_span = span_attrs not in ct_exit_spans
|
129 | 132 | if new_exit_span:
|
130 | 133 | ct_exit_spans[span_attrs] = event
|
131 | 134 | else:
|
132 |
| - ct_exit_spans[span_attrs][2]["ids"] = event[2]["guid"] |
| 135 | + ct_exit_spans[span_attrs][0]["ids"].append(event[0]["guid"]) |
133 | 136 | ct_processing_time += (time.time() - start_time)
|
| 137 | + #print(f"child {event[0]['traceId']} {parent_id} {event[0]['name']} {new_exit_span}") |
134 | 138 | if new_exit_span:
|
| 139 | + #print(f"{event}") |
| 140 | + import traceback |
| 141 | + traceback.print_stack() |
135 | 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) |
| 146 | + start_time = time.time() |
| 147 | + parent_id = parent_guid |
| 148 | + if span: # span will be None if the span is an inprocess span. |
| 149 | + yield span |
| 150 | + parent_id = self.guid |
| 151 | + for child in self.children: |
| 152 | + for event in child.span_events( # noqa: UP028 |
| 153 | + 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 | + ): |
| 155 | + if event: |
| 156 | + yield event |
136 | 157 | else:
|
137 | 158 | yield self.span_event(settings, base_attrs=base_attrs, parent_guid=parent_guid, attr_class=attr_class)
|
138 | 159 |
|
|
0 commit comments