From b3f5117fc94e085a07c56927461adcabdeb63ccc Mon Sep 17 00:00:00 2001 From: Ryan Karg Date: Fri, 23 May 2025 11:35:50 -0700 Subject: [PATCH 1/4] Feature for setting activity tags on creation --- .../Internal/HostingApplicationDiagnostics.cs | 4 ++-- .../src/IHttpActivityCreationTagsFeature.cs | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 src/Http/Http.Features/src/IHttpActivityCreationTagsFeature.cs diff --git a/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs b/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs index 1a344203727c..fb3842f17274 100644 --- a/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs +++ b/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs @@ -388,7 +388,7 @@ private void RecordRequestStartMetrics(HttpContext httpContext) private Activity? StartActivity(HttpContext httpContext, bool loggingEnabled, bool diagnosticListenerActivityCreationEnabled, out bool hasDiagnosticListener) { hasDiagnosticListener = false; - + var tagsForCreation = httpContext.Features.Get()?.ActivityCreationTags; var headers = httpContext.Request.Headers; var activity = ActivityCreator.CreateFromRemote( _activitySource, @@ -402,7 +402,7 @@ private void RecordRequestStartMetrics(HttpContext httpContext) }, ActivityName, ActivityKind.Server, - tags: null, + tags: tagsForCreation, links: null, loggingEnabled || diagnosticListenerActivityCreationEnabled); if (activity is null) diff --git a/src/Http/Http.Features/src/IHttpActivityCreationTagsFeature.cs b/src/Http/Http.Features/src/IHttpActivityCreationTagsFeature.cs new file mode 100644 index 000000000000..68a76aedfaab --- /dev/null +++ b/src/Http/Http.Features/src/IHttpActivityCreationTagsFeature.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Diagnostics; + +namespace Microsoft.AspNetCore.Http.Features; + +/// +/// Provides a mechanism to add tags to the at creation time for incoming HTTP requests. +/// These tags can be used for tracing when making sampling decisions. +/// +public interface IHttpActivityCreationTagsFeature +{ + /// + /// A collection of tags to be added to the when it is created for the current HTTP request. + /// These tags are available at Activity creation time and can be used for sampling decisions. + /// + /// An containing tags to add to the Activity at creation time. + ActivityTagsCollection? ActivityCreationTags { get; } +} + From 9fd4b517f6bc6aab5979737ca0a6f9fcc65af35d Mon Sep 17 00:00:00 2001 From: Ryan Karg Date: Fri, 23 May 2025 12:06:03 -0700 Subject: [PATCH 2/4] adding unshipped public API entries --- src/Http/Http.Features/src/PublicAPI.Unshipped.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Http/Http.Features/src/PublicAPI.Unshipped.txt b/src/Http/Http.Features/src/PublicAPI.Unshipped.txt index 7dc5c58110bf..f172642dc828 100644 --- a/src/Http/Http.Features/src/PublicAPI.Unshipped.txt +++ b/src/Http/Http.Features/src/PublicAPI.Unshipped.txt @@ -1 +1,3 @@ #nullable enable +Microsoft.AspNetCore.Http.Features.IHttpActivityCreationTagsFeature +Microsoft.AspNetCore.Http.Features.IHttpActivityCreationTagsFeature.ActivityCreationTags.get -> ActivityTagsCollection? From 69e6a27c95c0473f30673cf689b2df9084b7bf0e Mon Sep 17 00:00:00 2001 From: Ryan Karg Date: Fri, 23 May 2025 12:11:16 -0700 Subject: [PATCH 3/4] moving to TagList --- .../Http.Features/src/IHttpActivityCreationTagsFeature.cs | 5 ++--- src/Http/Http.Features/src/PublicAPI.Unshipped.txt | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Http/Http.Features/src/IHttpActivityCreationTagsFeature.cs b/src/Http/Http.Features/src/IHttpActivityCreationTagsFeature.cs index 68a76aedfaab..6007dc698063 100644 --- a/src/Http/Http.Features/src/IHttpActivityCreationTagsFeature.cs +++ b/src/Http/Http.Features/src/IHttpActivityCreationTagsFeature.cs @@ -15,7 +15,6 @@ public interface IHttpActivityCreationTagsFeature /// A collection of tags to be added to the when it is created for the current HTTP request. /// These tags are available at Activity creation time and can be used for sampling decisions. /// - /// An containing tags to add to the Activity at creation time. - ActivityTagsCollection? ActivityCreationTags { get; } + /// An containing tags to add to the Activity at creation time. + TagList? ActivityCreationTags { get; } } - diff --git a/src/Http/Http.Features/src/PublicAPI.Unshipped.txt b/src/Http/Http.Features/src/PublicAPI.Unshipped.txt index f172642dc828..3af4f4c5de98 100644 --- a/src/Http/Http.Features/src/PublicAPI.Unshipped.txt +++ b/src/Http/Http.Features/src/PublicAPI.Unshipped.txt @@ -1,3 +1,3 @@ #nullable enable Microsoft.AspNetCore.Http.Features.IHttpActivityCreationTagsFeature -Microsoft.AspNetCore.Http.Features.IHttpActivityCreationTagsFeature.ActivityCreationTags.get -> ActivityTagsCollection? +Microsoft.AspNetCore.Http.Features.IHttpActivityCreationTagsFeature.ActivityCreationTags.get -> TagList? From 94f7066f0810fe62b2d292f49907388657708111 Mon Sep 17 00:00:00 2001 From: Ryan Karg Date: Fri, 23 May 2025 12:42:10 -0700 Subject: [PATCH 4/4] Less specific property type also fixed up unshipped API documentation --- .../Http.Features/src/IHttpActivityCreationTagsFeature.cs | 6 ++---- src/Http/Http.Features/src/PublicAPI.Unshipped.txt | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Http/Http.Features/src/IHttpActivityCreationTagsFeature.cs b/src/Http/Http.Features/src/IHttpActivityCreationTagsFeature.cs index 6007dc698063..56fe7c1126f8 100644 --- a/src/Http/Http.Features/src/IHttpActivityCreationTagsFeature.cs +++ b/src/Http/Http.Features/src/IHttpActivityCreationTagsFeature.cs @@ -1,8 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.Diagnostics; - namespace Microsoft.AspNetCore.Http.Features; /// @@ -15,6 +13,6 @@ public interface IHttpActivityCreationTagsFeature /// A collection of tags to be added to the when it is created for the current HTTP request. /// These tags are available at Activity creation time and can be used for sampling decisions. /// - /// An containing tags to add to the Activity at creation time. - TagList? ActivityCreationTags { get; } + /// Tags to add to the Activity at creation time. + IEnumerable>? ActivityCreationTags { get; } } diff --git a/src/Http/Http.Features/src/PublicAPI.Unshipped.txt b/src/Http/Http.Features/src/PublicAPI.Unshipped.txt index 3af4f4c5de98..6b8cd9b46d82 100644 --- a/src/Http/Http.Features/src/PublicAPI.Unshipped.txt +++ b/src/Http/Http.Features/src/PublicAPI.Unshipped.txt @@ -1,3 +1,3 @@ #nullable enable Microsoft.AspNetCore.Http.Features.IHttpActivityCreationTagsFeature -Microsoft.AspNetCore.Http.Features.IHttpActivityCreationTagsFeature.ActivityCreationTags.get -> TagList? +Microsoft.AspNetCore.Http.Features.IHttpActivityCreationTagsFeature.ActivityCreationTags.get -> System.Collections.Generic.IEnumerable>?