I haven't find the way to make activitySource.StartActivity
return non-null activity, which is different comparing to DiagnosticSource.StartActivity
behavior. Is it expected? Am I'missing something obvious?
I can see docs says: "The created activity object, if it had active listeners, or null if it has no event listeners." The following test still fails, what's the correct way of initializing ActivityListener
? The package I'm using is "System.Diagnostics.DiagnosticSource" Version="5.0.0"
.
[TestMethod]
public void Start_Not_Null_When_ActivityListener_Added_And_ShouldListenTo_Explicitly_Defined_Activity()
{
var activitySource = new ActivitySource("ActivitySourceName");
var activityListener = new ActivityListener
{
ShouldListenTo = s => true
};
ActivitySource.AddActivityListener(activityListener);
using var activity = activitySource.StartActivity($"MethodType:/Path");
Assert.IsNotNull(activity);
}
SetSampler(new AlwaysOnSampler())
worked for me. However I think @Bores 's answer is the more long term solution. Either way, +1 from me for this answer – Telluric