Skip to content

Commit

Permalink
Add isRemote check for context propagation (#3329)
Browse files Browse the repository at this point in the history
  • Loading branch information
vishweshbankwar committed Jun 6, 2022
1 parent a2aa305 commit 5a566e6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

* `TracerProviderSDK` modified for spans with remote parent. For such spans
activity will be created irrespective of SamplingResult, to maintain context
propagation.
([#3329](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3329))

* Fix issue where a measurement would be dropped when recording it with a
null-valued tag.
([#3325](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3325))
Expand Down
12 changes: 6 additions & 6 deletions src/OpenTelemetry/Trace/TracerProviderSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ internal sealed class TracerProviderSdk : TracerProvider
else if (sampler is AlwaysOffSampler)
{
listener.Sample = (ref ActivityCreationOptions<ActivityContext> options) =>
!Sdk.SuppressInstrumentation ? PropagateOrIgnoreData(options.Parent.TraceId) : ActivitySamplingResult.None;
!Sdk.SuppressInstrumentation ? PropagateOrIgnoreData(options.Parent) : ActivitySamplingResult.None;
this.getRequestedDataAction = this.RunGetRequestedDataAlwaysOffSampler;
}
else
Expand Down Expand Up @@ -393,17 +393,17 @@ protected override void Dispose(bool disposing)
return activitySamplingResult;
}

return PropagateOrIgnoreData(options.Parent.TraceId);
return PropagateOrIgnoreData(options.Parent);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static ActivitySamplingResult PropagateOrIgnoreData(ActivityTraceId traceId)
private static ActivitySamplingResult PropagateOrIgnoreData(in ActivityContext parentContext)
{
var isRootSpan = traceId == default;
var isRootSpan = parentContext.TraceId == default;

// If it is the root span select PropagationData so the trace ID is preserved
// If it is the root span or the parent is remote select PropagationData so the trace ID is preserved
// even if no activity of the trace is recorded (sampled per OpenTelemetry parlance).
return isRootSpan
return (isRootSpan || parentContext.IsRemote)
? ActivitySamplingResult.PropagationData
: ActivitySamplingResult.None;
}
Expand Down
2 changes: 1 addition & 1 deletion test/OpenTelemetry.Tests/Trace/TracerProviderSdkTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public void TracerProviderSdkSamplerAttributesAreAppliedToActivity(SamplingDecis
}
}

[Fact(Skip = "https://github.com/open-telemetry/opentelemetry-dotnet/issues/3315")]
[Fact]
public void TracerSdkSetsActivitySamplingResultAsPropagationWhenParentIsRemote()
{
var testSampler = new TestSampler();
Expand Down

0 comments on commit 5a566e6

Please sign in to comment.