Skip to content

Commit

Permalink
Merged PR 4062: [3.1.4] | Fix activity correlator to continue using s…
Browse files Browse the repository at this point in the history
…ame GUID for current thread activity (#1997)

Ports [#1997](#1997)
  • Loading branch information
DavoudEshtehari committed Oct 16, 2023
1 parent 6e9ced1 commit ef52c79
Showing 1 changed file with 6 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@ internal sealed class ActivityId
internal readonly Guid Id;
internal readonly uint Sequence;

internal ActivityId(uint sequence)
internal ActivityId(Guid? currentActivityId, uint sequence = 1)
{
this.Id = Guid.NewGuid();
this.Sequence = sequence;
Id = currentActivityId ?? Guid.NewGuid();
Sequence = sequence;
}

public override string ToString()
{
return string.Format(CultureInfo.InvariantCulture, "{0}:{1}", this.Id, this.Sequence);
}
=> string.Format(CultureInfo.InvariantCulture, "{0}:{1}", Id, Sequence);
}

// Declare the ActivityId which will be stored in TLS. The Id is unique for each thread.
Expand All @@ -40,27 +38,12 @@ public override string ToString()
/// <summary>
/// Get the current ActivityId
/// </summary>
internal static ActivityId Current
{
get
{
if (t_tlsActivity == null)
{
t_tlsActivity = new ActivityId(1);
}
return t_tlsActivity;
}
}
internal static ActivityId Current => t_tlsActivity ??= new ActivityId(null);

/// <summary>
/// Increment the sequence number and generate the new ActivityId
/// </summary>
/// <returns>ActivityId</returns>
internal static ActivityId Next()
{
t_tlsActivity = new ActivityId( (t_tlsActivity?.Sequence ?? 0) + 1);

return t_tlsActivity;
}
internal static ActivityId Next() => t_tlsActivity = new ActivityId(t_tlsActivity?.Id, (t_tlsActivity?.Sequence ?? 0) + 1);
}
}

0 comments on commit ef52c79

Please sign in to comment.