Skip to content

Commit

Permalink
Update DistributedTraceContext (#969)
Browse files Browse the repository at this point in the history
This PR adds a setter for TraceParent to allow it to get serialized. Without this addition, we weren't able to run Netherite apps with the distributed tracing changes because we were seeing this exception: InvalidDataContractException: No set method for property 'TraceParent' in type 'DurableTask.Core.Tracing.DistributedTraceContext'.

It also updates the TraceState setter to include this condition - traceState?.Length <= 513 ? traceState : null instead of adding it in the constructor.
  • Loading branch information
bachuv authored Sep 27, 2023
1 parent 6dc7134 commit 20aed32
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/DurableTask.Core/Tracing/DistributedTraceContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ namespace DurableTask.Core.Tracing
[DataContract]
public class DistributedTraceContext
{
private string? traceState;

/// <summary>
/// Initializes a new instance of the <see cref="DistributedTraceContext"/> class.
/// </summary>
Expand All @@ -31,26 +33,35 @@ public class DistributedTraceContext
public DistributedTraceContext(string traceParent, string? traceState = null)
{
this.TraceParent = traceParent;

// The W3C spec allows vendors to truncate the trace state if it exceeds 513 characters,
// but it has very specific requirements on HOW trace state can be modified, including
// removing whole values, starting with the largest values, and preserving ordering.
// Rather than implementing these complex requirements, we take the lazy path of just
// truncating the whole thing.
this.TraceState = traceState?.Length <= 513 ? traceState : null;
this.traceState = traceState;
}

/// <summary>
/// The W3C traceparent data: https://www.w3.org/TR/trace-context/#traceparent-header
/// </summary>
[DataMember]
public string TraceParent { get; }
public string TraceParent { get; set; }

/// <summary>
/// The optional W3C tracestate parameter: https://www.w3.org/TR/trace-context/#tracestate-header
/// </summary>
[DataMember]
public string? TraceState { get; set; }
public string? TraceState
{
get
{
return this.traceState;
}
set
{
// The W3C spec allows vendors to truncate the trace state if it exceeds 513 characters,
// but it has very specific requirements on HOW trace state can be modified, including
// removing whole values, starting with the largest values, and preserving ordering.
// Rather than implementing these complex requirements, we take the lazy path of just
// truncating the whole thing.
this.traceState = value?.Length <= 513 ? value : null;
}
}

/// <summary>
/// The Activity's Id value that is used to restore an Activity during replays.
Expand Down

0 comments on commit 20aed32

Please sign in to comment.