Skip to content

Commit

Permalink
Fix Activity.OperationName when Activity is created with null value (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tarekgh authored Nov 1, 2022
1 parent 7e2af70 commit 4ad19b1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ public Activity(string operationName)
NotifyError(new ArgumentException(SR.OperationNameInvalid));
}

OperationName = operationName;
OperationName = operationName ?? string.Empty;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2216,6 +2216,27 @@ public void EnumerateLinkTagsTest()
}
}

[Fact]
public void CreateActivityWithNullOperationName()
{
Activity a = new Activity(operationName: null);
Assert.Equal(string.Empty, a.OperationName);

using ActivitySource aSource = new ActivitySource("NullOperationName");
using ActivityListener listener = new ActivityListener();
listener.ShouldListenTo = (activitySource) => activitySource == aSource;
listener.Sample = (ref ActivityCreationOptions<ActivityContext> activityOptions) => ActivitySamplingResult.AllData;
ActivitySource.AddActivityListener(listener);

using Activity a1 = aSource.StartActivity(null, ActivityKind.Client);
Assert.NotNull(a1);
Assert.Equal(string.Empty, a1.OperationName);

using Activity a2 = aSource.CreateActivity(null, ActivityKind.Client);
Assert.NotNull(a2);
Assert.Equal(string.Empty, a2.OperationName);
}

[Fact]
public void EnumerateEventTagsTest()
{
Expand Down

0 comments on commit 4ad19b1

Please sign in to comment.