Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ Increment the:

## [Unreleased]

* [EXPORTER] Populate `OtlpGrpcClientOptions` with spec-compliant environment
variable defaults, and add constructors to `OtlpGrpcExporterOptions` /
`OtlpGrpcMetricExporterOptions` / `OtlpGrpcLogRecordExporterOptions` that
build from a shared `OtlpGrpcClientOptions`, to support sharing one gRPC
client across the trace, metric, and log exporters.
[#4239](https://github.com/open-telemetry/opentelemetry-cpp/issues/4239)

* [SDK] Apply metric cardinality limits to non-overflow attribute sets and
reserve the overflow point separately.
[#4236](https://github.com/open-telemetry/opentelemetry-cpp/pull/4236)
Expand Down
19 changes: 19 additions & 0 deletions exporters/otlp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ cc_library(
srcs = [
"src/otlp_grpc_client.cc",
"src/otlp_grpc_client_factory.cc",
"src/otlp_grpc_client_options.cc",
"src/otlp_grpc_utils.cc",
],
hdrs = [
Expand All @@ -99,6 +100,7 @@ cc_library(
],
deps = [
"//ext:headers",
"//sdk/src/common:env_variables",
"//sdk/src/common:global_log_handler",
"@com_github_grpc_grpc//:grpc++",
"@com_github_opentelemetry_proto//:common_proto_cc",
Expand Down Expand Up @@ -733,6 +735,23 @@ cc_test(
],
)

cc_test(
name = "otlp_grpc_client_options_test",
srcs = ["test/otlp_grpc_client_options_test.cc"],
tags = [
"otlp",
"otlp_grpc",
"test",
],
deps = [
":otlp_grpc_client",
":otlp_grpc_exporter",
":otlp_grpc_metric_exporter",
":otlp_grpc_log_record_exporter",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "otlp_grpc_exporter_factory_test",
srcs = ["test/otlp_grpc_exporter_factory_test.cc"],
Expand Down
15 changes: 14 additions & 1 deletion exporters/otlp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ if(WITH_OTLP_GRPC)
add_library(
opentelemetry_exporter_otlp_grpc_client
${OPENTELEMETRY_OTLP_GRPC_CLIENT_LIB_TYPE} src/otlp_grpc_client.cc
src/otlp_grpc_client_factory.cc src/otlp_grpc_utils.cc)
src/otlp_grpc_client_factory.cc src/otlp_grpc_client_options.cc
src/otlp_grpc_utils.cc)
set_target_properties(opentelemetry_exporter_otlp_grpc_client
PROPERTIES EXPORT_NAME otlp_grpc_client)
set_target_version(opentelemetry_exporter_otlp_grpc_client)
Expand Down Expand Up @@ -932,6 +933,18 @@ if(BUILD_TESTING)
TEST_PREFIX exporter.otlp.
TEST_LIST otlp_grpc_target_test)

add_executable(otlp_grpc_client_options_test
test/otlp_grpc_client_options_test.cc)
target_link_libraries(
otlp_grpc_client_options_test ${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIB} opentelemetry_exporter_otlp_grpc
opentelemetry_exporter_otlp_grpc_log
opentelemetry_exporter_otlp_grpc_metrics)
gtest_add_tests(
TARGET otlp_grpc_client_options_test
TEST_PREFIX exporter.otlp.
TEST_LIST otlp_grpc_client_options_test)

add_executable(otlp_grpc_exporter_factory_test
test/otlp_grpc_exporter_factory_test.cc)
target_link_libraries(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <ctype.h>
#include <algorithm>
#include <chrono>
#include <cstdint>
#include <map>
#include <string>

Expand Down Expand Up @@ -168,6 +169,30 @@ float GetOtlpDefaultTracesRetryBackoffMultiplier();
float GetOtlpDefaultMetricsRetryBackoffMultiplier();
float GetOtlpDefaultLogsRetryBackoffMultiplier();

/**
* Signal-independent accessors, for use by a gRPC client shared across
* multiple signal exporters. These read only the generic OTEL_EXPORTER_OTLP_*
* environment variables and fall back to the same spec defaults used above.
*/

void DumpOtlpHeaders(OtlpHeaders &output, const char *env_var_name);

std::string GetOtlpDefaultGrpcClientEndpoint();
bool GetOtlpDefaultGrpcClientIsInsecure();
std::string GetOtlpDefaultGrpcClientSslCertificatePath();
std::string GetOtlpDefaultGrpcClientSslCertificateString();
std::string GetOtlpDefaultGrpcClientSslClientKeyPath();
std::string GetOtlpDefaultGrpcClientSslClientKeyString();
std::string GetOtlpDefaultGrpcClientSslClientCertificatePath();
std::string GetOtlpDefaultGrpcClientSslClientCertificateString();
std::chrono::system_clock::duration GetOtlpDefaultGrpcClientTimeout();
OtlpHeaders GetOtlpDefaultGrpcClientHeaders();
std::string GetOtlpDefaultGrpcClientCompression();
std::uint32_t GetOtlpDefaultGrpcClientRetryMaxAttempts();
std::chrono::duration<float> GetOtlpDefaultGrpcClientRetryInitialBackoff();
std::chrono::duration<float> GetOtlpDefaultGrpcClientRetryMaxBackoff();
float GetOtlpDefaultGrpcClientRetryBackoffMultiplier();

} // namespace otlp
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ namespace exporter
namespace otlp
{

struct OtlpGrpcClientOptions
struct OPENTELEMETRY_EXPORT OtlpGrpcClientOptions
{
virtual ~OtlpGrpcClientOptions() = default;
OtlpGrpcClientOptions() = default;
virtual ~OtlpGrpcClientOptions();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my understanding, if we implement public struct or function in .cc files. We need to use OPENTELEMETRY_EXPORT to export them. Or the symbols will be hidden and cause link error in some situation.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I missed that. I'll add OPENTELEMETRY_EXPORT.


/** Lookup environment variables, and populate spec-compliant defaults. */
OtlpGrpcClientOptions();

/** No defaults. */
explicit OtlpGrpcClientOptions(void *);

OtlpGrpcClientOptions(const OtlpGrpcClientOptions &) = default;
OtlpGrpcClientOptions(OtlpGrpcClientOptions &&) = default;
OtlpGrpcClientOptions &operator=(const OtlpGrpcClientOptions &) = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct OPENTELEMETRY_EXPORT OtlpGrpcExporterOptions : public OtlpGrpcClientOptio
OtlpGrpcExporterOptions();
/** No defaults. */
OtlpGrpcExporterOptions(void *);
explicit OtlpGrpcExporterOptions(const OtlpGrpcClientOptions &client_options);
OtlpGrpcExporterOptions(const OtlpGrpcExporterOptions &) = default;
OtlpGrpcExporterOptions(OtlpGrpcExporterOptions &&) = default;
OtlpGrpcExporterOptions &operator=(const OtlpGrpcExporterOptions &) = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct OPENTELEMETRY_EXPORT OtlpGrpcLogRecordExporterOptions : public OtlpGrpcCl
OtlpGrpcLogRecordExporterOptions();
/** No defaults. */
OtlpGrpcLogRecordExporterOptions(void *);
explicit OtlpGrpcLogRecordExporterOptions(const OtlpGrpcClientOptions &client_options);
OtlpGrpcLogRecordExporterOptions(const OtlpGrpcLogRecordExporterOptions &) = default;
OtlpGrpcLogRecordExporterOptions(OtlpGrpcLogRecordExporterOptions &&) = default;
OtlpGrpcLogRecordExporterOptions &operator=(const OtlpGrpcLogRecordExporterOptions &) = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct OPENTELEMETRY_EXPORT OtlpGrpcMetricExporterOptions : public OtlpGrpcClien
OtlpGrpcMetricExporterOptions();
/** No defaults. */
OtlpGrpcMetricExporterOptions(void *);
explicit OtlpGrpcMetricExporterOptions(const OtlpGrpcClientOptions &client_options);
OtlpGrpcMetricExporterOptions(const OtlpGrpcMetricExporterOptions &) = default;
OtlpGrpcMetricExporterOptions(OtlpGrpcMetricExporterOptions &&) = default;
OtlpGrpcMetricExporterOptions &operator=(const OtlpGrpcMetricExporterOptions &) = default;
Expand Down
Loading