Skip to content

Add API to allow forcing creation of a Activity using ActivitySource (rather than relying on ActivityListener) #48237

Closed
@shirhatti

Description

@shirhatti

Background and Motivation

Forcing creation of an Activity will allow existing codebases (e.g., aspnetcore) to migrate to using ActivitySource to create Activitys 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

dotnet/aspnetcore#30089

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions