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
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,17 @@ Increment the:
* docs: update supported development platforms
[#4260](https://github.com/open-telemetry/opentelemetry-cpp/pull/4260)

* [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)

* [RELEASE] Bump main branch to 1.29.0-dev
[#4259](https://github.com/open-telemetry/opentelemetry-cpp/pull/4259)

Expand Down
19 changes: 19 additions & 0 deletions exporters/otlp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,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 @@ -114,6 +115,7 @@ cc_library(
deps = [
":otlp_common",
"//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 @@ -757,6 +759,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_log_record_exporter",
":otlp_grpc_metric_exporter",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "otlp_grpc_exporter_factory_test",
srcs = ["test/otlp_grpc_exporter_factory_test.cc"],
Expand Down
18 changes: 17 additions & 1 deletion exporters/otlp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ if(OTELCPP_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 @@ -891,6 +892,21 @@ if(OTELCPP_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 <algorithm>
#include <cctype>
#include <chrono>
#include <cstdint>
#include <map>
#include <string>

Expand Down Expand Up @@ -121,6 +122,10 @@ std::chrono::system_clock::duration GetOtlpDefaultTracesTimeout();
std::chrono::system_clock::duration GetOtlpDefaultMetricsTimeout();
std::chrono::system_clock::duration GetOtlpDefaultLogsTimeout();

bool GetOtlpDefaultTracesTimeoutOverride(std::chrono::system_clock::duration &value);
bool GetOtlpDefaultMetricsTimeoutOverride(std::chrono::system_clock::duration &value);
bool GetOtlpDefaultLogsTimeoutOverride(std::chrono::system_clock::duration &value);

// Compatibility with OTELCPP 1.8.2
inline std::chrono::system_clock::duration GetOtlpDefaultTimeout()
{
Expand Down Expand Up @@ -168,6 +173,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);

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

} // namespace otlp
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@
#include "opentelemetry/version.h"

#include <chrono>
#include <memory>
#include <cstddef>
#include <cstdint>
#include <string>

#ifdef ENABLE_OTLP_GRPC_CREDENTIAL_PREVIEW
# include <memory>
#endif

namespace grpc
{
#ifdef ENABLE_OTLP_GRPC_CREDENTIAL_PREVIEW
class ChannelCredentials;
#endif
class ChannelArguments;
} // namespace grpc

Expand All @@ -22,10 +29,16 @@ namespace exporter
namespace otlp
{

struct OtlpGrpcClientOptions
struct OPENTELEMETRY_EXPORT 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.

RE: #4249 (comment)

@owent since this class now uses the same export declaration as the otlp exporter options classes that derive from it, would it be reasonable to defer any changes to those definitions to a follow up PR?

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.

The export/import declaration should follow the target. What I mean is:

  • Public functions in otlp_environment.cc should be declared as OPENTELEMETRY_OTLP_COMMON_API, since that file is built into the opentelemetry_otlp_common target.
  • Public functions in otlp_grpc_client.cc should be declared as OPENTELEMETRY_OTLP_GRPC_CLIENT_API.

As for OtlpGrpcClientOptions, it's fine to leave it without an export declaration — it's a header-only class with no source file. Every target that references it will compile its own copy. This only adds a bit of linker load; there's no visibility issue.

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.

The export/import declaration should follow the target.

That makes sense to me. Since this would be a new policy for the otlp exporter folder (and likely needed for the SDK classes as well), is it reasonable to apply the new policy in follow-up PRs?

Properly setting the export/import declarations (for all platforms and on the intended public facing classes) is something we need to address broadly throughout the project.

As for OtlpGrpcClientOptions, it's fine to leave it without an export declaration — it's a header-only class with no source file.

This PR adds the .cc file for OtlpGrpcClientOptions and may have prompted this discussion.

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.

That makes sense to me. Since this would be a new policy for the otlp exporter folder (and likely needed for the SDK classes as well), is it reasonable to apply the new policy in follow-up PRs?

My suggestion is to apply it to all components. If we export symbols this way consistently across all components, ext/src/dll/input.src would no longer be needed, and we could keep a uniform symbol-exporting rule across all platforms, compilers, and optimization settings — by setting the default visibility to hidden on Unix-like systems. It would also reduce linker load and speed up linking. (For example, some compiler versions may inline a symbol in Release builds but keep it "imported" in Debug builds, which leads to link errors. This issue has occurred with certain versions of protobuf.)

This PR adds the .cc file for OtlpGrpcClientOptions and may have prompted this discussion.

Sorry, I missed that. Then it should use something like OPENTELEMETRY_OTLP_GRPC_CLIENT_API to export its symbols.

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.

Applying the symbol visibility attributes to all components sounds like a nice improvement.

The grpc client class doesn't have symbol visibility attributes now so the change must be broader than this PR should take on.

Let's merge this once CI is passing and address the visibility attributes in a new PR that fixes the grpc client as well.

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.

@owent, This PR should pass CI now. Please take a review pass (your review is still requesting changes).

{
virtual ~OtlpGrpcClientOptions() = default;
OtlpGrpcClientOptions() = default;
virtual ~OtlpGrpcClientOptions();
Comment thread
owent marked this conversation as resolved.

/** 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 All @@ -35,7 +48,7 @@ struct OtlpGrpcClientOptions
std::string endpoint;

/** Use SSL. */
bool use_ssl_credentials{};
bool use_ssl_credentials{true};

/** CA CERT, path to a file. */
std::string ssl_credentials_cacert_path;
Expand Down Expand Up @@ -70,14 +83,14 @@ struct OtlpGrpcClientOptions
std::string user_agent;

/** max number of threads that can be allocated from this */
std::size_t max_threads{};
std::size_t max_threads{0};

/** Compression type. */
std::string compression;

#ifdef ENABLE_ASYNC_EXPORT
// Concurrent requests
std::size_t max_concurrent_requests{};
std::size_t max_concurrent_requests{64};
#endif

/** The maximum number of call attempts, including the original attempt. */
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
Loading