Improve discoverability of DI prerequisites in Http.Diagnostics package
- Dominant language
- C#
- Stars
- 3.2k
- Forks
- 894
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 23
Description
Currently, if I use `Microsoft.Extensions.Http.Diagnostics` package, it's assumed that I've already referenced `Microsoft.Extensions.Compliance.Redaction` package and registered `AddRedaction()` in the `IServiceCollection`.
For LatencyContext feature it's also required to call `AddLatencyContext()`.
If any of these actions weren't done, then a user gets an exception:
```
Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType:
Microsoft.Extensions.Http.Diagnostics.IHttpRouteParser Lifetime: Singleton ImplementationType: Microsoft.Extensions.Http.Diagnostics.HttpRouteParser':
Unable to resolve service for type 'Microsoft.Extensions.Compliance.Redaction.IRedactorProvider' while attempting to activate 'Microsoft.Extensions.Http.Diagnostics.HttpRouteParser'.)
...
```
For LatencyContext it's at the same level of being counter-intuitive on how to resolve the issue:
```
Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType:
Microsoft.Extensions.Http.Logging.HttpClientLogger Lifetime: Singleton ServiceKey: MyNamedClient KeyedImplementationType: Microsoft.Extensions.Http.Logging.HttpClientLogger':
Unable to resolve service for type 'Microsoft.Extensions.Diagnostics.Latency.ILatencyContextTokenIssuer' while attempting to activate 'Microsoft.Extensions.Http.Latency.Internal.HttpClientLatencyLogEnricher'.)
```
We need to throw at least some human-understandable exception that explains what requirements/missing dependencies need to be registered.
This is slightly related to #4560
Contributor guide
Assessment
This issue has not been assessed yet.