Skip to content

Commit b5d8cf3

Browse files
authored
Merge branch 'develop-hybrid-core-tracing' into hybrid-agent-span-links
2 parents 858a3b1 + c3b60d4 commit b5d8cf3

File tree

4 files changed

+37
-39
lines changed

4 files changed

+37
-39
lines changed

newrelic/core/attribute.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@
8787
"message.routingKey",
8888
"messaging.destination.name",
8989
"messaging.system",
90-
"nr.durations",
91-
"nr.ids",
92-
"nr.pg",
9390
"peer.address",
9491
"peer.hostname",
9592
"request.headers.accept",

newrelic/core/node_mixin.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def _span_event_partial_granularity_reduced(
102102
# If this is an entry span, add `nr.pg` to indicate transaction is partial
103103
# granularity sampled.
104104
if i_attrs.get("nr.entryPoint"):
105-
a_attrs["nr.pg"] = True
105+
i_attrs["nr.pg"] = True
106106
# If this is the entry node or an LLM span always return it.
107107
if i_attrs.get("nr.entryPoint") or i_attrs["name"].startswith("Llm/"):
108108
ct_exit_spans["kept"] += 1
@@ -143,13 +143,13 @@ def _span_event_partial_granularity_essential(
143143
# If this is an entry span, add `nr.pg` to indicate transaction is partial
144144
# granularity sampled.
145145
if i_attrs.get("nr.entryPoint"):
146-
a_attrs["nr.pg"] = True
146+
i_attrs["nr.pg"] = True
147147
# If this is the entry node or an LLM span always return it.
148148
if i_attrs.get("nr.entryPoint") or i_attrs["name"].startswith("Llm/"):
149149
ct_exit_spans["kept"] += 1
150-
# Only keep `nr.pg`, entity-synthesis, and error agent attributes, and intrinsics.
150+
# Only keep entity-synthesis and error agent attributes, and intrinsics.
151151
a_minimized_attrs = attribute.resolve_agent_attributes(
152-
{key: a_attrs[key] for key in exit_span_attrs_present | exit_span_error_attrs_present | {"nr.pg"}},
152+
{key: a_attrs[key] for key in exit_span_attrs_present | exit_span_error_attrs_present},
153153
settings.attribute_filter,
154154
DST_SPAN_EVENTS,
155155
attr_class=attr_class,
@@ -195,13 +195,13 @@ def _span_event_partial_granularity_compact(
195195
# If this is an entry span, add `nr.pg` to indicate transaction is partial
196196
# granularity sampled.
197197
if i_attrs.get("nr.entryPoint"):
198-
a_attrs["nr.pg"] = True
198+
i_attrs["nr.pg"] = True
199199
# If this is the entry node or an LLM span always return it.
200200
if i_attrs.get("nr.entryPoint") or i_attrs["name"].startswith("Llm/"):
201201
ct_exit_spans["kept"] += 1
202-
# Only keep `nr.pg`, entity-synthesis, and error agent attributes, and intrinsics.
202+
# Only keep entity-synthesis and error agent attributes, and intrinsics.
203203
a_minimized_attrs = attribute.resolve_agent_attributes(
204-
{key: a_attrs[key] for key in exit_span_attrs_present | exit_span_error_attrs_present | {"nr.pg"}},
204+
{key: a_attrs[key] for key in exit_span_attrs_present | exit_span_error_attrs_present},
205205
settings.attribute_filter,
206206
DST_SPAN_EVENTS,
207207
attr_class=attr_class,
@@ -227,8 +227,8 @@ def _span_event_partial_granularity_compact(
227227
# return it.
228228
if new_exit_span:
229229
# nr.ids is the list of span guids that share this unqiue exit span.
230-
a_minimized_attrs["nr.ids"] = []
231-
a_minimized_attrs["nr.durations"] = self.duration
230+
i_attrs["nr.ids"] = []
231+
i_attrs["nr.durations"] = self.duration
232232
ct_exit_spans[span_attrs] = [i_attrs, a_minimized_attrs]
233233
ct_exit_spans["kept"] += 1
234234
# Only keep entity-synthesis, and error agent attributes, and intrinsics.
@@ -241,31 +241,31 @@ def _span_event_partial_granularity_compact(
241241
attr_class({key: a_minimized_attrs[key] for key in exit_span_error_attrs_present})
242242
)
243243
# Max size for `nr.ids` = 1024. Max length = 63 (each span id is 16 bytes + 8 bytes for list type).
244-
if len(ct_exit_spans[span_attrs][1]["nr.ids"]) < 63:
245-
ct_exit_spans[span_attrs][1]["nr.ids"].append(self.guid)
244+
if len(ct_exit_spans[span_attrs][0]["nr.ids"]) < 63:
245+
ct_exit_spans[span_attrs][0]["nr.ids"].append(self.guid)
246246
else:
247247
ct_exit_spans["dropped_ids"] += 1
248248

249249
# Compute the new start and end time for all compressed spans and use
250250
# that to set the duration for all compressed spans.
251251
current_start_time = ct_exit_spans[span_attrs][0]["timestamp"]
252252
current_end_time = (
253-
ct_exit_spans[span_attrs][0]["timestamp"] / 1000 + ct_exit_spans[span_attrs][1]["nr.durations"]
253+
ct_exit_spans[span_attrs][0]["timestamp"] / 1000 + ct_exit_spans[span_attrs][0]["nr.durations"]
254254
)
255255
new_start_time = i_attrs["timestamp"]
256256
new_end_time = i_attrs["timestamp"] / 1000 + i_attrs["duration"]
257257
set_start_time = min(new_start_time, current_start_time)
258258
# If the new span starts after the old span's end time or the new span
259259
# ends before the current span starts; add the durations.
260260
if current_end_time < new_start_time / 1000 or new_end_time < current_start_time / 1000:
261-
set_duration = ct_exit_spans[span_attrs][1]["nr.durations"] + i_attrs["duration"]
261+
set_duration = ct_exit_spans[span_attrs][0]["nr.durations"] + i_attrs["duration"]
262262
# Otherwise, if the new and old span's overlap in time, use the newest
263263
# end time and subtract the start time from it to calculate the new
264264
# duration.
265265
else:
266266
set_duration = max(current_end_time, new_end_time) - set_start_time / 1000
267267
ct_exit_spans[span_attrs][0]["timestamp"] = set_start_time
268-
ct_exit_spans[span_attrs][1]["nr.durations"] = set_duration
268+
ct_exit_spans[span_attrs][0]["nr.durations"] = set_duration
269269

270270
PARTIAL_GRANULARITY_SPAN_EVENT_METHODS = { # noqa: RUF012
271271
"reduced": _span_event_partial_granularity_reduced,

newrelic/hooks/hybridagent_opentelemetry.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ def wrap__get_span(wrapped, instance, args, kwargs):
272272
value = getattr(properties, _property, None)
273273
if properties and value:
274274
params[_property] = value
275+
275276
span = wrapped(*args, **kwargs)
276277
span.set_attributes(params)
277278

tests/agent_features/test_distributed_tracing.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,14 @@ def _span_details():
143143
user_attrs = captured_event.user_attributes
144144
agent_attrs = captured_event.agent_attributes
145145
else:
146-
intrinsics, _, agent_attrs = captured_event
146+
intrinsics, _, _ = captured_event
147147

148148
# Find the span by name.
149149
if not check_value_equals(intrinsics, "name", name):
150150
continue
151-
assert check_value_length(agent_attrs, "nr.ids", compressed_span_count - 1, mismatches), _span_details()
151+
assert check_value_length(intrinsics, "nr.ids", compressed_span_count - 1, mismatches), _span_details()
152152
assert check_value_between(
153-
agent_attrs,
153+
intrinsics,
154154
"nr.durations",
155155
expected_nr_durations_low_bound,
156156
expected_nr_durations_high_bound,
@@ -946,16 +946,16 @@ async def call_tests():
946946
@validate_span_events(
947947
count=1, # Entry span.
948948
exact_intrinsics={
949-
"name": "Function/test_distributed_tracing:test_partial_granularity_max_compressed_spans.<locals>._test"
949+
"name": "Function/test_distributed_tracing:test_partial_granularity_max_compressed_spans.<locals>._test",
950+
"nr.pg": True,
950951
},
951-
exact_agents={"nr.pg": True},
952952
expected_intrinsics=["duration", "timestamp"],
953953
)
954954
@validate_span_events(
955955
count=1, # 1 external compressed span.
956956
exact_intrinsics={"name": "External/localhost:3000/requests/GET"},
957+
expected_intrinsics=["nr.durations", "nr.ids"],
957958
exact_agents={"http.url": "http://localhost:3000/"},
958-
expected_agents=["nr.durations", "nr.ids"],
959959
)
960960
@validate_compact_span_event(
961961
name="External/localhost:3000/requests/GET",
@@ -1001,16 +1001,16 @@ async def call_tests():
10011001
@validate_span_events(
10021002
count=1, # Entry span.
10031003
exact_intrinsics={
1004-
"name": "Function/test_distributed_tracing:test_partial_granularity_compressed_span_attributes_in_series.<locals>._test"
1004+
"name": "Function/test_distributed_tracing:test_partial_granularity_compressed_span_attributes_in_series.<locals>._test",
1005+
"nr.pg": True,
10051006
},
1006-
exact_agents={"nr.pg": True},
10071007
expected_intrinsics=["duration", "timestamp"],
10081008
)
10091009
@validate_span_events(
10101010
count=1, # 1 external compressed span.
10111011
exact_intrinsics={"name": "External/localhost:3000/requests/GET"},
1012+
expected_intrinsics=["nr.durations", "nr.ids"],
10121013
exact_agents={"http.url": "http://localhost:3000/"},
1013-
expected_agents=["nr.durations", "nr.ids"],
10141014
)
10151015
@validate_compact_span_event(
10161016
name="External/localhost:3000/requests/GET",
@@ -1046,16 +1046,16 @@ def test_partial_granularity_compressed_span_attributes_overlapping():
10461046
@validate_span_events(
10471047
count=1, # Entry span.
10481048
exact_intrinsics={
1049-
"name": "Function/test_distributed_tracing:test_partial_granularity_compressed_span_attributes_overlapping.<locals>._test"
1049+
"name": "Function/test_distributed_tracing:test_partial_granularity_compressed_span_attributes_overlapping.<locals>._test",
1050+
"nr.pg": True,
10501051
},
1051-
exact_agents={"nr.pg": True},
10521052
expected_intrinsics=["duration", "timestamp"],
10531053
)
10541054
@validate_span_events(
10551055
count=1, # 1 external compressed span.
10561056
exact_intrinsics={"name": "External/localhost:3000/requests/GET"},
1057+
expected_intrinsics=["nr.durations", "nr.ids"],
10571058
exact_agents={"http.url": "http://localhost:3000/"},
1058-
expected_agents=["nr.durations", "nr.ids"],
10591059
)
10601060
@validate_compact_span_event(
10611061
name="External/localhost:3000/requests/GET",
@@ -1101,9 +1101,9 @@ def foo():
11011101
@validate_span_events(
11021102
count=1, # Entry span.
11031103
exact_intrinsics={
1104-
"name": "Function/test_distributed_tracing:test_partial_granularity_reduced_span_attributes.<locals>._test"
1104+
"name": "Function/test_distributed_tracing:test_partial_granularity_reduced_span_attributes.<locals>._test",
1105+
"nr.pg": True,
11051106
},
1106-
exact_agents={"nr.pg": True},
11071107
expected_intrinsics=["duration", "timestamp"],
11081108
expected_agents=["code.function", "code.lineno", "code.namespace"],
11091109
)
@@ -1156,9 +1156,9 @@ def foo():
11561156
@validate_span_events(
11571157
count=1, # Entry span.
11581158
exact_intrinsics={
1159-
"name": "Function/test_distributed_tracing:test_partial_granularity_essential_span_attributes.<locals>._test"
1159+
"name": "Function/test_distributed_tracing:test_partial_granularity_essential_span_attributes.<locals>._test",
1160+
"nr.pg": True,
11601161
},
1161-
exact_agents={"nr.pg": True},
11621162
expected_intrinsics=["duration", "timestamp"],
11631163
unexpected_agents=["code.function", "code.lineno", "code.namespace"],
11641164
)
@@ -1491,21 +1491,21 @@ def call_tests():
14911491
@validate_span_events(
14921492
count=1, # Entry span.
14931493
exact_intrinsics={
1494-
"name": "Function/test_distributed_tracing:test_partial_granularity_errors_on_compressed_spans.<locals>._test"
1494+
"name": "Function/test_distributed_tracing:test_partial_granularity_errors_on_compressed_spans.<locals>._test",
1495+
"nr.pg": True,
14951496
},
1496-
exact_agents={"nr.pg": True},
14971497
expected_intrinsics=["duration", "timestamp"],
14981498
)
14991499
@validate_span_events(
15001500
count=1, # 1 external compressed span.
15011501
exact_intrinsics={"name": "External/localhost:3000/requests/GET"},
1502+
expected_intrinsics=["nr.durations", "nr.ids"],
15021503
exact_agents={
15031504
"http.url": "http://localhost:3000/",
15041505
"error.class": callable_name(Exception),
15051506
"error.message": "Exception 2",
15061507
"error.expected": True,
15071508
},
1508-
expected_agents=["nr.durations", "nr.ids"],
15091509
)
15101510
@validate_compact_span_event(
15111511
name="External/localhost:3000/requests/GET",
@@ -1554,21 +1554,21 @@ def call_tests():
15541554
@validate_span_events(
15551555
count=1, # Entry span.
15561556
exact_intrinsics={
1557-
"name": "Function/test_distributed_tracing:test_partial_granularity_errors_on_compressed_spans_status_overriden.<locals>._test"
1557+
"name": "Function/test_distributed_tracing:test_partial_granularity_errors_on_compressed_spans_status_overriden.<locals>._test",
1558+
"nr.pg": True,
15581559
},
1559-
exact_agents={"nr.pg": True},
15601560
expected_intrinsics=["duration", "timestamp"],
15611561
)
15621562
@validate_span_events(
15631563
count=1, # 1 external compressed span.
15641564
exact_intrinsics={"name": "External/localhost:3000/requests/GET"},
1565+
expected_intrinsics=["nr.durations", "nr.ids"],
15651566
exact_agents={
15661567
"http.url": "http://localhost:3000/",
15671568
"error.class": callable_name(Exception),
15681569
"error.message": "Exception 2",
15691570
"error.expected": False,
15701571
},
1571-
expected_agents=["nr.durations", "nr.ids"],
15721572
)
15731573
@validate_compact_span_event(
15741574
name="External/localhost:3000/requests/GET",

0 commit comments

Comments
 (0)