_traceIdSet = true;
_parentSpanId = spanId;
_parentSpanIdSet = true;
- _w3CIdFlags = (byte) activityTraceFlags;
+ _w3CIdFlags = (byte)activityTraceFlags;
_w3CIdFlagsSet = true;
}
return this;
{
if (!_w3CIdFlagsSet)
{
- if (Parent != null)
- {
- ActivityTraceFlags = Parent.ActivityTraceFlags;
- }
- else if (_parentId != null && IsW3CId(_parentId))
- {
- _w3CIdFlags = ActivityTraceId.HexByteFromChars(_parentId[53], _parentId[54]);
- _w3CIdFlagsSet = true;
- }
+ _w3CIdFlagsSet = TrySetTraceFlagsFromParent();
}
- return (ActivityTraceFlags) _w3CIdFlags;
+ return (ActivityTraceFlags)_w3CIdFlags;
}
set
{
_traceIdSet = true;
}
}
+
+ if (!_w3CIdFlagsSet)
+ {
+ _w3CIdFlagsSet = TrySetTraceFlagsFromParent();
+ }
+
// Create a new SpanID.
_spanId = ActivitySpanId.CreateRandom();
_spanIdSet = true;
return _traceIdSet;
}
+#if ALLOW_PARTIALLY_TRUSTED_CALLERS
+ [System.Security.SecuritySafeCriticalAttribute]
+#endif
+ private bool TrySetTraceFlagsFromParent()
+ {
+ Debug.Assert(!_w3CIdFlagsSet);
+
+ if (!_w3CIdFlagsSet)
+ {
+ if (Parent != null)
+ {
+ ActivityTraceFlags = Parent.ActivityTraceFlags;
+ }
+ else if (_parentId != null && IsW3CId(_parentId))
+ {
+ _w3CIdFlags = ActivityTraceId.HexByteFromChars(_parentId[53], _parentId[54]);
+ _w3CIdFlagsSet = true;
+ }
+ }
+
+ return _w3CIdFlagsSet;
+ }
+
+
private string _rootId;
private int _currentChildId; // A unique number for all children of this activity.
Assert.Equal("0123456789abcdef0123456789abcdef", activity.TraceId.ToHexString());
Assert.Equal("0123456789abcdef", activity.ParentSpanId.ToHexString());
Assert.True(IdIsW3CFormat(activity.Id));
+ Assert.Equal($"00-0123456789abcdef0123456789abcdef-{activity.SpanId.ToHexString()}-01", activity.Id);
Assert.Equal(ActivityTraceFlags.Recorded, activity.ActivityTraceFlags);
Assert.True(activity.Recorded);
activity.Stop();
Assert.Equal(ActivityIdFormat.W3C, activity.IdFormat);
Assert.Equal(activityTraceId.ToHexString(), activity.TraceId.ToHexString());
Assert.True(IdIsW3CFormat(activity.Id));
+ Assert.Equal($"00-{activity.TraceId.ToHexString()}-{activity.SpanId.ToHexString()}-01", activity.Id);
Assert.Equal(ActivityTraceFlags.Recorded, activity.ActivityTraceFlags);
Assert.True(activity.Recorded);
activity.Stop();
Assert.Equal("0123456789abcdef0123456789abcdef", activity.TraceId.ToHexString());
Assert.Equal("0123456789abcdef", activity.ParentSpanId.ToHexString());
Assert.True(IdIsW3CFormat(activity.Id));
+ Assert.Equal($"00-{activity.TraceId.ToHexString()}-{activity.SpanId.ToHexString()}-00", activity.Id);
Assert.Equal(ActivityTraceFlags.None, activity.ActivityTraceFlags);
Assert.False(activity.Recorded);
Assert.Equal("0123456789abcdef0123456789abcdef", activity.TraceId.ToHexString());
Assert.Equal("0123456789abcdef", activity.ParentSpanId.ToHexString());
Assert.True(IdIsW3CFormat(activity.Id));
+ Assert.Equal($"00-{activity.TraceId.ToHexString()}-{activity.SpanId.ToHexString()}-01", activity.Id);
Assert.Equal(ActivityTraceFlags.Recorded, activity.ActivityTraceFlags);
Assert.True(activity.Recorded);
Assert.Equal("0123456789abcdef0123456789abcdef", childActivity.TraceId.ToHexString());
Assert.NotEqual(activity.SpanId.ToHexString(), childActivity.SpanId.ToHexString());
Assert.True(IdIsW3CFormat(childActivity.Id));
+ Assert.Equal($"00-{childActivity.TraceId.ToHexString()}-{childActivity.SpanId.ToHexString()}-01", childActivity.Id);
Assert.Equal(ActivityTraceFlags.Recorded, childActivity.ActivityTraceFlags);
Assert.True(childActivity.Recorded);