opentelemetry-dotnet icon indicating copy to clipboard operation
opentelemetry-dotnet copied to clipboard

[feature request] Allow sending telemetry in HTTP2

Open NatMarchand opened this issue 4 months ago • 4 comments

Package

OpenTelemetry.Exporter.OpenTelemetryProtocol

Is your feature request related to a problem?

It is currently impossible to force OtlpExporter to use HTTP2 Using OpenTelemetry 1.12 with OtlpExporter, we are using a delegating handler in the HttpClientFactory to enforce the version of the HttpRequestMessage to HTTP2:

POST http://opentelemetry-collector-sts-collector.monitoring.svc.cluster.local/v1/metrics
      System.NotSupportedException: The synchronous method is not supported by 'System.Net.Http.SocketsHttpHandler' for HTTP/2 or higher. Either use an asynchronous method or downgrade the request version to HTTP/1.1 or lower.
         at System.Net.Http.SocketsHttpHandler.Send(HttpRequestMessage request, CancellationToken cancellationToken)

What is the expected behavior?

We are expecting to be able to enable HTTP2 on all the requests (and thus use the Async counterpart of Send)

Which alternative solutions or features have you considered?

We are currently removing the DelegatingHandler for this HttpClient

Additional context

No response

NatMarchand avatar Aug 26 '25 10:08 NatMarchand

Looking at the code, SendAsync() is used when RequireHttp2 is set to true:

https://github.com/open-telemetry/opentelemetry-dotnet/blob/8321588b2808bede8f2b018f286eb78b2f3dfd14/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpExportClient.cs#L94-L105

This is only set to true when using OtlpGrpcExportClient:

https://github.com/open-telemetry/opentelemetry-dotnet/blob/8321588b2808bede8f2b018f286eb78b2f3dfd14/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpGrpcExportClient.cs#L34

Supporting this would need some sort of new opt-in setting to allow OtlpHttpExportClient (or other) implementations to request use of HTTP/2.

martincostello avatar Aug 26 '25 10:08 martincostello

Would it be problematic to always use SendAsync ? Or is there any perf penalty ?

NatMarchand avatar Aug 26 '25 10:08 NatMarchand

I don't know the background on why Send() is being used where available. I assume it's a performance optimization to avoid the background thread sending the metrics needing to allocate the async state machinery.

martincostello avatar Aug 26 '25 10:08 martincostello

After digging a moment, I've found : https://github.com/open-telemetry/opentelemetry-dotnet/pull/2316

It seems that as the BaseExporter signatures are synchronous, it was chosen to pick the Send method (or use the SendAsync with sync over async in the net5 case)

NatMarchand avatar Aug 26 '25 11:08 NatMarchand