@@ -355,7 +355,52 @@ std::shared_ptr<grpc::Channel> OtlpGrpcClient::MakeChannel(const OtlpGrpcClientO
355355 return nullptr ;
356356 }
357357
358+ grpc::ChannelArguments grpc_arguments = BuildChannelArguments (options);
359+
360+ if (options.use_ssl_credentials )
361+ {
362+ grpc::SslCredentialsOptions ssl_opts;
363+ ssl_opts.pem_root_certs = GetFileContentsOrInMemoryContents (
364+ options.ssl_credentials_cacert_path , options.ssl_credentials_cacert_as_string );
365+ #ifdef ENABLE_OTLP_GRPC_SSL_MTLS_PREVIEW
366+ ssl_opts.pem_private_key = GetFileContentsOrInMemoryContents (options.ssl_client_key_path ,
367+ options.ssl_client_key_string );
368+ ssl_opts.pem_cert_chain = GetFileContentsOrInMemoryContents (options.ssl_client_cert_path ,
369+ options.ssl_client_cert_string );
370+
371+ #endif
372+ channel =
373+ grpc::CreateCustomChannel (grpc_target, grpc::SslCredentials (ssl_opts), grpc_arguments);
374+ }
375+ else
376+ {
377+ channel =
378+ grpc::CreateCustomChannel (grpc_target, grpc::InsecureChannelCredentials (), grpc_arguments);
379+ }
380+
381+ #ifdef ENABLE_OTLP_GRPC_CREDENTIAL_PREVIEW
382+ if (options.credentials )
383+ {
384+ if (options.use_ssl_credentials )
385+ {
386+ OTEL_INTERNAL_LOG_WARN (
387+ " [OTLP GRPC Client] Both 'credentials' and 'use_ssl_credentials' options are set. "
388+ " The former takes priority." );
389+ }
390+ channel = grpc::CreateCustomChannel (grpc_target, options.credentials , grpc_arguments);
391+ }
392+ #endif // ENABLE_OTLP_GRPC_CREDENTIAL_PREVIEW
393+
394+ return channel;
395+ }
396+
397+ grpc::ChannelArguments OtlpGrpcClient::BuildChannelArguments (const OtlpGrpcClientOptions &options)
398+ {
358399 grpc::ChannelArguments grpc_arguments;
400+ if (options.channel_arguments != nullptr )
401+ {
402+ grpc_arguments = *options.channel_arguments ;
403+ }
359404 grpc_arguments.SetUserAgentPrefix (options.user_agent );
360405
361406 if (options.max_threads > 0 )
@@ -399,9 +444,7 @@ std::shared_ptr<grpc::Channel> OtlpGrpcClient::MakeChannel(const OtlpGrpcClientO
399444 ]
400445 })" };
401446
402- // Allocate string with buffer large enough to hold the formatted json config
403447 auto service_config = std::string (kServiceConfigJson .size (), ' \0 ' );
404- // Prior to C++17, need to explicitly cast away constness from `data()` buffer
405448 std::snprintf (
406449 const_cast <decltype (service_config)::value_type *>(service_config.data ()),
407450 service_config.size (), kServiceConfigJson .data (), options.retry_policy_max_attempts ,
@@ -413,41 +456,7 @@ std::shared_ptr<grpc::Channel> OtlpGrpcClient::MakeChannel(const OtlpGrpcClientO
413456 }
414457#endif // ENABLE_OTLP_RETRY_PREVIEW
415458
416- if (options.use_ssl_credentials )
417- {
418- grpc::SslCredentialsOptions ssl_opts;
419- ssl_opts.pem_root_certs = GetFileContentsOrInMemoryContents (
420- options.ssl_credentials_cacert_path , options.ssl_credentials_cacert_as_string );
421- #ifdef ENABLE_OTLP_GRPC_SSL_MTLS_PREVIEW
422- ssl_opts.pem_private_key = GetFileContentsOrInMemoryContents (options.ssl_client_key_path ,
423- options.ssl_client_key_string );
424- ssl_opts.pem_cert_chain = GetFileContentsOrInMemoryContents (options.ssl_client_cert_path ,
425- options.ssl_client_cert_string );
426-
427- #endif
428- channel =
429- grpc::CreateCustomChannel (grpc_target, grpc::SslCredentials (ssl_opts), grpc_arguments);
430- }
431- else
432- {
433- channel =
434- grpc::CreateCustomChannel (grpc_target, grpc::InsecureChannelCredentials (), grpc_arguments);
435- }
436-
437- #ifdef ENABLE_OTLP_GRPC_CREDENTIAL_PREVIEW
438- if (options.credentials )
439- {
440- if (options.use_ssl_credentials )
441- {
442- OTEL_INTERNAL_LOG_WARN (
443- " [OTLP GRPC Client] Both 'credentials' and 'use_ssl_credentials' options are set. "
444- " The former takes priority." );
445- }
446- channel = grpc::CreateCustomChannel (grpc_target, options.credentials , grpc_arguments);
447- }
448- #endif // ENABLE_OTLP_GRPC_CREDENTIAL_PREVIEW
449-
450- return channel;
459+ return grpc_arguments;
451460}
452461
453462std::unique_ptr<grpc::ClientContext> OtlpGrpcClient::MakeClientContext (
0 commit comments