From 25dc909c3ebcc6e9bbbaecb79ee888d7a0f73b30 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Sun, 29 Oct 2023 01:31:07 +0200 Subject: [PATCH] Refactored GRPC options. --- examples/otlp/grpc_log_main.cc | 14 +++-- exporters/otlp/BUILD | 5 +- exporters/otlp/CMakeLists.txt | 9 ++- .../exporters/otlp/otlp_grpc_client.h | 12 ++-- .../exporters/otlp/otlp_grpc_client_options.h | 58 +++++++++++++++++++ .../otlp/otlp_grpc_exporter_options.h | 43 ++++---------- .../otlp/otlp_grpc_log_record_exporter.h | 6 +- .../otlp_grpc_log_record_exporter_factory.h | 4 +- .../otlp_grpc_log_record_exporter_options.h | 30 ++++++++++ .../otlp/otlp_grpc_metric_exporter_options.h | 20 ++++--- .../otlp_http_log_record_exporter_options.h | 2 +- exporters/otlp/src/otlp_grpc_client.cc | 10 ++-- .../otlp/src/otlp_grpc_exporter_options.cc | 36 ++++++++++++ .../otlp/src/otlp_grpc_log_record_exporter.cc | 6 +- .../otlp_grpc_log_record_exporter_factory.cc | 4 +- .../otlp_grpc_log_record_exporter_options.cc | 34 +++++++++++ .../src/otlp_grpc_metric_exporter_options.cc | 36 ++++++++++++ .../otlp/src/otlp_http_exporter_options.cc | 3 +- .../otlp_http_log_record_exporter_options.cc | 2 +- .../src/otlp_http_metric_exporter_options.cc | 2 +- ...p_grpc_log_record_exporter_factory_test.cc | 4 +- .../otlp_grpc_log_record_exporter_test.cc | 2 +- 22 files changed, 265 insertions(+), 77 deletions(-) create mode 100644 exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client_options.h create mode 100644 exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h create mode 100644 exporters/otlp/src/otlp_grpc_exporter_options.cc create mode 100644 exporters/otlp/src/otlp_grpc_log_record_exporter_options.cc create mode 100644 exporters/otlp/src/otlp_grpc_metric_exporter_options.cc diff --git a/examples/otlp/grpc_log_main.cc b/examples/otlp/grpc_log_main.cc index b1726de358..9d7399dbaf 100644 --- a/examples/otlp/grpc_log_main.cc +++ b/examples/otlp/grpc_log_main.cc @@ -2,7 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 #include "opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" #include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h" #include "opentelemetry/logs/provider.h" #include "opentelemetry/sdk/logs/exporter.h" #include "opentelemetry/sdk/logs/logger_provider_factory.h" @@ -37,6 +39,7 @@ namespace trace_sdk = opentelemetry::sdk::trace; namespace { opentelemetry::exporter::otlp::OtlpGrpcExporterOptions opts; +opentelemetry::exporter::otlp::OtlpGrpcLogRecordExporterOptions log_opts; void InitTracer() { // Create OTLP exporter instance @@ -65,7 +68,7 @@ void CleanupTracer() void InitLogger() { // Create OTLP exporter instance - auto exporter = otlp::OtlpGrpcLogRecordExporterFactory::Create(opts); + auto exporter = otlp::OtlpGrpcLogRecordExporterFactory::Create(log_opts); auto processor = logs_sdk::SimpleLogRecordProcessorFactory::Create(std::move(exporter)); nostd::shared_ptr provider( logs_sdk::LoggerProviderFactory::Create(std::move(processor))); @@ -92,11 +95,14 @@ int main(int argc, char *argv[]) { if (argc > 1) { - opts.endpoint = argv[1]; + opts.endpoint = argv[1]; + log_opts.endpoint = argv[1]; if (argc > 2) { - opts.use_ssl_credentials = true; - opts.ssl_credentials_cacert_path = argv[2]; + opts.use_ssl_credentials = true; + log_opts.use_ssl_credentials = true; + opts.ssl_credentials_cacert_path = argv[2]; + log_opts.ssl_credentials_cacert_path = argv[2]; } } InitLogger(); diff --git a/exporters/otlp/BUILD b/exporters/otlp/BUILD index f3a156988d..c5f1b1f348 100644 --- a/exporters/otlp/BUILD +++ b/exporters/otlp/BUILD @@ -73,6 +73,7 @@ cc_library( srcs = [ "src/otlp_grpc_exporter.cc", "src/otlp_grpc_exporter_factory.cc", + "src/otlp_grpc_exporter_options.cc", ], hdrs = [ "include/opentelemetry/exporters/otlp/otlp_environment.h", @@ -175,7 +176,6 @@ cc_library( ], hdrs = [ "include/opentelemetry/exporters/otlp/otlp_environment.h", - "include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h", "include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h", "include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h", "include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h", @@ -259,12 +259,13 @@ cc_library( srcs = [ "src/otlp_grpc_log_record_exporter.cc", "src/otlp_grpc_log_record_exporter_factory.cc", + "src/otlp_grpc_log_record_exporter_options.cc", ], hdrs = [ "include/opentelemetry/exporters/otlp/otlp_environment.h", - "include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h", "include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h", "include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h", + "include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h", "include/opentelemetry/exporters/otlp/protobuf_include_prefix.h", "include/opentelemetry/exporters/otlp/protobuf_include_suffix.h", ], diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index 96dec62dea..7f8b256b25 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -57,7 +57,8 @@ if(WITH_OTLP_GRPC) opentelemetry_exporter_otlp_grpc_client) add_library(opentelemetry_exporter_otlp_grpc - src/otlp_grpc_exporter.cc src/otlp_grpc_exporter_factory.cc) + src/otlp_grpc_exporter.cc src/otlp_grpc_exporter_factory.cc + src/otlp_grpc_exporter_options.cc) set_target_properties(opentelemetry_exporter_otlp_grpc PROPERTIES EXPORT_NAME otlp_grpc_exporter) @@ -73,7 +74,8 @@ if(WITH_OTLP_GRPC) add_library( opentelemetry_exporter_otlp_grpc_log src/otlp_grpc_log_record_exporter.cc - src/otlp_grpc_log_record_exporter_factory.cc) + src/otlp_grpc_log_record_exporter_factory.cc + src/otlp_grpc_log_record_exporter_options.cc) set_target_properties(opentelemetry_exporter_otlp_grpc_log PROPERTIES EXPORT_NAME otlp_grpc_log_record_exporter) @@ -88,7 +90,8 @@ if(WITH_OTLP_GRPC) add_library( opentelemetry_exporter_otlp_grpc_metrics - src/otlp_grpc_metric_exporter.cc src/otlp_grpc_metric_exporter_factory.cc) + src/otlp_grpc_metric_exporter.cc src/otlp_grpc_metric_exporter_factory.cc + src/otlp_grpc_metric_exporter_options.cc) set_target_properties(opentelemetry_exporter_otlp_grpc_metrics PROPERTIES EXPORT_NAME otlp_grpc_metrics_exporter) diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client.h index 7998bd2646..fe95281fad 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client.h @@ -23,6 +23,8 @@ namespace exporter namespace otlp { +struct OtlpGrpcClientOptions; + /** * The OTLP gRPC client contains utility functions of gRPC. */ @@ -32,13 +34,13 @@ class OtlpGrpcClient /** * Create gRPC channel from the exporter options. */ - static std::shared_ptr MakeChannel(const OtlpGrpcExporterOptions &options); + static std::shared_ptr MakeChannel(const OtlpGrpcClientOptions &options); /** * Create gRPC client context to call RPC. */ static std::unique_ptr MakeClientContext( - const OtlpGrpcExporterOptions &options); + const OtlpGrpcClientOptions &options); /** * Create gRPC CompletionQueue to async call RPC. @@ -49,19 +51,19 @@ class OtlpGrpcClient * Create trace service stub to communicate with the OpenTelemetry Collector. */ static std::unique_ptr - MakeTraceServiceStub(const OtlpGrpcExporterOptions &options); + MakeTraceServiceStub(const OtlpGrpcClientOptions &options); /** * Create metrics service stub to communicate with the OpenTelemetry Collector. */ static std::unique_ptr - MakeMetricsServiceStub(const OtlpGrpcExporterOptions &options); + MakeMetricsServiceStub(const OtlpGrpcClientOptions &options); /** * Create logs service stub to communicate with the OpenTelemetry Collector. */ static std::unique_ptr - MakeLogsServiceStub(const OtlpGrpcExporterOptions &options); + MakeLogsServiceStub(const OtlpGrpcClientOptions &options); static grpc::Status DelegateExport( proto::collector::trace::v1::TraceService::StubInterface *stub, diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client_options.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client_options.h new file mode 100644 index 0000000000..310fc94d4d --- /dev/null +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client_options.h @@ -0,0 +1,58 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/exporters/otlp/otlp_environment.h" +#include "opentelemetry/version.h" + +#include +#include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +struct OtlpGrpcClientOptions +{ + /** The endpoint to export to. */ + std::string endpoint; + + /** Use SSL. */ + bool use_ssl_credentials; + + /** CA CERT, path to a file. */ + std::string ssl_credentials_cacert_path; + + /** CA CERT, as a string. */ + std::string ssl_credentials_cacert_as_string; + +#ifdef ENABLE_OTLP_GRPC_SSL_MTLS_PREVIEW + /** CLIENT KEY, path to a file. */ + std::string ssl_client_key_path; + + /** CLIENT KEY, as a string. */ + std::string ssl_client_key_string; + + /** CLIENT CERT, path to a file. */ + std::string ssl_client_cert_path; + + /** CLIENT CERT, as a string. */ + std::string ssl_client_cert_string; +#endif + + /** Export timeout. */ + std::chrono::system_clock::duration timeout; + + /** Additional HTTP headers. */ + OtlpHeaders metadata; + + /** User agent. */ + std::string user_agent; +}; + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h index 01ac5b43f2..33a430ba9d 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h @@ -3,9 +3,8 @@ #pragma once -#include "opentelemetry/exporters/otlp/otlp_environment.h" - -#include +#include "opentelemetry/exporters/otlp/otlp_grpc_client_options.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -15,38 +14,16 @@ namespace otlp /** * Struct to hold OTLP GRPC traces exporter options. + * + * See + * https://github.com/open-telemetry/opentelemetry-proto/blob/main/docs/specification.md#otlpgrpc + * + * See + * https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md */ -struct OtlpGrpcExporterOptions +struct OtlpGrpcExporterOptions : public OtlpGrpcClientOptions { - // The endpoint to export to. By default the OpenTelemetry Collector's default endpoint. - std::string endpoint = GetOtlpDefaultGrpcEndpoint(); - // By default when false, uses grpc::InsecureChannelCredentials(); If true, - // uses ssl_credentials_cacert_path if non-empty, else uses ssl_credentials_cacert_as_string - bool use_ssl_credentials = GetOtlpDefaultIsSslEnable(); - // ssl_credentials_cacert_path specifies path to .pem file to be used for SSL encryption. - std::string ssl_credentials_cacert_path = GetOtlpDefaultSslCertificatePath(); - // ssl_credentials_cacert_as_string in-memory string representation of .pem file to be used for - // SSL encryption. - std::string ssl_credentials_cacert_as_string = GetOtlpDefaultSslCertificateString(); - -#ifdef ENABLE_OTLP_GRPC_SSL_MTLS_PREVIEW - // At most one of ssl_client_key_* should be non-empty. If use_ssl_credentials, they will - // be read to allow for mTLS. - std::string ssl_client_key_path = GetOtlpDefaultTracesSslClientKeyPath(); - std::string ssl_client_key_string = GetOtlpDefaultTracesSslClientKeyString(); - - // At most one of ssl_client_cert_* should be non-empty. If use_ssl_credentials, they will - // be read to allow for mTLS. - std::string ssl_client_cert_path = GetOtlpDefaultTracesSslClientCertificatePath(); - std::string ssl_client_cert_string = GetOtlpDefaultTracesSslClientCertificateString(); -#endif - - // Timeout for grpc deadline - std::chrono::system_clock::duration timeout = GetOtlpDefaultTimeout(); - // Additional HTTP headers - OtlpHeaders metadata = GetOtlpDefaultHeaders(); - // User agent - std::string user_agent = GetOtlpDefaultUserAgent(); + OtlpGrpcExporterOptions(); }; } // namespace otlp diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h index 33476297cb..29333703b1 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h @@ -13,7 +13,7 @@ // clang-format on #include "opentelemetry/exporters/otlp/otlp_environment.h" -#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h" #include "opentelemetry/sdk/logs/exporter.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -37,7 +37,7 @@ class OtlpGrpcLogRecordExporter : public opentelemetry::sdk::logs::LogRecordExpo * Create an OtlpGrpcLogRecordExporter with user specified options. * @param options An object containing the user's configuration options. */ - OtlpGrpcLogRecordExporter(const OtlpGrpcExporterOptions &options); + OtlpGrpcLogRecordExporter(const OtlpGrpcLogRecordExporterOptions &options); /** * Creates a recordable that stores the data in protobuf. @@ -71,7 +71,7 @@ class OtlpGrpcLogRecordExporter : public opentelemetry::sdk::logs::LogRecordExpo private: // Configuration options for the exporter - const OtlpGrpcExporterOptions options_; + const OtlpGrpcLogRecordExporterOptions options_; // For testing friend class OtlpGrpcLogRecordExporterTestPeer; diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h index 5f81e60f2e..7a88615959 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h @@ -3,7 +3,7 @@ #pragma once -#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h" #include "opentelemetry/sdk/logs/exporter.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -27,7 +27,7 @@ class OPENTELEMETRY_EXPORT OtlpGrpcLogRecordExporterFactory * Create a OtlpGrpcLogRecordExporter. */ static std::unique_ptr Create( - const OtlpGrpcExporterOptions &options); + const OtlpGrpcLogRecordExporterOptions &options); }; } // namespace otlp diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h new file mode 100644 index 0000000000..713bfafd9a --- /dev/null +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h @@ -0,0 +1,30 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/exporters/otlp/otlp_grpc_client_options.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +/** + * Struct to hold OTLP GRPC log record exporter options. + * + * See + * https://github.com/open-telemetry/opentelemetry-proto/blob/main/docs/specification.md#otlpgrpc + * + * See + * https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md + */ +struct OtlpGrpcLogRecordExporterOptions : public OtlpGrpcClientOptions +{ + OtlpGrpcLogRecordExporterOptions(); +}; + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h index a56cf8cb55..723c25a296 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h @@ -3,11 +3,9 @@ #pragma once -#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_client_options.h" #include "opentelemetry/exporters/otlp/otlp_preferred_temporality.h" -#include "opentelemetry/sdk/metrics/instruments.h" - -#include +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -17,13 +15,19 @@ namespace otlp /** * Struct to hold OTLP GRPC metrics exporter options. + * + * See + * https://github.com/open-telemetry/opentelemetry-proto/blob/main/docs/specification.md#otlpgrpc + * + * See + * https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md */ -struct OtlpGrpcMetricExporterOptions : public OtlpGrpcExporterOptions +struct OtlpGrpcMetricExporterOptions : public OtlpGrpcClientOptions { + OtlpGrpcMetricExporterOptions(); - // Preferred Aggregation Temporality - PreferredAggregationTemporality aggregation_temporality = - PreferredAggregationTemporality::kCumulative; + /** Preferred Aggregation Temporality. */ + PreferredAggregationTemporality aggregation_temporality; }; } // namespace otlp diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h index c16afd78d0..284d8dcc8f 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h @@ -19,7 +19,7 @@ namespace otlp { /** - * Struct to hold OTLP HTTP logs exporter options. + * Struct to hold OTLP HTTP log record exporter options. * * See * https://github.com/open-telemetry/opentelemetry-proto/blob/main/docs/specification.md#otlphttp diff --git a/exporters/otlp/src/otlp_grpc_client.cc b/exporters/otlp/src/otlp_grpc_client.cc index 625781025e..c0436eddaf 100644 --- a/exporters/otlp/src/otlp_grpc_client.cc +++ b/exporters/otlp/src/otlp_grpc_client.cc @@ -48,7 +48,7 @@ static std::string GetFileContentsOrInMemoryContents(const std::string &file_pat } // namespace -std::shared_ptr OtlpGrpcClient::MakeChannel(const OtlpGrpcExporterOptions &options) +std::shared_ptr OtlpGrpcClient::MakeChannel(const OtlpGrpcClientOptions &options) { std::shared_ptr channel; @@ -94,7 +94,7 @@ std::shared_ptr OtlpGrpcClient::MakeChannel(const OtlpGrpcExporte } std::unique_ptr OtlpGrpcClient::MakeClientContext( - const OtlpGrpcExporterOptions &options) + const OtlpGrpcClientOptions &options) { std::unique_ptr context{new grpc::ClientContext()}; if (!context) @@ -121,19 +121,19 @@ std::unique_ptr OtlpGrpcClient::MakeCompletionQueue() } std::unique_ptr -OtlpGrpcClient::MakeTraceServiceStub(const OtlpGrpcExporterOptions &options) +OtlpGrpcClient::MakeTraceServiceStub(const OtlpGrpcClientOptions &options) { return proto::collector::trace::v1::TraceService::NewStub(MakeChannel(options)); } std::unique_ptr -OtlpGrpcClient::MakeMetricsServiceStub(const OtlpGrpcExporterOptions &options) +OtlpGrpcClient::MakeMetricsServiceStub(const OtlpGrpcClientOptions &options) { return proto::collector::metrics::v1::MetricsService::NewStub(MakeChannel(options)); } std::unique_ptr -OtlpGrpcClient::MakeLogsServiceStub(const OtlpGrpcExporterOptions &options) +OtlpGrpcClient::MakeLogsServiceStub(const OtlpGrpcClientOptions &options) { return proto::collector::logs::v1::LogsService::NewStub(MakeChannel(options)); } diff --git a/exporters/otlp/src/otlp_grpc_exporter_options.cc b/exporters/otlp/src/otlp_grpc_exporter_options.cc new file mode 100644 index 0000000000..27daa98d45 --- /dev/null +++ b/exporters/otlp/src/otlp_grpc_exporter_options.cc @@ -0,0 +1,36 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" +#include "opentelemetry/version.h" + +#include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +OtlpGrpcExporterOptions::OtlpGrpcExporterOptions() +{ + endpoint = GetOtlpDefaultGrpcTracesEndpoint(); + use_ssl_credentials = !GetOtlpDefaultGrpcTracesIsInsecure(); /* negation intended. */ + ssl_credentials_cacert_path = GetOtlpDefaultTracesSslCertificatePath(); + ssl_credentials_cacert_as_string = GetOtlpDefaultTracesSslCertificateString(); + +#ifdef ENABLE_OTLP_GRPC_SSL_MTLS_PREVIEW + ssl_client_key_path = GetOtlpDefaultTracesSslClientKeyPath(); + ssl_client_key_string = GetOtlpDefaultTracesSslClientKeyString(); + ssl_client_cert_path = GetOtlpDefaultTracesSslClientCertificatePath(); + ssl_client_cert_string = GetOtlpDefaultTracesSslClientCertificateString(); +#endif + + timeout = GetOtlpDefaultTracesTimeout(); + metadata = GetOtlpDefaultTracesHeaders(); + user_agent = GetOtlpDefaultUserAgent(); +} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_grpc_log_record_exporter.cc b/exporters/otlp/src/otlp_grpc_log_record_exporter.cc index 01367da886..adcae11295 100644 --- a/exporters/otlp/src/otlp_grpc_log_record_exporter.cc +++ b/exporters/otlp/src/otlp_grpc_log_record_exporter.cc @@ -30,16 +30,16 @@ namespace otlp // -------------------------------- Constructors -------------------------------- OtlpGrpcLogRecordExporter::OtlpGrpcLogRecordExporter() - : OtlpGrpcLogRecordExporter(OtlpGrpcExporterOptions()) + : OtlpGrpcLogRecordExporter(OtlpGrpcLogRecordExporterOptions()) {} -OtlpGrpcLogRecordExporter::OtlpGrpcLogRecordExporter(const OtlpGrpcExporterOptions &options) +OtlpGrpcLogRecordExporter::OtlpGrpcLogRecordExporter(const OtlpGrpcLogRecordExporterOptions &options) : options_(options), log_service_stub_(OtlpGrpcClient::MakeLogsServiceStub(options)) {} OtlpGrpcLogRecordExporter::OtlpGrpcLogRecordExporter( std::unique_ptr stub) - : options_(OtlpGrpcExporterOptions()), log_service_stub_(std::move(stub)) + : options_(OtlpGrpcLogRecordExporterOptions()), log_service_stub_(std::move(stub)) {} // ----------------------------- Exporter methods ------------------------------ diff --git a/exporters/otlp/src/otlp_grpc_log_record_exporter_factory.cc b/exporters/otlp/src/otlp_grpc_log_record_exporter_factory.cc index b36eefa6cb..13fa3f8543 100644 --- a/exporters/otlp/src/otlp_grpc_log_record_exporter_factory.cc +++ b/exporters/otlp/src/otlp_grpc_log_record_exporter_factory.cc @@ -16,12 +16,12 @@ namespace otlp std::unique_ptr OtlpGrpcLogRecordExporterFactory::Create() { - OtlpGrpcExporterOptions options; + OtlpGrpcLogRecordExporterOptions options; return Create(options); } std::unique_ptr -OtlpGrpcLogRecordExporterFactory::Create(const OtlpGrpcExporterOptions &options) +OtlpGrpcLogRecordExporterFactory::Create(const OtlpGrpcLogRecordExporterOptions &options) { std::unique_ptr exporter( new OtlpGrpcLogRecordExporter(options)); diff --git a/exporters/otlp/src/otlp_grpc_log_record_exporter_options.cc b/exporters/otlp/src/otlp_grpc_log_record_exporter_options.cc new file mode 100644 index 0000000000..b5208120ef --- /dev/null +++ b/exporters/otlp/src/otlp_grpc_log_record_exporter_options.cc @@ -0,0 +1,34 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +OtlpGrpcLogRecordExporterOptions::OtlpGrpcLogRecordExporterOptions() +{ + endpoint = GetOtlpDefaultGrpcLogsEndpoint(); + use_ssl_credentials = !GetOtlpDefaultGrpcLogsIsInsecure(); /* negation intended. */ + ssl_credentials_cacert_path = GetOtlpDefaultLogsSslCertificatePath(); + ssl_credentials_cacert_as_string = GetOtlpDefaultLogsSslCertificateString(); + +#ifdef ENABLE_OTLP_GRPC_SSL_MTLS_PREVIEW + ssl_client_key_path = GetOtlpDefaultLogsSslClientKeyPath(); + ssl_client_key_string = GetOtlpDefaultLogsSslClientKeyString(); + ssl_client_cert_path = GetOtlpDefaultLogsSslClientCertificatePath(); + ssl_client_cert_string = GetOtlpDefaultLogsSslClientCertificateString(); +#endif + + timeout = GetOtlpDefaultLogsTimeout(); + metadata = GetOtlpDefaultLogsHeaders(); + user_agent = GetOtlpDefaultUserAgent(); +} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_grpc_metric_exporter_options.cc b/exporters/otlp/src/otlp_grpc_metric_exporter_options.cc new file mode 100644 index 0000000000..c8dc4a82ca --- /dev/null +++ b/exporters/otlp/src/otlp_grpc_metric_exporter_options.cc @@ -0,0 +1,36 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +OtlpGrpcMetricExporterOptions::OtlpGrpcMetricExporterOptions() +{ + endpoint = GetOtlpDefaultGrpcMetricsEndpoint(); + use_ssl_credentials = !GetOtlpDefaultGrpcMetricsIsInsecure(); /* negation intended. */ + ssl_credentials_cacert_path = GetOtlpDefaultMetricsSslCertificatePath(); + ssl_credentials_cacert_as_string = GetOtlpDefaultMetricsSslCertificateString(); + +#ifdef ENABLE_OTLP_GRPC_SSL_MTLS_PREVIEW + ssl_client_key_path = GetOtlpDefaultMetricsSslClientKeyPath(); + ssl_client_key_string = GetOtlpDefaultMetricsSslClientKeyString(); + ssl_client_cert_path = GetOtlpDefaultMetricsSslClientCertificatePath(); + ssl_client_cert_string = GetOtlpDefaultMetricsSslClientCertificateString(); +#endif + + timeout = GetOtlpDefaultMetricsTimeout(); + metadata = GetOtlpDefaultMetricsHeaders(); + user_agent = GetOtlpDefaultUserAgent(); + + aggregation_temporality = PreferredAggregationTemporality::kCumulative; +} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_http_exporter_options.cc b/exporters/otlp/src/otlp_http_exporter_options.cc index e41ab4e55d..61368f9350 100644 --- a/exporters/otlp/src/otlp_http_exporter_options.cc +++ b/exporters/otlp/src/otlp_http_exporter_options.cc @@ -45,7 +45,8 @@ OtlpHttpExporterOptions::OtlpHttpExporterOptions() ssl_cipher = GetOtlpDefaultTracesSslTlsCipher(); ssl_cipher_suite = GetOtlpDefaultTracesSslTlsCipherSuite(); #endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */ -}; +} + } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_http_log_record_exporter_options.cc b/exporters/otlp/src/otlp_http_log_record_exporter_options.cc index 7ce165997f..b9d49e69d8 100644 --- a/exporters/otlp/src/otlp_http_log_record_exporter_options.cc +++ b/exporters/otlp/src/otlp_http_log_record_exporter_options.cc @@ -45,7 +45,7 @@ OtlpHttpLogRecordExporterOptions::OtlpHttpLogRecordExporterOptions() ssl_cipher = GetOtlpDefaultLogsSslTlsCipher(); ssl_cipher_suite = GetOtlpDefaultLogsSslTlsCipherSuite(); #endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */ -}; +} } // namespace otlp } // namespace exporter diff --git a/exporters/otlp/src/otlp_http_metric_exporter_options.cc b/exporters/otlp/src/otlp_http_metric_exporter_options.cc index 64777b5959..f9de260802 100644 --- a/exporters/otlp/src/otlp_http_metric_exporter_options.cc +++ b/exporters/otlp/src/otlp_http_metric_exporter_options.cc @@ -46,7 +46,7 @@ OtlpHttpMetricExporterOptions::OtlpHttpMetricExporterOptions() ssl_cipher = GetOtlpDefaultMetricsSslTlsCipher(); ssl_cipher_suite = GetOtlpDefaultMetricsSslTlsCipherSuite(); #endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */ -}; +} } // namespace otlp } // namespace exporter diff --git a/exporters/otlp/test/otlp_grpc_log_record_exporter_factory_test.cc b/exporters/otlp/test/otlp_grpc_log_record_exporter_factory_test.cc index 2cc534277d..f71afd1282 100644 --- a/exporters/otlp/test/otlp_grpc_log_record_exporter_factory_test.cc +++ b/exporters/otlp/test/otlp_grpc_log_record_exporter_factory_test.cc @@ -3,7 +3,7 @@ #include -#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h" #include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h" /* @@ -22,7 +22,7 @@ namespace otlp TEST(OtlpGrpcLogRecordExporterFactoryTest, BuildTest) { - OtlpGrpcExporterOptions opts; + OtlpGrpcLogRecordExporterOptions opts; opts.endpoint = "localhost:45454"; std::unique_ptr exporter = diff --git a/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc b/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc index 547d21d056..9514b05d55 100644 --- a/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc @@ -59,7 +59,7 @@ class OtlpGrpcLogRecordExporterTestPeer : public ::testing::Test } // Get the options associated with the given exporter. - const OtlpGrpcExporterOptions &GetOptions(std::unique_ptr &exporter) + const OtlpGrpcLogRecordExporterOptions &GetOptions(std::unique_ptr &exporter) { return exporter->options_; }