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

Add more information and sample to Http.Diagnostics Readme #4808

Merged
merged 3 commits into from
Dec 12, 2023

Conversation

joperezr
Copy link
Member

@joperezr joperezr commented Dec 12, 2023

Adding more documentation to the Microsoft.Extensions.Http.Diagnostics package. We got a few reports stating that there is some confusion on how this package is intended to work, so hopefully this extra docs and samples will make it clearer and will help folks hitting issues with this.

cc: @CarnaViire @stephentoub @geeknoid @xakep139

Microsoft Reviewers: Open in CodeFlow

@ghost ghost assigned joperezr Dec 12, 2023
@joperezr joperezr merged commit cf2ea6b into dotnet:main Dec 12, 2023
6 checks passed
@ghost ghost added this to the 8.1 milestone Dec 12, 2023
@xakep139
Copy link
Contributor

Thanks @joperezr for improving the docs!

@@ -55,6 +55,47 @@ builder.Services.AddHttpClientLogEnricher<MyHttpClientLogEnricher>();
var host = builder.Build();
```

It is important to note that the `AddExtendedHttpClientLogging` method will add information to the logs using *enrichment*. This means that the information will be added as tags to the structured logs, but will not be visible in the log message that is printed by default in the console. To view the information, you will need to use a logging provider that supports structured logs. One quick and built-in way to do this, is to call `AddJsonConsole()` to your logging builder, which will print out the full structured logs to the console. Here is a quick sample that uses the `ExtendedHttpClientLogging()` method to automatically log all `HttpClient` request and response bodies, and then prints the full structured logs to the console:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit: the example below would only print the response body, because only ResponseBodyContentTypes is set up, right? And the description says "request and response bodies"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I'll fix that in a follow-up PR.

sebastienros added a commit that referenced this pull request Dec 18, 2023
* Address issue with legacy logger's calling ToString on the TState arguments. (#4798)

* Fix #4795

And while I was in the neighborhood, also addresses #4637

---------

Co-authored-by: Martin Taillefer <mataille@microsoft.com>
Co-authored-by: Igor Velikorossov <RussKie@users.noreply.github.com>

* Add missing [GeneratedCode] attribute (#4802)

The logging code generator emits a static lambda. The lambda's containing
function is annotated with the [GeneratedCode] attribute, but the lambda
itself is not. The result is that code generators can get confused,
considering the lambda as being user code.

This PR adds the [GeneratedCode] attribute to the lambda.

Co-authored-by: Martin Taillefer <mataille@microsoft.com>

* Add more information and sample to Http.Diagnostics Readme (#4808)

* Add more information and sample to Http.Diagnostics Readme

* Simplify first statement and adding using statements.

* Also add extra docs to xml docs

* Improve code coverage for M.E.Diagnostics.Testing (#4820)

---------

Co-authored-by: Martin Taillefer <geeknoid@users.noreply.github.com>
Co-authored-by: Martin Taillefer <mataille@microsoft.com>
Co-authored-by: Igor Velikorossov <RussKie@users.noreply.github.com>
Co-authored-by: Jose Perez Rodriguez <joperezr@microsoft.com>
Co-authored-by: Sébastien Ros <sebastienros@gmail.com>
@github-actions github-actions bot locked and limited conversation to collaborators Jan 13, 2024
@joperezr joperezr deleted the DiagnosticsReadme branch May 16, 2024 21:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants