Skip to content

Allow specifying a context propagator on SocketsHttpHandler #55556

Closed
@MihaZupan

Description

@MihaZupan

Background and Motivation

We approved the Propagator APIs in #50658, which we are consuming in the HttpClient stack.

The approved API includes a global static property Current.

Some advanced cases require more granular control over which propagator is used - for example only enabling propagation for a given handler/destination/library.
Unit testing of applications/libraries is also difficult without resorting to hacks like RemoteExecutor / writing a custom composite propagator / disabling test parallelization.
To address these scenarios, we propose exposing a property on SocketsHttpHandler to control which propagator is used.

Proposed API

namespace System.Net.Http
{
    public sealed class SocketsHttpHandler
    {
        public DistributedContextPropagator? ActivityHeadersPropagator { get; set; }
    }
}

null means no propagation.

Usage Examples

using var handler = new SocketsHttpHandler
{
    ActivityHeadersPropagator = DistributedContextPropagator.CreatePassThroughPropagator()
};

Alternative Designs

Different names for the property, e.g.

  • DistributedContextPropagator? DistributedContextPropagator { get; set; }
    • property name the same as the type name
    • Comment here was that we can be more specific about the property's role specifically for SocketsHttpHandler to hopefully make it easier for users to understand

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions