diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index efc01e2a00..99d9e1d60a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -160,6 +160,40 @@ jobs: run: | (cd ./functional/otlp; ./run_test.sh) + cmake_clang_yaml_config: + name: CMake clang 18 (maintainer mode, yaml config) + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + with: + submodules: 'recursive' + - name: setup + env: + CC: /usr/bin/clang-18 + CXX: /usr/bin/clang++-18 + PROTOBUF_VERSION: 21.12 + run: | + sudo apt remove needrestart #refer: https://github.com/actions/runner-images/issues/9937 + sudo -E ./ci/setup_googletest.sh + sudo -E ./ci/setup_ci_environment.sh + sudo -E ./ci/install_protobuf.sh + sudo -E ./ci/install_ryml.sh + - name: run cmake clang (maintainer mode, sync) + env: + CC: /usr/bin/clang-18 + CXX: /usr/bin/clang++-18 + run: | + ./ci/do_ci.sh cmake.maintainer.yaml.test + - name: generate test cert + env: + CFSSL_VERSION: 1.6.3 + run: | + sudo -E ./tools/setup-cfssl.sh + (cd ./functional/cert; ./generate_cert.sh) + - name: run func test + run: | + (cd ./functional/otlp; ./run_test.sh) + cmake_clang_maintainer_async_test: name: CMake clang 18 (maintainer mode, async) runs-on: ubuntu-24.04 diff --git a/.github/workflows/clang-tidy.yaml b/.github/workflows/clang-tidy.yaml index b467c56d44..7a0d0c3520 100644 --- a/.github/workflows/clang-tidy.yaml +++ b/.github/workflows/clang-tidy.yaml @@ -32,6 +32,7 @@ jobs: libgmock-dev \ libgtest-dev \ libbenchmark-dev + sudo ./ci/install_ryml.sh if ! command -v clang-tidy &> /dev/null; then echo "clang-tidy could not be found" @@ -61,6 +62,7 @@ jobs: -DBUILD_W3CTRACECONTEXT_TEST=ON \ -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ -DWITH_ASYNC_EXPORT_PREVIEW=ON \ + -DWITH_CONFIGURATION=ON \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON - name: Run clang-tidy diff --git a/.github/workflows/iwyu.yml b/.github/workflows/iwyu.yml index ae4c5fb96b..ad432a78dc 100644 --- a/.github/workflows/iwyu.yml +++ b/.github/workflows/iwyu.yml @@ -30,6 +30,7 @@ jobs: libgmock-dev \ libgtest-dev \ libbenchmark-dev + sudo ./ci/install_ryml.sh - name: Prepare CMake run: | @@ -39,6 +40,7 @@ jobs: -DCMAKE_CXX_STANDARD=14 \ -DWITH_STL=CXX14 \ -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="include-what-you-use;-w;-Xiwyu;--mapping_file=${TOPDIR}/.iwyu.imp;" \ + -DWITH_CONFIGURATION=ON \ -DBUILD_TESTING=ON \ -DBUILD_W3CTRACECONTEXT_TEST=ON \ -DWITH_OTLP_GRPC=OFF \ diff --git a/.iwyu.imp b/.iwyu.imp index a9d2c03058..88d4a0348d 100644 --- a/.iwyu.imp +++ b/.iwyu.imp @@ -11,6 +11,16 @@ { "include": ["", "private", "", "public"] }, { "include": ["", "private", "", "public"] }, + # Work around for ryml + { "include": ["", "private", "", "public"] }, + + { "include": ["", "private", "", "public"] }, + { "include": ["", "private", "", "public"] }, + { "include": ["", "private", "", "public"] }, + { "include": ["", "private", "", "public"] }, + { "include": ["", "private", "", "public"] }, + { "include": ["", "private", "", "public"] }, + # Local opentelemetry-cpp style # We prefer to include for simplicity diff --git a/CMakeLists.txt b/CMakeLists.txt index bf093f2caf..8c617d9d81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,6 +116,8 @@ endif() option(WITH_ABI_VERSION_1 "ABI version 1" ON) option(WITH_ABI_VERSION_2 "EXPERIMENTAL: ABI version 2 preview" OFF) +option(WITH_CONFIGURATION "EXPERIMENTAL: YAML configuration file" OFF) + file(READ "${CMAKE_CURRENT_LIST_DIR}/api/include/opentelemetry/version.h" OPENTELEMETRY_CPP_HEADER_VERSION_H) @@ -507,6 +509,18 @@ if((NOT WITH_API_ONLY) AND USE_NLOHMANN_JSON) include(cmake/nlohmann-json.cmake) endif() +# +# Do we need RapidYaml ? +# + +if((NOT WITH_API_ONLY) AND WITH_CONFIGURATION) + find_package(ryml 0.7.2 REQUIRED) + message( + STATUS + "Found ryml: include ${RYML_INCLUDE_DIR}, lib ${RYML_LIB_DIR}, version ${ryml_VERSION}" + ) +endif() + if(OTELCPP_MAINTAINER_MODE) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") message(STATUS "Building with gcc in maintainer mode.") diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 11dbe4ef80..7b48d20bd2 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -204,6 +204,29 @@ elif [[ "$1" == "cmake.maintainer.abiv2.test" ]]; then eval "$MAKE_COMMAND" make test exit 0 +elif [[ "$1" == "cmake.maintainer.yaml.test" ]]; then + cd "${BUILD_DIR}" + rm -rf * + cmake "${CMAKE_OPTIONS[@]}" \ + -DWITH_OTLP_HTTP=ON \ + -DWITH_OTLP_FILE=ON \ + -DWITH_PROMETHEUS=ON \ + -DWITH_EXAMPLES=ON \ + -DWITH_EXAMPLES_HTTP=ON \ + -DWITH_ZIPKIN=ON \ + -DBUILD_W3CTRACECONTEXT_TEST=ON \ + -DWITH_ELASTICSEARCH=ON \ + -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ + -DWITH_ASYNC_EXPORT_PREVIEW=OFF \ + -DOTELCPP_MAINTAINER_MODE=ON \ + -DWITH_NO_DEPRECATED_CODE=ON \ + -DWITH_OTLP_HTTP_COMPRESSION=ON \ + -DWITH_CONFIGURATION=ON \ + ${IWYU} \ + "${SRC_DIR}" + eval "$MAKE_COMMAND" + make test + exit 0 elif [[ "$1" == "cmake.with_async_export.test" ]]; then cd "${BUILD_DIR}" rm -rf * diff --git a/ci/install_ryml.sh b/ci/install_ryml.sh new file mode 100755 index 0000000000..6f94229f9c --- /dev/null +++ b/ci/install_ryml.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +set -ex +export DEBIAN_FRONTEND=noninteractive +[ -z "${RYML_VERSION}" ] && export RYML_VERSION="v0.7.2" + +BUILD_DIR=/tmp/ +INSTALL_DIR=/usr/local/ +pushd $BUILD_DIR +git clone --recursive -b ${RYML_VERSION} https://github.com/biojppm/rapidyaml.git + +cd rapidyaml +RYML_BUILD_OPTIONS=( + "-DBUILD_TESTING=OFF" + "-DCMAKE_POSITION_INDEPENDENT_CODE=ON" + "-DCMAKE_INSTALL_PREFIX=$INSTALL_DIR" +) + +if [ ! -z "${CXX_STANDARD}" ]; then + RYML_BUILD_OPTIONS=(${RYML_BUILD_OPTIONS[@]} "-DCMAKE_CXX_STANDARD=${CXX_STANDARD}") +fi + +mkdir build && pushd build +cmake "${RYML_BUILD_OPTIONS[@]}" .. +make -j $(nproc) +make install +popd +popd +export PATH=${INSTALL_DIR}/bin:$PATH # ensure to use the installed ryml diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 6a237af982..b0c857797b 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -29,3 +29,7 @@ add_subdirectory(multi_processor) if(WITH_EXAMPLES_HTTP) add_subdirectory(http) endif() + +if(WITH_CONFIGURATION) + add_subdirectory(yaml) +endif() diff --git a/examples/yaml/CMakeLists.txt b/examples/yaml/CMakeLists.txt new file mode 100644 index 0000000000..f0f1ad8c57 --- /dev/null +++ b/examples/yaml/CMakeLists.txt @@ -0,0 +1,59 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +if(DEFINED OPENTELEMETRY_BUILD_DLL) + add_definitions(-DOPENTELEMETRY_BUILD_IMPORT_DLL) +endif() + +include_directories(${CMAKE_SOURCE_DIR}/sdk/include) + +add_executable( + example_yaml + main.cc + custom_sampler.cc + custom_sampler_builder.cc + custom_span_exporter.cc + custom_span_exporter_builder.cc + custom_span_processor.cc + custom_span_processor_builder.cc) + +target_link_libraries( + example_yaml + ${CMAKE_THREAD_LIBS_INIT} + common_metrics_foo_library + common_logs_foo_library + opentelemetry_exporter_ostream_span + opentelemetry_exporter_ostream_metrics + opentelemetry_exporter_ostream_logs) + +if(WITH_OTLP_HTTP) + include_directories(${CMAKE_SOURCE_DIR}/exporters/otlp/include) + add_definitions(-DOTEL_HAVE_OTLP_HTTP) + target_link_libraries(example_yaml opentelemetry_otlp_http_builder) +endif() + +if(WITH_OTLP_GRPC) + include_directories(${CMAKE_SOURCE_DIR}/exporters/otlp/include) + add_definitions(-DOTEL_HAVE_OTLP_GRPC) + target_link_libraries(example_yaml opentelemetry_otlp_grpc_builder) +endif() + +if(WITH_ZIPKIN) + include_directories(${CMAKE_SOURCE_DIR}/exporters/zipkin/include) + add_definitions(-DOTEL_HAVE_ZIPKIN) + target_link_libraries(example_yaml opentelemetry_exporter_zipkin_trace) +endif() + +if(WITH_PROMETHEUS) + include_directories(${CMAKE_SOURCE_DIR}/exporters/prometheus/include) + add_definitions(-DOTEL_HAVE_PROMETHEUS) + target_link_libraries(example_yaml opentelemetry_exporter_prometheus) +endif() + +if(DEFINED OPENTELEMETRY_BUILD_DLL) + target_link_libraries(example_yaml opentelemetry_cpp) +else() + target_link_libraries( + example_yaml opentelemetry_configuration opentelemetry_init + opentelemetry_common opentelemetry_trace opentelemetry_logs) +endif() diff --git a/examples/yaml/anchors.yaml b/examples/yaml/anchors.yaml new file mode 100644 index 0000000000..b0ce674278 --- /dev/null +++ b/examples/yaml/anchors.yaml @@ -0,0 +1,45 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# anchors.yaml demonstrates anchor substitution to reuse OTLP exporter configuration across signals. + +file_format: "0.1" +exporters: + otlp: &otlp-exporter + protocol: http/protobuf + endpoint: http://localhost:4318 + certificate: /app/cert.pem + client_key: /app/cert.pem + client_certificate: /app/cert.pem + headers: + api-key: !!str 1234 + compression: gzip + timeout: 10000 + +logger_provider: + processors: + - batch: + exporter: + otlp: + # expand the otlp-exporter anchor + <<: *otlp-exporter + +meter_provider: + readers: + - periodic: + interval: 5000 + timeout: 30000 + exporter: + otlp: + # expand the otlp-exporter anchor and add metric specific configuration + <<: *otlp-exporter + temporality_preference: delta + default_histogram_aggregation: base2_exponential_bucket_histogram + +tracer_provider: + processors: + - batch: + exporter: + otlp: + # expand the otlp-exporter anchor + <<: *otlp-exporter diff --git a/examples/yaml/custom_sampler.cc b/examples/yaml/custom_sampler.cc new file mode 100644 index 0000000000..9485a93650 --- /dev/null +++ b/examples/yaml/custom_sampler.cc @@ -0,0 +1,36 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include +#include + +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/trace/span_context.h" +#include "opentelemetry/trace/trace_state.h" + +#include "custom_sampler.h" + +opentelemetry::sdk::trace::SamplingResult CustomSampler::ShouldSample( + const opentelemetry::trace::SpanContext &parent_context, + opentelemetry::trace::TraceId /* trace_id */, + opentelemetry::nostd::string_view /* name */, + opentelemetry::trace::SpanKind /* span_kind */, + const opentelemetry::common::KeyValueIterable & /* attributes */, + const opentelemetry::trace::SpanContextKeyValueIterable & /* links */) noexcept +{ + if (!parent_context.IsValid()) + { + return {opentelemetry::sdk::trace::Decision::RECORD_AND_SAMPLE, nullptr, + opentelemetry::trace::TraceState::GetDefault()}; + } + else + { + return {opentelemetry::sdk::trace::Decision::RECORD_AND_SAMPLE, nullptr, + parent_context.trace_state()}; + } +} + +opentelemetry::nostd::string_view CustomSampler::GetDescription() const noexcept +{ + return "CustomSampler"; +} diff --git a/examples/yaml/custom_sampler.h b/examples/yaml/custom_sampler.h new file mode 100644 index 0000000000..e2d3f8d087 --- /dev/null +++ b/examples/yaml/custom_sampler.h @@ -0,0 +1,31 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/common/key_value_iterable.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/trace/sampler.h" +#include "opentelemetry/trace/span_context.h" +#include "opentelemetry/trace/span_context_kv_iterable.h" +#include "opentelemetry/trace/span_metadata.h" +#include "opentelemetry/trace/trace_id.h" + +class CustomSampler : public opentelemetry::sdk::trace::Sampler +{ +public: + CustomSampler(const std::string & /* comment */) {} + ~CustomSampler() override = default; + + opentelemetry::sdk::trace::SamplingResult ShouldSample( + const opentelemetry::trace::SpanContext &parent_context, + opentelemetry::trace::TraceId trace_id, + opentelemetry::nostd::string_view name, + opentelemetry::trace::SpanKind span_kind, + const opentelemetry::common::KeyValueIterable &attributes, + const opentelemetry::trace::SpanContextKeyValueIterable &links) noexcept override; + + opentelemetry::nostd::string_view GetDescription() const noexcept override; +}; diff --git a/examples/yaml/custom_sampler_builder.cc b/examples/yaml/custom_sampler_builder.cc new file mode 100644 index 0000000000..e36be056db --- /dev/null +++ b/examples/yaml/custom_sampler_builder.cc @@ -0,0 +1,28 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include + +#include "opentelemetry/sdk/configuration/document_node.h" +#include "opentelemetry/sdk/init/registry.h" + +#include "custom_sampler.h" +#include "custom_sampler_builder.h" + +std::unique_ptr CustomSamplerBuilder::Build( + const opentelemetry::sdk::configuration::ExtensionSamplerConfiguration *model) const +{ + // Read yaml attributes + std::string comment = model->node->GetRequiredString("comment"); + + std::unique_ptr sdk(new CustomSampler(comment)); + + return sdk; +} + +static CustomSamplerBuilder singleton; + +void CustomSamplerBuilder::Register(opentelemetry::sdk::init::Registry *registry) +{ + registry->AddExtensionSamplerBuilder("my_custom_sampler", &singleton); +} diff --git a/examples/yaml/custom_sampler_builder.h b/examples/yaml/custom_sampler_builder.h new file mode 100644 index 0000000000..e347a4cc48 --- /dev/null +++ b/examples/yaml/custom_sampler_builder.h @@ -0,0 +1,23 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/extension_sampler_configuration.h" +#include "opentelemetry/sdk/init/extension_sampler_builder.h" +#include "opentelemetry/sdk/init/registry.h" +#include "opentelemetry/sdk/trace/sampler.h" + +class CustomSamplerBuilder : public opentelemetry::sdk::init::ExtensionSamplerBuilder +{ +public: + static void Register(opentelemetry::sdk::init::Registry *registry); + + CustomSamplerBuilder() = default; + ~CustomSamplerBuilder() override = default; + + std::unique_ptr Build( + const opentelemetry::sdk::configuration::ExtensionSamplerConfiguration *model) const override; +}; diff --git a/examples/yaml/custom_span_exporter.cc b/examples/yaml/custom_span_exporter.cc new file mode 100644 index 0000000000..70c2eb4aa7 --- /dev/null +++ b/examples/yaml/custom_span_exporter.cc @@ -0,0 +1,34 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/trace/recordable.h" +#include "opentelemetry/sdk/trace/span_data.h" + +#include "custom_span_exporter.h" + +std::unique_ptr CustomSpanExporter::MakeRecordable() noexcept +{ + return std::unique_ptr( + new opentelemetry::sdk::trace::SpanData); +} + +opentelemetry::sdk::common::ExportResult CustomSpanExporter::Export( + const opentelemetry::nostd::span> + & /* spans */) noexcept +{ + OTEL_INTERNAL_LOG_ERROR("CustomSpanExporter::Export(): FIXME"); + return opentelemetry::sdk::common::ExportResult::kSuccess; +} + +bool CustomSpanExporter::ForceFlush(std::chrono::microseconds /* timeout */) noexcept +{ + OTEL_INTERNAL_LOG_ERROR("CustomSpanExporter::ForceFlush(): FIXME"); + return false; +} + +bool CustomSpanExporter::Shutdown(std::chrono::microseconds /* timeout */) noexcept +{ + OTEL_INTERNAL_LOG_ERROR("CustomSpanExporter::Shutdown(): FIXME"); + return false; +} diff --git a/examples/yaml/custom_span_exporter.h b/examples/yaml/custom_span_exporter.h new file mode 100644 index 0000000000..24797e0b01 --- /dev/null +++ b/examples/yaml/custom_span_exporter.h @@ -0,0 +1,30 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include +#include +#include + +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/sdk/trace/recordable.h" + +class CustomSpanExporter : public opentelemetry::sdk::trace::SpanExporter +{ +public: + CustomSpanExporter(const std::string & /* comment */) {} + ~CustomSpanExporter() override = default; + + std::unique_ptr MakeRecordable() noexcept override; + + opentelemetry::sdk::common::ExportResult Export( + const opentelemetry::nostd::span> + &spans) noexcept override; + + bool ForceFlush(std::chrono::microseconds timeout) noexcept override; + + bool Shutdown(std::chrono::microseconds timeout) noexcept override; +}; diff --git a/examples/yaml/custom_span_exporter_builder.cc b/examples/yaml/custom_span_exporter_builder.cc new file mode 100644 index 0000000000..38e090a8d3 --- /dev/null +++ b/examples/yaml/custom_span_exporter_builder.cc @@ -0,0 +1,30 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include + +#include "opentelemetry/sdk/configuration/document_node.h" +#include "opentelemetry/sdk/configuration/extension_span_exporter_configuration.h" +#include "opentelemetry/sdk/init/registry.h" +#include "opentelemetry/sdk/trace/exporter.h" + +#include "custom_span_exporter.h" +#include "custom_span_exporter_builder.h" + +std::unique_ptr CustomSpanExporterBuilder::Build( + const opentelemetry::sdk::configuration::ExtensionSpanExporterConfiguration *model) const +{ + // Read yaml attributes + std::string comment = model->node->GetRequiredString("comment"); + + std::unique_ptr sdk(new CustomSpanExporter(comment)); + + return sdk; +} + +static CustomSpanExporterBuilder singleton; + +void CustomSpanExporterBuilder::Register(opentelemetry::sdk::init::Registry *registry) +{ + registry->AddExtensionSpanExporterBuilder("my_custom_span_exporter", &singleton); +} diff --git a/examples/yaml/custom_span_exporter_builder.h b/examples/yaml/custom_span_exporter_builder.h new file mode 100644 index 0000000000..c8246942cd --- /dev/null +++ b/examples/yaml/custom_span_exporter_builder.h @@ -0,0 +1,24 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/extension_span_exporter_configuration.h" +#include "opentelemetry/sdk/init/extension_span_exporter_builder.h" +#include "opentelemetry/sdk/init/registry.h" +#include "opentelemetry/sdk/trace/exporter.h" + +class CustomSpanExporterBuilder : public opentelemetry::sdk::init::ExtensionSpanExporterBuilder +{ +public: + static void Register(opentelemetry::sdk::init::Registry *registry); + + CustomSpanExporterBuilder() = default; + ~CustomSpanExporterBuilder() override = default; + + std::unique_ptr Build( + const opentelemetry::sdk::configuration::ExtensionSpanExporterConfiguration *model) + const override; +}; diff --git a/examples/yaml/custom_span_processor.cc b/examples/yaml/custom_span_processor.cc new file mode 100644 index 0000000000..1dea908585 --- /dev/null +++ b/examples/yaml/custom_span_processor.cc @@ -0,0 +1,41 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/trace/recordable.h" +#include "opentelemetry/sdk/trace/span_data.h" +#include "opentelemetry/trace/span_context.h" + +#include "custom_span_processor.h" + +std::unique_ptr +CustomSpanProcessor::MakeRecordable() noexcept +{ + return std::unique_ptr( + new opentelemetry::sdk::trace::SpanData); +} + +void CustomSpanProcessor::OnStart( + opentelemetry::sdk::trace::Recordable & /* span */, + const opentelemetry::trace::SpanContext & /* parent_context */) noexcept +{ + OTEL_INTERNAL_LOG_ERROR("CustomSpanProcessor::OnStart(): FIXME"); +} + +void CustomSpanProcessor::OnEnd( + std::unique_ptr && /* span */) noexcept +{ + OTEL_INTERNAL_LOG_ERROR("CustomSpanProcessor::OnEnd(): FIXME"); +} + +bool CustomSpanProcessor::ForceFlush(std::chrono::microseconds /* timeout */) noexcept +{ + OTEL_INTERNAL_LOG_ERROR("CustomSpanProcessor::ForceFlush(): FIXME"); + return false; +} + +bool CustomSpanProcessor::Shutdown(std::chrono::microseconds /* timeout */) noexcept +{ + OTEL_INTERNAL_LOG_ERROR("CustomSpanProcessor::Shutdown(): FIXME"); + return false; +} diff --git a/examples/yaml/custom_span_processor.h b/examples/yaml/custom_span_processor.h new file mode 100644 index 0000000000..7d0dae38de --- /dev/null +++ b/examples/yaml/custom_span_processor.h @@ -0,0 +1,33 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include +#include +#include + +#include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/recordable.h" +#include "opentelemetry/trace/span_context.h" + +class CustomSpanProcessor : public opentelemetry::sdk::trace::SpanProcessor +{ +public: + CustomSpanProcessor(const std::string &comment) : m_comment(comment) {} + ~CustomSpanProcessor() override = default; + + std::unique_ptr MakeRecordable() noexcept override; + + void OnStart(opentelemetry::sdk::trace::Recordable &span, + const opentelemetry::trace::SpanContext &parent_context) noexcept override; + + void OnEnd(std::unique_ptr &&span) noexcept override; + + bool ForceFlush(std::chrono::microseconds timeout) noexcept override; + + bool Shutdown(std::chrono::microseconds timeout) noexcept override; + +private: + std::string m_comment; +}; diff --git a/examples/yaml/custom_span_processor_builder.cc b/examples/yaml/custom_span_processor_builder.cc new file mode 100644 index 0000000000..9df169230f --- /dev/null +++ b/examples/yaml/custom_span_processor_builder.cc @@ -0,0 +1,30 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include + +#include "opentelemetry/sdk/configuration/document_node.h" +#include "opentelemetry/sdk/configuration/extension_span_processor_configuration.h" +#include "opentelemetry/sdk/init/registry.h" +#include "opentelemetry/sdk/trace/processor.h" + +#include "custom_span_processor.h" +#include "custom_span_processor_builder.h" + +std::unique_ptr CustomSpanProcessorBuilder::Build( + const opentelemetry::sdk::configuration::ExtensionSpanProcessorConfiguration *model) const +{ + // Read yaml attributes + std::string comment = model->node->GetRequiredString("comment"); + + std::unique_ptr sdk(new CustomSpanProcessor(comment)); + + return sdk; +} + +static CustomSpanProcessorBuilder singleton; + +void CustomSpanProcessorBuilder::Register(opentelemetry::sdk::init::Registry *registry) +{ + registry->AddExtensionSpanProcessorBuilder("my_custom_span_processor", &singleton); +} diff --git a/examples/yaml/custom_span_processor_builder.h b/examples/yaml/custom_span_processor_builder.h new file mode 100644 index 0000000000..8438531ab1 --- /dev/null +++ b/examples/yaml/custom_span_processor_builder.h @@ -0,0 +1,24 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/extension_span_processor_configuration.h" +#include "opentelemetry/sdk/init/extension_span_processor_builder.h" +#include "opentelemetry/sdk/init/registry.h" +#include "opentelemetry/sdk/trace/processor.h" + +class CustomSpanProcessorBuilder : public opentelemetry::sdk::init::ExtensionSpanProcessorBuilder +{ +public: + static void Register(opentelemetry::sdk::init::Registry *registry); + + CustomSpanProcessorBuilder() = default; + ~CustomSpanProcessorBuilder() override = default; + + std::unique_ptr Build( + const opentelemetry::sdk::configuration::ExtensionSpanProcessorConfiguration *model) + const override; +}; diff --git a/examples/yaml/extensions.yaml b/examples/yaml/extensions.yaml new file mode 100644 index 0000000000..97a8d0cf4a --- /dev/null +++ b/examples/yaml/extensions.yaml @@ -0,0 +1,58 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# The file format version +file_format: "0.1" + +# Configure if the SDK is disabled or not. This is not required to be provided +# to ensure the SDK isn't disabled, the default value when this is not provided +# is for the SDK to be enabled. +# +# Environment variable: OTEL_SDK_DISABLED +disabled: false + +# Configure text map context propagators. +# +# Environment variable: OTEL_PROPAGATORS +propagator: + # composite: [tracecontext, baggage, b3, b3multi, jaeger, xray, ottrace] + simple: tracecontext + +# Configure tracer provider. +tracer_provider: + # Configure span processors. + processors: + # Configure a batch span processor. + - batch: + # Configure exporter. + # + # Environment variable: OTEL_TRACES_EXPORTER + exporter: + # Configure exporter to be zipkin. + zipkin: + # Configure endpoint. + # + # Environment variable: OTEL_EXPORTER_ZIPKIN_ENDPOINT + endpoint: http://localhost:9411/api/v2/spans + # Configure max time (in milliseconds) to wait for each export. + # + # Environment variable: OTEL_EXPORTER_ZIPKIN_TIMEOUT + timeout: 10000 + # Configure a simple span processor. + - simple: + # Configure exporter. + exporter: + # Configure exporter to be console. + console: {} + - my_custom_span_processor: + comment: "This is a span processor extension point, with properties." + - batch: + exporter: + my_custom_span_exporter: + comment: "This is a span exporter extension point, with properties." + + # Configure the sampler. + sampler: + my_custom_sampler: + comment: "This is a sampler extension point, with properties." + diff --git a/examples/yaml/kitchen-sink.yaml b/examples/yaml/kitchen-sink.yaml new file mode 100644 index 0000000000..ded8bbc08d --- /dev/null +++ b/examples/yaml/kitchen-sink.yaml @@ -0,0 +1,408 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# kitchen-sink.yaml demonstrates all configurable surface area, including explanatory comments. +# +# It DOES NOT represent expected real world configuration, as it makes strange configuration +# choices in an effort to exercise the full surface area. +# +# Configuration values are set to their defaults when default values are defined. + +# The file format version +file_format: "0.1" + +# Configure if the SDK is disabled or not. This is not required to be provided +# to ensure the SDK isn't disabled, the default value when this is not provided +# is for the SDK to be enabled. +# +# Environment variable: OTEL_SDK_DISABLED +disabled: false + +# Configure general attribute limits. See also tracer_provider.limits, logger_provider.limits. +attribute_limits: + # Configure max attribute value size. + # + # Environment variable: OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT + attribute_value_length_limit: 4096 + # Configure max attribute count. + # + # Environment variable: OTEL_ATTRIBUTE_COUNT_LIMIT + attribute_count_limit: 128 + +# Configure logger provider. +logger_provider: + # Configure log record processors. + processors: + # Configure a batch log record processor. + - batch: + # Configure delay interval (in milliseconds) between two consecutive exports. + # + # Environment variable: OTEL_BLRP_SCHEDULE_DELAY + schedule_delay: 5000 + # Configure maximum allowed time (in milliseconds) to export data. + # + # Environment variable: OTEL_BLRP_EXPORT_TIMEOUT + export_timeout: 30000 + # Configure maximum queue size. + # + # Environment variable: OTEL_BLRP_MAX_QUEUE_SIZE + max_queue_size: 2048 + # Configure maximum batch size. + # + # Environment variable: OTEL_BLRP_MAX_EXPORT_BATCH_SIZE + max_export_batch_size: 512 + # Configure exporter. + # + # Environment variable: OTEL_LOGS_EXPORTER + exporter: + # Configure exporter to be OTLP. + otlp: + # Configure protocol. + # + # Environment variable: OTEL_EXPORTER_OTLP_PROTOCOL, OTEL_EXPORTER_OTLP_LOGS_PROTOCOL + protocol: http/protobuf + # Configure endpoint. + # + # Environment variable: OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_LOGS_ENDPOINT + endpoint: http://localhost:4318 + # Configure certificate. + # + # Environment variable: OTEL_EXPORTER_OTLP_CERTIFICATE, OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE + certificate: /app/cert.pem + # Configure mTLS private client key. + # + # Environment variable: OTEL_EXPORTER_OTLP_CLIENT_KEY, OTEL_EXPORTER_OTLP_LOGS_CLIENT_KEY + client_key: /app/cert.pem + # Configure mTLS client certificate. + # + # Environment variable: OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE, OTEL_EXPORTER_OTLP_LOGS_CLIENT_CERTIFICATE + client_certificate: /app/cert.pem + # Configure headers. + # + # Environment variable: OTEL_EXPORTER_OTLP_HEADERS, OTEL_EXPORTER_OTLP_LOGS_HEADERS + headers: + api-key: "1234" + # Configure compression. + # + # Environment variable: OTEL_EXPORTER_OTLP_COMPRESSION, OTEL_EXPORTER_OTLP_LOGS_COMPRESSION + compression: gzip + # Configure max time (in milliseconds) to wait for each export. + # + # Environment variable: OTEL_EXPORTER_OTLP_TIMEOUT, OTEL_EXPORTER_OTLP_LOGS_TIMEOUT + timeout: 10000 + # Configure client transport security for the exporter's connection. + # + # Environment variable: OTEL_EXPORTER_OTLP_INSECURE, OTEL_EXPORTER_OTLP_LOGS_INSECURE + insecure: false + # Configure a simple log record processor. + - simple: + # Configure exporter. + exporter: + # Configure exporter to be console. + console: {} + # Configure log record limits. See also attribute_limits. + limits: + # Configure max log record attribute value size. Overrides attribute_limits.attribute_value_length_limit. + # + # Environment variable: OTEL_LOGRECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT + attribute_value_length_limit: 4096 + # Configure max log record attribute count. Overrides attribute_limits.attribute_count_limit. + # + # Environment variable: OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT + attribute_count_limit: 128 + +# Configure meter provider. +meter_provider: + # Configure metric readers. + readers: + # Configure a pull-based metric reader. + - pull: + # Configure exporter. + # + # Environment variable: OTEL_METRICS_EXPORTER + exporter: + # Configure exporter to be prometheus. + prometheus: + # Configure host. + # + # Environment variable: OTEL_EXPORTER_PROMETHEUS_HOST + host: localhost + # Configure port. + # + # Environment variable: OTEL_EXPORTER_PROMETHEUS_PORT + port: 9464 + # Configure Prometheus Exporter to produce metrics without a unit suffix or UNIT metadata. + without_units: false + # Configure Prometheus Exporter to produce metrics without a type suffix. + without_type_suffix: false + # Configure Prometheus Exporter to produce metrics without a scope info metric. + without_scope_info: false + # Configure a periodic metric reader. + - periodic: + # Configure delay interval (in milliseconds) between start of two consecutive exports. + # + # Environment variable: OTEL_METRIC_EXPORT_INTERVAL + interval: 5000 + # Configure maximum allowed time (in milliseconds) to export data. + # + # Environment variable: OTEL_METRIC_EXPORT_TIMEOUT + timeout: 30000 + # Configure exporter. + # + # Environment variable: OTEL_METRICS_EXPORTER + exporter: + # Configure exporter to be OTLP. + otlp: + # Configure protocol. + # + # Environment variable: OTEL_EXPORTER_OTLP_PROTOCOL, OTEL_EXPORTER_OTLP_METRICS_PROTOCOL + protocol: http/protobuf + # Configure endpoint. + # + # Environment variable: OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_METRICS_ENDPOINT + endpoint: http://localhost:4318 + # Configure certificate. + # + # Environment variable: OTEL_EXPORTER_OTLP_CERTIFICATE, OTEL_EXPORTER_OTLP_METRICS_CERTIFICATE + certificate: /app/cert.pem + # Configure mTLS private client key. + # + # Environment variable: OTEL_EXPORTER_OTLP_CLIENT_KEY, OTEL_EXPORTER_OTLP_METRICS_CLIENT_KEY + client_key: /app/cert.pem + # Configure mTLS client certificate. + # + # Environment variable: OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE, OTEL_EXPORTER_OTLP_METRICS_CLIENT_CERTIFICATE + client_certificate: /app/cert.pem + # Configure headers. + # + # Environment variable: OTEL_EXPORTER_OTLP_HEADERS, OTEL_EXPORTER_OTLP_METRICS_HEADERS + headers: + api-key: !!str 1234 + # Configure compression. + # + # Environment variable: OTEL_EXPORTER_OTLP_COMPRESSION, OTEL_EXPORTER_OTLP_METRICS_COMPRESSION + compression: gzip + # Configure max time (in milliseconds) to wait for each export. + # + # Environment variable: OTEL_EXPORTER_OTLP_TIMEOUT, OTEL_EXPORTER_OTLP_METRICS_TIMEOUT + timeout: 10000 + # Configure client transport security for the exporter's connection. + # + # Environment variable: OTEL_EXPORTER_OTLP_INSECURE, OTEL_EXPORTER_OTLP_METRICS_INSECURE + insecure: false + # Configure temporality preference. + # + # Environment variable: OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE + temporality_preference: delta + # Configure default histogram aggregation. + # + # Environment variable: OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION + default_histogram_aggregation: base2_exponential_bucket_histogram + # Configure a periodic metric reader. + - periodic: + # Configure exporter. + exporter: + # Configure exporter to be console. + console: {} + # Configure views. Each view has a selector which determines the instrument(s) it applies to, and a configuration for the resulting stream(s). + views: + # Configure a view. + - selector: + # Configure instrument name selection criteria. + instrument_name: my-instrument + # Configure instrument type selection criteria. + instrument_type: histogram + # Configure the instrument unit selection criteria. + unit: ms + # Configure meter name selection criteria. + meter_name: my-meter + # Configure meter version selection criteria. + meter_version: 1.0.0 + # Configure meter schema url selection criteria. + meter_schema_url: https://opentelemetry.io/schemas/1.16.0 + # Configure stream. + stream: + # Configure metric name of the resulting stream(s). + name: new_instrument_name + # Configure metric description of the resulting stream(s). + description: new_description + # Configure aggregation of the resulting stream(s). Known values include: default, drop, explicit_bucket_histogram, base2_exponential_bucket_histogram, last_value, sum. + aggregation: + # Configure aggregation to be explicit_bucket_histogram. + explicit_bucket_histogram: + # Configure bucket boundaries. + boundaries: [ 0.0, 5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 250.0, 500.0, 750.0, 1000.0, 2500.0, 5000.0, 7500.0, 10000.0 ] + # Configure record min and max. + record_min_max: true + # Configure attribute keys retained in the resulting stream(s). + attribute_keys: + - key1 + - key2 + +# Configure text map context propagators. +# +# Environment variable: OTEL_PROPAGATORS +propagator: + # composite: [tracecontext, baggage, b3, b3multi, jaeger, xray, ottrace] + composite: [tracecontext, baggage, b3, b3multi, jaeger] + +# Configure tracer provider. +tracer_provider: + # Configure span processors. + processors: + # Configure a batch span processor. + - batch: + # Configure delay interval (in milliseconds) between two consecutive exports. + # + # Environment variable: OTEL_BSP_SCHEDULE_DELAY + schedule_delay: 5000 + # Configure maximum allowed time (in milliseconds) to export data. + # + # Environment variable: OTEL_BSP_EXPORT_TIMEOUT + export_timeout: 30000 + # Configure maximum queue size. + # + # Environment variable: OTEL_BSP_MAX_QUEUE_SIZE + max_queue_size: 2048 + # Configure maximum batch size. + # + # Environment variable: OTEL_BSP_MAX_EXPORT_BATCH_SIZE + max_export_batch_size: 512 + # Configure exporter. + # + # Environment variable: OTEL_TRACES_EXPORTER + exporter: + # Configure exporter to be OTLP. + otlp: + # Configure protocol. + # + # Environment variable: OTEL_EXPORTER_OTLP_PROTOCOL, OTEL_EXPORTER_OTLP_TRACES_PROTOCOL + protocol: http/protobuf + # Configure endpoint. + # + # Environment variable: OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_TRACES_ENDPOINT + endpoint: http://localhost:4318 + # Configure certificate. + # + # Environment variable: OTEL_EXPORTER_OTLP_CERTIFICATE, OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE + certificate: /app/cert.pem + # Configure mTLS private client key. + # + # Environment variable: OTEL_EXPORTER_OTLP_CLIENT_KEY, OTEL_EXPORTER_OTLP_TRACES_CLIENT_KEY + client_key: /app/cert.pem + # Configure mTLS client certificate. + # + # Environment variable: OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE, OTEL_EXPORTER_OTLP_TRACES_CLIENT_CERTIFICATE + client_certificate: /app/cert.pem + # Configure headers. + # + # Environment variable: OTEL_EXPORTER_OTLP_HEADERS, OTEL_EXPORTER_OTLP_TRACES_HEADERS + headers: + api-key: !!str 1234 + # Configure compression. + # + # Environment variable: OTEL_EXPORTER_OTLP_COMPRESSION, OTEL_EXPORTER_OTLP_TRACES_COMPRESSION + compression: gzip + # Configure max time (in milliseconds) to wait for each export. + # + # Environment variable: OTEL_EXPORTER_OTLP_TIMEOUT, OTEL_EXPORTER_OTLP_TRACES_TIMEOUT + timeout: 10000 + # Configure client transport security for the exporter's connection. + # + # Environment variable: OTEL_EXPORTER_OTLP_INSECURE, OTEL_EXPORTER_OTLP_TRACES_INSECURE + insecure: false + # Configure a batch span processor. + - batch: + # Configure exporter. + # + # Environment variable: OTEL_TRACES_EXPORTER + exporter: + # Configure exporter to be zipkin. + zipkin: + # Configure endpoint. + # + # Environment variable: OTEL_EXPORTER_ZIPKIN_ENDPOINT + endpoint: http://localhost:9411/api/v2/spans + # Configure max time (in milliseconds) to wait for each export. + # + # Environment variable: OTEL_EXPORTER_ZIPKIN_TIMEOUT + timeout: 10000 + # Configure a simple span processor. + - simple: + # Configure exporter. + exporter: + # Configure exporter to be console. + console: {} + # Configure span limits. See also attribute_limits. + limits: + # Configure max span attribute value size. Overrides attribute_limits.attribute_value_length_limit. + # + # Environment variable: OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT + attribute_value_length_limit: 4096 + # Configure max span attribute count. Overrides attribute_limits.attribute_count_limit. + # + # Environment variable: OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT + attribute_count_limit: 128 + # Configure max span event count. + # + # Environment variable: OTEL_SPAN_EVENT_COUNT_LIMIT + event_count_limit: 128 + # Configure max span link count. + # + # Environment variable: OTEL_SPAN_LINK_COUNT_LIMIT + link_count_limit: 128 + # Configure max attributes per span event. + # + # Environment variable: OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT + event_attribute_count_limit: 128 + # Configure max attributes per span link. + # + # Environment variable: OTEL_LINK_ATTRIBUTE_COUNT_LIMIT + link_attribute_count_limit: 128 + # Configure the sampler. + sampler: + # Configure sampler to be parent_based. Known values include: always_off, always_on, jaeger_remote, parent_based, trace_id_ratio_based. + # + # Environment variable: OTEL_TRACES_SAMPLER=parentbased_* + parent_based: + # Configure root sampler. + # + # Environment variable: OTEL_TRACES_SAMPLER=parentbased_traceidratio + root: + # Configure sampler to be trace_id_ratio_based. + trace_id_ratio_based: + # Configure trace_id_ratio. + # + # Environment variable: OTEL_TRACES_SAMPLER_ARG=traceidratio=0.0001 + ratio: 0.0001 + # Configure remote_parent_sampled sampler. + remote_parent_sampled: + # Configure sampler to be always_on. + always_on: {} + # Configure remote_parent_not_sampled sampler. + remote_parent_not_sampled: + # Configure sampler to be always_off. + always_off: {} + # Configure local_parent_sampled sampler. + local_parent_sampled: + # Configure sampler to be always_on. + always_on: {} + # Configure local_parent_not_sampled sampler. + local_parent_not_sampled: + # Configure sampler to be always_off. + always_off: {} + +# Configure resource for all signals. +resource: + # Configure resource attributes. + # + # Environment variable: OTEL_RESOURCE_ATTRIBUTES + attributes: + # Configure `service.name` resource attribute + # + # Environment variable: OTEL_SERVICE_NAME + service.name: !!str "unknown_service" + foo: the_foo + bar: the_bar + # Configure the resource schema URL. + schema_url: https://opentelemetry.io/schemas/1.16.0 diff --git a/examples/yaml/main.cc b/examples/yaml/main.cc new file mode 100644 index 0000000000..a7a8807454 --- /dev/null +++ b/examples/yaml/main.cc @@ -0,0 +1,208 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include +#include +#include +#include + +#include "opentelemetry/exporters/ostream/console_log_record_builder.h" +#include "opentelemetry/exporters/ostream/console_push_metric_builder.h" +#include "opentelemetry/exporters/ostream/console_span_builder.h" +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/configuration/yaml_configuration_factory.h" +#include "opentelemetry/sdk/init/configured_sdk.h" +#include "opentelemetry/sdk/init/registry.h" + +#include "custom_sampler_builder.h" +#include "custom_span_exporter_builder.h" +#include "custom_span_processor_builder.h" + +#ifdef BAZEL_BUILD +# include "examples/common/logs_foo_library/foo_library.h" +# include "examples/common/metrics_foo_library/foo_library.h" +#else +# include "logs_foo_library/foo_library.h" +# include "metrics_foo_library/foo_library.h" +#endif + +#ifdef OTEL_HAVE_OTLP_HTTP +# include "opentelemetry/exporters/otlp/otlp_http_log_record_builder.h" +# include "opentelemetry/exporters/otlp/otlp_http_push_metric_builder.h" +# include "opentelemetry/exporters/otlp/otlp_http_span_builder.h" +#endif + +#ifdef OTEL_HAVE_OTLP_GRPC +# include "opentelemetry/exporters/otlp/otlp_grpc_log_record_builder.h" +# include "opentelemetry/exporters/otlp/otlp_grpc_push_metric_builder.h" +# include "opentelemetry/exporters/otlp/otlp_grpc_span_builder.h" +#endif + +#ifdef OTEL_HAVE_ZIPKIN +# include "opentelemetry/exporters/zipkin/zipkin_builder.h" +#endif + +#ifdef OTEL_HAVE_PROMETHEUS +# include "opentelemetry/exporters/prometheus/prometheus_pull_builder.h" +#endif + +static bool opt_help = false; +static std::string yaml_file_path = ""; + +std::unique_ptr sdk; + +namespace +{ + +void InitOtel(const std::string &config_file) +{ + auto level = opentelemetry::sdk::common::internal_log::LogLevel::Debug; + + opentelemetry::sdk::common::internal_log::GlobalLogHandler::SetLogLevel(level); + + /* 1 - Create a registry */ + + std::shared_ptr registry( + new opentelemetry::sdk::init::Registry); + + /* 2 - Populate the registry with the core components supported */ + + opentelemetry::exporter::trace::ConsoleSpanBuilder::Register(registry.get()); + opentelemetry::exporter::metrics::ConsolePushMetricBuilder::Register(registry.get()); + opentelemetry::exporter::logs::ConsoleLogRecordBuilder::Register(registry.get()); + +#ifdef OTEL_HAVE_OTLP_HTTP + opentelemetry::exporter::otlp::OtlpHttpSpanBuilder::Register(registry.get()); + opentelemetry::exporter::otlp::OtlpHttpPushMetricBuilder::Register(registry.get()); + opentelemetry::exporter::otlp::OtlpHttpLogRecordBuilder::Register(registry.get()); +#endif + +#ifdef OTEL_HAVE_OTLP_GRPC + opentelemetry::exporter::otlp::OtlpGrpcSpanBuilder::Register(registry.get()); + opentelemetry::exporter::otlp::OtlpGrpcPushMetricBuilder::Register(registry.get()); + opentelemetry::exporter::otlp::OtlpGrpcLogRecordBuilder::Register(registry.get()); +#endif + +#ifdef OTEL_HAVE_ZIPKIN + opentelemetry::exporter::zipkin::ZipkinBuilder::Register(registry.get()); +#endif + +#ifdef OTEL_HAVE_PROMETHEUS + opentelemetry::exporter::metrics::PrometheusPullBuilder::Register(registry.get()); +#endif + + /* 3 - Populate the registry with external extensions plugins */ + + CustomSamplerBuilder::Register(registry.get()); + CustomSpanExporterBuilder::Register(registry.get()); + CustomSpanProcessorBuilder::Register(registry.get()); + + /* 4 - Parse a config.yaml */ + + // See + // https://github.com/open-telemetry/opentelemetry-configuration/blob/main/examples/kitchen-sink.yaml + auto model = opentelemetry::sdk::configuration::YamlConfigurationFactory::ParseFile(config_file); + + /* 5 - Build the SDK from the parsed config.yaml */ + + sdk = opentelemetry::sdk::init::ConfiguredSdk::Create(registry, model); + + /* 6 - Deploy the SDK */ + + if (sdk != nullptr) + { + sdk->Install(); + } +} + +void CleanupOtel() +{ + if (sdk != nullptr) + { + sdk->UnInstall(); + } + sdk.reset(nullptr); +} +} // namespace + +void usage(FILE *out) +{ + static const char *msg = + "Usage: example_yaml [options]\n" + "Valid options are:\n" + " --help Print this help\n" + " --yaml Path to a yaml configuration file\n" + "\n" + "The configuration file used will be:\n" + " 1) the file provided in the command line\n" + " 2) the file provided in environment variable ${OTEL_EXPERIMENTAL_CONFIG_FILE}\n" + " 3) file config.yaml\n"; + + fprintf(out, "%s", msg); +} + +int parse_args(int argc, char *argv[]) +{ + int remaining_argc = argc; + char **remaining_argv = argv; + + while (remaining_argc > 0) + { + if (strcmp(*remaining_argv, "--help") == 0) + { + opt_help = true; + return 0; + } + + if (remaining_argc >= 2) + { + if (strcmp(*remaining_argv, "--yaml") == 0) + { + remaining_argc--; + remaining_argv++; + yaml_file_path = *remaining_argv; + remaining_argc--; + remaining_argv++; + continue; + } + } + + if (remaining_argc) + { + // Unknown option + return 1; + } + } + + return 0; +} + +int main(int argc, char *argv[]) +{ + // Program name + argc--; + argv++; + + int rc = parse_args(argc, argv); + + if (rc != 0) + { + usage(stderr); + return 1; + } + + if (opt_help) + { + usage(stdout); + return 0; + } + + InitOtel(yaml_file_path); + + foo_library(); + foo_library::counter_example("yaml"); + foo_library::observable_counter_example("yaml"); + foo_library::histogram_example("yaml"); + + CleanupOtel(); +} diff --git a/exporters/ostream/BUILD b/exporters/ostream/BUILD index 177bf6a968..36f8ce9316 100644 --- a/exporters/ostream/BUILD +++ b/exporters/ostream/BUILD @@ -6,11 +6,13 @@ package(default_visibility = ["//visibility:public"]) cc_library( name = "ostream_log_record_exporter", srcs = [ + "src/console_log_record_builder.cc", "src/log_record_exporter.cc", "src/log_record_exporter_factory.cc", ], hdrs = [ "include/opentelemetry/exporters/ostream/common_utils.h", + "include/opentelemetry/exporters/ostream/console_log_record_builder.h", "include/opentelemetry/exporters/ostream/log_record_exporter.h", "include/opentelemetry/exporters/ostream/log_record_exporter_factory.h", ], @@ -37,11 +39,13 @@ cc_test( cc_library( name = "ostream_metric_exporter", srcs = [ + "src/console_push_metric_builder.cc", "src/metric_exporter.cc", "src/metric_exporter_factory.cc", ], hdrs = [ "include/opentelemetry/exporters/ostream/common_utils.h", + "include/opentelemetry/exporters/ostream/console_push_metric_builder.h", "include/opentelemetry/exporters/ostream/metric_exporter.h", "include/opentelemetry/exporters/ostream/metric_exporter_factory.h", ], @@ -71,11 +75,13 @@ cc_test( cc_library( name = "ostream_span_exporter", srcs = [ + "src/console_span_builder.cc", "src/span_exporter.cc", "src/span_exporter_factory.cc", ], hdrs = [ "include/opentelemetry/exporters/ostream/common_utils.h", + "include/opentelemetry/exporters/ostream/console_span_builder.h", "include/opentelemetry/exporters/ostream/span_exporter.h", "include/opentelemetry/exporters/ostream/span_exporter_factory.h", ], diff --git a/exporters/ostream/CMakeLists.txt b/exporters/ostream/CMakeLists.txt index e08d6592a3..8ba58a8cba 100644 --- a/exporters/ostream/CMakeLists.txt +++ b/exporters/ostream/CMakeLists.txt @@ -1,8 +1,9 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 -add_library(opentelemetry_exporter_ostream_span src/span_exporter.cc - src/span_exporter_factory.cc) +add_library( + opentelemetry_exporter_ostream_span + src/span_exporter.cc src/span_exporter_factory.cc src/console_span_builder.cc) set_target_properties(opentelemetry_exporter_ostream_span PROPERTIES EXPORT_NAME ostream_span_exporter) @@ -40,8 +41,10 @@ if(BUILD_TESTING) TEST_LIST ostream_span_test) endif() # BUILD_TESTING -add_library(opentelemetry_exporter_ostream_metrics - src/metric_exporter.cc src/metric_exporter_factory.cc) +add_library( + opentelemetry_exporter_ostream_metrics + src/metric_exporter.cc src/metric_exporter_factory.cc + src/console_push_metric_builder.cc) set_target_properties(opentelemetry_exporter_ostream_metrics PROPERTIES EXPORT_NAME ostream_metrics_exporter) set_target_version(opentelemetry_exporter_ostream_metrics) @@ -76,8 +79,10 @@ if(BUILD_TESTING) TEST_LIST ostream_metric_test) endif() -add_library(opentelemetry_exporter_ostream_logs - src/log_record_exporter.cc src/log_record_exporter_factory.cc) +add_library( + opentelemetry_exporter_ostream_logs + src/log_record_exporter.cc src/log_record_exporter_factory.cc + src/console_log_record_builder.cc) set_target_properties(opentelemetry_exporter_ostream_logs PROPERTIES EXPORT_NAME ostream_log_record_exporter) set_target_version(opentelemetry_exporter_ostream_logs) diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/console_log_record_builder.h b/exporters/ostream/include/opentelemetry/exporters/ostream/console_log_record_builder.h new file mode 100644 index 0000000000..a5ae66fcb2 --- /dev/null +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/console_log_record_builder.h @@ -0,0 +1,36 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/console_log_record_exporter_configuration.h" +#include "opentelemetry/sdk/init/console_log_record_exporter_builder.h" +#include "opentelemetry/sdk/init/registry.h" +#include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace logs +{ + +class OPENTELEMETRY_EXPORT ConsoleLogRecordBuilder + : public opentelemetry::sdk::init::ConsoleLogRecordExporterBuilder +{ +public: + static void Register(opentelemetry::sdk::init::Registry *registry); + + ConsoleLogRecordBuilder() = default; + ~ConsoleLogRecordBuilder() override = default; + + std::unique_ptr Build( + const opentelemetry::sdk::configuration::ConsoleLogRecordExporterConfiguration *model) + const override; +}; + +} // namespace logs +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/console_push_metric_builder.h b/exporters/ostream/include/opentelemetry/exporters/ostream/console_push_metric_builder.h new file mode 100644 index 0000000000..4c411e30cc --- /dev/null +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/console_push_metric_builder.h @@ -0,0 +1,36 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/console_push_metric_exporter_configuration.h" +#include "opentelemetry/sdk/init/console_push_metric_exporter_builder.h" +#include "opentelemetry/sdk/init/registry.h" +#include "opentelemetry/sdk/metrics/push_metric_exporter.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace metrics +{ + +class OPENTELEMETRY_EXPORT ConsolePushMetricBuilder + : public opentelemetry::sdk::init::ConsolePushMetricExporterBuilder +{ +public: + static void Register(opentelemetry::sdk::init::Registry *registry); + + ConsolePushMetricBuilder() = default; + ~ConsolePushMetricBuilder() override = default; + + std::unique_ptr Build( + const opentelemetry::sdk::configuration::ConsolePushMetricExporterConfiguration *model) + const override; +}; + +} // namespace metrics +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/console_span_builder.h b/exporters/ostream/include/opentelemetry/exporters/ostream/console_span_builder.h new file mode 100644 index 0000000000..356d180d87 --- /dev/null +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/console_span_builder.h @@ -0,0 +1,36 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/console_span_exporter_configuration.h" +#include "opentelemetry/sdk/init/console_span_exporter_builder.h" +#include "opentelemetry/sdk/init/registry.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace trace +{ + +class OPENTELEMETRY_EXPORT ConsoleSpanBuilder + : public opentelemetry::sdk::init::ConsoleSpanExporterBuilder +{ +public: + static void Register(opentelemetry::sdk::init::Registry *registry); + + ConsoleSpanBuilder() = default; + ~ConsoleSpanBuilder() override = default; + + std::unique_ptr Build( + const opentelemetry::sdk::configuration::ConsoleSpanExporterConfiguration *model) + const override; +}; + +} // namespace trace +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/ostream/src/console_log_record_builder.cc b/exporters/ostream/src/console_log_record_builder.cc new file mode 100644 index 0000000000..3f78c02cff --- /dev/null +++ b/exporters/ostream/src/console_log_record_builder.cc @@ -0,0 +1,30 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/ostream/console_log_record_builder.h" +#include "opentelemetry/exporters/ostream/log_record_exporter_factory.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace logs +{ + +static ConsoleLogRecordBuilder singleton; + +void ConsoleLogRecordBuilder::Register(opentelemetry::sdk::init::Registry *registry) +{ + registry->SetConsoleLogRecordBuilder(&singleton); +} + +std::unique_ptr ConsoleLogRecordBuilder::Build( + const opentelemetry::sdk::configuration::ConsoleLogRecordExporterConfiguration * /* model */) + const +{ + return OStreamLogRecordExporterFactory::Create(); +} + +} // namespace logs +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/ostream/src/console_push_metric_builder.cc b/exporters/ostream/src/console_push_metric_builder.cc new file mode 100644 index 0000000000..8b053a660b --- /dev/null +++ b/exporters/ostream/src/console_push_metric_builder.cc @@ -0,0 +1,30 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/ostream/console_push_metric_builder.h" +#include "opentelemetry/exporters/ostream/metric_exporter_factory.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace metrics +{ + +static ConsolePushMetricBuilder singleton; + +void ConsolePushMetricBuilder::Register(opentelemetry::sdk::init::Registry *registry) +{ + registry->SetConsolePushMetricExporterBuilder(&singleton); +} + +std::unique_ptr ConsolePushMetricBuilder::Build( + const opentelemetry::sdk::configuration::ConsolePushMetricExporterConfiguration * /* model */) + const +{ + return OStreamMetricExporterFactory::Create(); +} + +} // namespace metrics +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/ostream/src/console_span_builder.cc b/exporters/ostream/src/console_span_builder.cc new file mode 100644 index 0000000000..8e61234d27 --- /dev/null +++ b/exporters/ostream/src/console_span_builder.cc @@ -0,0 +1,29 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/ostream/console_span_builder.h" +#include "opentelemetry/exporters/ostream/span_exporter_factory.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace trace +{ + +static ConsoleSpanBuilder singleton; + +void ConsoleSpanBuilder::Register(opentelemetry::sdk::init::Registry *registry) +{ + registry->SetConsoleSpanBuilder(&singleton); +} + +std::unique_ptr ConsoleSpanBuilder::Build( + const opentelemetry::sdk::configuration::ConsoleSpanExporterConfiguration * /* model */) const +{ + return OStreamSpanExporterFactory::Create(); +} + +} // namespace trace +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/BUILD b/exporters/otlp/BUILD index eb3d23d579..936fee02c0 100644 --- a/exporters/otlp/BUILD +++ b/exporters/otlp/BUILD @@ -76,6 +76,7 @@ cc_library( "src/otlp_grpc_exporter.cc", "src/otlp_grpc_exporter_factory.cc", "src/otlp_grpc_exporter_options.cc", + "src/otlp_grpc_span_builder.cc", ], hdrs = [ "include/opentelemetry/exporters/otlp/otlp_environment.h", @@ -83,6 +84,7 @@ cc_library( "include/opentelemetry/exporters/otlp/otlp_grpc_exporter.h", "include/opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h", "include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h", + "include/opentelemetry/exporters/otlp/otlp_grpc_span_builder.h", "include/opentelemetry/exporters/otlp/otlp_grpc_utils.h", "include/opentelemetry/exporters/otlp/protobuf_include_prefix.h", "include/opentelemetry/exporters/otlp/protobuf_include_suffix.h", @@ -149,12 +151,14 @@ cc_library( "src/otlp_http_exporter.cc", "src/otlp_http_exporter_factory.cc", "src/otlp_http_exporter_options.cc", + "src/otlp_http_span_builder.cc", ], hdrs = [ "include/opentelemetry/exporters/otlp/otlp_environment.h", "include/opentelemetry/exporters/otlp/otlp_http_exporter.h", "include/opentelemetry/exporters/otlp/otlp_http_exporter_factory.h", "include/opentelemetry/exporters/otlp/otlp_http_exporter_options.h", + "include/opentelemetry/exporters/otlp/otlp_http_span_builder.h", "include/opentelemetry/exporters/otlp/protobuf_include_prefix.h", "include/opentelemetry/exporters/otlp/protobuf_include_suffix.h", ], @@ -232,6 +236,7 @@ cc_library( "src/otlp_grpc_metric_exporter.cc", "src/otlp_grpc_metric_exporter_factory.cc", "src/otlp_grpc_metric_exporter_options.cc", + "src/otlp_grpc_push_metric_builder.cc", ], hdrs = [ "include/opentelemetry/exporters/otlp/otlp_environment.h", @@ -239,6 +244,7 @@ cc_library( "include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h", "include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h", "include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h", + "include/opentelemetry/exporters/otlp/otlp_grpc_push_metric_builder.h", "include/opentelemetry/exporters/otlp/protobuf_include_prefix.h", "include/opentelemetry/exporters/otlp/protobuf_include_suffix.h", ], @@ -264,12 +270,14 @@ cc_library( "src/otlp_http_metric_exporter.cc", "src/otlp_http_metric_exporter_factory.cc", "src/otlp_http_metric_exporter_options.cc", + "src/otlp_http_push_metric_builder.cc", ], hdrs = [ "include/opentelemetry/exporters/otlp/otlp_environment.h", "include/opentelemetry/exporters/otlp/otlp_http_metric_exporter.h", "include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h", "include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h", + "include/opentelemetry/exporters/otlp/otlp_http_push_metric_builder.h", "include/opentelemetry/exporters/otlp/protobuf_include_prefix.h", "include/opentelemetry/exporters/otlp/protobuf_include_suffix.h", ], @@ -317,12 +325,14 @@ cc_library( cc_library( name = "otlp_http_log_record_exporter", srcs = [ + "src/otlp_http_log_record_builder.cc", "src/otlp_http_log_record_exporter.cc", "src/otlp_http_log_record_exporter_factory.cc", "src/otlp_http_log_record_exporter_options.cc", ], hdrs = [ "include/opentelemetry/exporters/otlp/otlp_environment.h", + "include/opentelemetry/exporters/otlp/otlp_http_log_record_builder.h", "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", @@ -373,6 +383,7 @@ cc_library( cc_library( name = "otlp_grpc_log_record_exporter", srcs = [ + "src/otlp_grpc_log_record_builder.cc", "src/otlp_grpc_log_record_exporter.cc", "src/otlp_grpc_log_record_exporter_factory.cc", "src/otlp_grpc_log_record_exporter_options.cc", @@ -380,6 +391,7 @@ cc_library( hdrs = [ "include/opentelemetry/exporters/otlp/otlp_environment.h", "include/opentelemetry/exporters/otlp/otlp_grpc_client_options.h", + "include/opentelemetry/exporters/otlp/otlp_grpc_log_record_builder.h", "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_record_exporter_options.h", diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index 34da75b563..a1ebf3972d 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -269,6 +269,58 @@ target_link_libraries( opentelemetry_otlp_recordable PUBLIC opentelemetry_trace opentelemetry_resources opentelemetry_proto) +if(WITH_OTLP_HTTP) + add_library( + opentelemetry_otlp_http_builder + src/otlp_http_span_builder.cc src/otlp_http_push_metric_builder.cc + src/otlp_http_log_record_builder.cc) + set_target_properties(opentelemetry_otlp_http_builder + PROPERTIES EXPORT_NAME otlp_http_builder) + set_target_version(opentelemetry_otlp_http_builder) + + target_include_directories( + opentelemetry_otlp_http_builder + PUBLIC "$" + "$") + + # Make sure to build with the proper ABI + target_link_libraries(opentelemetry_otlp_http_builder + PUBLIC opentelemetry_api) + + target_link_libraries(opentelemetry_otlp_http_builder + PUBLIC opentelemetry_exporter_otlp_http) + target_link_libraries(opentelemetry_otlp_http_builder + PUBLIC opentelemetry_exporter_otlp_http_metric) + target_link_libraries(opentelemetry_otlp_http_builder + PUBLIC opentelemetry_exporter_otlp_http_log) +endif() + +if(WITH_OTLP_GRPC) + add_library( + opentelemetry_otlp_grpc_builder + src/otlp_grpc_span_builder.cc src/otlp_grpc_push_metric_builder.cc + src/otlp_grpc_log_record_builder.cc) + set_target_properties(opentelemetry_otlp_grpc_builder + PROPERTIES EXPORT_NAME otlp_grpc_builder) + set_target_version(opentelemetry_otlp_grpc_builder) + + target_include_directories( + opentelemetry_otlp_grpc_builder + PUBLIC "$" + "$") + + # Make sure to build with the proper ABI + target_link_libraries(opentelemetry_otlp_grpc_builder + PUBLIC opentelemetry_api) + + target_link_libraries(opentelemetry_otlp_grpc_builder + PUBLIC opentelemetry_exporter_otlp_grpc) + target_link_libraries(opentelemetry_otlp_grpc_builder + PUBLIC opentelemetry_exporter_otlp_grpc_metrics) + target_link_libraries(opentelemetry_otlp_grpc_builder + PUBLIC opentelemetry_exporter_otlp_grpc_log) +endif() + if(OPENTELEMETRY_INSTALL) install( TARGETS ${OPENTELEMETRY_OTLP_TARGETS} diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_builder.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_builder.h new file mode 100644 index 0000000000..ae8abaf6d3 --- /dev/null +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_builder.h @@ -0,0 +1,36 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/otlp_log_record_exporter_configuration.h" +#include "opentelemetry/sdk/init/otlp_log_record_exporter_builder.h" +#include "opentelemetry/sdk/init/registry.h" +#include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +class OPENTELEMETRY_EXPORT OtlpGrpcLogRecordBuilder + : public opentelemetry::sdk::init::OtlpLogRecordExporterBuilder +{ +public: + static void Register(opentelemetry::sdk::init::Registry *registry); + + OtlpGrpcLogRecordBuilder() = default; + ~OtlpGrpcLogRecordBuilder() override = default; + + std::unique_ptr Build( + const opentelemetry::sdk::configuration::OtlpLogRecordExporterConfiguration *model) + const override; +}; + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_push_metric_builder.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_push_metric_builder.h new file mode 100644 index 0000000000..59236783a3 --- /dev/null +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_push_metric_builder.h @@ -0,0 +1,36 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/otlp_push_metric_exporter_configuration.h" +#include "opentelemetry/sdk/init/otlp_push_metric_exporter_builder.h" +#include "opentelemetry/sdk/init/registry.h" +#include "opentelemetry/sdk/metrics/push_metric_exporter.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +class OPENTELEMETRY_EXPORT OtlpGrpcPushMetricBuilder + : public opentelemetry::sdk::init::OtlpPushMetricExporterBuilder +{ +public: + static void Register(opentelemetry::sdk::init::Registry *registry); + + OtlpGrpcPushMetricBuilder() = default; + ~OtlpGrpcPushMetricBuilder() override = default; + + std::unique_ptr Build( + const opentelemetry::sdk::configuration::OtlpPushMetricExporterConfiguration *model) + const override; +}; + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_span_builder.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_span_builder.h new file mode 100644 index 0000000000..6932f9797f --- /dev/null +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_span_builder.h @@ -0,0 +1,35 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/otlp_span_exporter_configuration.h" +#include "opentelemetry/sdk/init/otlp_span_exporter_builder.h" +#include "opentelemetry/sdk/init/registry.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +class OPENTELEMETRY_EXPORT OtlpGrpcSpanBuilder + : public opentelemetry::sdk::init::OtlpSpanExporterBuilder +{ +public: + static void Register(opentelemetry::sdk::init::Registry *registry); + + OtlpGrpcSpanBuilder() = default; + ~OtlpGrpcSpanBuilder() override = default; + + std::unique_ptr Build( + const opentelemetry::sdk::configuration::OtlpSpanExporterConfiguration *model) const override; +}; + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_options.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_options.h index 7f6d5a1b35..7c6fb25b1f 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_options.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_options.h @@ -27,7 +27,10 @@ namespace otlp */ struct OPENTELEMETRY_EXPORT OtlpHttpExporterOptions { + /** Lookup environment variables. */ OtlpHttpExporterOptions(); + /** No defaults. */ + OtlpHttpExporterOptions(void * /* raw */); ~OtlpHttpExporterOptions(); /** The endpoint to export to. */ diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_builder.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_builder.h new file mode 100644 index 0000000000..edcb8d30a7 --- /dev/null +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_builder.h @@ -0,0 +1,36 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/otlp_log_record_exporter_configuration.h" +#include "opentelemetry/sdk/init/otlp_log_record_exporter_builder.h" +#include "opentelemetry/sdk/init/registry.h" +#include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +class OPENTELEMETRY_EXPORT OtlpHttpLogRecordBuilder + : public opentelemetry::sdk::init::OtlpLogRecordExporterBuilder +{ +public: + static void Register(opentelemetry::sdk::init::Registry *registry); + + OtlpHttpLogRecordBuilder() = default; + ~OtlpHttpLogRecordBuilder() override = default; + + std::unique_ptr Build( + const opentelemetry::sdk::configuration::OtlpLogRecordExporterConfiguration *model) + const override; +}; + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_push_metric_builder.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_push_metric_builder.h new file mode 100644 index 0000000000..8e694da82b --- /dev/null +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_push_metric_builder.h @@ -0,0 +1,36 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/otlp_push_metric_exporter_configuration.h" +#include "opentelemetry/sdk/init/otlp_push_metric_exporter_builder.h" +#include "opentelemetry/sdk/init/registry.h" +#include "opentelemetry/sdk/metrics/push_metric_exporter.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +class OPENTELEMETRY_EXPORT OtlpHttpPushMetricBuilder + : public opentelemetry::sdk::init::OtlpPushMetricExporterBuilder +{ +public: + static void Register(opentelemetry::sdk::init::Registry *registry); + + OtlpHttpPushMetricBuilder() = default; + ~OtlpHttpPushMetricBuilder() override = default; + + std::unique_ptr Build( + const opentelemetry::sdk::configuration::OtlpPushMetricExporterConfiguration *model) + const override; +}; + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_span_builder.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_span_builder.h new file mode 100644 index 0000000000..d91cd4395f --- /dev/null +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_span_builder.h @@ -0,0 +1,35 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/otlp_span_exporter_configuration.h" +#include "opentelemetry/sdk/init/otlp_span_exporter_builder.h" +#include "opentelemetry/sdk/init/registry.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +class OPENTELEMETRY_EXPORT OtlpHttpSpanBuilder + : public opentelemetry::sdk::init::OtlpSpanExporterBuilder +{ +public: + static void Register(opentelemetry::sdk::init::Registry *registry); + + OtlpHttpSpanBuilder() = default; + ~OtlpHttpSpanBuilder() override = default; + + std::unique_ptr Build( + const opentelemetry::sdk::configuration::OtlpSpanExporterConfiguration *model) const override; +}; + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_grpc_log_record_builder.cc b/exporters/otlp/src/otlp_grpc_log_record_builder.cc new file mode 100644 index 0000000000..cdac0f74e7 --- /dev/null +++ b/exporters/otlp/src/otlp_grpc_log_record_builder.cc @@ -0,0 +1,32 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/otlp/otlp_grpc_log_record_builder.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +static OtlpGrpcLogRecordBuilder singleton; + +void OtlpGrpcLogRecordBuilder::Register(opentelemetry::sdk::init::Registry *registry) +{ + registry->SetOtlpGrpcLogRecordBuilder(&singleton); +} + +std::unique_ptr OtlpGrpcLogRecordBuilder::Build( + const opentelemetry::sdk::configuration::OtlpLogRecordExporterConfiguration * /* model */) const +{ + // FIXME, use model + OtlpGrpcLogRecordExporterOptions options; + return OtlpGrpcLogRecordExporterFactory::Create(options); +} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_grpc_push_metric_builder.cc b/exporters/otlp/src/otlp_grpc_push_metric_builder.cc new file mode 100644 index 0000000000..5712eae070 --- /dev/null +++ b/exporters/otlp/src/otlp_grpc_push_metric_builder.cc @@ -0,0 +1,33 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/otlp/otlp_grpc_push_metric_builder.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +static OtlpGrpcPushMetricBuilder singleton; + +void OtlpGrpcPushMetricBuilder::Register(opentelemetry::sdk::init::Registry *registry) +{ + registry->SetOtlpGrpcPushMetricExporterBuilder(&singleton); +} + +std::unique_ptr OtlpGrpcPushMetricBuilder::Build( + const opentelemetry::sdk::configuration::OtlpPushMetricExporterConfiguration * /* model */) + const +{ + // FIXME, use model + OtlpGrpcMetricExporterOptions options; + return OtlpGrpcMetricExporterFactory::Create(options); +} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_grpc_span_builder.cc b/exporters/otlp/src/otlp_grpc_span_builder.cc new file mode 100644 index 0000000000..29568f3be3 --- /dev/null +++ b/exporters/otlp/src/otlp_grpc_span_builder.cc @@ -0,0 +1,32 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/otlp/otlp_grpc_span_builder.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h" +#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +static OtlpGrpcSpanBuilder singleton; + +void OtlpGrpcSpanBuilder::Register(opentelemetry::sdk::init::Registry *registry) +{ + registry->SetOtlpGrpcSpanBuilder(&singleton); +} + +std::unique_ptr OtlpGrpcSpanBuilder::Build( + const opentelemetry::sdk::configuration::OtlpSpanExporterConfiguration * /* model */) const +{ + // FIXME, use model + OtlpGrpcExporterOptions options; + return OtlpGrpcExporterFactory::Create(options); +} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_http_exporter_options.cc b/exporters/otlp/src/otlp_http_exporter_options.cc index f6f7027f50..2a51a57ced 100644 --- a/exporters/otlp/src/otlp_http_exporter_options.cc +++ b/exporters/otlp/src/otlp_http_exporter_options.cc @@ -39,6 +39,33 @@ OtlpHttpExporterOptions::OtlpHttpExporterOptions() #endif /* ENABLE_ASYNC_EXPORT */ } +OtlpHttpExporterOptions::OtlpHttpExporterOptions(void *) + : url(), + content_type(HttpRequestContentType::kBinary), + json_bytes_mapping(JsonBytesMappingKind::kHexId), + use_json_name(false), + console_debug(false), + timeout(0), + http_headers(), + ssl_insecure_skip_verify(false), + ssl_ca_cert_path(), + ssl_ca_cert_string(), + ssl_client_key_path(), + ssl_client_key_string(), + ssl_client_cert_path(), + ssl_client_cert_string(), + ssl_min_tls(), + ssl_max_tls(), + ssl_cipher(), + ssl_cipher_suite(), + compression() +{ +#ifdef ENABLE_ASYNC_EXPORT + max_concurrent_requests = 64; + max_requests_per_connection = 8; +#endif /* ENABLE_ASYNC_EXPORT */ +} + OtlpHttpExporterOptions::~OtlpHttpExporterOptions() {} } // namespace otlp diff --git a/exporters/otlp/src/otlp_http_log_record_builder.cc b/exporters/otlp/src/otlp_http_log_record_builder.cc new file mode 100644 index 0000000000..e224bcb099 --- /dev/null +++ b/exporters/otlp/src/otlp_http_log_record_builder.cc @@ -0,0 +1,32 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/otlp/otlp_http_log_record_builder.h" +#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h" +#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +static OtlpHttpLogRecordBuilder singleton; + +void OtlpHttpLogRecordBuilder::Register(opentelemetry::sdk::init::Registry *registry) +{ + registry->SetOtlpHttpLogRecordBuilder(&singleton); +} + +std::unique_ptr OtlpHttpLogRecordBuilder::Build( + const opentelemetry::sdk::configuration::OtlpLogRecordExporterConfiguration * /* model */) const +{ + // FIXME, use model + OtlpHttpLogRecordExporterOptions options; + return OtlpHttpLogRecordExporterFactory::Create(options); +} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_http_push_metric_builder.cc b/exporters/otlp/src/otlp_http_push_metric_builder.cc new file mode 100644 index 0000000000..9b165577fa --- /dev/null +++ b/exporters/otlp/src/otlp_http_push_metric_builder.cc @@ -0,0 +1,33 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/otlp/otlp_http_push_metric_builder.h" +#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h" +#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +static OtlpHttpPushMetricBuilder singleton; + +void OtlpHttpPushMetricBuilder::Register(opentelemetry::sdk::init::Registry *registry) +{ + registry->SetOtlpHttpPushMetricExporterBuilder(&singleton); +} + +std::unique_ptr OtlpHttpPushMetricBuilder::Build( + const opentelemetry::sdk::configuration::OtlpPushMetricExporterConfiguration * /* model */) + const +{ + // FIXME, use model + OtlpHttpMetricExporterOptions options; + return OtlpHttpMetricExporterFactory::Create(options); +} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_http_span_builder.cc b/exporters/otlp/src/otlp_http_span_builder.cc new file mode 100644 index 0000000000..2328486381 --- /dev/null +++ b/exporters/otlp/src/otlp_http_span_builder.cc @@ -0,0 +1,43 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include +#include + +#include "opentelemetry/exporters/otlp/otlp_http.h" +#include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.h" +#include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h" +#include "opentelemetry/exporters/otlp/otlp_http_span_builder.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +static OtlpHttpSpanBuilder singleton; + +void OtlpHttpSpanBuilder::Register(opentelemetry::sdk::init::Registry *registry) +{ + registry->SetOtlpHttpSpanBuilder(&singleton); +} + +std::unique_ptr OtlpHttpSpanBuilder::Build( + const opentelemetry::sdk::configuration::OtlpSpanExporterConfiguration *model) const +{ + OtlpHttpExporterOptions options(nullptr); + options.url = model->endpoint; + options.content_type = GetOtlpHttpProtocolFromString(model->protocol); + options.timeout = std::chrono::duration_cast( + std::chrono::seconds{model->timeout}); + // options.http_headers = model->xxx; + options.ssl_ca_cert_path = model->certificate; + options.ssl_client_key_path = model->client_key; + options.ssl_client_cert_path = model->client_certificate; + return OtlpHttpExporterFactory::Create(options); +} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_metric_utils.cc b/exporters/otlp/src/otlp_metric_utils.cc index 521a7e2f10..36c607230e 100644 --- a/exporters/otlp/src/otlp_metric_utils.cc +++ b/exporters/otlp/src/otlp_metric_utils.cc @@ -18,6 +18,7 @@ #include "opentelemetry/sdk/metrics/data/point_data.h" #include "opentelemetry/sdk/metrics/export/metric_producer.h" #include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/sdk/resource/resource.h" #include "opentelemetry/version.h" // clang-format off diff --git a/exporters/otlp/src/otlp_recordable_utils.cc b/exporters/otlp/src/otlp_recordable_utils.cc index 1be27204c7..b1f2ada401 100644 --- a/exporters/otlp/src/otlp_recordable_utils.cc +++ b/exporters/otlp/src/otlp_recordable_utils.cc @@ -14,7 +14,6 @@ #include "opentelemetry/exporters/otlp/otlp_recordable.h" #include "opentelemetry/exporters/otlp/otlp_recordable_utils.h" #include "opentelemetry/nostd/span.h" -#include "opentelemetry/sdk/common/attribute_utils.h" #include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" #include "opentelemetry/sdk/logs/recordable.h" #include "opentelemetry/sdk/resource/resource.h" diff --git a/exporters/otlp/test/otlp_grpc_exporter_test.cc b/exporters/otlp/test/otlp_grpc_exporter_test.cc index b8c651a8fe..6652f0fb9b 100644 --- a/exporters/otlp/test/otlp_grpc_exporter_test.cc +++ b/exporters/otlp/test/otlp_grpc_exporter_test.cc @@ -103,7 +103,7 @@ class OtlpMockTraceServiceStub : public proto::collector::trace::v1::MockTraceSe OtlpMockTraceServiceStub *stub_; }; - async_interface_base *async() { return &async_interface_; } + async_interface_base *async() override { return &async_interface_; } async_interface_base *experimental_async() { return &async_interface_; } ::grpc::Status GetLastAsyncStatus() const noexcept { return last_async_status_; } diff --git a/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc b/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc index a2604de096..22e7e16b31 100644 --- a/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc @@ -103,7 +103,7 @@ class OtlpMockTraceServiceStub : public proto::collector::trace::v1::MockTraceSe OtlpMockTraceServiceStub *stub_; }; - async_interface_base *async() { return &async_interface_; } + async_interface_base *async() override { return &async_interface_; } async_interface_base *experimental_async() { return &async_interface_; } ::grpc::Status GetLastAsyncStatus() const noexcept { return last_async_status_; } @@ -166,7 +166,7 @@ class OtlpMockLogsServiceStub : public proto::collector::logs::v1::MockLogsServi OtlpMockLogsServiceStub *stub_; }; - async_interface_base *async() { return &async_interface_; } + async_interface_base *async() override { return &async_interface_; } async_interface_base *experimental_async() { return &async_interface_; } ::grpc::Status GetLastAsyncStatus() const noexcept { return last_async_status_; } diff --git a/exporters/otlp/test/otlp_metrics_serialization_test.cc b/exporters/otlp/test/otlp_metrics_serialization_test.cc index 55ab80d0ab..0ec1ffcd83 100644 --- a/exporters/otlp/test/otlp_metrics_serialization_test.cc +++ b/exporters/otlp/test/otlp_metrics_serialization_test.cc @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include diff --git a/exporters/prometheus/BUILD b/exporters/prometheus/BUILD index fc981921d9..0d6aa8c2e3 100644 --- a/exporters/prometheus/BUILD +++ b/exporters/prometheus/BUILD @@ -9,11 +9,13 @@ cc_library( "src/exporter.cc", "src/exporter_factory.cc", "src/exporter_options.cc", + "src/prometheus_pull_builder.cc", ], hdrs = [ "include/opentelemetry/exporters/prometheus/exporter.h", "include/opentelemetry/exporters/prometheus/exporter_factory.h", "include/opentelemetry/exporters/prometheus/exporter_options.h", + "include/opentelemetry/exporters/prometheus/prometheus_pull_builder.h", ], strip_include_prefix = "include", tags = ["prometheus"], diff --git a/exporters/prometheus/CMakeLists.txt b/exporters/prometheus/CMakeLists.txt index 6c872be3ab..f34f46f458 100644 --- a/exporters/prometheus/CMakeLists.txt +++ b/exporters/prometheus/CMakeLists.txt @@ -9,7 +9,7 @@ endif() add_library( opentelemetry_exporter_prometheus src/exporter.cc src/exporter_options.cc src/exporter_factory.cc - src/collector.cc src/exporter_utils.cc) + src/collector.cc src/exporter_utils.cc src/prometheus_pull_builder.cc) set_target_properties(opentelemetry_exporter_prometheus PROPERTIES EXPORT_NAME prometheus_exporter) diff --git a/exporters/prometheus/include/opentelemetry/exporters/prometheus/prometheus_pull_builder.h b/exporters/prometheus/include/opentelemetry/exporters/prometheus/prometheus_pull_builder.h new file mode 100644 index 0000000000..b953feef36 --- /dev/null +++ b/exporters/prometheus/include/opentelemetry/exporters/prometheus/prometheus_pull_builder.h @@ -0,0 +1,36 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/prometheus_pull_metric_exporter_configuration.h" +#include "opentelemetry/sdk/init/prometheus_pull_metric_exporter_builder.h" +#include "opentelemetry/sdk/init/registry.h" +#include "opentelemetry/sdk/metrics/metric_reader.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace metrics +{ + +class OPENTELEMETRY_EXPORT PrometheusPullBuilder + : public opentelemetry::sdk::init::PrometheusPullMetricExporterBuilder +{ +public: + static void Register(opentelemetry::sdk::init::Registry *registry); + + PrometheusPullBuilder() = default; + ~PrometheusPullBuilder() override = default; + + std::unique_ptr Build( + const opentelemetry::sdk::configuration::PrometheusPullMetricExporterConfiguration *model) + const override; +}; + +} // namespace metrics +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/prometheus/src/prometheus_pull_builder.cc b/exporters/prometheus/src/prometheus_pull_builder.cc new file mode 100644 index 0000000000..e8d65fb0d7 --- /dev/null +++ b/exporters/prometheus/src/prometheus_pull_builder.cc @@ -0,0 +1,53 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include +#include + +#include "opentelemetry/exporters/prometheus/exporter_factory.h" +#include "opentelemetry/exporters/prometheus/exporter_options.h" +#include "opentelemetry/exporters/prometheus/prometheus_pull_builder.h" +#include "opentelemetry/sdk/configuration/prometheus_pull_metric_exporter_configuration.h" +#include "opentelemetry/sdk/init/registry.h" +#include "opentelemetry/sdk/metrics/metric_reader.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace metrics +{ + +static PrometheusPullBuilder singleton; + +void PrometheusPullBuilder::Register(opentelemetry::sdk::init::Registry *registry) +{ + registry->SetPrometheusPullMetricExporterBuilder(&singleton); +} + +std::unique_ptr PrometheusPullBuilder::Build( + const opentelemetry::sdk::configuration::PrometheusPullMetricExporterConfiguration + * /* model */) const +{ + opentelemetry::exporter::metrics::PrometheusExporterOptions options; + +#ifdef LATER + // Expected + options.url = model->xxx; + options.populate_target_info = model->xxx; + options.without_otel_scope = model->xxx; + + // Configuration model + options.xxx = model->host; + options.xxx = model->port; + options.xxx = model->without_units; + options.xxx = model->without_type_suffix; + options.xxx = model->without_scope_info; +#endif + + return PrometheusExporterFactory::Create(options); +} + +} // namespace metrics +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/zipkin/BUILD b/exporters/zipkin/BUILD index 16774e80df..8553984450 100644 --- a/exporters/zipkin/BUILD +++ b/exporters/zipkin/BUILD @@ -23,10 +23,12 @@ cc_library( cc_library( name = "zipkin_exporter", srcs = [ + "src/zipkin_builder.cc", "src/zipkin_exporter.cc", "src/zipkin_exporter_factory.cc", ], hdrs = [ + "include/opentelemetry/exporters/zipkin/zipkin_builder.h", "include/opentelemetry/exporters/zipkin/zipkin_exporter.h", "include/opentelemetry/exporters/zipkin/zipkin_exporter_factory.h", "include/opentelemetry/exporters/zipkin/zipkin_exporter_options.h", diff --git a/exporters/zipkin/CMakeLists.txt b/exporters/zipkin/CMakeLists.txt index 60f8a80a2a..e7cf69a38a 100644 --- a/exporters/zipkin/CMakeLists.txt +++ b/exporters/zipkin/CMakeLists.txt @@ -5,7 +5,8 @@ include_directories(include) add_definitions(-DWITH_CURL) add_library( opentelemetry_exporter_zipkin_trace - src/zipkin_exporter.cc src/zipkin_exporter_factory.cc src/recordable.cc) + src/zipkin_exporter.cc src/zipkin_exporter_factory.cc src/recordable.cc + src/zipkin_builder.cc) target_include_directories( opentelemetry_exporter_zipkin_trace diff --git a/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_builder.h b/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_builder.h new file mode 100644 index 0000000000..0b50e2fe46 --- /dev/null +++ b/exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_builder.h @@ -0,0 +1,36 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/zipkin_span_exporter_configuration.h" +#include "opentelemetry/sdk/init/registry.h" +#include "opentelemetry/sdk/init/zipkin_span_exporter_builder.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace zipkin +{ + +class OPENTELEMETRY_EXPORT ZipkinBuilder + : public opentelemetry::sdk::init::ZipkinSpanExporterBuilder +{ +public: + static void Register(opentelemetry::sdk::init::Registry *registry); + + ZipkinBuilder() = default; + ~ZipkinBuilder() override = default; + + std::unique_ptr Build( + const opentelemetry::sdk::configuration::ZipkinSpanExporterConfiguration *model) + const override; +}; + +} // namespace zipkin +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/zipkin/src/zipkin_builder.cc b/exporters/zipkin/src/zipkin_builder.cc new file mode 100644 index 0000000000..3c0fec966b --- /dev/null +++ b/exporters/zipkin/src/zipkin_builder.cc @@ -0,0 +1,44 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include +#include + +#include "opentelemetry/exporters/zipkin/zipkin_builder.h" +#include "opentelemetry/exporters/zipkin/zipkin_exporter_factory.h" +#include "opentelemetry/exporters/zipkin/zipkin_exporter_options.h" +#include "opentelemetry/sdk/configuration/zipkin_span_exporter_configuration.h" +#include "opentelemetry/sdk/init/registry.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace zipkin +{ + +static ZipkinBuilder singleton; + +void ZipkinBuilder::Register(opentelemetry::sdk::init::Registry *registry) +{ + registry->SetZipkinSpanBuilder(&singleton); +} + +std::unique_ptr ZipkinBuilder::Build( + const opentelemetry::sdk::configuration::ZipkinSpanExporterConfiguration *model) const +{ + ZipkinExporterOptions options; + + options.endpoint = model->endpoint; + +#ifdef LATER + options.xxx = model->timeout; +#endif + + return ZipkinExporterFactory::Create(options); +} + +} // namespace zipkin +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/aggregation_configuration.h b/sdk/include/opentelemetry/sdk/configuration/aggregation_configuration.h new file mode 100644 index 0000000000..65b14532c4 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/aggregation_configuration.h @@ -0,0 +1,27 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/meter_provider.json +// YAML-NODE: aggregation +class AggregationConfiguration +{ +public: + AggregationConfiguration() = default; + virtual ~AggregationConfiguration() = default; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/always_off_sampler_configuration.h b/sdk/include/opentelemetry/sdk/configuration/always_off_sampler_configuration.h new file mode 100644 index 0000000000..8f9156ae91 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/always_off_sampler_configuration.h @@ -0,0 +1,32 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/sampler_configuration.h" +#include "opentelemetry/sdk/configuration/sampler_configuration_visitor.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/tracer_provider.json +// YAML-NODE: always_off +class AlwaysOffSamplerConfiguration : public SamplerConfiguration +{ +public: + AlwaysOffSamplerConfiguration() = default; + ~AlwaysOffSamplerConfiguration() override = default; + + void Accept(SamplerConfigurationVisitor *visitor) const override + { + visitor->VisitAlwaysOff(this); + } +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/always_on_sampler_configuration.h b/sdk/include/opentelemetry/sdk/configuration/always_on_sampler_configuration.h new file mode 100644 index 0000000000..c6cd99e078 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/always_on_sampler_configuration.h @@ -0,0 +1,29 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/sampler_configuration.h" +#include "opentelemetry/sdk/configuration/sampler_configuration_visitor.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/tracer_provider.json +// YAML-NODE: always_on +class AlwaysOnSamplerConfiguration : public SamplerConfiguration +{ +public: + AlwaysOnSamplerConfiguration() = default; + ~AlwaysOnSamplerConfiguration() override = default; + + void Accept(SamplerConfigurationVisitor *visitor) const override { visitor->VisitAlwaysOn(this); } +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/attribute_limits_configuration.h b/sdk/include/opentelemetry/sdk/configuration/attribute_limits_configuration.h new file mode 100644 index 0000000000..33f9df9417 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/attribute_limits_configuration.h @@ -0,0 +1,27 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/opentelemetry_configuration.json +// YAML-NODE: AttributeLimits +class AttributeLimitsConfiguration +{ +public: + size_t attribute_value_length_limit; + size_t attribute_count_limit; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/attributes_configuration.h b/sdk/include/opentelemetry/sdk/configuration/attributes_configuration.h new file mode 100644 index 0000000000..25153665ab --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/attributes_configuration.h @@ -0,0 +1,27 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/resource.json +// YAML-NODE: AttributeNameValue +// FIXME: Name/Value/Type +class AttributesConfiguration +{ +public: + std::map kv_map; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/base2_exponential_bucket_histogram_aggregation_configuration.h b/sdk/include/opentelemetry/sdk/configuration/base2_exponential_bucket_histogram_aggregation_configuration.h new file mode 100644 index 0000000000..494f1b63be --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/base2_exponential_bucket_histogram_aggregation_configuration.h @@ -0,0 +1,32 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/aggregation_configuration.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/meter_provider.json +// YAML-NODE: base2_exponential_bucket_histogram +class Base2ExponentialBucketHistogramAggregationConfiguration : public AggregationConfiguration +{ +public: + Base2ExponentialBucketHistogramAggregationConfiguration() = default; + ~Base2ExponentialBucketHistogramAggregationConfiguration() override = default; + + size_t max_scale{0}; + size_t max_size{0}; + bool record_min_max{false}; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/batch_log_record_processor_configuration.h b/sdk/include/opentelemetry/sdk/configuration/batch_log_record_processor_configuration.h new file mode 100644 index 0000000000..b7d2592789 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/batch_log_record_processor_configuration.h @@ -0,0 +1,39 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/log_record_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/log_record_processor_configuration.h" +#include "opentelemetry/sdk/configuration/log_record_processor_configuration_visitor.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/logger_provider.json +// YAML-NODE: BatchLogRecordProcessor +class BatchLogRecordProcessorConfiguration : public LogRecordProcessorConfiguration +{ +public: + BatchLogRecordProcessorConfiguration() = default; + ~BatchLogRecordProcessorConfiguration() override = default; + + void Accept(LogRecordProcessorConfigurationVisitor *visitor) const override + { + visitor->VisitBatch(this); + } + + size_t schedule_delay{0}; + size_t export_timeout{0}; + size_t max_queue_size{0}; + size_t max_export_batch_size{0}; + std::unique_ptr exporter; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/batch_span_processor_configuration.h b/sdk/include/opentelemetry/sdk/configuration/batch_span_processor_configuration.h new file mode 100644 index 0000000000..7dd563500e --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/batch_span_processor_configuration.h @@ -0,0 +1,39 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/span_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/span_processor_configuration.h" +#include "opentelemetry/sdk/configuration/span_processor_configuration_visitor.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/tracer_provider.json +// YAML-NODE: BatchSpanProcessor +class BatchSpanProcessorConfiguration : public SpanProcessorConfiguration +{ +public: + BatchSpanProcessorConfiguration() = default; + ~BatchSpanProcessorConfiguration() override = default; + + void Accept(SpanProcessorConfigurationVisitor *visitor) const override + { + visitor->VisitBatch(this); + } + + size_t schedule_delay{0}; + size_t export_timeout{0}; + size_t max_queue_size{0}; + size_t max_export_batch_size{0}; + std::unique_ptr exporter; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/configuration.h b/sdk/include/opentelemetry/sdk/configuration/configuration.h new file mode 100644 index 0000000000..a16c928c0d --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/configuration.h @@ -0,0 +1,69 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/attribute_limits_configuration.h" +#include "opentelemetry/sdk/configuration/document.h" +#include "opentelemetry/sdk/configuration/logger_provider_configuration.h" +#include "opentelemetry/sdk/configuration/meter_provider_configuration.h" +#include "opentelemetry/sdk/configuration/propagator_configuration.h" +#include "opentelemetry/sdk/configuration/resource_configuration.h" +#include "opentelemetry/sdk/configuration/tracer_provider_configuration.h" +#include "opentelemetry/version.h" + +/* + * General notes about configuration classes. + * + * Each Yaml node that exists in the yaml schema, + * as defined by https://github.com/open-telemetry/opentelemetry-configuration + * is represented by a C++ class. + * Special comments are used to relate the C++ class to + * the Yaml node it represents. + * + * YAML-SCHEMA: points to the relevant file within the + * opentelemetry-configuration repository + * YAML-NODE: points to the relevant node within the file. + * + * For example, + * C++ class opentelemetry::sdk::configuration::Configuration + * corresponds to + * Yaml node OpenTelemetryConfiguration, + * in file + * https://github.com/open-telemetry/opentelemetry-configuration/blob/main/schema/opentelemetry_configuration.json + */ + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/opentelemetry_configuration.json +// YAML-NODE: OpenTelemetryConfiguration +class Configuration +{ +public: + Configuration(std::unique_ptr doc) : m_doc(std::move(doc)) {} + ~Configuration() = default; + + std::string file_format; + bool disabled{false}; + + std::unique_ptr attribute_limits; + std::unique_ptr logger_provider; + std::unique_ptr meter_provider; + std::unique_ptr propagator; + std::unique_ptr tracer_provider; + std::unique_ptr resource; + // Ignored: instrumentation + +private: + std::unique_ptr m_doc; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/configuration_factory.h b/sdk/include/opentelemetry/sdk/configuration/configuration_factory.h new file mode 100644 index 0000000000..985bf6b538 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/configuration_factory.h @@ -0,0 +1,28 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include +#include +#include + +#include "opentelemetry/sdk/configuration/configuration.h" +#include "opentelemetry/sdk/configuration/document_node.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +class ConfigurationFactory +{ +public: + static std::unique_ptr ParseConfiguration(std::unique_ptr doc); +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/console_log_record_exporter_configuration.h b/sdk/include/opentelemetry/sdk/configuration/console_log_record_exporter_configuration.h new file mode 100644 index 0000000000..8175f01fc0 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/console_log_record_exporter_configuration.h @@ -0,0 +1,32 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/log_record_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/log_record_exporter_configuration_visitor.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/common.json +// YAML-NODE: Console +class ConsoleLogRecordExporterConfiguration : public LogRecordExporterConfiguration +{ +public: + ConsoleLogRecordExporterConfiguration() = default; + ~ConsoleLogRecordExporterConfiguration() override = default; + + void Accept(LogRecordExporterConfigurationVisitor *visitor) const override + { + visitor->VisitConsole(this); + } +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/console_push_metric_exporter_configuration.h b/sdk/include/opentelemetry/sdk/configuration/console_push_metric_exporter_configuration.h new file mode 100644 index 0000000000..16b5bea296 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/console_push_metric_exporter_configuration.h @@ -0,0 +1,33 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/headers_configuration.h" +#include "opentelemetry/sdk/configuration/push_metric_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/push_metric_exporter_configuration_visitor.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/common.json +// YAML-NODE: Console +class ConsolePushMetricExporterConfiguration : public PushMetricExporterConfiguration +{ +public: + ConsolePushMetricExporterConfiguration() = default; + ~ConsolePushMetricExporterConfiguration() override = default; + + void Accept(PushMetricExporterConfigurationVisitor *visitor) const override + { + visitor->VisitConsole(this); + } +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/console_span_exporter_configuration.h b/sdk/include/opentelemetry/sdk/configuration/console_span_exporter_configuration.h new file mode 100644 index 0000000000..98735a8fae --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/console_span_exporter_configuration.h @@ -0,0 +1,32 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/span_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/span_exporter_configuration_visitor.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/common.json +// YAML-NODE: Console +class ConsoleSpanExporterConfiguration : public SpanExporterConfiguration +{ +public: + ConsoleSpanExporterConfiguration() = default; + ~ConsoleSpanExporterConfiguration() override = default; + + void Accept(SpanExporterConfigurationVisitor *visitor) const override + { + visitor->VisitConsole(this); + } +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/default_aggregation_configuration.h b/sdk/include/opentelemetry/sdk/configuration/default_aggregation_configuration.h new file mode 100644 index 0000000000..b55a3d6c6c --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/default_aggregation_configuration.h @@ -0,0 +1,28 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/aggregation_configuration.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/meter_provider.json +// YAML-NODE: default +class DefaultAggregationConfiguration : public AggregationConfiguration +{ +public: + DefaultAggregationConfiguration() = default; + ~DefaultAggregationConfiguration() override = default; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/detectors_configuration.h b/sdk/include/opentelemetry/sdk/configuration/detectors_configuration.h new file mode 100644 index 0000000000..024ab78655 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/detectors_configuration.h @@ -0,0 +1,28 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/string_array_configuration.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/resource.json +// YAML-NODE: Detectors +class DetectorsConfiguration +{ +public: + std::unique_ptr included; + std::unique_ptr excluded; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/document.h b/sdk/include/opentelemetry/sdk/configuration/document.h new file mode 100644 index 0000000000..aa55943a38 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/document.h @@ -0,0 +1,28 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/document_node.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +class Document +{ +public: + Document() = default; + virtual ~Document() = default; + + virtual std::unique_ptr GetRootNode() = 0; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/document_node.h b/sdk/include/opentelemetry/sdk/configuration/document_node.h new file mode 100644 index 0000000000..ac7657de05 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/document_node.h @@ -0,0 +1,153 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include +#include + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +class DocumentNodeConstIterator; +class PropertiesNodeConstIterator; + +class DocumentNode +{ +public: + // FIXME: proper sizing + static constexpr size_t MAX_NODE_DEPTH = 100; + + DocumentNode() = default; + virtual ~DocumentNode() = default; + + virtual std::string Key() const = 0; + + virtual bool AsBoolean() = 0; + virtual size_t AsInteger() = 0; + virtual double AsDouble() = 0; + virtual std::string AsString() = 0; + + virtual std::unique_ptr GetRequiredChildNode(const std::string &name) = 0; + virtual std::unique_ptr GetChildNode(const std::string &name) = 0; + + virtual bool GetRequiredBoolean(const std::string &name) = 0; + virtual bool GetBoolean(const std::string &name, bool default_value) = 0; + + virtual size_t GetRequiredInteger(const std::string &name) = 0; + virtual size_t GetInteger(const std::string &name, size_t default_value) = 0; + + virtual double GetRequiredDouble(const std::string &name) = 0; + virtual double GetDouble(const std::string &name, double default_value) = 0; + + virtual std::string GetRequiredString(const std::string &name) = 0; + virtual std::string GetString(const std::string &name, const std::string &default_value) = 0; + + virtual DocumentNodeConstIterator begin() const = 0; + virtual DocumentNodeConstIterator end() const = 0; + + virtual size_t num_children() const = 0; + virtual std::unique_ptr GetChild(size_t index) const = 0; + + virtual PropertiesNodeConstIterator begin_properties() const = 0; + virtual PropertiesNodeConstIterator end_properties() const = 0; + + virtual std::string Dump() const = 0; + +protected: + std::string DoSubstitution(const std::string &text); + std::string DoOneSubstitution(const std::string &text); + + bool BooleanFromString(const std::string &value); + size_t IntegerFromString(const std::string &value); + double DoubleFromString(const std::string &value); +}; + +class DocumentNodeConstIteratorImpl +{ +public: + DocumentNodeConstIteratorImpl() = default; + virtual ~DocumentNodeConstIteratorImpl() = default; + + virtual void Next() = 0; + virtual std::unique_ptr Item() const = 0; + virtual bool Equal(const DocumentNodeConstIteratorImpl *rhs) const = 0; +}; + +class PropertiesNodeConstIteratorImpl +{ +public: + PropertiesNodeConstIteratorImpl() = default; + virtual ~PropertiesNodeConstIteratorImpl() = default; + + virtual void Next() = 0; + virtual std::string Name() const = 0; + virtual std::unique_ptr Value() const = 0; + virtual bool Equal(const PropertiesNodeConstIteratorImpl *rhs) const = 0; +}; + +class DocumentNodeConstIterator +{ +public: + DocumentNodeConstIterator(DocumentNodeConstIteratorImpl *impl) : m_impl(impl) {} + ~DocumentNodeConstIterator() { delete m_impl; } + + bool operator==(const DocumentNodeConstIterator &rhs) const + { + return (m_impl->Equal(rhs.m_impl)); + } + + bool operator!=(const DocumentNodeConstIterator &rhs) const + { + return (!m_impl->Equal(rhs.m_impl)); + } + + std::unique_ptr operator*() const { return m_impl->Item(); } + + DocumentNodeConstIterator &operator++() + { + m_impl->Next(); + return *this; + } + +private: + DocumentNodeConstIteratorImpl *m_impl; +}; + +class PropertiesNodeConstIterator +{ +public: + PropertiesNodeConstIterator(PropertiesNodeConstIteratorImpl *impl) : m_impl(impl) {} + ~PropertiesNodeConstIterator() { delete m_impl; } + + bool operator==(const PropertiesNodeConstIterator &rhs) const + { + return (m_impl->Equal(rhs.m_impl)); + } + + bool operator!=(const PropertiesNodeConstIterator &rhs) const + { + return (!m_impl->Equal(rhs.m_impl)); + } + + std::string Name() const { return m_impl->Name(); } + std::unique_ptr Value() const { return m_impl->Value(); } + + PropertiesNodeConstIterator &operator++() + { + m_impl->Next(); + return *this; + } + +private: + PropertiesNodeConstIteratorImpl *m_impl; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/drop_aggregation_configuration.h b/sdk/include/opentelemetry/sdk/configuration/drop_aggregation_configuration.h new file mode 100644 index 0000000000..22454a3db5 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/drop_aggregation_configuration.h @@ -0,0 +1,28 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/aggregation_configuration.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/meter_provider.json +// YAML-NODE: drop +class DropAggregationConfiguration : public AggregationConfiguration +{ +public: + DropAggregationConfiguration() = default; + ~DropAggregationConfiguration() override = default; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/explicit_bucket_histogram_aggregation_configuration.h b/sdk/include/opentelemetry/sdk/configuration/explicit_bucket_histogram_aggregation_configuration.h new file mode 100644 index 0000000000..3419fea64d --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/explicit_bucket_histogram_aggregation_configuration.h @@ -0,0 +1,31 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/aggregation_configuration.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/meter_provider.json +// YAML-NODE: explicit_bucket_histogram +class ExplicitBucketHistogramAggregationConfiguration : public AggregationConfiguration +{ +public: + ExplicitBucketHistogramAggregationConfiguration() = default; + ~ExplicitBucketHistogramAggregationConfiguration() override = default; + + std::vector boundaries; + bool record_min_max{false}; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/extension_log_record_exporter_configuration.h b/sdk/include/opentelemetry/sdk/configuration/extension_log_record_exporter_configuration.h new file mode 100644 index 0000000000..d68c3b7d39 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/extension_log_record_exporter_configuration.h @@ -0,0 +1,36 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/document_node.h" +#include "opentelemetry/sdk/configuration/log_record_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/log_record_exporter_configuration_visitor.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/logger_provider.json +// YAML-NODE: LogRecordProcessor +class ExtensionLogRecordExporterConfiguration : public LogRecordExporterConfiguration +{ +public: + ExtensionLogRecordExporterConfiguration() = default; + ~ExtensionLogRecordExporterConfiguration() override = default; + + void Accept(LogRecordExporterConfigurationVisitor *visitor) const override + { + visitor->VisitExtension(this); + } + + std::string name; + std::unique_ptr node; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/extension_log_record_processor_configuration.h b/sdk/include/opentelemetry/sdk/configuration/extension_log_record_processor_configuration.h new file mode 100644 index 0000000000..23d6558a19 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/extension_log_record_processor_configuration.h @@ -0,0 +1,34 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/document_node.h" +#include "opentelemetry/sdk/configuration/log_record_processor_configuration.h" +#include "opentelemetry/sdk/configuration/log_record_processor_configuration_visitor.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +class ExtensionLogRecordProcessorConfiguration : public LogRecordProcessorConfiguration +{ +public: + ExtensionLogRecordProcessorConfiguration() = default; + ~ExtensionLogRecordProcessorConfiguration() override = default; + + void Accept(LogRecordProcessorConfigurationVisitor *visitor) const override + { + visitor->VisitExtension(this); + } + + std::string name; + std::unique_ptr node; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/extension_pull_metric_exporter_configuration.h b/sdk/include/opentelemetry/sdk/configuration/extension_pull_metric_exporter_configuration.h new file mode 100644 index 0000000000..cde2b0aa2d --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/extension_pull_metric_exporter_configuration.h @@ -0,0 +1,36 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/document_node.h" +#include "opentelemetry/sdk/configuration/pull_metric_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/pull_metric_exporter_configuration_visitor.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/meter_provider.json +// YAML-NODE: PullMetricExporter +class ExtensionPullMetricExporterConfiguration : public PullMetricExporterConfiguration +{ +public: + ExtensionPullMetricExporterConfiguration() = default; + ~ExtensionPullMetricExporterConfiguration() override = default; + + void Accept(PullMetricExporterConfigurationVisitor *visitor) const override + { + visitor->VisitExtension(this); + } + + std::string name; + std::unique_ptr node; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/extension_push_metric_exporter_configuration.h b/sdk/include/opentelemetry/sdk/configuration/extension_push_metric_exporter_configuration.h new file mode 100644 index 0000000000..05e71090b8 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/extension_push_metric_exporter_configuration.h @@ -0,0 +1,36 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/document_node.h" +#include "opentelemetry/sdk/configuration/push_metric_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/push_metric_exporter_configuration_visitor.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/meter_provider.json +// YAML-NODE: PushMetricExporter +class ExtensionPushMetricExporterConfiguration : public PushMetricExporterConfiguration +{ +public: + ExtensionPushMetricExporterConfiguration() = default; + ~ExtensionPushMetricExporterConfiguration() override = default; + + void Accept(PushMetricExporterConfigurationVisitor *visitor) const override + { + visitor->VisitExtension(this); + } + + std::string name; + std::unique_ptr node; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/extension_sampler_configuration.h b/sdk/include/opentelemetry/sdk/configuration/extension_sampler_configuration.h new file mode 100644 index 0000000000..e2347910a1 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/extension_sampler_configuration.h @@ -0,0 +1,35 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/document_node.h" +#include "opentelemetry/sdk/configuration/sampler_configuration.h" +#include "opentelemetry/sdk/configuration/sampler_configuration_visitor.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +class ExtensionSamplerConfiguration : public SamplerConfiguration +{ +public: + ExtensionSamplerConfiguration() = default; + ~ExtensionSamplerConfiguration() override = default; + + void Accept(SamplerConfigurationVisitor *visitor) const override + { + visitor->VisitExtension(this); + } + + std::string name; + std::unique_ptr node; + size_t depth{0}; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/extension_span_exporter_configuration.h b/sdk/include/opentelemetry/sdk/configuration/extension_span_exporter_configuration.h new file mode 100644 index 0000000000..b2993ecaaa --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/extension_span_exporter_configuration.h @@ -0,0 +1,34 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/document_node.h" +#include "opentelemetry/sdk/configuration/span_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/span_exporter_configuration_visitor.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +class ExtensionSpanExporterConfiguration : public SpanExporterConfiguration +{ +public: + ExtensionSpanExporterConfiguration() = default; + ~ExtensionSpanExporterConfiguration() override = default; + + void Accept(SpanExporterConfigurationVisitor *visitor) const override + { + visitor->VisitExtension(this); + } + + std::string name; + std::unique_ptr node; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/extension_span_processor_configuration.h b/sdk/include/opentelemetry/sdk/configuration/extension_span_processor_configuration.h new file mode 100644 index 0000000000..f1eba5952b --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/extension_span_processor_configuration.h @@ -0,0 +1,34 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/document_node.h" +#include "opentelemetry/sdk/configuration/span_processor_configuration.h" +#include "opentelemetry/sdk/configuration/span_processor_configuration_visitor.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +class ExtensionSpanProcessorConfiguration : public SpanProcessorConfiguration +{ +public: + ExtensionSpanProcessorConfiguration() = default; + ~ExtensionSpanProcessorConfiguration() override = default; + + void Accept(SpanProcessorConfigurationVisitor *visitor) const override + { + visitor->VisitExtension(this); + } + + std::string name; + std::unique_ptr node; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/headers_configuration.h b/sdk/include/opentelemetry/sdk/configuration/headers_configuration.h new file mode 100644 index 0000000000..b227b5f251 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/headers_configuration.h @@ -0,0 +1,25 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include +#include + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +class HeadersConfiguration +{ +public: + std::map kv_map; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/invalid_schema_exception.h b/sdk/include/opentelemetry/sdk/configuration/invalid_schema_exception.h new file mode 100644 index 0000000000..e17cf42341 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/invalid_schema_exception.h @@ -0,0 +1,28 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/document.h" +#include "opentelemetry/sdk/configuration/document_node.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +class InvalidSchemaException : public std::runtime_error +{ +public: + InvalidSchemaException(const std::string &msg) : std::runtime_error(msg) {} + + ~InvalidSchemaException() override = default; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/jaeger_remote_sampler_configuration.h b/sdk/include/opentelemetry/sdk/configuration/jaeger_remote_sampler_configuration.h new file mode 100644 index 0000000000..6a518d2f8c --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/jaeger_remote_sampler_configuration.h @@ -0,0 +1,36 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/sampler_configuration.h" +#include "opentelemetry/sdk/configuration/sampler_configuration_visitor.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/tracer_provider.json +// YAML-NODE: jaeger_remote +class JaegerRemoteSamplerConfiguration : public SamplerConfiguration +{ +public: + JaegerRemoteSamplerConfiguration() = default; + ~JaegerRemoteSamplerConfiguration() override = default; + + void Accept(SamplerConfigurationVisitor *visitor) const override + { + visitor->VisitJaegerRemote(this); + } + + std::string endpoint; + size_t interval{0}; + std::unique_ptr initial_sampler; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/last_value_aggregation_configuration.h b/sdk/include/opentelemetry/sdk/configuration/last_value_aggregation_configuration.h new file mode 100644 index 0000000000..7dad563860 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/last_value_aggregation_configuration.h @@ -0,0 +1,28 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/aggregation_configuration.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/meter_provider.json +// YAML-NODE: last_value +class LastValueAggregationConfiguration : public AggregationConfiguration +{ +public: + LastValueAggregationConfiguration() = default; + ~LastValueAggregationConfiguration() override = default; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/log_record_exporter_configuration.h b/sdk/include/opentelemetry/sdk/configuration/log_record_exporter_configuration.h new file mode 100644 index 0000000000..77c98eed71 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/log_record_exporter_configuration.h @@ -0,0 +1,28 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ +class LogRecordExporterConfigurationVisitor; + +// YAML-SCHEMA: schema/logger_provider.json +// YAML-NODE: LogRecordExporter +class LogRecordExporterConfiguration +{ +public: + LogRecordExporterConfiguration() = default; + virtual ~LogRecordExporterConfiguration() = default; + + virtual void Accept(LogRecordExporterConfigurationVisitor *visitor) const = 0; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/log_record_exporter_configuration_visitor.h b/sdk/include/opentelemetry/sdk/configuration/log_record_exporter_configuration_visitor.h new file mode 100644 index 0000000000..c36f8c43c9 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/log_record_exporter_configuration_visitor.h @@ -0,0 +1,31 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +class OtlpLogRecordExporterConfiguration; +class ConsoleLogRecordExporterConfiguration; +class ExtensionLogRecordExporterConfiguration; + +class LogRecordExporterConfigurationVisitor +{ +public: + LogRecordExporterConfigurationVisitor() = default; + virtual ~LogRecordExporterConfigurationVisitor() = default; + + virtual void VisitOtlp(const OtlpLogRecordExporterConfiguration *model) = 0; + virtual void VisitConsole(const ConsoleLogRecordExporterConfiguration *model) = 0; + virtual void VisitExtension(const ExtensionLogRecordExporterConfiguration *model) = 0; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/log_record_limits_configuration.h b/sdk/include/opentelemetry/sdk/configuration/log_record_limits_configuration.h new file mode 100644 index 0000000000..c8b9eb74ec --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/log_record_limits_configuration.h @@ -0,0 +1,25 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/logger_provider.json +// YAML-NODE: LogRecordLimits +class LogRecordLimitsConfiguration +{ +public: + size_t attribute_value_length_limit; + size_t attribute_count_limit; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/log_record_processor_configuration.h b/sdk/include/opentelemetry/sdk/configuration/log_record_processor_configuration.h new file mode 100644 index 0000000000..3e05ebd5af --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/log_record_processor_configuration.h @@ -0,0 +1,28 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ +class LogRecordProcessorConfigurationVisitor; + +// YAML-SCHEMA: schema/logger_provider.json +// YAML-NODE: LogRecordProcessor +class LogRecordProcessorConfiguration +{ +public: + LogRecordProcessorConfiguration() = default; + virtual ~LogRecordProcessorConfiguration() = default; + + virtual void Accept(LogRecordProcessorConfigurationVisitor *visitor) const = 0; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/log_record_processor_configuration_visitor.h b/sdk/include/opentelemetry/sdk/configuration/log_record_processor_configuration_visitor.h new file mode 100644 index 0000000000..263407b171 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/log_record_processor_configuration_visitor.h @@ -0,0 +1,31 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +class BatchLogRecordProcessorConfiguration; +class SimpleLogRecordProcessorConfiguration; +class ExtensionLogRecordProcessorConfiguration; + +class LogRecordProcessorConfigurationVisitor +{ +public: + LogRecordProcessorConfigurationVisitor() = default; + virtual ~LogRecordProcessorConfigurationVisitor() = default; + + virtual void VisitBatch(const BatchLogRecordProcessorConfiguration *model) = 0; + virtual void VisitSimple(const SimpleLogRecordProcessorConfiguration *model) = 0; + virtual void VisitExtension(const ExtensionLogRecordProcessorConfiguration *model) = 0; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/logger_provider_configuration.h b/sdk/include/opentelemetry/sdk/configuration/logger_provider_configuration.h new file mode 100644 index 0000000000..f9fcea7fb8 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/logger_provider_configuration.h @@ -0,0 +1,30 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include +#include + +#include "opentelemetry/sdk/configuration/log_record_limits_configuration.h" +#include "opentelemetry/sdk/configuration/log_record_processor_configuration.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/logger_provider.json +// YAML-NODE: LoggerProvider +class LoggerProviderConfiguration +{ +public: + std::vector> processors; + std::unique_ptr limits; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/meter_provider_configuration.h b/sdk/include/opentelemetry/sdk/configuration/meter_provider_configuration.h new file mode 100644 index 0000000000..05b2e0ae29 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/meter_provider_configuration.h @@ -0,0 +1,31 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include +#include + +#include "opentelemetry/sdk/configuration/metric_reader_configuration.h" +#include "opentelemetry/sdk/configuration/view_configuration.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/meter_provider.json +// YAML-NODE: MeterProvider +class MeterProviderConfiguration +{ +public: + std::vector> readers; + std::vector> views; + // FIXME: exemplar_filter +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/metric_producer_configuration.h b/sdk/include/opentelemetry/sdk/configuration/metric_producer_configuration.h new file mode 100644 index 0000000000..9e8fb8e411 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/metric_producer_configuration.h @@ -0,0 +1,30 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ +class MetricProducerConfigurationVisitor; + +// YAML-SCHEMA: schema/meter_provider.json +// YAML-NODE: MetricProducer +class MetricProducerConfiguration +{ +public: + MetricProducerConfiguration() = default; + virtual ~MetricProducerConfiguration() = default; + + virtual void Accept(MetricProducerConfigurationVisitor *visitor) const = 0; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/metric_reader_configuration.h b/sdk/include/opentelemetry/sdk/configuration/metric_reader_configuration.h new file mode 100644 index 0000000000..466cb57fd5 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/metric_reader_configuration.h @@ -0,0 +1,30 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ +class MetricReaderConfigurationVisitor; + +// YAML-SCHEMA: schema/meter_provider.json +// YAML-NODE: MetricReader +class MetricReaderConfiguration +{ +public: + MetricReaderConfiguration() = default; + virtual ~MetricReaderConfiguration() = default; + + virtual void Accept(MetricReaderConfigurationVisitor *visitor) const = 0; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/metric_reader_configuration_visitor.h b/sdk/include/opentelemetry/sdk/configuration/metric_reader_configuration_visitor.h new file mode 100644 index 0000000000..83b74c1b0b --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/metric_reader_configuration_visitor.h @@ -0,0 +1,29 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +class PeriodicMetricReaderConfiguration; +class PullMetricReaderConfiguration; + +class MetricReaderConfigurationVisitor +{ +public: + MetricReaderConfigurationVisitor() = default; + virtual ~MetricReaderConfigurationVisitor() = default; + + virtual void VisitPeriodic(const PeriodicMetricReaderConfiguration *model) = 0; + virtual void VisitPull(const PullMetricReaderConfiguration *model) = 0; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/otlp_log_record_exporter_configuration.h b/sdk/include/opentelemetry/sdk/configuration/otlp_log_record_exporter_configuration.h new file mode 100644 index 0000000000..752d9c6da7 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/otlp_log_record_exporter_configuration.h @@ -0,0 +1,44 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/headers_configuration.h" +#include "opentelemetry/sdk/configuration/log_record_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/log_record_exporter_configuration_visitor.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/common.json +// YAML-NODE: Otlp +class OtlpLogRecordExporterConfiguration : public LogRecordExporterConfiguration +{ +public: + OtlpLogRecordExporterConfiguration() = default; + ~OtlpLogRecordExporterConfiguration() override = default; + + void Accept(LogRecordExporterConfigurationVisitor *visitor) const override + { + visitor->VisitOtlp(this); + } + + std::string protocol; + std::string endpoint; + std::string certificate; + std::string client_key; + std::string client_certificate; + std::unique_ptr headers; + std::string headers_list; + std::string compression; + size_t timeout{0}; + bool insecure{false}; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/otlp_push_metric_exporter_configuration.h b/sdk/include/opentelemetry/sdk/configuration/otlp_push_metric_exporter_configuration.h new file mode 100644 index 0000000000..3e1123b546 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/otlp_push_metric_exporter_configuration.h @@ -0,0 +1,52 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/headers_configuration.h" +#include "opentelemetry/sdk/configuration/push_metric_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/push_metric_exporter_configuration_visitor.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +enum enum_default_histogram_aggregation +{ + explicit_bucket_histogram, + base2_exponential_bucket_histogram +}; + +// YAML-SCHEMA: schema/meter_provider.json +// YAML-NODE: OtlpMetric +class OtlpPushMetricExporterConfiguration : public PushMetricExporterConfiguration +{ +public: + OtlpPushMetricExporterConfiguration() = default; + ~OtlpPushMetricExporterConfiguration() override = default; + + void Accept(PushMetricExporterConfigurationVisitor *visitor) const override + { + visitor->VisitOtlp(this); + } + + std::string protocol; + std::string endpoint; + std::string certificate; + std::string client_key; + std::string client_certificate; + std::unique_ptr headers; + std::string headers_list; + std::string compression; + size_t timeout{0}; + std::string temporality_preference; + enum_default_histogram_aggregation default_histogram_aggregation{explicit_bucket_histogram}; + bool insecure{false}; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/otlp_span_exporter_configuration.h b/sdk/include/opentelemetry/sdk/configuration/otlp_span_exporter_configuration.h new file mode 100644 index 0000000000..643bb7e435 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/otlp_span_exporter_configuration.h @@ -0,0 +1,44 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/headers_configuration.h" +#include "opentelemetry/sdk/configuration/span_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/span_exporter_configuration_visitor.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/common.json +// YAML-NODE: Otlp +class OtlpSpanExporterConfiguration : public SpanExporterConfiguration +{ +public: + OtlpSpanExporterConfiguration() = default; + ~OtlpSpanExporterConfiguration() override = default; + + void Accept(SpanExporterConfigurationVisitor *visitor) const override + { + visitor->VisitOtlp(this); + } + + std::string protocol; + std::string endpoint; + std::string certificate; + std::string client_key; + std::string client_certificate; + std::unique_ptr headers; + std::string headers_list; + std::string compression; + size_t timeout{0}; + bool insecure{false}; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/parent_based_sampler_configuration.h b/sdk/include/opentelemetry/sdk/configuration/parent_based_sampler_configuration.h new file mode 100644 index 0000000000..a5a1079262 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/parent_based_sampler_configuration.h @@ -0,0 +1,38 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/sampler_configuration.h" +#include "opentelemetry/sdk/configuration/sampler_configuration_visitor.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/tracer_provider.json +// YAML-NODE: parent_based +class ParentBasedSamplerConfiguration : public SamplerConfiguration +{ +public: + ParentBasedSamplerConfiguration() = default; + ~ParentBasedSamplerConfiguration() override = default; + + void Accept(SamplerConfigurationVisitor *visitor) const override + { + visitor->VisitParentBased(this); + } + + std::unique_ptr root; + std::unique_ptr remote_parent_sampled; + std::unique_ptr remote_parent_not_sampled; + std::unique_ptr local_parent_sampled; + std::unique_ptr local_parent_not_sampled; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/periodic_metric_reader_configuration.h b/sdk/include/opentelemetry/sdk/configuration/periodic_metric_reader_configuration.h new file mode 100644 index 0000000000..f6b56601be --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/periodic_metric_reader_configuration.h @@ -0,0 +1,41 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/metric_producer_configuration.h" +#include "opentelemetry/sdk/configuration/metric_reader_configuration.h" +#include "opentelemetry/sdk/configuration/metric_reader_configuration_visitor.h" +#include "opentelemetry/sdk/configuration/push_metric_exporter_configuration.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/meter_provider.json +// YAML-NODE: PeriodicMetricReader +class PeriodicMetricReaderConfiguration : public MetricReaderConfiguration +{ +public: + PeriodicMetricReaderConfiguration() = default; + ~PeriodicMetricReaderConfiguration() override = default; + + void Accept(MetricReaderConfigurationVisitor *visitor) const override + { + visitor->VisitPeriodic(this); + } + + size_t interval{0}; + size_t timeout{0}; + std::unique_ptr exporter; + std::vector> producers; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/prometheus_pull_metric_exporter_configuration.h b/sdk/include/opentelemetry/sdk/configuration/prometheus_pull_metric_exporter_configuration.h new file mode 100644 index 0000000000..9c77d2366f --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/prometheus_pull_metric_exporter_configuration.h @@ -0,0 +1,40 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/headers_configuration.h" +#include "opentelemetry/sdk/configuration/pull_metric_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/pull_metric_exporter_configuration_visitor.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/meter_provider.json +// YAML-NODE: Prometheus +class PrometheusPullMetricExporterConfiguration : public PullMetricExporterConfiguration +{ +public: + PrometheusPullMetricExporterConfiguration() = default; + ~PrometheusPullMetricExporterConfiguration() override = default; + + void Accept(PullMetricExporterConfigurationVisitor *visitor) const override + { + visitor->VisitPrometheus(this); + } + + std::string host; + size_t port{0}; + bool without_units{false}; + bool without_type_suffix{false}; + bool without_scope_info{false}; + // FIXME: with_resource_constant_labels; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/propagator_configuration.h b/sdk/include/opentelemetry/sdk/configuration/propagator_configuration.h new file mode 100644 index 0000000000..3aa3a063ef --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/propagator_configuration.h @@ -0,0 +1,27 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/propagator.json +// YAML-NODE: Propagator +class PropagatorConfiguration +{ +public: + PropagatorConfiguration() = default; + virtual ~PropagatorConfiguration() = default; + + std::vector composite; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/pull_metric_exporter_configuration.h b/sdk/include/opentelemetry/sdk/configuration/pull_metric_exporter_configuration.h new file mode 100644 index 0000000000..9fda353948 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/pull_metric_exporter_configuration.h @@ -0,0 +1,26 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ +class PullMetricExporterConfigurationVisitor; + +class PullMetricExporterConfiguration +{ +public: + PullMetricExporterConfiguration() = default; + virtual ~PullMetricExporterConfiguration() = default; + + virtual void Accept(PullMetricExporterConfigurationVisitor *visitor) const = 0; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/pull_metric_exporter_configuration_visitor.h b/sdk/include/opentelemetry/sdk/configuration/pull_metric_exporter_configuration_visitor.h new file mode 100644 index 0000000000..1904db5954 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/pull_metric_exporter_configuration_visitor.h @@ -0,0 +1,29 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +class PrometheusPullMetricExporterConfiguration; +class ExtensionPullMetricExporterConfiguration; + +class PullMetricExporterConfigurationVisitor +{ +public: + PullMetricExporterConfigurationVisitor() = default; + virtual ~PullMetricExporterConfigurationVisitor() = default; + + virtual void VisitPrometheus(const PrometheusPullMetricExporterConfiguration *model) = 0; + virtual void VisitExtension(const ExtensionPullMetricExporterConfiguration *model) = 0; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/pull_metric_reader_configuration.h b/sdk/include/opentelemetry/sdk/configuration/pull_metric_reader_configuration.h new file mode 100644 index 0000000000..a5f37798f6 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/pull_metric_reader_configuration.h @@ -0,0 +1,39 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/metric_producer_configuration.h" +#include "opentelemetry/sdk/configuration/metric_reader_configuration.h" +#include "opentelemetry/sdk/configuration/metric_reader_configuration_visitor.h" +#include "opentelemetry/sdk/configuration/pull_metric_exporter_configuration.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/meter_provider.json +// YAML-NODE: PullMetricReader +class PullMetricReaderConfiguration : public MetricReaderConfiguration +{ +public: + PullMetricReaderConfiguration() = default; + ~PullMetricReaderConfiguration() override = default; + + void Accept(MetricReaderConfigurationVisitor *visitor) const override + { + visitor->VisitPull(this); + } + + std::unique_ptr exporter; + std::vector> producers; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/push_metric_exporter_configuration.h b/sdk/include/opentelemetry/sdk/configuration/push_metric_exporter_configuration.h new file mode 100644 index 0000000000..15133b7ee8 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/push_metric_exporter_configuration.h @@ -0,0 +1,28 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ +class PushMetricExporterConfigurationVisitor; + +// YAML-SCHEMA: schema/meter_provider.json +// YAML-NODE: PushMetricExporter +class PushMetricExporterConfiguration +{ +public: + PushMetricExporterConfiguration() = default; + virtual ~PushMetricExporterConfiguration() = default; + + virtual void Accept(PushMetricExporterConfigurationVisitor *visitor) const = 0; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/push_metric_exporter_configuration_visitor.h b/sdk/include/opentelemetry/sdk/configuration/push_metric_exporter_configuration_visitor.h new file mode 100644 index 0000000000..f88f7c3320 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/push_metric_exporter_configuration_visitor.h @@ -0,0 +1,31 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +class OtlpPushMetricExporterConfiguration; +class ConsolePushMetricExporterConfiguration; +class ExtensionPushMetricExporterConfiguration; + +class PushMetricExporterConfigurationVisitor +{ +public: + PushMetricExporterConfigurationVisitor() = default; + virtual ~PushMetricExporterConfigurationVisitor() = default; + + virtual void VisitOtlp(const OtlpPushMetricExporterConfiguration *model) = 0; + virtual void VisitConsole(const ConsolePushMetricExporterConfiguration *model) = 0; + virtual void VisitExtension(const ExtensionPushMetricExporterConfiguration *model) = 0; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/resource_configuration.h b/sdk/include/opentelemetry/sdk/configuration/resource_configuration.h new file mode 100644 index 0000000000..12dd60131e --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/resource_configuration.h @@ -0,0 +1,29 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/attributes_configuration.h" +#include "opentelemetry/sdk/configuration/detectors_configuration.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/resource.json +// YAML-NODE: Resource +class ResourceConfiguration +{ +public: + std::unique_ptr attributes; + std::unique_ptr detectors; + std::string schema_url; + std::string attributes_list; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/ryml_document.h b/sdk/include/opentelemetry/sdk/configuration/ryml_document.h new file mode 100644 index 0000000000..a6fe7658d7 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/ryml_document.h @@ -0,0 +1,35 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include +#include + +#include "opentelemetry/sdk/configuration/document.h" +#include "opentelemetry/sdk/configuration/document_node.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +class RymlDocument : public Document +{ +public: + static std::unique_ptr Parse(const std::string &source, const std::string &content); + + RymlDocument(ryml::Tree tree) : m_tree(tree) {} + ~RymlDocument() override = default; + + std::unique_ptr GetRootNode() override; + +private: + ryml::Tree m_tree; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/ryml_document_node.h b/sdk/include/opentelemetry/sdk/configuration/ryml_document_node.h new file mode 100644 index 0000000000..824fc6fb64 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/ryml_document_node.h @@ -0,0 +1,102 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include +#include +#include +#include + +#include "opentelemetry/sdk/configuration/document_node.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +class RymlDocumentNode : public DocumentNode +{ +public: + RymlDocumentNode(ryml::ConstNodeRef node, size_t depth) : m_node(node), m_depth(depth) {} + ~RymlDocumentNode() override = default; + + std::string Key() const override; + + bool AsBoolean() override; + size_t AsInteger() override; + double AsDouble() override; + std::string AsString() override; + + std::unique_ptr GetRequiredChildNode(const std::string &name) override; + std::unique_ptr GetChildNode(const std::string &name) override; + + bool GetRequiredBoolean(const std::string &name) override; + bool GetBoolean(const std::string &name, bool default_value) override; + + size_t GetRequiredInteger(const std::string &name) override; + size_t GetInteger(const std::string &name, size_t default_value) override; + + double GetRequiredDouble(const std::string &name) override; + double GetDouble(const std::string &name, double default_value) override; + + std::string GetRequiredString(const std::string &name) override; + std::string GetString(const std::string &name, const std::string &default_value) override; + + DocumentNodeConstIterator begin() const override; + DocumentNodeConstIterator end() const override; + + size_t num_children() const override; + std::unique_ptr GetChild(size_t index) const override; + + PropertiesNodeConstIterator begin_properties() const override; + PropertiesNodeConstIterator end_properties() const override; + + std::string Dump() const override; + +private: + ryml::ConstNodeRef GetRequiredRymlChildNode(const std::string &name); + ryml::ConstNodeRef GetRymlChildNode(const std::string &name); + + ryml::ConstNodeRef m_node; + size_t m_depth; +}; + +class RymlDocumentNodeConstIteratorImpl : public DocumentNodeConstIteratorImpl +{ +public: + RymlDocumentNodeConstIteratorImpl(ryml::ConstNodeRef parent, size_t index, size_t depth); + ~RymlDocumentNodeConstIteratorImpl() override; + + void Next() override; + std::unique_ptr Item() const override; + bool Equal(const DocumentNodeConstIteratorImpl *rhs) const override; + +private: + ryml::ConstNodeRef m_parent; + size_t m_index; + size_t m_depth; +}; + +class RymlPropertiesNodeConstIteratorImpl : public PropertiesNodeConstIteratorImpl +{ +public: + RymlPropertiesNodeConstIteratorImpl(ryml::ConstNodeRef parent, size_t index, size_t depth); + ~RymlPropertiesNodeConstIteratorImpl() override; + + void Next() override; + std::string Name() const override; + std::unique_ptr Value() const override; + bool Equal(const PropertiesNodeConstIteratorImpl *rhs) const override; + +private: + ryml::ConstNodeRef m_parent; + size_t m_index; + size_t m_depth; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/sampler_configuration.h b/sdk/include/opentelemetry/sdk/configuration/sampler_configuration.h new file mode 100644 index 0000000000..862bdd6382 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/sampler_configuration.h @@ -0,0 +1,29 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +class SamplerConfigurationVisitor; + +// YAML-SCHEMA: schema/tracer_provider.json +// YAML-NODE: Sampler +class SamplerConfiguration +{ +public: + SamplerConfiguration() = default; + virtual ~SamplerConfiguration() = default; + + virtual void Accept(SamplerConfigurationVisitor *visitor) const = 0; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/sampler_configuration_visitor.h b/sdk/include/opentelemetry/sdk/configuration/sampler_configuration_visitor.h new file mode 100644 index 0000000000..2820b4b25e --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/sampler_configuration_visitor.h @@ -0,0 +1,37 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +class AlwaysOffSamplerConfiguration; +class AlwaysOnSamplerConfiguration; +class JaegerRemoteSamplerConfiguration; +class ParentBasedSamplerConfiguration; +class TraceIdRatioBasedSamplerConfiguration; +class ExtensionSamplerConfiguration; + +class SamplerConfigurationVisitor +{ +public: + SamplerConfigurationVisitor() = default; + virtual ~SamplerConfigurationVisitor() = default; + + virtual void VisitAlwaysOff(const AlwaysOffSamplerConfiguration *model) = 0; + virtual void VisitAlwaysOn(const AlwaysOnSamplerConfiguration *model) = 0; + virtual void VisitJaegerRemote(const JaegerRemoteSamplerConfiguration *model) = 0; + virtual void VisitParentBased(const ParentBasedSamplerConfiguration *model) = 0; + virtual void VisitTraceIdRatioBased(const TraceIdRatioBasedSamplerConfiguration *model) = 0; + virtual void VisitExtension(const ExtensionSamplerConfiguration *model) = 0; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/selector_configuration.h b/sdk/include/opentelemetry/sdk/configuration/selector_configuration.h new file mode 100644 index 0000000000..43a3567c7a --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/selector_configuration.h @@ -0,0 +1,42 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +enum enum_instrument_type +{ + counter, + histogram, + observable_counter, + observable_gauge, + observable_up_down_counter, + up_down_counter +}; + +class SelectorConfiguration +{ +public: + SelectorConfiguration() = default; + ~SelectorConfiguration() = default; + + std::string instrument_name; + enum_instrument_type instrument_type{counter}; + std::string unit; + std::string meter_name; + std::string meter_version; + std::string meter_schema_url; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/simple_log_record_processor_configuration.h b/sdk/include/opentelemetry/sdk/configuration/simple_log_record_processor_configuration.h new file mode 100644 index 0000000000..aed3a3680c --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/simple_log_record_processor_configuration.h @@ -0,0 +1,34 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/log_record_processor_configuration.h" +#include "opentelemetry/sdk/configuration/log_record_processor_configuration_visitor.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/logger_provider.json +// YAML-NODE: SimpleLogRecordProcessor +class SimpleLogRecordProcessorConfiguration : public LogRecordProcessorConfiguration +{ +public: + SimpleLogRecordProcessorConfiguration() = default; + ~SimpleLogRecordProcessorConfiguration() override = default; + + void Accept(LogRecordProcessorConfigurationVisitor *visitor) const override + { + visitor->VisitSimple(this); + } + + std::unique_ptr exporter; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/simple_span_processor_configuration.h b/sdk/include/opentelemetry/sdk/configuration/simple_span_processor_configuration.h new file mode 100644 index 0000000000..91ed84ec02 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/simple_span_processor_configuration.h @@ -0,0 +1,34 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/span_processor_configuration.h" +#include "opentelemetry/sdk/configuration/span_processor_configuration_visitor.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/tracer_provider.json +// YAML-NODE: SimpleSpanProcessor +class SimpleSpanProcessorConfiguration : public SpanProcessorConfiguration +{ +public: + SimpleSpanProcessorConfiguration() = default; + ~SimpleSpanProcessorConfiguration() override = default; + + void Accept(SpanProcessorConfigurationVisitor *visitor) const override + { + visitor->VisitSimple(this); + } + + std::unique_ptr exporter; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/span_exporter_configuration.h b/sdk/include/opentelemetry/sdk/configuration/span_exporter_configuration.h new file mode 100644 index 0000000000..1231dfc29d --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/span_exporter_configuration.h @@ -0,0 +1,28 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ +class SpanExporterConfigurationVisitor; + +// YAML-SCHEMA: schema/tracer_provider.json +// YAML-NODE: SpanExporter +class SpanExporterConfiguration +{ +public: + SpanExporterConfiguration() = default; + virtual ~SpanExporterConfiguration() = default; + + virtual void Accept(SpanExporterConfigurationVisitor *visitor) const = 0; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/span_exporter_configuration_visitor.h b/sdk/include/opentelemetry/sdk/configuration/span_exporter_configuration_visitor.h new file mode 100644 index 0000000000..6b9c56075d --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/span_exporter_configuration_visitor.h @@ -0,0 +1,33 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +class OtlpSpanExporterConfiguration; +class ConsoleSpanExporterConfiguration; +class ZipkinSpanExporterConfiguration; +class ExtensionSpanExporterConfiguration; + +class SpanExporterConfigurationVisitor +{ +public: + SpanExporterConfigurationVisitor() = default; + virtual ~SpanExporterConfigurationVisitor() = default; + + virtual void VisitOtlp(const OtlpSpanExporterConfiguration *model) = 0; + virtual void VisitConsole(const ConsoleSpanExporterConfiguration *model) = 0; + virtual void VisitZipkin(const ZipkinSpanExporterConfiguration *model) = 0; + virtual void VisitExtension(const ExtensionSpanExporterConfiguration *model) = 0; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/span_limits_configuration.h b/sdk/include/opentelemetry/sdk/configuration/span_limits_configuration.h new file mode 100644 index 0000000000..fa7059e5ae --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/span_limits_configuration.h @@ -0,0 +1,29 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/tracer_provider.json +// YAML-NODE: SpanLimits +class SpanLimitsConfiguration +{ +public: + size_t attribute_value_length_limit; + size_t attribute_count_limit; + size_t event_count_limit; + size_t link_count_limit; + size_t event_attribute_count_limit; + size_t link_attribute_count_limit; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/span_processor_configuration.h b/sdk/include/opentelemetry/sdk/configuration/span_processor_configuration.h new file mode 100644 index 0000000000..9182a5eb52 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/span_processor_configuration.h @@ -0,0 +1,28 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ +class SpanProcessorConfigurationVisitor; + +// YAML-SCHEMA: schema/tracer_provider.json +// YAML-NODE: SpanProcessor +class SpanProcessorConfiguration +{ +public: + SpanProcessorConfiguration() = default; + virtual ~SpanProcessorConfiguration() = default; + + virtual void Accept(SpanProcessorConfigurationVisitor *visitor) const = 0; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/span_processor_configuration_visitor.h b/sdk/include/opentelemetry/sdk/configuration/span_processor_configuration_visitor.h new file mode 100644 index 0000000000..f905d5b34e --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/span_processor_configuration_visitor.h @@ -0,0 +1,31 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +class BatchSpanProcessorConfiguration; +class SimpleSpanProcessorConfiguration; +class ExtensionSpanProcessorConfiguration; + +class SpanProcessorConfigurationVisitor +{ +public: + SpanProcessorConfigurationVisitor() = default; + virtual ~SpanProcessorConfigurationVisitor() = default; + + virtual void VisitBatch(const BatchSpanProcessorConfiguration *model) = 0; + virtual void VisitSimple(const SimpleSpanProcessorConfiguration *model) = 0; + virtual void VisitExtension(const ExtensionSpanProcessorConfiguration *model) = 0; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/stream_configuration.h b/sdk/include/opentelemetry/sdk/configuration/stream_configuration.h new file mode 100644 index 0000000000..e445db976e --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/stream_configuration.h @@ -0,0 +1,31 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/aggregation_configuration.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +class StreamConfiguration +{ +public: + StreamConfiguration() = default; + ~StreamConfiguration() = default; + + std::string name; + std::string description; + std::unique_ptr aggregation; + std::vector attribute_keys; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/string_array_configuration.h b/sdk/include/opentelemetry/sdk/configuration/string_array_configuration.h new file mode 100644 index 0000000000..81427caf06 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/string_array_configuration.h @@ -0,0 +1,27 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/common.json +// YAML-NODE: included +// YAML-NODE: excluded +class StringArrayConfiguration +{ +public: + std::vector string_array; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/sum_aggregation_configuration.h b/sdk/include/opentelemetry/sdk/configuration/sum_aggregation_configuration.h new file mode 100644 index 0000000000..cfcd44d620 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/sum_aggregation_configuration.h @@ -0,0 +1,28 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/aggregation_configuration.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/meter_provider.json +// YAML-NODE: sum +class SumAggregationConfiguration : public AggregationConfiguration +{ +public: + SumAggregationConfiguration() = default; + ~SumAggregationConfiguration() override = default; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/trace_id_ratio_based_sampler_configuration.h b/sdk/include/opentelemetry/sdk/configuration/trace_id_ratio_based_sampler_configuration.h new file mode 100644 index 0000000000..e9f590c77a --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/trace_id_ratio_based_sampler_configuration.h @@ -0,0 +1,34 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/sampler_configuration.h" +#include "opentelemetry/sdk/configuration/sampler_configuration_visitor.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/tracer_provider.json +// YAML-NODE: trace_id_ratio_based +class TraceIdRatioBasedSamplerConfiguration : public SamplerConfiguration +{ +public: + TraceIdRatioBasedSamplerConfiguration() = default; + ~TraceIdRatioBasedSamplerConfiguration() override = default; + + void Accept(SamplerConfigurationVisitor *visitor) const override + { + visitor->VisitTraceIdRatioBased(this); + } + + double ratio{0.0}; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/tracer_provider_configuration.h b/sdk/include/opentelemetry/sdk/configuration/tracer_provider_configuration.h new file mode 100644 index 0000000000..79b77bbfbf --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/tracer_provider_configuration.h @@ -0,0 +1,32 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include +#include + +#include "opentelemetry/sdk/configuration/sampler_configuration.h" +#include "opentelemetry/sdk/configuration/span_limits_configuration.h" +#include "opentelemetry/sdk/configuration/span_processor_configuration.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/tracer_provider.json +// YAML-NODE: TracerProvider +class TracerProviderConfiguration +{ +public: + std::vector> processors; + std::unique_ptr limits; + std::unique_ptr sampler; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/view_configuration.h b/sdk/include/opentelemetry/sdk/configuration/view_configuration.h new file mode 100644 index 0000000000..ab525ead17 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/view_configuration.h @@ -0,0 +1,30 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/selector_configuration.h" +#include "opentelemetry/sdk/configuration/stream_configuration.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +class ViewConfiguration +{ +public: + ViewConfiguration() = default; + ~ViewConfiguration() = default; + + std::unique_ptr selector; + std::unique_ptr stream; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/yaml_configuration_factory.h b/sdk/include/opentelemetry/sdk/configuration/yaml_configuration_factory.h new file mode 100644 index 0000000000..5666df7c3f --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/yaml_configuration_factory.h @@ -0,0 +1,29 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include +#include +#include + +#include "opentelemetry/sdk/configuration/configuration.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +class YamlConfigurationFactory +{ +public: + static std::unique_ptr ParseFile(const std::string &filename); + static std::unique_ptr ParseString(const std::string &source, + const std::string &content); +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/zipkin_span_exporter_configuration.h b/sdk/include/opentelemetry/sdk/configuration/zipkin_span_exporter_configuration.h new file mode 100644 index 0000000000..c5946044bb --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/zipkin_span_exporter_configuration.h @@ -0,0 +1,37 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/span_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/span_exporter_configuration_visitor.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// YAML-SCHEMA: schema/tracer_provider.json +// YAML-NODE: Zipkin +class ZipkinSpanExporterConfiguration : public SpanExporterConfiguration +{ +public: + ZipkinSpanExporterConfiguration() = default; + ~ZipkinSpanExporterConfiguration() override = default; + + void Accept(SpanExporterConfigurationVisitor *visitor) const override + { + visitor->VisitZipkin(this); + } + + std::string endpoint; + size_t timeout{0}; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/init/configured_sdk.h b/sdk/include/opentelemetry/sdk/init/configured_sdk.h new file mode 100644 index 0000000000..941269a801 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/init/configured_sdk.h @@ -0,0 +1,42 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/context/propagation/text_map_propagator.h" +#include "opentelemetry/sdk/configuration/configuration.h" +#include "opentelemetry/sdk/init/registry.h" +#include "opentelemetry/sdk/logs/logger_provider.h" +#include "opentelemetry/sdk/metrics/meter_provider.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/sdk/trace/tracer_provider.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace init +{ + +class ConfiguredSdk +{ +public: + static std::unique_ptr Create( + std::shared_ptr registry, + const std::unique_ptr &model); + + ConfiguredSdk() : m_resource(opentelemetry::sdk::resource::Resource::GetEmpty()) {} + + void Install(); + void UnInstall(); + + opentelemetry::sdk::resource::Resource m_resource; + std::shared_ptr m_tracer_provider; + std::shared_ptr m_propagator; + std::shared_ptr m_meter_provider; + std::shared_ptr m_logger_provider; +}; + +} // namespace init +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/init/console_log_record_exporter_builder.h b/sdk/include/opentelemetry/sdk/init/console_log_record_exporter_builder.h new file mode 100644 index 0000000000..aeab09ed4c --- /dev/null +++ b/sdk/include/opentelemetry/sdk/init/console_log_record_exporter_builder.h @@ -0,0 +1,29 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/console_log_record_exporter_configuration.h" +#include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace init +{ + +class ConsoleLogRecordExporterBuilder +{ +public: + ConsoleLogRecordExporterBuilder() = default; + virtual ~ConsoleLogRecordExporterBuilder() = default; + + virtual std::unique_ptr Build( + const opentelemetry::sdk::configuration::ConsoleLogRecordExporterConfiguration *model) + const = 0; +}; + +} // namespace init +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/init/console_push_metric_exporter_builder.h b/sdk/include/opentelemetry/sdk/init/console_push_metric_exporter_builder.h new file mode 100644 index 0000000000..f00cb7ac43 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/init/console_push_metric_exporter_builder.h @@ -0,0 +1,29 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/console_push_metric_exporter_configuration.h" +#include "opentelemetry/sdk/metrics/push_metric_exporter.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace init +{ + +class ConsolePushMetricExporterBuilder +{ +public: + ConsolePushMetricExporterBuilder() = default; + virtual ~ConsolePushMetricExporterBuilder() = default; + + virtual std::unique_ptr Build( + const opentelemetry::sdk::configuration::ConsolePushMetricExporterConfiguration *model) + const = 0; +}; + +} // namespace init +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/init/console_span_exporter_builder.h b/sdk/include/opentelemetry/sdk/init/console_span_exporter_builder.h new file mode 100644 index 0000000000..60f159f373 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/init/console_span_exporter_builder.h @@ -0,0 +1,28 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/console_span_exporter_configuration.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace init +{ + +class ConsoleSpanExporterBuilder +{ +public: + ConsoleSpanExporterBuilder() = default; + virtual ~ConsoleSpanExporterBuilder() = default; + + virtual std::unique_ptr Build( + const opentelemetry::sdk::configuration::ConsoleSpanExporterConfiguration *model) const = 0; +}; + +} // namespace init +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/init/extension_log_record_exporter_builder.h b/sdk/include/opentelemetry/sdk/init/extension_log_record_exporter_builder.h new file mode 100644 index 0000000000..5540f05c54 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/init/extension_log_record_exporter_builder.h @@ -0,0 +1,29 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/extension_log_record_exporter_configuration.h" +#include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace init +{ + +class ExtensionLogRecordExporterBuilder +{ +public: + ExtensionLogRecordExporterBuilder() = default; + virtual ~ExtensionLogRecordExporterBuilder() = default; + + virtual std::unique_ptr Build( + const opentelemetry::sdk::configuration::ExtensionLogRecordExporterConfiguration *model) + const = 0; +}; + +} // namespace init +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/init/extension_log_record_processor_builder.h b/sdk/include/opentelemetry/sdk/init/extension_log_record_processor_builder.h new file mode 100644 index 0000000000..16b251ad21 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/init/extension_log_record_processor_builder.h @@ -0,0 +1,29 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/extension_log_record_processor_configuration.h" +#include "opentelemetry/sdk/logs/processor.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace init +{ + +class ExtensionLogRecordProcessorBuilder +{ +public: + ExtensionLogRecordProcessorBuilder() = default; + virtual ~ExtensionLogRecordProcessorBuilder() = default; + + virtual std::unique_ptr Build( + const opentelemetry::sdk::configuration::ExtensionLogRecordProcessorConfiguration *model) + const = 0; +}; + +} // namespace init +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/init/extension_pull_metric_exporter_builder.h b/sdk/include/opentelemetry/sdk/init/extension_pull_metric_exporter_builder.h new file mode 100644 index 0000000000..f1b55de2ac --- /dev/null +++ b/sdk/include/opentelemetry/sdk/init/extension_pull_metric_exporter_builder.h @@ -0,0 +1,29 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/extension_pull_metric_exporter_configuration.h" +#include "opentelemetry/sdk/metrics/metric_reader.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace init +{ + +class ExtensionPullMetricExporterBuilder +{ +public: + ExtensionPullMetricExporterBuilder() = default; + virtual ~ExtensionPullMetricExporterBuilder() = default; + + virtual std::unique_ptr Build( + const opentelemetry::sdk::configuration::ExtensionPullMetricExporterConfiguration *model) + const = 0; +}; + +} // namespace init +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/init/extension_push_metric_exporter_builder.h b/sdk/include/opentelemetry/sdk/init/extension_push_metric_exporter_builder.h new file mode 100644 index 0000000000..af1890de25 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/init/extension_push_metric_exporter_builder.h @@ -0,0 +1,29 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/extension_span_exporter_configuration.h" +#include "opentelemetry/sdk/metrics/push_metric_exporter.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace init +{ + +class ExtensionPushMetricExporterBuilder +{ +public: + ExtensionPushMetricExporterBuilder() = default; + virtual ~ExtensionPushMetricExporterBuilder() = default; + + virtual std::unique_ptr Build( + const opentelemetry::sdk::configuration::ExtensionPushMetricExporterConfiguration *model) + const = 0; +}; + +} // namespace init +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/init/extension_sampler_builder.h b/sdk/include/opentelemetry/sdk/init/extension_sampler_builder.h new file mode 100644 index 0000000000..dcd8498aaf --- /dev/null +++ b/sdk/include/opentelemetry/sdk/init/extension_sampler_builder.h @@ -0,0 +1,28 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/extension_sampler_configuration.h" +#include "opentelemetry/sdk/trace/sampler.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace init +{ + +class ExtensionSamplerBuilder +{ +public: + ExtensionSamplerBuilder() = default; + virtual ~ExtensionSamplerBuilder() = default; + + virtual std::unique_ptr Build( + const opentelemetry::sdk::configuration::ExtensionSamplerConfiguration *model) const = 0; +}; + +} // namespace init +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/init/extension_span_exporter_builder.h b/sdk/include/opentelemetry/sdk/init/extension_span_exporter_builder.h new file mode 100644 index 0000000000..95e08b2a9b --- /dev/null +++ b/sdk/include/opentelemetry/sdk/init/extension_span_exporter_builder.h @@ -0,0 +1,28 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/extension_span_exporter_configuration.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace init +{ + +class ExtensionSpanExporterBuilder +{ +public: + ExtensionSpanExporterBuilder() = default; + virtual ~ExtensionSpanExporterBuilder() = default; + + virtual std::unique_ptr Build( + const opentelemetry::sdk::configuration::ExtensionSpanExporterConfiguration *model) const = 0; +}; + +} // namespace init +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/init/extension_span_processor_builder.h b/sdk/include/opentelemetry/sdk/init/extension_span_processor_builder.h new file mode 100644 index 0000000000..d4d6ac7ec2 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/init/extension_span_processor_builder.h @@ -0,0 +1,29 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/extension_span_processor_configuration.h" +#include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace init +{ + +class ExtensionSpanProcessorBuilder +{ +public: + ExtensionSpanProcessorBuilder() = default; + virtual ~ExtensionSpanProcessorBuilder() = default; + + virtual std::unique_ptr Build( + const opentelemetry::sdk::configuration::ExtensionSpanProcessorConfiguration *model) + const = 0; +}; + +} // namespace init +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/init/otlp_log_record_exporter_builder.h b/sdk/include/opentelemetry/sdk/init/otlp_log_record_exporter_builder.h new file mode 100644 index 0000000000..effea6a196 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/init/otlp_log_record_exporter_builder.h @@ -0,0 +1,28 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/otlp_log_record_exporter_configuration.h" +#include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace init +{ + +class OtlpLogRecordExporterBuilder +{ +public: + OtlpLogRecordExporterBuilder() = default; + virtual ~OtlpLogRecordExporterBuilder() = default; + + virtual std::unique_ptr Build( + const opentelemetry::sdk::configuration::OtlpLogRecordExporterConfiguration *model) const = 0; +}; + +} // namespace init +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/init/otlp_push_metric_exporter_builder.h b/sdk/include/opentelemetry/sdk/init/otlp_push_metric_exporter_builder.h new file mode 100644 index 0000000000..f1ff3a544b --- /dev/null +++ b/sdk/include/opentelemetry/sdk/init/otlp_push_metric_exporter_builder.h @@ -0,0 +1,29 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/push_metric_exporter_configuration.h" +#include "opentelemetry/sdk/metrics/push_metric_exporter.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace init +{ + +class OtlpPushMetricExporterBuilder +{ +public: + OtlpPushMetricExporterBuilder() = default; + virtual ~OtlpPushMetricExporterBuilder() = default; + + virtual std::unique_ptr Build( + const opentelemetry::sdk::configuration::OtlpPushMetricExporterConfiguration *model) + const = 0; +}; + +} // namespace init +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/init/otlp_span_exporter_builder.h b/sdk/include/opentelemetry/sdk/init/otlp_span_exporter_builder.h new file mode 100644 index 0000000000..1607b595d2 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/init/otlp_span_exporter_builder.h @@ -0,0 +1,28 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/otlp_span_exporter_configuration.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace init +{ + +class OtlpSpanExporterBuilder +{ +public: + OtlpSpanExporterBuilder() = default; + virtual ~OtlpSpanExporterBuilder() = default; + + virtual std::unique_ptr Build( + const opentelemetry::sdk::configuration::OtlpSpanExporterConfiguration *model) const = 0; +}; + +} // namespace init +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/init/prometheus_pull_metric_exporter_builder.h b/sdk/include/opentelemetry/sdk/init/prometheus_pull_metric_exporter_builder.h new file mode 100644 index 0000000000..56d9e1d39b --- /dev/null +++ b/sdk/include/opentelemetry/sdk/init/prometheus_pull_metric_exporter_builder.h @@ -0,0 +1,29 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/prometheus_pull_metric_exporter_configuration.h" +#include "opentelemetry/sdk/metrics/metric_reader.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace init +{ + +class PrometheusPullMetricExporterBuilder +{ +public: + PrometheusPullMetricExporterBuilder() = default; + virtual ~PrometheusPullMetricExporterBuilder() = default; + + virtual std::unique_ptr Build( + const opentelemetry::sdk::configuration::PrometheusPullMetricExporterConfiguration *model) + const = 0; +}; + +} // namespace init +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/init/registry.h b/sdk/include/opentelemetry/sdk/init/registry.h new file mode 100644 index 0000000000..dc19dc8739 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/init/registry.h @@ -0,0 +1,193 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include +#include + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace init +{ +class OtlpSpanExporterBuilder; +class ConsoleSpanExporterBuilder; +class ZipkinSpanExporterBuilder; +class TextMapPropagatorBuilder; +class ExtensionSamplerBuilder; +class ExtensionSpanExporterBuilder; +class ExtensionSpanProcessorBuilder; + +class OtlpPushMetricExporterBuilder; +class ConsolePushMetricExporterBuilder; +class ExtensionPushMetricExporterBuilder; +class PrometheusPullMetricExporterBuilder; +class ExtensionPullMetricExporterBuilder; + +class OtlpLogRecordExporterBuilder; +class ConsoleLogRecordExporterBuilder; +class ExtensionLogRecordExporterBuilder; +class ExtensionLogRecordProcessorBuilder; + +class Registry +{ +public: + Registry(); + ~Registry() = default; + + /* Core optional components. */ + + const OtlpSpanExporterBuilder *GetOtlpHttpSpanBuilder() { return m_otlp_http_span_builder; } + void SetOtlpHttpSpanBuilder(const OtlpSpanExporterBuilder *builder) + { + m_otlp_http_span_builder = builder; + } + + const OtlpSpanExporterBuilder *GetOtlpGrpcSpanBuilder() { return m_otlp_grpc_span_builder; } + void SetOtlpGrpcSpanBuilder(const OtlpSpanExporterBuilder *builder) + { + m_otlp_grpc_span_builder = builder; + } + + const ConsoleSpanExporterBuilder *GetConsoleSpanBuilder() { return m_console_span_builder; } + void SetConsoleSpanBuilder(const ConsoleSpanExporterBuilder *builder) + { + m_console_span_builder = builder; + } + + const ZipkinSpanExporterBuilder *GetZipkinSpanBuilder() { return m_zipkin_span_builder; } + void SetZipkinSpanBuilder(const ZipkinSpanExporterBuilder *builder) + { + m_zipkin_span_builder = builder; + } + + const OtlpPushMetricExporterBuilder *GetOtlpHttpPushMetricExporterBuilder() + { + return m_otlp_http_push_metric_builder; + } + void SetOtlpHttpPushMetricExporterBuilder(const OtlpPushMetricExporterBuilder *builder) + { + m_otlp_http_push_metric_builder = builder; + } + + const OtlpPushMetricExporterBuilder *GetOtlpGrpcPushMetricExporterBuilder() + { + return m_otlp_grpc_push_metric_builder; + } + void SetOtlpGrpcPushMetricExporterBuilder(const OtlpPushMetricExporterBuilder *builder) + { + m_otlp_grpc_push_metric_builder = builder; + } + + const ConsolePushMetricExporterBuilder *GetConsolePushMetricExporterBuilder() + { + return m_console_metric_builder; + } + void SetConsolePushMetricExporterBuilder(const ConsolePushMetricExporterBuilder *builder) + { + m_console_metric_builder = builder; + } + + const PrometheusPullMetricExporterBuilder *GetPrometheusPullMetricExporterBuilder() + { + return m_prometheus_metric_builder; + } + void SetPrometheusPullMetricExporterBuilder(const PrometheusPullMetricExporterBuilder *builder) + { + m_prometheus_metric_builder = builder; + } + + const OtlpLogRecordExporterBuilder *GetOtlpHttpLogRecordBuilder() + { + return m_otlp_http_log_record_builder; + } + void SetOtlpHttpLogRecordBuilder(const OtlpLogRecordExporterBuilder *builder) + { + m_otlp_http_log_record_builder = builder; + } + + const OtlpLogRecordExporterBuilder *GetOtlpGrpcLogRecordBuilder() + { + return m_otlp_grpc_log_record_builder; + } + void SetOtlpGrpcLogRecordBuilder(const OtlpLogRecordExporterBuilder *builder) + { + m_otlp_grpc_log_record_builder = builder; + } + + const ConsoleLogRecordExporterBuilder *GetConsoleLogRecordBuilder() + { + return m_console_log_record_builder; + } + void SetConsoleLogRecordBuilder(const ConsoleLogRecordExporterBuilder *builder) + { + m_console_log_record_builder = builder; + } + + /* Extension points */ + + const TextMapPropagatorBuilder *GetTextMapPropagatorBuilder(const std::string &name); + void AddTextMapPropagatorBuilder(const std::string &name, TextMapPropagatorBuilder *builder); + + const ExtensionSamplerBuilder *GetExtensionSamplerBuilder(const std::string &name); + void AddExtensionSamplerBuilder(const std::string &name, ExtensionSamplerBuilder *builder); + + const ExtensionSpanExporterBuilder *GetExtensionSpanExporterBuilder(const std::string &name); + void AddExtensionSpanExporterBuilder(const std::string &name, + ExtensionSpanExporterBuilder *builder); + + const ExtensionSpanProcessorBuilder *GetExtensionSpanProcessorBuilder(const std::string &name); + void AddExtensionSpanProcessorBuilder(const std::string &name, + ExtensionSpanProcessorBuilder *builder); + + const ExtensionPushMetricExporterBuilder *GetExtensionPushMetricExporterBuilder( + const std::string &name); + void AddExtensionPushMetricExporterBuilder(const std::string &name, + ExtensionPushMetricExporterBuilder *builder); + + const ExtensionPullMetricExporterBuilder *GetExtensionPullMetricExporterBuilder( + const std::string &name); + void AddExtensionPullMetricExporterBuilder(const std::string &name, + ExtensionPullMetricExporterBuilder *builder); + + const ExtensionLogRecordExporterBuilder *GetExtensionLogRecordExporterBuilder( + const std::string &name); + void AddExtensionLogRecordExporterBuilder(const std::string &name, + ExtensionLogRecordExporterBuilder *builder); + + const ExtensionLogRecordProcessorBuilder *GetExtensionLogRecordProcessorBuilder( + const std::string &name); + void AddExtensionLogRecordProcessorBuilder(const std::string &name, + ExtensionLogRecordProcessorBuilder *builder); + +private: + const OtlpSpanExporterBuilder *m_otlp_http_span_builder{nullptr}; + const OtlpSpanExporterBuilder *m_otlp_grpc_span_builder{nullptr}; + const ConsoleSpanExporterBuilder *m_console_span_builder{nullptr}; + const ZipkinSpanExporterBuilder *m_zipkin_span_builder{nullptr}; + + const OtlpPushMetricExporterBuilder *m_otlp_http_push_metric_builder{nullptr}; + const OtlpPushMetricExporterBuilder *m_otlp_grpc_push_metric_builder{nullptr}; + const ConsolePushMetricExporterBuilder *m_console_metric_builder{nullptr}; + const PrometheusPullMetricExporterBuilder *m_prometheus_metric_builder{nullptr}; + + const OtlpLogRecordExporterBuilder *m_otlp_http_log_record_builder{nullptr}; + const OtlpLogRecordExporterBuilder *m_otlp_grpc_log_record_builder{nullptr}; + const ConsoleLogRecordExporterBuilder *m_console_log_record_builder{nullptr}; + + std::map m_propagator_builders; + std::map m_sampler_builders; + std::map m_span_exporter_builders; + std::map m_span_processor_builders; + std::map m_push_metric_exporter_builders; + std::map m_pull_metric_exporter_builders; + std::map m_log_record_exporter_builders; + std::map m_log_record_processor_builders; +}; + +} // namespace init +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/init/sdk_builder.h b/sdk/include/opentelemetry/sdk/init/sdk_builder.h new file mode 100644 index 0000000000..5666dba5f6 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/init/sdk_builder.h @@ -0,0 +1,204 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/always_off_sampler_configuration.h" +#include "opentelemetry/sdk/configuration/batch_log_record_processor_configuration.h" +#include "opentelemetry/sdk/configuration/batch_span_processor_configuration.h" +#include "opentelemetry/sdk/configuration/configuration.h" +#include "opentelemetry/sdk/configuration/console_log_record_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/console_push_metric_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/extension_pull_metric_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/extension_push_metric_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/extension_span_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/extension_span_processor_configuration.h" +#include "opentelemetry/sdk/configuration/metric_reader_configuration.h" +#include "opentelemetry/sdk/configuration/otlp_log_record_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/otlp_push_metric_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/otlp_span_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/periodic_metric_reader_configuration.h" +#include "opentelemetry/sdk/configuration/prometheus_pull_metric_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/pull_metric_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/pull_metric_reader_configuration.h" +#include "opentelemetry/sdk/configuration/push_metric_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/simple_span_processor_configuration.h" +#include "opentelemetry/sdk/configuration/span_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/zipkin_span_exporter_configuration.h" +#include "opentelemetry/sdk/init/registry.h" +#include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/sdk/logs/logger_provider.h" +#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader.h" +#include "opentelemetry/sdk/metrics/meter_provider.h" +#include "opentelemetry/sdk/metrics/push_metric_exporter.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/sampler.h" +#include "opentelemetry/trace/tracer_provider.h" + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace init +{ + +class SdkBuilder +{ +public: + SdkBuilder(std::shared_ptr registry) : m_registry(registry) {} + ~SdkBuilder() = default; + + std::unique_ptr CreateAlwaysOffSampler( + const opentelemetry::sdk::configuration::AlwaysOffSamplerConfiguration *model) const; + + std::unique_ptr CreateAlwaysOnSampler( + const opentelemetry::sdk::configuration::AlwaysOnSamplerConfiguration *model) const; + + std::unique_ptr CreateJaegerRemoteSampler( + const opentelemetry::sdk::configuration::JaegerRemoteSamplerConfiguration *model) const; + + std::unique_ptr CreateParentBasedSampler( + const opentelemetry::sdk::configuration::ParentBasedSamplerConfiguration *model) const; + + std::unique_ptr CreateTraceIdRatioBasedSampler( + const opentelemetry::sdk::configuration::TraceIdRatioBasedSamplerConfiguration *model) const; + + std::unique_ptr CreateExtensionSampler( + const opentelemetry::sdk::configuration::ExtensionSamplerConfiguration *model) const; + + std::unique_ptr CreateSampler( + const std::unique_ptr &model) const; + + std::unique_ptr CreateOtlpSpanExporter( + const opentelemetry::sdk::configuration::OtlpSpanExporterConfiguration *model) const; + + std::unique_ptr CreateConsoleSpanExporter( + const opentelemetry::sdk::configuration::ConsoleSpanExporterConfiguration *model) const; + + std::unique_ptr CreateZipkinSpanExporter( + const opentelemetry::sdk::configuration::ZipkinSpanExporterConfiguration *model) const; + + std::unique_ptr CreateExtensionSpanExporter( + const opentelemetry::sdk::configuration::ExtensionSpanExporterConfiguration *model) const; + + std::unique_ptr CreateSpanExporter( + const std::unique_ptr &model) + const; + + std::unique_ptr CreateBatchSpanProcessor( + const opentelemetry::sdk::configuration::BatchSpanProcessorConfiguration *model) const; + + std::unique_ptr CreateSimpleSpanProcessor( + const opentelemetry::sdk::configuration::SimpleSpanProcessorConfiguration *model) const; + + std::unique_ptr CreateExtensionSpanProcessor( + const opentelemetry::sdk::configuration::ExtensionSpanProcessorConfiguration *model) const; + + std::unique_ptr CreateSpanProcessor( + const std::unique_ptr &model) + const; + + std::unique_ptr CreateTracerProvider( + const std::unique_ptr &model, + const opentelemetry::sdk::resource::Resource &resource) const; + + std::unique_ptr CreateTextMapPropagator( + const std::string &name) const; + + std::unique_ptr CreatePropagator( + const std::unique_ptr &model) + const; + + std::unique_ptr CreateOtlpPushMetricExporter( + const opentelemetry::sdk::configuration::OtlpPushMetricExporterConfiguration *model) const; + + std::unique_ptr CreateConsolePushMetricExporter( + const opentelemetry::sdk::configuration::ConsolePushMetricExporterConfiguration *model) const; + + std::unique_ptr + CreateExtensionPushMetricExporter( + const opentelemetry::sdk::configuration::ExtensionPushMetricExporterConfiguration *model) + const; + + std::unique_ptr CreatePrometheusPullMetricExporter( + const opentelemetry::sdk::configuration::PrometheusPullMetricExporterConfiguration *model) + const; + + std::unique_ptr CreateExtensionPullMetricExporter( + const opentelemetry::sdk::configuration::ExtensionPullMetricExporterConfiguration *model) + const; + + std::unique_ptr CreatePushMetricExporter( + const std::unique_ptr + &model) const; + + std::unique_ptr CreatePullMetricExporter( + const std::unique_ptr + &model) const; + + std::unique_ptr CreatePeriodicMetricReader( + const opentelemetry::sdk::configuration::PeriodicMetricReaderConfiguration *model) const; + + std::unique_ptr CreatePullMetricReader( + const opentelemetry::sdk::configuration::PullMetricReaderConfiguration *model) const; + + std::unique_ptr CreateMetricReader( + const std::unique_ptr &model) + const; + + void AddView( + opentelemetry::sdk::metrics::ViewRegistry *registry, + const std::unique_ptr &model) const; + + std::unique_ptr CreateMeterProvider( + const std::unique_ptr &model, + const opentelemetry::sdk::resource::Resource &resource) const; + + std::unique_ptr CreateOtlpLogRecordExporter( + const opentelemetry::sdk::configuration::OtlpLogRecordExporterConfiguration *model) const; + + std::unique_ptr CreateConsoleLogRecordExporter( + const opentelemetry::sdk::configuration::ConsoleLogRecordExporterConfiguration *model) const; + + std::unique_ptr CreateExtensionLogRecordExporter( + const opentelemetry::sdk::configuration::ExtensionLogRecordExporterConfiguration *model) + const; + + std::unique_ptr CreateLogRecordExporter( + const std::unique_ptr + &model) const; + + std::unique_ptr CreateBatchLogRecordProcessor( + const opentelemetry::sdk::configuration::BatchLogRecordProcessorConfiguration *model) const; + + std::unique_ptr CreateSimpleLogRecordProcessor( + const opentelemetry::sdk::configuration::SimpleLogRecordProcessorConfiguration *model) const; + + std::unique_ptr CreateExtensionLogRecordProcessor( + const opentelemetry::sdk::configuration::ExtensionLogRecordProcessorConfiguration *model) + const; + + std::unique_ptr CreateLogRecordProcessor( + const std::unique_ptr + &model) const; + + std::unique_ptr CreateLoggerProvider( + const std::unique_ptr &model, + const opentelemetry::sdk::resource::Resource &resource) const; + + void SetResource(opentelemetry::sdk::resource::Resource &resource, + const std::unique_ptr + &opt_model) const; + + std::unique_ptr CreateConfiguredSdk( + const std::unique_ptr &model) const; + +private: + std::shared_ptr m_registry; +}; + +} // namespace init +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/init/text_map_propagator_builder.h b/sdk/include/opentelemetry/sdk/init/text_map_propagator_builder.h new file mode 100644 index 0000000000..0e1825c420 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/init/text_map_propagator_builder.h @@ -0,0 +1,26 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/context/propagation/text_map_propagator.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace init +{ + +class TextMapPropagatorBuilder +{ +public: + TextMapPropagatorBuilder() = default; + virtual ~TextMapPropagatorBuilder() = default; + + virtual std::unique_ptr Build() const = 0; +}; + +} // namespace init +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/init/unsupported_exception.h b/sdk/include/opentelemetry/sdk/init/unsupported_exception.h new file mode 100644 index 0000000000..3dc4face55 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/init/unsupported_exception.h @@ -0,0 +1,26 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace init +{ + +class UnsupportedException : public std::runtime_error +{ +public: + UnsupportedException(const std::string &msg) : std::runtime_error(msg) {} + + ~UnsupportedException() override = default; +}; + +} // namespace init +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/init/zipkin_span_exporter_builder.h b/sdk/include/opentelemetry/sdk/init/zipkin_span_exporter_builder.h new file mode 100644 index 0000000000..b2b745152e --- /dev/null +++ b/sdk/include/opentelemetry/sdk/init/zipkin_span_exporter_builder.h @@ -0,0 +1,28 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/zipkin_span_exporter_configuration.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace init +{ + +class ZipkinSpanExporterBuilder +{ +public: + ZipkinSpanExporterBuilder() = default; + virtual ~ZipkinSpanExporterBuilder() = default; + + virtual std::unique_ptr Build( + const opentelemetry::sdk::configuration::ZipkinSpanExporterConfiguration *model) const = 0; +}; + +} // namespace init +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor_options.h b/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor_options.h index b130f947af..84e03bcf37 100644 --- a/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor_options.h +++ b/sdk/include/opentelemetry/sdk/logs/batch_log_record_processor_options.h @@ -16,7 +16,7 @@ namespace logs { /** - * Struct to hold batch SpanProcessor options. + * Struct to hold batch LogRecordProcessor options. */ struct BatchLogRecordProcessorOptions { diff --git a/sdk/include/opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_factory.h b/sdk/include/opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_factory.h index 8cb439599e..c908295f1a 100644 --- a/sdk/include/opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_factory.h +++ b/sdk/include/opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_factory.h @@ -19,6 +19,7 @@ namespace metrics class OPENTELEMETRY_EXPORT PeriodicExportingMetricReaderFactory { public: + // FIXME, return type static std::unique_ptr Create(std::unique_ptr exporter, const PeriodicExportingMetricReaderOptions &option); }; diff --git a/sdk/include/opentelemetry/sdk/resource/resource.h b/sdk/include/opentelemetry/sdk/resource/resource.h index d578491d78..b89e84649e 100644 --- a/sdk/include/opentelemetry/sdk/resource/resource.h +++ b/sdk/include/opentelemetry/sdk/resource/resource.h @@ -19,7 +19,14 @@ using ResourceAttributes = opentelemetry::sdk::common::AttributeMap; class Resource { public: - Resource(const Resource &) = default; + Resource() noexcept; + + Resource(const ResourceAttributes &attributes) noexcept; + + Resource(const ResourceAttributes &attributes, const std::string &schema_url) noexcept; + + Resource(const Resource &) = default; + Resource &operator=(const Resource &) = default; const ResourceAttributes &GetAttributes() const noexcept; const std::string &GetSchemaURL() const noexcept; @@ -61,21 +68,9 @@ class Resource static Resource &GetDefault(); -protected: - /** - * The constructor is protected and only for use internally by the class and - * inside ResourceDetector class. - * Users should use the Create factory method to obtain a Resource - * instance. - */ - Resource(const ResourceAttributes &attributes = ResourceAttributes(), - const std::string &schema_url = std::string{}) noexcept; - private: ResourceAttributes attributes_; std::string schema_url_; - - friend class OTELResourceDetector; }; } // namespace resource diff --git a/sdk/src/CMakeLists.txt b/sdk/src/CMakeLists.txt index 377d305627..67fac35208 100644 --- a/sdk/src/CMakeLists.txt +++ b/sdk/src/CMakeLists.txt @@ -7,3 +7,8 @@ add_subdirectory(metrics) add_subdirectory(logs) add_subdirectory(version) add_subdirectory(resource) + +if(WITH_CONFIGURATION) + add_subdirectory(configuration) + add_subdirectory(init) +endif() diff --git a/sdk/src/configuration/CMakeLists.txt b/sdk/src/configuration/CMakeLists.txt new file mode 100644 index 0000000000..47d298fa19 --- /dev/null +++ b/sdk/src/configuration/CMakeLists.txt @@ -0,0 +1,36 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +add_library( + opentelemetry_configuration + configuration_factory.cc document_node.cc yaml_configuration_factory.cc + ryml_document.cc ryml_document_node.cc) + +set_target_properties(opentelemetry_configuration PROPERTIES EXPORT_NAME + configuration) +set_target_version(opentelemetry_configuration) + +target_include_directories( + opentelemetry_configuration + PUBLIC "$") + +target_link_libraries(opentelemetry_configuration PUBLIC opentelemetry_api + opentelemetry_common) + +# target_link_libraries( opentelemetry_configuration PUBLIC yaml-cpp::yaml-cpp) + +target_link_libraries(opentelemetry_configuration PUBLIC ryml::ryml) + +if(OPENTELEMETRY_INSTALL) + install( + TARGETS opentelemetry_configuration + EXPORT "${PROJECT_NAME}-target" + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + + opentelemetry_add_pkgconfig( + configuration "OpenTelemetry SDK - Configuration" + "Components for exporting traces in the OpenTelemetry SDK." + "opentelemetry_configuration") +endif() diff --git a/sdk/src/configuration/configuration_factory.cc b/sdk/src/configuration/configuration_factory.cc new file mode 100644 index 0000000000..96d1712ae1 --- /dev/null +++ b/sdk/src/configuration/configuration_factory.cc @@ -0,0 +1,1350 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/configuration/aggregation_configuration.h" +#include "opentelemetry/sdk/configuration/always_off_sampler_configuration.h" +#include "opentelemetry/sdk/configuration/always_on_sampler_configuration.h" +#include "opentelemetry/sdk/configuration/attribute_limits_configuration.h" +#include "opentelemetry/sdk/configuration/attributes_configuration.h" +#include "opentelemetry/sdk/configuration/base2_exponential_bucket_histogram_aggregation_configuration.h" +#include "opentelemetry/sdk/configuration/batch_log_record_processor_configuration.h" +#include "opentelemetry/sdk/configuration/batch_span_processor_configuration.h" +#include "opentelemetry/sdk/configuration/configuration.h" +#include "opentelemetry/sdk/configuration/configuration_factory.h" +#include "opentelemetry/sdk/configuration/console_log_record_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/console_push_metric_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/console_span_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/default_aggregation_configuration.h" +#include "opentelemetry/sdk/configuration/detectors_configuration.h" +#include "opentelemetry/sdk/configuration/document.h" +#include "opentelemetry/sdk/configuration/document_node.h" +#include "opentelemetry/sdk/configuration/drop_aggregation_configuration.h" +#include "opentelemetry/sdk/configuration/explicit_bucket_histogram_aggregation_configuration.h" +#include "opentelemetry/sdk/configuration/extension_log_record_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/extension_log_record_processor_configuration.h" +#include "opentelemetry/sdk/configuration/extension_pull_metric_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/extension_push_metric_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/extension_sampler_configuration.h" +#include "opentelemetry/sdk/configuration/extension_span_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/extension_span_processor_configuration.h" +#include "opentelemetry/sdk/configuration/headers_configuration.h" +#include "opentelemetry/sdk/configuration/invalid_schema_exception.h" +#include "opentelemetry/sdk/configuration/jaeger_remote_sampler_configuration.h" +#include "opentelemetry/sdk/configuration/last_value_aggregation_configuration.h" +#include "opentelemetry/sdk/configuration/log_record_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/log_record_limits_configuration.h" +#include "opentelemetry/sdk/configuration/log_record_processor_configuration.h" +#include "opentelemetry/sdk/configuration/logger_provider_configuration.h" +#include "opentelemetry/sdk/configuration/meter_provider_configuration.h" +#include "opentelemetry/sdk/configuration/metric_reader_configuration.h" +#include "opentelemetry/sdk/configuration/otlp_log_record_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/otlp_push_metric_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/otlp_span_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/parent_based_sampler_configuration.h" +#include "opentelemetry/sdk/configuration/periodic_metric_reader_configuration.h" +#include "opentelemetry/sdk/configuration/prometheus_pull_metric_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/propagator_configuration.h" +#include "opentelemetry/sdk/configuration/pull_metric_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/pull_metric_reader_configuration.h" +#include "opentelemetry/sdk/configuration/push_metric_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/resource_configuration.h" +#include "opentelemetry/sdk/configuration/sampler_configuration.h" +#include "opentelemetry/sdk/configuration/selector_configuration.h" +#include "opentelemetry/sdk/configuration/simple_log_record_processor_configuration.h" +#include "opentelemetry/sdk/configuration/simple_span_processor_configuration.h" +#include "opentelemetry/sdk/configuration/span_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/span_limits_configuration.h" +#include "opentelemetry/sdk/configuration/span_processor_configuration.h" +#include "opentelemetry/sdk/configuration/stream_configuration.h" +#include "opentelemetry/sdk/configuration/string_array_configuration.h" +#include "opentelemetry/sdk/configuration/sum_aggregation_configuration.h" +#include "opentelemetry/sdk/configuration/trace_id_ratio_based_sampler_configuration.h" +#include "opentelemetry/sdk/configuration/tracer_provider_configuration.h" +#include "opentelemetry/sdk/configuration/view_configuration.h" +#include "opentelemetry/sdk/configuration/zipkin_span_exporter_configuration.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +// FIXME: proper sizing +constexpr size_t MAX_SAMPLER_DEPTH = 10; + +static std::unique_ptr ParseHeadersConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model(new HeadersConfiguration); + + for (auto it = node->begin_properties(); it != node->end_properties(); ++it) + { + std::string name = it.Name(); + std::unique_ptr child = it.Value(); + std::string string_value = child->AsString(); + + OTEL_INTERNAL_LOG_DEBUG("ParseHeadersConfiguration() name = " << name + << ", value = " << string_value); + std::pair entry(name, string_value); + model->kv_map.insert(entry); + } + + return model; +} + +static std::unique_ptr ParseAttributeLimitsConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model(new AttributeLimitsConfiguration); + + model->attribute_value_length_limit = node->GetInteger("attribute_value_length_limit", 4096); + model->attribute_count_limit = node->GetInteger("attribute_count_limit", 128); + + return model; +} + +static std::unique_ptr ParseOtlpLogRecordExporterConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model(new OtlpLogRecordExporterConfiguration); + std::unique_ptr child; + + model->protocol = node->GetRequiredString("protocol"); + model->endpoint = node->GetRequiredString("endpoint"); + model->certificate = node->GetString("certificate", ""); + model->client_key = node->GetString("client_key", ""); + model->client_certificate = node->GetString("client_certificate", ""); + + child = node->GetChildNode("headers"); + if (child) + { + model->headers = ParseHeadersConfiguration(child); + } + + model->headers_list = node->GetString("headers_list", ""); + model->compression = node->GetString("compression", ""); + model->timeout = node->GetInteger("timeout", 10000); + model->insecure = node->GetBoolean("insecure", false); + + return model; +} + +static std::unique_ptr +ParseConsoleLogRecordExporterConfiguration(const std::unique_ptr & /* node */) +{ + std::unique_ptr model( + new ConsoleLogRecordExporterConfiguration); + + return model; +} + +static std::unique_ptr +ParseExtensionLogRecordExporterConfiguration(const std::string &name, + std::unique_ptr node) +{ + std::unique_ptr model( + new ExtensionLogRecordExporterConfiguration); + model->name = name; + model->node = std::move(node); + return model; +} + +static std::unique_ptr ParseLogRecordExporterConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model; + + std::string name; + std::unique_ptr child; + size_t count = 0; + + for (auto it = node->begin_properties(); it != node->end_properties(); ++it) + { + name = it.Name(); + child = it.Value(); + count++; + } + + if (count != 1) + { + OTEL_INTERNAL_LOG_ERROR("ParseLogRecordExporterConfiguration: count " << count); + throw InvalidSchemaException("Illegal span exporter"); + } + + if (name == "otlp") + { + model = ParseOtlpLogRecordExporterConfiguration(child); + } + else if (name == "console") + { + model = ParseConsoleLogRecordExporterConfiguration(child); + } + else + { + model = ParseExtensionLogRecordExporterConfiguration(name, std::move(child)); + } + + return model; +} + +static std::unique_ptr +ParseBatchLogRecordProcessorConfiguration(const std::unique_ptr &node) +{ + std::unique_ptr model( + new BatchLogRecordProcessorConfiguration); + std::unique_ptr child; + + model->schedule_delay = node->GetInteger("schedule_delay", 5000); + model->export_timeout = node->GetInteger("export_timeout", 30000); + model->max_queue_size = node->GetInteger("max_queue_size", 2048); + model->max_export_batch_size = node->GetInteger("max_export_batch_size", 512); + + child = node->GetRequiredChildNode("exporter"); + model->exporter = ParseLogRecordExporterConfiguration(child); + + return model; +} + +static std::unique_ptr +ParseSimpleLogRecordProcessorConfiguration(const std::unique_ptr &node) +{ + std::unique_ptr model( + new SimpleLogRecordProcessorConfiguration); + std::unique_ptr child; + + child = node->GetRequiredChildNode("exporter"); + model->exporter = ParseLogRecordExporterConfiguration(child); + + return model; +} + +static std::unique_ptr +ParseExtensionLogRecordProcessorConfiguration(const std::string &name, + std::unique_ptr node) +{ + std::unique_ptr model( + new ExtensionLogRecordProcessorConfiguration); + model->name = name; + model->node = std::move(node); + return model; +} + +static std::unique_ptr ParseLogRecordProcessorConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model; + + std::string name; + std::unique_ptr child; + size_t count = 0; + + for (auto it = node->begin_properties(); it != node->end_properties(); ++it) + { + name = it.Name(); + child = it.Value(); + count++; + } + + if (count != 1) + { + OTEL_INTERNAL_LOG_ERROR("ParseLogRecordProcessorConfiguration: count " << count); + throw InvalidSchemaException("Illegal log record processor"); + } + + if (name == "batch") + { + model = ParseBatchLogRecordProcessorConfiguration(child); + } + else if (name == "simple") + { + model = ParseSimpleLogRecordProcessorConfiguration(child); + } + else + { + model = ParseExtensionLogRecordProcessorConfiguration(name, std::move(child)); + } + + return model; +} + +static std::unique_ptr ParseLogRecordLimitsConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model(new LogRecordLimitsConfiguration); + + model->attribute_value_length_limit = node->GetInteger("attribute_value_length_limit", 4096); + model->attribute_count_limit = node->GetInteger("attribute_count_limit", 128); + + return model; +} + +static std::unique_ptr ParseLoggerProviderConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model(new LoggerProviderConfiguration); + std::unique_ptr child; + + child = node->GetRequiredChildNode("processors"); + + for (auto it = child->begin(); it != child->end(); ++it) + { + model->processors.push_back(ParseLogRecordProcessorConfiguration(*it)); + } + + size_t count = model->processors.size(); + if (count == 0) + { + OTEL_INTERNAL_LOG_ERROR("ParseLoggerProviderConfiguration: 0 processors "); + throw InvalidSchemaException("Illegal processors"); + } + + child = node->GetChildNode("limits"); + if (child) + { + model->limits = ParseLogRecordLimitsConfiguration(child); + } + + return model; +} + +static enum_default_histogram_aggregation ParseDefaultHistogramAggregation(const std::string &name) +{ + if (name == "explicit_bucket_histogram") + { + return explicit_bucket_histogram; + } + + if (name == "base2_exponential_bucket_histogram") + { + return base2_exponential_bucket_histogram; + } + + OTEL_INTERNAL_LOG_ERROR("ParseDefaultHistogramAggregation: name = " << name); + throw InvalidSchemaException("Illegal default_histogram_aggregation"); +} + +static std::unique_ptr +ParseOtlpPushMetricExporterConfiguration(const std::unique_ptr &node) +{ + std::unique_ptr model( + new OtlpPushMetricExporterConfiguration); + std::unique_ptr child; + + model->protocol = node->GetRequiredString("protocol"); + model->endpoint = node->GetRequiredString("endpoint"); + model->certificate = node->GetString("certificate", ""); + model->client_key = node->GetString("client_key", ""); + model->client_certificate = node->GetString("client_certificate", ""); + + child = node->GetChildNode("headers"); + if (child) + { + model->headers = ParseHeadersConfiguration(child); + } + + model->headers_list = node->GetString("headers_list", ""); + model->compression = node->GetString("compression", ""); + model->timeout = node->GetInteger("timeout", 10000); + model->temporality_preference = node->GetString("temporality_preference", ""); + + std::string default_histogram_aggregation = node->GetString("default_histogram_aggregation", ""); + model->default_histogram_aggregation = + ParseDefaultHistogramAggregation(default_histogram_aggregation); + + model->insecure = node->GetBoolean("insecure", false); + + return model; +} + +static std::unique_ptr +ParseConsolePushMetricExporterConfiguration(const std::unique_ptr & /* node */) +{ + std::unique_ptr model( + new ConsolePushMetricExporterConfiguration); + + return model; +} + +static std::unique_ptr +ParsePrometheusPullMetricExporterConfiguration(const std::unique_ptr &node) +{ + std::unique_ptr model( + new PrometheusPullMetricExporterConfiguration); + + model->host = node->GetString("host", "localhost"); + model->port = node->GetInteger("port", 9464); + model->without_units = node->GetBoolean("without_units", false); + model->without_type_suffix = node->GetBoolean("without_type_suffix", false); + model->without_scope_info = node->GetBoolean("without_scope_info", false); + + return model; +} + +static std::unique_ptr +ParsePushMetricExporterExtensionConfiguration(const std::string &name, + std::unique_ptr node) +{ + std::unique_ptr model( + new ExtensionPushMetricExporterConfiguration); + model->name = name; + model->node = std::move(node); + return model; +} + +static std::unique_ptr +ParsePullMetricExporterExtensionConfiguration(const std::string &name, + std::unique_ptr node) +{ + std::unique_ptr model( + new ExtensionPullMetricExporterConfiguration); + model->name = name; + model->node = std::move(node); + return model; +} + +static std::unique_ptr ParsePushMetricExporterConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model; + + std::string name; + std::unique_ptr child; + size_t count = 0; + + for (auto it = node->begin_properties(); it != node->end_properties(); ++it) + { + name = it.Name(); + child = it.Value(); + count++; + } + + if (count != 1) + { + OTEL_INTERNAL_LOG_ERROR("ParsePushMetricExporterConfiguration: count " << count); + throw InvalidSchemaException("Illegal metric exporter"); + } + + if (name == "otlp") + { + model = ParseOtlpPushMetricExporterConfiguration(child); + } + else if (name == "console") + { + model = ParseConsolePushMetricExporterConfiguration(child); + } + else + { + model = ParsePushMetricExporterExtensionConfiguration(name, std::move(child)); + } + + return model; +} + +static std::unique_ptr ParsePullMetricExporterConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model; + + std::string name; + std::unique_ptr child; + size_t count = 0; + + for (auto it = node->begin_properties(); it != node->end_properties(); ++it) + { + name = it.Name(); + child = it.Value(); + count++; + } + + if (count != 1) + { + OTEL_INTERNAL_LOG_ERROR("ParsePullMetricExporterConfiguration: count " << count); + throw InvalidSchemaException("Illegal metric exporter"); + } + + if (name == "prometheus") + { + model = ParsePrometheusPullMetricExporterConfiguration(child); + } + else + { + model = ParsePullMetricExporterExtensionConfiguration(name, std::move(child)); + } + + return model; +} + +static std::unique_ptr ParsePeriodicMetricReaderConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model(new PeriodicMetricReaderConfiguration); + std::unique_ptr child; + + model->interval = node->GetInteger("interval", 5000); + model->timeout = node->GetInteger("timeout", 30000); + + child = node->GetRequiredChildNode("exporter"); + model->exporter = ParsePushMetricExporterConfiguration(child); + + return model; +} + +static std::unique_ptr ParsePullMetricReaderConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model(new PullMetricReaderConfiguration); + std::unique_ptr child; + + child = node->GetRequiredChildNode("exporter"); + model->exporter = ParsePullMetricExporterConfiguration(child); + + return model; +} + +static std::unique_ptr ParseMetricReaderConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model; + + std::string name; + std::unique_ptr child; + size_t count = 0; + + for (auto it = node->begin_properties(); it != node->end_properties(); ++it) + { + name = it.Name(); + child = it.Value(); + count++; + } + + if (count != 1) + { + OTEL_INTERNAL_LOG_ERROR("ParseMetricReaderConfiguration: count " << count); + throw InvalidSchemaException("Illegal metric reader"); + } + + if (name == "periodic") + { + model = ParsePeriodicMetricReaderConfiguration(child); + } + else if (name == "pull") + { + model = ParsePullMetricReaderConfiguration(child); + } + else + { + OTEL_INTERNAL_LOG_ERROR("ParseMetricReaderConfiguration: name " << name); + throw InvalidSchemaException("Illegal metric reader"); + } + + return model; +} + +static enum_instrument_type ParseInstrumentType(const std::string &name) +{ + if (name == "counter") + { + return counter; + } + + if (name == "histogram") + { + return histogram; + } + + if (name == "observable_counter") + { + return observable_counter; + } + + if (name == "observable_gauge") + { + return observable_gauge; + } + + if (name == "observable_up_down_counter") + { + return observable_up_down_counter; + } + + if (name == "up_down_counter") + { + return up_down_counter; + } + + OTEL_INTERNAL_LOG_ERROR("ParseInstrumentType: name = " << name); + throw InvalidSchemaException("Illegal instrument_type"); +} + +static std::unique_ptr ParseSelectorConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model(new SelectorConfiguration); + + model->instrument_name = node->GetString("instrument_name", ""); + + std::string instrument_type = node->GetString("instrument_type", ""); + model->instrument_type = ParseInstrumentType(instrument_type); + + model->unit = node->GetString("unit", ""); + model->meter_name = node->GetString("meter_name", ""); + model->meter_version = node->GetString("meter_version", ""); + model->meter_schema_url = node->GetString("meter_schema_url", ""); + + return model; +} + +static std::unique_ptr ParseDefaultAggregationConfiguration( + const std::unique_ptr & /* node */) +{ + std::unique_ptr model(new DefaultAggregationConfiguration); + + return model; +} + +static std::unique_ptr ParseDropAggregationConfiguration( + const std::unique_ptr & /* node */) +{ + std::unique_ptr model(new DropAggregationConfiguration); + + return model; +} + +static std::unique_ptr +ParseExplicitBucketHistogramAggregationConfiguration(const std::unique_ptr &node) +{ + std::unique_ptr model( + new ExplicitBucketHistogramAggregationConfiguration); + std::unique_ptr child; + + child = node->GetChildNode("boundaries"); + + if (child) + { + for (auto it = child->begin(); it != child->end(); ++it) + { + std::unique_ptr attribute_key(*it); + + double boundary = attribute_key->AsDouble(); + + model->boundaries.push_back(boundary); + } + } + + model->record_min_max = node->GetBoolean("record_min_max", true); + + return model; +} + +static std::unique_ptr +ParseBase2ExponentialBucketHistogramAggregationConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model( + new Base2ExponentialBucketHistogramAggregationConfiguration); + + model->max_scale = node->GetInteger("max_scale", 0); // FIXME: default ? + model->max_size = node->GetInteger("max_size", 0); // FIXME: default ? + model->record_min_max = node->GetBoolean("record_min_max", true); + + return model; +} + +static std::unique_ptr ParseLastValueAggregationConfiguration( + const std::unique_ptr & /* node */) +{ + std::unique_ptr model(new LastValueAggregationConfiguration); + + return model; +} + +static std::unique_ptr ParseSumAggregationConfiguration( + const std::unique_ptr & /* node */) +{ + std::unique_ptr model(new SumAggregationConfiguration); + + return model; +} + +static std::unique_ptr ParseAggregationConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model; + std::unique_ptr child; + + size_t count = node->num_children(); + + if (count != 1) + { + OTEL_INTERNAL_LOG_ERROR("ParseAggregationConfiguration: count " << count); + throw InvalidSchemaException("Illegal aggregation"); + } + + child = node->GetChild(0); + std::string name = child->Key(); + + if (name == "default") + { + model = ParseDefaultAggregationConfiguration(child); + } + else if (name == "drop") + { + model = ParseDropAggregationConfiguration(child); + } + else if (name == "explicit_bucket_histogram") + { + model = ParseExplicitBucketHistogramAggregationConfiguration(child); + } + else if (name == "base2_exponential_bucket_histogram") + { + model = ParseBase2ExponentialBucketHistogramAggregationConfiguration(child); + } + else if (name == "last_value") + { + model = ParseLastValueAggregationConfiguration(child); + } + else if (name == "sum") + { + model = ParseSumAggregationConfiguration(child); + } + else + { + OTEL_INTERNAL_LOG_ERROR("ParseAggregationConfiguration: name " << name); + throw InvalidSchemaException("Illegal aggregation"); + } + + return model; +} + +static std::unique_ptr ParseStreamConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model(new StreamConfiguration); + std::unique_ptr child; + + model->name = node->GetString("name", ""); + model->description = node->GetString("description", ""); + + child = node->GetChildNode("aggregation"); + if (child) + { + model->aggregation = ParseAggregationConfiguration(child); + } + + child = node->GetChildNode("attribute_keys"); + + if (child) + { + for (auto it = child->begin(); it != child->end(); ++it) + { + std::unique_ptr attribute_key(*it); + + std::string name = attribute_key->AsString(); + + model->attribute_keys.push_back(name); + } + } + + return model; +} + +static std::unique_ptr ParseViewConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model(new ViewConfiguration); + std::unique_ptr child; + + child = node->GetRequiredChildNode("selector"); + model->selector = ParseSelectorConfiguration(child); + + child = node->GetRequiredChildNode("stream"); + model->stream = ParseStreamConfiguration(child); + + return model; +} + +static std::unique_ptr ParseMeterProviderConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model(new MeterProviderConfiguration); + std::unique_ptr child; + + child = node->GetRequiredChildNode("readers"); + + for (auto it = child->begin(); it != child->end(); ++it) + { + model->readers.push_back(ParseMetricReaderConfiguration(*it)); + } + + child = node->GetRequiredChildNode("views"); + + for (auto it = child->begin(); it != child->end(); ++it) + { + model->views.push_back(ParseViewConfiguration(*it)); + } + + return model; +} + +static std::unique_ptr ParsePropagatorConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model(new PropagatorConfiguration); + + std::unique_ptr child; + child = node->GetRequiredChildNode("composite"); + + for (auto it = child->begin(); it != child->end(); ++it) + { + std::unique_ptr element(*it); + + std::string name = element->AsString(); + + model->composite.push_back(name); + } + + return model; +} + +static std::unique_ptr ParseSpanLimitsConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model(new SpanLimitsConfiguration); + + model->attribute_value_length_limit = node->GetInteger("attribute_value_length_limit", 4096); + model->attribute_count_limit = node->GetInteger("attribute_count_limit", 128); + model->event_count_limit = node->GetInteger("event_count_limit", 128); + model->link_count_limit = node->GetInteger("link_count_limit", 128); + model->event_attribute_count_limit = node->GetInteger("event_attribute_count_limit", 128); + model->link_attribute_count_limit = node->GetInteger("link_attribute_count_limit", 128); + + return model; +} + +static std::unique_ptr ParseSamplerConfiguration( + const std::unique_ptr &node, + size_t depth); + +static std::unique_ptr ParseAlwaysOffSamplerConfiguration( + const std::unique_ptr & /* node */, + size_t /* depth */) +{ + std::unique_ptr model(new AlwaysOffSamplerConfiguration); + + return model; +} + +static std::unique_ptr ParseAlwaysOnSamplerConfiguration( + const std::unique_ptr & /* node */, + size_t /* depth */) +{ + std::unique_ptr model(new AlwaysOnSamplerConfiguration); + + return model; +} + +static std::unique_ptr ParseJaegerRemoteSamplerConfiguration( + const std::unique_ptr &node, + size_t depth) +{ + std::unique_ptr model(new JaegerRemoteSamplerConfiguration); + std::unique_ptr child; + + // Unclear if endpoint and interval are required/optional + OTEL_INTERNAL_LOG_ERROR("JaegerRemoteSamplerConfiguration: FIXME"); + + model->endpoint = node->GetString("endpoint", "FIXME"); + model->interval = node->GetInteger("interval", 0); + + child = node->GetChildNode("initial_sampler"); + if (child) + { + model->initial_sampler = ParseSamplerConfiguration(child, depth + 1); + } + + return model; +} + +static std::unique_ptr ParseParentBasedSamplerConfiguration( + const std::unique_ptr &node, + size_t depth) +{ + std::unique_ptr model(new ParentBasedSamplerConfiguration); + std::unique_ptr child; + + child = node->GetChildNode("root"); + if (child) + { + model->root = ParseSamplerConfiguration(child, depth + 1); + } + + child = node->GetChildNode("remote_parent_sampled"); + if (child) + { + model->remote_parent_sampled = ParseSamplerConfiguration(child, depth + 1); + } + + child = node->GetChildNode("remote_parent_not_sampled"); + if (child) + { + model->remote_parent_not_sampled = ParseSamplerConfiguration(child, depth + 1); + } + + child = node->GetChildNode("local_parent_sampled"); + if (child) + { + model->local_parent_sampled = ParseSamplerConfiguration(child, depth + 1); + } + + child = node->GetChildNode("local_parent_not_sampled"); + if (child) + { + model->local_parent_not_sampled = ParseSamplerConfiguration(child, depth + 1); + } + + return model; +} + +static std::unique_ptr +ParseTraceIdRatioBasedSamplerConfiguration(const std::unique_ptr &node, + size_t /* depth */) +{ + std::unique_ptr model( + new TraceIdRatioBasedSamplerConfiguration); + std::unique_ptr child; + + model->ratio = node->GetDouble("ratio", 0); + + return model; +} + +static std::unique_ptr ParseSamplerExtensionConfiguration( + const std::string &name, + std::unique_ptr node, + size_t depth) +{ + std::unique_ptr model(new ExtensionSamplerConfiguration); + model->name = name; + model->node = std::move(node); + model->depth = depth; + return model; +} + +static std::unique_ptr ParseSamplerConfiguration( + const std::unique_ptr &node, + size_t depth) +{ + /* + * ParseSamplerConfiguration() is recursive, + * enforce a limit to prevent attacks from yaml. + */ + if (depth >= MAX_SAMPLER_DEPTH) + { + OTEL_INTERNAL_LOG_ERROR("ParseSamplerConfiguration: depth " << depth); + throw InvalidSchemaException("Samplers nested too deeply"); + } + + std::unique_ptr model; + + std::string name; + std::unique_ptr child; + size_t count = 0; + + for (auto it = node->begin_properties(); it != node->end_properties(); ++it) + { + name = it.Name(); + child = it.Value(); + count++; + } + + if (count != 1) + { + OTEL_INTERNAL_LOG_ERROR("ParseSamplerConfiguration: count " << count); + throw InvalidSchemaException("Illegal sampler"); + } + + if (name == "always_off") + { + model = ParseAlwaysOffSamplerConfiguration(child, depth); + } + else if (name == "always_on") + { + model = ParseAlwaysOnSamplerConfiguration(child, depth); + } + else if (name == "jaeger_remote") + { + model = ParseJaegerRemoteSamplerConfiguration(child, depth); + } + else if (name == "parent_based") + { + model = ParseParentBasedSamplerConfiguration(child, depth); + } + else if (name == "trace_id_ratio_based") + { + model = ParseTraceIdRatioBasedSamplerConfiguration(child, depth); + } + else + { + model = ParseSamplerExtensionConfiguration(name, std::move(child), depth); + } + + return model; +} + +static std::unique_ptr ParseOtlpSpanExporterConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model(new OtlpSpanExporterConfiguration); + std::unique_ptr child; + + model->protocol = node->GetRequiredString("protocol"); + model->endpoint = node->GetRequiredString("endpoint"); + model->certificate = node->GetString("certificate", ""); + model->client_key = node->GetString("client_key", ""); + model->client_certificate = node->GetString("client_certificate", ""); + + child = node->GetChildNode("headers"); + if (child) + { + model->headers = ParseHeadersConfiguration(child); + } + + model->headers_list = node->GetString("headers_list", ""); + model->compression = node->GetString("compression", ""); + model->timeout = node->GetInteger("timeout", 10000); + model->insecure = node->GetBoolean("insecure", false); + + return model; +} + +static std::unique_ptr ParseConsoleSpanExporterConfiguration( + const std::unique_ptr & /* node */) +{ + std::unique_ptr model(new ConsoleSpanExporterConfiguration); + + return model; +} + +static std::unique_ptr ParseZipkinSpanExporterConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model(new ZipkinSpanExporterConfiguration); + + model->endpoint = node->GetRequiredString("endpoint"); + model->timeout = node->GetInteger("timeout", 10000); + + return model; +} + +static std::unique_ptr ParseExtensionSpanExporterConfiguration( + const std::string &name, + std::unique_ptr node) +{ + std::unique_ptr model(new ExtensionSpanExporterConfiguration); + model->name = name; + model->node = std::move(node); + return model; +} + +static std::unique_ptr ParseSpanExporterConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model; + + std::string name; + std::unique_ptr child; + size_t count = 0; + + for (auto it = node->begin_properties(); it != node->end_properties(); ++it) + { + name = it.Name(); + child = it.Value(); + count++; + } + + if (count != 1) + { + OTEL_INTERNAL_LOG_ERROR("ParseSpanExporterConfiguration: count " << count); + throw InvalidSchemaException("Illegal span exporter"); + } + + if (name == "otlp") + { + model = ParseOtlpSpanExporterConfiguration(child); + } + else if (name == "console") + { + model = ParseConsoleSpanExporterConfiguration(child); + } + else if (name == "zipkin") + { + model = ParseZipkinSpanExporterConfiguration(child); + } + else + { + model = ParseExtensionSpanExporterConfiguration(name, std::move(child)); + } + + return model; +} + +static std::unique_ptr ParseBatchSpanProcessorConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model(new BatchSpanProcessorConfiguration); + std::unique_ptr child; + + model->schedule_delay = node->GetInteger("schedule_delay", 5000); + model->export_timeout = node->GetInteger("export_timeout", 30000); + model->max_queue_size = node->GetInteger("max_queue_size", 2048); + model->max_export_batch_size = node->GetInteger("max_export_batch_size", 512); + + child = node->GetRequiredChildNode("exporter"); + model->exporter = ParseSpanExporterConfiguration(child); + + return model; +} + +static std::unique_ptr ParseSimpleSpanProcessorConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model(new SimpleSpanProcessorConfiguration); + std::unique_ptr child; + + child = node->GetRequiredChildNode("exporter"); + model->exporter = ParseSpanExporterConfiguration(child); + + return model; +} + +static std::unique_ptr +ParseExtensionSpanProcessorConfiguration(const std::string &name, + std::unique_ptr node) +{ + std::unique_ptr model( + new ExtensionSpanProcessorConfiguration); + model->name = name; + model->node = std::move(node); + return model; +} + +static std::unique_ptr ParseSpanProcessorConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model; + + std::string name; + std::unique_ptr child; + size_t count = 0; + + for (auto it = node->begin_properties(); it != node->end_properties(); ++it) + { + name = it.Name(); + child = it.Value(); + count++; + } + + if (count != 1) + { + OTEL_INTERNAL_LOG_ERROR("ParseSpanProcessorConfiguration: count " << count); + throw InvalidSchemaException("Illegal span processor"); + } + + if (name == "batch") + { + model = ParseBatchSpanProcessorConfiguration(child); + } + else if (name == "simple") + { + model = ParseSimpleSpanProcessorConfiguration(child); + } + else + { + model = ParseExtensionSpanProcessorConfiguration(name, std::move(child)); + } + + return model; +} + +static std::unique_ptr ParseTracerProviderConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model(new TracerProviderConfiguration); + std::unique_ptr child; + + child = node->GetRequiredChildNode("processors"); + + for (auto it = child->begin(); it != child->end(); ++it) + { + model->processors.push_back(ParseSpanProcessorConfiguration(*it)); + } + + size_t count = model->processors.size(); + if (count == 0) + { + OTEL_INTERNAL_LOG_ERROR("ParseTracerProviderConfiguration: 0 processors "); + throw InvalidSchemaException("Illegal processors"); + } + + child = node->GetChildNode("limits"); + if (child) + { + model->limits = ParseSpanLimitsConfiguration(child); + } + + child = node->GetChildNode("sampler"); + if (child) + { + model->sampler = ParseSamplerConfiguration(child, 0); + } + + return model; +} + +static std::unique_ptr ParseAttributesConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model(new AttributesConfiguration); + std::unique_ptr child; + + for (auto it = node->begin_properties(); it != node->end_properties(); ++it) + { + std::string name = it.Name(); + std::unique_ptr child = it.Value(); + std::string string_value = child->AsString(); + + OTEL_INTERNAL_LOG_DEBUG( + "ParseAttributesConfiguration() name = " << name << ", value = " << string_value); + + std::pair entry(name, string_value); + model->kv_map.insert(entry); + } + + return model; +} + +static std::unique_ptr ParseStringArrayConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model(new StringArrayConfiguration); + + for (auto it = node->begin(); it != node->end(); ++it) + { + std::unique_ptr child(*it); + + std::string name = child->AsString(); + + model->string_array.push_back(name); + } + + return model; +} + +static std::unique_ptr ParseDetectorsConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model(new DetectorsConfiguration); + std::unique_ptr child; + + child = node->GetChildNode("included"); + if (child) + { + model->included = ParseStringArrayConfiguration(child); + } + + child = node->GetChildNode("excluded"); + if (child) + { + model->excluded = ParseStringArrayConfiguration(child); + } + + return model; +} + +static std::unique_ptr ParseResourceConfiguration( + const std::unique_ptr &node) +{ + std::unique_ptr model(new ResourceConfiguration); + std::unique_ptr child; + + model->schema_url = node->GetString("schema_url", ""); + model->attributes_list = node->GetString("attributes_list", ""); + + child = node->GetChildNode("attributes"); + if (child) + { + model->attributes = ParseAttributesConfiguration(child); + } + + child = node->GetChildNode("detectors"); + if (child) + { + model->detectors = ParseDetectorsConfiguration(child); + } + + return model; +} + +std::unique_ptr ConfigurationFactory::ParseConfiguration( + std::unique_ptr doc) +{ + std::unique_ptr node = doc->GetRootNode(); + std::unique_ptr model(new Configuration(std::move(doc))); + + model->file_format = node->GetRequiredString("file_format"); + model->disabled = node->GetBoolean("disabled", false); + + std::unique_ptr child; + + child = node->GetChildNode("attribute_limits"); + if (child) + { + model->attribute_limits = ParseAttributeLimitsConfiguration(child); + } + + child = node->GetChildNode("logger_provider"); + if (child) + { + model->logger_provider = ParseLoggerProviderConfiguration(child); + } + + child = node->GetChildNode("meter_provider"); + if (child) + { + model->meter_provider = ParseMeterProviderConfiguration(child); + } + + child = node->GetChildNode("propagator"); + if (child) + { + model->propagator = ParsePropagatorConfiguration(child); + } + + child = node->GetChildNode("tracer_provider"); + if (child) + { + model->tracer_provider = ParseTracerProviderConfiguration(child); + } + + child = node->GetChildNode("resource"); + if (child) + { + model->resource = ParseResourceConfiguration(child); + } + + return model; +} + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/configuration/document_node.cc b/sdk/src/configuration/document_node.cc new file mode 100644 index 0000000000..8ebe7a552b --- /dev/null +++ b/sdk/src/configuration/document_node.cc @@ -0,0 +1,257 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include +#include +#include + +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/configuration/document_node.h" +#include "opentelemetry/sdk/configuration/invalid_schema_exception.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +/** + * Perform environment variables substitution on a full line. + * Supported: + * - Text line with no substitution + * - ${SUBSTITUTION} + * - Some text with ${SUBSTITUTION} in it + * - Multiple ${SUBSTITUTION_A} substitutions ${SUBSTITUTION_B} in the line + */ +std::string DocumentNode::DoSubstitution(const std::string &text) +{ + static std::string begin_token{"${"}; + static std::string end_token{"}"}; + + std::string result; + + std::string::size_type current_pos; + std::string::size_type begin_pos; + std::string::size_type end_pos; + std::string copy; + std::string substitution; + + current_pos = 0; + begin_pos = text.find(begin_token); + + while (begin_pos != std::string::npos) + { + if (current_pos < begin_pos) + { + /* + * ^ < COPY_ME > ${... + * ...} < COPY_ME > ${... + * + * copy [current_pos, begin_pos[ + */ + copy = text.substr(current_pos, begin_pos - current_pos); + result.append(copy); + current_pos = begin_pos; + } + + end_pos = text.find(end_token, begin_pos); + + if (end_pos == std::string::npos) + { + /* ... < ${NOT_A_SUBSTITUTION > */ + copy = text.substr(current_pos); + result.append(copy); + return result; + } + + /* ... < ${SUBSTITUTION} > ... */ + substitution = text.substr(current_pos, end_pos - current_pos + 1); + + copy = DoOneSubstitution(substitution); + result.append(copy); + begin_pos = text.find(begin_token, end_pos); + current_pos = end_pos + 1; + } + + copy = text.substr(current_pos); + result.append(copy); + + return result; +} + +/** + Perform one substitution on a string scalar. + Supported: + - ${ENV_NAME} + - ${env:ENV_NAME} + - ${ENV_NAME:-fallback} (including when ENV_NAME is actually "env") + - ${env:ENV_NAME:-fallback} +*/ +std::string DocumentNode::DoOneSubstitution(const std::string &text) +{ + static std::string env_token{"env:"}; + static std::string env_with_replacement{"env:-"}; + static std::string replacement_token{":-"}; + + size_t len = text.length(); + char c; + std::string::size_type begin_name; + std::string::size_type end_name; + std::string::size_type begin_fallback; + std::string::size_type end_fallback; + std::string::size_type pos; + std::string name; + std::string fallback; + const char *sub; + + if (len < 4) + { + goto illegal; + } + + c = text[0]; + if (c != '$') + { + goto illegal; + } + + c = text[1]; + if (c != '{') + { + goto illegal; + } + + c = text[len - 1]; + if (c != '}') + { + goto illegal; + } + + begin_name = 2; + + /* If text[2] starts with "env:" */ + if (text.find(env_token, begin_name) == begin_name) + { + /* If text[2] starts with "env:-" */ + if (text.find(env_with_replacement, begin_name) == begin_name) + { + /* ${env:-fallback} is legal. It is variable "env". */ + } + else + { + begin_name += env_token.length(); // Skip "env:" + } + } + + c = text[begin_name]; + if (!std::isalpha(c) && c != '_') + { + goto illegal; + } + + end_name = begin_name + 1; + + for (size_t i = begin_name + 1; i + 2 <= len; i++) + { + c = text[i]; + if (std::isalnum(c) || (c == '_')) + { + end_name = i + 1; + } + else + { + break; + } + } + + // text is of the form ${ENV_NAME ... + + name = text.substr(begin_name, end_name - begin_name); + + if (end_name + 1 == len) + { + // text is of the form ${ENV_NAME} + begin_fallback = 0; + end_fallback = 0; + } + else + { + pos = text.find(replacement_token, end_name); + if (pos != end_name) + { + goto illegal; + } + // text is of the form ${ENV_NAME:-fallback} + begin_fallback = pos + replacement_token.length(); + end_fallback = len - 1; + } + + sub = std::getenv(name.c_str()); + if (sub != nullptr) + { + return sub; + } + + if (begin_fallback < end_fallback) + { + fallback = text.substr(begin_fallback, end_fallback - begin_fallback); + } + else + { + fallback = ""; + } + return fallback; + +illegal: + OTEL_INTERNAL_LOG_ERROR("Illegal substitution expression: " << text); + throw InvalidSchemaException("Illegal substitution expression"); +} + +bool DocumentNode::BooleanFromString(const std::string &value) +{ + if (value == "true") + { + return true; + } + + if (value == "false") + { + return false; + } + + OTEL_INTERNAL_LOG_ERROR("Illegal integer value: " << value); + throw InvalidSchemaException("Illegal bool value"); +} + +size_t DocumentNode::IntegerFromString(const std::string &value) +{ + const char *ptr = value.c_str(); + char *end = nullptr; + size_t len = value.length(); + size_t val = strtoll(ptr, &end, 10); + if (ptr + len != end) + { + OTEL_INTERNAL_LOG_ERROR("Illegal integer value: " << value); + throw InvalidSchemaException("Illegal integer value"); + } + return val; +} + +double DocumentNode::DoubleFromString(const std::string &value) +{ + const char *ptr = value.c_str(); + char *end = nullptr; + size_t len = value.length(); + double val = strtod(ptr, &end); + if (ptr + len != end) + { + OTEL_INTERNAL_LOG_ERROR("Illegal double value: " << value); + throw InvalidSchemaException("Illegal double value"); + } + return val; +} + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/configuration/ryml_document.cc b/sdk/src/configuration/ryml_document.cc new file mode 100644 index 0000000000..eadd25a859 --- /dev/null +++ b/sdk/src/configuration/ryml_document.cc @@ -0,0 +1,89 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/configuration/document.h" +#include "opentelemetry/sdk/configuration/document_node.h" +#include "opentelemetry/sdk/configuration/ryml_document.h" +#include "opentelemetry/sdk/configuration/ryml_document_node.h" +#include "opentelemetry/version.h" + +/* We require 0.7.1 or better */ +#define OTEL_HAVE_RYML 7 + +/* Code using ryml 0.6.0 preserved for regression testing. */ +/* #define OTEL_HAVE_RYML 6 */ + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +std::unique_ptr RymlDocument::Parse(const std::string &source, const std::string &content) +{ + ryml::ParserOptions opts; + opts.locations(true); + +#if OTEL_HAVE_RYML == 6 + ryml::Parser parser(opts); +#endif + +#if OTEL_HAVE_RYML == 7 + ryml::Parser::handler_type event_handler; + ryml::Parser parser(&event_handler, opts); +#endif + + ryml::Tree tree; + ryml::csubstr filename; + ryml::csubstr csubstr_content; + std::unique_ptr doc; + + filename = ryml::to_csubstr(source); + csubstr_content = ryml::to_csubstr(content); + + try + { +#if OTEL_HAVE_RYML == 6 + tree = parser.parse_in_arena(filename, csubstr_content); +#endif + +#if OTEL_HAVE_RYML == 7 + tree = parse_in_arena(&parser, filename, csubstr_content); +#endif + + tree.resolve(); + } + catch (const std::exception &e) + { + OTEL_INTERNAL_LOG_ERROR("[Ryml Document] Parse failed with exception: " << e.what()); + return doc; + } + catch (...) + { + OTEL_INTERNAL_LOG_ERROR("[Ryml Document] Parse failed with unknown exception."); + return doc; + } + + RymlDocument *ryml_doc = new RymlDocument(tree); + doc = std::unique_ptr(ryml_doc); + return doc; +} + +std::unique_ptr RymlDocument::GetRootNode() +{ + RymlDocumentNode *ryml_node = new RymlDocumentNode(m_tree.rootref(), 0); + std::unique_ptr node(ryml_node); + return node; +} + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/configuration/ryml_document_node.cc b/sdk/src/configuration/ryml_document_node.cc new file mode 100644 index 0000000000..3d9aa76fe1 --- /dev/null +++ b/sdk/src/configuration/ryml_document_node.cc @@ -0,0 +1,495 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include +#include +#include +#include +#include + +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/configuration/document_node.h" +#include "opentelemetry/sdk/configuration/invalid_schema_exception.h" +#include "opentelemetry/sdk/configuration/ryml_document_node.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +#if 0 +static void DebugNode(opentelemetry::nostd::string_view name, ryml::ConstNodeRef node) +{ + OTEL_INTERNAL_LOG_DEBUG("Processing: " << name); + OTEL_INTERNAL_LOG_DEBUG(" - readable() : " << node.readable()); + OTEL_INTERNAL_LOG_DEBUG(" - empty() : " << node.empty()); + OTEL_INTERNAL_LOG_DEBUG(" - is_container() : " << node.is_container()); + OTEL_INTERNAL_LOG_DEBUG(" - is_map() : " << node.is_map()); + OTEL_INTERNAL_LOG_DEBUG(" - is_seq() : " << node.is_seq()); + OTEL_INTERNAL_LOG_DEBUG(" - is_val() : " << node.is_val()); + OTEL_INTERNAL_LOG_DEBUG(" - is_keyval() : " << node.is_keyval()); + OTEL_INTERNAL_LOG_DEBUG(" - has_key() : " << node.has_key()); + OTEL_INTERNAL_LOG_DEBUG(" - has_val() : " << node.has_val()); + OTEL_INTERNAL_LOG_DEBUG(" - num_children() : " << node.num_children()); + if (node.has_key()) + { + OTEL_INTERNAL_LOG_DEBUG(" - key() : " << node.key()); + } + if (node.has_val()) + { + OTEL_INTERNAL_LOG_DEBUG(" - val() : " << node.val()); + } +} +#endif + +std::string RymlDocumentNode::Key() const +{ + OTEL_INTERNAL_LOG_DEBUG("RymlDocumentNode::Key()"); + + if (!m_node.has_key()) + { + OTEL_INTERNAL_LOG_ERROR("Yaml: no key"); + throw InvalidSchemaException(""); + } + + ryml::csubstr k = m_node.key(); + std::string name(k.str, k.len); + return name; +} + +bool RymlDocumentNode::AsBoolean() +{ + OTEL_INTERNAL_LOG_DEBUG("RymlDocumentNode::AsBoolean()"); + + if (!m_node.is_val() && !m_node.is_keyval()) + { + OTEL_INTERNAL_LOG_ERROR("Yaml: not scalar"); + throw InvalidSchemaException(""); + } + ryml::csubstr view = m_node.val(); + std::string value(view.str, view.len); + return BooleanFromString(value); +} + +size_t RymlDocumentNode::AsInteger() +{ + OTEL_INTERNAL_LOG_DEBUG("RymlDocumentNode::AsInteger()"); + + if (!m_node.is_val() && !m_node.is_keyval()) + { + OTEL_INTERNAL_LOG_ERROR("Yaml: not scalar"); + throw InvalidSchemaException(""); + } + ryml::csubstr view = m_node.val(); + std::string value(view.str, view.len); + return IntegerFromString(value); +} + +double RymlDocumentNode::AsDouble() +{ + OTEL_INTERNAL_LOG_DEBUG("RymlDocumentNode::AsDouble()"); + + if (!m_node.is_val() && !m_node.is_keyval()) + { + OTEL_INTERNAL_LOG_ERROR("Yaml: not scalar"); + throw InvalidSchemaException(""); + } + ryml::csubstr view = m_node.val(); + std::string value(view.str, view.len); + return DoubleFromString(value); +} + +std::string RymlDocumentNode::AsString() +{ + OTEL_INTERNAL_LOG_DEBUG("RymlDocumentNode::AsString()"); + + if (!m_node.is_val() && !m_node.is_keyval()) + { + OTEL_INTERNAL_LOG_ERROR("Yaml: not scalar"); + throw InvalidSchemaException(""); + } + ryml::csubstr view = m_node.val(); + std::string value(view.str, view.len); + return value; +} + +ryml::ConstNodeRef RymlDocumentNode::GetRequiredRymlChildNode(const std::string &name) +{ + if (!m_node.is_map()) + { + OTEL_INTERNAL_LOG_ERROR("Yaml: not a map, looking for " << name); + throw InvalidSchemaException(name); + } + + const char *name_str = name.c_str(); + if (!m_node.has_child(name_str)) + { + OTEL_INTERNAL_LOG_ERROR("Yaml: required node: " << name); + throw InvalidSchemaException(name); + } + + ryml::ConstNodeRef ryml_child = m_node[name_str]; + return ryml_child; +} + +ryml::ConstNodeRef RymlDocumentNode::GetRymlChildNode(const std::string &name) +{ + if (!m_node.is_map()) + { + return ryml::ConstNodeRef{}; + } + + const char *name_str = name.c_str(); + if (!m_node.has_child(name_str)) + { + return ryml::ConstNodeRef{}; + } + + ryml::ConstNodeRef ryml_child = m_node[name_str]; + return ryml_child; +} + +std::unique_ptr RymlDocumentNode::GetRequiredChildNode(const std::string &name) +{ + OTEL_INTERNAL_LOG_DEBUG("RymlDocumentNode::GetRequiredChildNode(" << m_depth << ", " << name + << ")"); + + if (m_depth >= MAX_NODE_DEPTH) + { + OTEL_INTERNAL_LOG_ERROR("Yaml nested too deeply " << name); + throw InvalidSchemaException(name); + } + + auto ryml_child = GetRequiredRymlChildNode(name); + auto child = std::unique_ptr(new RymlDocumentNode(ryml_child, m_depth + 1)); + return child; +} + +std::unique_ptr RymlDocumentNode::GetChildNode(const std::string &name) +{ + OTEL_INTERNAL_LOG_DEBUG("RymlDocumentNode::GetChildNode(" << m_depth << ", " << name << ")"); + + if (m_depth >= MAX_NODE_DEPTH) + { + OTEL_INTERNAL_LOG_ERROR("Yaml nested too deeply " << name); + throw InvalidSchemaException(name); + } + + std::unique_ptr child; + + if (!m_node.is_map()) + { + return child; + } + + const char *name_str = name.c_str(); + if (!m_node.has_child(name_str)) + { + return child; + } + + ryml::ConstNodeRef ryml_child = m_node[name_str]; + child = std::unique_ptr(new RymlDocumentNode(ryml_child, m_depth + 1)); + return child; +} + +bool RymlDocumentNode::GetRequiredBoolean(const std::string &name) +{ + OTEL_INTERNAL_LOG_DEBUG("RymlDocumentNode::GetRequiredBoolean(" << name << ")"); + + auto ryml_child = GetRequiredRymlChildNode(name); + + ryml::csubstr view = ryml_child.val(); + std::string value(view.str, view.len); + + value = DoSubstitution(value); + + return BooleanFromString(value); +} + +bool RymlDocumentNode::GetBoolean(const std::string &name, bool default_value) +{ + OTEL_INTERNAL_LOG_DEBUG("RymlDocumentNode::GetBoolean(" << name << ", " << default_value << ")"); + + auto ryml_child = GetRymlChildNode(name); + + if (ryml_child.invalid()) + { + return default_value; + } + + ryml::csubstr view = ryml_child.val(); + std::string value(view.str, view.len); + + value = DoSubstitution(value); + + if (value.empty()) + { + return default_value; + } + + return BooleanFromString(value); +} + +size_t RymlDocumentNode::GetRequiredInteger(const std::string &name) +{ + OTEL_INTERNAL_LOG_DEBUG("RymlDocumentNode::GetRequiredInteger(" << name << ")"); + + auto ryml_child = GetRequiredRymlChildNode(name); + + ryml::csubstr view = ryml_child.val(); + std::string value(view.str, view.len); + + value = DoSubstitution(value); + + return IntegerFromString(value); +} + +size_t RymlDocumentNode::GetInteger(const std::string &name, size_t default_value) +{ + OTEL_INTERNAL_LOG_DEBUG("RymlDocumentNode::GetInteger(" << name << ", " << default_value << ")"); + + auto ryml_child = GetRymlChildNode(name); + + if (ryml_child.invalid()) + { + return default_value; + } + + ryml::csubstr view = ryml_child.val(); + std::string value(view.str, view.len); + + value = DoSubstitution(value); + + if (value.empty()) + { + return default_value; + } + + return IntegerFromString(value); +} + +double RymlDocumentNode::GetRequiredDouble(const std::string &name) +{ + OTEL_INTERNAL_LOG_DEBUG("RymlDocumentNode::GetRequiredDouble(" << name << ")"); + + auto ryml_child = GetRequiredRymlChildNode(name); + + ryml::csubstr view = ryml_child.val(); + std::string value(view.str, view.len); + + value = DoSubstitution(value); + + return DoubleFromString(value); +} + +double RymlDocumentNode::GetDouble(const std::string &name, double default_value) +{ + OTEL_INTERNAL_LOG_DEBUG("RymlDocumentNode::GetDouble(" << name << ", " << default_value << ")"); + + auto ryml_child = GetRymlChildNode(name); + + if (ryml_child.invalid()) + { + return default_value; + } + + ryml::csubstr view = ryml_child.val(); + std::string value(view.str, view.len); + + value = DoSubstitution(value); + + if (value.empty()) + { + return default_value; + } + + return DoubleFromString(value); +} + +std::string RymlDocumentNode::GetRequiredString(const std::string &name) +{ + OTEL_INTERNAL_LOG_DEBUG("RymlDocumentNode::GetRequiredString(" << name << ")"); + + ryml::ConstNodeRef ryml_child = GetRequiredRymlChildNode(name); + ryml::csubstr view = ryml_child.val(); + std::string value(view.str, view.len); + + value = DoSubstitution(value); + + if (value.empty()) + { + OTEL_INTERNAL_LOG_ERROR("Yaml: string value is empty: " << name); + throw InvalidSchemaException(name); + } + + return value; +} + +std::string RymlDocumentNode::GetString(const std::string &name, const std::string &default_value) +{ + OTEL_INTERNAL_LOG_DEBUG("RymlDocumentNode::GetString(" << name << ", " << default_value << ")"); + + ryml::ConstNodeRef ryml_child = GetRymlChildNode(name); + + if (ryml_child.invalid()) + { + return default_value; + } + + ryml::csubstr view = ryml_child.val(); + std::string value(view.str, view.len); + + value = DoSubstitution(value); + + return value; +} + +DocumentNodeConstIterator RymlDocumentNode::begin() const +{ + OTEL_INTERNAL_LOG_DEBUG("RymlDocumentNode::begin()"); + +#if 0 + DebugNode("::begin()", m_node); + + for (int index = 0; index < m_node.num_children(); index++) + { + DebugNode("(child)", m_node[index]); + } +#endif + + return DocumentNodeConstIterator(new RymlDocumentNodeConstIteratorImpl(m_node, 0, m_depth)); +} + +DocumentNodeConstIterator RymlDocumentNode::end() const +{ + OTEL_INTERNAL_LOG_DEBUG("RymlDocumentNode::end()"); + + return DocumentNodeConstIterator( + new RymlDocumentNodeConstIteratorImpl(m_node, m_node.num_children(), m_depth)); +} + +size_t RymlDocumentNode::num_children() const +{ + return m_node.num_children(); +} + +std::unique_ptr RymlDocumentNode::GetChild(size_t index) const +{ + std::unique_ptr child; + ryml::ConstNodeRef ryml_child = m_node[index]; + child = std::unique_ptr(new RymlDocumentNode(ryml_child, m_depth + 1)); + return child; +} + +PropertiesNodeConstIterator RymlDocumentNode::begin_properties() const +{ + OTEL_INTERNAL_LOG_DEBUG("RymlDocumentNode::begin_properties()"); + +#if 0 + DebugNode("::begin_properties()", m_node); + + for (int index = 0; index < m_node.num_children(); index++) + { + DebugNode("(child)", m_node[index]); + } +#endif + + return PropertiesNodeConstIterator(new RymlPropertiesNodeConstIteratorImpl(m_node, 0, m_depth)); +} + +PropertiesNodeConstIterator RymlDocumentNode::end_properties() const +{ + OTEL_INTERNAL_LOG_DEBUG("RymlDocumentNode::end_properties()"); + + return PropertiesNodeConstIterator( + new RymlPropertiesNodeConstIteratorImpl(m_node, m_node.num_children(), m_depth)); +} + +std::string RymlDocumentNode::Dump() const +{ + return "FIXME: Dump"; +} + +RymlDocumentNodeConstIteratorImpl::RymlDocumentNodeConstIteratorImpl(ryml::ConstNodeRef parent, + size_t index, + size_t depth) + : m_parent(parent), m_index(index), m_depth(depth) +{} + +RymlDocumentNodeConstIteratorImpl::~RymlDocumentNodeConstIteratorImpl() {} + +void RymlDocumentNodeConstIteratorImpl::Next() +{ + ++m_index; +} + +std::unique_ptr RymlDocumentNodeConstIteratorImpl::Item() const +{ + std::unique_ptr item; + ryml::ConstNodeRef ryml_item = m_parent[m_index]; + if (ryml_item.invalid()) + { + OTEL_INTERNAL_LOG_ERROR("iterator is lost "); + // Throw + } + item = std::unique_ptr(new RymlDocumentNode(ryml_item, m_depth + 1)); + return item; +} + +bool RymlDocumentNodeConstIteratorImpl::Equal(const DocumentNodeConstIteratorImpl *rhs) const +{ + const RymlDocumentNodeConstIteratorImpl *other = + static_cast(rhs); + return m_index == other->m_index; +} + +RymlPropertiesNodeConstIteratorImpl::RymlPropertiesNodeConstIteratorImpl(ryml::ConstNodeRef parent, + size_t index, + size_t depth) + : m_parent(parent), m_index(index), m_depth(depth) +{} + +RymlPropertiesNodeConstIteratorImpl::~RymlPropertiesNodeConstIteratorImpl() {} + +void RymlPropertiesNodeConstIteratorImpl::Next() +{ + OTEL_INTERNAL_LOG_DEBUG("RymlPropertiesNodeConstIteratorImpl::Next()"); + ++m_index; +} + +std::string RymlPropertiesNodeConstIteratorImpl::Name() const +{ + ryml::ConstNodeRef ryml_item = m_parent[m_index]; + ryml::csubstr k = ryml_item.key(); + std::string name(k.str, k.len); + + OTEL_INTERNAL_LOG_DEBUG("RymlPropertiesNodeConstIteratorImpl::Name() = " << name); + + return name; +} + +std::unique_ptr RymlPropertiesNodeConstIteratorImpl::Value() const +{ + std::unique_ptr item; + + ryml::ConstNodeRef ryml_item = m_parent[m_index]; + item = std::unique_ptr(new RymlDocumentNode(ryml_item, m_depth + 1)); + + OTEL_INTERNAL_LOG_DEBUG("RymlPropertiesNodeConstIteratorImpl::Value()"); + + return item; +} + +bool RymlPropertiesNodeConstIteratorImpl::Equal(const PropertiesNodeConstIteratorImpl *rhs) const +{ + const RymlPropertiesNodeConstIteratorImpl *other = + static_cast(rhs); + return m_index == other->m_index; +} + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/configuration/yaml_configuration_factory.cc b/sdk/src/configuration/yaml_configuration_factory.cc new file mode 100644 index 0000000000..04a628308c --- /dev/null +++ b/sdk/src/configuration/yaml_configuration_factory.cc @@ -0,0 +1,101 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/configuration/configuration.h" +#include "opentelemetry/sdk/configuration/configuration_factory.h" +#include "opentelemetry/sdk/configuration/document.h" +#include "opentelemetry/sdk/configuration/document_node.h" +#include "opentelemetry/sdk/configuration/ryml_document.h" +#include "opentelemetry/sdk/configuration/yaml_configuration_factory.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +std::unique_ptr YamlConfigurationFactory::ParseFile(const std::string &filename) +{ + std::string input_file = filename; + + if (input_file.empty()) + { + const char *env_var = std::getenv("OTEL_EXPERIMENTAL_CONFIG_FILE"); + if (env_var != nullptr) + { + input_file = env_var; + } + } + + if (input_file.empty()) + { + input_file = "config.yaml"; + } + + std::unique_ptr conf; + std::ifstream in(input_file, std::ios::binary); + if (!in.is_open()) + { + OTEL_INTERNAL_LOG_ERROR("Failed to open yaml file <" << input_file << ">."); + } + else + { + std::ostringstream content; + content << in.rdbuf(); + conf = YamlConfigurationFactory::ParseString(input_file, content.str()); + } + + return conf; +} + +static std::unique_ptr RymlParse(const std::string &source, const std::string &content) +{ + std::unique_ptr doc; + + doc = RymlDocument::Parse(source, content); + + return doc; +} + +std::unique_ptr YamlConfigurationFactory::ParseString(const std::string &source, + const std::string &content) +{ + std::unique_ptr doc; + std::unique_ptr root; + std::unique_ptr config; + + doc = RymlParse(source, content); + + try + { + if (doc) + { + config = ConfigurationFactory::ParseConfiguration(std::move(doc)); + } + } + catch (const std::exception &e) + { + OTEL_INTERNAL_LOG_ERROR( + "[Yaml Configuration Factory] ParseConfiguration failed with exception: " << e.what()); + } + catch (...) + { + OTEL_INTERNAL_LOG_ERROR( + "[Yaml Configuration Factory] ParseConfiguration failed with unknown exception."); + } + + return config; +} + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/init/CMakeLists.txt b/sdk/src/init/CMakeLists.txt new file mode 100644 index 0000000000..efeac9139f --- /dev/null +++ b/sdk/src/init/CMakeLists.txt @@ -0,0 +1,28 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +add_library(opentelemetry_init configured_sdk.cc sdk_builder.cc registry.cc) + +set_target_properties(opentelemetry_init PROPERTIES EXPORT_NAME init) +set_target_version(opentelemetry_init) + +target_include_directories( + opentelemetry_init + PUBLIC "$") + +target_link_libraries(opentelemetry_init PUBLIC opentelemetry_configuration + opentelemetry_trace) + +if(OPENTELEMETRY_INSTALL) + install( + TARGETS opentelemetry_init + EXPORT "${PROJECT_NAME}-target" + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + + opentelemetry_add_pkgconfig( + init "OpenTelemetry SDK - Init" + "Components for exporting traces in the OpenTelemetry SDK." + "opentelemetry_init") +endif() diff --git a/sdk/src/init/configured_sdk.cc b/sdk/src/init/configured_sdk.cc new file mode 100644 index 0000000000..c7bd4b19fe --- /dev/null +++ b/sdk/src/init/configured_sdk.cc @@ -0,0 +1,97 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include +#include +#include + +#include "opentelemetry/logs/logger_provider.h" +#include "opentelemetry/logs/provider.h" +#include "opentelemetry/metrics/meter_provider.h" +#include "opentelemetry/metrics/provider.h" +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/configuration/configuration.h" +#include "opentelemetry/sdk/init/configured_sdk.h" +#include "opentelemetry/sdk/init/registry.h" +#include "opentelemetry/sdk/init/sdk_builder.h" +#include "opentelemetry/trace/provider.h" +#include "opentelemetry/trace/tracer_provider.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace init +{ + +std::unique_ptr ConfiguredSdk::Create( + std::shared_ptr registry, + const std::unique_ptr &model) +{ + std::unique_ptr sdk; + + if (model) + { + try + { + SdkBuilder builder(registry); + sdk = builder.CreateConfiguredSdk(model); + } + catch (const std::exception &e) + { + OTEL_INTERNAL_LOG_ERROR("[Configured Sdk] builder failed with exception: " << e.what()); + } + catch (...) + { + OTEL_INTERNAL_LOG_ERROR("[Configured Sdk] builder failed with unknown exception."); + } + } + + return sdk; +} + +void ConfiguredSdk::Install() +{ + if (m_tracer_provider) + { + std::shared_ptr api_tracer_provider = m_tracer_provider; + opentelemetry::trace::Provider::SetTracerProvider(api_tracer_provider); + } + + if (m_meter_provider) + { + std::shared_ptr api_meter_provider = m_meter_provider; + opentelemetry::metrics::Provider::SetMeterProvider(api_meter_provider); + } + + if (m_logger_provider) + { + std::shared_ptr api_logger_provider = m_logger_provider; + opentelemetry::logs::Provider::SetLoggerProvider(api_logger_provider); + } +} + +void ConfiguredSdk::UnInstall() +{ + if (m_tracer_provider) + { + std::shared_ptr none; + opentelemetry::trace::Provider::SetTracerProvider(none); + } + + if (m_meter_provider) + { + std::shared_ptr none; + opentelemetry::metrics::Provider::SetMeterProvider(none); + } + + if (m_logger_provider) + { + std::shared_ptr none; + opentelemetry::logs::Provider::SetLoggerProvider(none); + } +} + +} // namespace init +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/init/registry.cc b/sdk/src/init/registry.cc new file mode 100644 index 0000000000..f10cb40840 --- /dev/null +++ b/sdk/src/init/registry.cc @@ -0,0 +1,276 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include +#include +#include +#include + +#include "opentelemetry/baggage/propagation/baggage_propagator.h" +#include "opentelemetry/context/propagation/text_map_propagator.h" +#include "opentelemetry/sdk/init/registry.h" +#include "opentelemetry/sdk/init/text_map_propagator_builder.h" +#include "opentelemetry/trace/propagation/b3_propagator.h" +#include "opentelemetry/trace/propagation/http_trace_context.h" +#include "opentelemetry/version.h" + +#ifndef OPENTELEMETRY_NO_DEPRECATED_CODE +# include "opentelemetry/trace/propagation/jaeger.h" +#endif /* OPENTELEMETRY_NO_DEPRECATED_CODE */ + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace init +{ + +class TraceContextBuilder : public TextMapPropagatorBuilder +{ +public: + TraceContextBuilder() = default; + virtual ~TraceContextBuilder() override = default; + + std::unique_ptr Build() const override + { + return std::unique_ptr( + new opentelemetry::trace::propagation::HttpTraceContext()); + } +}; + +class BaggageBuilder : public TextMapPropagatorBuilder +{ +public: + BaggageBuilder() = default; + virtual ~BaggageBuilder() override = default; + + std::unique_ptr Build() const override + { + return std::unique_ptr( + new opentelemetry::baggage::propagation::BaggagePropagator()); + } +}; + +class B3Builder : public TextMapPropagatorBuilder +{ +public: + B3Builder() = default; + virtual ~B3Builder() override = default; + + std::unique_ptr Build() const override + { + return std::unique_ptr( + new opentelemetry::trace::propagation::B3Propagator()); + } +}; + +class B3MultiBuilder : public TextMapPropagatorBuilder +{ +public: + B3MultiBuilder() = default; + virtual ~B3MultiBuilder() override = default; + + std::unique_ptr Build() const override + { + return std::unique_ptr( + new opentelemetry::trace::propagation::B3PropagatorMultiHeader()); + } +}; + +#ifndef OPENTELEMETRY_NO_DEPRECATED_CODE +class JaegerBuilder : public TextMapPropagatorBuilder +{ +public: + JaegerBuilder() = default; + virtual ~JaegerBuilder() override = default; + + std::unique_ptr Build() const override + { + return std::unique_ptr( + new opentelemetry::trace::propagation::JaegerPropagator()); + } +}; +#endif /* OPENTELEMETRY_NO_DEPRECATED_CODE */ + +static TraceContextBuilder trace_context_builder; +static BaggageBuilder baggage_builder; +static B3Builder b3_builder; +static B3MultiBuilder b3_multi_builder; + +#ifndef OPENTELEMETRY_NO_DEPRECATED_CODE +static JaegerBuilder jaeger_builder; +#endif /* OPENTELEMETRY_NO_DEPRECATED_CODE */ + +Registry::Registry() +{ + std::pair entry; + + entry = {"tracecontext", &trace_context_builder}; + m_propagator_builders.insert(entry); + + entry = {"baggage", &baggage_builder}; + m_propagator_builders.insert(entry); + + entry = {"b3", &b3_builder}; + m_propagator_builders.insert(entry); + + entry = {"b3multi", &b3_multi_builder}; + m_propagator_builders.insert(entry); + +#ifndef OPENTELEMETRY_NO_DEPRECATED_CODE + entry = {"jaeger", &jaeger_builder}; + m_propagator_builders.insert(entry); +#endif /* OPENTELEMETRY_NO_DEPRECATED_CODE */ +} + +const TextMapPropagatorBuilder *Registry::GetTextMapPropagatorBuilder(const std::string &name) +{ + TextMapPropagatorBuilder *builder = nullptr; + auto search = m_propagator_builders.find(name); + if (search != m_propagator_builders.end()) + { + builder = search->second; + } + return builder; +} + +void Registry::AddTextMapPropagatorBuilder(const std::string &name, + TextMapPropagatorBuilder *builder) +{ + std::pair entry{name, builder}; + m_propagator_builders.insert(entry); +} + +const ExtensionSamplerBuilder *Registry::GetExtensionSamplerBuilder(const std::string &name) +{ + ExtensionSamplerBuilder *builder = nullptr; + auto search = m_sampler_builders.find(name); + if (search != m_sampler_builders.end()) + { + builder = search->second; + } + return builder; +} + +void Registry::AddExtensionSamplerBuilder(const std::string &name, ExtensionSamplerBuilder *builder) +{ + std::pair entry{name, builder}; + m_sampler_builders.insert(entry); +} + +const ExtensionSpanExporterBuilder *Registry::GetExtensionSpanExporterBuilder( + const std::string &name) +{ + ExtensionSpanExporterBuilder *builder = nullptr; + auto search = m_span_exporter_builders.find(name); + if (search != m_span_exporter_builders.end()) + { + builder = search->second; + } + return builder; +} + +void Registry::AddExtensionSpanExporterBuilder(const std::string &name, + ExtensionSpanExporterBuilder *builder) +{ + std::pair entry{name, builder}; + m_span_exporter_builders.insert(entry); +} + +const ExtensionSpanProcessorBuilder *Registry::GetExtensionSpanProcessorBuilder( + const std::string &name) +{ + ExtensionSpanProcessorBuilder *builder = nullptr; + auto search = m_span_processor_builders.find(name); + if (search != m_span_processor_builders.end()) + { + builder = search->second; + } + return builder; +} + +void Registry::AddExtensionSpanProcessorBuilder(const std::string &name, + ExtensionSpanProcessorBuilder *builder) +{ + std::pair entry{name, builder}; + m_span_processor_builders.insert(entry); +} + +const ExtensionPushMetricExporterBuilder *Registry::GetExtensionPushMetricExporterBuilder( + const std::string &name) +{ + ExtensionPushMetricExporterBuilder *builder = nullptr; + auto search = m_push_metric_exporter_builders.find(name); + if (search != m_push_metric_exporter_builders.end()) + { + builder = search->second; + } + return builder; +} + +void Registry::AddExtensionPushMetricExporterBuilder(const std::string &name, + ExtensionPushMetricExporterBuilder *builder) +{ + std::pair entry{name, builder}; + m_push_metric_exporter_builders.insert(entry); +} + +const ExtensionPullMetricExporterBuilder *Registry::GetExtensionPullMetricExporterBuilder( + const std::string &name) +{ + ExtensionPullMetricExporterBuilder *builder = nullptr; + auto search = m_pull_metric_exporter_builders.find(name); + if (search != m_pull_metric_exporter_builders.end()) + { + builder = search->second; + } + return builder; +} + +void Registry::AddExtensionPullMetricExporterBuilder(const std::string &name, + ExtensionPullMetricExporterBuilder *builder) +{ + std::pair entry{name, builder}; + m_pull_metric_exporter_builders.insert(entry); +} + +const ExtensionLogRecordExporterBuilder *Registry::GetExtensionLogRecordExporterBuilder( + const std::string &name) +{ + ExtensionLogRecordExporterBuilder *builder = nullptr; + auto search = m_log_record_exporter_builders.find(name); + if (search != m_log_record_exporter_builders.end()) + { + builder = search->second; + } + return builder; +} + +void Registry::AddExtensionLogRecordExporterBuilder(const std::string &name, + ExtensionLogRecordExporterBuilder *builder) +{ + std::pair entry{name, builder}; + m_log_record_exporter_builders.insert(entry); +} + +const ExtensionLogRecordProcessorBuilder *Registry::GetExtensionLogRecordProcessorBuilder( + const std::string &name) +{ + ExtensionLogRecordProcessorBuilder *builder = nullptr; + auto search = m_log_record_processor_builders.find(name); + if (search != m_log_record_processor_builders.end()) + { + builder = search->second; + } + return builder; +} + +void Registry::AddExtensionLogRecordProcessorBuilder(const std::string &name, + ExtensionLogRecordProcessorBuilder *builder) +{ + std::pair entry{name, builder}; + m_log_record_processor_builders.insert(entry); +} + +} // namespace init +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/init/sdk_builder.cc b/sdk/src/init/sdk_builder.cc new file mode 100644 index 0000000000..7388de2ff3 --- /dev/null +++ b/sdk/src/init/sdk_builder.cc @@ -0,0 +1,1347 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/context/propagation/composite_propagator.h" +#include "opentelemetry/context/propagation/text_map_propagator.h" +#include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/configuration/always_off_sampler_configuration.h" +#include "opentelemetry/sdk/configuration/always_on_sampler_configuration.h" +#include "opentelemetry/sdk/configuration/attributes_configuration.h" +#include "opentelemetry/sdk/configuration/batch_log_record_processor_configuration.h" +#include "opentelemetry/sdk/configuration/batch_span_processor_configuration.h" +#include "opentelemetry/sdk/configuration/configuration.h" +#include "opentelemetry/sdk/configuration/console_log_record_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/console_push_metric_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/console_span_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/extension_log_record_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/extension_log_record_processor_configuration.h" +#include "opentelemetry/sdk/configuration/extension_pull_metric_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/extension_push_metric_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/extension_sampler_configuration.h" +#include "opentelemetry/sdk/configuration/extension_span_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/extension_span_processor_configuration.h" +#include "opentelemetry/sdk/configuration/jaeger_remote_sampler_configuration.h" +#include "opentelemetry/sdk/configuration/log_record_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/log_record_exporter_configuration_visitor.h" +#include "opentelemetry/sdk/configuration/log_record_processor_configuration.h" +#include "opentelemetry/sdk/configuration/log_record_processor_configuration_visitor.h" +#include "opentelemetry/sdk/configuration/logger_provider_configuration.h" +#include "opentelemetry/sdk/configuration/meter_provider_configuration.h" +#include "opentelemetry/sdk/configuration/metric_reader_configuration.h" +#include "opentelemetry/sdk/configuration/metric_reader_configuration_visitor.h" +#include "opentelemetry/sdk/configuration/otlp_log_record_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/otlp_push_metric_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/otlp_span_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/parent_based_sampler_configuration.h" +#include "opentelemetry/sdk/configuration/periodic_metric_reader_configuration.h" +#include "opentelemetry/sdk/configuration/prometheus_pull_metric_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/propagator_configuration.h" +#include "opentelemetry/sdk/configuration/pull_metric_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/pull_metric_exporter_configuration_visitor.h" +#include "opentelemetry/sdk/configuration/pull_metric_reader_configuration.h" +#include "opentelemetry/sdk/configuration/push_metric_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/push_metric_exporter_configuration_visitor.h" +#include "opentelemetry/sdk/configuration/resource_configuration.h" +#include "opentelemetry/sdk/configuration/sampler_configuration.h" +#include "opentelemetry/sdk/configuration/sampler_configuration_visitor.h" +#include "opentelemetry/sdk/configuration/selector_configuration.h" +#include "opentelemetry/sdk/configuration/simple_log_record_processor_configuration.h" +#include "opentelemetry/sdk/configuration/simple_span_processor_configuration.h" +#include "opentelemetry/sdk/configuration/span_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/span_exporter_configuration_visitor.h" +#include "opentelemetry/sdk/configuration/span_processor_configuration.h" +#include "opentelemetry/sdk/configuration/span_processor_configuration_visitor.h" +#include "opentelemetry/sdk/configuration/stream_configuration.h" +#include "opentelemetry/sdk/configuration/trace_id_ratio_based_sampler_configuration.h" +#include "opentelemetry/sdk/configuration/tracer_provider_configuration.h" +#include "opentelemetry/sdk/configuration/view_configuration.h" +#include "opentelemetry/sdk/configuration/zipkin_span_exporter_configuration.h" +#include "opentelemetry/sdk/init/configured_sdk.h" +#include "opentelemetry/sdk/init/console_log_record_exporter_builder.h" +#include "opentelemetry/sdk/init/console_push_metric_exporter_builder.h" +#include "opentelemetry/sdk/init/console_span_exporter_builder.h" +#include "opentelemetry/sdk/init/extension_log_record_exporter_builder.h" +#include "opentelemetry/sdk/init/extension_log_record_processor_builder.h" +#include "opentelemetry/sdk/init/extension_pull_metric_exporter_builder.h" +#include "opentelemetry/sdk/init/extension_push_metric_exporter_builder.h" +#include "opentelemetry/sdk/init/extension_sampler_builder.h" +#include "opentelemetry/sdk/init/extension_span_exporter_builder.h" +#include "opentelemetry/sdk/init/extension_span_processor_builder.h" +#include "opentelemetry/sdk/init/otlp_log_record_exporter_builder.h" +#include "opentelemetry/sdk/init/otlp_push_metric_exporter_builder.h" +#include "opentelemetry/sdk/init/otlp_span_exporter_builder.h" +#include "opentelemetry/sdk/init/prometheus_pull_metric_exporter_builder.h" +#include "opentelemetry/sdk/init/registry.h" +#include "opentelemetry/sdk/init/sdk_builder.h" +#include "opentelemetry/sdk/init/text_map_propagator_builder.h" +#include "opentelemetry/sdk/init/unsupported_exception.h" +#include "opentelemetry/sdk/init/zipkin_span_exporter_builder.h" +#include "opentelemetry/sdk/logs/batch_log_record_processor_factory.h" +#include "opentelemetry/sdk/logs/batch_log_record_processor_options.h" +#include "opentelemetry/sdk/logs/exporter.h" +#include "opentelemetry/sdk/logs/logger_provider.h" +#include "opentelemetry/sdk/logs/logger_provider_factory.h" +#include "opentelemetry/sdk/logs/processor.h" +#include "opentelemetry/sdk/logs/simple_log_record_processor_factory.h" +#include "opentelemetry/sdk/metrics/aggregation/aggregation_config.h" +#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_factory.h" +#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_options.h" +#include "opentelemetry/sdk/metrics/instruments.h" +#include "opentelemetry/sdk/metrics/meter_context.h" +#include "opentelemetry/sdk/metrics/meter_context_factory.h" +#include "opentelemetry/sdk/metrics/meter_provider.h" +#include "opentelemetry/sdk/metrics/meter_provider_factory.h" +#include "opentelemetry/sdk/metrics/metric_reader.h" +#include "opentelemetry/sdk/metrics/push_metric_exporter.h" +#include "opentelemetry/sdk/metrics/view/attributes_processor.h" +#include "opentelemetry/sdk/metrics/view/instrument_selector.h" +#include "opentelemetry/sdk/metrics/view/meter_selector.h" +#include "opentelemetry/sdk/metrics/view/view.h" +#include "opentelemetry/sdk/metrics/view/view_registry.h" +#include "opentelemetry/sdk/metrics/view/view_registry_factory.h" +#include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/sdk/trace/batch_span_processor_factory.h" +#include "opentelemetry/sdk/trace/batch_span_processor_options.h" +#include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/sampler.h" +#include "opentelemetry/sdk/trace/samplers/always_off_factory.h" +#include "opentelemetry/sdk/trace/samplers/always_on_factory.h" +#include "opentelemetry/sdk/trace/samplers/parent_factory.h" +#include "opentelemetry/sdk/trace/samplers/trace_id_ratio_factory.h" +#include "opentelemetry/sdk/trace/simple_processor_factory.h" +#include "opentelemetry/sdk/trace/tracer_provider.h" +#include "opentelemetry/sdk/trace/tracer_provider_factory.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace init +{ + +class SamplerBuilder : public opentelemetry::sdk::configuration::SamplerConfigurationVisitor +{ +public: + SamplerBuilder(const SdkBuilder *b) : m_sdk_builder(b) {} + ~SamplerBuilder() override = default; + + void VisitAlwaysOff( + const opentelemetry::sdk::configuration::AlwaysOffSamplerConfiguration *model) override + { + sampler = m_sdk_builder->CreateAlwaysOffSampler(model); + } + + void VisitAlwaysOn( + const opentelemetry::sdk::configuration::AlwaysOnSamplerConfiguration *model) override + { + sampler = m_sdk_builder->CreateAlwaysOnSampler(model); + } + + void VisitJaegerRemote( + const opentelemetry::sdk::configuration::JaegerRemoteSamplerConfiguration *model) override + { + sampler = m_sdk_builder->CreateJaegerRemoteSampler(model); + } + + void VisitParentBased( + const opentelemetry::sdk::configuration::ParentBasedSamplerConfiguration *model) override + { + sampler = m_sdk_builder->CreateParentBasedSampler(model); + } + + void VisitTraceIdRatioBased( + const opentelemetry::sdk::configuration::TraceIdRatioBasedSamplerConfiguration *model) + override + { + sampler = m_sdk_builder->CreateTraceIdRatioBasedSampler(model); + } + + void VisitExtension( + const opentelemetry::sdk::configuration::ExtensionSamplerConfiguration *model) override + { + sampler = m_sdk_builder->CreateExtensionSampler(model); + } + + std::unique_ptr sampler; + +private: + const SdkBuilder *m_sdk_builder; +}; + +class SpanProcessorBuilder + : public opentelemetry::sdk::configuration::SpanProcessorConfigurationVisitor +{ +public: + SpanProcessorBuilder(const SdkBuilder *b) : m_sdk_builder(b) {} + ~SpanProcessorBuilder() override = default; + + void VisitBatch( + const opentelemetry::sdk::configuration::BatchSpanProcessorConfiguration *model) override + { + processor = m_sdk_builder->CreateBatchSpanProcessor(model); + } + + void VisitSimple( + const opentelemetry::sdk::configuration::SimpleSpanProcessorConfiguration *model) override + { + processor = m_sdk_builder->CreateSimpleSpanProcessor(model); + } + + void VisitExtension( + const opentelemetry::sdk::configuration::ExtensionSpanProcessorConfiguration *model) override + { + processor = m_sdk_builder->CreateExtensionSpanProcessor(model); + } + + std::unique_ptr processor; + +private: + const SdkBuilder *m_sdk_builder; +}; + +class SpanExporterBuilder + : public opentelemetry::sdk::configuration::SpanExporterConfigurationVisitor +{ +public: + SpanExporterBuilder(const SdkBuilder *b) : m_sdk_builder(b) {} + ~SpanExporterBuilder() override = default; + + void VisitOtlp( + const opentelemetry::sdk::configuration::OtlpSpanExporterConfiguration *model) override + { + exporter = m_sdk_builder->CreateOtlpSpanExporter(model); + } + + void VisitConsole( + const opentelemetry::sdk::configuration::ConsoleSpanExporterConfiguration *model) override + { + exporter = m_sdk_builder->CreateConsoleSpanExporter(model); + } + + void VisitZipkin( + const opentelemetry::sdk::configuration::ZipkinSpanExporterConfiguration *model) override + { + exporter = m_sdk_builder->CreateZipkinSpanExporter(model); + } + + void VisitExtension( + const opentelemetry::sdk::configuration::ExtensionSpanExporterConfiguration *model) override + { + exporter = m_sdk_builder->CreateExtensionSpanExporter(model); + } + + std::unique_ptr exporter; + +private: + const SdkBuilder *m_sdk_builder; +}; + +class MetricReaderBuilder + : public opentelemetry::sdk::configuration::MetricReaderConfigurationVisitor +{ +public: + MetricReaderBuilder(const SdkBuilder *b) : m_sdk_builder(b) {} + ~MetricReaderBuilder() override = default; + + void VisitPeriodic( + const opentelemetry::sdk::configuration::PeriodicMetricReaderConfiguration *model) override + { + metric_reader = m_sdk_builder->CreatePeriodicMetricReader(model); + } + + void VisitPull( + const opentelemetry::sdk::configuration::PullMetricReaderConfiguration *model) override + { + metric_reader = m_sdk_builder->CreatePullMetricReader(model); + } + + std::unique_ptr metric_reader; + +private: + const SdkBuilder *m_sdk_builder; +}; + +class PushMetricExporterBuilder + : public opentelemetry::sdk::configuration::PushMetricExporterConfigurationVisitor +{ +public: + PushMetricExporterBuilder(const SdkBuilder *b) : m_sdk_builder(b) {} + ~PushMetricExporterBuilder() override = default; + + void VisitOtlp( + const opentelemetry::sdk::configuration::OtlpPushMetricExporterConfiguration *model) override + { + exporter = m_sdk_builder->CreateOtlpPushMetricExporter(model); + } + + void VisitConsole(const opentelemetry::sdk::configuration::ConsolePushMetricExporterConfiguration + *model) override + { + exporter = m_sdk_builder->CreateConsolePushMetricExporter(model); + } + + void VisitExtension( + const opentelemetry::sdk::configuration::ExtensionPushMetricExporterConfiguration *model) + override + { + exporter = m_sdk_builder->CreateExtensionPushMetricExporter(model); + } + + std::unique_ptr exporter; + +private: + const SdkBuilder *m_sdk_builder; +}; + +class PullMetricExporterBuilder + : public opentelemetry::sdk::configuration::PullMetricExporterConfigurationVisitor +{ +public: + PullMetricExporterBuilder(const SdkBuilder *b) : m_sdk_builder(b) {} + ~PullMetricExporterBuilder() override = default; + + void VisitPrometheus( + const opentelemetry::sdk::configuration::PrometheusPullMetricExporterConfiguration *model) + override + { + exporter = m_sdk_builder->CreatePrometheusPullMetricExporter(model); + } + + void VisitExtension( + const opentelemetry::sdk::configuration::ExtensionPullMetricExporterConfiguration *model) + override + { + exporter = m_sdk_builder->CreateExtensionPullMetricExporter(model); + } + + std::unique_ptr exporter; + +private: + const SdkBuilder *m_sdk_builder; +}; + +class LogRecordProcessorBuilder + : public opentelemetry::sdk::configuration::LogRecordProcessorConfigurationVisitor +{ +public: + LogRecordProcessorBuilder(const SdkBuilder *b) : m_sdk_builder(b) {} + ~LogRecordProcessorBuilder() override = default; + + void VisitBatch( + const opentelemetry::sdk::configuration::BatchLogRecordProcessorConfiguration *model) override + { + processor = m_sdk_builder->CreateBatchLogRecordProcessor(model); + } + + void VisitSimple(const opentelemetry::sdk::configuration::SimpleLogRecordProcessorConfiguration + *model) override + { + processor = m_sdk_builder->CreateSimpleLogRecordProcessor(model); + } + + void VisitExtension( + const opentelemetry::sdk::configuration::ExtensionLogRecordProcessorConfiguration *model) + override + { + processor = m_sdk_builder->CreateExtensionLogRecordProcessor(model); + } + + std::unique_ptr processor; + +private: + const SdkBuilder *m_sdk_builder; +}; + +class LogRecordExporterBuilder + : public opentelemetry::sdk::configuration::LogRecordExporterConfigurationVisitor +{ +public: + LogRecordExporterBuilder(const SdkBuilder *b) : m_sdk_builder(b) {} + ~LogRecordExporterBuilder() override = default; + + void VisitOtlp( + const opentelemetry::sdk::configuration::OtlpLogRecordExporterConfiguration *model) override + { + exporter = m_sdk_builder->CreateOtlpLogRecordExporter(model); + } + + void VisitConsole(const opentelemetry::sdk::configuration::ConsoleLogRecordExporterConfiguration + *model) override + { + exporter = m_sdk_builder->CreateConsoleLogRecordExporter(model); + } + + void VisitExtension( + const opentelemetry::sdk::configuration::ExtensionLogRecordExporterConfiguration *model) + override + { + exporter = m_sdk_builder->CreateExtensionLogRecordExporter(model); + } + + std::unique_ptr exporter; + +private: + const SdkBuilder *m_sdk_builder; +}; + +std::unique_ptr SdkBuilder::CreateAlwaysOffSampler( + const opentelemetry::sdk::configuration::AlwaysOffSamplerConfiguration * /* model */) const +{ + std::unique_ptr sdk; + + sdk = opentelemetry::sdk::trace::AlwaysOffSamplerFactory::Create(); + + return sdk; +} + +std::unique_ptr SdkBuilder::CreateAlwaysOnSampler( + const opentelemetry::sdk::configuration::AlwaysOnSamplerConfiguration * /* model */) const +{ + std::unique_ptr sdk; + + sdk = opentelemetry::sdk::trace::AlwaysOnSamplerFactory::Create(); + + return sdk; +} + +std::unique_ptr SdkBuilder::CreateJaegerRemoteSampler( + const opentelemetry::sdk::configuration::JaegerRemoteSamplerConfiguration * /* model */) const +{ + std::unique_ptr sdk; + + std::string die("JeagerRemoteSampler not available in opentelemetry-cpp"); + OTEL_INTERNAL_LOG_ERROR(die); + throw UnsupportedException(die); + + return sdk; +} + +std::unique_ptr SdkBuilder::CreateParentBasedSampler( + const opentelemetry::sdk::configuration::ParentBasedSamplerConfiguration *model) const +{ + std::unique_ptr sdk; + + auto root_sdk = SdkBuilder::CreateSampler(model->root); + auto remote_parent_sampled_sdk = SdkBuilder::CreateSampler(model->remote_parent_sampled); + auto remote_parent_not_sampled_sdk = SdkBuilder::CreateSampler(model->remote_parent_not_sampled); + auto local_parent_sampled_sdk = SdkBuilder::CreateSampler(model->local_parent_sampled); + auto local_parent_not_sampled_sdk = SdkBuilder::CreateSampler(model->local_parent_not_sampled); + + OTEL_INTERNAL_LOG_ERROR("CreateParentBasedSampler: FIXME, missing param in parent factory"); + std::shared_ptr delegate_sampler = std::move(root_sdk); + sdk = opentelemetry::sdk::trace::ParentBasedSamplerFactory::Create(delegate_sampler); + + return sdk; +} + +std::unique_ptr SdkBuilder::CreateTraceIdRatioBasedSampler( + const opentelemetry::sdk::configuration::TraceIdRatioBasedSamplerConfiguration *model) const +{ + std::unique_ptr sdk; + + sdk = opentelemetry::sdk::trace::TraceIdRatioBasedSamplerFactory::Create(model->ratio); + + return sdk; +} + +std::unique_ptr SdkBuilder::CreateExtensionSampler( + const opentelemetry::sdk::configuration::ExtensionSamplerConfiguration *model) const +{ + std::unique_ptr sdk; + std::string name = model->name; + + const ExtensionSamplerBuilder *builder = m_registry->GetExtensionSamplerBuilder(name); + + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("CreateExtensionSampler() using registered builder " << name); + sdk = builder->Build(model); + } + else + { + std::string die("CreateExtensionSampler() no builder for "); + die.append(name); + OTEL_INTERNAL_LOG_ERROR(die); + throw UnsupportedException(die); + } + return sdk; +} + +std::unique_ptr SdkBuilder::CreateSampler( + const std::unique_ptr &model) const +{ + std::unique_ptr sdk; + + SamplerBuilder builder(this); + model->Accept(&builder); + sdk = std::move(builder.sampler); + + return sdk; +} + +std::unique_ptr SdkBuilder::CreateOtlpSpanExporter( + const opentelemetry::sdk::configuration::OtlpSpanExporterConfiguration *model) const +{ + std::unique_ptr sdk; + const OtlpSpanExporterBuilder *builder; + + if (model->protocol.find("http/") == 0) + { + builder = m_registry->GetOtlpHttpSpanBuilder(); + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("CreateOtlpSpanExporter() using registered http builder"); + sdk = builder->Build(model); + return sdk; + } + + std::string die("No http builder for OtlpSpanExporter"); + OTEL_INTERNAL_LOG_ERROR(die); + throw UnsupportedException(die); + } + + if (model->protocol.find("grpc/") == 0) + { + builder = m_registry->GetOtlpGrpcSpanBuilder(); + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("CreateOtlpSpanExporter() using registered grpc builder"); + sdk = builder->Build(model); + return sdk; + } + + std::string die("No builder for OtlpSpanExporter"); + OTEL_INTERNAL_LOG_ERROR(die); + throw UnsupportedException(die); + } + + std::string die("OtlpSpanExporter: illegal protocol: "); + die.append(model->protocol); + OTEL_INTERNAL_LOG_ERROR(die); + throw UnsupportedException(die); + + return sdk; +} + +std::unique_ptr SdkBuilder::CreateConsoleSpanExporter( + const opentelemetry::sdk::configuration::ConsoleSpanExporterConfiguration *model) const +{ + std::unique_ptr sdk; + const ConsoleSpanExporterBuilder *builder = m_registry->GetConsoleSpanBuilder(); + + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("CreateConsoleSpanExporter() using registered builder"); + sdk = builder->Build(model); + } + else + { + std::string die("No builder for ConsoleSpanExporter"); + OTEL_INTERNAL_LOG_ERROR(die); + throw UnsupportedException(die); + } + + return sdk; +} + +std::unique_ptr SdkBuilder::CreateZipkinSpanExporter( + const opentelemetry::sdk::configuration::ZipkinSpanExporterConfiguration *model) const +{ + std::unique_ptr sdk; + const ZipkinSpanExporterBuilder *builder = m_registry->GetZipkinSpanBuilder(); + + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("CreateZipkinSpanExporter() using registered builder"); + sdk = builder->Build(model); + } + else + { + std::string die("No builder for ZipkinSpanExporter"); + OTEL_INTERNAL_LOG_ERROR(die); + throw UnsupportedException(die); + } + + return sdk; +} + +std::unique_ptr SdkBuilder::CreateExtensionSpanExporter( + const opentelemetry::sdk::configuration::ExtensionSpanExporterConfiguration *model) const +{ + std::unique_ptr sdk; + std::string name = model->name; + + const ExtensionSpanExporterBuilder *builder = m_registry->GetExtensionSpanExporterBuilder(name); + + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("CreateExtensionSpanExporter() using registered builder " << name); + sdk = builder->Build(model); + } + else + { + std::string die("CreateExtensionSpanExporter() no builder for "); + die.append(name); + OTEL_INTERNAL_LOG_ERROR(die); + throw UnsupportedException(die); + } + return sdk; +} + +std::unique_ptr SdkBuilder::CreateSpanExporter( + const std::unique_ptr &model) + const +{ + std::unique_ptr sdk; + + SpanExporterBuilder builder(this); + model->Accept(&builder); + sdk = std::move(builder.exporter); + + return sdk; +} + +std::unique_ptr SdkBuilder::CreateBatchSpanProcessor( + const opentelemetry::sdk::configuration::BatchSpanProcessorConfiguration *model) const +{ + std::unique_ptr sdk; + opentelemetry::sdk::trace::BatchSpanProcessorOptions options; + + options.schedule_delay_millis = std::chrono::milliseconds(model->schedule_delay); + +#ifdef LATER + options.xxx = model->export_timeout; +#endif + + options.max_queue_size = model->max_queue_size; + options.max_export_batch_size = model->max_export_batch_size; + + auto exporter_sdk = CreateSpanExporter(model->exporter); + + sdk = opentelemetry::sdk::trace::BatchSpanProcessorFactory::Create(std::move(exporter_sdk), + options); + return sdk; +} + +std::unique_ptr SdkBuilder::CreateSimpleSpanProcessor( + const opentelemetry::sdk::configuration::SimpleSpanProcessorConfiguration *model) const +{ + std::unique_ptr sdk; + + auto exporter_sdk = CreateSpanExporter(model->exporter); + + sdk = opentelemetry::sdk::trace::SimpleSpanProcessorFactory::Create(std::move(exporter_sdk)); + + return sdk; +} + +std::unique_ptr SdkBuilder::CreateExtensionSpanProcessor( + const opentelemetry::sdk::configuration::ExtensionSpanProcessorConfiguration *model) const +{ + std::unique_ptr sdk; + std::string name = model->name; + + const ExtensionSpanProcessorBuilder *builder = m_registry->GetExtensionSpanProcessorBuilder(name); + + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("CreateExtensionSpanProcessor() using registered builder " << name); + sdk = builder->Build(model); + } + else + { + std::string die("CreateExtensionSpanProcessor() no builder for "); + die.append(name); + OTEL_INTERNAL_LOG_ERROR(die); + throw UnsupportedException(die); + } + return sdk; +} + +std::unique_ptr SdkBuilder::CreateSpanProcessor( + const std::unique_ptr &model) + const +{ + std::unique_ptr sdk; + + SpanProcessorBuilder builder(this); + model->Accept(&builder); + sdk = std::move(builder.processor); + + return sdk; +} + +std::unique_ptr SdkBuilder::CreateTracerProvider( + const std::unique_ptr &model, + const opentelemetry::sdk::resource::Resource &resource) const +{ + std::unique_ptr sdk; + + // FIXME-CONFIG: https://github.com/open-telemetry/opentelemetry-configuration/issues/70 + OTEL_INTERNAL_LOG_ERROR("CreateTracerProvider: FIXME (IdGenerator)"); + + std::unique_ptr sampler; + + if (model->sampler) + { + sampler = CreateSampler(model->sampler); + } + + std::vector> sdk_processors; + + for (const auto &processor_model : model->processors) + { + sdk_processors.push_back(CreateSpanProcessor(processor_model)); + } + + // FIXME: use sampler, limits, id_generator, ... + sdk = + opentelemetry::sdk::trace::TracerProviderFactory::Create(std::move(sdk_processors), resource); + + return sdk; +} + +std::unique_ptr +SdkBuilder::CreateTextMapPropagator(const std::string &name) const +{ + std::unique_ptr sdk; + + const TextMapPropagatorBuilder *builder = m_registry->GetTextMapPropagatorBuilder(name); + + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("CreateTextMapPropagator() using registered builder " << name); + sdk = builder->Build(); + } + else + { + std::string die("CreateTextMapPropagator() no builder for "); + die.append(name); + OTEL_INTERNAL_LOG_ERROR(die); + throw UnsupportedException(die); + } + return sdk; +} + +std::unique_ptr +SdkBuilder::CreatePropagator( + const std::unique_ptr &model) const +{ + std::vector> propagators; + std::unique_ptr propagator; + + for (const auto &name : model->composite) + { + propagator = CreateTextMapPropagator(name); + propagators.push_back(std::move(propagator)); + } + + std::unique_ptr sdk( + new opentelemetry::context::propagation::CompositePropagator(std::move(propagators))); + + return sdk; +} + +static opentelemetry::sdk::metrics::InstrumentType ConvertInstrumentType( + enum opentelemetry::sdk::configuration::enum_instrument_type config) +{ + opentelemetry::sdk::metrics::InstrumentType sdk; + + switch (config) + { + case opentelemetry::sdk::configuration::counter: + sdk = opentelemetry::sdk::metrics::InstrumentType::kCounter; + break; + case opentelemetry::sdk::configuration::histogram: + sdk = opentelemetry::sdk::metrics::InstrumentType::kHistogram; + break; + case opentelemetry::sdk::configuration::observable_counter: + sdk = opentelemetry::sdk::metrics::InstrumentType::kObservableCounter; + break; + case opentelemetry::sdk::configuration::observable_gauge: + sdk = opentelemetry::sdk::metrics::InstrumentType::kObservableGauge; + break; + case opentelemetry::sdk::configuration::observable_up_down_counter: + sdk = opentelemetry::sdk::metrics::InstrumentType::kObservableUpDownCounter; + break; + case opentelemetry::sdk::configuration::up_down_counter: + sdk = opentelemetry::sdk::metrics::InstrumentType::kUpDownCounter; + break; + } + + return sdk; +} + +std::unique_ptr +SdkBuilder::CreateOtlpPushMetricExporter( + const opentelemetry::sdk::configuration::OtlpPushMetricExporterConfiguration *model) const +{ + std::unique_ptr sdk; + const OtlpPushMetricExporterBuilder *builder; + + if (model->protocol.find("http/") == 0) + { + builder = m_registry->GetOtlpHttpPushMetricExporterBuilder(); + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("CreateOtlpPushMetricExporter() using registered http builder"); + sdk = builder->Build(model); + return sdk; + } + + std::string die("No http builder for OtlpPushMetricExporter"); + OTEL_INTERNAL_LOG_ERROR(die); + throw UnsupportedException(die); + } + + if (model->protocol.find("grpc/") == 0) + { + builder = m_registry->GetOtlpGrpcPushMetricExporterBuilder(); + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("CreateOtlpPushMetricExporter() using registered grpc builder"); + sdk = builder->Build(model); + return sdk; + } + + std::string die("No grpc builder for OtlpPushMetricExporter"); + OTEL_INTERNAL_LOG_ERROR(die); + throw UnsupportedException(die); + } + + std::string die("OtlpPushMetricExporter: illegal protocol: "); + die.append(model->protocol); + OTEL_INTERNAL_LOG_ERROR(die); + throw UnsupportedException(die); + + return sdk; +} + +std::unique_ptr +SdkBuilder::CreateConsolePushMetricExporter( + const opentelemetry::sdk::configuration::ConsolePushMetricExporterConfiguration *model) const +{ + std::unique_ptr sdk; + + const ConsolePushMetricExporterBuilder *builder = + m_registry->GetConsolePushMetricExporterBuilder(); + + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("CreateConsolePushMetricExporter() using registered builder"); + sdk = builder->Build(model); + } + else + { + std::string die("No builder for ConsolePushMetricExporter"); + OTEL_INTERNAL_LOG_ERROR(die); + throw UnsupportedException(die); + } + + return sdk; +} + +std::unique_ptr +SdkBuilder::CreateExtensionPushMetricExporter( + const opentelemetry::sdk::configuration::ExtensionPushMetricExporterConfiguration *model) const +{ + std::unique_ptr sdk; + std::string name = model->name; + + const ExtensionPushMetricExporterBuilder *builder = + m_registry->GetExtensionPushMetricExporterBuilder(name); + + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("CreateExtensionPushMetricExporter() using registered builder" << name); + sdk = builder->Build(model); + } + else + { + std::string die("No builder for ExtensionPushMetricExporter "); + die.append(name); + OTEL_INTERNAL_LOG_ERROR(die); + throw UnsupportedException(die); + } + + return sdk; +} + +std::unique_ptr +SdkBuilder::CreatePrometheusPullMetricExporter( + const opentelemetry::sdk::configuration::PrometheusPullMetricExporterConfiguration *model) const +{ + std::unique_ptr sdk; + + const PrometheusPullMetricExporterBuilder *builder = + m_registry->GetPrometheusPullMetricExporterBuilder(); + + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("CreatePrometheusPullMetricExporter() using registered builder"); + sdk = builder->Build(model); + } + else + { + std::string die("No builder for PrometheusMetricExporter"); + OTEL_INTERNAL_LOG_ERROR(die); + throw UnsupportedException(die); + } + + return sdk; +} + +std::unique_ptr +SdkBuilder::CreateExtensionPullMetricExporter( + const opentelemetry::sdk::configuration::ExtensionPullMetricExporterConfiguration *model) const +{ + std::unique_ptr sdk; + std::string name = model->name; + + const ExtensionPullMetricExporterBuilder *builder = + m_registry->GetExtensionPullMetricExporterBuilder(name); + + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("CreateExtensionPullMetricExporter() using registered builder" << name); + sdk = builder->Build(model); + } + else + { + std::string die("No builder for ExtensionPullMetricExporter "); + die.append(name); + OTEL_INTERNAL_LOG_ERROR(die); + throw UnsupportedException(die); + } + + return sdk; +} + +std::unique_ptr +SdkBuilder::CreatePushMetricExporter( + const std::unique_ptr + &model) const +{ + std::unique_ptr sdk; + + OTEL_INTERNAL_LOG_ERROR("SdkBuilder::CreatePushMetricExporter: FIXME"); + + PushMetricExporterBuilder builder(this); + model->Accept(&builder); + sdk = std::move(builder.exporter); + + return sdk; +} + +std::unique_ptr SdkBuilder::CreatePullMetricExporter( + const std::unique_ptr + &model) const +{ + std::unique_ptr sdk; + + OTEL_INTERNAL_LOG_ERROR("SdkBuilder::CreatePullMetricExporter: FIXME"); + + PullMetricExporterBuilder builder(this); + model->Accept(&builder); + sdk = std::move(builder.exporter); + + return sdk; +} + +std::unique_ptr SdkBuilder::CreatePeriodicMetricReader( + const opentelemetry::sdk::configuration::PeriodicMetricReaderConfiguration *model) const +{ + std::unique_ptr sdk; + + opentelemetry::sdk::metrics::PeriodicExportingMetricReaderOptions options; + + options.export_interval_millis = std::chrono::milliseconds(model->interval); + options.export_timeout_millis = std::chrono::milliseconds(model->timeout); + + auto exporter_sdk = CreatePushMetricExporter(model->exporter); + + sdk = opentelemetry::sdk::metrics::PeriodicExportingMetricReaderFactory::Create( + std::move(exporter_sdk), options); + + return sdk; +} + +std::unique_ptr SdkBuilder::CreatePullMetricReader( + const opentelemetry::sdk::configuration::PullMetricReaderConfiguration *model) const +{ + std::unique_ptr sdk; + + OTEL_INTERNAL_LOG_ERROR("SdkBuilder::CreatePullMetricReader: FIXME"); + sdk = CreatePullMetricExporter(model->exporter); + + return sdk; +} + +std::unique_ptr SdkBuilder::CreateMetricReader( + const std::unique_ptr &model) + const +{ + std::unique_ptr sdk; + + MetricReaderBuilder builder(this); + model->Accept(&builder); + sdk = std::move(builder.metric_reader); + + return sdk; +} + +void SdkBuilder::AddView( + opentelemetry::sdk::metrics::ViewRegistry *registry, + const std::unique_ptr &model) const +{ + auto *selector = model->selector.get(); + + auto sdk_instrument_type = ConvertInstrumentType(selector->instrument_type); + + std::unique_ptr sdk_instrument_selector( + new opentelemetry::sdk::metrics::InstrumentSelector( + sdk_instrument_type, selector->instrument_name, selector->unit)); + + std::unique_ptr sdk_meter_selector( + new opentelemetry::sdk::metrics::MeterSelector(selector->meter_name, selector->meter_version, + selector->meter_schema_url)); + + auto *stream = model->stream.get(); + + std::string unit("FIXME"); + + opentelemetry::sdk::metrics::AggregationType sdk_aggregation_type = + opentelemetry::sdk::metrics::AggregationType::kDefault; // FIXME + + std::shared_ptr sdk_aggregation_config = + nullptr; // FIXME + + std::unique_ptr + sdk_attribute_processor; // FIXME + + std::unique_ptr sdk_view(new opentelemetry::sdk::metrics::View( + stream->name, stream->description, unit, sdk_aggregation_type, sdk_aggregation_config, + std::move(sdk_attribute_processor))); + + registry->AddView(std::move(sdk_instrument_selector), std::move(sdk_meter_selector), + std::move(sdk_view)); + + OTEL_INTERNAL_LOG_ERROR("AddView() FIXME"); +} + +std::unique_ptr SdkBuilder::CreateMeterProvider( + const std::unique_ptr &model, + const opentelemetry::sdk::resource::Resource &resource) const +{ + std::unique_ptr sdk; + + auto view_registry = opentelemetry::sdk::metrics::ViewRegistryFactory::Create(); + + for (const auto &view_configuration : model->views) + { + AddView(view_registry.get(), view_configuration); + } + + auto meter_context = + opentelemetry::sdk::metrics::MeterContextFactory::Create(std::move(view_registry), resource); + + OTEL_INTERNAL_LOG_ERROR("CreateMeterProvider() FIXME"); + + for (const auto &reader_configuration : model->readers) + { + std::shared_ptr metric_reader; + metric_reader = CreateMetricReader(reader_configuration); + meter_context->AddMetricReader(metric_reader); + } + + sdk = opentelemetry::sdk::metrics::MeterProviderFactory::Create(std::move(meter_context)); + + return sdk; +} + +std::unique_ptr +SdkBuilder::CreateOtlpLogRecordExporter( + const opentelemetry::sdk::configuration::OtlpLogRecordExporterConfiguration *model) const +{ + std::unique_ptr sdk; + const OtlpLogRecordExporterBuilder *builder; + + if (model->protocol.find("http/") == 0) + { + builder = m_registry->GetOtlpHttpLogRecordBuilder(); + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("CreateOtlpLogRecordExporter() using registered http builder"); + sdk = builder->Build(model); + return sdk; + } + + std::string die("No http builder for OtlpLogRecordExporter"); + OTEL_INTERNAL_LOG_ERROR(die); + throw UnsupportedException(die); + } + + if (model->protocol.find("grpc/") == 0) + { + builder = m_registry->GetOtlpGrpcLogRecordBuilder(); + if (builder != nullptr) + { + builder = m_registry->GetOtlpGrpcLogRecordBuilder(); + OTEL_INTERNAL_LOG_DEBUG("CreateOtlpLogRecordExporter() using registered grpc builder"); + sdk = builder->Build(model); + return sdk; + } + + std::string die("No grpc builder for OtlpLogRecordExporter"); + OTEL_INTERNAL_LOG_ERROR(die); + throw UnsupportedException(die); + } + + std::string die("OtlpLogRecordExporter: illegal protocol: "); + die.append(model->protocol); + OTEL_INTERNAL_LOG_ERROR(die); + throw UnsupportedException(die); + + return sdk; +} + +std::unique_ptr +SdkBuilder::CreateConsoleLogRecordExporter( + const opentelemetry::sdk::configuration::ConsoleLogRecordExporterConfiguration *model) const +{ + std::unique_ptr sdk; + const ConsoleLogRecordExporterBuilder *builder = m_registry->GetConsoleLogRecordBuilder(); + + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("CreateConsoleLogRecordExporter() using registered builder"); + sdk = builder->Build(model); + } + else + { + std::string die("No builder for ConsoleLogRecordExporter"); + OTEL_INTERNAL_LOG_ERROR(die); + throw UnsupportedException(die); + } + + return sdk; +} + +std::unique_ptr +SdkBuilder::CreateExtensionLogRecordExporter( + const opentelemetry::sdk::configuration::ExtensionLogRecordExporterConfiguration *model) const +{ + std::unique_ptr sdk; + std::string name = model->name; + + const ExtensionLogRecordExporterBuilder *builder = + m_registry->GetExtensionLogRecordExporterBuilder(name); + + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("CreateExtensionLogRecordExporter() using registered builder " << name); + sdk = builder->Build(model); + } + else + { + std::string die("CreateExtensionLogRecordExporter() no builder for "); + die.append(name); + OTEL_INTERNAL_LOG_ERROR(die); + throw UnsupportedException(die); + } + return sdk; +} + +std::unique_ptr SdkBuilder::CreateLogRecordExporter( + const std::unique_ptr &model) + const +{ + std::unique_ptr sdk; + + LogRecordExporterBuilder builder(this); + model->Accept(&builder); + sdk = std::move(builder.exporter); + + return sdk; +} + +std::unique_ptr +SdkBuilder::CreateBatchLogRecordProcessor( + const opentelemetry::sdk::configuration::BatchLogRecordProcessorConfiguration *model) const +{ + std::unique_ptr sdk; + opentelemetry::sdk::logs::BatchLogRecordProcessorOptions options; + + options.schedule_delay_millis = std::chrono::milliseconds(model->schedule_delay); + options.max_queue_size = model->max_queue_size; + options.max_export_batch_size = model->max_export_batch_size; + + auto exporter_sdk = CreateLogRecordExporter(model->exporter); + + sdk = opentelemetry::sdk::logs::BatchLogRecordProcessorFactory::Create(std::move(exporter_sdk), + options); + + return sdk; +} + +std::unique_ptr +SdkBuilder::CreateSimpleLogRecordProcessor( + const opentelemetry::sdk::configuration::SimpleLogRecordProcessorConfiguration *model) const +{ + std::unique_ptr sdk; + + auto exporter_sdk = CreateLogRecordExporter(model->exporter); + + sdk = opentelemetry::sdk::logs::SimpleLogRecordProcessorFactory::Create(std::move(exporter_sdk)); + + return sdk; +} + +std::unique_ptr +SdkBuilder::CreateExtensionLogRecordProcessor( + const opentelemetry::sdk::configuration::ExtensionLogRecordProcessorConfiguration *model) const +{ + std::unique_ptr sdk; + std::string name = model->name; + + const ExtensionLogRecordProcessorBuilder *builder = + m_registry->GetExtensionLogRecordProcessorBuilder(name); + + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("CreateExtensionLogRecordProcessor() using registered builder " + << name); + sdk = builder->Build(model); + } + else + { + std::string die("CreateExtensionLogRecordProcessor() no builder for "); + die.append(name); + OTEL_INTERNAL_LOG_ERROR(die); + throw UnsupportedException(die); + } + return sdk; +} + +std::unique_ptr SdkBuilder::CreateLogRecordProcessor( + const std::unique_ptr + &model) const +{ + std::unique_ptr sdk; + + LogRecordProcessorBuilder builder(this); + model->Accept(&builder); + sdk = std::move(builder.processor); + + return sdk; +} + +std::unique_ptr SdkBuilder::CreateLoggerProvider( + const std::unique_ptr &model, + const opentelemetry::sdk::resource::Resource &resource) const +{ + std::unique_ptr sdk; + + std::vector> sdk_processors; + + for (const auto &processor_model : model->processors) + { + sdk_processors.push_back(CreateLogRecordProcessor(processor_model)); + } + + // FIXME: use limits + sdk = + opentelemetry::sdk::logs::LoggerProviderFactory::Create(std::move(sdk_processors), resource); + + return sdk; +} + +void SdkBuilder::SetResource( + opentelemetry::sdk::resource::Resource &resource, + const std::unique_ptr &opt_model) + const +{ + if (opt_model) + { + opentelemetry::sdk::resource::ResourceAttributes sdk_attributes; + + if (opt_model->attributes) + { + for (const auto &kv : opt_model->attributes->kv_map) + { + sdk_attributes.SetAttribute(kv.first, kv.second); + } + } + + if (opt_model->attributes_list.size() != 0) + { + OTEL_INTERNAL_LOG_ERROR("SdkBuilder::SetResource: FIXME attributes_list"); + } + + if (opt_model->detectors != nullptr) + { + OTEL_INTERNAL_LOG_ERROR("SdkBuilder::SetResource: FIXME detectors"); + } + + auto sdk_resource = + opentelemetry::sdk::resource::Resource::Create(sdk_attributes, opt_model->schema_url); + resource = resource.Merge(sdk_resource); + } + else + { + resource = opentelemetry::sdk::resource::Resource::GetDefault(); + } +} + +std::unique_ptr SdkBuilder::CreateConfiguredSdk( + const std::unique_ptr &model) const +{ + std::unique_ptr sdk(new ConfiguredSdk); + + if (!model->disabled) + { + SetResource(sdk->m_resource, model->resource); + + if (model->attribute_limits) + { + OTEL_INTERNAL_LOG_ERROR("SdkBuilder::CreateConfiguredSdk: FIXME limits"); + // Ignore limits + // throw UnsupportedException("attribute_limits not available in opentelemetry-cpp"); + } + + if (model->tracer_provider) + { + sdk->m_tracer_provider = CreateTracerProvider(model->tracer_provider, sdk->m_resource); + } + + if (model->propagator) + { + sdk->m_propagator = CreatePropagator(model->propagator); + } + + if (model->meter_provider) + { + sdk->m_meter_provider = CreateMeterProvider(model->meter_provider, sdk->m_resource); + } + + if (model->logger_provider) + { + sdk->m_logger_provider = CreateLoggerProvider(model->logger_provider, sdk->m_resource); + } + } + + return sdk; +} + +} // namespace init +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/resource/resource.cc b/sdk/src/resource/resource.cc index 5ae5446e80..95b41498f8 100644 --- a/sdk/src/resource/resource.cc +++ b/sdk/src/resource/resource.cc @@ -20,6 +20,12 @@ namespace sdk namespace resource { +Resource::Resource() noexcept : attributes_(), schema_url_() {} + +Resource::Resource(const ResourceAttributes &attributes) noexcept + : attributes_(attributes), schema_url_() +{} + Resource::Resource(const ResourceAttributes &attributes, const std::string &schema_url) noexcept : attributes_(attributes), schema_url_(schema_url) {} diff --git a/sdk/test/CMakeLists.txt b/sdk/test/CMakeLists.txt index 33dd07f81a..dd957fae1f 100644 --- a/sdk/test/CMakeLists.txt +++ b/sdk/test/CMakeLists.txt @@ -7,3 +7,7 @@ add_subdirectory(metrics) add_subdirectory(logs) add_subdirectory(resource) add_subdirectory(instrumentationscope) + +if(WITH_CONFIGURATION) + add_subdirectory(configuration) +endif() diff --git a/sdk/test/configuration/CMakeLists.txt b/sdk/test/configuration/CMakeLists.txt new file mode 100644 index 0000000000..6dfe2d856a --- /dev/null +++ b/sdk/test/configuration/CMakeLists.txt @@ -0,0 +1,12 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +foreach(testname yaml_test yaml_trace_test yaml_resource_test) + add_executable(${testname} "${testname}.cc") + target_link_libraries(${testname} ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_configuration) + gtest_add_tests( + TARGET ${testname} + TEST_PREFIX trace. + TEST_LIST ${testname}) +endforeach() diff --git a/sdk/test/configuration/yaml_resource_test.cc b/sdk/test/configuration/yaml_resource_test.cc new file mode 100644 index 0000000000..a2c139c718 --- /dev/null +++ b/sdk/test/configuration/yaml_resource_test.cc @@ -0,0 +1,225 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include +#include +#include +#include +#include + +#include "opentelemetry/sdk/configuration/attributes_configuration.h" +#include "opentelemetry/sdk/configuration/configuration.h" +#include "opentelemetry/sdk/configuration/detectors_configuration.h" +#include "opentelemetry/sdk/configuration/resource_configuration.h" +#include "opentelemetry/sdk/configuration/string_array_configuration.h" +#include "opentelemetry/sdk/configuration/yaml_configuration_factory.h" + +std::unique_ptr DoParse(const std::string &yaml) +{ + static const std::string source("test"); + return opentelemetry::sdk::configuration::YamlConfigurationFactory::ParseString(source, yaml); +} + +TEST(YamlResource, empty_resource) +{ + std::string yaml = R"( +file_format: xx.yy +resource: +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_NE(config->resource, nullptr); + ASSERT_EQ(config->resource->attributes, nullptr); + ASSERT_EQ(config->resource->attributes_list, ""); + ASSERT_EQ(config->resource->detectors, nullptr); +} + +TEST(YamlResource, empty_attributes) +{ + std::string yaml = R"( +file_format: xx.yy +resource: + attributes: +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_NE(config->resource, nullptr); + ASSERT_NE(config->resource->attributes, nullptr); + ASSERT_EQ(config->resource->attributes->kv_map.size(), 0); +} + +TEST(YamlResource, some_attributes) +{ + std::string yaml = R"( +file_format: xx.yy +resource: + attributes: + foo: "1234" + bar: "5678" +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_NE(config->resource, nullptr); + ASSERT_NE(config->resource->attributes, nullptr); + ASSERT_EQ(config->resource->attributes->kv_map.size(), 2); + ASSERT_EQ(config->resource->attributes->kv_map["foo"], "1234"); + ASSERT_EQ(config->resource->attributes->kv_map["bar"], "5678"); +} + +TEST(YamlResource, empty_attributes_list) +{ + std::string yaml = R"( +file_format: xx.yy +resource: + attributes_list: +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_NE(config->resource, nullptr); + ASSERT_EQ(config->resource->attributes_list, ""); +} + +TEST(YamlResource, some_attributes_list) +{ + std::string yaml = R"( +file_format: xx.yy +resource: + attributes_list: "foo=1234,bar=5678" +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_NE(config->resource, nullptr); + ASSERT_EQ(config->resource->attributes_list, "foo=1234,bar=5678"); +} + +TEST(YamlResource, both) +{ + std::string yaml = R"( +file_format: xx.yy +resource: + attributes: + foo: "1234" + bar: "5678" + attributes_list: "foo=aaaa,bar=bbbb" +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_NE(config->resource, nullptr); + ASSERT_NE(config->resource->attributes, nullptr); + ASSERT_EQ(config->resource->attributes->kv_map.size(), 2); + ASSERT_EQ(config->resource->attributes->kv_map["foo"], "1234"); + ASSERT_EQ(config->resource->attributes->kv_map["bar"], "5678"); + ASSERT_EQ(config->resource->attributes_list, "foo=aaaa,bar=bbbb"); +} + +TEST(YamlResource, empty_detectors) +{ + std::string yaml = R"( +file_format: xx.yy +resource: + detectors: +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_NE(config->resource, nullptr); + ASSERT_NE(config->resource->detectors, nullptr); + ASSERT_EQ(config->resource->detectors->included, nullptr); + ASSERT_EQ(config->resource->detectors->excluded, nullptr); +} + +TEST(YamlResource, empty_included_detectors) +{ + std::string yaml = R"( +file_format: xx.yy +resource: + detectors: + included: +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_NE(config->resource, nullptr); + ASSERT_NE(config->resource->detectors, nullptr); + ASSERT_NE(config->resource->detectors->included, nullptr); + ASSERT_EQ(config->resource->detectors->included->string_array.size(), 0); + ASSERT_EQ(config->resource->detectors->excluded, nullptr); +} + +TEST(YamlResource, some_included_detectors) +{ + std::string yaml = R"( +file_format: xx.yy +resource: + detectors: + included: + - foo + - bar +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_NE(config->resource, nullptr); + ASSERT_NE(config->resource->detectors, nullptr); + ASSERT_NE(config->resource->detectors->included, nullptr); + ASSERT_EQ(config->resource->detectors->included->string_array.size(), 2); + ASSERT_EQ(config->resource->detectors->included->string_array[0], "foo"); + ASSERT_EQ(config->resource->detectors->included->string_array[1], "bar"); + ASSERT_EQ(config->resource->detectors->excluded, nullptr); +} + +TEST(YamlResource, some_excluded_detectors) +{ + std::string yaml = R"( +file_format: xx.yy +resource: + detectors: + excluded: + - foo + - bar +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_NE(config->resource, nullptr); + ASSERT_NE(config->resource->detectors, nullptr); + ASSERT_EQ(config->resource->detectors->included, nullptr); + ASSERT_NE(config->resource->detectors->excluded, nullptr); + ASSERT_EQ(config->resource->detectors->excluded->string_array.size(), 2); + ASSERT_EQ(config->resource->detectors->excluded->string_array[0], "foo"); + ASSERT_EQ(config->resource->detectors->excluded->string_array[1], "bar"); +} + +TEST(YamlResource, some_detectors) +{ + std::string yaml = R"( +file_format: xx.yy +resource: + detectors: + included: + - foo.in + - bar.in + excluded: + - foo.ex + - bar.ex +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_NE(config->resource, nullptr); + ASSERT_NE(config->resource->detectors, nullptr); + ASSERT_NE(config->resource->detectors->included, nullptr); + ASSERT_EQ(config->resource->detectors->included->string_array.size(), 2); + ASSERT_EQ(config->resource->detectors->included->string_array[0], "foo.in"); + ASSERT_EQ(config->resource->detectors->included->string_array[1], "bar.in"); + ASSERT_NE(config->resource->detectors->excluded, nullptr); + ASSERT_EQ(config->resource->detectors->excluded->string_array.size(), 2); + ASSERT_EQ(config->resource->detectors->excluded->string_array[0], "foo.ex"); + ASSERT_EQ(config->resource->detectors->excluded->string_array[1], "bar.ex"); +} diff --git a/sdk/test/configuration/yaml_test.cc b/sdk/test/configuration/yaml_test.cc new file mode 100644 index 0000000000..e3398a3d78 --- /dev/null +++ b/sdk/test/configuration/yaml_test.cc @@ -0,0 +1,662 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include +#include +#include +#include + +#include "opentelemetry/sdk/configuration/attribute_limits_configuration.h" +#include "opentelemetry/sdk/configuration/configuration.h" +#include "opentelemetry/sdk/configuration/trace_id_ratio_based_sampler_configuration.h" +#include "opentelemetry/sdk/configuration/tracer_provider_configuration.h" +#include "opentelemetry/sdk/configuration/yaml_configuration_factory.h" + +std::unique_ptr DoParse(const std::string &yaml) +{ + static const std::string source("test"); + return opentelemetry::sdk::configuration::YamlConfigurationFactory::ParseString(source, yaml); +} + +TEST(Yaml, empty) +{ + std::string yaml = ""; + + auto config = DoParse(yaml); + ASSERT_EQ(config, nullptr); +} + +TEST(Yaml, no_format) +{ + std::string yaml = R"( +file_format: +)"; + + auto config = DoParse(yaml); + ASSERT_EQ(config, nullptr); +} + +TEST(Yaml, just_format) +{ + std::string yaml = R"( +file_format: xx.yy +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_EQ(config->file_format, "xx.yy"); +} + +TEST(Yaml, disabled) +{ + std::string yaml = R"( +file_format: xx.yy +disabled: true +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_EQ(config->file_format, "xx.yy"); + ASSERT_EQ(config->disabled, true); +} + +TEST(Yaml, enabled) +{ + std::string yaml = R"( +file_format: xx.yy +disabled: false +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_EQ(config->file_format, "xx.yy"); + ASSERT_EQ(config->disabled, false); +} + +TEST(Yaml, enabled_by_default) +{ + std::string yaml = R"( +file_format: xx.yy +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_EQ(config->file_format, "xx.yy"); + ASSERT_EQ(config->disabled, false); +} + +TEST(Yaml, no_attribute_limits) +{ + std::string yaml = R"( +file_format: xx.yy +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_EQ(config->attribute_limits, nullptr); +} + +TEST(Yaml, empty_attribute_limits) +{ + std::string yaml = R"( +file_format: xx.yy +attribute_limits: +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_EQ(config->file_format, "xx.yy"); + ASSERT_NE(config->attribute_limits, nullptr); + ASSERT_EQ(config->attribute_limits->attribute_value_length_limit, 4096); + ASSERT_EQ(config->attribute_limits->attribute_count_limit, 128); +} + +TEST(Yaml, attribute_limits) +{ + std::string yaml = R"( +file_format: xx.yy +attribute_limits: + attribute_value_length_limit: 1234 + attribute_count_limit: 5678 +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_EQ(config->file_format, "xx.yy"); + ASSERT_NE(config->attribute_limits, nullptr); + ASSERT_EQ(config->attribute_limits->attribute_value_length_limit, 1234); + ASSERT_EQ(config->attribute_limits->attribute_count_limit, 5678); +} + +TEST(Yaml, no_optional_boolean) +{ + std::string yaml = R"( +file_format: 0.0 +disabled: +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_EQ(config->disabled, false); +} + +TEST(Yaml, illegal_boolean) +{ + std::string yaml = R"( +file_format: 0.0 +disabled: illegal +)"; + + auto config = DoParse(yaml); + ASSERT_EQ(config, nullptr); +} + +TEST(Yaml, no_boolean_substitution) +{ + unsetenv("ENV_NAME"); + + std::string yaml = R"( +file_format: 0.0 +disabled: ${ENV_NAME} +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_EQ(config->disabled, false); +} + +TEST(Yaml, no_boolean_substitution_env) +{ + unsetenv("ENV_NAME"); + + std::string yaml = R"( +file_format: 0.0 +disabled: ${env:ENV_NAME} +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_EQ(config->disabled, false); +} + +TEST(Yaml, empty_boolean_substitution) +{ + setenv("ENV_NAME", "", 1); + + std::string yaml = R"( +file_format: 0.0 +disabled: ${ENV_NAME} +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_EQ(config->disabled, false); +} + +TEST(Yaml, empty_boolean_substitution_env) +{ + setenv("ENV_NAME", "", 1); + + std::string yaml = R"( +file_format: 0.0 +disabled: ${env:ENV_NAME} +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_EQ(config->disabled, false); +} + +TEST(Yaml, true_boolean_substitution) +{ + setenv("ENV_NAME", "true", 1); + + std::string yaml = R"( +file_format: 0.0 +disabled: ${ENV_NAME} +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_EQ(config->disabled, true); +} + +TEST(Yaml, false_boolean_substitution) +{ + setenv("ENV_NAME", "false", 1); + + std::string yaml = R"( +file_format: 0.0 +disabled: ${ENV_NAME} +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_EQ(config->disabled, false); +} + +TEST(Yaml, illegal_boolean_substitution) +{ + setenv("ENV_NAME", "illegal", 1); + + std::string yaml = R"( +file_format: 0.0 +disabled: ${ENV_NAME} +)"; + + auto config = DoParse(yaml); + ASSERT_EQ(config, nullptr); +} + +TEST(Yaml, empty_boolean_substitution_fallback) +{ + unsetenv("ENV_NAME"); + + std::string yaml = R"( +file_format: 0.0 +disabled: ${ENV_NAME:-} +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_EQ(config->disabled, false); +} + +TEST(Yaml, true_boolean_substitution_fallback) +{ + unsetenv("ENV_NAME"); + + std::string yaml = R"( +file_format: 0.0 +disabled: ${ENV_NAME:-true} +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_EQ(config->disabled, true); +} + +TEST(Yaml, false_boolean_substitution_fallback) +{ + unsetenv("ENV_NAME"); + + std::string yaml = R"( +file_format: 0.0 +disabled: ${ENV_NAME:-false} +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_EQ(config->disabled, false); +} + +TEST(Yaml, illegal_boolean_substitution_fallback) +{ + unsetenv("ENV_NAME"); + + std::string yaml = R"( +file_format: 0.0 +disabled: ${ENV_NAME:-illegal} +)"; + + auto config = DoParse(yaml); + ASSERT_EQ(config, nullptr); +} + +TEST(Yaml, torture_boolean_substitution_fallback) +{ + setenv("env", "true", 1); + + std::string yaml = R"( +file_format: 0.0 +disabled: ${env:-false} +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_EQ(config->disabled, true); +} + +TEST(Yaml, no_required_string) +{ + std::string yaml = R"( +file_format: +)"; + + auto config = DoParse(yaml); + ASSERT_EQ(config, nullptr); +} + +TEST(Yaml, no_string_substitution) +{ + unsetenv("ENV_NAME"); + + std::string yaml = R"( +file_format: ${ENV_NAME} +)"; + + auto config = DoParse(yaml); + ASSERT_EQ(config, nullptr); +} + +TEST(Yaml, no_string_substitution_env) +{ + unsetenv("ENV_NAME"); + + std::string yaml = R"( +file_format: ${env:ENV_NAME} +)"; + + auto config = DoParse(yaml); + ASSERT_EQ(config, nullptr); +} + +TEST(Yaml, empty_string_substitution) +{ + setenv("ENV_NAME", "", 1); + + std::string yaml = R"( +file_format: ${ENV_NAME} +)"; + + auto config = DoParse(yaml); + ASSERT_EQ(config, nullptr); +} + +TEST(Yaml, empty_string_substitution_env) +{ + setenv("ENV_NAME", "", 1); + + std::string yaml = R"( +file_format: ${env:ENV_NAME} +)"; + + auto config = DoParse(yaml); + ASSERT_EQ(config, nullptr); +} + +TEST(Yaml, with_string_substitution) +{ + setenv("ENV_NAME", "foo.bar", 1); + + std::string yaml = R"( +file_format: ${ENV_NAME} +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_EQ(config->file_format, "foo.bar"); +} + +TEST(Yaml, with_string_substitution_env) +{ + setenv("ENV_NAME", "foo.bar", 1); + + std::string yaml = R"( +file_format: ${env:ENV_NAME} +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_EQ(config->file_format, "foo.bar"); +} + +TEST(Yaml, with_string_substitution_fallback) +{ + unsetenv("ENV_NAME"); + + std::string yaml = R"( +file_format: ${env:ENV_NAME:-foo.bar} +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_EQ(config->file_format, "foo.bar"); +} + +TEST(Yaml, multiple_string_substitution) +{ + setenv("PREFIX", "foo", 1); + unsetenv("DOT"); + setenv("SUFFIX", "bar", 1); + + std::string yaml = R"( +file_format: ${env:PREFIX:-failed}${DOT:-.}${SUFFIX:-failed} +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_EQ(config->file_format, "foo.bar"); +} + +TEST(Yaml, no_optional_integer) +{ + std::string yaml = R"( +file_format: 0.0 +attribute_limits: + attribute_count_limit: +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_NE(config->attribute_limits, nullptr); + ASSERT_EQ(config->attribute_limits->attribute_count_limit, 128); +} + +TEST(Yaml, illegal_integer) +{ + std::string yaml = R"( +file_format: 0.0 +attribute_limits: + attribute_count_limit: "just enough" +)"; + + auto config = DoParse(yaml); + ASSERT_EQ(config, nullptr); +} + +TEST(Yaml, no_integer_substitution) +{ + unsetenv("ENV_NAME"); + + std::string yaml = R"( +file_format: 0.0 +attribute_limits: + attribute_count_limit: ${ENV_NAME} +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_NE(config->attribute_limits, nullptr); + ASSERT_EQ(config->attribute_limits->attribute_count_limit, 128); +} + +TEST(Yaml, empty_integer_substitution) +{ + setenv("ENV_NAME", "", 1); + + std::string yaml = R"( +file_format: 0.0 +attribute_limits: + attribute_count_limit: ${ENV_NAME} +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_NE(config->attribute_limits, nullptr); + ASSERT_EQ(config->attribute_limits->attribute_count_limit, 128); +} + +TEST(Yaml, with_integer_substitution) +{ + setenv("ENV_NAME", "7777", 1); + + std::string yaml = R"( +file_format: 0.0 +attribute_limits: + attribute_count_limit: ${ENV_NAME} +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_NE(config->attribute_limits, nullptr); + ASSERT_EQ(config->attribute_limits->attribute_count_limit, 7777); +} + +TEST(Yaml, with_illegal_integer_substitution) +{ + setenv("ENV_NAME", "still not enough", 1); + + std::string yaml = R"( +file_format: 0.0 +attribute_limits: + attribute_count_limit: ${ENV_NAME} +)"; + + auto config = DoParse(yaml); + ASSERT_EQ(config, nullptr); +} + +TEST(Yaml, no_optional_double) +{ + std::string yaml = R"( +file_format: 0.0 +tracer_provider: + processors: + - simple: + exporter: + console: + sampler: + trace_id_ratio_based: + ratio: +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_NE(config->tracer_provider, nullptr); + ASSERT_NE(config->tracer_provider->sampler, nullptr); + auto sampler = config->tracer_provider->sampler.get(); + auto ratio_sampler = + static_cast( + sampler); + ASSERT_EQ(ratio_sampler->ratio, 0.0); +} + +TEST(Yaml, illegal_double) +{ + std::string yaml = R"( +file_format: 0.0 +tracer_provider: + processors: + - simple: + exporter: + console: + sampler: + trace_id_ratio_based: + ratio: something +)"; + + auto config = DoParse(yaml); + ASSERT_EQ(config, nullptr); +} + +TEST(Yaml, no_double_substitution) +{ + unsetenv("ENV_NAME"); + + std::string yaml = R"( +file_format: 0.0 +tracer_provider: + processors: + - simple: + exporter: + console: + sampler: + trace_id_ratio_based: + ratio: ${ENV_NAME} +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_NE(config->tracer_provider, nullptr); + ASSERT_NE(config->tracer_provider->sampler, nullptr); + auto sampler = config->tracer_provider->sampler.get(); + auto ratio_sampler = + static_cast( + sampler); + ASSERT_EQ(ratio_sampler->ratio, 0.0); +} + +TEST(Yaml, empty_double_substitution) +{ + setenv("ENV_NAME", "", 1); + + std::string yaml = R"( +file_format: 0.0 +tracer_provider: + processors: + - simple: + exporter: + console: + sampler: + trace_id_ratio_based: + ratio: ${ENV_NAME} +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_NE(config->tracer_provider, nullptr); + ASSERT_NE(config->tracer_provider->sampler, nullptr); + auto sampler = config->tracer_provider->sampler.get(); + auto ratio_sampler = + static_cast( + sampler); + ASSERT_EQ(ratio_sampler->ratio, 0.0); +} + +TEST(Yaml, with_double_substitution) +{ + setenv("ENV_NAME", "3.14", 1); + + std::string yaml = R"( +file_format: 0.0 +tracer_provider: + processors: + - simple: + exporter: + console: + sampler: + trace_id_ratio_based: + ratio: ${ENV_NAME} +)"; + + auto config = DoParse(yaml); + ASSERT_NE(config, nullptr); + ASSERT_NE(config->tracer_provider, nullptr); + ASSERT_NE(config->tracer_provider->sampler, nullptr); + auto sampler = config->tracer_provider->sampler.get(); + auto ratio_sampler = + static_cast( + sampler); + ASSERT_EQ(ratio_sampler->ratio, 3.14); +} + +TEST(Yaml, with_illegal_double_substitution) +{ + setenv("ENV_NAME", "something else", 1); + + std::string yaml = R"( +file_format: 0.0 +tracer_provider: + processors: + - simple: + exporter: + console: + sampler: + trace_id_ratio_based: + ratio: ${ENV_NAME} +)"; + + auto config = DoParse(yaml); + ASSERT_EQ(config, nullptr); +} diff --git a/sdk/test/configuration/yaml_trace_test.cc b/sdk/test/configuration/yaml_trace_test.cc new file mode 100644 index 0000000000..e448d3305f --- /dev/null +++ b/sdk/test/configuration/yaml_trace_test.cc @@ -0,0 +1,38 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include +#include +#include + +#include "opentelemetry/sdk/configuration/configuration.h" +#include "opentelemetry/sdk/configuration/yaml_configuration_factory.h" + +std::unique_ptr DoParse(const std::string &yaml) +{ + static const std::string source("test"); + return opentelemetry::sdk::configuration::YamlConfigurationFactory::ParseString(source, yaml); +} + +TEST(YamlTrace, no_processors) +{ + std::string yaml = R"( +file_format: xx.yy +tracer_provider: +)"; + + auto config = DoParse(yaml); + ASSERT_EQ(config, nullptr); +} + +TEST(YamlTrace, empty_processors) +{ + std::string yaml = R"( +file_format: xx.yy +tracer_provider: + processors: +)"; + + auto config = DoParse(yaml); + ASSERT_EQ(config, nullptr); +}