question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[feature] add a new http pipeline policy for special header `client-request-id` and `return-client-request-id`

See original GitHub issue

Batch service will have special header client-request-id and return-client-request-id set in HTTP request for diagnostic instead of x-ms-client-request-id and x-ms-return-client-request-id which are used in other Azure Service for diagnostic.

Current in .Net Azure.Core pipeline, the ClientRequestIdPolicy is added into pipeline by default, so each http request has x-ms-client-request-id and x-ms-return-client-request-id see following: https://github.com/Azure/azure-sdk-for-net/blob/592196f5c96a5bfdb7ab29fd28fec2db6edffdcd/sdk/core/Azure.Core/src/Pipeline/HttpPipelineBuilder.cs#L148-L149

policies.Add(ClientRequestIdPolicy.Shared); 

Expected behavior: in each http request message, there are client-request-id and return-client-request-id but there are no x-ms-client-request-id and x-ms-return-client-request-id.

So there are two possible approach:

approach 1

update existing ClientRequestIdPolicy and let it accept a parameter to customize the head name, and in HttpPipelineBuilder will update the head name when add it.

approach 2

To recognize those two headers,

  • SDK will instrument a policy similar as ClientRequestIdPolicy into HTTP pipeline, and pipeline will append those two headers for each http request.

  • And HttpPipelineBuilder will not add ClientRequestIdPolicy by default.

Current Azure.Core does not have such policy. Can we add this new policy in Azure.Core and export it either mark it public or define it in Azure.Core.Shared?

expected new policy:

namespace Azure.Core.Pipeline
{
    internal class AzureClientRequestIdPolicy : HttpPipelineSynchronousPolicy
    {
        internal const string ClientRequestIdHeader = "client-request-id";
        internal const string EchoClientRequestId = "return-client-request-id";

        protected AzureClientRequestIdPolicy()
        {
        }

        public static AzureClientRequestIdPolicy Shared { get; } = new AzureClientRequestIdPolicy();

        public override void OnSendingRequest(HttpMessage message)
        {
            message.Request.Headers.SetValue(ClientRequestIdHeader, message.Request.ClientRequestId);
            message.Request.Headers.SetValue(EchoClientRequestId, "true");
        }
    }
}

Issue Analytics

  • State:open
  • Created 2 months ago
  • Comments:14 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
m-nashcommented, Jul 19, 2023

@jsquire as discussed in our last core sync, @chunyu3 will do an estimation exercise on what it would take to update the generator / custom code to no longer use the policy but instead simply add the headers always at request creation time.

@christothes was going to do an estimation exercise on how many fully hand written libraries would be impacted.

After both of these we were going to decide if we wanted to go with replacing the policy or not.

If we decide to replace the policy we need to be able to roll this out in a 2 phase process where adding the headers at the request level doesn’t conflict in a negative way with the policy. This could be a simple change in the policy to check existence before adding or some other mechanism. We would add the generator / manual code then once we are confident in the changes remove the policy from being added in the default pipeline.

If we decide not to replace the policy we need some public mechanism to change the name of the header to use since this is hard coded today.

In the meantime to unblock batch we will create an internal policy that runs after the Azure.Core one, removes the default named headers and adds the custom named headers.

1reaction
jsquirecommented, Jul 6, 2023

@chunyu3 : Can you please help us understand why this should be in Core rather than specific to Batch? Is this something that we believe is a pattern that we’ll see across Azure services? Do we have other examples of it in use currently?

Read more comments on GitHub >

github_iconTop Results From Across the Web

azure.core.pipeline.policies - Microsoft .NET
Allows custom values to be added to the User-Agent header. Parameters. base_user_agent (str) – Sets the base user agent value. Keyword Arguments.
Read more >
azure.core.pipeline.policies.HeadersPolicy class
A simple policy that sends the given headers with the request. This will overwrite any headers already defined in the request. Headers can...
Read more >
Embed Power BI Report In ASP.Net Core Website
As a workaround, you can compose the HTTP request directly. ... Headers.Add("return-client-request-id", "true"); realmRequest.Headers.
Read more >
General Guidelines: Azure Core | Azure SDKs
The HTTP pipeline consists of a HTTP transport that is wrapped by multiple policies. Each policy is a control point during which the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found