diff --git a/CHANGELOG.md b/CHANGELOG.md index 32a5bbbe20..f1ce1125d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -242,6 +242,7 @@ update the semantic convention in instrumentation library is needed. * [BUILD] Remove `--config Debug` when installing. [#1480](https://github.com/open-telemetry/opentelemetry-cpp/pull/1480) * [EXPORTER] Fix endpoint in otlp grpc exporter [#1474](https://github.com/open-telemetry/opentelemetry-cpp/pull/1474) * [EXAMPLE] Fix memory ownership of InMemorySpanExporter (#1473) [#1471](https://github.com/open-telemetry/opentelemetry-cpp/pull/1471) +<<<<<<< HEAD * [EXPORTER TESTS] Prometheus unit test [#1461](https://github.com/open-telemetry/opentelemetry-cpp/pull/1461) * [DOCS] Update docs to use relative code links. [#1447](https://github.com/open-telemetry/opentelemetry-cpp/pull/1447) * [SDK] Remove reference to deprecated InstrumentationLibrary in OTLP [#1469](https://github.com/open-telemetry/opentelemetry-cpp/pull/1469) @@ -249,6 +250,10 @@ update the semantic convention in instrumentation library is needed. * [METRICS EXPORTER] OTLP gRPC Metrics Exporter [#1454](https://github.com/open-telemetry/opentelemetry-cpp/pull/1454) * [EXPORTER] fix prometheus exporter failure type [#1460](https://github.com/open-telemetry/opentelemetry-cpp/pull/1460) * [SDK] Fix build warnings about missing aggregates. [#1368](https://github.com/open-telemetry/opentelemetry-cpp/pull/1368) +======= +* [EXPORTER] Add metrics OTLP/HTTP exporter [#1487](https://github.com/open-telemetry/opentelemetry-cpp/pull/1487) +* [EXPORTER] OTLP http exporter allow concurrency session ([#1209](https://github.com/open-telemetry/opentelemetry-cpp/pull/1209)) +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) * [EXT] `curl::HttpClient` use `curl_multi_handle` instead of creating a thread for every request and it's able to reuse connections now. ([#1317](https://github.com/open-telemetry/opentelemetry-cpp/pull/1317)) <<<<<<< HEAD diff --git a/cmake/opentelemetry-cpp-config.cmake.in b/cmake/opentelemetry-cpp-config.cmake.in index 5f5878c5a5..3199bd5ff1 100644 --- a/cmake/opentelemetry-cpp-config.cmake.in +++ b/cmake/opentelemetry-cpp-config.cmake.in @@ -61,9 +61,11 @@ # opentelemetry-cpp::otlp_recordable - Imported target of opentelemetry-cpp::otlp_recordable # opentelemetry-cpp::otlp_grpc_exporter - Imported target of opentelemetry-cpp::otlp_grpc_exporter # opentelemetry-cpp::otlp_grpc_log_exporter - Imported target of opentelemetry-cpp::otlp_grpc_log_exporter +# opentelemetry-cpp::otlp_grpc_metrics_exporter - Imported target of opentelemetry-cpp::otlp_grpc_metrics_exporter # opentelemetry-cpp::otlp_http_client - Imported target of opentelemetry-cpp::otlp_http_client # opentelemetry-cpp::otlp_http_exporter - Imported target of opentelemetry-cpp::otlp_http_exporter # opentelemetry-cpp::otlp_http_log_exporter - Imported target of opentelemetry-cpp::otlp_http_log_exporter +# opentelemetry-cpp::otlp_http_metric_exporter - Imported target of opentelemetry-cpp::otlp_http_metric_exporter # opentelemetry-cpp::ostream_log_exporter - Imported target of opentelemetry-cpp::ostream_log_exporter # opentelemetry-cpp::ostream_metrics_exporter - Imported target of opentelemetry-cpp::ostream_metrics_exporter # opentelemetry-cpp::ostream_span_exporter - Imported target of opentelemetry-cpp::ostream_span_exporter @@ -116,6 +118,7 @@ set(_OPENTELEMETRY_CPP_LIBRARIES_TEST_TARGETS otlp_recordable otlp_grpc_client otlp_grpc_exporter +<<<<<<< HEAD otlp_grpc_log_record_exporter otlp_grpc_metrics_exporter otlp_http_client @@ -123,6 +126,15 @@ set(_OPENTELEMETRY_CPP_LIBRARIES_TEST_TARGETS otlp_http_log_record_exporter otlp_http_metric_exporter ostream_log_record_exporter +======= + otlp_grpc_log_exporter + otlp_grpc_metrics_exporter + otlp_http_client + otlp_http_exporter + otlp_http_log_exporter + otlp_http_metric_exporter + ostream_log_exporter +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) ostream_metrics_exporter ostream_span_exporter prometheus_exporter diff --git a/exporters/otlp/BUILD b/exporters/otlp/BUILD index 0e5d6909f6..30479c7452 100644 --- a/exporters/otlp/BUILD +++ b/exporters/otlp/BUILD @@ -254,7 +254,35 @@ cc_library( ) cc_library( +<<<<<<< HEAD name = "otlp_grpc_log_record_exporter", +======= + name = "otlp_http_metric_exporter", + srcs = [ + "src/otlp_http_metric_exporter.cc", + ], + hdrs = [ + "include/opentelemetry/exporters/otlp/otlp_environment.h", + "include/opentelemetry/exporters/otlp/otlp_http_metric_exporter.h", + "include/opentelemetry/exporters/otlp/protobuf_include_prefix.h", + "include/opentelemetry/exporters/otlp/protobuf_include_suffix.h", + ], + strip_include_prefix = "include", + tags = [ + "otlp", + "otlp_http_metric", + ], + deps = [ + ":otlp_http_client", + ":otlp_recordable", + "//sdk/src/metrics", + "@com_github_opentelemetry_proto//:metrics_service_proto_cc", + ], +) + +cc_library( + name = "otlp_grpc_log_exporter", +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) srcs = [ "src/otlp_grpc_log_record_exporter.cc", "src/otlp_grpc_log_record_exporter_factory.cc", @@ -392,6 +420,7 @@ cc_test( ) cc_test( +<<<<<<< HEAD name = "otlp_http_log_record_exporter_factory_test", srcs = ["test/otlp_http_log_record_exporter_factory_test.cc"], tags = [ @@ -403,13 +432,31 @@ cc_test( ":otlp_http_log_record_exporter", "//api", "//test_common/src/http/client/nosend:http_client_nosend", +======= + name = "otlp_http_metric_exporter_test", + srcs = ["test/otlp_http_metric_exporter_test.cc"], + tags = [ + "otlp", + "otlp_http_metric", + "test", + ], + deps = [ + ":otlp_http_metric_exporter", + "//api", + "//ext/src/http/client/nosend:http_client_nosend", +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) "@com_google_googletest//:gtest_main", ], ) cc_test( +<<<<<<< HEAD name = "otlp_grpc_log_record_exporter_test", srcs = ["test/otlp_grpc_log_record_exporter_test.cc"], +======= + name = "otlp_grpc_log_exporter_test", + srcs = ["test/otlp_grpc_log_exporter_test.cc"], +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) tags = [ "otlp", "otlp_grpc_log", diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index 7cecab0eca..6fb7a7f679 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -144,6 +144,7 @@ if(WITH_OTLP_HTTP) list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_http_log) endif() +<<<<<<< HEAD add_library( opentelemetry_exporter_otlp_http_metric src/otlp_http_metric_exporter.cc src/otlp_http_metric_exporter_factory.cc) @@ -158,6 +159,23 @@ if(WITH_OTLP_HTTP) list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_http_metric) +======= + if(NOT WITH_METRICS_PREVIEW) + add_library(opentelemetry_exporter_otlp_http_metric + src/otlp_http_metric_exporter.cc) + + set_target_properties(opentelemetry_exporter_otlp_http_metric + PROPERTIES EXPORT_NAME otlp_http_metric_exporter) + + target_link_libraries( + opentelemetry_exporter_otlp_http_metric + PUBLIC opentelemetry_otlp_recordable + opentelemetry_exporter_otlp_http_client) + + list(APPEND OPENTELEMETRY_OTLP_TARGETS + opentelemetry_exporter_otlp_http_metric) + endif() +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) endif() install( @@ -326,6 +344,7 @@ if(BUILD_TESTING) TEST_LIST otlp_http_log_record_exporter_factory_test) endif() +<<<<<<< HEAD add_executable(otlp_http_metric_exporter_test test/otlp_http_metric_exporter_test.cc) target_link_libraries( @@ -351,5 +370,23 @@ if(BUILD_TESTING) TARGET otlp_http_metric_exporter_factory_test TEST_PREFIX exporter.otlp. TEST_LIST otlp_http_metric_exporter_factory_test) +======= + if(NOT WITH_METRICS_PREVIEW) + add_executable(otlp_http_metric_exporter_test + test/otlp_http_metric_exporter_test.cc) + target_link_libraries( + otlp_http_metric_exporter_test + ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} + ${GMOCK_LIB} + opentelemetry_exporter_otlp_http_metric + opentelemetry_metrics + http_client_nosend) + gtest_add_tests( + TARGET otlp_http_metric_exporter_test + TEST_PREFIX exporter.otlp. + TEST_LIST otlp_http_metric_exporter_test) + endif() +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) endif() endif() # BUILD_TESTING diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_environment.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_environment.h index 27bd378b7c..3f86519dda 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_environment.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_environment.h @@ -273,8 +273,12 @@ inline OtlpHeaders GetOtlpDefaultLogHeaders() return result; } +<<<<<<< HEAD // --- Metrics Environment Variables inline const std::string GetOtlpDefaultMetricsEndpoint() +======= +inline const std::string GetOtlpDefaultHttpMetricEndpoint() +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) { constexpr char kOtlpMetricsEndpointEnv[] = "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT"; constexpr char kOtlpEndpointEnv[] = "OTEL_EXPORTER_OTLP_ENDPOINT"; @@ -292,7 +296,11 @@ inline const std::string GetOtlpDefaultMetricsEndpoint() return endpoint.size() ? endpoint : kOtlpEndpointDefault; } +<<<<<<< HEAD inline const std::chrono::system_clock::duration GetOtlpDefaultMetricsTimeout() +======= +inline const std::chrono::system_clock::duration GetOtlpDefaultMetricTimeout() +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) { constexpr char kOtlpMetricsTimeoutEnv[] = "OTEL_EXPORTER_OTLP_METRICS_TIMEOUT"; constexpr char kOtlpTimeoutEnv[] = "OTEL_EXPORTER_OTLP_TIMEOUT"; @@ -305,7 +313,11 @@ inline const std::chrono::system_clock::duration GetOtlpDefaultMetricsTimeout() return GetOtlpTimeoutFromString(timeout.c_str()); } +<<<<<<< HEAD inline OtlpHeaders GetOtlpDefaultMetricsHeaders() +======= +inline OtlpHeaders GetOtlpDefaultMetricHeaders() +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) { constexpr char kOtlpMetricsHeadersEnv[] = "OTEL_EXPORTER_OTLP_METRICS_HEADERS"; constexpr char kOtlpHeadersEnv[] = "OTEL_EXPORTER_OTLP_HEADERS"; @@ -320,6 +332,7 @@ inline OtlpHeaders GetOtlpDefaultMetricsHeaders() return result; } +<<<<<<< HEAD inline bool GetOtlpDefaultMetricsIsSslEnable() { constexpr char kOtlpMetricsIsSslEnableEnv[] = "OTEL_EXPORTER_OTLP_METRICS_SSL_ENABLE"; @@ -364,6 +377,8 @@ inline const std::string GetOtlpDefaultMetricsSslCertificateString() return ssl_cert.size() ? ssl_cert : ""; } +======= +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_client.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_client.h index d230f64dae..d567802e90 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_client.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_client.h @@ -230,7 +230,11 @@ class OtlpHttpClient // For testing friend class OtlpHttpExporterTestPeer; +<<<<<<< HEAD friend class OtlpHttpLogRecordExporterTestPeer; +======= + friend class OtlpHttpLogExporterTestPeer; +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) friend class OtlpHttpMetricExporterTestPeer; /** 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 4ad5d82005..2c3fe829e0 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 @@ -60,6 +60,62 @@ struct OtlpHttpLogRecordExporterOptions # endif }; +<<<<<<< HEAD:exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h +======= +/** + * The OTLP exporter exports log data in OpenTelemetry Protocol (OTLP) format. + */ +class OtlpHttpLogExporter final : public opentelemetry::sdk::logs::LogExporter +{ +public: + /** + * Create an OtlpHttpLogExporter with default exporter options. + */ + OtlpHttpLogExporter(); + + /** + * Create an OtlpHttpLogExporter with user specified options. + * @param options An object containing the user's configuration options. + */ + OtlpHttpLogExporter(const OtlpHttpLogExporterOptions &options); + + /** + * Creates a recordable that stores the data in a JSON object + */ + std::unique_ptr MakeRecordable() noexcept override; + + /** + * Exports a vector of log records to the Elasticsearch instance. Guaranteed to return after a + * timeout specified from the options passed from the constructor. + * @param records A list of log records to send to Elasticsearch. + */ + opentelemetry::sdk::common::ExportResult Export( + const nostd::span> &records) noexcept + override; + + /** + * Shutdown this exporter. + * @param timeout The maximum time to wait for the shutdown method to return + */ + bool Shutdown( + std::chrono::microseconds timeout = std::chrono::microseconds::max()) noexcept override; + +private: + // Configuration options for the exporter + const OtlpHttpLogExporterOptions options_; + + // Object that stores the HTTP sessions that have been created + std::unique_ptr http_client_; + // For testing + friend class OtlpHttpLogExporterTestPeer; + /** + * Create an OtlpHttpLogExporter using the specified http client. + * Only tests can call this constructor directly. + * @param http_client the http client to be used for exporting + */ + OtlpHttpLogExporter(std::unique_ptr http_client); +}; +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)):exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter.h } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter.h index d09d7f525c..16f712f7bd 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter.h @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once +<<<<<<< HEAD #include "opentelemetry/sdk/metrics/push_metric_exporter.h" @@ -14,16 +15,79 @@ #include #include #include +======= +#ifndef ENABLE_METRICS_PREVIEW + +# include "opentelemetry/sdk/metrics/metric_exporter.h" + +# include "opentelemetry/exporters/otlp/otlp_http_client.h" + +# include "opentelemetry/exporters/otlp/otlp_environment.h" + +# include +# include +# include +# include +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { namespace otlp { +<<<<<<< HEAD /** * The OTLP exporter exports metrics data in OpenTelemetry Protocol (OTLP) format in HTTP. */ class OtlpHttpMetricExporter final : public opentelemetry::sdk::metrics::PushMetricExporter +======= + +/** + * Struct to hold OTLP exporter options. + */ +struct 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 = GetOtlpDefaultHttpMetricEndpoint(); + + // By default, post json data + HttpRequestContentType content_type = HttpRequestContentType::kJson; + + // 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; + + // 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; + + // Whether to print the status of the exporter in the console + bool console_debug = false; + + // TODO: Enable/disable to verify SSL certificate + std::chrono::system_clock::duration timeout = GetOtlpDefaultMetricTimeout(); + + // Additional HTTP headers + OtlpHeaders http_headers = GetOtlpDefaultMetricHeaders(); + +# 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; + + // Requests per connections + std::size_t max_requests_per_connection = 8; +# endif +}; + +/** + * The OTLP exporter exports metrics data in OpenTelemetry Protocol (OTLP) format in HTTP. + */ +class OtlpHttpMetricExporter final : public opentelemetry::sdk::metrics::MetricExporter +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) { public: /** @@ -37,6 +101,7 @@ class OtlpHttpMetricExporter final : public opentelemetry::sdk::metrics::PushMet */ OtlpHttpMetricExporter(const OtlpHttpMetricExporterOptions &options); +<<<<<<< HEAD /** * Get the AggregationTemporality for exporter * @@ -45,6 +110,8 @@ class OtlpHttpMetricExporter final : public opentelemetry::sdk::metrics::PushMet sdk::metrics::AggregationTemporality GetAggregationTemporality( sdk::metrics::InstrumentType instrument_type) const noexcept override; +======= +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) opentelemetry::sdk::common::ExportResult Export( const opentelemetry::sdk::metrics::ResourceMetrics &data) noexcept override; @@ -61,9 +128,12 @@ class OtlpHttpMetricExporter final : public opentelemetry::sdk::metrics::PushMet // Configuration options for the exporter const OtlpHttpMetricExporterOptions options_; +<<<<<<< HEAD // Aggregation Temporality Selector const sdk::metrics::AggregationTemporalitySelector aggregation_temporality_selector_; +======= +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) // Object that stores the HTTP sessions that have been created std::unique_ptr http_client_; // For testing @@ -79,3 +149,7 @@ class OtlpHttpMetricExporter final : public opentelemetry::sdk::metrics::PushMet } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE +<<<<<<< HEAD +======= +#endif +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) diff --git a/exporters/otlp/src/otlp_http_metric_exporter.cc b/exporters/otlp/src/otlp_http_metric_exporter.cc index 1ac89b3238..f38df7b0ed 100644 --- a/exporters/otlp/src/otlp_http_metric_exporter.cc +++ b/exporters/otlp/src/otlp_http_metric_exporter.cc @@ -1,6 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +<<<<<<< HEAD #include "opentelemetry/exporters/otlp/otlp_http_metric_exporter.h" #include "opentelemetry/exporters/otlp/otlp_metric_utils.h" @@ -11,6 +12,20 @@ #include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" #include "opentelemetry/sdk/common/global_log_handler.h" +======= +#ifndef ENABLE_METRICS_PREVIEW + +# include "opentelemetry/exporters/otlp/otlp_http_metric_exporter.h" +# include "opentelemetry/exporters/otlp/otlp_metric_utils.h" + +# include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" + +# include "opentelemetry/proto/collector/metrics/v1/metrics_service.pb.h" + +# include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" + +# include "opentelemetry/sdk/common/global_log_handler.h" +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) namespace nostd = opentelemetry::nostd; @@ -26,8 +41,11 @@ OtlpHttpMetricExporter::OtlpHttpMetricExporter() OtlpHttpMetricExporter::OtlpHttpMetricExporter(const OtlpHttpMetricExporterOptions &options) : options_(options), +<<<<<<< HEAD aggregation_temporality_selector_{ OtlpMetricUtils::ChooseTemporalitySelector(options_.aggregation_temporality)}, +======= +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) http_client_(new OtlpHttpClient(OtlpHttpClientOptions(options.url, options.content_type, options.json_bytes_mapping, @@ -35,19 +53,31 @@ OtlpHttpMetricExporter::OtlpHttpMetricExporter(const OtlpHttpMetricExporterOptio options.console_debug, options.timeout, options.http_headers +<<<<<<< HEAD #ifdef ENABLE_ASYNC_EXPORT , options.max_concurrent_requests, options.max_requests_per_connection #endif +======= +# ifdef ENABLE_ASYNC_EXPORT + , + options.max_concurrent_requests, + options.max_requests_per_connection +# endif +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) ))) {} OtlpHttpMetricExporter::OtlpHttpMetricExporter(std::unique_ptr http_client) +<<<<<<< HEAD : options_(OtlpHttpMetricExporterOptions()), aggregation_temporality_selector_{ OtlpMetricUtils::ChooseTemporalitySelector(options_.aggregation_temporality)}, http_client_(std::move(http_client)) +======= + : options_(OtlpHttpMetricExporterOptions()), http_client_(std::move(http_client)) +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) { OtlpHttpMetricExporterOptions &options = const_cast(options_); options.url = http_client_->GetOptions().url; @@ -57,6 +87,7 @@ OtlpHttpMetricExporter::OtlpHttpMetricExporter(std::unique_ptr h options.console_debug = http_client_->GetOptions().console_debug; options.timeout = http_client_->GetOptions().timeout; options.http_headers = http_client_->GetOptions().http_headers; +<<<<<<< HEAD #ifdef ENABLE_ASYNC_EXPORT options.max_concurrent_requests = http_client_->GetOptions().max_concurrent_requests; options.max_requests_per_connection = http_client_->GetOptions().max_requests_per_connection; @@ -71,25 +102,47 @@ sdk::metrics::AggregationTemporality OtlpHttpMetricExporter::GetAggregationTempo return aggregation_temporality_selector_(instrument_type); } +======= +# ifdef ENABLE_ASYNC_EXPORT + options.max_concurrent_requests = http_client_->GetOptions().max_concurrent_requests; + options.max_requests_per_connection = http_client_->GetOptions().max_requests_per_connection; +# endif +} +// ----------------------------- Exporter methods ------------------------------ + +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) opentelemetry::sdk::common::ExportResult OtlpHttpMetricExporter::Export( const opentelemetry::sdk::metrics::ResourceMetrics &data) noexcept { if (http_client_->IsShutdown()) { +<<<<<<< HEAD std::size_t metric_count = data.scope_metric_data_.size(); +======= + std::size_t metric_count = data.instrumentation_info_metric_data_.size(); +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) OTEL_INTERNAL_LOG_ERROR("[OTLP HTTP Client] ERROR: Export " << metric_count << " metric(s) failed, exporter is shutdown"); return opentelemetry::sdk::common::ExportResult::kFailure; } +<<<<<<< HEAD if (data.scope_metric_data_.empty()) +======= + if (data.instrumentation_info_metric_data_.empty()) +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) { return opentelemetry::sdk::common::ExportResult::kSuccess; } proto::collector::metrics::v1::ExportMetricsServiceRequest service_request; OtlpMetricUtils::PopulateRequest(data, &service_request); +<<<<<<< HEAD std::size_t metric_count = data.scope_metric_data_.size(); #ifdef ENABLE_ASYNC_EXPORT +======= + std::size_t metric_count = data.instrumentation_info_metric_data_.size(); +# ifdef ENABLE_ASYNC_EXPORT +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) http_client_->Export(service_request, [metric_count]( opentelemetry::sdk::common::ExportResult result) { if (result != opentelemetry::sdk::common::ExportResult::kSuccess) @@ -105,7 +158,11 @@ opentelemetry::sdk::common::ExportResult OtlpHttpMetricExporter::Export( return true; }); return opentelemetry::sdk::common::ExportResult::kSuccess; +<<<<<<< HEAD #else +======= +# else +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) opentelemetry::sdk::common::ExportResult result = http_client_->Export(service_request); if (result != opentelemetry::sdk::common::ExportResult::kSuccess) { @@ -118,7 +175,11 @@ opentelemetry::sdk::common::ExportResult OtlpHttpMetricExporter::Export( << " metric(s) success"); } return opentelemetry::sdk::common::ExportResult::kSuccess; +<<<<<<< HEAD #endif +======= +# endif +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) } bool OtlpHttpMetricExporter::ForceFlush(std::chrono::microseconds timeout) noexcept @@ -134,3 +195,8 @@ bool OtlpHttpMetricExporter::Shutdown(std::chrono::microseconds timeout) noexcep } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE +<<<<<<< HEAD +======= + +#endif +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) diff --git a/exporters/otlp/src/otlp_metric_utils.cc b/exporters/otlp/src/otlp_metric_utils.cc index 674a87801c..75654c834f 100644 --- a/exporters/otlp/src/otlp_metric_utils.cc +++ b/exporters/otlp/src/otlp_metric_utils.cc @@ -62,7 +62,11 @@ void OtlpMetricUtils::ConvertSumMetric(const metric_sdk::MetricData &metric_data if ((nostd::holds_alternative(sum_data.value_))) { +<<<<<<< HEAD proto_sum_point_data->set_as_int(nostd::get(sum_data.value_)); +======= + proto_sum_point_data->set_as_int(nostd::get(sum_data.value_)); +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) } else { @@ -96,7 +100,11 @@ void OtlpMetricUtils::ConvertHistogramMetric( // sum if ((nostd::holds_alternative(histogram_data.sum_))) { +<<<<<<< HEAD proto_histogram_point_data->set_sum(nostd::get(histogram_data.sum_)); +======= + proto_histogram_point_data->set_sum(nostd::get(histogram_data.sum_)); +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) } else { @@ -104,10 +112,16 @@ void OtlpMetricUtils::ConvertHistogramMetric( } // count proto_histogram_point_data->set_count(histogram_data.count_); +<<<<<<< HEAD if (histogram_data.record_min_max_) +======= + // buckets + if ((nostd::holds_alternative>(histogram_data.boundaries_))) +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) { if (nostd::holds_alternative(histogram_data.min_)) { +<<<<<<< HEAD proto_histogram_point_data->set_min(nostd::get(histogram_data.min_)); } else @@ -121,13 +135,24 @@ void OtlpMetricUtils::ConvertHistogramMetric( else { proto_histogram_point_data->set_max(nostd::get(histogram_data.max_)); +======= + proto_histogram_point_data->add_explicit_bounds(bound); +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) } } // buckets for (auto bound : histogram_data.boundaries_) { +<<<<<<< HEAD proto_histogram_point_data->add_explicit_bounds(bound); +======= + auto boundaries = nostd::get>(histogram_data.boundaries_); + for (auto bound : boundaries) + { + proto_histogram_point_data->add_explicit_bounds(bound); + } +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) } // bucket counts for (auto bucket_value : histogram_data.counts_) @@ -138,6 +163,39 @@ void OtlpMetricUtils::ConvertHistogramMetric( for (auto &kv_attr : point_data_with_attributes.attributes) { OtlpPopulateAttributeUtils::PopulateAttribute(proto_histogram_point_data->add_attributes(), +<<<<<<< HEAD +======= + kv_attr.first, kv_attr.second); + } + } +} + +void OtlpMetricUtils::ConvertGaugeMetric(const opentelemetry::sdk::metrics::MetricData &metric_data, + proto::metrics::v1::Gauge *const gauge) noexcept +{ + auto start_ts = metric_data.start_ts.time_since_epoch().count(); + auto ts = metric_data.end_ts.time_since_epoch().count(); + for (auto &point_data_with_attributes : metric_data.point_data_attr_) + { + proto::metrics::v1::NumberDataPoint *proto_gauge_point_data = gauge->add_data_points(); + proto_gauge_point_data->set_start_time_unix_nano(start_ts); + proto_gauge_point_data->set_time_unix_nano(ts); + auto gauge_data = + nostd::get(point_data_with_attributes.point_data); + + if ((nostd::holds_alternative(gauge_data.value_))) + { + proto_gauge_point_data->set_as_int(nostd::get(gauge_data.value_)); + } + else + { + proto_gauge_point_data->set_as_double(nostd::get(gauge_data.value_)); + } + // set attributes + for (auto &kv_attr : point_data_with_attributes.attributes) + { + OtlpPopulateAttributeUtils::PopulateAttribute(proto_gauge_point_data->add_attributes(), +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) kv_attr.first, kv_attr.second); } } @@ -205,6 +263,15 @@ void OtlpMetricUtils::PopulateInstrumentationInfoMetric( } default: break; +<<<<<<< HEAD +======= + } + else if (kind == metric_sdk::AggregationType::kLastValue) + { + proto::metrics::v1::Gauge gauge; + ConvertGaugeMetric(metric_data, &gauge); + *metric->mutable_gauge() = gauge; +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) } } @@ -221,14 +288,27 @@ void OtlpMetricUtils::PopulateResourceMetrics( { continue; } +<<<<<<< HEAD auto scope_lib_metrics = resource_metrics->add_scope_metrics(); proto::common::v1::InstrumentationScope *scope = scope_lib_metrics->mutable_scope(); scope->set_name(scope_metrics.scope_->GetName()); scope->set_version(scope_metrics.scope_->GetVersion()); +======= + auto instrumentation_lib_metrics = resource_metrics->add_instrumentation_library_metrics(); + proto::common::v1::InstrumentationLibrary *instrumentation_library = + instrumentation_lib_metrics->mutable_instrumentation_library(); + instrumentation_library->set_name(instrumentation_metrics.instrumentation_library_->GetName()); + instrumentation_library->set_version( + instrumentation_metrics.instrumentation_library_->GetVersion()); +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) for (auto &metric_data : scope_metrics.metric_data_) { +<<<<<<< HEAD PopulateInstrumentInfoMetrics(metric_data, scope_lib_metrics->add_metrics()); +======= + PopulateInstrumentationInfoMetric(metric_data, instrumentation_lib_metrics->add_metrics()); +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) } } } diff --git a/exporters/otlp/test/otlp_http_log_record_exporter_test.cc b/exporters/otlp/test/otlp_http_log_record_exporter_test.cc index 6dc8ef8960..36cfd939b1 100644 --- a/exporters/otlp/test/otlp_http_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_log_record_exporter_test.cc @@ -486,10 +486,16 @@ class OtlpHttpLogRecordExporterTestPeer : public ::testing::Test # endif }; +<<<<<<< HEAD:exporters/otlp/test/otlp_http_log_record_exporter_test.cc TEST(OtlpHttpLogRecordExporterTest, Shutdown) { auto exporter = std::unique_ptr(new OtlpHttpLogRecordExporter()); +======= +TEST(OtlpHttpLogExporterTest, Shutdown) +{ + auto exporter = std::unique_ptr(new OtlpHttpLogExporter()); +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)):exporters/otlp/test/otlp_http_log_exporter_test.cc ASSERT_TRUE(exporter->Shutdown()); nostd::span> logs = {}; diff --git a/exporters/otlp/test/otlp_http_metric_exporter_test.cc b/exporters/otlp/test/otlp_http_metric_exporter_test.cc index 54abb88511..ea5c644843 100644 --- a/exporters/otlp/test/otlp_http_metric_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_metric_exporter_test.cc @@ -1,6 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +<<<<<<< HEAD #include #include #include @@ -34,6 +35,42 @@ using opentelemetry::sdk::common::setenv; using opentelemetry::sdk::common::unsetenv; #endif +======= +#ifndef ENABLE_METRICS_PREVIEW + +# include +# include +# include + +# include "opentelemetry/exporters/otlp/otlp_http_metric_exporter.h" + +# include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" + +# include "opentelemetry/proto/collector/metrics/v1/metrics_service.pb.h" + +# include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" + +# include "opentelemetry/common/key_value_iterable_view.h" +# include "opentelemetry/ext/http/client/http_client_factory.h" +# include "opentelemetry/ext/http/client/nosend/http_client_nosend.h" +# include "opentelemetry/ext/http/server/http_server.h" +# include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" +# include "opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h" +# include "opentelemetry/sdk/metrics/data/metric_data.h" +# include "opentelemetry/sdk/metrics/instruments.h" +# include "opentelemetry/sdk/resource/resource.h" + +# include +# include "gmock/gmock.h" + +# include "nlohmann/json.hpp" + +# if defined(_MSC_VER) +# include "opentelemetry/sdk/common/env_variables.h" +using opentelemetry::sdk::common::setenv; +using opentelemetry::sdk::common::unsetenv; +# endif +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) using namespace testing; @@ -77,10 +114,17 @@ namespace http_client = opentelemetry::ext::http::client; class OtlpHttpMetricExporterTestPeer : public ::testing::Test { public: +<<<<<<< HEAD std::unique_ptr GetExporter( std::unique_ptr http_client) { return std::unique_ptr( +======= + std::unique_ptr GetExporter( + std::unique_ptr http_client) + { + return std::unique_ptr( +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) new OtlpHttpMetricExporter(std::move(http_client))); } @@ -98,17 +142,30 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test } void ExportJsonIntegrationTestExportSumPointData( +<<<<<<< HEAD #ifdef ENABLE_ASYNC_EXPORT bool async_mode #endif +======= +# ifdef ENABLE_ASYNC_EXPORT + bool async_mode +# endif +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) ) { auto mock_otlp_client = OtlpHttpMetricExporterTestPeer::GetMockOtlpHttpClient(HttpRequestContentType::kJson +<<<<<<< HEAD #ifdef ENABLE_ASYNC_EXPORT , async_mode #endif +======= +# ifdef ENABLE_ASYNC_EXPORT + , + async_mode +# endif +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) ); auto mock_otlp_http_client = mock_otlp_client.first; auto client = mock_otlp_client.second; @@ -122,8 +179,14 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test auto resource = opentelemetry::sdk::resource::Resource::Create( opentelemetry::sdk::resource::ResourceAttributes{}); data.resource_ = &resource; +<<<<<<< HEAD auto scope = opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create( "library_name", "1.5.0"); +======= + auto instrumentation_library = + opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary::Create("library_name", + "1.5.0"); +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) opentelemetry::sdk::metrics::MetricData metric_data{ opentelemetry::sdk::metrics::InstrumentDescriptor{ "metrics_library_name", "metrics_description", "metrics_unit", @@ -134,8 +197,15 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test std::vector{ {opentelemetry::sdk::metrics::PointAttributes{{"a1", "b1"}}, sum_point_data}, {opentelemetry::sdk::metrics::PointAttributes{{"a2", "b2"}}, sum_point_data2}}}; +<<<<<<< HEAD data.scope_metric_data_ = std::vector{ {scope.get(), std::vector{metric_data}}}; +======= + data.instrumentation_info_metric_data_ = + std::vector{ + {instrumentation_library.get(), + std::vector{metric_data}}}; +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) auto no_send_client = std::static_pointer_cast(client); auto mock_session = @@ -147,12 +217,25 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); auto resource_metrics = *check_json["resource_metrics"].begin(); +<<<<<<< HEAD auto scope_metrics = *resource_metrics["scope_metrics"].begin(); auto scope = scope_metrics["scope"]; EXPECT_EQ("library_name", scope["name"].get()); EXPECT_EQ("1.5.0", scope["version"].get()); auto metric = *scope_metrics["metrics"].begin(); +======= + // auto scope_metrics = *resource_metrics["scope_metrics"].begin(); + // auto scope = scope_metrics["scope"]; + auto instrumentation_library_metrics = + *resource_metrics["instrumentation_library_metrics"].begin(); + auto scope = instrumentation_library_metrics["instrumentation_library"]; + EXPECT_EQ("library_name", scope["name"].get()); + EXPECT_EQ("1.5.0", scope["version"].get()); + + // auto metric = *scope_metrics["metrics"].begin(); + auto metric = *instrumentation_library_metrics["metrics"].begin(); +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) EXPECT_EQ("metrics_library_name", metric["name"].get()); EXPECT_EQ("metrics_description", metric["description"].get()); EXPECT_EQ("metrics_unit", metric["unit"].get()); @@ -179,22 +262,46 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test } void ExportBinaryIntegrationTestExportSumPointData( +<<<<<<< HEAD #ifdef ENABLE_ASYNC_EXPORT bool async_mode #endif +======= +# ifdef ENABLE_ASYNC_EXPORT + bool async_mode +# endif +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) ) { auto mock_otlp_client = OtlpHttpMetricExporterTestPeer::GetMockOtlpHttpClient(HttpRequestContentType::kBinary +<<<<<<< HEAD #ifdef ENABLE_ASYNC_EXPORT , async_mode #endif +======= +# ifdef ENABLE_ASYNC_EXPORT + , + async_mode +# endif +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) ); auto mock_otlp_http_client = mock_otlp_client.first; auto client = mock_otlp_client.second; auto exporter = GetExporter(std::unique_ptr{mock_otlp_http_client}); +<<<<<<< HEAD +======= + bool attribute_storage_bool_value[] = {true, false, true}; + int32_t attribute_storage_int32_value[] = {1, 2}; + uint32_t attribute_storage_uint32_value[] = {3, 4}; + int64_t attribute_storage_int64_value[] = {5, 6}; + uint64_t attribute_storage_uint64_value[] = {7, 8}; + double attribute_storage_double_value[] = {3.2, 3.3}; + std::string attribute_storage_string_value[] = {"vector", "string"}; + +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) opentelemetry::sdk::metrics::SumPointData sum_point_data{}; sum_point_data.value_ = 10.0; opentelemetry::sdk::metrics::SumPointData sum_point_data2{}; @@ -203,8 +310,14 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test auto resource = opentelemetry::sdk::resource::Resource::Create( opentelemetry::sdk::resource::ResourceAttributes{}); data.resource_ = &resource; +<<<<<<< HEAD auto scope = opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create( "library_name", "1.5.0"); +======= + auto instrumentation_library = + opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary::Create("library_name", + "1.5.0"); +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) opentelemetry::sdk::metrics::MetricData metric_data{ opentelemetry::sdk::metrics::InstrumentDescriptor{ "metrics_library_name", "metrics_description", "metrics_unit", @@ -215,8 +328,15 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test std::vector{ {opentelemetry::sdk::metrics::PointAttributes{{"a1", "b1"}}, sum_point_data}, {opentelemetry::sdk::metrics::PointAttributes{{"a2", "b2"}}, sum_point_data2}}}; +<<<<<<< HEAD data.scope_metric_data_ = std::vector{ {scope.get(), std::vector{metric_data}}}; +======= + data.instrumentation_info_metric_data_ = + std::vector{ + {instrumentation_library.get(), + std::vector{metric_data}}}; +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) auto no_send_client = std::static_pointer_cast(client); auto mock_session = @@ -228,12 +348,25 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test opentelemetry::proto::collector::metrics::v1::ExportMetricsServiceRequest request_body; request_body.ParseFromArray(&mock_session->GetRequest()->body_[0], static_cast(mock_session->GetRequest()->body_.size())); +<<<<<<< HEAD auto &scope_metrics = request_body.resource_metrics(0).scope_metrics(0); auto &scope = scope_metrics.scope(); EXPECT_EQ("library_name", scope.name()); EXPECT_EQ("1.5.0", scope.version()); auto &metric = scope_metrics.metrics(0); +======= + // auto &scope_metrics = request_body.resource_metrics(0).scope_metrics(0); + // auto &scope = instrumentation_library_metrics.scope(); + auto &instrumentation_library_metrics = + request_body.resource_metrics(0).instrumentation_library_metrics(0); + auto &scope = instrumentation_library_metrics.instrumentation_library(); + EXPECT_EQ("library_name", scope.name()); + EXPECT_EQ("1.5.0", scope.version()); + + // auto metric = *scope_metrics["metrics"].begin(); + auto &metric = instrumentation_library_metrics.metrics(0); +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) EXPECT_EQ("metrics_library_name", metric.name()); EXPECT_EQ("metrics_description", metric.description()); EXPECT_EQ("metrics_unit", metric.unit()); @@ -274,17 +407,30 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test } void ExportJsonIntegrationTestExportLastValuePointData( +<<<<<<< HEAD #ifdef ENABLE_ASYNC_EXPORT bool async_mode #endif +======= +# ifdef ENABLE_ASYNC_EXPORT + bool async_mode +# endif +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) ) { auto mock_otlp_client = OtlpHttpMetricExporterTestPeer::GetMockOtlpHttpClient(HttpRequestContentType::kJson +<<<<<<< HEAD #ifdef ENABLE_ASYNC_EXPORT , async_mode #endif +======= +# ifdef ENABLE_ASYNC_EXPORT + , + async_mode +# endif +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) ); auto mock_otlp_http_client = mock_otlp_client.first; auto client = mock_otlp_client.second; @@ -295,7 +441,11 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test last_value_point_data.is_lastvalue_valid_ = true; last_value_point_data.sample_ts_ = opentelemetry::common::SystemTimestamp{}; opentelemetry::sdk::metrics::LastValuePointData last_value_point_data2{}; +<<<<<<< HEAD last_value_point_data2.value_ = (int64_t)20; +======= + last_value_point_data2.value_ = 20l; +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) last_value_point_data2.is_lastvalue_valid_ = true; last_value_point_data2.sample_ts_ = opentelemetry::common::SystemTimestamp{}; opentelemetry::sdk::metrics::MetricData metric_data{ @@ -313,10 +463,20 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test auto resource = opentelemetry::sdk::resource::Resource::Create( opentelemetry::sdk::resource::ResourceAttributes{}); data.resource_ = &resource; +<<<<<<< HEAD auto scope = opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create( "library_name", "1.5.0"); data.scope_metric_data_ = std::vector{ {scope.get(), std::vector{metric_data}}}; +======= + auto instrumentation_library = + opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary::Create("library_name", + "1.5.0"); + data.instrumentation_info_metric_data_ = + std::vector{ + {instrumentation_library.get(), + std::vector{metric_data}}}; +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) auto no_send_client = std::static_pointer_cast(client); auto mock_session = @@ -328,12 +488,25 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); auto resource_metrics = *check_json["resource_metrics"].begin(); +<<<<<<< HEAD auto scope_metrics = *resource_metrics["scope_metrics"].begin(); auto scope = scope_metrics["scope"]; EXPECT_EQ("library_name", scope["name"].get()); EXPECT_EQ("1.5.0", scope["version"].get()); auto metric = *scope_metrics["metrics"].begin(); +======= + // auto scope_metrics = *resource_metrics["scope_metrics"].begin(); + // auto scope = scope_metrics["scope"]; + auto instrumentation_library_metrics = + *resource_metrics["instrumentation_library_metrics"].begin(); + auto scope = instrumentation_library_metrics["instrumentation_library"]; + EXPECT_EQ("library_name", scope["name"].get()); + EXPECT_EQ("1.5.0", scope["version"].get()); + + // auto metric = *scope_metrics["metrics"].begin(); + auto metric = *instrumentation_library_metrics["metrics"].begin(); +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) EXPECT_EQ("metrics_library_name", metric["name"].get()); EXPECT_EQ("metrics_description", metric["description"].get()); EXPECT_EQ("metrics_unit", metric["unit"].get()); @@ -360,22 +533,46 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test } void ExportBinaryIntegrationTestExportLastValuePointData( +<<<<<<< HEAD #ifdef ENABLE_ASYNC_EXPORT bool async_mode #endif +======= +# ifdef ENABLE_ASYNC_EXPORT + bool async_mode +# endif +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) ) { auto mock_otlp_client = OtlpHttpMetricExporterTestPeer::GetMockOtlpHttpClient(HttpRequestContentType::kBinary +<<<<<<< HEAD #ifdef ENABLE_ASYNC_EXPORT , async_mode #endif +======= +# ifdef ENABLE_ASYNC_EXPORT + , + async_mode +# endif +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) ); auto mock_otlp_http_client = mock_otlp_client.first; auto client = mock_otlp_client.second; auto exporter = GetExporter(std::unique_ptr{mock_otlp_http_client}); +<<<<<<< HEAD +======= + bool attribute_storage_bool_value[] = {true, false, true}; + int32_t attribute_storage_int32_value[] = {1, 2}; + uint32_t attribute_storage_uint32_value[] = {3, 4}; + int64_t attribute_storage_int64_value[] = {5, 6}; + uint64_t attribute_storage_uint64_value[] = {7, 8}; + double attribute_storage_double_value[] = {3.2, 3.3}; + std::string attribute_storage_string_value[] = {"vector", "string"}; + +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) opentelemetry::sdk::metrics::SumPointData sum_point_data{}; sum_point_data.value_ = 10.0; opentelemetry::sdk::metrics::SumPointData sum_point_data2{}; @@ -384,14 +581,24 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test auto resource = opentelemetry::sdk::resource::Resource::Create( opentelemetry::sdk::resource::ResourceAttributes{}); data.resource_ = &resource; +<<<<<<< HEAD auto scope = opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create( "library_name", "1.5.0"); +======= + auto instrumentation_library = + opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary::Create("library_name", + "1.5.0"); +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) opentelemetry::sdk::metrics::LastValuePointData last_value_point_data{}; last_value_point_data.value_ = 10.0; last_value_point_data.is_lastvalue_valid_ = true; last_value_point_data.sample_ts_ = opentelemetry::common::SystemTimestamp{}; opentelemetry::sdk::metrics::LastValuePointData last_value_point_data2{}; +<<<<<<< HEAD last_value_point_data2.value_ = (int64_t)20; +======= + last_value_point_data2.value_ = 20l; +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) last_value_point_data2.is_lastvalue_valid_ = true; last_value_point_data2.sample_ts_ = opentelemetry::common::SystemTimestamp{}; opentelemetry::sdk::metrics::MetricData metric_data{ @@ -405,8 +612,15 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test {opentelemetry::sdk::metrics::PointAttributes{{"a1", "b1"}}, last_value_point_data}, {opentelemetry::sdk::metrics::PointAttributes{{"a2", "b2"}}, last_value_point_data2}}}; +<<<<<<< HEAD data.scope_metric_data_ = std::vector{ {scope.get(), std::vector{metric_data}}}; +======= + data.instrumentation_info_metric_data_ = + std::vector{ + {instrumentation_library.get(), + std::vector{metric_data}}}; +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) auto no_send_client = std::static_pointer_cast(client); auto mock_session = @@ -418,12 +632,25 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test opentelemetry::proto::collector::metrics::v1::ExportMetricsServiceRequest request_body; request_body.ParseFromArray(&mock_session->GetRequest()->body_[0], static_cast(mock_session->GetRequest()->body_.size())); +<<<<<<< HEAD auto &scope_metrics = request_body.resource_metrics(0).scope_metrics(0); auto &scope = scope_metrics.scope(); EXPECT_EQ("library_name", scope.name()); EXPECT_EQ("1.5.0", scope.version()); auto &metric = scope_metrics.metrics(0); +======= + // auto &scope_metrics = request_body.resource_metrics(0).scope_metrics(0); + // auto &scope = instrumentation_library_metrics.scope(); + auto &instrumentation_library_metrics = + request_body.resource_metrics(0).instrumentation_library_metrics(0); + auto &scope = instrumentation_library_metrics.instrumentation_library(); + EXPECT_EQ("library_name", scope.name()); + EXPECT_EQ("1.5.0", scope.version()); + + // auto metric = *scope_metrics["metrics"].begin(); + auto &metric = instrumentation_library_metrics.metrics(0); +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) EXPECT_EQ("metrics_library_name", metric.name()); EXPECT_EQ("metrics_description", metric.description()); EXPECT_EQ("metrics_unit", metric.unit()); @@ -464,23 +691,37 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test } void ExportJsonIntegrationTestExportHistogramPointData( +<<<<<<< HEAD #ifdef ENABLE_ASYNC_EXPORT bool async_mode #endif +======= +# ifdef ENABLE_ASYNC_EXPORT + bool async_mode +# endif +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) ) { auto mock_otlp_client = OtlpHttpMetricExporterTestPeer::GetMockOtlpHttpClient(HttpRequestContentType::kJson +<<<<<<< HEAD #ifdef ENABLE_ASYNC_EXPORT , async_mode #endif +======= +# ifdef ENABLE_ASYNC_EXPORT + , + async_mode +# endif +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) ); auto mock_otlp_http_client = mock_otlp_client.first; auto client = mock_otlp_client.second; auto exporter = GetExporter(std::unique_ptr{mock_otlp_http_client}); opentelemetry::sdk::metrics::HistogramPointData histogram_point_data{}; +<<<<<<< HEAD histogram_point_data.boundaries_ = {10.1, 20.2, 30.2}; histogram_point_data.count_ = 3; histogram_point_data.counts_ = {200, 300, 400, 500}; @@ -492,6 +733,17 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test histogram_point_data2.count_ = 3; histogram_point_data2.counts_ = {200, 300, 400, 500}; histogram_point_data2.sum_ = (int64_t)900; +======= + histogram_point_data.boundaries_ = std::list{10.1, 20.2, 30.2}; + histogram_point_data.count_ = 3; + histogram_point_data.counts_ = {200, 300, 400, 500}; + histogram_point_data.sum_ = 900.5; + opentelemetry::sdk::metrics::HistogramPointData histogram_point_data2{}; + histogram_point_data2.boundaries_ = std::list{10, 20, 30}; + histogram_point_data2.count_ = 3; + histogram_point_data2.counts_ = {200, 300, 400, 500}; + histogram_point_data2.sum_ = 900l; +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) opentelemetry::sdk::metrics::MetricData metric_data{ opentelemetry::sdk::metrics::InstrumentDescriptor{ @@ -508,10 +760,20 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test auto resource = opentelemetry::sdk::resource::Resource::Create( opentelemetry::sdk::resource::ResourceAttributes{}); data.resource_ = &resource; +<<<<<<< HEAD auto scope = opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create( "library_name", "1.5.0"); data.scope_metric_data_ = std::vector{ {scope.get(), std::vector{metric_data}}}; +======= + auto instrumentation_library = + opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary::Create("library_name", + "1.5.0"); + data.instrumentation_info_metric_data_ = + std::vector{ + {instrumentation_library.get(), + std::vector{metric_data}}}; +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) auto no_send_client = std::static_pointer_cast(client); auto mock_session = @@ -523,12 +785,25 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test nlohmann::json::parse(mock_session->GetRequest()->body_, nullptr, false); auto resource_metrics = *check_json["resource_metrics"].begin(); +<<<<<<< HEAD auto scope_metrics = *resource_metrics["scope_metrics"].begin(); auto scope = scope_metrics["scope"]; EXPECT_EQ("library_name", scope["name"].get()); EXPECT_EQ("1.5.0", scope["version"].get()); auto metric = *scope_metrics["metrics"].begin(); +======= + // auto scope_metrics = *resource_metrics["scope_metrics"].begin(); + // auto scope = scope_metrics["scope"]; + auto instrumentation_library_metrics = + *resource_metrics["instrumentation_library_metrics"].begin(); + auto scope = instrumentation_library_metrics["instrumentation_library"]; + EXPECT_EQ("library_name", scope["name"].get()); + EXPECT_EQ("1.5.0", scope["version"].get()); + + // auto metric = *scope_metrics["metrics"].begin(); + auto metric = *instrumentation_library_metrics["metrics"].begin(); +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) EXPECT_EQ("metrics_library_name", metric["name"].get()); EXPECT_EQ("metrics_description", metric["description"].get()); EXPECT_EQ("metrics_unit", metric["unit"].get()); @@ -536,8 +811,11 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test auto data_points = metric["histogram"]["data_points"]; EXPECT_EQ(3, JsonToInteger(data_points[0]["count"])); EXPECT_EQ(900.5, data_points[0]["sum"].get()); +<<<<<<< HEAD EXPECT_EQ(1.8, data_points[0]["min"].get()); EXPECT_EQ(19, data_points[0]["max"].get()); +======= +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) EXPECT_EQ(4, data_points[0]["bucket_counts"].size()); if (4 == data_points[0]["bucket_counts"].size()) { @@ -590,22 +868,46 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test } void ExportBinaryIntegrationTestExportHistogramPointData( +<<<<<<< HEAD #ifdef ENABLE_ASYNC_EXPORT bool async_mode #endif +======= +# ifdef ENABLE_ASYNC_EXPORT + bool async_mode +# endif +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) ) { auto mock_otlp_client = OtlpHttpMetricExporterTestPeer::GetMockOtlpHttpClient(HttpRequestContentType::kBinary +<<<<<<< HEAD #ifdef ENABLE_ASYNC_EXPORT , async_mode #endif +======= +# ifdef ENABLE_ASYNC_EXPORT + , + async_mode +# endif +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) ); auto mock_otlp_http_client = mock_otlp_client.first; auto client = mock_otlp_client.second; auto exporter = GetExporter(std::unique_ptr{mock_otlp_http_client}); +<<<<<<< HEAD +======= + bool attribute_storage_bool_value[] = {true, false, true}; + int32_t attribute_storage_int32_value[] = {1, 2}; + uint32_t attribute_storage_uint32_value[] = {3, 4}; + int64_t attribute_storage_int64_value[] = {5, 6}; + uint64_t attribute_storage_uint64_value[] = {7, 8}; + double attribute_storage_double_value[] = {3.2, 3.3}; + std::string attribute_storage_string_value[] = {"vector", "string"}; + +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) opentelemetry::sdk::metrics::SumPointData sum_point_data{}; sum_point_data.value_ = 10.0; opentelemetry::sdk::metrics::SumPointData sum_point_data2{}; @@ -614,19 +916,35 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test auto resource = opentelemetry::sdk::resource::Resource::Create( opentelemetry::sdk::resource::ResourceAttributes{}); data.resource_ = &resource; +<<<<<<< HEAD auto scope = opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create( "library_name", "1.5.0"); opentelemetry::sdk::metrics::HistogramPointData histogram_point_data{}; histogram_point_data.boundaries_ = {10.1, 20.2, 30.2}; +======= + auto instrumentation_library = + opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary::Create("library_name", + "1.5.0"); + + opentelemetry::sdk::metrics::HistogramPointData histogram_point_data{}; + histogram_point_data.boundaries_ = std::list{10.1, 20.2, 30.2}; +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) histogram_point_data.count_ = 3; histogram_point_data.counts_ = {200, 300, 400, 500}; histogram_point_data.sum_ = 900.5; opentelemetry::sdk::metrics::HistogramPointData histogram_point_data2{}; +<<<<<<< HEAD histogram_point_data2.boundaries_ = {10.0, 20.0, 30.0}; histogram_point_data2.count_ = 3; histogram_point_data2.counts_ = {200, 300, 400, 500}; histogram_point_data2.sum_ = (int64_t)900; +======= + histogram_point_data2.boundaries_ = std::list{10, 20, 30}; + histogram_point_data2.count_ = 3; + histogram_point_data2.counts_ = {200, 300, 400, 500}; + histogram_point_data2.sum_ = 900l; +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) opentelemetry::sdk::metrics::MetricData metric_data{ opentelemetry::sdk::metrics::InstrumentDescriptor{ @@ -639,8 +957,15 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test {opentelemetry::sdk::metrics::PointAttributes{{"a1", "b1"}}, histogram_point_data}, {opentelemetry::sdk::metrics::PointAttributes{{"a2", "b2"}}, histogram_point_data2}}}; +<<<<<<< HEAD data.scope_metric_data_ = std::vector{ {scope.get(), std::vector{metric_data}}}; +======= + data.instrumentation_info_metric_data_ = + std::vector{ + {instrumentation_library.get(), + std::vector{metric_data}}}; +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) auto no_send_client = std::static_pointer_cast(client); auto mock_session = @@ -652,12 +977,25 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test opentelemetry::proto::collector::metrics::v1::ExportMetricsServiceRequest request_body; request_body.ParseFromArray(&mock_session->GetRequest()->body_[0], static_cast(mock_session->GetRequest()->body_.size())); +<<<<<<< HEAD auto &scope_metrics = request_body.resource_metrics(0).scope_metrics(0); auto &scope = scope_metrics.scope(); EXPECT_EQ("library_name", scope.name()); EXPECT_EQ("1.5.0", scope.version()); auto &metric = scope_metrics.metrics(0); +======= + // auto &scope_metrics = request_body.resource_metrics(0).scope_metrics(0); + // auto &scope = instrumentation_library_metrics.scope(); + auto &instrumentation_library_metrics = + request_body.resource_metrics(0).instrumentation_library_metrics(0); + auto &scope = instrumentation_library_metrics.instrumentation_library(); + EXPECT_EQ("library_name", scope.name()); + EXPECT_EQ("1.5.0", scope.version()); + + // auto metric = *scope_metrics["metrics"].begin(); + auto &metric = instrumentation_library_metrics.metrics(0); +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) EXPECT_EQ("metrics_library_name", metric.name()); EXPECT_EQ("metrics_description", metric.description()); EXPECT_EQ("metrics_unit", metric.unit()); @@ -733,14 +1071,23 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test TEST(OtlpHttpMetricExporterTest, Shutdown) { +<<<<<<< HEAD auto exporter = std::unique_ptr( new OtlpHttpMetricExporter()); +======= + auto exporter = + std::unique_ptr(new OtlpHttpMetricExporter()); +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) ASSERT_TRUE(exporter->Shutdown()); auto result = exporter->Export(opentelemetry::sdk::metrics::ResourceMetrics{}); EXPECT_EQ(result, opentelemetry::sdk::common::ExportResult::kFailure); } +<<<<<<< HEAD #ifdef ENABLE_ASYNC_EXPORT +======= +# ifdef ENABLE_ASYNC_EXPORT +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) TEST_F(OtlpHttpMetricExporterTestPeer, ExportJsonIntegrationTestSumPointDataAsync) { ExportJsonIntegrationTestExportSumPointData(true); @@ -792,7 +1139,11 @@ TEST_F(OtlpHttpMetricExporterTestPeer, ExportBinaryIntegrationTestHistogramPoint ExportBinaryIntegrationTestExportHistogramPointData(false); } +<<<<<<< HEAD #else +======= +# else +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) TEST_F(OtlpHttpMetricExporterTestPeer, ExportJsonIntegrationTestSumPointData) { ExportJsonIntegrationTestExportSumPointData(); @@ -819,7 +1170,11 @@ TEST_F(OtlpHttpMetricExporterTestPeer, ExportBinaryIntegrationTestHistogramPoint { ExportBinaryIntegrationTestExportHistogramPointData(); } +<<<<<<< HEAD #endif +======= +# endif +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) // Test exporter configuration options TEST_F(OtlpHttpMetricExporterTestPeer, ConfigTest) @@ -846,10 +1201,16 @@ TEST_F(OtlpHttpMetricExporterTestPeer, ConfigJsonBytesMappingTest) opts.json_bytes_mapping = JsonBytesMappingKind::kHex; std::unique_ptr exporter(new OtlpHttpMetricExporter(opts)); EXPECT_EQ(GetOptions(exporter).json_bytes_mapping, JsonBytesMappingKind::kHex); +<<<<<<< HEAD google::protobuf::ShutdownProtobufLibrary(); } #ifndef NO_GETENV +======= +} + +# ifndef NO_GETENV +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) // Test exporter configuration options with use_ssl_credentials TEST_F(OtlpHttpMetricExporterTestPeer, ConfigFromEnv) { @@ -933,6 +1294,7 @@ TEST_F(OtlpHttpMetricExporterTestPeer, ConfigFromMetricsEnv) TEST_F(OtlpHttpMetricExporterTestPeer, DefaultEndpoint) { +<<<<<<< HEAD EXPECT_EQ("http://localhost:4318/v1/metrics", GetOtlpDefaultMetricsEndpoint()); } @@ -959,7 +1321,18 @@ TEST_F(OtlpHttpMetricExporterTestPeer, CheckDefaultTemporality) opentelemetry::sdk::metrics::InstrumentType::kObservableUpDownCounter)); } #endif +======= + EXPECT_EQ("http://localhost:4318/v1/metrics", GetOtlpDefaultHttpMetricEndpoint()); +} + +# endif +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE +<<<<<<< HEAD +======= + +#endif +>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487))