Skip to content

Commit 3b25e47

Browse files
committed
merged from upstream, enabled grpc cred preview
2 parents 7da562c + b1253a7 commit 3b25e47

File tree

9 files changed

+70
-5
lines changed

9 files changed

+70
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ Increment the:
1818
* [TEST] Test examples in CI with CMake Part 1
1919
[#3449](https://github.com/open-telemetry/opentelemetry-cpp/pull/3449)
2020

21+
* [EXPORTER] Add `credentials` option to OTLP Exporter’s gRPC Client
22+
[#3403](https://github.com/open-telemetry/opentelemetry-cpp/pull/3403)
23+
24+
* To enable with CMake: `-DWITH_OTLP_GRPC_CREDENTIAL_PREVIEW=ON`
25+
* To enable with Bazel: `--@io_opentelemetry_cpp//exporters/otlp:with_otlp_grpc_credential_preview=true`
26+
2127
## [1.21 2025-05-28]
2228

2329
* [BUILD] Remove WITH_ABSEIL

CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,10 @@ option(WITH_OTLP_RETRY_PREVIEW
222222
"Whether to enable experimental retry functionality" OFF)
223223

224224
option(WITH_OTLP_GRPC_SSL_MTLS_PREVIEW
225-
"Whether to enable mTLS support fro gRPC" OFF)
225+
"Whether to enable mTLS support for gRPC" OFF)
226+
227+
option(WITH_OTLP_GRPC_CREDENTIAL_PREVIEW
228+
"Whether to enable gRPC credentials option in OTLP gRPC Exporter" OFF)
226229

227230
option(WITH_OTLP_GRPC "Whether to include the OTLP gRPC exporter in the SDK"
228231
OFF)
@@ -793,6 +796,9 @@ message(
793796
message(STATUS "WITH_REMOVE_METER_PREVIEW: ${WITH_REMOVE_METER_PREVIEW}")
794797
message(
795798
STATUS "WITH_OTLP_GRPC_SSL_MTLS_PREVIEW: ${WITH_OTLP_GRPC_SSL_MTLS_PREVIEW}")
799+
message(
800+
STATUS
801+
"WITH_OTLP_GRPC_CREDENTIAL_PREVIEW: ${WITH_OTLP_GRPC_CREDENTIAL_PREVIEW}")
796802
message(STATUS "WITH_OTLP_RETRY_PREVIEW: ${WITH_OTLP_RETRY_PREVIEW}")
797803
message(STATUS "---------------------------------------------")
798804
message(STATUS "third-party options")

api/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ if(WITH_OTLP_GRPC_SSL_MTLS_PREVIEW)
116116
INTERFACE ENABLE_OTLP_GRPC_SSL_MTLS_PREVIEW)
117117
endif()
118118

119+
if(WITH_OTLP_GRPC_CREDENTIAL_PREVIEW)
120+
target_compile_definitions(opentelemetry_api
121+
INTERFACE ENABLE_OTLP_GRPC_CREDENTIAL_PREVIEW)
122+
endif()
123+
119124
if(WITH_METRICS_EXEMPLAR_PREVIEW)
120125
target_compile_definitions(opentelemetry_api
121126
INTERFACE ENABLE_METRICS_EXEMPLAR_PREVIEW)

api/include/opentelemetry/common/macros.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ point.
564564
#define ENABLE_OTLP_RETRY_PREVIEW 1
565565
#define ENABLE_THREAD_INSTRUMENTATION_PREVIEW 1
566566
#define ENABLE_CURL_LOGGING 1
567+
#define ENABLE_OTLP_GRPC_CREDENTIAL_PREVIEW 1
567568

568569
// What follows is specific to the https://github.com/malkia/opentelemetry-cpp windows-dll branch.
569570
// Users should not predefine OPENTELEMETRY_DLL, and it would get set to 1 ("dllimport").
@@ -639,7 +640,8 @@ point.
639640
"+otlp_compr:" OPENTELEMETRY_STR(ENABLE_OTLP_COMPRESSION_PREVIEW) \
640641
"+otlp_retry:" OPENTELEMETRY_STR(ENABLE_OTLP_RETRY_PREVIEW) \
641642
"+thrd_instr:" OPENTELEMETRY_STR(ENABLE_THREAD_INSTRUMENTATION_PREVIEW) \
642-
"+curl_log:" OPENTELEMETRY_STR(ENABLE_CURL_LOGGING) \
643+
"+curl_log:" OPENTELEMETRY_STR(ENABLE_CURL_LOGGING) \
644+
"+grpc_cred:" OPENTELEMETRY_STR(ENABLE_OTLP_GRPC_CREDENTIAL_PREVIEW) \
643645
)
644646

645647
// "+have_excpts:" OPENTELEMETRY_STR(OPENTELEMETRY_HAVE_EXCEPTIONS)

ci/do_ci.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ switch ($action) {
348348
-DWITH_METRICS_EXEMPLAR_PREVIEW=ON `
349349
-DWITH_ASYNC_EXPORT_PREVIEW=ON `
350350
-DWITH_OTLP_GRPC_SSL_MTLS_PREVIEW=ON `
351+
-DWITH_OTLP_GRPC_CREDENTIAL_PREVIEW=ON `
351352
-DWITH_OTLP_RETRY_PREVIEW=ON `
352353
-DWITH_OTLP_GRPC=ON `
353354
-DWITH_OTLP_HTTP=ON `
@@ -453,6 +454,7 @@ switch ($action) {
453454
-DWITH_ETW=ON `
454455
-DOPENTELEMETRY_INSTALL=ON `
455456
-DWITH_OTLP_GRPC_SSL_MTLS_PREVIEW=OFF `
457+
-DWITH_OTLP_GRPC_CREDENTIAL_PREVIEW=OFF `
456458
-DWITH_OTLP_RETRY_PREVIEW=OFF `
457459
-DWITH_OTLP_GRPC=OFF `
458460
-DWITH_OTLP_HTTP=OFF `

ci/do_ci.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ MAKE_COMMAND="make -k -j \$(nproc)"
6969

7070
echo "make command: ${MAKE_COMMAND}"
7171

72-
BAZEL_OPTIONS_DEFAULT="--copt=-DENABLE_METRICS_EXEMPLAR_PREVIEW"
72+
BAZEL_OPTIONS_DEFAULT="--copt=-DENABLE_METRICS_EXEMPLAR_PREVIEW --//exporters/otlp:with_otlp_grpc_credential_preview=true"
7373
BAZEL_OPTIONS="$BAZEL_OPTIONS_DEFAULT"
7474

7575
BAZEL_TEST_OPTIONS="$BAZEL_OPTIONS --test_output=errors"
@@ -381,6 +381,7 @@ elif [[ "$1" == "cmake.exporter.otprotocol.test" ]]; then
381381
-DWITH_OTLP_HTTP=ON \
382382
-DWITH_OTLP_FILE=ON \
383383
-DWITH_OTLP_GRPC_SSL_MTLS_PREVIEW=ON \
384+
-DWITH_OTLP_GRPC_CREDENTIAL_PREVIEW=ON \
384385
-DWITH_OTLP_RETRY_PREVIEW=ON \
385386
"${SRC_DIR}"
386387
grpc_cpp_plugin=`which grpc_cpp_plugin`
@@ -467,6 +468,7 @@ elif [[ "$1" == "cmake.install.test" ]]; then
467468
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
468469
-DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON \
469470
-DWITH_OTLP_GRPC_SSL_MTLS_PREVIEW=ON \
471+
-DWITH_OTLP_GRPC_CREDENTIAL_PREVIEW=ON \
470472
-DWITH_OTLP_RETRY_PREVIEW=ON \
471473
-DWITH_OTLP_GRPC=ON \
472474
-DWITH_OTLP_HTTP=ON \
@@ -534,6 +536,7 @@ elif [[ "$1" == "cmake.fetch_content.test" ]]; then
534536
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
535537
-DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON \
536538
-DWITH_OTLP_GRPC_SSL_MTLS_PREVIEW=ON \
539+
-DWITH_OTLP_GRPC_CREDENTIAL_PREVIEW=ON \
537540
-DWITH_OTLP_RETRY_PREVIEW=ON \
538541
-DWITH_OTLP_GRPC=ON \
539542
-DWITH_OTLP_HTTP=ON \
@@ -592,8 +595,8 @@ elif [[ "$1" == "bazel.no_bzlmod.test" ]]; then
592595
bazel $BAZEL_STARTUP_OPTIONS test --enable_bzlmod=false $BAZEL_TEST_OPTIONS //...
593596
exit 0
594597
elif [[ "$1" == "bazel.test" ]]; then
595-
bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_OPTIONS //...
596-
bazel $BAZEL_STARTUP_OPTIONS test $BAZEL_TEST_OPTIONS //...
598+
bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_OPTIONS $BAZEL_WITH_PREVIEW //...
599+
bazel $BAZEL_STARTUP_OPTIONS test $BAZEL_TEST_OPTIONS $BAZEL_WITH_PREVIEW //...
597600
exit 0
598601
elif [[ "$1" == "bazel.with_async_export.test" ]]; then
599602
bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_OPTIONS_ASYNC //...

exporters/otlp/BUILD

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright The OpenTelemetry Authors
22
# SPDX-License-Identifier: Apache-2.0
33

4+
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
45
load("//bazel:otel_cc_benchmark.bzl", "otel_cc_benchmark")
56
load("//:dll_deps.bzl", "dll_deps")
67
load("//bazel:otel_cc.bzl", "otel_cc_binary", "otel_cc_library", "otel_cc_test")
@@ -84,6 +85,10 @@ otel_cc_library(
8485
"include/opentelemetry/exporters/otlp/protobuf_include_prefix.h",
8586
"include/opentelemetry/exporters/otlp/protobuf_include_suffix.h",
8687
],
88+
# defines = select({
89+
# ":enable_otlp_grpc_credential_preview": ["ENABLE_OTLP_GRPC_CREDENTIAL_PREVIEW"],
90+
# "//conditions:default": [],
91+
# }),
8792
strip_include_prefix = "include",
8893
tags = [
8994
"otlp",
@@ -100,6 +105,18 @@ otel_cc_library(
100105
],
101106
)
102107

108+
# config_setting(
109+
# name = "enable_otlp_grpc_credential_preview",
110+
# flag_values = {
111+
# ":with_otlp_grpc_credential_preview": "true",
112+
# },
113+
# )
114+
115+
# bool_flag(
116+
# name = "with_otlp_grpc_credential_preview",
117+
# build_setting_default = False,
118+
# )
119+
103120
otel_cc_library(
104121
name = "otlp_grpc_exporter",
105122
srcs = [

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@
77
#include "opentelemetry/exporters/otlp/otlp_environment.h"
88

99
#include <chrono>
10+
#include <memory>
1011
#include <string>
1112

13+
namespace grpc
14+
{
15+
class ChannelCredentials;
16+
}
17+
1218
OPENTELEMETRY_BEGIN_NAMESPACE
1319
namespace exporter
1420
{
@@ -43,6 +49,11 @@ struct OtlpGrpcClientOptions
4349
std::string ssl_client_cert_string;
4450
#endif
4551

52+
#ifdef ENABLE_OTLP_GRPC_CREDENTIAL_PREVIEW
53+
/** Use custom ChannelCredentials, instead of the SSL options above. */
54+
std::shared_ptr<grpc::ChannelCredentials> credentials;
55+
#endif
56+
4657
/** Export timeout. */
4758
std::chrono::system_clock::duration timeout;
4859

exporters/otlp/src/otlp_grpc_client.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,19 @@ std::shared_ptr<grpc::Channel> OtlpGrpcClient::MakeChannel(const OtlpGrpcClientO
433433
grpc::CreateCustomChannel(grpc_target, grpc::InsecureChannelCredentials(), grpc_arguments);
434434
}
435435

436+
#ifdef ENABLE_OTLP_GRPC_CREDENTIAL_PREVIEW
437+
if (options.credentials)
438+
{
439+
if (options.use_ssl_credentials)
440+
{
441+
OTEL_INTERNAL_LOG_WARN(
442+
"[OTLP GRPC Client] Both 'credentials' and 'use_ssl_credentials' options are set. "
443+
"The former takes priority.");
444+
}
445+
channel = grpc::CreateCustomChannel(grpc_target, options.credentials, grpc_arguments);
446+
}
447+
#endif // ENABLE_OTLP_GRPC_CREDENTIAL_PREVIEW
448+
436449
return channel;
437450
}
438451

0 commit comments

Comments
 (0)