Skip to content

Commit

Permalink
refactor for minor perf
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishwesh Bankwar committed Jun 6, 2022
1 parent 3615b7b commit c9880cc
Showing 1 changed file with 5 additions and 5 deletions.
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

0 comments on commit c9880cc

Please sign in to comment.