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 isRemote check for context propagation #3329

Merged
merged 13 commits into from
Jun 6, 2022
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