Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,12 @@ internal static Activity Create(ActivitySource source, string name, ActivityKind
{
activity.ActivityTraceFlags |= ActivityTraceFlags.Recorded;
}
else
{
// Note: Recorded may be inherited from the parent so it needs
// to be cleared for the Activity being created when not desired
activity.ActivityTraceFlags &= ~ActivityTraceFlags.Recorded;
}

if (startTime != default)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,36 @@ public void EnsureRecordingTest()
}).Dispose();
}

[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
public void EnsureRecordingClearedTest()
{
RemoteExecutor.Invoke(() => {
Activity.ForceDefaultIdFormat = true;
Activity.DefaultIdFormat = ActivityIdFormat.W3C;

ActivitySource aSource = new ActivitySource("EnsureRecordingTest");

ActivityListener listener = new ActivityListener
{
ShouldListenTo = (activitySource) => true,
Sample = (ref ActivityCreationOptions<ActivityContext> activityOptions) => ActivitySamplingResult.PropagationData
};

ActivitySource.AddActivityListener(listener);

// Note: Remote parent is set as recorded
var parentContext = new ActivityContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.Recorded, isRemote: true);

Activity a = aSource.StartActivity("RecordedActivity", ActivityKind.Internal, parentContext);
Assert.NotNull(a);

// Note: The sampler requests PropagationData so recorded should be removed
Assert.False(a.IsAllDataRequested);
Assert.False(a.Recorded);
Assert.False((a.Context.TraceFlags & ActivityTraceFlags.Recorded) != 0);
}).Dispose();
}

[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
public void TestExpectedListenersReturnValues()
{
Expand Down
Loading