From 0b7d4ab57b8a28f4347bdaf7695364dbde247fac Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Tue, 13 Sep 2022 11:14:47 +0800 Subject: [PATCH 1/3] Add OTLP Metric Exporter Factory and `OtlpGrpcClient` (#1606) --- CHANGELOG.md | 3 + cmake/opentelemetry-cpp-config.cmake.in | 2 + examples/otlp/CMakeLists.txt | 5 +- exporters/otlp/BUILD | 138 +++++++++++++++--- exporters/otlp/CMakeLists.txt | 84 +++++++++-- .../exporters/otlp/otlp_grpc_client.h | 47 ++++++ .../otlp/otlp_grpc_metric_exporter.h | 25 +--- .../otlp/otlp_grpc_metric_exporter_factory.h | 39 +++++ .../otlp/otlp_grpc_metric_exporter_options.h | 2 +- .../otlp/otlp_http_metric_exporter.h | 50 +------ .../otlp/otlp_http_metric_exporter_factory.h | 39 +++++ .../otlp/otlp_http_metric_exporter_options.h | 70 +++++++++ exporters/otlp/src/otlp_grpc_client.cc | 104 +++++++++++++ exporters/otlp/src/otlp_grpc_exporter.cc | 91 ++---------- exporters/otlp/src/otlp_grpc_log_exporter.cc | 97 ++---------- .../otlp/src/otlp_grpc_metric_exporter.cc | 91 +----------- .../src/otlp_grpc_metric_exporter_factory.cc | 36 +++++ .../src/otlp_http_metric_exporter_factory.cc | 34 +++++ .../otlp/test/otlp_grpc_log_exporter_test.cc | 50 ++++--- .../otlp_grpc_metric_exporter_factory_test.cc | 40 +++++ .../otlp/test/otlp_http_log_exporter_test.cc | 56 +++---- .../otlp_http_metric_exporter_factory_test.cc | 48 ++++++ 22 files changed, 737 insertions(+), 414 deletions(-) create mode 100644 exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client.h create mode 100644 exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h create mode 100644 exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h create mode 100644 exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h create mode 100644 exporters/otlp/src/otlp_grpc_client.cc create mode 100644 exporters/otlp/src/otlp_grpc_metric_exporter_factory.cc create mode 100644 exporters/otlp/src/otlp_http_metric_exporter_factory.cc create mode 100644 exporters/otlp/test/otlp_grpc_metric_exporter_factory_test.cc create mode 100644 exporters/otlp/test/otlp_http_metric_exporter_factory_test.cc diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a14e0c0a3..9a0a688e38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,9 @@ Increment the: ## [Unreleased] * [BUILD] Upgrade opentelemetry-proto to v0.19.0 [#1579](https://github.com/open-telemetry/opentelemetry-cpp/pull/1579) +* [METRICS EXPORTER] Add `OtlpGrpcMetricExporterFactory` and `OtlpHttpMetricExporterFactory`. + [#1606](https://github.com/open-telemetry/opentelemetry-cpp/pull/1606) +* [METRICS EXPORTER] Add `OtlpGrpcClient` [#1606](https://github.com/open-telemetry/opentelemetry-cpp/pull/1606) ## [1.6.0] 2022-08-15 diff --git a/cmake/opentelemetry-cpp-config.cmake.in b/cmake/opentelemetry-cpp-config.cmake.in index 0c1d898501..98d997b555 100644 --- a/cmake/opentelemetry-cpp-config.cmake.in +++ b/cmake/opentelemetry-cpp-config.cmake.in @@ -29,6 +29,7 @@ # opentelemetry-cpp::metrics - Imported target of opentelemetry-cpp::metrics # opentelemetry-cpp::logs - Imported target of opentelemetry-cpp::logs # opentelemetry-cpp::in_memory_span_exporter - Imported target of opentelemetry-cpp::in_memory_span_exporter +# opentelemetry-cpp::otlp_grpc_client - Imported target of opentelemetry-cpp::otlp_grpc_client # 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 @@ -85,6 +86,7 @@ set(_OPENTELEMETRY_CPP_LIBRARIES_TEST_TARGETS logs in_memory_span_exporter otlp_recordable + otlp_grpc_client otlp_grpc_exporter otlp_grpc_log_exporter otlp_grpc_metrics_exporter diff --git a/examples/otlp/CMakeLists.txt b/examples/otlp/CMakeLists.txt index 52d9846a0d..3bd02737b1 100644 --- a/examples/otlp/CMakeLists.txt +++ b/examples/otlp/CMakeLists.txt @@ -6,7 +6,7 @@ if(WITH_OTLP_GRPC) add_executable(example_otlp_grpc grpc_main.cc) target_link_libraries( example_otlp_grpc ${CMAKE_THREAD_LIBS_INIT} common_foo_library - opentelemetry_trace opentelemetry_exporter_otlp_grpc gRPC::grpc++) + opentelemetry_trace opentelemetry_exporter_otlp_grpc) if(WITH_LOGS_PREVIEW) add_executable(example_otlp_grpc_log grpc_log_main.cc) target_link_libraries( @@ -16,8 +16,7 @@ if(WITH_OTLP_GRPC) opentelemetry_trace opentelemetry_logs opentelemetry_exporter_otlp_grpc - opentelemetry_exporter_otlp_grpc_log - gRPC::grpc++) + opentelemetry_exporter_otlp_grpc_log) endif() endif() diff --git a/exporters/otlp/BUILD b/exporters/otlp/BUILD index c4270f47ed..b029cbe65b 100644 --- a/exporters/otlp/BUILD +++ b/exporters/otlp/BUILD @@ -46,6 +46,31 @@ cc_library( ], ) +cc_library( + name = "otlp_grpc_client", + srcs = [ + "src/otlp_grpc_client.cc", + ], + 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/protobuf_include_prefix.h", + "include/opentelemetry/exporters/otlp/protobuf_include_suffix.h", + ], + strip_include_prefix = "include", + tags = [ + "otlp", + "otlp_grpc", + ], + deps = [ + "//ext:headers", + "//sdk/src/common:global_log_handler", + "@com_github_grpc_grpc//:grpc++", + "@com_github_opentelemetry_proto//:common_proto_cc", + ], +) + cc_library( name = "otlp_grpc_exporter", srcs = [ @@ -67,12 +92,12 @@ cc_library( ], deps = [ ":otlp_recordable", + ":otlp_grpc_client", "//ext:headers", "//sdk/src/trace", # For gRPC "@com_github_opentelemetry_proto//:trace_service_grpc_cc", - "@com_github_grpc_grpc//:grpc++", ], ) @@ -141,29 +166,33 @@ cc_library( ) cc_library( - name = "otlp_http_log_exporter", + name = "otlp_grpc_metric_exporter", srcs = [ - "src/otlp_http_log_exporter.cc", - "src/otlp_http_log_exporter_factory.cc", + "src/otlp_grpc_metric_exporter.cc", + "src/otlp_grpc_metric_exporter_factory.cc", ], hdrs = [ "include/opentelemetry/exporters/otlp/otlp_environment.h", - "include/opentelemetry/exporters/otlp/otlp_http_log_exporter.h", - "include/opentelemetry/exporters/otlp/otlp_http_log_exporter_factory.h", - "include/opentelemetry/exporters/otlp/otlp_http_log_exporter_options.h", + "include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h", + "include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h", + "include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h", + "include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h", "include/opentelemetry/exporters/otlp/protobuf_include_prefix.h", "include/opentelemetry/exporters/otlp/protobuf_include_suffix.h", ], strip_include_prefix = "include", tags = [ "otlp", - "otlp_http_log", + "otlp_grpc_metric", ], deps = [ - ":otlp_http_client", ":otlp_recordable", - "//sdk/src/logs", - "@com_github_opentelemetry_proto//:logs_service_proto_cc", + ":otlp_grpc_client", + "//ext:headers", + "//sdk/src/metrics", + + # For gRPC + "@com_github_opentelemetry_proto//:metrics_service_grpc_cc", ], ) @@ -171,10 +200,13 @@ cc_library( name = "otlp_http_metric_exporter", srcs = [ "src/otlp_http_metric_exporter.cc", + "src/otlp_http_metric_exporter_factory.cc", ], hdrs = [ "include/opentelemetry/exporters/otlp/otlp_environment.h", "include/opentelemetry/exporters/otlp/otlp_http_metric_exporter.h", + "include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h", + "include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h", "include/opentelemetry/exporters/otlp/protobuf_include_prefix.h", "include/opentelemetry/exporters/otlp/protobuf_include_suffix.h", ], @@ -191,6 +223,33 @@ cc_library( ], ) +cc_library( + name = "otlp_http_log_exporter", + srcs = [ + "src/otlp_http_log_exporter.cc", + "src/otlp_http_log_exporter_factory.cc", + ], + hdrs = [ + "include/opentelemetry/exporters/otlp/otlp_environment.h", + "include/opentelemetry/exporters/otlp/otlp_http_log_exporter.h", + "include/opentelemetry/exporters/otlp/otlp_http_log_exporter_factory.h", + "include/opentelemetry/exporters/otlp/otlp_http_log_exporter_options.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_log", + ], + deps = [ + ":otlp_http_client", + ":otlp_recordable", + "//sdk/src/logs", + "@com_github_opentelemetry_proto//:logs_service_proto_cc", + ], +) + cc_library( name = "otlp_grpc_log_exporter", srcs = [ @@ -212,12 +271,12 @@ cc_library( ], deps = [ ":otlp_recordable", + ":otlp_grpc_client", "//ext:headers", "//sdk/src/logs", "@com_github_opentelemetry_proto//:logs_service_proto_cc", # For gRPC "@com_github_opentelemetry_proto//:logs_service_grpc_cc", - "@com_github_grpc_grpc//:grpc++", ], ) @@ -346,24 +405,24 @@ cc_test( ) cc_test( - name = "otlp_http_metric_exporter_test", - srcs = ["test/otlp_http_metric_exporter_test.cc"], + name = "otlp_grpc_log_exporter_test", + srcs = ["test/otlp_grpc_log_exporter_test.cc"], tags = [ "otlp", - "otlp_http_metric", + "otlp_grpc_log", "test", ], deps = [ - ":otlp_http_metric_exporter", + ":otlp_grpc_log_exporter", "//api", - "//ext/src/http/client/nosend:http_client_nosend", + "//sdk/src/logs", "@com_google_googletest//:gtest_main", ], ) cc_test( - name = "otlp_grpc_log_exporter_test", - srcs = ["test/otlp_grpc_log_exporter_test.cc"], + name = "otlp_grpc_log_exporter_factory_test", + srcs = ["test/otlp_grpc_log_exporter_factory_test.cc"], tags = [ "otlp", "otlp_grpc_log", @@ -378,17 +437,48 @@ cc_test( ) cc_test( - name = "otlp_grpc_log_exporter_factory_test", - srcs = ["test/otlp_grpc_log_exporter_factory_test.cc"], + name = "otlp_grpc_metric_exporter_factory_test", + srcs = ["test/otlp_grpc_metric_exporter_factory_test.cc"], tags = [ "otlp", - "otlp_grpc_log", + "otlp_grpc_metric", "test", ], deps = [ - ":otlp_grpc_log_exporter", + ":otlp_grpc_metric_exporter", "//api", - "//sdk/src/logs", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + 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", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "otlp_http_metric_exporter_factory_test", + srcs = ["test/otlp_http_metric_exporter_factory_test.cc"], + tags = [ + "otlp", + "otlp_http_metric", + "test", + ], + deps = [ + ":otlp_http_metric_exporter", + "//api", + "//ext/src/http/client/nosend:http_client_nosend", "@com_google_googletest//:gtest_main", ], ) diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index c822859ee3..7c158a09ac 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -16,16 +16,50 @@ target_link_libraries( opentelemetry_otlp_recordable PUBLIC opentelemetry_trace opentelemetry_resources opentelemetry_proto) +if(WITH_LOGS_PREVIEW) + target_link_libraries(opentelemetry_otlp_recordable PUBLIC opentelemetry_logs) +endif() +if(NOT WITH_METRICS_PREVIEW) + target_link_libraries(opentelemetry_otlp_recordable + PUBLIC opentelemetry_metrics) +endif() + if(WITH_OTLP_GRPC) find_package(gRPC REQUIRED) + add_library(opentelemetry_exporter_otlp_grpc_client src/otlp_grpc_client.cc) + set_target_properties(opentelemetry_exporter_otlp_grpc_client + PROPERTIES EXPORT_NAME otlp_grpc_client) + target_link_libraries( + opentelemetry_exporter_otlp_grpc_client + PUBLIC opentelemetry_sdk opentelemetry_ext opentelemetry_proto) + + target_link_libraries(opentelemetry_exporter_otlp_grpc_client + PRIVATE gRPC::grpc++) + get_target_property(GRPC_INCLUDE_DIRECTORY gRPC::grpc++ + INTERFACE_INCLUDE_DIRECTORIES) + if(GRPC_INCLUDE_DIRECTORY) + target_include_directories( + opentelemetry_exporter_otlp_grpc_client + PUBLIC "$") + endif() + target_include_directories( + opentelemetry_exporter_otlp_grpc_client + PUBLIC "$" + "$") + + 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) set_target_properties(opentelemetry_exporter_otlp_grpc PROPERTIES EXPORT_NAME otlp_grpc_exporter) - target_link_libraries(opentelemetry_exporter_otlp_grpc - PUBLIC opentelemetry_otlp_recordable gRPC::grpc++) + target_link_libraries( + opentelemetry_exporter_otlp_grpc + PUBLIC opentelemetry_otlp_recordable + opentelemetry_exporter_otlp_grpc_client) list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_grpc) @@ -36,20 +70,25 @@ if(WITH_OTLP_GRPC) set_target_properties(opentelemetry_exporter_otlp_grpc_log PROPERTIES EXPORT_NAME otlp_grpc_log_exporter) - target_link_libraries(opentelemetry_exporter_otlp_grpc_log - PUBLIC opentelemetry_otlp_recordable gRPC::grpc++) + target_link_libraries( + opentelemetry_exporter_otlp_grpc_log + PUBLIC opentelemetry_otlp_recordable + opentelemetry_exporter_otlp_grpc_client) list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_grpc_log) if(NOT WITH_METRICS_PREVIEW) - add_library(opentelemetry_exporter_otlp_grpc_metrics - src/otlp_grpc_metric_exporter.cc) + add_library( + opentelemetry_exporter_otlp_grpc_metrics + src/otlp_grpc_metric_exporter.cc src/otlp_grpc_metric_exporter_factory.cc) set_target_properties(opentelemetry_exporter_otlp_grpc_metrics PROPERTIES EXPORT_NAME otlp_grpc_metrics_exporter) - target_link_libraries(opentelemetry_exporter_otlp_grpc_metrics - PUBLIC opentelemetry_otlp_recordable gRPC::grpc++) + target_link_libraries( + opentelemetry_exporter_otlp_grpc_metrics + PUBLIC opentelemetry_otlp_recordable + opentelemetry_exporter_otlp_grpc_client) list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_grpc_metrics) @@ -107,8 +146,9 @@ if(WITH_OTLP_HTTP) endif() if(NOT WITH_METRICS_PREVIEW) - add_library(opentelemetry_exporter_otlp_http_metric - src/otlp_http_metric_exporter.cc) + add_library( + opentelemetry_exporter_otlp_http_metric + src/otlp_http_metric_exporter.cc src/otlp_http_metric_exporter_factory.cc) set_target_properties(opentelemetry_exporter_otlp_http_metric PROPERTIES EXPORT_NAME otlp_http_metric_exporter) @@ -230,6 +270,19 @@ if(BUILD_TESTING) TEST_PREFIX exporter.otlp. TEST_LIST otlp_grpc_log_exporter_factory_test) endif() + + if(NOT WITH_METRICS_PREVIEW) + add_executable(otlp_grpc_metric_exporter_factory_test + test/otlp_grpc_metric_exporter_factory_test.cc) + target_link_libraries( + otlp_grpc_metric_exporter_factory_test ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIB} + opentelemetry_exporter_otlp_grpc_metrics opentelemetry_metrics) + gtest_add_tests( + TARGET otlp_grpc_metric_exporter_factory_test + TEST_PREFIX exporter.otlp. + TEST_LIST otlp_grpc_metric_exporter_factory_test) + endif() endif() if(WITH_OTLP_HTTP) @@ -295,6 +348,17 @@ if(BUILD_TESTING) TARGET otlp_http_metric_exporter_test TEST_PREFIX exporter.otlp. TEST_LIST otlp_http_metric_exporter_test) + + add_executable(otlp_http_metric_exporter_factory_test + test/otlp_http_metric_exporter_factory_test.cc) + target_link_libraries( + otlp_http_metric_exporter_factory_test ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIB} + opentelemetry_exporter_otlp_http_metric opentelemetry_metrics) + gtest_add_tests( + TARGET otlp_http_metric_exporter_factory_test + TEST_PREFIX exporter.otlp. + TEST_LIST otlp_http_metric_exporter_factory_test) endif() endif() endif() # BUILD_TESTING diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client.h new file mode 100644 index 0000000000..4ac2c4fe01 --- /dev/null +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client.h @@ -0,0 +1,47 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include + +#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +/** + * The OTLP gRPC client contains utility functions of gRPC. + */ +class OtlpGrpcClient +{ +public: + /** + * Create gRPC channel from the exporter options. + */ + static std::shared_ptr MakeChannel(const OtlpGrpcExporterOptions &options); + + /** + * Create gRPC client context to call RPC. + */ + static std::unique_ptr MakeClientContext( + const OtlpGrpcExporterOptions &options); + + /** + * Create service stub to communicate with the OpenTelemetry Collector. + */ + template + static std::unique_ptr MakeServiceStub( + const OtlpGrpcExporterOptions &options) + { + return ServiceType::NewStub(MakeChannel(options)); + } +}; +} // 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 b741df905a..643a0cd3d5 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 @@ -14,6 +14,7 @@ // clang-format on # include "opentelemetry/exporters/otlp/otlp_environment.h" +# include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h" # include "opentelemetry/sdk/metrics/metric_exporter.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -22,30 +23,6 @@ namespace exporter namespace otlp { -/** - * Struct to hold OTLP metrics exporter options. - */ -struct OtlpGrpcMetricExporterOptions -{ - - // The endpoint to export to. By default the OpenTelemetry Collector's default endpoint. - std::string endpoint = GetOtlpDefaultMetricsEndpoint(); - // 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 = GetOtlpDefaultMetricsIsSslEnable(); - // ssl_credentials_cacert_path specifies path to .pem file to be used for SSL encryption. - std::string ssl_credentials_cacert_path = GetOtlpDefaultMetricsSslCertificatePath(); - // 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 = GetOtlpDefaultMetricsSslCertificateString(); - // Timeout for grpc deadline - std::chrono::system_clock::duration timeout = GetOtlpDefaultMetricsTimeout(); - // Additional HTTP headers - OtlpHeaders metadata = GetOtlpDefaultMetricsHeaders(); - opentelemetry::sdk::metrics::AggregationTemporality aggregation_temporality = - opentelemetry::sdk::metrics::AggregationTemporality::kDelta; -}; - /** * The OTLP exporter exports metrics data in OpenTelemetry Protocol (OTLP) format in gRPC. */ diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h new file mode 100644 index 0000000000..5a105ba4c0 --- /dev/null +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h @@ -0,0 +1,39 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#ifndef ENABLE_METRICS_PREVIEW + +# include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h" +# include "opentelemetry/sdk/metrics/metric_exporter.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +/** + * Factory class for OtlpGrpcMetricExporter. + */ +class OtlpGrpcMetricExporterFactory +{ +public: + /** + * Create a OtlpGrpcMetricExporter. + */ + static std::unique_ptr Create(); + + /** + * Create a OtlpGrpcMetricExporter. + */ + static std::unique_ptr Create( + const OtlpGrpcMetricExporterOptions &options); +}; + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE + +#endif /* ENABLE_METRICS_PREVIEW */ 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 00c4412564..1459fe8596 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 @@ -22,7 +22,7 @@ struct OtlpGrpcMetricExporterOptions : public OtlpGrpcExporterOptions // Preferred Aggregation Temporality sdk::metrics::AggregationTemporality aggregation_temporality = - sdk::metrics::AggregationTemporality::kCumulative; + sdk::metrics::AggregationTemporality::kDelta; }; } // namespace otlp 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 4cb2556f53..c037f58168 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 @@ -6,9 +6,9 @@ # include "opentelemetry/sdk/metrics/metric_exporter.h" -# include "opentelemetry/exporters/otlp/otlp_http_client.h" - # include "opentelemetry/exporters/otlp/otlp_environment.h" +# include "opentelemetry/exporters/otlp/otlp_http_client.h" +# include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h" # include "opentelemetry/exporters/otlp/otlp_metric_utils.h" # include @@ -21,52 +21,6 @@ namespace exporter { namespace otlp { - -/** - * 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 = GetOtlpDefaultMetricsEndpoint(); - - // 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 = GetOtlpDefaultMetricsTimeout(); - - // Additional HTTP headers - OtlpHeaders http_headers = GetOtlpDefaultMetricsHeaders(); - - // Preferred Aggregation Temporality - sdk::metrics::AggregationTemporality aggregation_temporality = - sdk::metrics::AggregationTemporality::kDelta; - -# 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. */ diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h new file mode 100644 index 0000000000..913e5097dc --- /dev/null +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h @@ -0,0 +1,39 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#ifndef ENABLE_METRICS_PREVIEW + +# include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h" +# include "opentelemetry/sdk/metrics/metric_exporter.h" + +# include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +/** + * Factory class for OtlpHttpMetricExporter. + */ +class OtlpHttpMetricExporterFactory +{ +public: + /** + * Create a OtlpHttpMetricExporter. + */ + static std::unique_ptr Create(); + + /** + * Create a OtlpHttpMetricExporter. + */ + static std::unique_ptr Create( + const OtlpHttpMetricExporterOptions &options); +}; + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE +#endif 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 new file mode 100644 index 0000000000..bb8d9c956c --- /dev/null +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h @@ -0,0 +1,70 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#ifndef ENABLE_METRICS_PREVIEW + +# include "opentelemetry/exporters/otlp/otlp_environment.h" +# include "opentelemetry/exporters/otlp/otlp_http.h" +# include "opentelemetry/sdk/metrics/instruments.h" + +# include +# include +# include +# include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +/** + * 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 = GetOtlpDefaultMetricsEndpoint(); + + // 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 = GetOtlpDefaultMetricsTimeout(); + + // Additional HTTP headers + OtlpHeaders http_headers = GetOtlpDefaultMetricsHeaders(); + + // Preferred Aggregation Temporality + sdk::metrics::AggregationTemporality aggregation_temporality = + sdk::metrics::AggregationTemporality::kDelta; + +# 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 +}; + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/exporters/otlp/src/otlp_grpc_client.cc b/exporters/otlp/src/otlp_grpc_client.cc new file mode 100644 index 0000000000..ede5ca892d --- /dev/null +++ b/exporters/otlp/src/otlp_grpc_client.cc @@ -0,0 +1,104 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/otlp/otlp_grpc_client.h" + +#if defined(HAVE_GSL) +# include +#else +# include +#endif + +#include +#include +#include +#include + +#include "opentelemetry/ext/http/common/url_parser.h" +#include "opentelemetry/sdk/common/global_log_handler.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +namespace +{ +// ----------------------------- Helper functions ------------------------------ +static std::string GetFileContents(const char *fpath) +{ + std::ifstream finstream(fpath); + std::string contents; + contents.assign((std::istreambuf_iterator(finstream)), std::istreambuf_iterator()); + finstream.close(); + return contents; +} +} // namespace + +std::shared_ptr OtlpGrpcClient::MakeChannel(const OtlpGrpcExporterOptions &options) +{ + std::shared_ptr channel; + + // + // Scheme is allowed in OTLP endpoint definition, but is not allowed for creating gRPC channel. + // Passing URI with scheme to grpc::CreateChannel could resolve the endpoint to some unexpected + // address. + // + + ext::http::common::UrlParser url(options.endpoint); + if (!url.success_) + { + OTEL_INTERNAL_LOG_ERROR("[OTLP GRPC Client] invalid endpoint: " << options.endpoint); + + return nullptr; + } + + std::string grpc_target = url.host_ + ":" + std::to_string(static_cast(url.port_)); + + if (options.use_ssl_credentials) + { + grpc::SslCredentialsOptions ssl_opts; + if (options.ssl_credentials_cacert_path.empty()) + { + ssl_opts.pem_root_certs = options.ssl_credentials_cacert_as_string; + } + else + { + ssl_opts.pem_root_certs = GetFileContents((options.ssl_credentials_cacert_path).c_str()); + } + channel = grpc::CreateChannel(grpc_target, grpc::SslCredentials(ssl_opts)); + } + else + { + channel = grpc::CreateChannel(grpc_target, grpc::InsecureChannelCredentials()); + } + + return channel; +} + +std::unique_ptr OtlpGrpcClient::MakeClientContext( + const OtlpGrpcExporterOptions &options) +{ + std::unique_ptr context{new grpc::ClientContext()}; + if (!context) + { + return context; + } + + if (options.timeout.count() > 0) + { + context->set_deadline(std::chrono::system_clock::now() + options.timeout); + } + + for (auto &header : options.metadata) + { + context->AddMetadata(header.first, header.second); + } + + return context; +} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_grpc_exporter.cc b/exporters/otlp/src/otlp_grpc_exporter.cc index 32f4a60a52..3693732bf7 100644 --- a/exporters/otlp/src/otlp_grpc_exporter.cc +++ b/exporters/otlp/src/otlp_grpc_exporter.cc @@ -1,92 +1,31 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include "opentelemetry/exporters/otlp/otlp_grpc_exporter.h" +#include #include + +#include "opentelemetry/exporters/otlp/otlp_grpc_exporter.h" + +#include "opentelemetry/exporters/otlp/otlp_grpc_client.h" #include "opentelemetry/exporters/otlp/otlp_recordable.h" #include "opentelemetry/exporters/otlp/otlp_recordable_utils.h" -#include "opentelemetry/ext/http/common/url_parser.h" #include "opentelemetry/sdk_config.h" #include -#include -#include // std::stringstream OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { namespace otlp { - -// ----------------------------- Helper functions ------------------------------ -static std::string get_file_contents(const char *fpath) -{ - std::ifstream finstream(fpath); - std::string contents; - contents.assign((std::istreambuf_iterator(finstream)), std::istreambuf_iterator()); - finstream.close(); - return contents; -} - -/** - * Create gRPC channel from the exporter options. - */ -std::shared_ptr MakeGrpcChannel(const OtlpGrpcExporterOptions &options) -{ - std::shared_ptr channel; - - // - // Scheme is allowed in OTLP endpoint definition, but is not allowed for creating gRPC channel. - // Passing URI with scheme to grpc::CreateChannel could resolve the endpoint to some unexpected - // address. - // - - ext::http::common::UrlParser url(options.endpoint); - if (!url.success_) - { - OTEL_INTERNAL_LOG_ERROR("[OTLP Exporter] invalid endpoint: " << options.endpoint); - - return nullptr; - } - - std::string grpc_target = url.host_ + ":" + std::to_string(static_cast(url.port_)); - - if (options.use_ssl_credentials) - { - grpc::SslCredentialsOptions ssl_opts; - if (options.ssl_credentials_cacert_path.empty()) - { - ssl_opts.pem_root_certs = options.ssl_credentials_cacert_as_string; - } - else - { - ssl_opts.pem_root_certs = get_file_contents((options.ssl_credentials_cacert_path).c_str()); - } - channel = grpc::CreateChannel(grpc_target, grpc::SslCredentials(ssl_opts)); - } - else - { - channel = grpc::CreateChannel(grpc_target, grpc::InsecureChannelCredentials()); - } - - return channel; -} - -/** - * Create service stub to communicate with the OpenTelemetry Collector. - */ -std::unique_ptr MakeTraceServiceStub( - const OtlpGrpcExporterOptions &options) -{ - return proto::collector::trace::v1::TraceService::NewStub(MakeGrpcChannel(options)); -} - // -------------------------------- Constructors -------------------------------- OtlpGrpcExporter::OtlpGrpcExporter() : OtlpGrpcExporter(OtlpGrpcExporterOptions()) {} OtlpGrpcExporter::OtlpGrpcExporter(const OtlpGrpcExporterOptions &options) - : options_(options), trace_service_stub_(MakeTraceServiceStub(options)) + : options_(options), + trace_service_stub_( + OtlpGrpcClient::MakeServiceStub(options)) {} OtlpGrpcExporter::OtlpGrpcExporter( @@ -118,20 +57,10 @@ sdk::common::ExportResult OtlpGrpcExporter::Export( proto::collector::trace::v1::ExportTraceServiceRequest request; OtlpRecordableUtils::PopulateRequest(spans, &request); - grpc::ClientContext context; + auto context = OtlpGrpcClient::MakeClientContext(options_); proto::collector::trace::v1::ExportTraceServiceResponse response; - if (options_.timeout.count() > 0) - { - context.set_deadline(std::chrono::system_clock::now() + options_.timeout); - } - - for (auto &header : options_.metadata) - { - context.AddMetadata(header.first, header.second); - } - - grpc::Status status = trace_service_stub_->Export(&context, request, &response); + grpc::Status status = trace_service_stub_->Export(context.get(), request, &response); if (!status.ok()) { diff --git a/exporters/otlp/src/otlp_grpc_log_exporter.cc b/exporters/otlp/src/otlp_grpc_log_exporter.cc index 38bfb0a5bb..8985485642 100644 --- a/exporters/otlp/src/otlp_grpc_log_exporter.cc +++ b/exporters/otlp/src/otlp_grpc_log_exporter.cc @@ -3,6 +3,10 @@ #ifdef ENABLE_LOGS_PREVIEW +# include +# include + +# include "opentelemetry/exporters/otlp/otlp_grpc_client.h" # include "opentelemetry/exporters/otlp/otlp_grpc_log_exporter.h" # include "opentelemetry/exporters/otlp/otlp_log_recordable.h" # include "opentelemetry/exporters/otlp/otlp_recordable_utils.h" @@ -18,95 +22,21 @@ // clang-format on -# include "opentelemetry/ext/http/common/url_parser.h" # include "opentelemetry/sdk/common/global_log_handler.h" -# include -# include -# include - -# include - OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { namespace otlp { - -// ----------------------------- Helper functions ------------------------------ -// TODO: move exporters shared function to OTLP common library. -static std::string get_file_contents(const char *fpath) -{ - std::ifstream finstream(fpath); - std::string contents; - contents.assign((std::istreambuf_iterator(finstream)), std::istreambuf_iterator()); - finstream.close(); - return contents; -} - -struct OtlpGrpcExporterOptions; - -/** - * Create gRPC channel from the exporter options. - */ -static std::shared_ptr MakeGrpcChannel(const OtlpGrpcExporterOptions &options) -{ - std::shared_ptr channel; - - // - // Scheme is allowed in OTLP endpoint definition, but is not allowed for creating gRPC channel. - // Passing URI with scheme to grpc::CreateChannel could resolve the endpoint to some unexpected - // address. - // - - ext::http::common::UrlParser url(options.endpoint); - if (!url.success_) - { - OTEL_INTERNAL_LOG_ERROR("[OTLP Exporter] invalid endpoint: " << options.endpoint); - - return nullptr; - } - - std::string grpc_target = url.host_ + ":" + std::to_string(static_cast(url.port_)); - - if (options.use_ssl_credentials) - { - grpc::SslCredentialsOptions ssl_opts; - if (options.ssl_credentials_cacert_path.empty()) - { - ssl_opts.pem_root_certs = options.ssl_credentials_cacert_as_string; - } - else - { - ssl_opts.pem_root_certs = get_file_contents((options.ssl_credentials_cacert_path).c_str()); - } - channel = grpc::CreateChannel(grpc_target, grpc::SslCredentials(ssl_opts)); - } - else - { - channel = grpc::CreateChannel(grpc_target, grpc::InsecureChannelCredentials()); - } - - return channel; -} - -// ----------------------------- Helper functions ------------------------------ - -/** - * Create log service stub to communicate with the OpenTelemetry Collector. - */ -std::unique_ptr<::opentelemetry::proto::collector::logs::v1::LogsService::Stub> MakeLogServiceStub( - const OtlpGrpcExporterOptions &options) -{ - return proto::collector::logs::v1::LogsService::NewStub(MakeGrpcChannel(options)); -} - // -------------------------------- Constructors -------------------------------- OtlpGrpcLogExporter::OtlpGrpcLogExporter() : OtlpGrpcLogExporter(OtlpGrpcExporterOptions()) {} OtlpGrpcLogExporter::OtlpGrpcLogExporter(const OtlpGrpcExporterOptions &options) - : options_(options), log_service_stub_(MakeLogServiceStub(options)) + : options_(options), + log_service_stub_( + OtlpGrpcClient::MakeServiceStub(options)) {} OtlpGrpcLogExporter::OtlpGrpcLogExporter( @@ -139,19 +69,10 @@ opentelemetry::sdk::common::ExportResult OtlpGrpcLogExporter::Export( proto::collector::logs::v1::ExportLogsServiceRequest request; OtlpRecordableUtils::PopulateRequest(logs, &request); - grpc::ClientContext context; + auto context = OtlpGrpcClient::MakeClientContext(options_); proto::collector::logs::v1::ExportLogsServiceResponse response; - if (options_.timeout.count() > 0) - { - context.set_deadline(std::chrono::system_clock::now() + options_.timeout); - } - - for (auto &header : options_.metadata) - { - context.AddMetadata(header.first, header.second); - } - grpc::Status status = log_service_stub_->Export(&context, request, &response); + grpc::Status status = log_service_stub_->Export(context.get(), request, &response); if (!status.ok()) { diff --git a/exporters/otlp/src/otlp_grpc_metric_exporter.cc b/exporters/otlp/src/otlp_grpc_metric_exporter.cc index 19b60f5637..409c969fed 100644 --- a/exporters/otlp/src/otlp_grpc_metric_exporter.cc +++ b/exporters/otlp/src/otlp_grpc_metric_exporter.cc @@ -3,86 +3,20 @@ #ifndef ENABLE_METRICS_PREVIEW +# include +# include + +# include "opentelemetry/exporters/otlp/otlp_grpc_client.h" # include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h" # include "opentelemetry/exporters/otlp/otlp_metric_utils.h" -# include -# include "opentelemetry/ext/http/common/url_parser.h" # include "opentelemetry/sdk_config.h" -# include -# include -# include // std::stringstream - OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { namespace otlp { - -// ----------------------------- Helper functions ------------------------------ -static std::string get_file_contents(const char *fpath) -{ - std::ifstream finstream(fpath); - std::string contents; - contents.assign((std::istreambuf_iterator(finstream)), std::istreambuf_iterator()); - finstream.close(); - return contents; -} - -/** - * Create gRPC channel from the exporter options. - */ -static std::shared_ptr MakeGrpcChannel(const OtlpGrpcMetricExporterOptions &options) -{ - std::shared_ptr channel; - - // - // Scheme is allowed in OTLP endpoint definition, but is not allowed for creating gRPC channel. - // Passing URI with scheme to grpc::CreateChannel could resolve the endpoint to some unexpected - // address. - // - - ext::http::common::UrlParser url(options.endpoint); - if (!url.success_) - { - OTEL_INTERNAL_LOG_ERROR("[OTLP Exporter] invalid endpoint: " << options.endpoint); - - return nullptr; - } - - std::string grpc_target = url.host_ + ":" + std::to_string(static_cast(url.port_)); - - if (options.use_ssl_credentials) - { - grpc::SslCredentialsOptions ssl_opts; - if (options.ssl_credentials_cacert_path.empty()) - { - ssl_opts.pem_root_certs = options.ssl_credentials_cacert_as_string; - } - else - { - ssl_opts.pem_root_certs = get_file_contents((options.ssl_credentials_cacert_path).c_str()); - } - channel = grpc::CreateChannel(grpc_target, grpc::SslCredentials(ssl_opts)); - } - else - { - channel = grpc::CreateChannel(grpc_target, grpc::InsecureChannelCredentials()); - } - - return channel; -} - -/** - * Create metrics service stub to communicate with the OpenTelemetry Collector. - */ -std::unique_ptr<::opentelemetry::proto::collector::metrics::v1::MetricsService::Stub> -MakeMetricsServiceStub(const OtlpGrpcMetricExporterOptions &options) -{ - return proto::collector::metrics::v1::MetricsService::NewStub(MakeGrpcChannel(options)); -} - // -------------------------------- Constructors -------------------------------- OtlpGrpcMetricExporter::OtlpGrpcMetricExporter() @@ -93,7 +27,8 @@ OtlpGrpcMetricExporter::OtlpGrpcMetricExporter(const OtlpGrpcMetricExporterOptio : options_(options), aggregation_temporality_selector_{ OtlpMetricUtils::ChooseTemporalitySelector(options_.aggregation_temporality)}, - metrics_service_stub_(MakeMetricsServiceStub(options)) + metrics_service_stub_( + OtlpGrpcClient::MakeServiceStub(options)) {} OtlpGrpcMetricExporter::OtlpGrpcMetricExporter( @@ -131,20 +66,10 @@ opentelemetry::sdk::common::ExportResult OtlpGrpcMetricExporter::Export( proto::collector::metrics::v1::ExportMetricsServiceRequest request; OtlpMetricUtils::PopulateRequest(data, &request); - grpc::ClientContext context; + auto context = OtlpGrpcClient::MakeClientContext(options_); proto::collector::metrics::v1::ExportMetricsServiceResponse response; - if (options_.timeout.count() > 0) - { - context.set_deadline(std::chrono::system_clock::now() + options_.timeout); - } - - for (auto &header : options_.metadata) - { - context.AddMetadata(header.first, header.second); - } - - grpc::Status status = metrics_service_stub_->Export(&context, request, &response); + grpc::Status status = metrics_service_stub_->Export(context.get(), request, &response); if (!status.ok()) { diff --git a/exporters/otlp/src/otlp_grpc_metric_exporter_factory.cc b/exporters/otlp/src/otlp_grpc_metric_exporter_factory.cc new file mode 100644 index 0000000000..9060d705b9 --- /dev/null +++ b/exporters/otlp/src/otlp_grpc_metric_exporter_factory.cc @@ -0,0 +1,36 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifndef ENABLE_METRICS_PREVIEW + +// MUST be first (absl) +# 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" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +std::unique_ptr OtlpGrpcMetricExporterFactory::Create() +{ + OtlpGrpcMetricExporterOptions options; + return Create(options); +} + +std::unique_ptr OtlpGrpcMetricExporterFactory::Create( + const OtlpGrpcMetricExporterOptions &options) +{ + std::unique_ptr exporter( + new OtlpGrpcMetricExporter(options)); + return exporter; +} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE + +#endif diff --git a/exporters/otlp/src/otlp_http_metric_exporter_factory.cc b/exporters/otlp/src/otlp_http_metric_exporter_factory.cc new file mode 100644 index 0000000000..e5c194777f --- /dev/null +++ b/exporters/otlp/src/otlp_http_metric_exporter_factory.cc @@ -0,0 +1,34 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifndef ENABLE_METRICS_PREVIEW + +# include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h" +# include "opentelemetry/exporters/otlp/otlp_http_metric_exporter.h" +# include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +std::unique_ptr OtlpHttpMetricExporterFactory::Create() +{ + OtlpHttpMetricExporterOptions options; + return Create(options); +} + +std::unique_ptr OtlpHttpMetricExporterFactory::Create( + const OtlpHttpMetricExporterOptions &options) +{ + std::unique_ptr exporter( + new OtlpHttpMetricExporter(options)); + return exporter; +} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE + +#endif diff --git a/exporters/otlp/test/otlp_grpc_log_exporter_test.cc b/exporters/otlp/test/otlp_grpc_log_exporter_test.cc index b60aac61a4..e7574fb5ba 100644 --- a/exporters/otlp/test/otlp_grpc_log_exporter_test.cc +++ b/exporters/otlp/test/otlp_grpc_log_exporter_test.cc @@ -3,6 +3,8 @@ #ifdef ENABLE_LOGS_PREVIEW +# include + # include "opentelemetry/exporters/otlp/otlp_grpc_log_exporter.h" # include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" @@ -110,13 +112,13 @@ TEST_F(OtlpGrpcLogExporterTestPeer, ExportIntegrationTest) auto exporter = GetExporter(stub_interface); - 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"}; + 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}; + opentelemetry::nostd::string_view attribute_storage_string_value[] = {"vector", "string"}; auto provider = nostd::shared_ptr(new sdk::logs::LoggerProvider()); provider->AddProcessor(std::unique_ptr( @@ -135,23 +137,23 @@ TEST_F(OtlpGrpcLogExporterTestPeer, ExportIntegrationTest) const std::string schema_url{"https://opentelemetry.io/schemas/1.11.0"}; auto logger = provider->GetLogger("test", "", "opentelelemtry_library", "", schema_url); - logger->Log(opentelemetry::logs::Severity::kInfo, "Log message", - {{"service.name", "unit_test_service"}, - {"tenant.id", "test_user"}, - {"bool_value", true}, - {"int32_value", static_cast(1)}, - {"uint32_value", static_cast(2)}, - {"int64_value", static_cast(0x1100000000LL)}, - {"uint64_value", static_cast(0x1200000000ULL)}, - {"double_value", static_cast(3.1)}, - {"vec_bool_value", attribute_storage_bool_value}, - {"vec_int32_value", attribute_storage_int32_value}, - {"vec_uint32_value", attribute_storage_uint32_value}, - {"vec_int64_value", attribute_storage_int64_value}, - {"vec_uint64_value", attribute_storage_uint64_value}, - {"vec_double_value", attribute_storage_double_value}, - {"vec_string_value", attribute_storage_string_value}}, - trace_id, span_id, + std::unordered_map attributes; + attributes["service.name"] = "unit_test_service"; + attributes["tenant.id"] = "test_user"; + attributes["bool_value"] = true; + attributes["int32_value"] = static_cast(1); + attributes["uint32_value"] = static_cast(2); + attributes["int64_value"] = static_cast(0x1100000000LL); + attributes["uint64_value"] = static_cast(0x1200000000ULL); + attributes["double_value"] = static_cast(3.1); + attributes["vec_bool_value"] = attribute_storage_bool_value; + attributes["vec_int32_value"] = attribute_storage_int32_value; + attributes["vec_uint32_value"] = attribute_storage_uint32_value; + attributes["vec_int64_value"] = attribute_storage_int64_value; + attributes["vec_uint64_value"] = attribute_storage_uint64_value; + attributes["vec_double_value"] = attribute_storage_double_value; + attributes["vec_string_value"] = attribute_storage_string_value; + logger->Log(opentelemetry::logs::Severity::kInfo, "Log message", attributes, trace_id, span_id, opentelemetry::trace::TraceFlags{opentelemetry::trace::TraceFlags::kIsSampled}, std::chrono::system_clock::now()); } diff --git a/exporters/otlp/test/otlp_grpc_metric_exporter_factory_test.cc b/exporters/otlp/test/otlp_grpc_metric_exporter_factory_test.cc new file mode 100644 index 0000000000..8073b6658d --- /dev/null +++ b/exporters/otlp/test/otlp_grpc_metric_exporter_factory_test.cc @@ -0,0 +1,40 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifndef ENABLE_METRICS_PREVIEW + +# include + +# include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h" +# include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h" + +/* + Make sure OtlpGrpcMetricExporterFactory does not require, + even indirectly, protobuf headers. +*/ +# ifdef GOOGLE_PROTOBUF_VERSION +# error "protobuf should not be included" +# endif + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +TEST(OtlpGrpcMetricExporterFactory, BuildTest) +{ + OtlpGrpcMetricExporterOptions opts; + opts.endpoint = "localhost:45454"; + + std::unique_ptr exporter = + OtlpGrpcMetricExporterFactory::Create(opts); + + EXPECT_TRUE(exporter != nullptr); +} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE + +#endif // ENABLE_METRICS_PREVIEW diff --git a/exporters/otlp/test/otlp_http_log_exporter_test.cc b/exporters/otlp/test/otlp_http_log_exporter_test.cc index 24b0fd6593..c79acf0069 100644 --- a/exporters/otlp/test/otlp_http_log_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_log_exporter_test.cc @@ -100,13 +100,13 @@ class OtlpHttpLogExporterTestPeer : public ::testing::Test auto client = mock_otlp_client.second; auto exporter = GetExporter(std::unique_ptr{mock_otlp_http_client}); - 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"}; + 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}; + opentelemetry::nostd::string_view attribute_storage_string_value[] = {"vector", "string"}; auto provider = nostd::shared_ptr(new sdk::logs::LoggerProvider()); @@ -194,13 +194,13 @@ class OtlpHttpLogExporterTestPeer : public ::testing::Test auto client = mock_otlp_client.second; auto exporter = GetExporter(std::unique_ptr{mock_otlp_http_client}); - 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"}; + 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}; + opentelemetry::nostd::string_view attribute_storage_string_value[] = {"vector", "string"}; auto provider = nostd::shared_ptr(new sdk::logs::LoggerProvider()); sdk::logs::BatchLogProcessorOptions options; @@ -296,13 +296,13 @@ class OtlpHttpLogExporterTestPeer : public ::testing::Test auto client = mock_otlp_client.second; auto exporter = GetExporter(std::unique_ptr{mock_otlp_http_client}); - 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"}; + 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}; + opentelemetry::nostd::string_view attribute_storage_string_value[] = {"vector", "string"}; auto provider = nostd::shared_ptr(new sdk::logs::LoggerProvider()); sdk::logs::BatchLogProcessorOptions processor_options; @@ -390,13 +390,13 @@ class OtlpHttpLogExporterTestPeer : public ::testing::Test auto client = mock_otlp_client.second; auto exporter = GetExporter(std::unique_ptr{mock_otlp_http_client}); - 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"}; + 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}; + opentelemetry::nostd::string_view attribute_storage_string_value[] = {"vector", "string"}; auto provider = nostd::shared_ptr(new sdk::logs::LoggerProvider()); diff --git a/exporters/otlp/test/otlp_http_metric_exporter_factory_test.cc b/exporters/otlp/test/otlp_http_metric_exporter_factory_test.cc new file mode 100644 index 0000000000..949aa778e5 --- /dev/null +++ b/exporters/otlp/test/otlp_http_metric_exporter_factory_test.cc @@ -0,0 +1,48 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifndef ENABLE_METRICS_PREVIEW + +# include + +# include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h" +# include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h" + +/* + Make sure OtlpHttpExporterFactory does not require, + even indirectly, nlohmann/json headers. +*/ +# ifdef NLOHMANN_JSON_VERSION_MAJOR +# error "nlohmann/json should not be included" +# endif /* NLOHMANN_JSON_VERSION_MAJOR */ + +/* + Make sure OtlpHttpExporterFactory does not require, + even indirectly, protobuf headers. +*/ +# ifdef GOOGLE_PROTOBUF_VERSION +# error "protobuf should not be included" +# endif + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +TEST(OtlpHttpMetricExporterFactory, BuildTest) +{ + OtlpHttpMetricExporterOptions opts; + opts.url = "localhost:45454"; + + std::unique_ptr exporter = + OtlpHttpMetricExporterFactory::Create(opts); + + EXPECT_TRUE(exporter != nullptr); +} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE + +#endif // ENABLE_METRICS_PREVIEW From c44fd917d615c80b8a14640edfba6f0c5dd153f4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Sep 2022 21:49:54 -0700 Subject: [PATCH 2/3] Bump actions/upload-artifact from 2 to 3 (#1610) --- .github/workflows/benchmark.yml | 2 +- .github/workflows/ci.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index d6b12b82d0..9b5edc2df5 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -35,7 +35,7 @@ jobs: mv api-benchmark_result.json benchmarks mv sdk-benchmark_result.json benchmarks mv exporters-benchmark_result.json benchmarks - - uses: actions/upload-artifact@master + - uses: actions/upload-artifact@v3 with: name: benchmark_results path: benchmarks diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d723ea2fe1..3a1c419334 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -398,7 +398,7 @@ jobs: env BENCHMARK_DIR=/benchmark ./ci/do_ci.sh benchmark - name: Upload benchmark results - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: benchmark_reports path: /home/runner/benchmark From cfaf8a1f6ca33ecdef514cca649168ee9155af68 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Mon, 12 Sep 2022 23:44:35 -0700 Subject: [PATCH 3/3] Example for OTLP gRPC exporter for Metrics. (#1598) --- examples/otlp/CMakeLists.txt | 8 ++ examples/otlp/README.md | 24 ++++- examples/otlp/grpc_metric_main.cc | 97 +++++++++++++++++++ .../config.dev.yaml | 7 +- 4 files changed, 130 insertions(+), 6 deletions(-) create mode 100644 examples/otlp/grpc_metric_main.cc diff --git a/examples/otlp/CMakeLists.txt b/examples/otlp/CMakeLists.txt index 3bd02737b1..f6bf25f932 100644 --- a/examples/otlp/CMakeLists.txt +++ b/examples/otlp/CMakeLists.txt @@ -37,3 +37,11 @@ if(WITH_OTLP_HTTP) opentelemetry_exporter_otlp_http_log) endif() endif() + +if(WITH_OTLP_GRPC AND NOT WITH_METRICS_PREVIEW) + add_executable(example_otlp_metric_grpc grpc_metric_main.cc) + target_link_libraries( + example_otlp_metric_grpc ${CMAKE_THREAD_LIBS_INIT} + common_metrics_foo_library opentelemetry_metrics + opentelemetry_exporter_otlp_grpc_metrics) +endif() diff --git a/examples/otlp/README.md b/examples/otlp/README.md index 91f86f8f50..f97af279da 100644 --- a/examples/otlp/README.md +++ b/examples/otlp/README.md @@ -4,21 +4,37 @@ This is an example of how to use the [OpenTelemetry Protocol](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/README.md) (OTLP) exporter. +### Traces The application in `grpc_main.cc` initializes an `OtlpGrpcExporter` instance, the application in `http_main.cc` initializes an `OtlpHttpExporter` instance. -The application in `http_log_main.cc` initializes an `OtlpHttpLogExporter` instance, -the application in `grpc_log_main.cc` initializes an `OtlpGrpcLogExporter` instance. And they register a tracer provider from the [OpenTelemetry SDK](https://github.com/open-telemetry/opentelemetry-cpp). The application then calls a `foo_library` which has been instrumented using the [OpenTelemetry API](https://github.com/open-telemetry/opentelemetry-cpp/tree/main/api). +### Logs +The application in `http_log_main.cc` initializes an `OtlpHttpLogExporter` instance, +the application in `grpc_log_main.cc` initializes an `OtlpGrpcLogExporter` instance. +And they register a logger provider from the [OpenTelemetry +SDK](https://github.com/open-telemetry/opentelemetry-cpp). The application then +calls a `logs_foo_library` which has been instrumented using the [OpenTelemetry +API](https://github.com/open-telemetry/opentelemetry-cpp/tree/main/api). + +### Metrics +The application in `grpc_metrics_main.cc` initializes an `OtlpGrpcMetricExporter` instance. +And it registers a meter provider from the [OpenTelemetry +SDK](https://github.com/open-telemetry/opentelemetry-cpp). The application then +calls a `metrics_foo_library` which has been instrumented using the [OpenTelemetry +API](https://github.com/open-telemetry/opentelemetry-cpp/tree/main/api). + +### Enable SSL/TLS To enable TLS authentication for OTLP grpc exporter, SslCredentials can be used by specifying the path to client certificate pem file, or the string containing this certificate via OtlpGrpcExporterOptions. The path to such a .pem file can be provided as a command-line argument alongwith the collector endpoint to the main binary invocation above. +### Running OpenTelemetry Collector as docker container Resulting spans are exported to the **OpenTelemetry Collector** using the OTLP exporter. The OpenTelemetry Collector can be configured to export to other backends (see list of [supported @@ -34,13 +50,13 @@ OpenTelemetry Collector with an OTLP receiver by running: - On Unix based systems use: ```console -docker run --rm -it -p 4317:4317 -p 4318:4318 -v $(pwd)/examples/otlp:/cfg otel/opentelemetry-collector:0.38.0 --config=/cfg/opentelemetry-collector-config/config.dev.yaml +docker run --rm -it -p 4317:4317 -p 4318:4318 -v $(pwd)/examples/otlp:/cfg otel/opentelemetry-collector:0.59.0 --config=/cfg/opentelemetry-collector-config/config.dev.yaml ``` - On Windows use: ```console -docker run --rm -it -p 4317:4317 -p 4318:4318 -v "%cd%/examples/otlp":/cfg otel/opentelemetry-collector:0.38.0 --config=/cfg/opentelemetry-collector-config/config.dev.yaml +docker run --rm -it -p 4317:4317 -p 4318:4318 -v "%cd%/examples/otlp":/cfg otel/opentelemetry-collector:0.59.0 --config=/cfg/opentelemetry-collector-config/config.dev.yaml ``` Note that the OTLP gRPC and HTTP exporters connects to the Collector at `localhost:4317` and `localhost:4318/v1/traces` respectively. This can be changed with first argument from command-line, for example: diff --git a/examples/otlp/grpc_metric_main.cc b/examples/otlp/grpc_metric_main.cc new file mode 100644 index 0000000000..c316ed4d1b --- /dev/null +++ b/examples/otlp/grpc_metric_main.cc @@ -0,0 +1,97 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifndef ENABLE_METRICS_PREVIEW + +# include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h" +# include "opentelemetry/metrics/provider.h" +# include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" +# include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader.h" +# include "opentelemetry/sdk/metrics/meter.h" +# include "opentelemetry/sdk/metrics/meter_provider.h" + +# include +# include + +# ifdef BAZEL_BUILD +# include "examples/common/metrics_foo_library/foo_library.h" +# else +# include "metrics_foo_library/foo_library.h" +# endif + +namespace metric_sdk = opentelemetry::sdk::metrics; +namespace nostd = opentelemetry::nostd; +namespace common = opentelemetry::common; +namespace metrics_api = opentelemetry::metrics; +namespace otlp_exporter = opentelemetry::exporter::otlp; + +namespace +{ + +otlp_exporter::OtlpGrpcMetricExporterOptions options; + +void initMetrics() +{ + auto exporter = otlp_exporter::OtlpGrpcMetricExporterFactory::Create(options); + + std::string version{"1.2.0"}; + std::string schema{"https://opentelemetry.io/schemas/1.2.0"}; + + // Initialize and set the global MeterProvider + metric_sdk::PeriodicExportingMetricReaderOptions options; + options.export_interval_millis = std::chrono::milliseconds(1000); + options.export_timeout_millis = std::chrono::milliseconds(500); + std::unique_ptr reader{ + new metric_sdk::PeriodicExportingMetricReader(std::move(exporter), options)}; + auto provider = std::shared_ptr(new metric_sdk::MeterProvider()); + auto p = std::static_pointer_cast(provider); + p->AddMetricReader(std::move(reader)); + + metrics_api::Provider::SetMeterProvider(provider); +} +} // namespace + +int main(int argc, char *argv[]) +{ + std::string example_type; + if (argc > 1) + { + options.endpoint = argv[1]; + if (argc > 2) + { + example_type = argv[2]; + if (argc > 3) + { + options.use_ssl_credentials = true; + options.ssl_credentials_cacert_path = argv[3]; + } + } + } + // Removing this line will leave the default noop MetricProvider in place. + initMetrics(); + std::string name{"otlp_grpc_metric_example"}; + + if (example_type == "counter") + { + foo_library::counter_example(name); + } + else if (example_type == "observable_counter") + { + foo_library::observable_counter_example(name); + } + else if (example_type == "histogram") + { + foo_library::histogram_example(name); + } + else + { + std::thread counter_example{&foo_library::counter_example, name}; + std::thread observable_counter_example{&foo_library::observable_counter_example, name}; + std::thread histogram_example{&foo_library::histogram_example, name}; + + counter_example.join(); + observable_counter_example.join(); + histogram_example.join(); + } +} +#endif diff --git a/examples/otlp/opentelemetry-collector-config/config.dev.yaml b/examples/otlp/opentelemetry-collector-config/config.dev.yaml index f10252b953..895d70ece1 100644 --- a/examples/otlp/opentelemetry-collector-config/config.dev.yaml +++ b/examples/otlp/opentelemetry-collector-config/config.dev.yaml @@ -8,8 +8,6 @@ receivers: endpoint: 0.0.0.0:4317 http: endpoint: 0.0.0.0:4318 - cors_allowed_origins: - - '*' service: pipelines: traces: @@ -22,3 +20,8 @@ service: - otlp exporters: - logging + metrics: + receivers: + - otlp + exporters: + - logging