-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Customized SocketsHttpHandler does not support diagnostics tracking #31261
Comments
cc: @lmolkova |
Can you give more detail on how explicitly using a Max connections per server can be customized via the using var handler = new HttpClientHandler { MaxConnectionsPerServer = 10 };
using var client = new HttpClient(handler); |
@scalablecory, DiagnosticHandler is created and wrapped around SocketsHttpHandler in HttpClientHandler, e.g. |
@stephentoub yes, that is clear. |
@scalablecory Thanks for the info, I didn't see that HttpClientHandler is customizable this way. However I would also like to adjust I think that my dependency tracking is broken because DiagnosticsHandler is missing around my SocketsHttpHandler. I'm using application insights' automatic dependency tracking that seems to integrate with the diagnostics propagated by DiagnosticsHandler. In general I would like the freedom to adjust the settings of the SocketsHttpHandler contained in my HttpClient without losing the diagnostics. The issue I'm having is that I can't access the SocketsHttpHandler that's automatically created by HttpClientHandler and as explained I can't just create a SocketsHttpHandler myself without losing diagnostic information. I just posted this as an issue because I expected to be able to adjust the full set of HttpConnectionSettings without trade-offs like losing dependency tracking |
The dotnet ApplicationInsights SDK also builds on this. If we create a custom |
Triage: We should do something -- there is multiple options - expose it as type (not a very interesting one), static factory, or We should make it happen in 5.0 as AppInsights is important scenario for custom handler -- Xamarin and SocketsHttpHandler. |
Workaround: you can probably copy DiagnosticsHandler into your project. Has anyone tried that? |
What about making gRPC client will be customizing the |
@JamesNK it is one of the options listed above - #31261 (comment) ... we just didn't get to making a decision here :(. |
I was OOF for quite a while, sorry for not commenting earlier. I agree that exposing @karelz assuming we make decision to expose it , did we miss .NET 5 train or there is still a chance ? |
Please consider making backports to 2.1 and 3.1 as well to benefit more customers. :) Many of the affected customers are not going to be in 5.0 anytime soon :( |
The chance to get it into 5.0 is very low at this point. The team is busy, time is short, this is not the highest priority issue for 5.0 and the design is unclear and will require iterations - #31261 (comment) @cijothomas .NET Core does not add new APIs in servicing -- I think it is because we don't ship new ref assemblies to use the new APIs. If targeting older versions is top need, then we should think about temporary alternarives like standalone package outside of .NET Core. |
I have tried this and this causes other issues. Using reflection does work: private static Func<SocketsHttpHandler, DelegatingHandler> CreateDiagnosticsHandlerFactory()
{
var diagnosticsHandler = typeof(SocketsHttpHandler).Assembly.GetType("System.Net.Http.DiagnosticsHandler");
var ctor = diagnosticsHandler!.GetConstructors().First();
var param = Expression.Parameter(typeof(HttpMessageHandler), "innerHandler");
var newExp = Expression.New(ctor, param);
var lambda = Expression.Lambda<Func<SocketsHttpHandler, DelegatingHandler>>(newExp, param);
return lambda.Compile();
} var createDiagnosticsHandler= CreateDiagnosticsHandlerFactory();
var diagnosticsHandler = createDiagnosticsHandler(socketsHttpHandler); |
Problem again: grpc/grpc-dotnet#1210 I have fixed it in grpc-dotnet by basically duplicating all of DiagnosticsSource: grpc/grpc-dotnet#1211 |
@karelz @JamesNK is there a plan of record for this in .NET 6.0? With a preview already out and 6.0 being the LTS version, it seems like we should make a fix or at least some forward progress on some scenarios. Perhaps getting a |
@jeffreyrivor yes, it is on our 6.0 list to solve. Technical details how it will be solved are still TBD. |
FYI, AppInsights doesn't like events it listens to being raised by multiple libraries: microsoft/ApplicationInsights-dotnet#2194 I submitted a PR to them. |
Regardless of Application Insights (or OpenTelemetry, for that matter) a tracing handler should exist to be injected via |
#55392 changed the behavior of On top of the global default, the behavior can also be customized on a per-handler basis (#55556): using var handler = new SocketsHttpHandler
{
ActivityHeadersPropagator = DistributedContextPropagator.CreatePassThroughPropagator()
}; |
I want to use custom
HttpConnectionSettings
for my requests since I need to decreaseDefaultMaxConnectionsPerServer
. As far as I knowHttpConnectionSettings
are only exposed when creating a newSocketsHttpHandler
. However if I create a new handler with custom settings and use the handler as message handler for myHttpClient
I lose my dependency tracking.Upon debugging I noticed that the default message handler is
HttpClientHandler
which includes aDiagnosticsHandler
that is not publicly exposed.How can I customize
HttpConnectionSettings
while still seeing request diagnostics?I don't necessarily want to copy DiagnosticsHandler into my code to accomplish this.
On first glance I could see two possible solutions:
DiagnosticsHandler
publicly, so consumers can wrap their custom HttpHandlers with it.HttpConnectionSettings
without creating a new message handler, so consumers can use theHttpClientHandler
while still being able to configure connection behavior.The text was updated successfully, but these errors were encountered: