You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 17, 2018. It is now read-only.
Polly Policy instances can be used across multiple call sites for intended functional outcomes. This is a good fit for named HttpClient configurations on HttpClientFactory with a BaseUri eg api.contoso.com indicating all calls will be to endpoints on api.contoso.com.
To complement re-use, Polly provides an execution-scoped Context which travels with every execution. This:
(b) distinguishes different call sites at which Policy instances may be being used, allowing logging and telemetry to correlate statistics particular to a single usage site/call path;
For instance, it is typical to use the same circuit-breaker instance for all endpoints on api.contoso.com, but when analysing failures, it can be very useful to extract that call path A tended to be healthy but call path B tended to require retries, break circuits, etc.
The execution-scoped Polly.Context is already made available to policy delegate hooks (eg onRetry, onBreak etc) and will also be available to forthcoming raw telemetry events.
Without HttpClientFactory doing anything around this, correlation ids (a) would be inconsistent in cases where multiple Polly policies are applied by layering DelegatingHandlers (each PolicyHttpMessageHandler layer would generate a fresh guid). And features (b) and (c) would not be available.
Options for supporting Polly.Context in PolicyHttpMessageHandler
[1] and [2] ensure when there is a chain of delegating handlers, they all use the same context, fixing (a) above. [3] just despatches so that all Polly logging and telemetry has access to the Context.
This enables and fixes both use cases (b) and (c) above.
Stepping back: the issue here is that Polly users normally code the fooPolicy.ExecuteAsync(...) call directly, so can pass in a Context. In the HttpClientFactory integration, that call is (necessarily) within PolicyHttpMessageHandler.cs, so the user cannot directly pass in Context.
HttpClient being (presumably) not for modification, HttpRequestMessage.Properties seems like the intended(?)/available place for attaching execution-scoped data.
The extra line, [5], would not be necessary for ordinary usage. It would be an available option, for those who wanted the richer telemetry or to use CachePolicy.
Thoughts? Should this be part of the Polly-HttpClientFactory story? Are there any good alternatives?
The text was updated successfully, but these errors were encountered:
We might even go further than 4b and just define extension methods that do this in a nicer way.
Perfect! My concern around [5] was that while sthg like this seemed necessary, it wasn't as pretty as it could be, so if you have licence to add extension methods to wrap-and-hide [4b] / [5], even better.
Polly Policy instances can be used across multiple call sites for intended functional outcomes. This is a good fit for named
HttpClient
configurations onHttpClientFactory
with aBaseUri
egapi.contoso.com
indicating all calls will be to endpoints onapi.contoso.com
.To complement re-use, Polly provides an execution-scoped
Context
which travels with every execution. This:(a) provides a correlation id unique to each execution, allowing logging and telemetry to correlate the events particular to a single execution;
(b) distinguishes different call sites at which Policy instances may be being used, allowing logging and telemetry to correlate statistics particular to a single usage site/call path;
api.contoso.com
, but when analysing failures, it can be very useful to extract that call path A tended to be healthy but call path B tended to require retries, break circuits, etc.(c) allows the functioning of
CachePolicy
. WithCachePolicy
, one typically configures a singleCachePolicy
instance, thenContext
supplies the key that the policy should use for caching items on that particular call path.The execution-scoped
Polly.Context
is already made available to policy delegate hooks (egonRetry
,onBreak
etc) and will also be available to forthcoming raw telemetry events.Without HttpClientFactory doing anything around this, correlation ids (a) would be inconsistent in cases where multiple Polly policies are applied by layering DelegatingHandlers (each
PolicyHttpMessageHandler
layer would generate a fresh guid). And features (b) and (c) would not be available.Options for supporting
Polly.Context
inPolicyHttpMessageHandler
Here within
PolicyHttpMessageHandler
we could:where:
[1] and [2] ensure when there is a chain of delegating handlers, they all use the same context, fixing (a) above. [3] just despatches so that all Polly logging and telemetry has access to the Context.
If we changed [4] to:
then users who desired, would have this usage:
This enables and fixes both use cases (b) and (c) above.
Stepping back: the issue here is that Polly users normally code the
fooPolicy.ExecuteAsync(...)
call directly, so can pass in aContext
. In theHttpClientFactory
integration, that call is (necessarily) withinPolicyHttpMessageHandler.cs
, so the user cannot directly pass inContext
.HttpClient
being (presumably) not for modification,HttpRequestMessage.Properties
seems like the intended(?)/available place for attaching execution-scoped data.The extra line, [5], would not be necessary for ordinary usage. It would be an available option, for those who wanted the richer telemetry or to use
CachePolicy
.Thoughts? Should this be part of the Polly-HttpClientFactory story? Are there any good alternatives?
The text was updated successfully, but these errors were encountered: