From 925d18b1ee6bb7961705f0a7f2e677dc7813d6f0 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Thu, 28 Jul 2022 09:41:14 +0200 Subject: [PATCH 1/7] Fix log sdk builder (#1486) --- examples/otlp/grpc_log_main.cc | 19 +++--- examples/otlp/http_log_main.cc | 19 +++--- exporters/otlp/CMakeLists.txt | 10 +-- .../otlp/otlp_grpc_log_exporter_factory.h | 39 +++++++++++ .../exporters/otlp/otlp_http_log_exporter.h | 42 +----------- .../otlp/otlp_http_log_exporter_factory.h | 39 +++++++++++ .../otlp/otlp_http_log_exporter_options.h | 66 +++++++++++++++++++ .../src/otlp_grpc_log_exporter_factory.cc | 36 ++++++++++ .../src/otlp_http_log_exporter_factory.cc | 33 ++++++++++ .../sdk/logs/batch_log_processor.h | 22 +------ .../sdk/logs/batch_log_processor_factory.h | 35 ++++++++++ .../sdk/logs/batch_log_processor_options.h | 44 +++++++++++++ .../sdk/logs/logger_provider_factory.h | 66 +++++++++++++++++++ .../sdk/logs/multi_log_processor_factory.h | 33 ++++++++++ .../sdk/logs/simple_log_processor_factory.h | 32 +++++++++ sdk/src/logs/CMakeLists.txt | 4 ++ sdk/src/logs/batch_log_processor_factory.cc | 26 ++++++++ sdk/src/logs/logger_provider_factory.cc | 58 ++++++++++++++++ sdk/src/logs/multi_log_processor_factory.cc | 30 +++++++++ sdk/src/logs/simple_log_processor_factory.cc | 25 +++++++ 20 files changed, 591 insertions(+), 87 deletions(-) create mode 100644 exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_exporter_factory.h create mode 100644 exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter_factory.h create mode 100644 exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter_options.h create mode 100644 exporters/otlp/src/otlp_grpc_log_exporter_factory.cc create mode 100644 exporters/otlp/src/otlp_http_log_exporter_factory.cc create mode 100644 sdk/include/opentelemetry/sdk/logs/batch_log_processor_factory.h create mode 100644 sdk/include/opentelemetry/sdk/logs/batch_log_processor_options.h create mode 100644 sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h create mode 100644 sdk/include/opentelemetry/sdk/logs/multi_log_processor_factory.h create mode 100644 sdk/include/opentelemetry/sdk/logs/simple_log_processor_factory.h create mode 100644 sdk/src/logs/batch_log_processor_factory.cc create mode 100644 sdk/src/logs/logger_provider_factory.cc create mode 100644 sdk/src/logs/multi_log_processor_factory.cc create mode 100644 sdk/src/logs/simple_log_processor_factory.cc diff --git a/examples/otlp/grpc_log_main.cc b/examples/otlp/grpc_log_main.cc index 980b18e50a..0d9669d847 100644 --- a/examples/otlp/grpc_log_main.cc +++ b/examples/otlp/grpc_log_main.cc @@ -2,15 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 #ifdef ENABLE_LOGS_PREVIEW -// Make sure to include GRPC exporter first because otherwise Abseil may create -// ambiguity with `nostd::variant`. See issue: -// https://github.com/open-telemetry/opentelemetry-cpp/issues/880 -# include "opentelemetry/exporters/otlp/otlp_grpc_log_exporter.h" - # include "opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h" +# include "opentelemetry/exporters/otlp/otlp_grpc_log_exporter_factory.h" # include "opentelemetry/logs/provider.h" # include "opentelemetry/sdk/logs/logger_provider.h" +# include "opentelemetry/sdk/logs/logger_provider_factory.h" # include "opentelemetry/sdk/logs/simple_log_processor.h" +# include "opentelemetry/sdk/logs/simple_log_processor_factory.h" # include "opentelemetry/sdk/trace/simple_processor_factory.h" # include "opentelemetry/sdk/trace/tracer_provider_factory.h" # include "opentelemetry/trace/provider.h" @@ -47,12 +45,11 @@ void InitTracer() void InitLogger() { // Create OTLP exporter instance - auto exporter = std::unique_ptr(new otlp::OtlpGrpcLogExporter(opts)); - auto sdkProvider = std::shared_ptr( - new logs_sdk::LoggerProvider(std::unique_ptr( - new logs_sdk::SimpleLogProcessor(std::move(exporter))))); - auto apiProvider = nostd::shared_ptr(sdkProvider); - auto provider = nostd::shared_ptr(apiProvider); + auto exporter = otlp::OtlpGrpcLogExporterFactory::Create(opts); + auto processor = logs_sdk::SimpleLogProcessorFactory::Create(std::move(exporter)); + nostd::shared_ptr provider( + logs_sdk::LoggerProviderFactory::Create(std::move(processor))); + opentelemetry::logs::Provider::SetLoggerProvider(provider); } } // namespace diff --git a/examples/otlp/http_log_main.cc b/examples/otlp/http_log_main.cc index 1789f542da..a764252aac 100644 --- a/examples/otlp/http_log_main.cc +++ b/examples/otlp/http_log_main.cc @@ -3,10 +3,11 @@ #ifdef ENABLE_LOGS_PREVIEW # include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.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/logs/provider.h" -# include "opentelemetry/sdk/logs/logger_provider.h" -# include "opentelemetry/sdk/logs/simple_log_processor.h" +# include "opentelemetry/sdk/logs/logger_provider_factory.h" +# include "opentelemetry/sdk/logs/simple_log_processor_factory.h" # include "opentelemetry/sdk/trace/simple_processor_factory.h" # include "opentelemetry/sdk/trace/tracer_provider_factory.h" # include "opentelemetry/trace/provider.h" @@ -46,13 +47,11 @@ void InitLogger() { logger_opts.console_debug = true; // Create OTLP exporter instance - auto exporter = - std::unique_ptr(new otlp::OtlpHttpLogExporter(logger_opts)); - auto sdkProvider = std::shared_ptr( - new logs_sdk::LoggerProvider(std::unique_ptr( - new logs_sdk::SimpleLogProcessor(std::move(exporter))))); - auto apiProvider = nostd::shared_ptr(sdkProvider); - auto provider = nostd::shared_ptr(apiProvider); + auto exporter = otlp::OtlpHttpLogExporterFactory::Create(logger_opts); + auto processor = logs_sdk::SimpleLogProcessorFactory::Create(std::move(exporter)); + std::shared_ptr provider = + logs_sdk::LoggerProviderFactory::Create(std::move(processor)); + opentelemetry::logs::Provider::SetLoggerProvider(provider); } } // namespace diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index a1f6546279..10de697dc1 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -29,8 +29,9 @@ if(WITH_OTLP_GRPC) list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_grpc) - add_library(opentelemetry_exporter_otlp_grpc_log - src/otlp_grpc_log_exporter.cc) + add_library( + opentelemetry_exporter_otlp_grpc_log src/otlp_grpc_log_exporter.cc + src/otlp_grpc_log_exporter_factory.cc) set_target_properties(opentelemetry_exporter_otlp_grpc_log PROPERTIES EXPORT_NAME otlp_grpc_log_exporter) @@ -90,8 +91,9 @@ if(WITH_OTLP_HTTP) list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_http) if(WITH_LOGS_PREVIEW) - add_library(opentelemetry_exporter_otlp_http_log - src/otlp_http_log_exporter.cc) + add_library( + opentelemetry_exporter_otlp_http_log + src/otlp_http_log_exporter.cc src/otlp_http_log_exporter_factory.cc) set_target_properties(opentelemetry_exporter_otlp_http_log PROPERTIES EXPORT_NAME otlp_http_log_exporter) diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_exporter_factory.h new file mode 100644 index 0000000000..dfe3dfd6a0 --- /dev/null +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_exporter_factory.h @@ -0,0 +1,39 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#ifdef ENABLE_LOGS_PREVIEW + +# include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" +# include "opentelemetry/sdk/logs/exporter.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +/** + * Factory class for OtlpGrpcLogExporter. + */ +class OtlpGrpcLogExporterFactory +{ +public: + /** + * Create a OtlpGrpcLogExporter. + */ + static std::unique_ptr Create(); + + /** + * Create a OtlpGrpcLogExporter. + */ + static std::unique_ptr Create( + const OtlpGrpcExporterOptions &options); +}; + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE + +#endif /* ENABLE_LOGS_PREVIEW */ diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter.h index c6b2da30c3..c139b9ee6c 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter.h @@ -9,6 +9,7 @@ # include "opentelemetry/exporters/otlp/otlp_http_client.h" # include "opentelemetry/exporters/otlp/otlp_environment.h" +# include "opentelemetry/exporters/otlp/otlp_http_log_exporter_options.h" # include # include @@ -21,47 +22,6 @@ namespace exporter namespace otlp { -/** - * Struct to hold OTLP exporter options. - */ -struct OtlpHttpLogExporterOptions -{ - // 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 = GetOtlpDefaultHttpLogEndpoint(); - - // 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 = GetOtlpDefaultLogTimeout(); - - // Additional HTTP headers - OtlpHeaders http_headers = GetOtlpDefaultLogHeaders(); - -# 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 log data in OpenTelemetry Protocol (OTLP) format. */ diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter_factory.h new file mode 100644 index 0000000000..b2f509f683 --- /dev/null +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter_factory.h @@ -0,0 +1,39 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#ifdef ENABLE_LOGS_PREVIEW + +# include "opentelemetry/exporters/otlp/otlp_http_log_exporter_options.h" +# include "opentelemetry/sdk/logs/exporter.h" + +# include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +/** + * Factory class for OtlpHttpLogExporter. + */ +class OtlpHttpLogExporterFactory +{ +public: + /** + * Create a OtlpHttpLogExporter. + */ + static std::unique_ptr Create(); + + /** + * Create a OtlpHttpLogExporter. + */ + static std::unique_ptr Create( + const OtlpHttpLogExporterOptions &options); +}; + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter_options.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter_options.h new file mode 100644 index 0000000000..7c145a648d --- /dev/null +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter_options.h @@ -0,0 +1,66 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#ifdef ENABLE_LOGS_PREVIEW + +# include "opentelemetry/exporters/otlp/otlp_http_client.h" + +# include "opentelemetry/sdk/logs/exporter.h" + +# include +# include +# include +# include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +/** + * Struct to hold OTLP exporter options. + */ +struct OtlpHttpLogExporterOptions +{ + // 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 = GetOtlpDefaultHttpLogEndpoint(); + + // 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 = GetOtlpDefaultLogTimeout(); + + // Additional HTTP headers + OtlpHeaders http_headers = GetOtlpDefaultLogHeaders(); + +# 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_log_exporter_factory.cc b/exporters/otlp/src/otlp_grpc_log_exporter_factory.cc new file mode 100644 index 0000000000..69162cee3e --- /dev/null +++ b/exporters/otlp/src/otlp_grpc_log_exporter_factory.cc @@ -0,0 +1,36 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifdef ENABLE_LOGS_PREVIEW + +// MUST be first (absl) +# include "opentelemetry/exporters/otlp/otlp_grpc_log_exporter.h" + +# include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" +# include "opentelemetry/exporters/otlp/otlp_grpc_log_exporter_factory.h" +# include "opentelemetry/sdk/common/global_log_handler.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +std::unique_ptr OtlpGrpcLogExporterFactory::Create() +{ + OtlpGrpcExporterOptions options; + return Create(options); +} + +std::unique_ptr OtlpGrpcLogExporterFactory::Create( + const OtlpGrpcExporterOptions &options) +{ + std::unique_ptr exporter(new OtlpGrpcLogExporter(options)); + return exporter; +} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE + +#endif diff --git a/exporters/otlp/src/otlp_http_log_exporter_factory.cc b/exporters/otlp/src/otlp_http_log_exporter_factory.cc new file mode 100644 index 0000000000..29e173454d --- /dev/null +++ b/exporters/otlp/src/otlp_http_log_exporter_factory.cc @@ -0,0 +1,33 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifdef ENABLE_LOGS_PREVIEW + +# include "opentelemetry/exporters/otlp/otlp_http_log_exporter_factory.h" +# include "opentelemetry/exporters/otlp/otlp_http_log_exporter.h" +# include "opentelemetry/exporters/otlp/otlp_http_log_exporter_options.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +std::unique_ptr OtlpHttpLogExporterFactory::Create() +{ + OtlpHttpLogExporterOptions options; + return Create(options); +} + +std::unique_ptr OtlpHttpLogExporterFactory::Create( + const OtlpHttpLogExporterOptions &options) +{ + std::unique_ptr exporter(new OtlpHttpLogExporter(options)); + return exporter; +} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE + +#endif diff --git a/sdk/include/opentelemetry/sdk/logs/batch_log_processor.h b/sdk/include/opentelemetry/sdk/logs/batch_log_processor.h index 2a781b937c..e70b511a10 100644 --- a/sdk/include/opentelemetry/sdk/logs/batch_log_processor.h +++ b/sdk/include/opentelemetry/sdk/logs/batch_log_processor.h @@ -5,6 +5,7 @@ #ifdef ENABLE_LOGS_PREVIEW # include "opentelemetry/sdk/common/circular_buffer.h" +# include "opentelemetry/sdk/logs/batch_log_processor_options.h" # include "opentelemetry/sdk/logs/exporter.h" # include "opentelemetry/sdk/logs/processor.h" @@ -21,27 +22,6 @@ namespace sdk namespace logs { -/** - * Struct to hold batch SpanProcessor options. - */ -struct BatchLogProcessorOptions -{ - /** - * The maximum buffer/queue size. After the size is reached, spans are - * dropped. - */ - size_t max_queue_size = 2048; - - /* The time interval between two consecutive exports. */ - std::chrono::milliseconds schedule_delay_millis = std::chrono::milliseconds(5000); - - /** - * The maximum batch size of every export. It must be smaller or - * equal to max_queue_size. - */ - size_t max_export_batch_size = 512; -}; - /** * This is an implementation of the LogProcessor which creates batches of finished logs and passes * the export-friendly log data representations to the configured LogExporter. diff --git a/sdk/include/opentelemetry/sdk/logs/batch_log_processor_factory.h b/sdk/include/opentelemetry/sdk/logs/batch_log_processor_factory.h new file mode 100644 index 0000000000..6ccb8e43c0 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/logs/batch_log_processor_factory.h @@ -0,0 +1,35 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#ifdef ENABLE_LOGS_PREVIEW + +# include "opentelemetry/sdk/logs/batch_log_processor_options.h" +# include "opentelemetry/sdk/logs/exporter.h" +# include "opentelemetry/sdk/logs/processor.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ + +namespace logs +{ + +/** + * Factory class for BatchLogProcessor. + */ +class BatchLogProcessorFactory +{ +public: + /** + * Create a BatchLogProcessor. + */ + std::unique_ptr Create(std::unique_ptr &&exporter, + const BatchLogProcessorOptions &options); +}; + +} // namespace logs +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/logs/batch_log_processor_options.h b/sdk/include/opentelemetry/sdk/logs/batch_log_processor_options.h new file mode 100644 index 0000000000..591e12af72 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/logs/batch_log_processor_options.h @@ -0,0 +1,44 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#ifdef ENABLE_LOGS_PREVIEW + +# include "opentelemetry/sdk/version/version.h" + +# include +# include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ + +namespace logs +{ + +/** + * Struct to hold batch SpanProcessor options. + */ +struct BatchLogProcessorOptions +{ + /** + * The maximum buffer/queue size. After the size is reached, spans are + * dropped. + */ + size_t max_queue_size = 2048; + + /* The time interval between two consecutive exports. */ + std::chrono::milliseconds schedule_delay_millis = std::chrono::milliseconds(5000); + + /** + * The maximum batch size of every export. It must be smaller or + * equal to max_queue_size. + */ + size_t max_export_batch_size = 512; +}; + +} // namespace logs +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h b/sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h new file mode 100644 index 0000000000..eb6bee2ab1 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h @@ -0,0 +1,66 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0/ + +#pragma once + +#ifdef ENABLE_LOGS_PREVIEW + +# include +# include + +# include "opentelemetry/logs/logger_provider.h" +# include "opentelemetry/nostd/shared_ptr.h" +# include "opentelemetry/sdk/common/atomic_shared_ptr.h" +# include "opentelemetry/sdk/logs/logger.h" +# include "opentelemetry/sdk/logs/logger_context.h" +# include "opentelemetry/sdk/logs/processor.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace logs +{ + +/** + * Factory class for LoggerProvider. + */ +class LoggerProviderFactory +{ +public: + /** + * Create a LoggerProvider. + */ + static std::unique_ptr Create( + std::unique_ptr &&processor); + + /** + * Create a LoggerProvider. + */ + static std::unique_ptr Create( + std::unique_ptr &&processor, + const opentelemetry::sdk::resource::Resource &resource); + + /** + * Create a LoggerProvider. + */ + static std::unique_ptr Create( + std::vector> &&processors); + + /** + * Create a LoggerProvider. + */ + static std::unique_ptr Create( + std::vector> &&processors, + const opentelemetry::sdk::resource::Resource &resource); + + /** + * Create a LoggerProvider. + */ + static std::unique_ptr Create( + std::shared_ptr context); +}; + +} // namespace logs +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE +#endif /* ENABLE_LOGS_PREVIEW */ diff --git a/sdk/include/opentelemetry/sdk/logs/multi_log_processor_factory.h b/sdk/include/opentelemetry/sdk/logs/multi_log_processor_factory.h new file mode 100644 index 0000000000..a61ae5522b --- /dev/null +++ b/sdk/include/opentelemetry/sdk/logs/multi_log_processor_factory.h @@ -0,0 +1,33 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#ifdef ENABLE_LOGS_PREVIEW + +# include +# include + +# include "opentelemetry/sdk/logs/processor.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace logs +{ + +/** + * Factory class for MultiLogProcessor. + */ +class MultiLogProcessorFactory +{ +public: + static std::unique_ptr Create( + std::vector> &&processors); +}; + +} // namespace logs +} // namespace sdk + +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/logs/simple_log_processor_factory.h b/sdk/include/opentelemetry/sdk/logs/simple_log_processor_factory.h new file mode 100644 index 0000000000..2576a61eb6 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/logs/simple_log_processor_factory.h @@ -0,0 +1,32 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#ifdef ENABLE_LOGS_PREVIEW + +# include "opentelemetry/sdk/logs/exporter.h" +# include "opentelemetry/sdk/logs/processor.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace logs +{ + +/** + * Factory class for SimpleLogProcessor. + */ +class SimpleLogProcessorFactory +{ +public: + /** + * Create a SimpleLogProcessor. + */ + static std::unique_ptr Create(std::unique_ptr &&exporter); +}; + +} // namespace logs +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE +#endif /* ENABLE_LOGS_PREVIEW */ diff --git a/sdk/src/logs/CMakeLists.txt b/sdk/src/logs/CMakeLists.txt index 20f13324e7..4ab289c190 100644 --- a/sdk/src/logs/CMakeLists.txt +++ b/sdk/src/logs/CMakeLists.txt @@ -1,11 +1,15 @@ add_library( opentelemetry_logs logger_provider.cc + logger_provider_factory.cc logger.cc simple_log_processor.cc + simple_log_processor_factory.cc batch_log_processor.cc + batch_log_processor_factory.cc logger_context.cc multi_log_processor.cc + multi_log_processor_factory.cc multi_recordable.cc) set_target_properties(opentelemetry_logs PROPERTIES EXPORT_NAME logs) diff --git a/sdk/src/logs/batch_log_processor_factory.cc b/sdk/src/logs/batch_log_processor_factory.cc new file mode 100644 index 0000000000..d5e825e6f5 --- /dev/null +++ b/sdk/src/logs/batch_log_processor_factory.cc @@ -0,0 +1,26 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifdef ENABLE_LOGS_PREVIEW + +# include "opentelemetry/sdk/logs/batch_log_processor_factory.h" +# include "opentelemetry/sdk/logs/batch_log_processor.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace logs +{ + +std::unique_ptr BatchLogProcessorFactory::Create( + std::unique_ptr &&exporter, + const BatchLogProcessorOptions &options) +{ + std::unique_ptr processor(new BatchLogProcessor(std::move(exporter), options)); + return processor; +} + +} // namespace logs +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/src/logs/logger_provider_factory.cc b/sdk/src/logs/logger_provider_factory.cc new file mode 100644 index 0000000000..8b9e6a694e --- /dev/null +++ b/sdk/src/logs/logger_provider_factory.cc @@ -0,0 +1,58 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifdef ENABLE_LOGS_PREVIEW + +# include "opentelemetry/sdk/logs/logger_provider_factory.h" +# include "opentelemetry/sdk/logs/logger_provider.h" +# include "opentelemetry/sdk/resource/resource.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace logs +{ + +std::unique_ptr LoggerProviderFactory::Create( + std::unique_ptr &&processor) +{ + auto resource = opentelemetry::sdk::resource::Resource::Create({}); + return Create(std::move(processor), resource); +} + +std::unique_ptr LoggerProviderFactory::Create( + std::unique_ptr &&processor, + const opentelemetry::sdk::resource::Resource &resource) +{ + std::unique_ptr provider( + new LoggerProvider(std::move(processor), resource)); + return provider; +} + +std::unique_ptr LoggerProviderFactory::Create( + std::vector> &&processors) +{ + auto resource = opentelemetry::sdk::resource::Resource::Create({}); + return Create(std::move(processors), resource); +} + +std::unique_ptr LoggerProviderFactory::Create( + std::vector> &&processors, + const opentelemetry::sdk::resource::Resource &resource) +{ + std::unique_ptr provider( + new LoggerProvider(std::move(processors), resource)); + return provider; +} + +std::unique_ptr LoggerProviderFactory::Create( + std::shared_ptr context) +{ + std::unique_ptr provider(new LoggerProvider(context)); + return provider; +} + +} // namespace logs +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/src/logs/multi_log_processor_factory.cc b/sdk/src/logs/multi_log_processor_factory.cc new file mode 100644 index 0000000000..a0b8a8c911 --- /dev/null +++ b/sdk/src/logs/multi_log_processor_factory.cc @@ -0,0 +1,30 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifdef ENABLE_LOGS_PREVIEW + +# include "opentelemetry/sdk/logs/multi_log_processor_factory.h" +# include "opentelemetry/sdk/logs/multi_log_processor.h" + +# include +# include +# include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace logs +{ + +std::unique_ptr MultiLogProcessorFactory::Create( + std::vector> &&processors) +{ + std::unique_ptr processor(new MultiLogProcessor(std::move(processors))); + return processor; +} + +} // namespace logs +} // namespace sdk + +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/src/logs/simple_log_processor_factory.cc b/sdk/src/logs/simple_log_processor_factory.cc new file mode 100644 index 0000000000..25cf46521e --- /dev/null +++ b/sdk/src/logs/simple_log_processor_factory.cc @@ -0,0 +1,25 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifdef ENABLE_LOGS_PREVIEW + +# include "opentelemetry/sdk/logs/simple_log_processor_factory.h" +# include "opentelemetry/sdk/logs/simple_log_processor.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace logs +{ + +std::unique_ptr SimpleLogProcessorFactory::Create( + std::unique_ptr &&exporter) +{ + std::unique_ptr processor(new SimpleLogProcessor(std::move(exporter))); + return processor; +} + +} // namespace logs +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE +#endif From a13add04ff24ee87975a368d9faa710a086ee9a3 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Thu, 28 Jul 2022 10:56:52 +0200 Subject: [PATCH 2/7] Fix log sdk builder (#1486) Fixed bazel build. Added CHANGELOG entry. --- CHANGELOG.md | 1 + exporters/otlp/BUILD | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a71aa5d22..f7c43dd3aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ Increment the: * [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)) * [SEMANTIC CONVENTIONS] Upgrade to version 1.12.0 [#873](https://github.com/open-telemetry/opentelemetry-cpp/pull/873) +* [LOG SDK] Add log sdk builders (#1486) [#1524](https://github.com/open-telemetry/opentelemetry-cpp/pull/1524) ## [1.4.1] 2022-06-19 diff --git a/exporters/otlp/BUILD b/exporters/otlp/BUILD index 1619a010ca..d447aaa073 100644 --- a/exporters/otlp/BUILD +++ b/exporters/otlp/BUILD @@ -144,10 +144,13 @@ 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", ], @@ -192,11 +195,13 @@ cc_library( name = "otlp_grpc_log_exporter", srcs = [ "src/otlp_grpc_log_exporter.cc", + "src/otlp_grpc_log_exporter_factory.cc", ], hdrs = [ "include/opentelemetry/exporters/otlp/otlp_environment.h", "include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h", "include/opentelemetry/exporters/otlp/otlp_grpc_log_exporter.h", + "include/opentelemetry/exporters/otlp/otlp_grpc_log_exporter_factory.h", "include/opentelemetry/exporters/otlp/protobuf_include_prefix.h", "include/opentelemetry/exporters/otlp/protobuf_include_suffix.h", ], From 5996d8dc172786ec4b2dacd99a8431d4927d1160 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Thu, 28 Jul 2022 12:07:37 +0200 Subject: [PATCH 3/7] Fix log sdk builder (#1486) Code cleanup --- examples/otlp/grpc_log_main.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/otlp/grpc_log_main.cc b/examples/otlp/grpc_log_main.cc index 0d9669d847..b8f7441b71 100644 --- a/examples/otlp/grpc_log_main.cc +++ b/examples/otlp/grpc_log_main.cc @@ -5,9 +5,7 @@ # include "opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h" # include "opentelemetry/exporters/otlp/otlp_grpc_log_exporter_factory.h" # include "opentelemetry/logs/provider.h" -# include "opentelemetry/sdk/logs/logger_provider.h" # include "opentelemetry/sdk/logs/logger_provider_factory.h" -# include "opentelemetry/sdk/logs/simple_log_processor.h" # include "opentelemetry/sdk/logs/simple_log_processor_factory.h" # include "opentelemetry/sdk/trace/simple_processor_factory.h" # include "opentelemetry/sdk/trace/tracer_provider_factory.h" From 6e2cc90f243db927b11a8e1934297328d51d04f4 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Fri, 29 Jul 2022 18:10:09 +0200 Subject: [PATCH 4/7] Fix log sdk builder (#1486) Implemented code review comments. Fixed typo (processor -> processors) in TracerContextFactory --- .../src/otlp_grpc_log_exporter_factory.cc | 1 - .../sdk/logs/logger_context_factory.h | 43 +++++++++++++++++++ .../sdk/trace/tracer_context_factory.h | 8 ++-- sdk/src/logs/CMakeLists.txt | 1 + sdk/src/logs/logger_context_factory.cc | 36 ++++++++++++++++ sdk/src/trace/tracer_context_factory.cc | 16 +++---- 6 files changed, 92 insertions(+), 13 deletions(-) create mode 100644 sdk/include/opentelemetry/sdk/logs/logger_context_factory.h create mode 100644 sdk/src/logs/logger_context_factory.cc diff --git a/exporters/otlp/src/otlp_grpc_log_exporter_factory.cc b/exporters/otlp/src/otlp_grpc_log_exporter_factory.cc index 69162cee3e..9e90070844 100644 --- a/exporters/otlp/src/otlp_grpc_log_exporter_factory.cc +++ b/exporters/otlp/src/otlp_grpc_log_exporter_factory.cc @@ -8,7 +8,6 @@ # include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" # include "opentelemetry/exporters/otlp/otlp_grpc_log_exporter_factory.h" -# include "opentelemetry/sdk/common/global_log_handler.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter diff --git a/sdk/include/opentelemetry/sdk/logs/logger_context_factory.h b/sdk/include/opentelemetry/sdk/logs/logger_context_factory.h new file mode 100644 index 0000000000..55a5ec87fa --- /dev/null +++ b/sdk/include/opentelemetry/sdk/logs/logger_context_factory.h @@ -0,0 +1,43 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#ifdef ENABLE_LOGS_PREVIEW + +# include "opentelemetry/sdk/logs/logger_context.h" +# include "opentelemetry/sdk/logs/processor.h" +# include "opentelemetry/sdk/resource/resource.h" +# include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace logs +{ + +/** + * Factory class for LoggerContext. + */ +class LoggerContextFactory +{ +public: + /** + * Create a LoggerContext. + */ + static std::unique_ptr Create( + std::vector> &&processors); + + /** + * Create a LoggerContext. + */ + static std::unique_ptr Create( + std::vector> &&processors, + const opentelemetry::sdk::resource::Resource &resource); +}; + +} // namespace logs +} // namespace sdk + +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_context_factory.h b/sdk/include/opentelemetry/sdk/trace/tracer_context_factory.h index 447db73104..eb88707328 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_context_factory.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_context_factory.h @@ -24,20 +24,20 @@ class TracerContextFactory * Create a TracerContext. */ static std::unique_ptr Create( - std::vector> &&processor); + std::vector> &&processors); /** * Create a TracerContext. */ static std::unique_ptr Create( - std::vector> &&processor, + std::vector> &&processors, const opentelemetry::sdk::resource::Resource &resource); /** * Create a TracerContext. */ static std::unique_ptr Create( - std::vector> &&processor, + std::vector> &&processors, const opentelemetry::sdk::resource::Resource &resource, std::unique_ptr sampler); @@ -45,7 +45,7 @@ class TracerContextFactory * Create a TracerContext. */ static std::unique_ptr Create( - std::vector> &&processor, + std::vector> &&processors, const opentelemetry::sdk::resource::Resource &resource, std::unique_ptr sampler, std::unique_ptr id_generator); diff --git a/sdk/src/logs/CMakeLists.txt b/sdk/src/logs/CMakeLists.txt index 4ab289c190..ec9a3b8c79 100644 --- a/sdk/src/logs/CMakeLists.txt +++ b/sdk/src/logs/CMakeLists.txt @@ -8,6 +8,7 @@ add_library( batch_log_processor.cc batch_log_processor_factory.cc logger_context.cc + logger_context_factory.cc multi_log_processor.cc multi_log_processor_factory.cc multi_recordable.cc) diff --git a/sdk/src/logs/logger_context_factory.cc b/sdk/src/logs/logger_context_factory.cc new file mode 100644 index 0000000000..5cbe8b4510 --- /dev/null +++ b/sdk/src/logs/logger_context_factory.cc @@ -0,0 +1,36 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifdef ENABLE_LOGS_PREVIEW + +# include "opentelemetry/sdk/logs/logger_context_factory.h" + +# include +# include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace logs +{ + +std::unique_ptr LoggerContextFactory::Create( + std::vector> &&processors) +{ + auto resource = opentelemetry::sdk::resource::Resource::Create({}); + return Create(std::move(processors), resource); +} + +std::unique_ptr LoggerContextFactory::Create( + std::vector> &&processors, + const opentelemetry::sdk::resource::Resource &resource) +{ + std::unique_ptr context(new LoggerContext(std::move(processors), resource)); + return context; +} + +} // namespace logs +} // namespace sdk + +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/src/trace/tracer_context_factory.cc b/sdk/src/trace/tracer_context_factory.cc index a966b5f5d9..df9d81a197 100644 --- a/sdk/src/trace/tracer_context_factory.cc +++ b/sdk/src/trace/tracer_context_factory.cc @@ -14,37 +14,37 @@ namespace trace { std::unique_ptr TracerContextFactory::Create( - std::vector> &&processor) + std::vector> &&processors) { auto resource = opentelemetry::sdk::resource::Resource::Create({}); - return Create(std::move(processor), resource); + return Create(std::move(processors), resource); } std::unique_ptr TracerContextFactory::Create( - std::vector> &&processor, + std::vector> &&processors, const opentelemetry::sdk::resource::Resource &resource) { auto sampler = AlwaysOnSamplerFactory::Create(); - return Create(std::move(processor), resource, std::move(sampler)); + return Create(std::move(processors), resource, std::move(sampler)); } std::unique_ptr TracerContextFactory::Create( - std::vector> &&processor, + std::vector> &&processors, const opentelemetry::sdk::resource::Resource &resource, std::unique_ptr sampler) { auto id_generator = RandomIdGeneratorFactory::Create(); - return Create(std::move(processor), resource, std::move(sampler), std::move(id_generator)); + return Create(std::move(processors), resource, std::move(sampler), std::move(id_generator)); } std::unique_ptr TracerContextFactory::Create( - std::vector> &&processor, + std::vector> &&processors, const opentelemetry::sdk::resource::Resource &resource, std::unique_ptr sampler, std::unique_ptr id_generator) { std::unique_ptr context(new TracerContext( - std::move(processor), resource, std::move(sampler), std::move(id_generator))); + std::move(processors), resource, std::move(sampler), std::move(id_generator))); return context; } From 0595c68b495c1ff634b8f93abb27525be4b3fb66 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Mon, 1 Aug 2022 10:16:50 +0200 Subject: [PATCH 5/7] Fix log sdk builder (#1486) CHANGELOG cleanup after 1.5.0 release. --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01d45a62fb..40b13e0dfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ Increment the: ## [Unreleased] +* [LOG SDK] Add log sdk builders (#1486) [#1524](https://github.com/open-telemetry/opentelemetry-cpp/pull/1524) + ## [1.5.0] 2022-07-29 * [EXPORTER BUILD] Add resources to dep list of prometheus exporter test [#1527](https://github.com/open-telemetry/opentelemetry-cpp/pull/1527) @@ -46,7 +48,6 @@ Increment the: * [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)) * [SEMANTIC CONVENTIONS] Upgrade to version 1.12.0 [#873](https://github.com/open-telemetry/opentelemetry-cpp/pull/873) -* [LOG SDK] Add log sdk builders (#1486) [#1524](https://github.com/open-telemetry/opentelemetry-cpp/pull/1524) ## [1.4.1] 2022-06-19 From f6ab143553ca91c0f720ce3e2cef917ef3a215d9 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Mon, 1 Aug 2022 20:57:40 +0200 Subject: [PATCH 6/7] Fix log sdk builder (#1486) Implemented code review comments, added unit tests. --- exporters/otlp/BUILD | 32 ++++++++++++++ exporters/otlp/CMakeLists.txt | 22 ++++++++++ .../otlp/otlp_http_log_exporter_options.h | 4 +- .../otlp_grpc_log_exporter_factory_test.cc | 40 +++++++++++++++++ .../otlp_http_log_exporter_factory_test.cc | 44 +++++++++++++++++++ 5 files changed, 140 insertions(+), 2 deletions(-) create mode 100644 exporters/otlp/test/otlp_grpc_log_exporter_factory_test.cc create mode 100644 exporters/otlp/test/otlp_http_log_exporter_factory_test.cc diff --git a/exporters/otlp/BUILD b/exporters/otlp/BUILD index d447aaa073..c4270f47ed 100644 --- a/exporters/otlp/BUILD +++ b/exporters/otlp/BUILD @@ -329,6 +329,22 @@ cc_test( ], ) +cc_test( + name = "otlp_http_log_exporter_factory_test", + srcs = ["test/otlp_http_log_exporter_factory_test.cc"], + tags = [ + "otlp", + "otlp_http_log", + "test", + ], + deps = [ + ":otlp_http_log_exporter", + "//api", + "//ext/src/http/client/nosend:http_client_nosend", + "@com_google_googletest//:gtest_main", + ], +) + cc_test( name = "otlp_http_metric_exporter_test", srcs = ["test/otlp_http_metric_exporter_test.cc"], @@ -361,6 +377,22 @@ cc_test( ], ) +cc_test( + name = "otlp_grpc_log_exporter_factory_test", + srcs = ["test/otlp_grpc_log_exporter_factory_test.cc"], + tags = [ + "otlp", + "otlp_grpc_log", + "test", + ], + deps = [ + ":otlp_grpc_log_exporter", + "//api", + "//sdk/src/logs", + "@com_google_googletest//:gtest_main", + ], +) + otel_cc_benchmark( name = "otlp_grpc_exporter_benchmark", srcs = ["test/otlp_grpc_exporter_benchmark.cc"], diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index 10de697dc1..c822859ee3 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -218,6 +218,17 @@ if(BUILD_TESTING) TARGET otlp_grpc_log_exporter_test TEST_PREFIX exporter.otlp. TEST_LIST otlp_grpc_log_exporter_test) + + add_executable(otlp_grpc_log_exporter_factory_test + test/otlp_grpc_log_exporter_factory_test.cc) + target_link_libraries( + otlp_grpc_log_exporter_factory_test ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIB} + opentelemetry_exporter_otlp_grpc_log opentelemetry_logs) + gtest_add_tests( + TARGET otlp_grpc_log_exporter_factory_test + TEST_PREFIX exporter.otlp. + TEST_LIST otlp_grpc_log_exporter_factory_test) endif() endif() @@ -256,6 +267,17 @@ if(BUILD_TESTING) TARGET otlp_http_log_exporter_test TEST_PREFIX exporter.otlp. TEST_LIST otlp_http_log_exporter_test) + + add_executable(otlp_http_log_exporter_factory_test + test/otlp_http_log_exporter_factory_test.cc) + target_link_libraries( + otlp_http_log_exporter_factory_test ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIB} + opentelemetry_exporter_otlp_http_log opentelemetry_logs) + gtest_add_tests( + TARGET otlp_http_log_exporter_factory_test + TEST_PREFIX exporter.otlp. + TEST_LIST otlp_http_log_exporter_factory_test) endif() if(NOT WITH_METRICS_PREVIEW) diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter_options.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter_options.h index 7c145a648d..daea975b1c 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter_options.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter_options.h @@ -4,8 +4,8 @@ #pragma once #ifdef ENABLE_LOGS_PREVIEW -# include "opentelemetry/exporters/otlp/otlp_http_client.h" - +# include "opentelemetry/exporters/otlp/otlp_environment.h" +# include "opentelemetry/exporters/otlp/otlp_http.h" # include "opentelemetry/sdk/logs/exporter.h" # include diff --git a/exporters/otlp/test/otlp_grpc_log_exporter_factory_test.cc b/exporters/otlp/test/otlp_grpc_log_exporter_factory_test.cc new file mode 100644 index 0000000000..98f42721f1 --- /dev/null +++ b/exporters/otlp/test/otlp_grpc_log_exporter_factory_test.cc @@ -0,0 +1,40 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifdef ENABLE_LOGS_PREVIEW + +# include + +# include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" +# include "opentelemetry/exporters/otlp/otlp_grpc_log_exporter_factory.h" + +/* + Make sure OtlpGrpcLogExporterFactory 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(OtlpGrpcLogExporterFactoryTest, BuildTest) +{ + OtlpGrpcExporterOptions opts; + opts.endpoint = "localhost:45454"; + + std::unique_ptr exporter = + OtlpGrpcLogExporterFactory::Create(opts); + + EXPECT_TRUE(exporter != nullptr); +} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE + +#endif // ENABLE_LOGS_PREVIEW diff --git a/exporters/otlp/test/otlp_http_log_exporter_factory_test.cc b/exporters/otlp/test/otlp_http_log_exporter_factory_test.cc new file mode 100644 index 0000000000..9ab9feef29 --- /dev/null +++ b/exporters/otlp/test/otlp_http_log_exporter_factory_test.cc @@ -0,0 +1,44 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include + +#include "opentelemetry/exporters/otlp/otlp_http_log_exporter_factory.h" +#include "opentelemetry/exporters/otlp/otlp_http_log_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(OtlpHttpLogExporterFactoryTest, BuildTest) +{ + OtlpHttpLogExporterOptions opts; + opts.url = "localhost:45454"; + + std::unique_ptr exporter = + OtlpHttpLogExporterFactory::Create(opts); + + EXPECT_TRUE(exporter != nullptr); +} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE From fa5dd8d7c4eebb5f7430d7e89575787170422c2e Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Mon, 1 Aug 2022 21:51:13 +0200 Subject: [PATCH 7/7] Fix log sdk builder (#1486) Fixed build break. --- .../otlp_http_log_exporter_factory_test.cc | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/exporters/otlp/test/otlp_http_log_exporter_factory_test.cc b/exporters/otlp/test/otlp_http_log_exporter_factory_test.cc index 9ab9feef29..3d54a3fa9b 100644 --- a/exporters/otlp/test/otlp_http_log_exporter_factory_test.cc +++ b/exporters/otlp/test/otlp_http_log_exporter_factory_test.cc @@ -1,26 +1,28 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include +#ifdef ENABLE_LOGS_PREVIEW -#include "opentelemetry/exporters/otlp/otlp_http_log_exporter_factory.h" -#include "opentelemetry/exporters/otlp/otlp_http_log_exporter_options.h" +# include + +# include "opentelemetry/exporters/otlp/otlp_http_log_exporter_factory.h" +# include "opentelemetry/exporters/otlp/otlp_http_log_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 */ +# 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 +# ifdef GOOGLE_PROTOBUF_VERSION +# error "protobuf should not be included" +# endif OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -42,3 +44,5 @@ TEST(OtlpHttpLogExporterFactoryTest, BuildTest) } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE + +#endif // ENABLE_LOGS_PREVIEW