Skip to content

Impossible to set Activity.IdFormat when using ActivitySource #43853

Closed
@pakrym

Description

@pakrym

Description

Because the ActivitySource doesn't expose the IdFormat in any way it's impossible to set the value before the new activity is started. The format is inferred from the global setting or the parent if it exists but if there is no parent and the global setting is hierarchical it's impossible to start a W3C root activity.

Regression?

Regression from the previous pattern, it was possible to set Activity.IdFormat using Activity.SetIdFormat before calling DiagnosticSource.StartActivity

cc @noahfalk @tarekgh

The proposal is added by @tarekgh

Proposal

In 6.0 we already added an overload for ActivitySource.StartActivity. The proposal here is just adding the idFormat as optional parameter to that overload.

namespace System.Diagnostics
{
    public sealed class ActivitySource : IDisposable
    {
	      public Activity? StartActivity(
	          ActivityKind kind, 
	          ActivityContext parentContext = default, 
	          IEnumerable<KeyValuePair<string, object?>>? tags = null, 
	          IEnumerable<ActivityLink>? links = null, 
+	          ActivityIdFormat idFormat = ActivityIdFormat.Unknown,
	          DateTimeOffset startTime = default,
              [CallerMemberName] string name = "");
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions