Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions src/OpenTelemetry/Trace/TracerProviderSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using Microsoft.Extensions.DependencyInjection;
using OpenTelemetry.Internal;
Expand Down Expand Up @@ -249,7 +248,7 @@ internal TracerProviderSdk(
else if (this.sampler is AlwaysOffSampler)
{
listener.Sample = (ref ActivityCreationOptions<ActivityContext> options) =>
!Sdk.SuppressInstrumentation ? PropagateOrIgnoreData(options.Parent) : ActivitySamplingResult.None;
!Sdk.SuppressInstrumentation ? ActivitySamplingResult.PropagationData : ActivitySamplingResult.None;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is extremely hard to read. There is some deep nesting of if/else/Listener callback code going on here. I would suggest to extract some (named, top-level) methods to make the code more readable/reviewable.

this.getRequestedDataAction = this.RunGetRequestedDataAlwaysOffSampler;
}
else
Expand Down Expand Up @@ -461,23 +460,9 @@ private static ActivitySamplingResult ComputeActivitySamplingResult(
{
options = options with { TraceState = samplingResult.TraceStateString };
}

return activitySamplingResult;
}

return PropagateOrIgnoreData(options.Parent);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static ActivitySamplingResult PropagateOrIgnoreData(in ActivityContext parentContext)
{
var isRootSpan = parentContext.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 || parentContext.IsRemote)
? ActivitySamplingResult.PropagationData
: ActivitySamplingResult.None;
return activitySamplingResult;
}

private void RunGetRequestedDataAlwaysOnSampler(Activity activity)
Expand Down