@@ -356,6 +356,52 @@ std::shared_ptr<grpc::Channel> OtlpGrpcClient::MakeChannel(const OtlpGrpcClientO
356356 }
357357
358358 grpc::ChannelArguments grpc_arguments;
359+ PopulateChannelArguments (options, grpc_arguments);
360+
361+ if (options.use_ssl_credentials )
362+ {
363+ grpc::SslCredentialsOptions ssl_opts;
364+ ssl_opts.pem_root_certs = GetFileContentsOrInMemoryContents (
365+ options.ssl_credentials_cacert_path , options.ssl_credentials_cacert_as_string );
366+ #ifdef ENABLE_OTLP_GRPC_SSL_MTLS_PREVIEW
367+ ssl_opts.pem_private_key = GetFileContentsOrInMemoryContents (options.ssl_client_key_path ,
368+ options.ssl_client_key_string );
369+ ssl_opts.pem_cert_chain = GetFileContentsOrInMemoryContents (options.ssl_client_cert_path ,
370+ options.ssl_client_cert_string );
371+
372+ #endif
373+ channel =
374+ grpc::CreateCustomChannel (grpc_target, grpc::SslCredentials (ssl_opts), grpc_arguments);
375+ }
376+ else
377+ {
378+ channel =
379+ grpc::CreateCustomChannel (grpc_target, grpc::InsecureChannelCredentials (), grpc_arguments);
380+ }
381+
382+ #ifdef ENABLE_OTLP_GRPC_CREDENTIAL_PREVIEW
383+ if (options.credentials )
384+ {
385+ if (options.use_ssl_credentials )
386+ {
387+ OTEL_INTERNAL_LOG_WARN (
388+ " [OTLP GRPC Client] Both 'credentials' and 'use_ssl_credentials' options are set. "
389+ " The former takes priority." );
390+ }
391+ channel = grpc::CreateCustomChannel (grpc_target, options.credentials , grpc_arguments);
392+ }
393+ #endif // ENABLE_OTLP_GRPC_CREDENTIAL_PREVIEW
394+
395+ return channel;
396+ }
397+
398+ void OtlpGrpcClient::PopulateChannelArguments (const OtlpGrpcClientOptions &options,
399+ grpc::ChannelArguments &grpc_arguments)
400+ {
401+ if (options.channel_arguments != nullptr )
402+ {
403+ grpc_arguments = *options.channel_arguments ;
404+ }
359405 grpc_arguments.SetUserAgentPrefix (options.user_agent );
360406
361407 if (options.max_threads > 0 )
@@ -399,9 +445,7 @@ std::shared_ptr<grpc::Channel> OtlpGrpcClient::MakeChannel(const OtlpGrpcClientO
399445 ]
400446 })" };
401447
402- // Allocate string with buffer large enough to hold the formatted json config
403448 auto service_config = std::string (kServiceConfigJson .size (), ' \0 ' );
404- // Prior to C++17, need to explicitly cast away constness from `data()` buffer
405449 std::snprintf (
406450 const_cast <decltype (service_config)::value_type *>(service_config.data ()),
407451 service_config.size (), kServiceConfigJson .data (), options.retry_policy_max_attempts ,
@@ -412,42 +456,6 @@ std::shared_ptr<grpc::Channel> OtlpGrpcClient::MakeChannel(const OtlpGrpcClientO
412456 grpc_arguments.SetServiceConfigJSON (service_config);
413457 }
414458#endif // ENABLE_OTLP_RETRY_PREVIEW
415-
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;
451459}
452460
453461std::unique_ptr<grpc::ClientContext> OtlpGrpcClient::MakeClientContext (
0 commit comments