Open nblumhardt opened 6 months ago
Tagging subscribers to this area: @dotnet/area-system-diagnostics-activity See info in area-owners.md if you want to be subscribed.
This is similar/duplicate of https://github.com/dotnet/runtime/issues/85198 I guess.
Description
In .NET 8,
System.Diagnostics.Activity.SetParentId()
enables calling the internalActivitySpanId
constructor without checking for the default case"0000000000000000"
.This breaks an implied invariant exploited by
ActivitySpanId.operator==
, where"0000000000000000"
is expected to map to a null_hexString
, eliminating the cost of ensuringnull == "0000000000000000"
and vice-versa:I hit this because I'd assumed that
activity.ParentSpanId == default
was a valid way to determine whether an activity had a logical W3C parent.Because of the bug, this comparison may return
true
, despite the parent actually being the invalid all-zeroes value.Given the rest of the codebase attempts to protect against creation of
ActivitySpanId
values with non-null, all-zero_hexString
fields, I suspect this is a bug inSetParentId()
:The second line here should probably set
_parentSpanId
tonull
ifspanId
isdefault
.Reproduction Steps
Expected behavior
activity.ParentSpanId == default
should be true in any scenario in whichParentSpanId
is an all-zeroes value.Actual behavior
activity.ParentSpanId == default
is false.Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response