diff --git a/CHANGELOG.md b/CHANGELOG.md index a5beedc28c..bbeccf4ecb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -286,7 +286,11 @@ update the semantic convention in instrumentation library is needed. [#873](https://github.com/open-telemetry/opentelemetry-cpp/pull/873) >>>>>>> d9ad0afb (Add automatically semantic conventions from the spec (#873) (#1497)) - ## [1.5.0] 2022-07-29 +## [1.5.0] 2022-07-29 + +``` +## [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) diff --git a/examples/otlp/grpc_log_main.cc b/examples/otlp/grpc_log_main.cc index 2dcfd92f1a..39e5a0a64e 100644 --- a/examples/otlp/grpc_log_main.cc +++ b/examples/otlp/grpc_log_main.cc @@ -3,10 +3,17 @@ #ifdef ENABLE_LOGS_PREVIEW # include "opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h" +<<<<<<< HEAD # include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h" # include "opentelemetry/logs/provider.h" # include "opentelemetry/sdk/logs/logger_provider_factory.h" # include "opentelemetry/sdk/logs/simple_log_record_processor_factory.h" +======= +# include "opentelemetry/exporters/otlp/otlp_grpc_log_exporter_factory.h" +# include "opentelemetry/logs/provider.h" +# include "opentelemetry/sdk/logs/logger_provider_factory.h" +# include "opentelemetry/sdk/logs/simple_log_processor_factory.h" +>>>>>>> efd9596f (Fix log sdk builder (#1486) (#1524)) # include "opentelemetry/sdk/trace/simple_processor_factory.h" # include "opentelemetry/sdk/trace/tracer_provider_factory.h" # include "opentelemetry/trace/provider.h" @@ -43,8 +50,13 @@ void InitTracer() void InitLogger() { // Create OTLP exporter instance +<<<<<<< HEAD auto exporter = otlp::OtlpGrpcLogRecordExporterFactory::Create(opts); auto processor = logs_sdk::SimpleLogRecordProcessorFactory::Create(std::move(exporter)); +======= + auto exporter = otlp::OtlpGrpcLogExporterFactory::Create(opts); + auto processor = logs_sdk::SimpleLogProcessorFactory::Create(std::move(exporter)); +>>>>>>> efd9596f (Fix log sdk builder (#1486) (#1524)) nostd::shared_ptr provider( logs_sdk::LoggerProviderFactory::Create(std::move(processor))); diff --git a/examples/otlp/http_log_main.cc b/examples/otlp/http_log_main.cc index ed52389f6e..1d77b7e0a0 100644 --- a/examples/otlp/http_log_main.cc +++ b/examples/otlp/http_log_main.cc @@ -3,11 +3,19 @@ #ifdef ENABLE_LOGS_PREVIEW # include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.h" +<<<<<<< HEAD # include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h" # include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h" # include "opentelemetry/logs/provider.h" # include "opentelemetry/sdk/logs/logger_provider_factory.h" # include "opentelemetry/sdk/logs/simple_log_record_processor_factory.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_factory.h" +# include "opentelemetry/sdk/logs/simple_log_processor_factory.h" +>>>>>>> efd9596f (Fix log sdk builder (#1486) (#1524)) # include "opentelemetry/sdk/trace/simple_processor_factory.h" # include "opentelemetry/sdk/trace/tracer_provider_factory.h" # include "opentelemetry/trace/provider.h" @@ -47,8 +55,13 @@ void InitLogger() { logger_opts.console_debug = true; // Create OTLP exporter instance +<<<<<<< HEAD auto exporter = otlp::OtlpHttpLogRecordExporterFactory::Create(logger_opts); auto processor = logs_sdk::SimpleLogRecordProcessorFactory::Create(std::move(exporter)); +======= + auto exporter = otlp::OtlpHttpLogExporterFactory::Create(logger_opts); + auto processor = logs_sdk::SimpleLogProcessorFactory::Create(std::move(exporter)); +>>>>>>> efd9596f (Fix log sdk builder (#1486) (#1524)) std::shared_ptr provider = logs_sdk::LoggerProviderFactory::Create(std::move(processor)); diff --git a/exporters/otlp/BUILD b/exporters/otlp/BUILD index 30479c7452..9703941d16 100644 --- a/exporters/otlp/BUILD +++ b/exporters/otlp/BUILD @@ -171,6 +171,7 @@ cc_library( cc_library( name = "otlp_grpc_metric_exporter", srcs = [ +<<<<<<< HEAD "src/otlp_grpc_metric_exporter.cc", "src/otlp_grpc_metric_exporter_factory.cc", ], @@ -237,6 +238,16 @@ cc_library( "include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h", "include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h", "include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h", +======= + "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", +>>>>>>> efd9596f (Fix log sdk builder (#1486) (#1524)) "include/opentelemetry/exporters/otlp/protobuf_include_prefix.h", "include/opentelemetry/exporters/otlp/protobuf_include_suffix.h", ], @@ -284,14 +295,24 @@ cc_library( name = "otlp_grpc_log_exporter", >>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487)) srcs = [ +<<<<<<< HEAD "src/otlp_grpc_log_record_exporter.cc", "src/otlp_grpc_log_record_exporter_factory.cc", +======= + "src/otlp_grpc_log_exporter.cc", + "src/otlp_grpc_log_exporter_factory.cc", +>>>>>>> efd9596f (Fix log sdk builder (#1486) (#1524)) ], hdrs = [ "include/opentelemetry/exporters/otlp/otlp_environment.h", "include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h", +<<<<<<< HEAD "include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h", "include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h", +======= + "include/opentelemetry/exporters/otlp/otlp_grpc_log_exporter.h", + "include/opentelemetry/exporters/otlp/otlp_grpc_log_exporter_factory.h", +>>>>>>> efd9596f (Fix log sdk builder (#1486) (#1524)) "include/opentelemetry/exporters/otlp/protobuf_include_prefix.h", "include/opentelemetry/exporters/otlp/protobuf_include_suffix.h", ], @@ -501,6 +522,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"], @@ -533,6 +570,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 6fb7a7f679..2755078f2d 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -63,9 +63,14 @@ if(WITH_OTLP_GRPC) list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_grpc) add_library( +<<<<<<< HEAD opentelemetry_exporter_otlp_grpc_log src/otlp_grpc_log_record_exporter.cc src/otlp_grpc_log_record_exporter_factory.cc) +======= + opentelemetry_exporter_otlp_grpc_log src/otlp_grpc_log_exporter.cc + src/otlp_grpc_log_exporter_factory.cc) +>>>>>>> efd9596f (Fix log sdk builder (#1486) (#1524)) set_target_properties(opentelemetry_exporter_otlp_grpc_log PROPERTIES EXPORT_NAME otlp_grpc_log_record_exporter) @@ -130,8 +135,12 @@ if(WITH_OTLP_HTTP) if(WITH_LOGS_PREVIEW) add_library( opentelemetry_exporter_otlp_http_log +<<<<<<< HEAD src/otlp_http_log_record_exporter.cc src/otlp_http_log_record_exporter_factory.cc) +======= + src/otlp_http_log_exporter.cc src/otlp_http_log_exporter_factory.cc) +>>>>>>> efd9596f (Fix log sdk builder (#1486) (#1524)) set_target_properties(opentelemetry_exporter_otlp_http_log PROPERTIES EXPORT_NAME otlp_http_log_record_exporter) @@ -269,6 +278,7 @@ if(BUILD_TESTING) gtest_add_tests( TARGET otlp_grpc_log_record_exporter_test TEST_PREFIX exporter.otlp. +<<<<<<< HEAD TEST_LIST otlp_grpc_log_record_exporter_test) add_executable(otlp_grpc_log_record_exporter_factory_test @@ -281,6 +291,20 @@ if(BUILD_TESTING) TARGET otlp_grpc_log_record_exporter_factory_test TEST_PREFIX exporter.otlp. TEST_LIST otlp_grpc_log_record_exporter_factory_test) +======= + 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) +>>>>>>> efd9596f (Fix log sdk builder (#1486) (#1524)) endif() add_executable(otlp_grpc_metric_exporter_factory_test @@ -330,6 +354,7 @@ if(BUILD_TESTING) gtest_add_tests( TARGET otlp_http_log_record_exporter_test TEST_PREFIX exporter.otlp. +<<<<<<< HEAD TEST_LIST otlp_http_log_record_exporter_test) add_executable(otlp_http_log_record_exporter_factory_test @@ -342,6 +367,20 @@ if(BUILD_TESTING) TARGET otlp_http_log_record_exporter_factory_test TEST_PREFIX exporter.otlp. TEST_LIST otlp_http_log_record_exporter_factory_test) +======= + 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) +>>>>>>> efd9596f (Fix log sdk builder (#1486) (#1524)) endif() <<<<<<< HEAD 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_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..daea975b1c --- /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_environment.h" +# include "opentelemetry/exporters/otlp/otlp_http.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/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h index 2c3fe829e0..bfcde36cd0 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h @@ -5,8 +5,12 @@ #ifdef ENABLE_LOGS_PREVIEW # include "opentelemetry/exporters/otlp/otlp_environment.h" +<<<<<<< HEAD:exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h # include "opentelemetry/exporters/otlp/otlp_http.h" # include "opentelemetry/sdk/logs/exporter.h" +======= +# include "opentelemetry/exporters/otlp/otlp_http_log_exporter_options.h" +>>>>>>> efd9596f (Fix log sdk builder (#1486) (#1524)):exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter.h # include # include @@ -20,6 +24,7 @@ namespace otlp { /** +<<<<<<< HEAD:exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h * Struct to hold OTLP exporter options. */ struct OtlpHttpLogRecordExporterOptions @@ -63,6 +68,8 @@ struct OtlpHttpLogRecordExporterOptions <<<<<<< HEAD:exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h ======= /** +======= +>>>>>>> efd9596f (Fix log sdk builder (#1486) (#1524)):exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter.h * The OTLP exporter exports log data in OpenTelemetry Protocol (OTLP) format. */ class OtlpHttpLogExporter final : public opentelemetry::sdk::logs::LogExporter 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..9e90070844 --- /dev/null +++ b/exporters/otlp/src/otlp_grpc_log_exporter_factory.cc @@ -0,0 +1,35 @@ +// 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" + +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/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..3d54a3fa9b --- /dev/null +++ b/exporters/otlp/test/otlp_http_log_exporter_factory_test.cc @@ -0,0 +1,48 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifdef ENABLE_LOGS_PREVIEW + +# 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 + +#endif // ENABLE_LOGS_PREVIEW 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/batch_log_record_processor.h b/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor.h index 0621316dcd..d874478e6b 100644 --- a/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor.h +++ b/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor.h @@ -5,7 +5,11 @@ #ifdef ENABLE_LOGS_PREVIEW # include "opentelemetry/sdk/common/circular_buffer.h" +<<<<<<< HEAD:sdk/include/opentelemetry/sdk/logs/batch_log_record_processor.h # include "opentelemetry/sdk/logs/batch_log_record_processor_options.h" +======= +# include "opentelemetry/sdk/logs/batch_log_processor_options.h" +>>>>>>> efd9596f (Fix log sdk builder (#1486) (#1524)):sdk/include/opentelemetry/sdk/logs/batch_log_processor.h # include "opentelemetry/sdk/logs/exporter.h" # include "opentelemetry/sdk/logs/processor.h" @@ -23,10 +27,17 @@ namespace logs { /** +<<<<<<< HEAD:sdk/include/opentelemetry/sdk/logs/batch_log_record_processor.h * This is an implementation of the LogRecordProcessor which creates batches of finished logs and * passes the export-friendly log data representations to the configured LogRecordExporter. */ class BatchLogRecordProcessor : public LogRecordProcessor +======= + * 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. + */ +class BatchLogProcessor : public LogProcessor +>>>>>>> efd9596f (Fix log sdk builder (#1486) (#1524)):sdk/include/opentelemetry/sdk/logs/batch_log_processor.h { public: /** diff --git a/sdk/include/opentelemetry/sdk/logs/logger_context_factory.h b/sdk/include/opentelemetry/sdk/logs/logger_context_factory.h index 28dc24d56c..68c2037f3e 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger_context_factory.h +++ b/sdk/include/opentelemetry/sdk/logs/logger_context_factory.h @@ -26,13 +26,21 @@ class LoggerContextFactory * Create a LoggerContext. */ static std::unique_ptr Create( +<<<<<<< HEAD std::vector> &&processors); +======= + std::vector> &&processors); +>>>>>>> efd9596f (Fix log sdk builder (#1486) (#1524)) /** * Create a LoggerContext. */ static std::unique_ptr Create( +<<<<<<< HEAD std::vector> &&processors, +======= + std::vector> &&processors, +>>>>>>> efd9596f (Fix log sdk builder (#1486) (#1524)) const opentelemetry::sdk::resource::Resource &resource); }; diff --git a/sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h b/sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h index e103fce8be..3e88bd2f15 100644 --- a/sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h +++ b/sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h @@ -31,26 +31,42 @@ class LoggerProviderFactory * Create a LoggerProvider. */ static std::unique_ptr Create( +<<<<<<< HEAD std::unique_ptr &&processor); +======= + std::unique_ptr &&processor); +>>>>>>> efd9596f (Fix log sdk builder (#1486) (#1524)) /** * Create a LoggerProvider. */ static std::unique_ptr Create( +<<<<<<< HEAD std::unique_ptr &&processor, +======= + std::unique_ptr &&processor, +>>>>>>> efd9596f (Fix log sdk builder (#1486) (#1524)) const opentelemetry::sdk::resource::Resource &resource); /** * Create a LoggerProvider. */ static std::unique_ptr Create( +<<<<<<< HEAD std::vector> &&processors); +======= + std::vector> &&processors); +>>>>>>> efd9596f (Fix log sdk builder (#1486) (#1524)) /** * Create a LoggerProvider. */ static std::unique_ptr Create( +<<<<<<< HEAD std::vector> &&processors, +======= + std::vector> &&processors, +>>>>>>> efd9596f (Fix log sdk builder (#1486) (#1524)) const opentelemetry::sdk::resource::Resource &resource); /** 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 546e66614b..2ea3e2c1c7 100644 --- a/sdk/src/logs/CMakeLists.txt +++ b/sdk/src/logs/CMakeLists.txt @@ -3,6 +3,7 @@ add_library( logger_provider.cc logger_provider_factory.cc logger.cc +<<<<<<< HEAD simple_log_record_processor.cc simple_log_record_processor_factory.cc batch_log_record_processor.cc @@ -11,6 +12,16 @@ add_library( logger_context_factory.cc multi_log_record_processor.cc multi_log_record_processor_factory.cc +======= + simple_log_processor.cc + simple_log_processor_factory.cc + 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 +>>>>>>> efd9596f (Fix log sdk builder (#1486) (#1524)) 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_context_factory.cc b/sdk/src/logs/logger_context_factory.cc index 985743fd67..9a8fdbc731 100644 --- a/sdk/src/logs/logger_context_factory.cc +++ b/sdk/src/logs/logger_context_factory.cc @@ -15,14 +15,22 @@ namespace logs { std::unique_ptr LoggerContextFactory::Create( +<<<<<<< HEAD std::vector> &&processors) +======= + std::vector> &&processors) +>>>>>>> efd9596f (Fix log sdk builder (#1486) (#1524)) { auto resource = opentelemetry::sdk::resource::Resource::Create({}); return Create(std::move(processors), resource); } std::unique_ptr LoggerContextFactory::Create( +<<<<<<< HEAD std::vector> &&processors, +======= + std::vector> &&processors, +>>>>>>> efd9596f (Fix log sdk builder (#1486) (#1524)) const opentelemetry::sdk::resource::Resource &resource) { std::unique_ptr context(new LoggerContext(std::move(processors), resource)); diff --git a/sdk/src/logs/logger_provider_factory.cc b/sdk/src/logs/logger_provider_factory.cc index 3177b9180e..d633805d0b 100644 --- a/sdk/src/logs/logger_provider_factory.cc +++ b/sdk/src/logs/logger_provider_factory.cc @@ -14,14 +14,22 @@ namespace logs { std::unique_ptr LoggerProviderFactory::Create( +<<<<<<< HEAD std::unique_ptr &&processor) +======= + std::unique_ptr &&processor) +>>>>>>> efd9596f (Fix log sdk builder (#1486) (#1524)) { auto resource = opentelemetry::sdk::resource::Resource::Create({}); return Create(std::move(processor), resource); } std::unique_ptr LoggerProviderFactory::Create( +<<<<<<< HEAD std::unique_ptr &&processor, +======= + std::unique_ptr &&processor, +>>>>>>> efd9596f (Fix log sdk builder (#1486) (#1524)) const opentelemetry::sdk::resource::Resource &resource) { std::unique_ptr provider( @@ -30,14 +38,22 @@ std::unique_ptr LoggerProviderFactory::Crea } std::unique_ptr LoggerProviderFactory::Create( +<<<<<<< HEAD std::vector> &&processors) +======= + std::vector> &&processors) +>>>>>>> efd9596f (Fix log sdk builder (#1486) (#1524)) { auto resource = opentelemetry::sdk::resource::Resource::Create({}); return Create(std::move(processors), resource); } std::unique_ptr LoggerProviderFactory::Create( +<<<<<<< HEAD std::vector> &&processors, +======= + std::vector> &&processors, +>>>>>>> efd9596f (Fix log sdk builder (#1486) (#1524)) const opentelemetry::sdk::resource::Resource &resource) { std::unique_ptr provider( 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