Skip to content

Commit e702811

Browse files
committed
Fix nullable annotations on IW3CActivity
1 parent ebcdc7c commit e702811

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

tracer/src/Datadog.Trace/Activity/DuckTypes/IW3CActivity.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ namespace Datadog.Trace.Activity.DuckTypes
1111
{
1212
internal interface IW3CActivity : IActivity
1313
{
14+
// Note that TraceId and SpanId will not be null when using W3C IDs, but they
15+
// _Can_ be nullable when using Hierarchical IDs. Also note that IW3CActivity
16+
// could be using _either_ type of ID
1417
[DuckField(Name = "_traceId")]
15-
string TraceId { get; set; }
18+
string? TraceId { get; set; }
1619

1720
[DuckField(Name = "_spanId")]
18-
string SpanId { get; set; }
21+
string? SpanId { get; set; }
1922

2023
[DuckField(Name = "_parentSpanId")]
2124
string ParentSpanId { get; set; }

tracer/src/Datadog.Trace/Activity/Handlers/AzureServiceBusActivityHandler.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,11 @@ public void ActivityStopped<T>(string sourceName, T activity)
4646
// then we can retrieve the active message object using our mapping. With access to the message
4747
// object, we can accurately calculate the payload size for the DataStreamsCheckpoint
4848

49-
ActivityKey key;
50-
if (activity is IW3CActivity w3cActivity)
49+
ActivityKey key = activity switch
5150
{
52-
key = new(w3cActivity.TraceId, w3cActivity.SpanId);
53-
}
54-
else
55-
{
56-
key = new ActivityKey(activity.Id);
57-
}
51+
IW3CActivity { TraceId: not null, SpanId: not null } w3cActivity => new(w3cActivity.TraceId, w3cActivity.SpanId),
52+
_ => new(activity.Id)
53+
};
5854

5955
if (key.IsValid() && ActivityHandlerCommon.ActivityMappingById.TryRemove(key, out ActivityMapping activityMapping)
6056
&& activityMapping.Scope?.Span is Span span)

tracer/src/Datadog.Trace/Activity/Handlers/QuartzActivityHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void ActivityStopped<T>(string sourceName, T activity)
4747
// Find the span and update it before the common handler processes it
4848
ActivityKey key = activity switch
4949
{
50-
IW3CActivity w3cActivity => new(w3cActivity.TraceId, w3cActivity.SpanId),
50+
IW3CActivity { TraceId: not null, SpanId: not null } w3cActivity => new(w3cActivity.TraceId, w3cActivity.SpanId),
5151
_ => new(activity.Id)
5252
};
5353

0 commit comments

Comments
 (0)