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

Add checker for passing correct sampling decision for xray #1355

Merged
merged 10 commits into from
Jan 14, 2021
10 changes: 9 additions & 1 deletion src/OpenTelemetry/Trace/ActivitySourceAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ private void RunGetRequestedDataAlwaysOffSampler(Activity activity)
private void RunGetRequestedDataOtherSampler(Activity activity)
{
ActivityContext parentContext;
if (string.IsNullOrEmpty(activity.ParentId))

// Check activity.ParentId alone is sufficient to normally determine if a activity is root or not. But if one uses activity.SetParentId to override the TraceId (without intending to set an actual parent), then additional check of parentspanid being empty is required to confirm if an activity is root or not.
// This checker can be removed, once Activity exposes an API to customize ID Generation (https://github.com/dotnet/runtime/issues/46704) or issue https://github.com/dotnet/runtime/issues/46706 is addressed.
if (string.IsNullOrEmpty(activity.ParentId) || this.IsParentSpanIdEmpty(activity))
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
{
parentContext = default;
}
Expand Down Expand Up @@ -186,5 +189,10 @@ private void RunGetRequestedDataOtherSampler(Activity activity)
}
}
}

private bool IsParentSpanIdEmpty(Activity activity)
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
{
return activity.ParentSpanId.ToHexString() == "0000000000000000";
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
}
}
}