Open Rishabh-V opened 1 year ago
Tagging subscribers to this area: @tarekgh, @tommcdon, @pjanotti See info in area-owners.md if you want to be subscribed.
Author: | Rishabh-V |
---|---|
Assignees: | - |
Labels: | `area-System.Diagnostics.Tracing` |
Milestone: | - |
Tagging subscribers to this area: @dotnet/area-system-diagnostics-activity See info in area-owners.md if you want to be subscribed.
Author: | Rishabh-V |
---|---|
Assignees: | - |
Labels: | `untriaged`, `area-System.Diagnostics.Activity` |
Milestone: | - |
Please call out if I am doing or expecting something unreasonable.
You are not doing anything wrong. This is a corner case. For now, if you want to work around the issue, try to compare ActivityTraceId.ToHexString
which should work fine in all cases.
You are not doing anything wrong. This is a corner case. For now, if you want to work around the issue, try to compare
ActivityTraceId.ToHexString
which should work fine in all cases.
Thanks for a quick response. Given ToString()
internally calls ToHexString()
, so I think, ToString()
should work equally well, which I am using currently. Thanks.
Description
I suspect that there is an issue with the way equality is implemented in
ActivityTraceId
. If the activity.TraceId has a default value and we use either the==
operator orEquals
method to compare it with the defaultActivityTraceId
, it always seems to returns false. This behavior is unexpected and can lead to bugs in applications that rely on this comparison.Using F12 on Visual Studio to see the definition of
ActivityTraceId
, I noticed that it internally uses _hexString to calculate HashCode and forEquals
and==
implementation. When we usedefault
, the _hexString is uninitialized which causes this comparison to fail.Please call out if I am doing or expecting something unreasonable. Thanks.
Reproduction Steps
Activity
object with a defaultActivityTraceId
.activity.TraceId
with the defaultActivityTraceId
using the==
operator orEquals
method.false
, even though theTraceId
property of the activity is set to the default value.Here is a simple xUnit Test to demonstrate the same. (My library targets .NET Standard 2.1 and uses .NET 6.)
Expected behavior
When comparing the
activity.TraceId
with the defaultActivityTraceId
using the==
operator orEquals
method, the comparison should return true if theactivity.TraceId
has the default value.`Actual behavior
When comparing the
activity.TraceId
with the defaultActivityTraceId
using the==
operator orEquals
method, the comparison always returnsfalse
, even if theactivity.TraceId
has the default value.Regression?
No response
Known Workarounds
Use
ToString()
and then compare.Configuration
Other information
No response