diff --git a/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs b/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs index 1a344203727c..cbe566ef7c1e 100644 --- a/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs +++ b/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs @@ -388,7 +388,8 @@ 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 +403,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..56fe7c1126f8 --- /dev/null +++ b/src/Http/Http.Features/src/IHttpActivityCreationTagsFeature.cs @@ -0,0 +1,18 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +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. + /// + /// 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 7dc5c58110bf..6b8cd9b46d82 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 -> System.Collections.Generic.IEnumerable>?