Skip to content

Conversation

@rainsxng
Copy link
Contributor

@rainsxng rainsxng commented Oct 2, 2025

As per following API proposal, this PR exposes the DownstreamDependencyMetadataManager class with the new name that allows you to configure the downstream dependency metadata resolution and brings more flexibility into the flow

Microsoft Reviewers: Open in CodeFlow

@rainsxng rainsxng changed the title new metadata resolver api HttpDependencyMetadataResolver class for the custom downstream dependency metadata resolution Oct 22, 2025
@rainsxng rainsxng marked this pull request as ready for review October 22, 2025 15:19
@rainsxng rainsxng requested a review from a team as a code owner October 22, 2025 15:19
Copilot AI review requested due to automatic review settings October 22, 2025 15:19
Copy link
Contributor

Copilot AI left a 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 DownstreamDependencyMetadataManager to public HttpDependencyMetadataResolver as an abstract class
  • Adds DefaultHttpDependencyMetadataResolver as the default implementation
  • Updates registration methods to use TryAddEnumerable for 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

/// 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>
Copy link

Copilot AI Oct 22, 2025

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.

Suggested change
/// <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>

Copilot uses AI. Check for mistakes.
_ = services.AddSingleton(downstreamDependencyMetadata);
_ = Throw.IfNull(downstreamDependencyMetadata);

services.TryAddEnumerable(ServiceDescriptor.Singleton<IDownstreamDependencyMetadata>(downstreamDependencyMetadata));
Copy link

Copilot AI Oct 22, 2025

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.

Copilot uses AI. Check for mistakes.
{
_ = Throw.IfNull(services);
services.TryAddSingleton<IDownstreamDependencyMetadataManager, DownstreamDependencyMetadataManager>();
services.TryAddSingleton<HttpDependencyMetadataResolver, DefaultHttpDependencyMetadataResolver>();
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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

Comment on lines +39 to +43
/// <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>
Copy link
Member

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// 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"/>.
Copy link
Member

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
Copy link
Member

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>();
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants