Skip to content

Commit

Permalink
Add checker for passing correct sampling decision for xray (#1355)
Browse files Browse the repository at this point in the history
* Add checker for passing correct sampling decision when apply xray id generator.

* Added comment

* Update comments.

* Update links.

* Updated CHANGELOG.md

* Fixed the typo and lining

* Moved check inline.

Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
  • Loading branch information
lupengamzn and cijothomas authored Jan 14, 2021
1 parent 9b60e1f commit b17278f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
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
5 changes: 4 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) || activity.ParentSpanId.ToHexString() == "0000000000000000")
{
parentContext = default;
}
Expand Down

0 comments on commit b17278f

Please sign in to comment.