-
Couldn't load subscription status.
- Fork 840
HttpDependencyMetadataResolver class for the custom downstream dependency metadata resolution #6880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the downstream dependency metadata resolution system by introducing a new public API HttpDependencyMetadataResolver to replace the internal IDownstreamDependencyMetadataManager interface. The changes expose the dependency metadata resolution functionality with improved naming and flexibility.
- Renames internal
DownstreamDependencyMetadataManagerto publicHttpDependencyMetadataResolveras an abstract class - Adds
DefaultHttpDependencyMetadataResolveras the default implementation - Updates registration methods to use
TryAddEnumerablefor proper DI behavior with multiple metadata instances
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| HttpDependencyMetadataResolver.cs | Converts internal sealed class to public abstract class with documentation and removes obsolete HttpWebRequest support |
| DefaultHttpDependencyMetadataResolver.cs | New sealed class providing default implementation of the resolver |
| HttpDiagnosticsServiceCollectionExtensions.cs | Updates registration to use TryAddEnumerable and adds new AddStandardHttpDependencyMetadataResolver method |
| HttpRequestReader.cs | Updates field and parameter names to use new resolver type |
| IDownstreamDependencyMetadataManager.cs | Marks internal interface as obsolete |
| DownstreamDependencyMetadataManagerTests.cs | Updates test class to use new resolver type and namespace |
src/Libraries/Microsoft.Extensions.Http.Diagnostics/Http/HttpDependencyMetadataResolver.cs
Show resolved
Hide resolved
| /// Adds services required for HTTP dependency metadata resolution. | ||
| /// </summary> | ||
| /// <param name="services">The <see cref="IServiceCollection"/> to add the services to.</param> | ||
| /// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns> |
Copilot
AI
Oct 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation should clarify the relationship between AddStandardHttpDependencyMetadataResolver and AddDownstreamDependencyMetadata. It's unclear whether calling this method requires or replaces calling AddDownstreamDependencyMetadata, or if they should be used together.
| /// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns> | |
| /// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns> | |
| /// <remarks> | |
| /// <para> | |
| /// <b>Relationship to <see cref="AddDownstreamDependencyMetadata(IServiceCollection, IDownstreamDependencyMetadata)"/> and <see cref="AddDownstreamDependencyMetadata{T}(IServiceCollection)"/>:</b> | |
| /// </para> | |
| /// <para> | |
| /// <see cref="AddStandardHttpDependencyMetadataResolver(IServiceCollection)"/> only registers the default HTTP dependency metadata resolver. | |
| /// If you need to provide custom downstream dependency metadata, use <see cref="AddDownstreamDependencyMetadata(IServiceCollection, IDownstreamDependencyMetadata)"/> | |
| /// or <see cref="AddDownstreamDependencyMetadata{T}(IServiceCollection)"/>. These methods also register the resolver if it is not already present. | |
| /// </para> | |
| /// <para> | |
| /// You do not need to call both methods unless you want to register the resolver without any downstream dependency metadata. | |
| /// Calling <see cref="AddDownstreamDependencyMetadata"/> is sufficient if you are registering metadata, as it also adds the resolver. | |
| /// </para> | |
| /// </remarks> |
| _ = services.AddSingleton(downstreamDependencyMetadata); | ||
| _ = Throw.IfNull(downstreamDependencyMetadata); | ||
|
|
||
| services.TryAddEnumerable(ServiceDescriptor.Singleton<IDownstreamDependencyMetadata>(downstreamDependencyMetadata)); |
Copilot
AI
Oct 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change from AddSingleton to TryAddEnumerable is correct for allowing multiple metadata registrations, but there's an inconsistency: the resolver registration on line 29 uses TryAddSingleton, which means only the first resolver wins. This could cause issues if someone registers multiple metadata instances expecting them all to be used. Consider documenting this behavior or ensuring the resolver is only registered once before any metadata registrations.
| { | ||
| _ = Throw.IfNull(services); | ||
| services.TryAddSingleton<IDownstreamDependencyMetadataManager, DownstreamDependencyMetadataManager>(); | ||
| services.TryAddSingleton<HttpDependencyMetadataResolver, DefaultHttpDependencyMetadataResolver>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since calling AddDownstreamDependencyMetadata already includes the DefaultHttpDependencyMetadataResolver, when would a user ever need AddStandardHttpDependencyMetadataResolver? Right now, it's unclear from the documentation alone and might confuse people.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that we auto register these resolvers, it might be a good idea to remove this excessive AddStandardHttpDependencyMetadataResolver method. @evgenyfedorov2 wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree, let's remove AddStandardHttpDependencyMetadataResolver. It is not part of approved API either
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="HttpDependencyMetadataResolver"/> class. | ||
| /// </summary> | ||
| /// <param name="dependencyMetadata">A collection of HTTP dependency metadata used for request resolution.</param> | ||
| /// <exception cref="ArgumentNullException"><paramref name="dependencyMetadata"/> is <see langword="null"/>.</exception> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't have to have XML comments for protected methods
|
|
||
| public RequestMetadata? GetRequestMetadata(HttpRequestMessage requestMessage) | ||
| /// <summary> | ||
| /// Gets request metadata for the specified HTTP request message. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// Gets request metadata for the specified HTTP request message. | |
| /// Gets request metadata for the specified instance of <see cref="HttpRequestMessage">. |
|
|
||
| /// <summary> | ||
| /// Interface to manage dependency metadata. | ||
| /// (Obsolete) Use <see cref="HttpDependencyMetadataResolver"/>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just remove this?
| /// trie-based lookup algorithm. | ||
| /// </summary> | ||
| [Experimental(diagnosticId: DiagnosticIds.Experiments.Telemetry, UrlFormat = DiagnosticIds.UrlFormat)] | ||
| public sealed class DefaultHttpDependencyMetadataResolver : HttpDependencyMetadataResolver |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this need to public?
| { | ||
| _ = Throw.IfNull(services); | ||
| services.TryAddSingleton<IDownstreamDependencyMetadataManager, DownstreamDependencyMetadataManager>(); | ||
| services.TryAddSingleton<HttpDependencyMetadataResolver, DefaultHttpDependencyMetadataResolver>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree, let's remove AddStandardHttpDependencyMetadataResolver. It is not part of approved API either
As per following API proposal, this PR exposes the
DownstreamDependencyMetadataManagerclass with the new name that allows you to configure the downstream dependency metadata resolution and brings more flexibility into the flowMicrosoft Reviewers: Open in CodeFlow