Skip to content
Merged
3 changes: 3 additions & 0 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
for Activity.Recorded in SimpleActivityExportProcessor and
BatchActivityExportProcessor
([#1622](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1622))
* Added check in `ActivitySourceAdapter` class for root activity if traceid is
overridden by calling `SetParentId`
([#1355](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1355))

## 1.0.0-rc1.1

Expand Down
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))
Comment thread
cijothomas marked this conversation as resolved.
Outdated
{
parentContext = default;
}
Expand Down Expand Up @@ -186,5 +189,10 @@ private void RunGetRequestedDataOtherSampler(Activity activity)
}
}
}

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