Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix activity correlator to continue using same GUID for connection activity #1997

Merged
merged 1 commit into from Apr 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
cheenamalhotra marked this conversation as resolved.
Show resolved Hide resolved
{
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);
}
}