diff --git a/CHANGELOG.md b/CHANGELOG.md index 7317b2b5f1..2f89ef1505 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,8 +25,10 @@ Increment the: [#2385](https://github.com/open-telemetry/opentelemetry-cpp/pull/2385) * [API] Add a new AddLink() operation to Span [#2380](https://github.com/open-telemetry/opentelemetry-cpp/pull/2380) -* [SDK] Fix GetLogger with empty library - name[#2398](https://github.com/open-telemetry/opentelemetry-cpp/pull/2398) +* [SDK] Fix GetLogger with empty library name + [#2398](https://github.com/open-telemetry/opentelemetry-cpp/pull/2398) +* [EXPORTER] Rework OTLP/HTTP and OTLP/GRPC exporter options + [#2388](https://github.com/open-telemetry/opentelemetry-cpp/pull/2388) Important changes: @@ -56,6 +58,14 @@ Important changes: * These build options are scheduled to be removed by the next release, building without SSL/TLS will no longer be possible. +* [EXPORTER] Rework OTLP/HTTP and OTLP/GRPC exporter options + [#2388](https://github.com/open-telemetry/opentelemetry-cpp/pull/2388) + * `OtlpGrpcMetricExporterOptions` used to honor `_TRACES_` + environment variables, instead of `_METRICS_` environment variables. + * The implementation of `OtlpGrpcMetricExporterOptions` is now fixed. + * Please check configuration variables, + to make sure `_METRICS_` variables are set as expected. + Breaking changes: * [BUILD] Remove WITH_REMOVE_METER_PREVIEW, use WITH_ABI_VERSION_2 instead @@ -77,6 +87,20 @@ Breaking changes: instead of nostd::string_view for name, version and schema to maintain a single export definition for DLL. +* [EXPORTER] Rework OTLP/HTTP and OTLP/GRPC exporter options + [#2388](https://github.com/open-telemetry/opentelemetry-cpp/pull/2388) + * `OtlpGrpcLogRecordExporter` incorrectly used `OtlpGrpcExporterOptions`, + which are options for traces and not logs. + * This created a bug: the `OtlpGrpcLogRecordExporter` honors `_TRACES_` + environment variables, instead of `_LOGS_` environment variables. + * `OtlpGrpcLogRecordExporter` is changed to use + `OtlpGrpcLogRecordExporterOptions` instead, fixing the bug. + * User code that initializes the SDK with a GRPC Log exporter, + and uses exporter options, should adjust to replace + `OtlpGrpcExporterOptions` with `OtlpGrpcLogRecordExporterOptions`. + * Please check configuration variables, + to make sure `_LOGS_` variables are set as expected. + ## [1.12.0] 2023-10-16 * [BUILD] Support `pkg-config` 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 5099b43510..a70153edd8 100644 --- a/exporters/otlp/BUILD +++ b/exporters/otlp/BUILD @@ -47,7 +47,7 @@ cc_library( hdrs = [ "include/opentelemetry/exporters/otlp/otlp_environment.h", "include/opentelemetry/exporters/otlp/otlp_grpc_client.h", - "include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h", + "include/opentelemetry/exporters/otlp/otlp_grpc_client_options.h", "include/opentelemetry/exporters/otlp/otlp_grpc_utils.h", "include/opentelemetry/exporters/otlp/protobuf_include_prefix.h", "include/opentelemetry/exporters/otlp/protobuf_include_suffix.h", @@ -73,9 +73,11 @@ 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", + "include/opentelemetry/exporters/otlp/otlp_grpc_client_options.h", "include/opentelemetry/exporters/otlp/otlp_grpc_exporter.h", "include/opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h", "include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h", @@ -143,6 +145,7 @@ cc_library( srcs = [ "src/otlp_http_exporter.cc", "src/otlp_http_exporter_factory.cc", + "src/otlp_http_exporter_options.cc", ], hdrs = [ "include/opentelemetry/exporters/otlp/otlp_environment.h", @@ -170,10 +173,11 @@ cc_library( srcs = [ "src/otlp_grpc_metric_exporter.cc", "src/otlp_grpc_metric_exporter_factory.cc", + "src/otlp_grpc_metric_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_client_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", @@ -201,6 +205,7 @@ cc_library( srcs = [ "src/otlp_http_metric_exporter.cc", "src/otlp_http_metric_exporter_factory.cc", + "src/otlp_http_metric_exporter_options.cc", ], hdrs = [ "include/opentelemetry/exporters/otlp/otlp_environment.h", @@ -228,6 +233,7 @@ cc_library( srcs = [ "src/otlp_http_log_record_exporter.cc", "src/otlp_http_log_record_exporter_factory.cc", + "src/otlp_http_log_record_exporter_options.cc", ], hdrs = [ "include/opentelemetry/exporters/otlp/otlp_environment.h", @@ -255,12 +261,14 @@ 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_client_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", ], @@ -436,6 +444,22 @@ cc_test( ], ) +cc_test( + name = "otlp_grpc_metric_exporter_test", + srcs = ["test/otlp_grpc_metric_exporter_test.cc"], + tags = [ + "otlp", + "otlp_grpc_metric", + "test", + ], + deps = [ + ":otlp_grpc_metric_exporter", + "//api", + "//sdk/src/metrics", + "@com_google_googletest//:gtest_main", + ], +) + cc_test( name = "otlp_grpc_metric_exporter_factory_test", srcs = ["test/otlp_grpc_metric_exporter_factory_test.cc"], diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index adab87ff02..ec55211a6d 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -56,8 +56,10 @@ if(WITH_OTLP_GRPC) list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_grpc_client) - add_library(opentelemetry_exporter_otlp_grpc - src/otlp_grpc_exporter.cc src/otlp_grpc_exporter_factory.cc) + add_library( + opentelemetry_exporter_otlp_grpc + 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 +75,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 +91,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) @@ -130,8 +134,10 @@ if(WITH_OTLP_HTTP) list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_http_client) - add_library(opentelemetry_exporter_otlp_http - src/otlp_http_exporter.cc src/otlp_http_exporter_factory.cc) + add_library( + opentelemetry_exporter_otlp_http + src/otlp_http_exporter.cc src/otlp_http_exporter_factory.cc + src/otlp_http_exporter_options.cc) set_target_properties(opentelemetry_exporter_otlp_http PROPERTIES EXPORT_NAME otlp_http_exporter) @@ -147,7 +153,8 @@ if(WITH_OTLP_HTTP) add_library( opentelemetry_exporter_otlp_http_log src/otlp_http_log_record_exporter.cc - src/otlp_http_log_record_exporter_factory.cc) + src/otlp_http_log_record_exporter_factory.cc + src/otlp_http_log_record_exporter_options.cc) set_target_properties(opentelemetry_exporter_otlp_http_log PROPERTIES EXPORT_NAME otlp_http_log_record_exporter) @@ -162,7 +169,8 @@ if(WITH_OTLP_HTTP) add_library( opentelemetry_exporter_otlp_http_metric - src/otlp_http_metric_exporter.cc src/otlp_http_metric_exporter_factory.cc) + src/otlp_http_metric_exporter.cc src/otlp_http_metric_exporter_factory.cc + src/otlp_http_metric_exporter_options.cc) set_target_properties(opentelemetry_exporter_otlp_http_metric PROPERTIES EXPORT_NAME otlp_http_metric_exporter) @@ -295,6 +303,17 @@ if(BUILD_TESTING) TEST_PREFIX exporter.otlp. TEST_LIST otlp_grpc_log_record_exporter_factory_test) + add_executable(otlp_grpc_metric_exporter_test + test/otlp_grpc_metric_exporter_test.cc) + target_link_libraries( + otlp_grpc_metric_exporter_test ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIB} opentelemetry_exporter_otlp_grpc + opentelemetry_exporter_otlp_grpc_metrics) + gtest_add_tests( + TARGET otlp_grpc_metric_exporter_test + TEST_PREFIX exporter.otlp. + TEST_LIST otlp_grpc_metric_exporter_test) + add_executable(otlp_grpc_metric_exporter_factory_test test/otlp_grpc_metric_exporter_factory_test.cc) target_link_libraries( 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..fa1a69d619 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client.h @@ -7,7 +7,7 @@ #include -#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_client_options.h" #include "opentelemetry/exporters/otlp/protobuf_include_prefix.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..b2556f1f76 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,17 @@ 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 OPENTELEMETRY_EXPORT 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(); + ~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..cc1a199c4b --- /dev/null +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h @@ -0,0 +1,31 @@ +// 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 OPENTELEMETRY_EXPORT OtlpGrpcLogRecordExporterOptions : public OtlpGrpcClientOptions +{ + OtlpGrpcLogRecordExporterOptions(); + ~OtlpGrpcLogRecordExporterOptions(); +}; + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h index 11bb64c24f..5f975c8ce3 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h @@ -63,7 +63,7 @@ class OtlpGrpcMetricExporter : public opentelemetry::sdk::metrics::PushMetricExp const sdk::metrics::AggregationTemporalitySelector aggregation_temporality_selector_; // For testing - friend class OtlpGrpcExporterTestPeer; + friend class OtlpGrpcMetricExporterTestPeer; // Store service stub internally. Useful for testing. std::unique_ptr 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..22be580972 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,20 @@ 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 OPENTELEMETRY_EXPORT OtlpGrpcMetricExporterOptions : public OtlpGrpcClientOptions { + OtlpGrpcMetricExporterOptions(); + ~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_exporter_options.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_options.h index 29b4b76ec0..9200a506b8 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_options.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_options.h @@ -3,9 +3,9 @@ #pragma once -#include "opentelemetry/exporters/otlp/otlp_http.h" - #include "opentelemetry/exporters/otlp/otlp_environment.h" +#include "opentelemetry/exporters/otlp/otlp_http.h" +#include "opentelemetry/version.h" #include #include @@ -20,65 +20,89 @@ namespace otlp /** * Struct to hold OTLP HTTP traces exporter options. + * + * See + * https://github.com/open-telemetry/opentelemetry-proto/blob/main/docs/specification.md#otlphttp + * + * See + * https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md */ -struct OtlpHttpExporterOptions +struct OPENTELEMETRY_EXPORT OtlpHttpExporterOptions { - // The endpoint to export to. By default - // @see - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md - // @see https://github.com/open-telemetry/opentelemetry-collector/tree/main/receiver/otlpreceiver - std::string url = GetOtlpDefaultHttpEndpoint(); + OtlpHttpExporterOptions(); + ~OtlpHttpExporterOptions(); - // By default, post json data - HttpRequestContentType content_type = HttpRequestContentType::kJson; + /** The endpoint to export to. */ + std::string url; - // If convert bytes into hex. By default, we will convert all bytes but id into base64 - // This option is ignored if content_type is not kJson - JsonBytesMappingKind json_bytes_mapping = JsonBytesMappingKind::kHexId; + /** HTTP content type. */ + HttpRequestContentType content_type; - // If using the json name of protobuf field to set the key of json. By default, we will use the - // field name just like proto files. - bool use_json_name = false; + /** + Json byte mapping. - // Whether to print the status of the exporter in the console - bool console_debug = false; + Used only for HttpRequestContentType::kJson. + Convert bytes to hex / base64. + */ + JsonBytesMappingKind json_bytes_mapping; - std::chrono::system_clock::duration timeout = GetOtlpDefaultTimeout(); + /** + Use json names (true) or protobuf field names (false) to set the json key. + */ + bool use_json_name; - // Additional HTTP headers - OtlpHeaders http_headers = GetOtlpDefaultHeaders(); + /** Print debug messages. */ + bool console_debug; + + /** Export timeout. */ + std::chrono::system_clock::duration timeout; + + /** Additional HTTP headers. */ + OtlpHeaders http_headers; #ifdef ENABLE_ASYNC_EXPORT - // Concurrent requests - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md#otlpgrpc-concurrent-requests - std::size_t max_concurrent_requests = 64; + /** Max number of concurrent requests. */ + std::size_t max_concurrent_requests; - // Requests per connections - std::size_t max_requests_per_connection = 8; + /** Max number of requests per connection. */ + std::size_t max_requests_per_connection; #endif #ifdef ENABLE_OTLP_HTTP_SSL_PREVIEW - bool ssl_insecure_skip_verify{false}; + /** True do disable SSL. */ + bool ssl_insecure_skip_verify; + + /** CA CERT, path to a file. */ + std::string ssl_ca_cert_path; - std::string ssl_ca_cert_path = GetOtlpDefaultTracesSslCertificatePath(); - std::string ssl_ca_cert_string = GetOtlpDefaultTracesSslCertificateString(); + /** CA CERT, as a string. */ + std::string ssl_ca_cert_string; - std::string ssl_client_key_path = GetOtlpDefaultTracesSslClientKeyPath(); - std::string ssl_client_key_string = GetOtlpDefaultTracesSslClientKeyString(); + /** CLIENT KEY, path to a file. */ + std::string ssl_client_key_path; - std::string ssl_client_cert_path = GetOtlpDefaultTracesSslClientCertificatePath(); - std::string ssl_client_cert_string = GetOtlpDefaultTracesSslClientCertificateString(); + /** 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 /* ENABLE_OTLP_HTTP_SSL_PREVIEW */ #ifdef ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW /** Minimum TLS version. */ - std::string ssl_min_tls = GetOtlpDefaultTracesSslTlsMinVersion(); + std::string ssl_min_tls; + /** Maximum TLS version. */ - std::string ssl_max_tls = GetOtlpDefaultTracesSslTlsMaxVersion(); + std::string ssl_max_tls; + /** TLS cipher. */ - std::string ssl_cipher = GetOtlpDefaultTracesSslTlsCipher(); + std::string ssl_cipher; + /** TLS cipher suite. */ - std::string ssl_cipher_suite = GetOtlpDefaultTracesSslTlsCipherSuite(); + std::string ssl_cipher_suite; #endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */ }; 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 65fd2b9b63..e2a6264675 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 @@ -5,7 +5,7 @@ #include "opentelemetry/exporters/otlp/otlp_environment.h" #include "opentelemetry/exporters/otlp/otlp_http.h" -#include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/version.h" #include #include @@ -19,66 +19,90 @@ 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 + * + * See + * https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md */ -struct OtlpHttpLogRecordExporterOptions +struct OPENTELEMETRY_EXPORT OtlpHttpLogRecordExporterOptions { - // The endpoint to export to. By default - // @see - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md - // @see https://github.com/open-telemetry/opentelemetry-collector/tree/main/receiver/otlpreceiver - std::string url = GetOtlpDefaultHttpLogsEndpoint(); + OtlpHttpLogRecordExporterOptions(); + ~OtlpHttpLogRecordExporterOptions(); - // By default, post json data - HttpRequestContentType content_type = HttpRequestContentType::kJson; + /** The endpoint to export to. */ + std::string url; - // If convert bytes into hex. By default, we will convert all bytes but id into base64 - // This option is ignored if content_type is not kJson - JsonBytesMappingKind json_bytes_mapping = JsonBytesMappingKind::kHexId; + /** HTTP content type. */ + HttpRequestContentType content_type; - // If using the json name of protobuf field to set the key of json. By default, we will use the - // field name just like proto files. - bool use_json_name = false; + /** + Json byte mapping. - // Whether to print the status of the exporter in the console - bool console_debug = false; + Used only for HttpRequestContentType::kJson. + Convert bytes to hex / base64. + */ + JsonBytesMappingKind json_bytes_mapping; - std::chrono::system_clock::duration timeout = GetOtlpDefaultLogsTimeout(); + /** + Use json names (true) or protobuf field names (false) to set the json key. + */ + bool use_json_name; - // Additional HTTP headers - OtlpHeaders http_headers = GetOtlpDefaultLogsHeaders(); + /** Print debug messages. */ + bool console_debug; + + /** Export timeout. */ + std::chrono::system_clock::duration timeout; + + /** Additional HTTP headers. */ + OtlpHeaders http_headers; #ifdef ENABLE_ASYNC_EXPORT - // Concurrent requests - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md#otlpgrpc-concurrent-requests - std::size_t max_concurrent_requests = 64; + /** Max number of concurrent requests. */ + std::size_t max_concurrent_requests; - // Requests per connections - std::size_t max_requests_per_connection = 8; + /** Max number of requests per connection. */ + std::size_t max_requests_per_connection; #endif #ifdef ENABLE_OTLP_HTTP_SSL_PREVIEW - bool ssl_insecure_skip_verify{false}; + /** True do disable SSL. */ + bool ssl_insecure_skip_verify; + + /** CA CERT, path to a file. */ + std::string ssl_ca_cert_path; + + /** CA CERT, as a string. */ + std::string ssl_ca_cert_string; - std::string ssl_ca_cert_path = GetOtlpDefaultLogsSslCertificatePath(); - std::string ssl_ca_cert_string = GetOtlpDefaultLogsSslCertificateString(); + /** CLIENT KEY, path to a file. */ + std::string ssl_client_key_path; - std::string ssl_client_key_path = GetOtlpDefaultLogsSslClientKeyPath(); - std::string ssl_client_key_string = GetOtlpDefaultLogsSslClientKeyString(); + /** CLIENT KEY, as a string. */ + std::string ssl_client_key_string; - std::string ssl_client_cert_path = GetOtlpDefaultLogsSslClientCertificatePath(); - std::string ssl_client_cert_string = GetOtlpDefaultLogsSslClientCertificateString(); + /** CLIENT CERT, path to a file. */ + std::string ssl_client_cert_path; + + /** CLIENT CERT, as a string. */ + std::string ssl_client_cert_string; #endif /* ENABLE_OTLP_HTTP_SSL_PREVIEW */ #ifdef ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW /** Minimum TLS version. */ - std::string ssl_min_tls = GetOtlpDefaultLogsSslTlsMinVersion(); + std::string ssl_min_tls; + /** Maximum TLS version. */ - std::string ssl_max_tls = GetOtlpDefaultLogsSslTlsMaxVersion(); + std::string ssl_max_tls; + /** TLS cipher. */ - std::string ssl_cipher = GetOtlpDefaultLogsSslTlsCipher(); + std::string ssl_cipher; + /** TLS cipher suite. */ - std::string ssl_cipher_suite = GetOtlpDefaultLogsSslTlsCipherSuite(); + std::string ssl_cipher_suite; #endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */ }; diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h index 8aa0ccad21..38446be73b 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h @@ -6,6 +6,7 @@ #include "opentelemetry/exporters/otlp/otlp_environment.h" #include "opentelemetry/exporters/otlp/otlp_http.h" #include "opentelemetry/exporters/otlp/otlp_preferred_temporality.h" +#include "opentelemetry/version.h" #include #include @@ -20,70 +21,91 @@ namespace otlp /** * Struct to hold OTLP HTTP metrics exporter options. + * + * See + * https://github.com/open-telemetry/opentelemetry-proto/blob/main/docs/specification.md#otlphttp + * + * See + * https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md */ -struct OtlpHttpMetricExporterOptions +struct OPENTELEMETRY_EXPORT OtlpHttpMetricExporterOptions { - // The endpoint to export to. By default - // @see - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md - // @see https://github.com/open-telemetry/opentelemetry-collector/tree/main/receiver/otlpreceiver - std::string url = GetOtlpDefaultMetricsEndpoint(); + OtlpHttpMetricExporterOptions(); + ~OtlpHttpMetricExporterOptions(); - // By default, post json data - HttpRequestContentType content_type = HttpRequestContentType::kJson; + /** The endpoint to export to. */ + std::string url; - // If convert bytes into hex. By default, we will convert all bytes but id into base64 - // This option is ignored if content_type is not kJson - JsonBytesMappingKind json_bytes_mapping = JsonBytesMappingKind::kHexId; + /** HTTP content type. */ + HttpRequestContentType content_type; - // If using the json name of protobuf field to set the key of json. By default, we will use the - // field name just like proto files. - bool use_json_name = false; + /** + Json byte mapping. - // Whether to print the status of the exporter in the console - bool console_debug = false; + Used only for HttpRequestContentType::kJson. + Convert bytes to hex / base64. + */ + JsonBytesMappingKind json_bytes_mapping; - // TODO: Enable/disable to verify SSL certificate - std::chrono::system_clock::duration timeout = GetOtlpDefaultMetricsTimeout(); + /** + Use json names (true) or protobuf field names (false) to set the json key. + */ + bool use_json_name; - // Additional HTTP headers - OtlpHeaders http_headers = GetOtlpDefaultMetricsHeaders(); + /** Print debug messages. */ + bool console_debug; - // Preferred Aggregation Temporality - PreferredAggregationTemporality aggregation_temporality = - PreferredAggregationTemporality::kCumulative; + /** Export timeout. */ + std::chrono::system_clock::duration timeout; + + /** Additional HTTP headers. */ + OtlpHeaders http_headers; + + PreferredAggregationTemporality aggregation_temporality; #ifdef ENABLE_ASYNC_EXPORT - // Concurrent requests - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md#otlpgrpc-concurrent-requests - std::size_t max_concurrent_requests = 64; + /** Max number of concurrent requests. */ + std::size_t max_concurrent_requests; - // Requests per connections - std::size_t max_requests_per_connection = 8; + /** Max number of requests per connection. */ + std::size_t max_requests_per_connection; #endif #ifdef ENABLE_OTLP_HTTP_SSL_PREVIEW - bool ssl_insecure_skip_verify{false}; + /** True do disable SSL. */ + bool ssl_insecure_skip_verify; + + /** CA CERT, path to a file. */ + std::string ssl_ca_cert_path; + + /** CA CERT, as a string. */ + std::string ssl_ca_cert_string; - std::string ssl_ca_cert_path = GetOtlpDefaultMetricsSslCertificatePath(); - std::string ssl_ca_cert_string = GetOtlpDefaultMetricsSslCertificateString(); + /** CLIENT KEY, path to a file. */ + std::string ssl_client_key_path; - std::string ssl_client_key_path = GetOtlpDefaultMetricsSslClientKeyPath(); - std::string ssl_client_key_string = GetOtlpDefaultMetricsSslClientKeyString(); + /** CLIENT KEY, as a string. */ + std::string ssl_client_key_string; - std::string ssl_client_cert_path = GetOtlpDefaultMetricsSslClientCertificatePath(); - std::string ssl_client_cert_string = GetOtlpDefaultMetricsSslClientCertificateString(); + /** CLIENT CERT, path to a file. */ + std::string ssl_client_cert_path; + + /** CLIENT CERT, as a string. */ + std::string ssl_client_cert_string; #endif /* ENABLE_OTLP_HTTP_SSL_PREVIEW */ #ifdef ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW /** Minimum TLS version. */ - std::string ssl_min_tls = GetOtlpDefaultMetricsSslTlsMinVersion(); + std::string ssl_min_tls; + /** Maximum TLS version. */ - std::string ssl_max_tls = GetOtlpDefaultMetricsSslTlsMaxVersion(); + std::string ssl_max_tls; + /** TLS cipher. */ - std::string ssl_cipher = GetOtlpDefaultMetricsSslTlsCipher(); + std::string ssl_cipher; + /** TLS cipher suite. */ - std::string ssl_cipher_suite = GetOtlpDefaultMetricsSslTlsCipherSuite(); + std::string ssl_cipher_suite; #endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */ }; 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..3099303ac4 --- /dev/null +++ b/exporters/otlp/src/otlp_grpc_exporter_options.cc @@ -0,0 +1,38 @@ +// 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(); +} + +OtlpGrpcExporterOptions::~OtlpGrpcExporterOptions() {} + +} // 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..2b397262b0 100644 --- a/exporters/otlp/src/otlp_grpc_log_record_exporter.cc +++ b/exporters/otlp/src/otlp_grpc_log_record_exporter.cc @@ -30,16 +30,17 @@ 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..7229de569a 100644 --- a/exporters/otlp/src/otlp_grpc_log_record_exporter_factory.cc +++ b/exporters/otlp/src/otlp_grpc_log_record_exporter_factory.cc @@ -4,8 +4,8 @@ // MUST be first (absl) #include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.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" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -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..697ef28f2a --- /dev/null +++ b/exporters/otlp/src/otlp_grpc_log_record_exporter_options.cc @@ -0,0 +1,36 @@ +// 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(); +} + +OtlpGrpcLogRecordExporterOptions::~OtlpGrpcLogRecordExporterOptions() {} + +} // 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..cb99d1cc5a --- /dev/null +++ b/exporters/otlp/src/otlp_grpc_metric_exporter_options.cc @@ -0,0 +1,38 @@ +// 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; +} + +OtlpGrpcMetricExporterOptions::~OtlpGrpcMetricExporterOptions() {} + +} // 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 new file mode 100644 index 0000000000..91121e0c35 --- /dev/null +++ b/exporters/otlp/src/otlp_http_exporter_options.cc @@ -0,0 +1,54 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h" + +#include +#include +#include +#include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +OtlpHttpExporterOptions::OtlpHttpExporterOptions() +{ + url = GetOtlpDefaultHttpTracesEndpoint(); + content_type = HttpRequestContentType::kJson; + json_bytes_mapping = JsonBytesMappingKind::kHexId; + use_json_name = false; + console_debug = false; + timeout = GetOtlpDefaultTracesTimeout(); + http_headers = GetOtlpDefaultTracesHeaders(); + +#ifdef ENABLE_ASYNC_EXPORT + max_concurrent_requests = 64; + max_requests_per_connection = 8; +#endif /* ENABLE_ASYNC_EXPORT */ + +#ifdef ENABLE_OTLP_HTTP_SSL_PREVIEW + ssl_insecure_skip_verify = false; + ssl_ca_cert_path = GetOtlpDefaultTracesSslCertificatePath(); + ssl_ca_cert_string = GetOtlpDefaultTracesSslCertificateString(); + ssl_client_key_path = GetOtlpDefaultTracesSslClientKeyPath(); + ssl_client_key_string = GetOtlpDefaultTracesSslClientKeyString(); + ssl_client_cert_path = GetOtlpDefaultTracesSslClientCertificatePath(); + ssl_client_cert_string = GetOtlpDefaultTracesSslClientCertificateString(); +#endif /* ENABLE_OTLP_HTTP_SSL_PREVIEW */ + +#ifdef ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW + ssl_min_tls = GetOtlpDefaultTracesSslTlsMinVersion(); + ssl_max_tls = GetOtlpDefaultTracesSslTlsMaxVersion(); + ssl_cipher = GetOtlpDefaultTracesSslTlsCipher(); + ssl_cipher_suite = GetOtlpDefaultTracesSslTlsCipherSuite(); +#endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */ +} + +OtlpHttpExporterOptions::~OtlpHttpExporterOptions() {} + +} // 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 new file mode 100644 index 0000000000..bda37b9730 --- /dev/null +++ b/exporters/otlp/src/otlp_http_log_record_exporter_options.cc @@ -0,0 +1,54 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h" + +#include +#include +#include +#include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +OtlpHttpLogRecordExporterOptions::OtlpHttpLogRecordExporterOptions() +{ + url = GetOtlpDefaultHttpLogsEndpoint(); + content_type = HttpRequestContentType::kJson; + json_bytes_mapping = JsonBytesMappingKind::kHexId; + use_json_name = false; + console_debug = false; + timeout = GetOtlpDefaultLogsTimeout(); + http_headers = GetOtlpDefaultLogsHeaders(); + +#ifdef ENABLE_ASYNC_EXPORT + max_concurrent_requests = 64; + max_requests_per_connection = 8; +#endif + +#ifdef ENABLE_OTLP_HTTP_SSL_PREVIEW + ssl_insecure_skip_verify = false; + ssl_ca_cert_path = GetOtlpDefaultLogsSslCertificatePath(); + ssl_ca_cert_string = GetOtlpDefaultLogsSslCertificateString(); + ssl_client_key_path = GetOtlpDefaultLogsSslClientKeyPath(); + ssl_client_key_string = GetOtlpDefaultLogsSslClientKeyString(); + ssl_client_cert_path = GetOtlpDefaultLogsSslClientCertificatePath(); + ssl_client_cert_string = GetOtlpDefaultLogsSslClientCertificateString(); +#endif /* ENABLE_OTLP_HTTP_SSL_PREVIEW */ + +#ifdef ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW + ssl_min_tls = GetOtlpDefaultLogsSslTlsMinVersion(); + ssl_max_tls = GetOtlpDefaultLogsSslTlsMaxVersion(); + ssl_cipher = GetOtlpDefaultLogsSslTlsCipher(); + ssl_cipher_suite = GetOtlpDefaultLogsSslTlsCipherSuite(); +#endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */ +} + +OtlpHttpLogRecordExporterOptions::~OtlpHttpLogRecordExporterOptions() {} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_http_metric_exporter_options.cc b/exporters/otlp/src/otlp_http_metric_exporter_options.cc new file mode 100644 index 0000000000..4dc0f40631 --- /dev/null +++ b/exporters/otlp/src/otlp_http_metric_exporter_options.cc @@ -0,0 +1,55 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h" + +#include +#include +#include +#include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +OtlpHttpMetricExporterOptions::OtlpHttpMetricExporterOptions() +{ + url = GetOtlpDefaultMetricsEndpoint(); + content_type = HttpRequestContentType::kJson; + json_bytes_mapping = JsonBytesMappingKind::kHexId; + use_json_name = false; + console_debug = false; + timeout = GetOtlpDefaultMetricsTimeout(); + http_headers = GetOtlpDefaultMetricsHeaders(); + aggregation_temporality = PreferredAggregationTemporality::kCumulative; + +#ifdef ENABLE_ASYNC_EXPORT + max_concurrent_requests = 64; + max_requests_per_connection = 8; +#endif + +#ifdef ENABLE_OTLP_HTTP_SSL_PREVIEW + ssl_insecure_skip_verify = false; + ssl_ca_cert_path = GetOtlpDefaultMetricsSslCertificatePath(); + ssl_ca_cert_string = GetOtlpDefaultMetricsSslCertificateString(); + ssl_client_key_path = GetOtlpDefaultMetricsSslClientKeyPath(); + ssl_client_key_string = GetOtlpDefaultMetricsSslClientKeyString(); + ssl_client_cert_path = GetOtlpDefaultMetricsSslClientCertificatePath(); + ssl_client_cert_string = GetOtlpDefaultMetricsSslClientCertificateString(); +#endif /* ENABLE_OTLP_HTTP_SSL_PREVIEW */ + +#ifdef ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW + ssl_min_tls = GetOtlpDefaultMetricsSslTlsMinVersion(); + ssl_max_tls = GetOtlpDefaultMetricsSslTlsMaxVersion(); + ssl_cipher = GetOtlpDefaultMetricsSslTlsCipher(); + ssl_cipher_suite = GetOtlpDefaultMetricsSslTlsCipherSuite(); +#endif /* ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW */ +} + +OtlpHttpMetricExporterOptions::~OtlpHttpMetricExporterOptions() {} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE 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..cb1d1849aa 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,8 +3,8 @@ #include -#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" /* Make sure OtlpGrpcLogRecordExporterFactory does not require, @@ -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..6a31639219 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,8 @@ 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_; } diff --git a/exporters/otlp/test/otlp_grpc_metric_exporter_test.cc b/exporters/otlp/test/otlp_grpc_metric_exporter_test.cc new file mode 100644 index 0000000000..dc6dde9d79 --- /dev/null +++ b/exporters/otlp/test/otlp_grpc_metric_exporter_test.cc @@ -0,0 +1,209 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifndef OPENTELEMETRY_STL_VERSION +// Unfortunately as of 04/27/2021 the fix is NOT in the vcpkg snapshot of Google Test. +// Remove above `#ifdef` once the GMock fix for C++20 is in the mainline. +// +// Please refer to this GitHub issue for additional details: +// https://github.com/google/googletest/issues/2914 +// https://github.com/google/googletest/commit/61f010d703b32de9bfb20ab90ece38ab2f25977f +// +// If we compile using Visual Studio 2019 with `c++latest` (C++20) without the GMock fix, +// then the compilation here fails in `gmock-actions.h` from: +// .\tools\vcpkg\installed\x64-windows\include\gmock\gmock-actions.h(819): +// error C2653: 'result_of': is not a class or namespace name +// +// That is because `std::result_of` has been removed in C++20. + +# include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h" + +# include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" + +// Problematic code that pulls in Gmock and breaks with vs2019/c++latest : +# include "opentelemetry/proto/collector/metrics/v1/metrics_service_mock.grpc.pb.h" + +# include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" + +# include "opentelemetry/sdk/trace/simple_processor.h" +# include "opentelemetry/sdk/trace/tracer_provider.h" +# include "opentelemetry/trace/provider.h" + +# include + +# if defined(_MSC_VER) +# include "opentelemetry/sdk/common/env_variables.h" +using opentelemetry::sdk::common::setenv; +using opentelemetry::sdk::common::unsetenv; +# endif + +using namespace testing; + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +class OtlpGrpcMetricExporterTestPeer : public ::testing::Test +{ +public: + std::unique_ptr GetExporter( + std::unique_ptr &stub_interface) + { + return std::unique_ptr( + new OtlpGrpcMetricExporter(std::move(stub_interface))); + } + + // Get the options associated with the given exporter. + const OtlpGrpcMetricExporterOptions &GetOptions(std::unique_ptr &exporter) + { + return exporter->options_; + } +}; + +// Test exporter configuration options +TEST_F(OtlpGrpcMetricExporterTestPeer, ConfigTest) +{ + OtlpGrpcMetricExporterOptions opts; + opts.endpoint = "localhost:45454"; + std::unique_ptr exporter(new OtlpGrpcMetricExporter(opts)); + EXPECT_EQ(GetOptions(exporter).endpoint, "localhost:45454"); +} + +// Test exporter configuration options with use_ssl_credentials +TEST_F(OtlpGrpcMetricExporterTestPeer, ConfigSslCredentialsTest) +{ + std::string cacert_str = "--begin and end fake cert--"; + OtlpGrpcMetricExporterOptions opts; + opts.use_ssl_credentials = true; + opts.ssl_credentials_cacert_as_string = cacert_str; + std::unique_ptr exporter(new OtlpGrpcMetricExporter(opts)); + EXPECT_EQ(GetOptions(exporter).ssl_credentials_cacert_as_string, cacert_str); + EXPECT_EQ(GetOptions(exporter).use_ssl_credentials, true); +} + +# ifndef NO_GETENV +// Test exporter configuration options with use_ssl_credentials +TEST_F(OtlpGrpcMetricExporterTestPeer, ConfigFromEnv) +{ + const std::string cacert_str = "--begin and end fake cert--"; + setenv("OTEL_EXPORTER_OTLP_CERTIFICATE_STRING", cacert_str.c_str(), 1); + setenv("OTEL_EXPORTER_OTLP_SSL_ENABLE", "True", 1); + const std::string endpoint = "https://localhost:9999"; + setenv("OTEL_EXPORTER_OTLP_ENDPOINT", endpoint.c_str(), 1); + setenv("OTEL_EXPORTER_OTLP_TIMEOUT", "20050ms", 1); + setenv("OTEL_EXPORTER_OTLP_HEADERS", "k1=v1,k2=v2", 1); + setenv("OTEL_EXPORTER_OTLP_METRICS_HEADERS", "k1=v3,k1=v4", 1); + + std::unique_ptr exporter(new OtlpGrpcMetricExporter()); + EXPECT_EQ(GetOptions(exporter).ssl_credentials_cacert_as_string, cacert_str); + EXPECT_EQ(GetOptions(exporter).use_ssl_credentials, true); + EXPECT_EQ(GetOptions(exporter).endpoint, endpoint); + EXPECT_EQ(GetOptions(exporter).timeout.count(), + std::chrono::duration_cast( + std::chrono::milliseconds{20050}) + .count()); + EXPECT_EQ(GetOptions(exporter).metadata.size(), 3); + { + // Test k2 + auto range = GetOptions(exporter).metadata.equal_range("k2"); + EXPECT_TRUE(range.first != range.second); + EXPECT_EQ(range.first->second, std::string("v2")); + ++range.first; + EXPECT_TRUE(range.first == range.second); + } + { + // Test k1 + auto range = GetOptions(exporter).metadata.equal_range("k1"); + EXPECT_TRUE(range.first != range.second); + EXPECT_EQ(range.first->second, std::string("v3")); + ++range.first; + EXPECT_EQ(range.first->second, std::string("v4")); + ++range.first; + EXPECT_TRUE(range.first == range.second); + } + + unsetenv("OTEL_EXPORTER_OTLP_ENDPOINT"); + unsetenv("OTEL_EXPORTER_OTLP_CERTIFICATE_STRING"); + unsetenv("OTEL_EXPORTER_OTLP_SSL_ENABLE"); + unsetenv("OTEL_EXPORTER_OTLP_TIMEOUT"); + unsetenv("OTEL_EXPORTER_OTLP_HEADERS"); + unsetenv("OTEL_EXPORTER_OTLP_METRICS_HEADERS"); +} +# endif + +# ifndef NO_GETENV +// Test exporter configuration options with use_ssl_credentials +TEST_F(OtlpGrpcMetricExporterTestPeer, ConfigHttpsSecureFromEnv) +{ + // https takes precedence over insecure + const std::string endpoint = "https://localhost:9999"; + setenv("OTEL_EXPORTER_OTLP_ENDPOINT", endpoint.c_str(), 1); + setenv("OTEL_EXPORTER_OTLP_METRICS_INSECURE", "true", 1); + + std::unique_ptr exporter(new OtlpGrpcMetricExporter()); + EXPECT_EQ(GetOptions(exporter).use_ssl_credentials, true); + EXPECT_EQ(GetOptions(exporter).endpoint, endpoint); + + unsetenv("OTEL_EXPORTER_OTLP_ENDPOINT"); + unsetenv("OTEL_EXPORTER_OTLP_METRICS_INSECURE"); +} +# endif + +# ifndef NO_GETENV +// Test exporter configuration options with use_ssl_credentials +TEST_F(OtlpGrpcMetricExporterTestPeer, ConfigHttpInsecureFromEnv) +{ + // http takes precedence over secure + const std::string endpoint = "http://localhost:9999"; + setenv("OTEL_EXPORTER_OTLP_ENDPOINT", endpoint.c_str(), 1); + setenv("OTEL_EXPORTER_OTLP_METRICS_INSECURE", "false", 1); + + std::unique_ptr exporter(new OtlpGrpcMetricExporter()); + EXPECT_EQ(GetOptions(exporter).use_ssl_credentials, false); + EXPECT_EQ(GetOptions(exporter).endpoint, endpoint); + + unsetenv("OTEL_EXPORTER_OTLP_ENDPOINT"); + unsetenv("OTEL_EXPORTER_OTLP_METRICS_INSECURE"); +} +# endif + +# ifndef NO_GETENV +// Test exporter configuration options with use_ssl_credentials +TEST_F(OtlpGrpcMetricExporterTestPeer, ConfigUnknownSecureFromEnv) +{ + const std::string endpoint = "localhost:9999"; + setenv("OTEL_EXPORTER_OTLP_ENDPOINT", endpoint.c_str(), 1); + setenv("OTEL_EXPORTER_OTLP_METRICS_INSECURE", "false", 1); + + std::unique_ptr exporter(new OtlpGrpcMetricExporter()); + EXPECT_EQ(GetOptions(exporter).use_ssl_credentials, true); + EXPECT_EQ(GetOptions(exporter).endpoint, endpoint); + + unsetenv("OTEL_EXPORTER_OTLP_ENDPOINT"); + unsetenv("OTEL_EXPORTER_OTLP_METRICS_INSECURE"); +} +# endif + +# ifndef NO_GETENV +// Test exporter configuration options with use_ssl_credentials +TEST_F(OtlpGrpcMetricExporterTestPeer, ConfigUnknownInsecureFromEnv) +{ + const std::string endpoint = "localhost:9999"; + setenv("OTEL_EXPORTER_OTLP_ENDPOINT", endpoint.c_str(), 1); + setenv("OTEL_EXPORTER_OTLP_METRICS_INSECURE", "true", 1); + + std::unique_ptr exporter(new OtlpGrpcMetricExporter()); + EXPECT_EQ(GetOptions(exporter).use_ssl_credentials, false); + EXPECT_EQ(GetOptions(exporter).endpoint, endpoint); + + unsetenv("OTEL_EXPORTER_OTLP_ENDPOINT"); + unsetenv("OTEL_EXPORTER_OTLP_METRICS_INSECURE"); +} +# endif + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE +#endif /* OPENTELEMETRY_STL_VERSION */ diff --git a/ext/src/dll/opentelemetry_cpp.src b/ext/src/dll/opentelemetry_cpp.src index 10172dbb3f..195b30640a 100644 --- a/ext/src/dll/opentelemetry_cpp.src +++ b/ext/src/dll/opentelemetry_cpp.src @@ -14,22 +14,6 @@ EXPORTS #endif // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::trace::TracerProviderFactory::Create(class std::unique_ptr >) ?Create@TracerProviderFactory@trace@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VTracerProvider@trace@v1@opentelemetry@@U?$default_delete@VTracerProvider@trace@v1@opentelemetry@@@std@@@std@@V?$unique_ptr@VSpanProcessor@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanProcessor@trace@sdk@v1@opentelemetry@@@std@@@7@@Z -#if defined(WITH_OTLP_GRPC) - // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpGrpcExporterOptions const & __ptr64) -#if defined(_WIN64) - ?Create@OtlpGrpcExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VSpanExporter@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanExporter@trace@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpGrpcExporterOptions@2345@@Z -#else - ?Create@OtlpGrpcExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VSpanExporter@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanExporter@trace@sdk@v1@opentelemetry@@@std@@@std@@ABUOtlpGrpcExporterOptions@2345@@Z -#endif // defined(_WIN64) -#endif // defined(WITH_OTLP_GRPC) -#if defined(WITH_OTLP_HTTP) - // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpHttpExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpHttpExporterOptions const & __ptr64) -#if defined(_WIN64) - ?Create@OtlpHttpExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VSpanExporter@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanExporter@trace@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpHttpExporterOptions@2345@@Z -#else - ?Create@OtlpHttpExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VSpanExporter@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanExporter@trace@sdk@v1@opentelemetry@@@std@@@std@@ABUOtlpHttpExporterOptions@2345@@Z -#endif // defined(_WIN64) -#endif // defined(WITH_OTLP_HTTP) // public: static class std::unique_ptr > __cdecl opentelemetry::v1::sdk::logs::LoggerProviderFactory::Create(class std::unique_ptr > && __ptr64) #if defined(_WIN64) ?Create@LoggerProviderFactory@logs@sdk@v1@opentelemetry@@SA?AV?$unique_ptr@VLoggerProvider@logs@v1@opentelemetry@@U?$default_delete@VLoggerProvider@logs@v1@opentelemetry@@@std@@@std@@$$QEAV?$unique_ptr@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordProcessor@logs@sdk@v1@opentelemetry@@@std@@@7@@Z @@ -82,7 +66,6 @@ EXPORTS ?AddMetricReader@MeterProvider@metrics@sdk@v1@opentelemetry@@QEAAXV?$shared_ptr@VMetricReader@metrics@sdk@v1@opentelemetry@@@std@@@Z // public: void __cdecl opentelemetry::v1::sdk::metrics::MeterProvider::AddView(class std::unique_ptr >,class std::unique_ptr >,class std::unique_ptr >) ?AddView@MeterProvider@metrics@sdk@v1@opentelemetry@@QEAAXV?$unique_ptr@VInstrumentSelector@metrics@sdk@v1@opentelemetry@@U?$default_delete@VInstrumentSelector@metrics@sdk@v1@opentelemetry@@@std@@@std@@V?$unique_ptr@VMeterSelector@metrics@sdk@v1@opentelemetry@@U?$default_delete@VMeterSelector@metrics@sdk@v1@opentelemetry@@@std@@@7@V?$unique_ptr@VView@metrics@sdk@v1@opentelemetry@@U?$default_delete@VView@metrics@sdk@v1@opentelemetry@@@std@@@7@@Z - #if defined(WITH_OTLP_GRPC) || defined(WITH_OTLP_HTTP) ?GetOtlpDefaultTracesTimeout@otlp@exporter@v1@opentelemetry@@YA?AV?$duration@_JU?$ratio@$00$0JIJGIA@@std@@@chrono@std@@XZ ?GetOtlpDefaultTracesHeaders@otlp@exporter@v1@opentelemetry@@YA?AV?$multimap@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@Ucmp_ic@otlp@exporter@v1@opentelemetry@@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@2@@std@@XZ @@ -90,26 +73,63 @@ EXPORTS ?GetOtlpDefaultLogsHeaders@otlp@exporter@v1@opentelemetry@@YA?AV?$multimap@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@Ucmp_ic@otlp@exporter@v1@opentelemetry@@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@2@@std@@XZ ?GetOtlpDefaultMetricsTimeout@otlp@exporter@v1@opentelemetry@@YA?AV?$duration@_JU?$ratio@$00$0JIJGIA@@std@@@chrono@std@@XZ ?GetOtlpDefaultMetricsHeaders@otlp@exporter@v1@opentelemetry@@YA?AV?$multimap@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@Ucmp_ic@otlp@exporter@v1@opentelemetry@@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@2@@std@@XZ + ?GetOtlpDefaultTracesSslCertificatePath@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ + ?GetOtlpDefaultMetricsSslCertificatePath@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ + ?GetOtlpDefaultLogsSslCertificatePath@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ + ?GetOtlpDefaultTracesSslCertificateString@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ + ?GetOtlpDefaultMetricsSslCertificateString@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ + ?GetOtlpDefaultLogsSslCertificateString@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ #endif // defined(WITH_OTLP_GRPC) || defined(WITH_OTLP_HTTP) #if defined(WITH_OTLP_GRPC) - // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcLogRecordExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpGrpcExporterOptions const & __ptr64) - ?Create@OtlpGrpcLogRecordExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VLogRecordExporter@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordExporter@logs@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpGrpcExporterOptions@2345@@Z + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpGrpcExporterOptions const & __ptr64) + ?Create@OtlpGrpcExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VSpanExporter@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanExporter@trace@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpGrpcExporterOptions@2345@@Z // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcMetricExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpGrpcMetricExporterOptions const & __ptr64) ?Create@OtlpGrpcMetricExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VPushMetricExporter@metrics@sdk@v1@opentelemetry@@U?$default_delete@VPushMetricExporter@metrics@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpGrpcMetricExporterOptions@2345@@Z + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcLogRecordExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpGrpcLogRecordExporterOptions const &) + ?Create@OtlpGrpcLogRecordExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VLogRecordExporter@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordExporter@logs@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpGrpcLogRecordExporterOptions@2345@@Z + // public: __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcExporterOptions::OtlpGrpcExporterOptions(void) + ??0OtlpGrpcExporterOptions@otlp@exporter@v1@opentelemetry@@QEAA@XZ + // public: __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcExporterOptions::~OtlpGrpcExporterOptions(void) + ??1OtlpGrpcExporterOptions@otlp@exporter@v1@opentelemetry@@QEAA@XZ + // public: __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcMetricExporterOptions::OtlpGrpcMetricExporterOptions(void) + ??0OtlpGrpcMetricExporterOptions@otlp@exporter@v1@opentelemetry@@QEAA@XZ + // public: __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcMetricExporterOptions::~OtlpGrpcMetricExporterOptions(void) + ??1OtlpGrpcMetricExporterOptions@otlp@exporter@v1@opentelemetry@@QEAA@XZ + // public: __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcLogRecordExporterOptions::OtlpGrpcLogRecordExporterOptions(void) + ??0OtlpGrpcLogRecordExporterOptions@otlp@exporter@v1@opentelemetry@@QEAA@XZ + // public: __cdecl opentelemetry::v1::exporter::otlp::OtlpGrpcLogRecordExporterOptions::~OtlpGrpcLogRecordExporterOptions(void) + ??1OtlpGrpcLogRecordExporterOptions@otlp@exporter@v1@opentelemetry@@QEAA@XZ ?GetOtlpDefaultGrpcTracesEndpoint@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ + ?GetOtlpDefaultGrpcMetricsEndpoint@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ + ?GetOtlpDefaultGrpcLogsEndpoint@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ ?GetOtlpDefaultGrpcTracesIsInsecure@otlp@exporter@v1@opentelemetry@@YA_NXZ - ?GetOtlpDefaultTracesSslCertificatePath@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ - ?GetOtlpDefaultTracesSslCertificateString@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ + ?GetOtlpDefaultGrpcMetricsIsInsecure@otlp@exporter@v1@opentelemetry@@YA_NXZ + ?GetOtlpDefaultGrpcLogsIsInsecure@otlp@exporter@v1@opentelemetry@@YA_NXZ #endif // defined(WITH_OTLP_GRPC) + #if defined(WITH_OTLP_HTTP) + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpHttpExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpHttpExporterOptions const & __ptr64) + ?Create@OtlpHttpExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VSpanExporter@trace@sdk@v1@opentelemetry@@U?$default_delete@VSpanExporter@trace@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpHttpExporterOptions@2345@@Z + // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpHttpMetricExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpHttpMetricExporterOptions const &) + ?Create@OtlpHttpMetricExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VPushMetricExporter@metrics@sdk@v1@opentelemetry@@U?$default_delete@VPushMetricExporter@metrics@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpHttpMetricExporterOptions@2345@@Z // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpHttpLogRecordExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpHttpLogRecordExporterOptions const & __ptr64) ?Create@OtlpHttpLogRecordExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VLogRecordExporter@logs@sdk@v1@opentelemetry@@U?$default_delete@VLogRecordExporter@logs@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpHttpLogRecordExporterOptions@2345@@Z - ?GetOtlpDefaultHttpTracesEndpoint@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ - ?GetOtlpDefaultHttpLogsEndpoint@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ + // public: __cdecl opentelemetry::v1::exporter::otlp::OtlpHttpExporterOptions::OtlpHttpExporterOptions(void) + ??0OtlpHttpExporterOptions@otlp@exporter@v1@opentelemetry@@QEAA@XZ + // public: __cdecl opentelemetry::v1::exporter::otlp::OtlpHttpExporterOptions::~OtlpHttpExporterOptions(void) + ??1OtlpHttpExporterOptions@otlp@exporter@v1@opentelemetry@@QEAA@XZ + // public: __cdecl opentelemetry::v1::exporter::otlp::OtlpHttpMetricExporterOptions::OtlpHttpMetricExporterOptions(void) + ??0OtlpHttpMetricExporterOptions@otlp@exporter@v1@opentelemetry@@QEAA@XZ + // public: __cdecl opentelemetry::v1::exporter::otlp::OtlpHttpMetricExporterOptions::~OtlpHttpMetricExporterOptions(void) + ??1OtlpHttpMetricExporterOptions@otlp@exporter@v1@opentelemetry@@QEAA@XZ + // public: __cdecl opentelemetry::v1::exporter::otlp::OtlpHttpLogRecordExporterOptions::OtlpHttpLogRecordExporterOptions(void) + ??0OtlpHttpLogRecordExporterOptions@otlp@exporter@v1@opentelemetry@@QEAA@XZ + // public: __cdecl opentelemetry::v1::exporter::otlp::OtlpHttpLogRecordExporterOptions::~OtlpHttpLogRecordExporterOptions(void) + ??1OtlpHttpLogRecordExporterOptions@otlp@exporter@v1@opentelemetry@@QEAA@XZ - // public: static class std::unique_ptr > __cdecl opentelemetry::v1::exporter::otlp::OtlpHttpMetricExporterFactory::Create(struct opentelemetry::v1::exporter::otlp::OtlpHttpMetricExporterOptions const &) - ?Create@OtlpHttpMetricExporterFactory@otlp@exporter@v1@opentelemetry@@SA?AV?$unique_ptr@VPushMetricExporter@metrics@sdk@v1@opentelemetry@@U?$default_delete@VPushMetricExporter@metrics@sdk@v1@opentelemetry@@@std@@@std@@AEBUOtlpHttpMetricExporterOptions@2345@@Z + ?GetOtlpDefaultHttpTracesEndpoint@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ ?GetOtlpDefaultHttpMetricsEndpoint@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ + ?GetOtlpDefaultHttpLogsEndpoint@otlp@exporter@v1@opentelemetry@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ #endif // defined(WITH_OTLP_HTTP) // clang-format on