From 1c084bed8d7a22ff7f22e414da4d2ee0e472fbee Mon Sep 17 00:00:00 2001 From: Dmytro Bohdanov Date: Thu, 2 Oct 2025 14:26:38 +0200 Subject: [PATCH 01/18] new metadata resolver api --- ...r.cs => HttpDependencyMetadataResolver.cs} | 62 +++++++++++++------ ...pDiagnosticsServiceCollectionExtensions.cs | 4 +- .../IHttpDependencyMetadata.cs | 27 ++++++++ 3 files changed, 73 insertions(+), 20 deletions(-) rename src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/{DownstreamDependencyMetadataManager.cs => HttpDependencyMetadataResolver.cs} (84%) create mode 100644 src/Libraries/Microsoft.Extensions.Http.Diagnostics/IHttpDependencyMetadata.cs diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/DownstreamDependencyMetadataManager.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs similarity index 84% rename from src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/DownstreamDependencyMetadataManager.cs rename to src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs index 93c3e534e8e..16b93c52b22 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/DownstreamDependencyMetadataManager.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs @@ -8,11 +8,18 @@ using System.Net; using System.Net.Http; using System.Text.RegularExpressions; -using Microsoft.Extensions.Telemetry.Internal; namespace Microsoft.Extensions.Http.Diagnostics; -internal sealed class DownstreamDependencyMetadataManager : IDownstreamDependencyMetadataManager +/// +/// Resolves metadata for HTTP requests based on hostname, path, and method patterns. +/// +/// +/// This class provides a high-performance way to identify HTTP requests by mapping them to previously +/// configured metadata using specialized trie-based data structures. This enables efficient lookup +/// of service information, operation names, and other metadata for telemetry and policy application. +/// +public abstract class HttpDependencyMetadataResolver { internal readonly struct ProcessedMetadata { @@ -27,22 +34,37 @@ internal readonly struct ProcessedMetadata private readonly HostSuffixTrieNode _hostSuffixTrieRoot = new(); private readonly FrozenDictionary _frozenProcessedMetadataMap; - public DownstreamDependencyMetadataManager(IEnumerable downstreamDependencyMetadata) + /// + /// Initializes a new instance of the class. + /// + /// A collection of HTTP dependency metadata used for request resolution. + /// is . + protected HttpDependencyMetadataResolver(IEnumerable dependencyMetadata) { + if (dependencyMetadata == null) + { + throw new ArgumentNullException(nameof(dependencyMetadata)); + } + Dictionary dependencyTrieMap = []; - foreach (var dependency in downstreamDependencyMetadata) + foreach (var dependency in dependencyMetadata) { AddDependency(dependency, dependencyTrieMap); } - _frozenProcessedMetadataMap = ProcessDownstreamDependencyMetadata(dependencyTrieMap).ToFrozenDictionary(StringComparer.Ordinal); + _frozenProcessedMetadataMap = ProcessDependencyMetadata(dependencyTrieMap).ToFrozenDictionary(StringComparer.Ordinal); } - public RequestMetadata? GetRequestMetadata(HttpRequestMessage requestMessage) + /// + /// Gets request metadata for the specified HTTP request message. + /// + /// The HTTP request message. + /// The resolved if found; otherwise, . + public virtual RequestMetadata? GetRequestMetadata(HttpRequestMessage requestMessage) { try { - if (requestMessage.RequestUri == null) + if (requestMessage?.RequestUri == null) { return null; } @@ -57,7 +79,12 @@ public DownstreamDependencyMetadataManager(IEnumerable + /// Gets request metadata for the specified HTTP web request. + /// + /// The HTTP web request. + /// The resolved if found; otherwise, . + public virtual RequestMetadata? GetRequestMetadata(HttpWebRequest requestMessage) { try { @@ -75,7 +102,6 @@ private static char[] MakeToUpperArray() { // Initialize the _toUpper array for quick conversion of any ascii char to upper // without incurring cost of checking whether the character requires conversion. - var a = new char[Constants.ASCIICharCount]; for (int i = 0; i < Constants.ASCIICharCount; i++) { @@ -173,12 +199,12 @@ private static void AddRouteToTrie(RequestMetadata routeMetadata, Dictionary ProcessDownstreamDependencyMetadata(Dictionary dependencyTrieMap) + private static Dictionary ProcessDependencyMetadata(Dictionary dependencyTrieMap) { Dictionary finalArrayDict = []; foreach (var dep in dependencyTrieMap) { - var finalArray = ProcessDownstreamDependencyMetadataInternal(dep.Value); + var finalArray = ProcessDependencyMetadataInternal(dep.Value); finalArrayDict.Add(dep.Key, finalArray); } @@ -190,7 +216,7 @@ private static Dictionary ProcessDownstreamDependency // remove the ExlcudeCodeCoverage attribute and ensure it's covered fully using local runs and enable it back before // pushing the change to PR. [ExcludeFromCodeCoverage] - private static ProcessedMetadata ProcessDownstreamDependencyMetadataInternal(RequestMetadataTrieNode requestMetadataTrieRoot) + private static ProcessedMetadata ProcessDependencyMetadataInternal(RequestMetadataTrieNode requestMetadataTrieRoot) { Queue queue = new(); queue.Enqueue(requestMetadataTrieRoot); @@ -278,17 +304,17 @@ private static ProcessedMetadata ProcessDownstreamDependencyMetadataInternal(Req return null; } - private void AddDependency(IDownstreamDependencyMetadata downstreamDependencyMetadata, Dictionary dependencyTrieMap) + private void AddDependency(IHttpDependencyMetadata dependencyMetadata, Dictionary dependencyTrieMap) { - foreach (var hostNameSuffix in downstreamDependencyMetadata.UniqueHostNameSuffixes) + foreach (var hostNameSuffix in dependencyMetadata.UniqueHostNameSuffixes) { // Add hostname to hostname suffix trie - AddHostnameToTrie(hostNameSuffix, downstreamDependencyMetadata.DependencyName); + AddHostnameToTrie(hostNameSuffix, dependencyMetadata.DependencyName); } - foreach (var routeMetadata in downstreamDependencyMetadata.RequestMetadata) + foreach (var routeMetadata in dependencyMetadata.RequestMetadata) { - routeMetadata.DependencyName = downstreamDependencyMetadata.DependencyName; + routeMetadata.DependencyName = dependencyMetadata.DependencyName; // Add route metadata to the route per dependency trie AddRouteToTrie(routeMetadata, dependencyTrieMap); @@ -445,4 +471,4 @@ private void AddHostnameToTrie(string hostNameSuffix, string dependencyName) hostMetadata.RequestMetadata : // Return the default request metadata for this host if no matching route is found. routeMetadataTrieRoot.RequestMetadatas[trieCurrent.RequestMetadataEntryIndex]; } -} +} \ No newline at end of file diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDiagnosticsServiceCollectionExtensions.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDiagnosticsServiceCollectionExtensions.cs index 6cdcd74b263..9cad693613e 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDiagnosticsServiceCollectionExtensions.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDiagnosticsServiceCollectionExtensions.cs @@ -23,7 +23,7 @@ public static class HttpDiagnosticsServiceCollectionExtensions public static IServiceCollection AddDownstreamDependencyMetadata(this IServiceCollection services, IDownstreamDependencyMetadata downstreamDependencyMetadata) { _ = Throw.IfNull(services); - services.TryAddSingleton(); + services.TryAddSingleton(); _ = services.AddSingleton(downstreamDependencyMetadata); return services; @@ -39,7 +39,7 @@ public static IServiceCollection AddDownstreamDependencyMetadata(this IServiceCo where T : class, IDownstreamDependencyMetadata { _ = Throw.IfNull(services); - services.TryAddSingleton(); + services.TryAddSingleton(); _ = services.AddSingleton(); return services; diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/IHttpDependencyMetadata.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/IHttpDependencyMetadata.cs new file mode 100644 index 00000000000..489eb3d0bcd --- /dev/null +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/IHttpDependencyMetadata.cs @@ -0,0 +1,27 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections.Generic; + +namespace Microsoft.Extensions.Http.Diagnostics; + +/// +/// Interface for passing dependency metadata. +/// +public interface IHttpDependencyMetadata +{ + /// + /// Gets the name of the dependent service. + /// + string DependencyName { get; } + + /// + /// Gets the list of host name suffixes that can uniquely identify a host as this dependency. + /// + ISet UniqueHostNameSuffixes { get; } + + /// + /// Gets the list of all metadata for all routes to the dependency service. + /// + ISet RequestMetadata { get; } +} From 11ccdb3b50bdd74829ac303b9009bc2f84069650 Mon Sep 17 00:00:00 2001 From: Dmytro Bohdanov Date: Thu, 2 Oct 2025 15:48:20 +0200 Subject: [PATCH 02/18] extension methods for the metadata resolvers --- .../DefaultHttpDependencyMetadataResolver.cs | 22 +++++++++++++ ...pDiagnosticsServiceCollectionExtensions.cs | 32 ++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/DefaultHttpDependencyMetadataResolver.cs diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/DefaultHttpDependencyMetadataResolver.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/DefaultHttpDependencyMetadataResolver.cs new file mode 100644 index 00000000000..b2c837c6688 --- /dev/null +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/DefaultHttpDependencyMetadataResolver.cs @@ -0,0 +1,22 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections.Generic; + +namespace Microsoft.Extensions.Http.Diagnostics; + +/// +/// Default implementation of that uses the base +/// trie-based lookup algorithm. +/// +public sealed class DefaultHttpDependencyMetadataResolver : HttpDependencyMetadataResolver +{ + /// + /// Initializes a new instance of the class. + /// + /// A collection of HTTP dependency metadata used for request resolution. + public DefaultHttpDependencyMetadataResolver(IEnumerable dependencyMetadata) + : base(dependencyMetadata) + { + } +} diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDiagnosticsServiceCollectionExtensions.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDiagnosticsServiceCollectionExtensions.cs index 9cad693613e..9caeb0ea441 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDiagnosticsServiceCollectionExtensions.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDiagnosticsServiceCollectionExtensions.cs @@ -4,7 +4,6 @@ using System.Diagnostics.CodeAnalysis; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Http.Diagnostics; -using Microsoft.Extensions.Telemetry.Internal; using Microsoft.Shared.Diagnostics; namespace Microsoft.Extensions.DependencyInjection; @@ -44,4 +43,35 @@ public static IServiceCollection AddDownstreamDependencyMetadata(this IServiceCo return services; } + + /// + /// Adds services required for HTTP dependency metadata resolution. + /// + /// The to add the services to. + /// The so that additional calls can be chained. + public static IServiceCollection AddHttpDependencyMetadataResolver(this IServiceCollection services) + { + services.TryAddSingleton(); + return services; + } + + /// + /// Adds services required for HTTP dependency metadata resolution with the specified metadata providers. + /// + /// The to add the services to. + /// The HTTP dependency metadata providers to register. + /// The so that additional calls can be chained. + public static IServiceCollection AddHttpDependencyMetadataResolver( + this IServiceCollection services, + params IHttpDependencyMetadata[] metadataProviders) + { + foreach (var provider in metadataProviders) + { + services.TryAddEnumerable(ServiceDescriptor.Singleton(provider)); + } + + services.TryAddSingleton(); + + return services; + } } From 798cd50b235742257e5e14996e20f671bc1b2589 Mon Sep 17 00:00:00 2001 From: Dmytro Bohdanov Date: Mon, 6 Oct 2025 11:34:02 +0200 Subject: [PATCH 03/18] update di resolution --- .../Http/HttpDiagnosticsServiceCollectionExtensions.cs | 4 ++-- .../Internal/IDownstreamDependencyMetadataManager.cs | 4 +++- .../DownstreamDependencyMetadataManagerTests.cs | 10 +++++----- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDiagnosticsServiceCollectionExtensions.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDiagnosticsServiceCollectionExtensions.cs index 9caeb0ea441..0460be4d3db 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDiagnosticsServiceCollectionExtensions.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDiagnosticsServiceCollectionExtensions.cs @@ -22,7 +22,7 @@ public static class HttpDiagnosticsServiceCollectionExtensions public static IServiceCollection AddDownstreamDependencyMetadata(this IServiceCollection services, IDownstreamDependencyMetadata downstreamDependencyMetadata) { _ = Throw.IfNull(services); - services.TryAddSingleton(); + services.TryAddSingleton(); _ = services.AddSingleton(downstreamDependencyMetadata); return services; @@ -38,7 +38,7 @@ public static IServiceCollection AddDownstreamDependencyMetadata(this IServiceCo where T : class, IDownstreamDependencyMetadata { _ = Throw.IfNull(services); - services.TryAddSingleton(); + services.TryAddSingleton(); _ = services.AddSingleton(); return services; diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Logging/Internal/IDownstreamDependencyMetadataManager.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Logging/Internal/IDownstreamDependencyMetadataManager.cs index 5c49827a3b0..2da95ca2b95 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Logging/Internal/IDownstreamDependencyMetadataManager.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Logging/Internal/IDownstreamDependencyMetadataManager.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; using System.Net; using System.Net.Http; using Microsoft.Extensions.Http.Diagnostics; @@ -8,8 +9,9 @@ namespace Microsoft.Extensions.Telemetry.Internal; /// -/// Interface to manage dependency metadata. +/// (Obsolete) Use . /// +[Obsolete("Use HttpDependencyMetadataResolver instead. This internal interface will be removed.")] internal interface IDownstreamDependencyMetadataManager { /// diff --git a/test/Libraries/Microsoft.Extensions.Http.Diagnostics.Tests/Telemetry/DownstreamDependencyMetadataManagerTests.cs b/test/Libraries/Microsoft.Extensions.Http.Diagnostics.Tests/Telemetry/DownstreamDependencyMetadataManagerTests.cs index e7cdb4d3f32..c0763cc7ed8 100644 --- a/test/Libraries/Microsoft.Extensions.Http.Diagnostics.Tests/Telemetry/DownstreamDependencyMetadataManagerTests.cs +++ b/test/Libraries/Microsoft.Extensions.Http.Diagnostics.Tests/Telemetry/DownstreamDependencyMetadataManagerTests.cs @@ -4,14 +4,14 @@ using System; using System.Net.Http; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Telemetry.Internal; +using Microsoft.Extensions.Http.Diagnostics; using Xunit; namespace Microsoft.Extensions.Telemetry.Telemetry; public class DownstreamDependencyMetadataManagerTests : IDisposable { - private readonly IDownstreamDependencyMetadataManager _depMetadataManager; + private readonly HttpDependencyMetadataResolver _metadataResolver; private readonly ServiceProvider _sp; public DownstreamDependencyMetadataManagerTests() @@ -20,7 +20,7 @@ public DownstreamDependencyMetadataManagerTests() .AddDownstreamDependencyMetadata(new BackslashDownstreamDependencyMetadata()) .AddDownstreamDependencyMetadata(new EmptyRouteDependencyMetadata()) .BuildServiceProvider(); - _depMetadataManager = _sp.GetRequiredService(); + _metadataResolver = _sp.GetRequiredService(); } [Theory] @@ -51,7 +51,7 @@ public void GetRequestMetadata_RoutesRegisteredWithBackslashes_ShouldReturnHostM RequestUri = new Uri(uriString: urlString) }; - var requestMetadata = _depMetadataManager.GetRequestMetadata(requestMessage); + var requestMetadata = _metadataResolver.GetRequestMetadata(requestMessage); Assert.NotNull(requestMetadata); Assert.Equal(new BackslashDownstreamDependencyMetadata().DependencyName, requestMetadata.DependencyName); Assert.Equal(expectedRequestName, requestMetadata.RequestName); @@ -71,7 +71,7 @@ public void GetRequestMetadata_EmptyRouteRegisteredForDependency_ShouldReturnMet RequestUri = new Uri(uriString: urlString) }; - var requestMetadata = _depMetadataManager.GetRequestMetadata(requestMessage); + var requestMetadata = _metadataResolver.GetRequestMetadata(requestMessage); Assert.NotNull(requestMetadata); Assert.Equal("EmptyRouteService", requestMetadata.DependencyName); From 040e51baae3f658ccfb76a5fbb3555b1e834118b Mon Sep 17 00:00:00 2001 From: Dmytro Bohdanov Date: Mon, 6 Oct 2025 14:25:26 +0200 Subject: [PATCH 04/18] update metadata resolver usage, fix tests --- .../DefaultHttpDependencyMetadataResolver.cs | 2 +- .../Http/HttpDependencyMetadataResolver.cs | 4 +-- ...pDiagnosticsServiceCollectionExtensions.cs | 19 ++++++------- .../IHttpDependencyMetadata.cs | 27 ------------------- .../Logging/Internal/HttpRequestReader.cs | 13 +++++---- 5 files changed, 19 insertions(+), 46 deletions(-) delete mode 100644 src/Libraries/Microsoft.Extensions.Http.Diagnostics/IHttpDependencyMetadata.cs diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/DefaultHttpDependencyMetadataResolver.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/DefaultHttpDependencyMetadataResolver.cs index b2c837c6688..fa15cea6283 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/DefaultHttpDependencyMetadataResolver.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/DefaultHttpDependencyMetadataResolver.cs @@ -15,7 +15,7 @@ public sealed class DefaultHttpDependencyMetadataResolver : HttpDependencyMetada /// Initializes a new instance of the class. /// /// A collection of HTTP dependency metadata used for request resolution. - public DefaultHttpDependencyMetadataResolver(IEnumerable dependencyMetadata) + public DefaultHttpDependencyMetadataResolver(IEnumerable dependencyMetadata) : base(dependencyMetadata) { } diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs index 16b93c52b22..a1fca06c841 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs @@ -39,7 +39,7 @@ internal readonly struct ProcessedMetadata /// /// A collection of HTTP dependency metadata used for request resolution. /// is . - protected HttpDependencyMetadataResolver(IEnumerable dependencyMetadata) + protected HttpDependencyMetadataResolver(IEnumerable dependencyMetadata) { if (dependencyMetadata == null) { @@ -304,7 +304,7 @@ private static ProcessedMetadata ProcessDependencyMetadataInternal(RequestMetada return null; } - private void AddDependency(IHttpDependencyMetadata dependencyMetadata, Dictionary dependencyTrieMap) + private void AddDependency(IDownstreamDependencyMetadata dependencyMetadata, Dictionary dependencyTrieMap) { foreach (var hostNameSuffix in dependencyMetadata.UniqueHostNameSuffixes) { diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDiagnosticsServiceCollectionExtensions.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDiagnosticsServiceCollectionExtensions.cs index 0460be4d3db..8a70a5d6860 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDiagnosticsServiceCollectionExtensions.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDiagnosticsServiceCollectionExtensions.cs @@ -22,9 +22,10 @@ public static class HttpDiagnosticsServiceCollectionExtensions public static IServiceCollection AddDownstreamDependencyMetadata(this IServiceCollection services, IDownstreamDependencyMetadata downstreamDependencyMetadata) { _ = Throw.IfNull(services); - services.TryAddSingleton(); - _ = services.AddSingleton(downstreamDependencyMetadata); + _ = Throw.IfNull(downstreamDependencyMetadata); + services.TryAddEnumerable(ServiceDescriptor.Singleton(downstreamDependencyMetadata)); + services.TryAddSingleton(); return services; } @@ -38,9 +39,8 @@ public static IServiceCollection AddDownstreamDependencyMetadata(this IServiceCo where T : class, IDownstreamDependencyMetadata { _ = Throw.IfNull(services); + services.TryAddEnumerable(ServiceDescriptor.Singleton()); services.TryAddSingleton(); - _ = services.AddSingleton(); - return services; } @@ -59,19 +59,20 @@ public static IServiceCollection AddHttpDependencyMetadataResolver(this IService /// Adds services required for HTTP dependency metadata resolution with the specified metadata providers. /// /// The to add the services to. - /// The HTTP dependency metadata providers to register. + /// The HTTP dependency metadata providers to register. /// The so that additional calls can be chained. public static IServiceCollection AddHttpDependencyMetadataResolver( this IServiceCollection services, - params IHttpDependencyMetadata[] metadataProviders) + params IDownstreamDependencyMetadata[] providers) { - foreach (var provider in metadataProviders) + _ = Throw.IfNull(services); + + foreach (var provider in providers) { - services.TryAddEnumerable(ServiceDescriptor.Singleton(provider)); + services.TryAddEnumerable(ServiceDescriptor.Singleton(provider)); } services.TryAddSingleton(); - return services; } } diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/IHttpDependencyMetadata.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/IHttpDependencyMetadata.cs deleted file mode 100644 index 489eb3d0bcd..00000000000 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/IHttpDependencyMetadata.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections.Generic; - -namespace Microsoft.Extensions.Http.Diagnostics; - -/// -/// Interface for passing dependency metadata. -/// -public interface IHttpDependencyMetadata -{ - /// - /// Gets the name of the dependent service. - /// - string DependencyName { get; } - - /// - /// Gets the list of host name suffixes that can uniquely identify a host as this dependency. - /// - ISet UniqueHostNameSuffixes { get; } - - /// - /// Gets the list of all metadata for all routes to the dependency service. - /// - ISet RequestMetadata { get; } -} diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Logging/Internal/HttpRequestReader.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Logging/Internal/HttpRequestReader.cs index 78cb73bbddc..c9d7883a22c 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Logging/Internal/HttpRequestReader.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Logging/Internal/HttpRequestReader.cs @@ -12,7 +12,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Http.Diagnostics; using Microsoft.Extensions.Options; -using Microsoft.Extensions.Telemetry.Internal; using Microsoft.Shared.Diagnostics; using Microsoft.Shared.Pools; @@ -43,7 +42,7 @@ internal sealed class HttpRequestReader : IHttpRequestReader private readonly OutgoingPathLoggingMode _outgoingPathLogMode; private readonly IOutgoingRequestContext _requestMetadataContext; - private readonly IDownstreamDependencyMetadataManager? _downstreamDependencyMetadataManager; + private readonly HttpDependencyMetadataResolver? _dependencyMetadataResolver; public HttpRequestReader( IServiceProvider serviceProvider, @@ -51,7 +50,7 @@ public HttpRequestReader( IHttpRouteFormatter routeFormatter, IHttpRouteParser httpRouteParser, IOutgoingRequestContext requestMetadataContext, - IDownstreamDependencyMetadataManager? downstreamDependencyMetadataManager = null, + HttpDependencyMetadataResolver? dependencyMetadataResolver = null, [ServiceKey] string? serviceKey = null) : this( optionsMonitor.GetKeyedOrCurrent(serviceKey), @@ -59,7 +58,7 @@ public HttpRequestReader( httpRouteParser, serviceProvider.GetRequiredOrKeyedRequiredService(serviceKey), requestMetadataContext, - downstreamDependencyMetadataManager) + dependencyMetadataResolver) { } @@ -69,7 +68,7 @@ internal HttpRequestReader( IHttpRouteParser httpRouteParser, IHttpHeadersReader httpHeadersReader, IOutgoingRequestContext requestMetadataContext, - IDownstreamDependencyMetadataManager? downstreamDependencyMetadataManager = null) + HttpDependencyMetadataResolver? dependencyMetadataResolver = null) { _outgoingPathLogMode = Throw.IfOutOfRange(options.RequestPathLoggingMode); _httpHeadersReader = httpHeadersReader; @@ -77,7 +76,7 @@ internal HttpRequestReader( _routeFormatter = routeFormatter; _httpRouteParser = httpRouteParser; _requestMetadataContext = requestMetadataContext; - _downstreamDependencyMetadataManager = downstreamDependencyMetadataManager; + _dependencyMetadataResolver = dependencyMetadataResolver; _defaultSensitiveParameters = options.RouteParameterDataClasses.ToFrozenDictionary(StringComparer.Ordinal); _queryParameterDataClasses = options.RequestQueryParametersDataClasses.ToFrozenDictionary(StringComparer.Ordinal); @@ -234,7 +233,7 @@ private void GetRedactedPathAndParameters(HttpRequestMessage request, LogRecord var requestMetadata = request.GetRequestMetadata() ?? _requestMetadataContext.RequestMetadata ?? - _downstreamDependencyMetadataManager?.GetRequestMetadata(request); + _dependencyMetadataResolver?.GetRequestMetadata(request); if (requestMetadata == null) { From 51e6cce9f543de9ab740b164c81bd0890c017e5d Mon Sep 17 00:00:00 2001 From: Dmytro Bohdanov Date: Wed, 8 Oct 2025 15:43:58 +0200 Subject: [PATCH 05/18] update api according to the proposal --- .../Http/HttpDependencyMetadataResolver.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs index a1fca06c841..e9e1845dd90 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs @@ -8,6 +8,7 @@ using System.Net; using System.Net.Http; using System.Text.RegularExpressions; +using Microsoft.Shared.Diagnostics; namespace Microsoft.Extensions.Http.Diagnostics; @@ -41,10 +42,7 @@ internal readonly struct ProcessedMetadata /// is . protected HttpDependencyMetadataResolver(IEnumerable dependencyMetadata) { - if (dependencyMetadata == null) - { - throw new ArgumentNullException(nameof(dependencyMetadata)); - } + _ = Throw.IfNull(dependencyMetadata); Dictionary dependencyTrieMap = []; foreach (var dependency in dependencyMetadata) @@ -55,6 +53,7 @@ protected HttpDependencyMetadataResolver(IEnumerable /// Gets request metadata for the specified HTTP request message. /// @@ -78,7 +77,7 @@ protected HttpDependencyMetadataResolver(IEnumerable /// Gets request metadata for the specified HTTP web request. /// @@ -97,6 +96,7 @@ protected HttpDependencyMetadataResolver(IEnumerable Date: Wed, 22 Oct 2025 16:22:02 +0200 Subject: [PATCH 06/18] remove conditional compilation --- .../Http/HttpDependencyMetadataResolver.cs | 23 ------------------- .../Logging/Internal/IHttpRequestReader.cs | 1 + 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs index e9e1845dd90..d1435df39db 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs @@ -5,7 +5,6 @@ using System.Collections.Frozen; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; -using System.Net; using System.Net.Http; using System.Text.RegularExpressions; using Microsoft.Shared.Diagnostics; @@ -53,7 +52,6 @@ protected HttpDependencyMetadataResolver(IEnumerable /// Gets request metadata for the specified HTTP request message. /// @@ -77,27 +75,6 @@ protected HttpDependencyMetadataResolver(IEnumerable - /// Gets request metadata for the specified HTTP web request. - /// - /// The HTTP web request. - /// The resolved if found; otherwise, . - public virtual RequestMetadata? GetRequestMetadata(HttpWebRequest requestMessage) - { - try - { - var hostMetadata = GetHostMetadata(requestMessage.RequestUri.Host); - return GetRequestMetadataInternal(requestMessage.Method, requestMessage.RequestUri.AbsolutePath, hostMetadata); - } - catch (Exception) - { - // Catch exceptions here to avoid impacting services if a bug ever gets introduced in this path. - return null; - } - } -#endif - private static char[] MakeToUpperArray() { // Initialize the _toUpper array for quick conversion of any ascii char to upper diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Logging/Internal/IHttpRequestReader.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Logging/Internal/IHttpRequestReader.cs index a0a93df0dd8..3c0614fbc06 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Logging/Internal/IHttpRequestReader.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Logging/Internal/IHttpRequestReader.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; +using System.Net; using System.Net.Http; using System.Threading; using System.Threading.Tasks; From 397d5df7381dd64729c15dfbbc8faec865b1fc01 Mon Sep 17 00:00:00 2001 From: Dmytro Bohdanov Date: Wed, 22 Oct 2025 16:44:32 +0200 Subject: [PATCH 07/18] fix lint --- .../DefaultHttpDependencyMetadataResolver.cs | 3 +++ .../Http/HttpDependencyMetadataResolver.cs | 2 ++ ...pDiagnosticsServiceCollectionExtensions.cs | 25 +++---------------- 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/DefaultHttpDependencyMetadataResolver.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/DefaultHttpDependencyMetadataResolver.cs index fa15cea6283..4218029224d 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/DefaultHttpDependencyMetadataResolver.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/DefaultHttpDependencyMetadataResolver.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using Microsoft.Shared.DiagnosticIds; namespace Microsoft.Extensions.Http.Diagnostics; @@ -9,6 +11,7 @@ namespace Microsoft.Extensions.Http.Diagnostics; /// Default implementation of that uses the base /// trie-based lookup algorithm. /// +[Experimental(diagnosticId: DiagnosticIds.Experiments.Telemetry, UrlFormat = DiagnosticIds.UrlFormat)] public sealed class DefaultHttpDependencyMetadataResolver : HttpDependencyMetadataResolver { /// diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs index d1435df39db..7cdae3dca99 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs @@ -7,6 +7,7 @@ using System.Diagnostics.CodeAnalysis; using System.Net.Http; using System.Text.RegularExpressions; +using Microsoft.Shared.DiagnosticIds; using Microsoft.Shared.Diagnostics; namespace Microsoft.Extensions.Http.Diagnostics; @@ -19,6 +20,7 @@ namespace Microsoft.Extensions.Http.Diagnostics; /// configured metadata using specialized trie-based data structures. This enables efficient lookup /// of service information, operation names, and other metadata for telemetry and policy application. /// +[Experimental(diagnosticId: DiagnosticIds.Experiments.Telemetry, UrlFormat = DiagnosticIds.UrlFormat)] public abstract class HttpDependencyMetadataResolver { internal readonly struct ProcessedMetadata diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDiagnosticsServiceCollectionExtensions.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDiagnosticsServiceCollectionExtensions.cs index 8a70a5d6860..11792a0a8c8 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDiagnosticsServiceCollectionExtensions.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDiagnosticsServiceCollectionExtensions.cs @@ -4,6 +4,7 @@ using System.Diagnostics.CodeAnalysis; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Http.Diagnostics; +using Microsoft.Shared.DiagnosticIds; using Microsoft.Shared.Diagnostics; namespace Microsoft.Extensions.DependencyInjection; @@ -49,30 +50,10 @@ public static IServiceCollection AddDownstreamDependencyMetadata(this IServiceCo /// /// The to add the services to. /// The so that additional calls can be chained. - public static IServiceCollection AddHttpDependencyMetadataResolver(this IServiceCollection services) + [Experimental(diagnosticId: DiagnosticIds.Experiments.Telemetry, UrlFormat = DiagnosticIds.UrlFormat)] + public static IServiceCollection AddStandardHttpDependencyMetadataResolver(this IServiceCollection services) { services.TryAddSingleton(); return services; } - - /// - /// Adds services required for HTTP dependency metadata resolution with the specified metadata providers. - /// - /// The to add the services to. - /// The HTTP dependency metadata providers to register. - /// The so that additional calls can be chained. - public static IServiceCollection AddHttpDependencyMetadataResolver( - this IServiceCollection services, - params IDownstreamDependencyMetadata[] providers) - { - _ = Throw.IfNull(services); - - foreach (var provider in providers) - { - services.TryAddEnumerable(ServiceDescriptor.Singleton(provider)); - } - - services.TryAddSingleton(); - return services; - } } From e045b3b17aca0ff73d7c600afb6c7a6a2b1236af Mon Sep 17 00:00:00 2001 From: Dmytro Bohdanov Date: Wed, 22 Oct 2025 17:02:09 +0200 Subject: [PATCH 08/18] remove unused using --- .../Logging/Internal/IHttpRequestReader.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Logging/Internal/IHttpRequestReader.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Logging/Internal/IHttpRequestReader.cs index 3c0614fbc06..a0a93df0dd8 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Logging/Internal/IHttpRequestReader.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Logging/Internal/IHttpRequestReader.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; -using System.Net; using System.Net.Http; using System.Threading; using System.Threading.Tasks; From fa5a9b66f661dad48dc6066a58859d26d39f9f48 Mon Sep 17 00:00:00 2001 From: Dmytro Bohdanov Date: Wed, 22 Oct 2025 17:35:13 +0200 Subject: [PATCH 09/18] update extension methods --- .../Http/HttpDependencyMetadataResolver.cs | 2 +- .../Http/HttpDiagnosticsServiceCollectionExtensions.cs | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs index 7cdae3dca99..ed0b442c16c 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs @@ -63,7 +63,7 @@ protected HttpDependencyMetadataResolver(IEnumerable(downstreamDependencyMetadata)); services.TryAddSingleton(); + _ = services.AddSingleton(downstreamDependencyMetadata); + return services; } @@ -40,8 +39,8 @@ public static IServiceCollection AddDownstreamDependencyMetadata(this IServiceCo where T : class, IDownstreamDependencyMetadata { _ = Throw.IfNull(services); - services.TryAddEnumerable(ServiceDescriptor.Singleton()); services.TryAddSingleton(); + _ = services.AddSingleton(); return services; } From ba2c5f35064e483b959c5d6fdc559aa1fe7ecd64 Mon Sep 17 00:00:00 2001 From: Dmytro Bohdanov Date: Wed, 22 Oct 2025 18:00:23 +0200 Subject: [PATCH 10/18] fix warnings --- .../Http/HttpDependencyMetadataResolver.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs index ed0b442c16c..7cdae3dca99 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs @@ -63,7 +63,7 @@ protected HttpDependencyMetadataResolver(IEnumerable Date: Thu, 30 Oct 2025 16:58:24 +0100 Subject: [PATCH 11/18] remove AddStandardHttpDependencyMetadataResolver API, fix PR comments --- .../Http/DefaultHttpDependencyMetadataResolver.cs | 2 +- .../Http/HttpDependencyMetadataResolver.cs | 4 +++- .../HttpDiagnosticsServiceCollectionExtensions.cs | 12 ------------ .../Http/IDownstreamDependencyMetadata.cs | 2 +- 4 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/DefaultHttpDependencyMetadataResolver.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/DefaultHttpDependencyMetadataResolver.cs index 4218029224d..5083abf6581 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/DefaultHttpDependencyMetadataResolver.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/DefaultHttpDependencyMetadataResolver.cs @@ -12,7 +12,7 @@ namespace Microsoft.Extensions.Http.Diagnostics; /// trie-based lookup algorithm. /// [Experimental(diagnosticId: DiagnosticIds.Experiments.Telemetry, UrlFormat = DiagnosticIds.UrlFormat)] -public sealed class DefaultHttpDependencyMetadataResolver : HttpDependencyMetadataResolver +internal sealed class DefaultHttpDependencyMetadataResolver : HttpDependencyMetadataResolver { /// /// Initializes a new instance of the class. diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs index 7cdae3dca99..4203cb8e149 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs @@ -55,7 +55,7 @@ protected HttpDependencyMetadataResolver(IEnumerable - /// Gets request metadata for the specified HTTP request message. + /// Gets request metadata for the specified instance of /// /// The HTTP request message. /// The resolved if found; otherwise, . @@ -450,4 +450,6 @@ private void AddHostnameToTrie(string hostNameSuffix, string dependencyName) hostMetadata.RequestMetadata : // Return the default request metadata for this host if no matching route is found. routeMetadataTrieRoot.RequestMetadatas[trieCurrent.RequestMetadataEntryIndex]; } +}ataTrieRoot.RequestMetadatas[trieCurrent.RequestMetadataEntryIndex]; + } } \ No newline at end of file diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDiagnosticsServiceCollectionExtensions.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDiagnosticsServiceCollectionExtensions.cs index ad63c247948..5ed1fd8ba5c 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDiagnosticsServiceCollectionExtensions.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDiagnosticsServiceCollectionExtensions.cs @@ -43,16 +43,4 @@ public static IServiceCollection AddDownstreamDependencyMetadata(this IServiceCo _ = services.AddSingleton(); return services; } - - /// - /// Adds services required for HTTP dependency metadata resolution. - /// - /// The to add the services to. - /// The so that additional calls can be chained. - [Experimental(diagnosticId: DiagnosticIds.Experiments.Telemetry, UrlFormat = DiagnosticIds.UrlFormat)] - public static IServiceCollection AddStandardHttpDependencyMetadataResolver(this IServiceCollection services) - { - services.TryAddSingleton(); - return services; - } } diff --git a/src/Libraries/Microsoft.Extensions.Telemetry.Abstractions/Http/IDownstreamDependencyMetadata.cs b/src/Libraries/Microsoft.Extensions.Telemetry.Abstractions/Http/IDownstreamDependencyMetadata.cs index bed838f31e7..671e1dc3c2c 100644 --- a/src/Libraries/Microsoft.Extensions.Telemetry.Abstractions/Http/IDownstreamDependencyMetadata.cs +++ b/src/Libraries/Microsoft.Extensions.Telemetry.Abstractions/Http/IDownstreamDependencyMetadata.cs @@ -6,7 +6,7 @@ namespace Microsoft.Extensions.Http.Diagnostics; /// -/// Interface for passing dependency metadata. +/// (Obsolete) Use . /// public interface IDownstreamDependencyMetadata { From 5f5e6e358d213baa05da53e23323850d11d3da73 Mon Sep 17 00:00:00 2001 From: Dmytro Bohdanov Date: Thu, 30 Oct 2025 17:27:27 +0100 Subject: [PATCH 12/18] fix crefs --- .../Http/IDownstreamDependencyMetadata.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Libraries/Microsoft.Extensions.Telemetry.Abstractions/Http/IDownstreamDependencyMetadata.cs b/src/Libraries/Microsoft.Extensions.Telemetry.Abstractions/Http/IDownstreamDependencyMetadata.cs index 671e1dc3c2c..a77707ad605 100644 --- a/src/Libraries/Microsoft.Extensions.Telemetry.Abstractions/Http/IDownstreamDependencyMetadata.cs +++ b/src/Libraries/Microsoft.Extensions.Telemetry.Abstractions/Http/IDownstreamDependencyMetadata.cs @@ -6,7 +6,7 @@ namespace Microsoft.Extensions.Http.Diagnostics; /// -/// (Obsolete) Use . +/// (Obsolete) Use . /// public interface IDownstreamDependencyMetadata { From e9839a63786dafdada3b3b4548c13bf6bd4c6c39 Mon Sep 17 00:00:00 2001 From: Dmytro Bohdanov Date: Thu, 30 Oct 2025 17:29:55 +0100 Subject: [PATCH 13/18] fix build --- .../Http/HttpDependencyMetadataResolver.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs index 4203cb8e149..a46bc75fc45 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs @@ -450,6 +450,4 @@ private void AddHostnameToTrie(string hostNameSuffix, string dependencyName) hostMetadata.RequestMetadata : // Return the default request metadata for this host if no matching route is found. routeMetadataTrieRoot.RequestMetadatas[trieCurrent.RequestMetadataEntryIndex]; } -}ataTrieRoot.RequestMetadatas[trieCurrent.RequestMetadataEntryIndex]; - } } \ No newline at end of file From 27f1f56e3afa6ab0592fa61d7bf21855ac19e66e Mon Sep 17 00:00:00 2001 From: Dmytro Bohdanov Date: Thu, 30 Oct 2025 17:41:25 +0100 Subject: [PATCH 14/18] revert interface changes --- .../Http/IDownstreamDependencyMetadata.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Libraries/Microsoft.Extensions.Telemetry.Abstractions/Http/IDownstreamDependencyMetadata.cs b/src/Libraries/Microsoft.Extensions.Telemetry.Abstractions/Http/IDownstreamDependencyMetadata.cs index a77707ad605..bed838f31e7 100644 --- a/src/Libraries/Microsoft.Extensions.Telemetry.Abstractions/Http/IDownstreamDependencyMetadata.cs +++ b/src/Libraries/Microsoft.Extensions.Telemetry.Abstractions/Http/IDownstreamDependencyMetadata.cs @@ -6,7 +6,7 @@ namespace Microsoft.Extensions.Http.Diagnostics; /// -/// (Obsolete) Use . +/// Interface for passing dependency metadata. /// public interface IDownstreamDependencyMetadata { From 46fa1abdaf9de118d7e57b10ef30e7faf60f444c Mon Sep 17 00:00:00 2001 From: Dmytro Bohdanov Date: Thu, 30 Oct 2025 17:45:07 +0100 Subject: [PATCH 15/18] remove interface and rename tests --- .../IDownstreamDependencyMetadataManager.cs | 30 ------------------- ...=> HttpDependencyMetadataResolverTests.cs} | 4 +-- 2 files changed, 2 insertions(+), 32 deletions(-) delete mode 100644 src/Libraries/Microsoft.Extensions.Http.Diagnostics/Logging/Internal/IDownstreamDependencyMetadataManager.cs rename test/Libraries/Microsoft.Extensions.Http.Diagnostics.Tests/Telemetry/{DownstreamDependencyMetadataManagerTests.cs => HttpDependencyMetadataResolverTests.cs} (97%) diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Logging/Internal/IDownstreamDependencyMetadataManager.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Logging/Internal/IDownstreamDependencyMetadataManager.cs deleted file mode 100644 index 2da95ca2b95..00000000000 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Logging/Internal/IDownstreamDependencyMetadataManager.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Net; -using System.Net.Http; -using Microsoft.Extensions.Http.Diagnostics; - -namespace Microsoft.Extensions.Telemetry.Internal; - -/// -/// (Obsolete) Use . -/// -[Obsolete("Use HttpDependencyMetadataResolver instead. This internal interface will be removed.")] -internal interface IDownstreamDependencyMetadataManager -{ - /// - /// Get metadata for the given request. - /// - /// Request object. - /// object. - RequestMetadata? GetRequestMetadata(HttpRequestMessage requestMessage); - - /// - /// Get metadata for the given request. - /// - /// Request object. - /// object. - RequestMetadata? GetRequestMetadata(HttpWebRequest requestMessage); -} diff --git a/test/Libraries/Microsoft.Extensions.Http.Diagnostics.Tests/Telemetry/DownstreamDependencyMetadataManagerTests.cs b/test/Libraries/Microsoft.Extensions.Http.Diagnostics.Tests/Telemetry/HttpDependencyMetadataResolverTests.cs similarity index 97% rename from test/Libraries/Microsoft.Extensions.Http.Diagnostics.Tests/Telemetry/DownstreamDependencyMetadataManagerTests.cs rename to test/Libraries/Microsoft.Extensions.Http.Diagnostics.Tests/Telemetry/HttpDependencyMetadataResolverTests.cs index c0763cc7ed8..ce9b44e3dc2 100644 --- a/test/Libraries/Microsoft.Extensions.Http.Diagnostics.Tests/Telemetry/DownstreamDependencyMetadataManagerTests.cs +++ b/test/Libraries/Microsoft.Extensions.Http.Diagnostics.Tests/Telemetry/HttpDependencyMetadataResolverTests.cs @@ -9,12 +9,12 @@ namespace Microsoft.Extensions.Telemetry.Telemetry; -public class DownstreamDependencyMetadataManagerTests : IDisposable +public class HttpDependencyMetadataResolverTests : IDisposable { private readonly HttpDependencyMetadataResolver _metadataResolver; private readonly ServiceProvider _sp; - public DownstreamDependencyMetadataManagerTests() + public HttpDependencyMetadataResolverTests() { _sp = new ServiceCollection() .AddDownstreamDependencyMetadata(new BackslashDownstreamDependencyMetadata()) From 2c2ef478f2d3861cd4c7f3143615ed5d93cbacef Mon Sep 17 00:00:00 2001 From: Dmytro Bohdanov Date: Fri, 31 Oct 2025 10:50:42 +0100 Subject: [PATCH 16/18] fix lint --- .../Http/HttpDependencyMetadataResolver.cs | 2 +- .../Http/HttpDiagnosticsServiceCollectionExtensions.cs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs index a46bc75fc45..179956fb3ea 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs @@ -55,7 +55,7 @@ protected HttpDependencyMetadataResolver(IEnumerable - /// Gets request metadata for the specified instance of + /// Gets request metadata for the specified instance of . /// /// The HTTP request message. /// The resolved if found; otherwise, . diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDiagnosticsServiceCollectionExtensions.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDiagnosticsServiceCollectionExtensions.cs index 5ed1fd8ba5c..8fd2d142cc9 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDiagnosticsServiceCollectionExtensions.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDiagnosticsServiceCollectionExtensions.cs @@ -4,7 +4,6 @@ using System.Diagnostics.CodeAnalysis; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Http.Diagnostics; -using Microsoft.Shared.DiagnosticIds; using Microsoft.Shared.Diagnostics; namespace Microsoft.Extensions.DependencyInjection; From ba412bb426686a8926e33a31bbe585978309a7ee Mon Sep 17 00:00:00 2001 From: Dmytro Bohdanov Date: Thu, 6 Nov 2025 14:32:04 +0100 Subject: [PATCH 17/18] remove experimental attribute from the internal class --- .../Http/DefaultHttpDependencyMetadataResolver.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/DefaultHttpDependencyMetadataResolver.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/DefaultHttpDependencyMetadataResolver.cs index 5083abf6581..8b6c1c6c189 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/DefaultHttpDependencyMetadataResolver.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/DefaultHttpDependencyMetadataResolver.cs @@ -11,7 +11,6 @@ namespace Microsoft.Extensions.Http.Diagnostics; /// Default implementation of that uses the base /// trie-based lookup algorithm. /// -[Experimental(diagnosticId: DiagnosticIds.Experiments.Telemetry, UrlFormat = DiagnosticIds.UrlFormat)] internal sealed class DefaultHttpDependencyMetadataResolver : HttpDependencyMetadataResolver { /// From e9269496828586afe213fd664f9b37ee02cb55b9 Mon Sep 17 00:00:00 2001 From: Dmytro Bohdanov Date: Thu, 6 Nov 2025 15:05:38 +0100 Subject: [PATCH 18/18] fix lint --- .../Http/DefaultHttpDependencyMetadataResolver.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/DefaultHttpDependencyMetadataResolver.cs b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/DefaultHttpDependencyMetadataResolver.cs index 8b6c1c6c189..776bd26df39 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/DefaultHttpDependencyMetadataResolver.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/DefaultHttpDependencyMetadataResolver.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using Microsoft.Shared.DiagnosticIds; namespace Microsoft.Extensions.Http.Diagnostics;