Skip to content

Commit f0ccf89

Browse files
committed
Add logic for dropping inprocess spans
1 parent 423e028 commit f0ccf89

File tree

6 files changed

+62
-6
lines changed

6 files changed

+62
-6
lines changed

newrelic/core/attribute.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,23 @@
9898
"server.address",
9999
}
100100

101+
SPAN_ENTITY_RELATIONSHIP_ATTRIBUTES = {
102+
"cloud.account.id",
103+
"cloud.platform",
104+
"cloud.region",
105+
"cloud.resource_id",
106+
"db.instance",
107+
"db.system",
108+
"http.url",
109+
"messaging.destination.name",
110+
"messaging.system",
111+
"peer.hostname",
112+
"server.address",
113+
"server.port",
114+
"span.kind",
115+
}
116+
117+
101118
MAX_NUM_USER_ATTRIBUTES = 128
102119
MAX_ATTRIBUTE_LENGTH = 255
103120
MAX_NUM_ML_USER_ATTRIBUTES = 64

newrelic/core/external_node.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ def trace_node(self, stats, root, connections):
172172
def span_event(self, *args, **kwargs):
173173
self.agent_attributes["http.url"] = self.http_url
174174
attrs = super().span_event(*args, **kwargs)
175+
if not attrs:
176+
return None
175177
i_attrs = attrs[0]
176178

177179
i_attrs["category"] = "http"

newrelic/core/function_node.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ def trace_node(self, stats, root, connections):
116116

117117
def span_event(self, *args, **kwargs):
118118
attrs = super().span_event(*args, **kwargs)
119+
if not attrs:
120+
return None
119121
i_attrs = attrs[0]
120122

121123
i_attrs["name"] = f"{self.group}/{self.name}"

newrelic/core/loop_node.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ def trace_node(self, stats, root, connections):
8181

8282
def span_event(self, *args, **kwargs):
8383
attrs = super().span_event(*args, **kwargs)
84+
if not attrs:
85+
return None
8486
i_attrs = attrs[0]
8587

8688
i_attrs["name"] = f"EventLoop/Wait/{self.name}"

newrelic/core/node_mixin.py

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,38 @@ def span_event(self, settings, base_attrs=None, parent_guid=None, attr_class=dic
7070
)
7171

7272
# intrinsics, user attrs, agent attrs
73+
if settings.core_tracing.drop_inprocess_spans:
74+
if not parent_guid:
75+
return [i_attrs, u_attrs, a_attrs]
76+
set_inprocess_attrs = set(attribute.SPAN_ENTITY_RELATIONSHIP_ATTRIBUTES)
77+
set_a_attrs = set(a_attrs)
78+
exit_span_attrs_present = set_inprocess_attrs & set_a_attrs
79+
if not exit_span_attrs_present:
80+
return None
7381
return [i_attrs, u_attrs, a_attrs]
7482

7583
def span_events(self, settings, base_attrs=None, parent_guid=None, attr_class=dict):
76-
yield self.span_event(settings, base_attrs=base_attrs, parent_guid=parent_guid, attr_class=attr_class)
84+
if settings.core_tracing.drop_inprocess_spans:
85+
span = self.span_event(settings, base_attrs=base_attrs, parent_guid=parent_guid, attr_class=attr_class)
86+
parent_id = parent_guid
87+
if span: # span will be None if the span is an inprocess span.
88+
yield span
89+
parent_id = self.guid
90+
91+
for child in self.children:
92+
for event in child.span_events( # noqa: UP028
93+
settings, base_attrs=base_attrs, parent_guid=parent_id, attr_class=attr_class
94+
):
95+
if event:
96+
yield event
97+
else:
98+
yield self.span_event(settings, base_attrs=base_attrs, parent_guid=parent_guid, attr_class=attr_class)
7799

78-
for child in self.children:
79-
for event in child.span_events( # noqa: UP028
80-
settings, base_attrs=base_attrs, parent_guid=self.guid, attr_class=attr_class
81-
):
82-
yield event
100+
for child in self.children:
101+
for event in child.span_events( # noqa: UP028
102+
settings, base_attrs=base_attrs, parent_guid=self.guid, attr_class=attr_class
103+
):
104+
yield event
83105

84106

85107
class DatastoreNodeMixin(GenericNodeMixin):
@@ -141,4 +163,13 @@ def span_event(self, *args, **kwargs):
141163
except Exception:
142164
pass
143165

166+
# intrinsics, user attrs, agent attrs
167+
if settings.core_tracing.drop_inprocess_spans:
168+
if not parent_guid:
169+
return [i_attrs, u_attrs, a_attrs]
170+
set_inprocess_attrs = set(attribute.SPAN_ENTITY_RELATIONSHIP_ATTRIBUTES)
171+
set_a_attrs = set(a_attrs)
172+
exit_span_attrs_present = set_inprocess_attrs & set_a_attrs
173+
if not exit_span_attrs_present:
174+
return None
144175
return attrs

newrelic/core/root_node.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +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
4244
i_attrs = span[0]
4345
i_attrs["transaction.name"] = self.path
4446
i_attrs["nr.entryPoint"] = True

0 commit comments

Comments
 (0)