使用OpenTelemetry时报grpc调用错误的处理方式

报错信息

InvalidOperationException: Calling insecure gRPC services on .NET Core 3.x requires enabling the'System.Net.Http.socketsHittpHandler.Http2Unencryptedsupport switch. See: https://learn.microsoft.com/zh-cn/aspnet/core/grpc/troubleshoot?view=aspnetcore-8.0#call-insecure-grpc-services-with-net-core-client

在程序启动入口加入如下配置

// This switch must be set before creating the GrpcChannel/HttpClient.
AppContext.SetSwitch(
    "System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);

参考官方文档

https://learn.microsoft.com/zh-cn/aspnet/core/grpc/troubleshoot?view=aspnetcore-8.0#call-insecure-grpc-services-with-net-core-client

posted @ 2024-05-21 16:35  七星飘虫  阅读(62)  评论(0)    收藏  举报