Closed
Description
Background and Motivation
Forcing creation of an Activity will allow existing codebases (e.g., aspnetcore) to migrate to using ActivitySource
to create Activity
s while still preserving compat with existing DiagnosticListeners.
Proposed API
namespace System.Diagnostics.DiagnosticSource
{
public sealed class ActivitySource
{
+ public System.Diagnostics.Activity? StartActivity (string name,
+ System.Diagnostics.ActivityKind kind,
+ string parentId,
+ bool forceCreation,
+ System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string,object?>>? tags = default,
+ System.Collections.Generic.IEnumerable<System.Diagnostics.ActivityLink>? links = default,
+ DateTimeOffset startTime = default);
}
}
Usage Examples
Alternative Designs
The alternative design to achieve compat with DiagnosticListener was to create a dummy ActivityListener. However, the decision to sample/or not sample can change frequently (on a per request-basis), making it expensive to mutate the Sample
/SampleUsingParentId
delegate in a thread-safe.
Risks
When used incorrectly, forcing creation of an Activity
could be a potentially expensive/high-allocation operation.