Skip to content

Commit fd43dcf

Browse files
committed
Fix datastore node mixin attributes
1 parent 7f7a878 commit fd43dcf

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

newrelic/core/node_mixin.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,30 @@ def span_event(self, *args, **kwargs):
115115
a_attrs = attrs[2]
116116

117117
i_attrs["category"] = "datastore"
118-
i_attrs["component"] = self.product
119118
i_attrs["span.kind"] = "client"
120119

120+
if self.product:
121+
i_attrs["component"] = a_attrs["db.system"] = attribute.process_user_attribute("db.system", self.product)[1]
122+
if self.operation:
123+
a_attrs["db.operation"] = attribute.process_user_attribute("db.operation", self.operation)[1]
124+
if self.target:
125+
a_attrs["db.collection"] = attribute.process_user_attribute("db.collection", self.target)[1]
126+
121127
if self.instance_hostname:
122-
_, a_attrs["peer.hostname"] = attribute.process_user_attribute("peer.hostname", self.instance_hostname)
128+
peer_hostname = attribute.process_user_attribute("peer.hostname", self.instance_hostname)[1]
123129
else:
124-
a_attrs["peer.hostname"] = "Unknown"
130+
peer_hostname = "Unknown"
131+
132+
a_attrs["peer.hostname"] = a_attrs["server.address"] = peer_hostname
133+
134+
peer_address = f"{peer_hostname}:{self.port_path_or_id or 'Unknown'}"
125135

126-
peer_address = f"{self.instance_hostname or 'Unknown'}:{self.port_path_or_id or 'Unknown'}"
136+
a_attrs["peer.address"] = attribute.process_user_attribute("peer.address", peer_address)[1]
127137

128-
_, a_attrs["peer.address"] = attribute.process_user_attribute("peer.address", peer_address)
138+
# Attempt to treat port_path_or_id as an integer, fallback to not including it
139+
try:
140+
a_attrs["server.port"] = int(self.port_path_or_id)
141+
except Exception:
142+
pass
129143

130144
return attrs

0 commit comments

Comments
 (0)