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
Prev Previous commit
Next Next commit
refactor for minor perf
  • Loading branch information
Vishwesh Bankwar committed Jun 6, 2022
commit c9880ccbeb2368b3a994e76177dff3a22935f242
10 changes: 5 additions & 5 deletions src/OpenTelemetry/Trace/TracerProviderSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ internal TracerProviderSdk(
else if (sampler is AlwaysOffSampler)
{
listener.Sample = (ref ActivityCreationOptions<ActivityContext> options) =>
!Sdk.SuppressInstrumentation ? PropagateOrIgnoreData(options.Parent.TraceId, options.Parent.IsRemote) : ActivitySamplingResult.None;
!Sdk.SuppressInstrumentation ? PropagateOrIgnoreData(options.Parent) : ActivitySamplingResult.None;
this.getRequestedDataAction = this.RunGetRequestedDataAlwaysOffSampler;
}
else
Expand Down Expand Up @@ -393,17 +393,17 @@ private static ActivitySamplingResult ComputeActivitySamplingResult(
return activitySamplingResult;
}

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

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

// 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 || isParentRemote)
return (isRootSpan || context.IsRemote)
? ActivitySamplingResult.PropagationData
: ActivitySamplingResult.None;
}
Expand Down