Skip to content

Ability to set and extract request metadata for outgoing http requests #84728

Closed as duplicate

Description

@dpk83

Ask:
An ability to extract some useful route/request metadata about the request inside HttpMessageHandlers/DelegatingHandlers.

Currently in AspNetCore the routing component provide applications the ability to get route metadata for incoming HTTP requests. This let application and library developers to utilize this information in custom middlewares. A similar capability however lacks in the HttpClient framework as there is no way for a handler in pipeline to determine the route of the request.

Scenario
Currently we write telemetry libraries for consumption by 100s of services in our org. These telemetry libraries automatically captures and emit telemetry about incoming and outgoing http requests. When capturing metrics to monitor service health and gain useful insights the captured metrics need to be able to narrow down the problems by the requests (if certain requests are impacted or all requests are impacted) or by the target service to which the requests are made, so one can see which of the target service is unhealthy.

For the incoming requests the telemetry middlewares can extract the route information from route metadata provided by endpoint routing, however for outgoing requests delegating handlers don't have access to any such information. They only have access to the full URL which can't be used when capturing metrics becuase URLs might have parameters which leads to every URL being different at which point it just becomes not useful.

Currently everywhere services have to write their custom logics or library developers provide hooks for services to provide such information. Because at that point service developers have no way to get this information easily they need to resort to using regular expressions to match the URL with some set of list of routes. This regular expression matching becomes extremely inefficient. So, the ask is for dotnet runtime to include some efficient mechanism to extract the route information and possibility some additional metadata like a friendly name of the target service where the http client is making request to.

What we have
As part of telemetry libraries we have created our own solution to let services configure and register metadata with us when they configure our telemetry libraries. Our libraries then performs the matching of requests against routes (in a more efficient manner without involving regexes) to extract the metadata so it can be included in the telemetry.

We would like to see an efficient solution from dotnet runtime itself which can provide metadata about outgoing requests to these delegating handlers.

Activity

  1. ghost added
    untriaged
    on Apr 12, 2023
  2. dpk83 commented on Apr 12, 2023

    @dpk83
    Author
  3. added this to the 8.0.0 milestone on Apr 12, 2023
  4. ghost removed
    untriaged
    on Apr 12, 2023
  5. added
    untriaged
    partner-impact
    on Apr 12, 2023
  6. removed
    untriaged
    on Apr 13, 2023
  7. modified the milestones: 8.0.0, Future on Apr 23, 2023
  8. tarekgh commented on Apr 23, 2023

    @tarekgh
    Member

    @dpk83 per last discussion with @noahfalk, moving this issue to future milestone to consider it after .NET 8.0.

  9. removed their assignment
    on Apr 23, 2023
  10. antonfirsov commented on Aug 29, 2023

    @antonfirsov
    Contributor

    @dpk83 is this issue talking about enrichment? If so, can we considered it to be done as part of #86281 and related work in higher levels of the stack?

  11. antonfirsov commented on May 22, 2025

    @antonfirsov
    Contributor

    The client side counterpart of http.route would be url.template, therefore closing this as duplicate of #110017.

    Please reopen if I'm misunderstanding the request.

  12. locked and limited conversation to collaborators on Jun 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Net.Httppartner-impact

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions