Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion newrelic/common/encoding_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,8 @@ def text(self):
pr = f"{pr:.6f}".rstrip("0").rstrip(".")
version = self.get("v", "0")
ty = "0" # Hardcode this as it will always be App.
payload = f"{version}-{ty}-{self['ac']}-{self['ap']}-{self.get('id', '')}-{self.get('tx', '')}-{'1' if self.get('sa') else '0'}-{pr}-{self['ti']!s}"
# Do not send the span id-this has been deprecated.
payload = f"{version}-{ty}-{self['ac']}-{self['ap']}--{self.get('tx', '')}-{'1' if self.get('sa') else '0'}-{pr}-{self['ti']!s}"
return f"{self.get('tk', self['ac'])}@nr={payload}"

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion tests/agent_features/test_asgi_w3c_trace_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def _test():
"0.4" if inbound_nr_tracestate else "1.2",
]

assert len(fields[4]) == 16
assert len(fields[4]) == 0
assert len(fields[5]) == 16


Expand Down
2 changes: 1 addition & 1 deletion tests/agent_features/test_w3c_trace_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def _test():
"0.4" if inbound_nr_tracestate else "1.2",
]

assert len(fields[4]) == 16
assert len(fields[4]) == 0
assert len(fields[5]) == 16


Expand Down
71 changes: 48 additions & 23 deletions tests/cross_agent/fixtures/distributed_tracing/trace_context.json
Original file line number Diff line number Diff line change
Expand Up @@ -998,10 +998,12 @@
},
"expected": [
"traceparent.parent_id",
"tracestate.span_id",
"tracestate.transaction_id",
"tracestate.timestamp",
"tracestate.parent_application_id"
],
"unexpected": [
"tracestate.span_id"
]
}
],
Expand Down Expand Up @@ -1131,9 +1133,11 @@
"traceparent.parent_id",
"tracestate.timestamp",
"tracestate.parent_application_id",
"tracestate.span_id",
"tracestate.transaction_id"
],
"unexpected": [
"tracestate.span_id"
],
"notequal": {
"traceparent.parent_id": "7d3efb1b173fecfa"
}
Expand Down Expand Up @@ -1560,10 +1564,12 @@
},
"expected": [
"traceparent.parent_id",
"tracestate.span_id",
"tracestate.transaction_id",
"tracestate.timestamp",
"tracestate.parent_application_id"
],
"unexpected": [
"tracestate.span_id"
]
}
],
Expand Down Expand Up @@ -1638,10 +1644,12 @@
},
"expected": [
"traceparent.parent_id",
"tracestate.span_id",
"tracestate.transaction_id",
"tracestate.timestamp",
"tracestate.parent_application_id"
],
"unexpected": [
"tracestate.span_id"
]
},
{
Expand All @@ -1658,10 +1666,12 @@
},
"expected": [
"traceparent.parent_id",
"tracestate.span_id",
"tracestate.transaction_id",
"tracestate.timestamp",
"tracestate.parent_application_id"
],
"unexpected": [
"tracestate.span_id"
]
}
],
Expand Down Expand Up @@ -1736,10 +1746,12 @@
},
"expected": [
"traceparent.parent_id",
"tracestate.span_id",
"tracestate.transaction_id",
"tracestate.timestamp",
"tracestate.parent_application_id"
],
"unexpected": [
"tracestate.span_id"
]
}
],
Expand Down Expand Up @@ -1901,10 +1913,12 @@
},
"expected": [
"traceparent.parent_id",
"tracestate.span_id",
"tracestate.transaction_id",
"tracestate.timestamp",
"tracestate.parent_application_id"
],
"unexpected": [
"tracestate.span_id"
]
}
],
Expand Down Expand Up @@ -2217,13 +2231,15 @@
"expected": [
"traceparent.trace_flags",
"traceparent.parent_id",
"tracestate.span_id",
"tracestate.transaction_id",
"tracestate.parent_application_id",
"tracestate.timestamp",
"tracestate.sampled",
"tracestate.priority"
],
"unexpected": [
"tracestate.span_id"
],
"vendors": [
"foo",
"bar"
Expand Down Expand Up @@ -2301,12 +2317,14 @@
"expected": [
"traceparent.trace_flags",
"traceparent.parent_id",
"tracestate.span_id",
"tracestate.transaction_id",
"tracestate.parent_application_id",
"tracestate.timestamp",
"tracestate.sampled",
"tracestate.priority"
],
"unexpected": [
"tracestate.span_id"
]
}
],
Expand Down Expand Up @@ -2382,13 +2400,15 @@
"traceparent.trace_id",
"traceparent.trace_flags",
"traceparent.parent_id",
"tracestate.span_id",
"tracestate.transaction_id",
"tracestate.parent_application_id",
"tracestate.timestamp",
"tracestate.sampled",
"tracestate.priority"
],
"unexpected": [
"tracestate.span_id"
],
"vendors": [
]
}
Expand Down Expand Up @@ -2423,12 +2443,14 @@
"traceparent.trace_id",
"traceparent.trace_flags",
"traceparent.parent_id",
"tracestate.span_id",
"tracestate.transaction_id",
"tracestate.parent_application_id",
"tracestate.timestamp",
"tracestate.sampled",
"tracestate.priority"
],
"unexpected": [
"tracestate.span_id"
]
}
],
Expand Down Expand Up @@ -2467,11 +2489,13 @@
"expected": [
"traceparent.trace_flags",
"traceparent.parent_id",
"tracestate.span_id",
"tracestate.transaction_id",
"tracestate.parent_application_id",
"tracestate.timestamp"
],
"unexpected": [
"tracestate.span_id"
],
"vendors": [
"44@nr"
]
Expand Down Expand Up @@ -2546,11 +2570,14 @@
"expected": [
"traceparent.trace_flags",
"traceparent.parent_id",
"tracestate.span_id",
"tracestate.transaction_id",
"tracestate.parent_application_id",
"tracestate.timestamp"
] }
],
"unexpected": [
"tracestate.span_id"
]
}
],
"intrinsics": {
"target_events": ["Transaction"],
Expand Down Expand Up @@ -2825,15 +2852,14 @@
"traceparent.parent_id",
"tracestate.timestamp",
"tracestate.parent_application_id",
"tracestate.span_id",
"tracestate.transaction_id",
"newrelic.d.ap",
"newrelic.d.tx",
"newrelic.d.ti",
"newrelic.d.id",
"newrelic.d.pr"
],
"unexpected": ["newrelic.d.tk"]
"unexpected": ["tracestate.span_id", "newrelic.d.tk"]
}
],
"intrinsics": {
Expand Down Expand Up @@ -2904,12 +2930,11 @@
},
"expected": [
"traceparent.parent_id",
"tracestate.span_id",
"tracestate.timestamp",
"tracestate.parent_application_id"
],
"unexpected": [
"tracestate.transaction_id"
"tracestate.span_id", "tracestate.transaction_id"
]
}
],
Expand Down Expand Up @@ -3035,7 +3060,6 @@
"expected": [
"traceparent.trace_flags",
"traceparent.parent_id",
"tracestate.span_id",
"tracestate.transaction_id",
"tracestate.parent_application_id",
"tracestate.timestamp",
Expand All @@ -3044,7 +3068,7 @@
"newrelic.d.ti",
"newrelic.d.id"
],
"unexpected": ["newrelic.d.tk"]
"unexpected": ["tracestate.span_id", "newrelic.d.tk"]
}
],
"expected_metrics": [
Expand Down Expand Up @@ -3088,10 +3112,12 @@
"expected": [
"traceparent.trace_flags",
"traceparent.parent_id",
"tracestate.span_id",
"tracestate.transaction_id",
"tracestate.parent_application_id",
"tracestate.timestamp"
],
"unexpected": [
"tracestate.span_id"
]
}
],
Expand Down Expand Up @@ -3141,7 +3167,6 @@
"expected": [
"traceparent.trace_flags",
"traceparent.parent_id",
"tracestate.span_id",
"tracestate.transaction_id",
"tracestate.parent_application_id",
"tracestate.timestamp",
Expand All @@ -3150,7 +3175,7 @@
"newrelic.d.ti",
"newrelic.d.id"
],
"unexpected": ["newrelic.d.tk"]
"unexpected": ["tracestate.span_id", "newrelic.d.tk"]
}
],
"expected_metrics": [
Expand Down
5 changes: 3 additions & 2 deletions tests/framework_grpc/test_distributed_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ def _test():
# The external span should be the parent
exact_intrinsics["guid"] = w3c_parent["id"]

# Check that tracestate and traceparent agree on the span id / sampled flag
assert nr_tracestate["id"] == w3c_parent["id"]
# Check that traceparent contains the span id
assert w3c_parent["id"]
# Check that tracestate and traceparent agree on the sampled flag
assert nr_tracestate["sa"] == w3c_parent["sa"]

_test()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,9 @@ def validate_distributed_tracing_header():
# Verify data belonging to this transaction
assert data["tx"] == transaction.guid

# If span events are enabled, id should be sent
# otherwise, id should be omitted
if transaction.settings.span_events.enabled:
assert "id" in data
assert data["id"] == w3c_parent["id"]
else:
assert "id" not in data
# span id should not ever be sent.
assert "id" not in data
assert w3c_parent["id"]

# Verify timestamp is an integer
assert isinstance(data["ti"], int)
Expand Down
Loading