Skip to content

Commit 78d8286

Browse files
committed
[SDK] Add credentials option to OTLP gRPC client (#3402)
This allows passing custom `ChannelCredentials` when creating gRPC channels, to support authentication protocols that require short-lived tokens.
1 parent 1e33bb5 commit 78d8286

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client_options.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#pragma once
55

6+
#include <grpcpp/security/credentials.h>
7+
68
#include "opentelemetry/exporters/otlp/otlp_environment.h"
79
#include "opentelemetry/version.h"
810

@@ -43,6 +45,9 @@ struct OtlpGrpcClientOptions
4345
std::string ssl_client_cert_string;
4446
#endif
4547

48+
/** Use custom ChannelCredentials, instead of the SSL options above. */
49+
std::shared_ptr<grpc::ChannelCredentials> credentials;
50+
4651
/** Export timeout. */
4752
std::chrono::system_clock::duration timeout;
4853

exporters/otlp/src/otlp_grpc_client.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,11 @@ std::shared_ptr<grpc::Channel> OtlpGrpcClient::MakeChannel(const OtlpGrpcClientO
392392
}
393393
#endif // ENABLE_OTLP_RETRY_PREVIEW
394394

395-
if (options.use_ssl_credentials)
395+
if (options.credentials)
396+
{
397+
channel = grpc::CreateCustomChannel(grpc_target, options.credentials, grpc_arguments);
398+
}
399+
else if (options.use_ssl_credentials)
396400
{
397401
grpc::SslCredentialsOptions ssl_opts;
398402
ssl_opts.pem_root_certs = GetFileContentsOrInMemoryContents(

0 commit comments

Comments
 (0)