@@ -309,6 +309,32 @@ OtlpGrpcClient::~OtlpGrpcClient()
309
309
#endif
310
310
}
311
311
312
+ std::string OtlpGrpcClient::GetGrpcTarget (const std::string &endpoint)
313
+ {
314
+ //
315
+ // Scheme is allowed in OTLP endpoint definition, but is not allowed for creating gRPC
316
+ // channel. Passing URI with scheme to grpc::CreateChannel could resolve the endpoint to some
317
+ // unexpected address.
318
+ //
319
+ ext::http::common::UrlParser url (endpoint);
320
+ if (!url.success_ )
321
+ {
322
+ OTEL_INTERNAL_LOG_ERROR (" [OTLP GRPC Client] invalid endpoint: " << endpoint);
323
+ return " " ;
324
+ }
325
+
326
+ std::string grpc_target;
327
+ if (url.scheme_ == " unix" )
328
+ {
329
+ grpc_target = " unix:" + url.path_ ;
330
+ }
331
+ else
332
+ {
333
+ grpc_target = url.host_ + " :" + std::to_string (static_cast <int >(url.port_ ));
334
+ }
335
+ return grpc_target;
336
+ }
337
+
312
338
std::shared_ptr<grpc::Channel> OtlpGrpcClient::MakeChannel (const OtlpGrpcClientOptions &options)
313
339
{
314
340
@@ -318,22 +344,16 @@ std::shared_ptr<grpc::Channel> OtlpGrpcClient::MakeChannel(const OtlpGrpcClientO
318
344
319
345
return nullptr ;
320
346
}
321
- //
322
- // Scheme is allowed in OTLP endpoint definition, but is not allowed for creating gRPC
323
- // channel. Passing URI with scheme to grpc::CreateChannel could resolve the endpoint to some
324
- // unexpected address.
325
- //
326
347
327
- ext::http::common::UrlParser url (options.endpoint );
328
- if (!url.success_ )
348
+ std::shared_ptr<grpc::Channel> channel;
349
+ std::string grpc_target = GetGrpcTarget (options.endpoint );
350
+
351
+ if (grpc_target.empty ())
329
352
{
330
353
OTEL_INTERNAL_LOG_ERROR (" [OTLP GRPC Client] invalid endpoint: " << options.endpoint );
331
-
332
354
return nullptr ;
333
355
}
334
356
335
- std::shared_ptr<grpc::Channel> channel;
336
- std::string grpc_target = url.host_ + " :" + std::to_string (static_cast <int >(url.port_ ));
337
357
grpc::ChannelArguments grpc_arguments;
338
358
grpc_arguments.SetUserAgentPrefix (options.user_agent );
339
359
0 commit comments