Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce TelemetryResilienceStrategyOptions.ResultFormatter #1294

Merged
merged 2 commits into from
Jun 14, 2023

Conversation

martintmk
Copy link
Contributor

@martintmk martintmk commented Jun 14, 2023

Details on the issue fix or feature implementation

One very common scenario when using ResilienceStrategy is to handle HttpResponseMessage.

The built-in telemetry now logs the whole result simply by formatting it to string. For HttpResponseMessage this can be noisy, non-performant and could reveal sensitive data as demonstrated bellow:

var response = new HttpResponseMessage(System.Net.HttpStatusCode.OK);
response.Headers.Add("Header1", "value");
response.Headers.Add("Header2", "Sensitive Value");
response.Content = new StringContent("Sensitive Content");
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StringContent, Headers:
{
  Header1: value
  Header2: Sensitive Value
  Content-Type: text/plain; charset=utf-8
}

This PR allows customization of how the results are formatted and also changes the default formatting behavior for HttpResponseMessage.

Confirm the following

  • I started this PR by branching from the head of the default branch
  • I have targeted the PR to merge into the default branch
  • I have included unit tests for the issue/feature
  • I have successfully run a local build

@martintmk martintmk added the v8 Issues related to the new version 8 of the Polly library. label Jun 14, 2023
@martintmk martintmk added this to the v8.0.0 milestone Jun 14, 2023
/// Gets or sets the result formatter.
/// </summary>
/// <remarks>
/// Defaults to a formatter that returns a status code for HTTP based responses and result as-is for all other result types.
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
/// Defaults to a formatter that returns a status code for HTTP based responses and result as-is for all other result types.
/// Defaults to a formatter that returns a status code for HTTP based responses and the result as-is for all other result types.

@martintmk martintmk enabled auto-merge (squash) June 14, 2023 07:32
@codecov
Copy link

codecov bot commented Jun 14, 2023

Codecov Report

Merging #1294 (53a9ad6) into main (cd9c59e) will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1294      +/-   ##
==========================================
+ Coverage   83.26%   83.28%   +0.02%     
==========================================
  Files         263      263              
  Lines        6291     6299       +8     
  Branches      993      994       +1     
==========================================
+ Hits         5238     5246       +8     
  Misses        844      844              
  Partials      209      209              
Flag Coverage Δ
linux 83.28% <100.00%> (+0.02%) ⬆️
macos 83.28% <100.00%> (+0.02%) ⬆️
windows ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...xtensions/Telemetry/TelemetryResilienceStrategy.cs 100.00% <100.00%> (ø)
...ry/TelemetryResilienceStrategyBuilderExtensions.cs 100.00% <100.00%> (ø)
...ns/Telemetry/TelemetryResilienceStrategyOptions.cs 100.00% <100.00%> (ø)

@martintmk martintmk merged commit 155a062 into main Jun 14, 2023
@martintmk martintmk deleted the mtomka/result-formatter branch June 14, 2023 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v8 Issues related to the new version 8 of the Polly library.
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants