Skip to content

System.Diagnostics.DiagnosticSource: Activity with null operation name #77621

@CodeBlanch

Description

@CodeBlanch

Activity has a quirk in that its OperationName is not marked as nullable but its constructor allows it to be null. Chatted offline with the group CCed below and we agreed that it is a low-risk change to coalesce to string.Empty in this case.

Something like this:

        public Activity(string operationName)
        {
            Source = s_defaultSource;
            // Allow data by default in the constructor to keep the compatibility.
            IsAllDataRequested = true;

            if (string.IsNullOrEmpty(operationName))
            {
                NotifyError(new ArgumentException(SR.OperationNameInvalid)); // <- Note: Does not throw.
                operationName = string.Empty; // <- New logic here.
            }

            OperationName = operationName;
        }

We consider setting to something like "<null>" but decided to use string.Empty because that is similar to what happens for Activity.Source.Name in the case of legacy instances.

/cc @tarekgh @noahfalk @reyang @cijothomas @utpilla @alanwest

Metadata

Metadata

Assignees

Labels

area-System.Diagnostics.Activitybreaking-changeIssue or PR that represents a breaking API or functional change over a previous release.needs-breaking-change-doc-createdBreaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions