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