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

Provide an option to customize GrpcChannelOptions

Open En3Tho opened this issue 1 year ago • 2 comments

Feature Request

Is your feature request related to a problem?

Unable to use grpc exporter in BlazorWasm with current OpenTelemetry grpc exporter code. Currently GrpcChannel is created with default GrpcChannelOptions which default ot using SocketsHttpHandler and invoke load balancing code which ends up crashing.

Unhandled exception: System.NullReferenceException: Object reference not set to an instance of an object.
         at Grpc.Net.Client.Balancer.Internal.BalancerHttpHandler.IsSocketsHttpHandlerSetup(SocketsHttpHandler socketsHttpHandler)
         at Grpc.Net.Client.Balancer.Internal.BalancerHttpHandler.ConfigureSocketsHttpHandlerSetup(SocketsHttpHandler socketsHttpHandler, Func`3 connectCallback)
         at Grpc.Net.Client.GrpcChannel.CreateInternalHttpInvoker(HttpMessageHandler handler)
         at Grpc.Net.Client.GrpcChannel..ctor(Uri address, GrpcChannelOptions channelOptions)
         at Grpc.Net.Client.GrpcChannel.ForAddress(Uri address, GrpcChannelOptions channelOptions)
         at Grpc.Net.Client.GrpcChannel.ForAddress(Uri address)

Describe the solution you'd like:

I want to introduce a class

public class OpenTelemetryGrpcChannelOptions
{
    public GrpcChannelOptions { get; set; } = new()
}

And augment OtlpGrpcTraceExportClient to somehow consume these options which then will be passed to OtlpExporterOptionsExtensions.CreateChannel

What do you want to happen instead? What is the expected behavior?

I want to provide a custom HttpClient/HttpClientHandler so grpc exporter in wasm won't crash

Which alternative solutions or features have you considered?

Alternative solution would be using HttpProtobuf but it requires keeping track of special endpoint for wasm and it is less effective than grpc

Additional Context

Add any other context about the feature request here.

En3Tho avatar Nov 26 '23 08:11 En3Tho

Related: https://github.com/open-telemetry/opentelemetry-dotnet/issues/5028 but with a different approach

En3Tho avatar Nov 26 '23 08:11 En3Tho

We face a similar issue. Behind our corporate proxy load-balancing does not work:

2024-04-04T06:42:16.9695242Z:Exporter failed send data to collector to {0} endpoint. Data will not be sent. Exception: {1}{https://xxx.apm.westeurope.azure.elastic-cloud.com/}{Grpc.Core.RpcException: Status(StatusCode="Internal", Detail="Error starting gRPC call. HttpRequestException: Unable to get subchannel from HttpRequestMessage. (127.0.0.1:9000) InvalidOperationException: Unable to get subchannel from HttpRequestMessage.", DebugException="System.Net.Http.HttpRequestException: Unable to get subchannel from HttpRequestMessage. (127.0.0.1:9000)")
 ---> System.Net.Http.HttpRequestException: Unable to get subchannel from HttpRequestMessage. (127.0.0.1:9000)
 ---> System.InvalidOperationException: Unable to get subchannel from HttpRequestMessage.
   at Grpc.Net.Client.Balancer.Internal.BalancerHttpHandler.OnConnect(SocketsHttpConnectionContext context, CancellationToken cancellationToken) in /_/src/Grpc.Net.Client/Balancer/Internal/BalancerHttpHandler.cs:line 89
   at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---

In other gRPC scenarios the following suggestion solved this issue: https://github.com/grpc/grpc-dotnet/issues/2116#issuecomment-1535971414

It requires to set the HttpHandler property of GrpcChannelOptions. Without this possibility we have to stick with version 1.5 of the OpenTelemetry.Exporter.OpenTelemetryProtocol package. An upgrade to version 1.6 results in the problem described above.

pihai avatar Apr 04 '24 11:04 pihai