From 469bc0e345ab559766c91ead0e3dc0a22c4858cd Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Thu, 1 Feb 2024 02:01:01 +0100 Subject: [PATCH] POC --- .../batch_span_processor_configuration.h | 6 + .../extension_span_exporter_configuration.h | 31 ++++ .../extension_span_processor_configuration.h | 31 ++++ .../otlp_span_exporter_configuration.h | 6 + .../simple_span_processor_configuration.h | 6 + .../span_exporter_configuration.h | 2 + .../span_exporter_configuration_visitor.h | 28 ++++ .../span_processor_configuration.h | 2 + .../span_processor_configuration_visitor.h | 28 ++++ .../zipkin_span_exporter_configuration.h | 6 + .../opentelemetry/sdk/init/sdk_builder.h | 29 ++++ .../configuration/configuration_factory.cc | 2 +- sdk/src/init/sdk_builder.cc | 148 +++++++++++++++++- 13 files changed, 323 insertions(+), 2 deletions(-) create mode 100644 sdk/include/opentelemetry/sdk/configuration/extension_span_exporter_configuration.h create mode 100644 sdk/include/opentelemetry/sdk/configuration/extension_span_processor_configuration.h create mode 100644 sdk/include/opentelemetry/sdk/configuration/span_exporter_configuration_visitor.h create mode 100644 sdk/include/opentelemetry/sdk/configuration/span_processor_configuration_visitor.h diff --git a/sdk/include/opentelemetry/sdk/configuration/batch_span_processor_configuration.h b/sdk/include/opentelemetry/sdk/configuration/batch_span_processor_configuration.h index c64f6ab529..cff399b2e6 100644 --- a/sdk/include/opentelemetry/sdk/configuration/batch_span_processor_configuration.h +++ b/sdk/include/opentelemetry/sdk/configuration/batch_span_processor_configuration.h @@ -5,6 +5,7 @@ #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 @@ -16,6 +17,11 @@ namespace configuration class BatchSpanProcessorConfiguration : public SpanProcessorConfiguration { public: + void Accept(SpanProcessorConfigurationVisitor *visitor) const override + { + visitor->VisitBatch(this); + } + size_t schedule_delay; size_t export_timeout; size_t max_queue_size; 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..3d5c244a0c --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/extension_span_exporter_configuration.h @@ -0,0 +1,31 @@ +// 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: + 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..49733f35f5 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/extension_span_processor_configuration.h @@ -0,0 +1,31 @@ +// 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: + 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/otlp_span_exporter_configuration.h b/sdk/include/opentelemetry/sdk/configuration/otlp_span_exporter_configuration.h index 5217ae4fe5..90a4b7c7d3 100644 --- a/sdk/include/opentelemetry/sdk/configuration/otlp_span_exporter_configuration.h +++ b/sdk/include/opentelemetry/sdk/configuration/otlp_span_exporter_configuration.h @@ -5,6 +5,7 @@ #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 @@ -16,6 +17,11 @@ namespace configuration class OtlpSpanExporterConfiguration : public SpanExporterConfiguration { public: + void Accept(SpanExporterConfigurationVisitor *visitor) const override + { + visitor->VisitOtlp(this); + } + std::string protocol; std::string endpoint; std::string certificate; diff --git a/sdk/include/opentelemetry/sdk/configuration/simple_span_processor_configuration.h b/sdk/include/opentelemetry/sdk/configuration/simple_span_processor_configuration.h index 12d037f887..9204a9f7d2 100644 --- a/sdk/include/opentelemetry/sdk/configuration/simple_span_processor_configuration.h +++ b/sdk/include/opentelemetry/sdk/configuration/simple_span_processor_configuration.h @@ -4,6 +4,7 @@ #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 @@ -15,6 +16,11 @@ namespace configuration class SimpleSpanProcessorConfiguration : public SpanProcessorConfiguration { public: + void Accept(SpanProcessorConfigurationVisitor *visitor) const override + { + visitor->VisitSimple(this); + } + std::unique_ptr exporter; }; diff --git a/sdk/include/opentelemetry/sdk/configuration/span_exporter_configuration.h b/sdk/include/opentelemetry/sdk/configuration/span_exporter_configuration.h index 89e4646770..9e3e0e41b0 100644 --- a/sdk/include/opentelemetry/sdk/configuration/span_exporter_configuration.h +++ b/sdk/include/opentelemetry/sdk/configuration/span_exporter_configuration.h @@ -10,10 +10,12 @@ namespace sdk { namespace configuration { +class SpanExporterConfigurationVisitor; class SpanExporterConfiguration { public: + virtual void Accept(SpanExporterConfigurationVisitor *visitor) const = 0; }; } // namespace configuration 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..955b8a3c23 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/span_exporter_configuration_visitor.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 OtlpSpanExporterConfiguration; +class ZipkinSpanExporterConfiguration; +class ExtensionSpanExporterConfiguration; + +class SpanExporterConfigurationVisitor +{ +public: + virtual void VisitOtlp(const OtlpSpanExporterConfiguration *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_processor_configuration.h b/sdk/include/opentelemetry/sdk/configuration/span_processor_configuration.h index 7df54cf71b..58a1204e68 100644 --- a/sdk/include/opentelemetry/sdk/configuration/span_processor_configuration.h +++ b/sdk/include/opentelemetry/sdk/configuration/span_processor_configuration.h @@ -10,10 +10,12 @@ namespace sdk { namespace configuration { +class SpanProcessorConfigurationVisitor; class SpanProcessorConfiguration { public: + virtual void Accept(SpanProcessorConfigurationVisitor *visitor) const = 0; }; } // namespace configuration 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..df174cd518 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/span_processor_configuration_visitor.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 BatchSpanProcessorConfiguration; +class SimpleSpanProcessorConfiguration; +class ExtensionSpanProcessorConfiguration; + +class SpanProcessorConfigurationVisitor +{ +public: + 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/zipkin_span_exporter_configuration.h b/sdk/include/opentelemetry/sdk/configuration/zipkin_span_exporter_configuration.h index 6b1cd72dae..21f40ba67e 100644 --- a/sdk/include/opentelemetry/sdk/configuration/zipkin_span_exporter_configuration.h +++ b/sdk/include/opentelemetry/sdk/configuration/zipkin_span_exporter_configuration.h @@ -4,6 +4,7 @@ #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 @@ -15,6 +16,11 @@ namespace configuration class ZipkinSpanExporterConfiguration : public SpanExporterConfiguration { public: + void Accept(SpanExporterConfigurationVisitor *visitor) const override + { + visitor->VisitZipkin(this); + } + std::string endpoint; size_t timeout; }; diff --git a/sdk/include/opentelemetry/sdk/init/sdk_builder.h b/sdk/include/opentelemetry/sdk/init/sdk_builder.h index fa1b1d4887..3613ceb96f 100644 --- a/sdk/include/opentelemetry/sdk/init/sdk_builder.h +++ b/sdk/include/opentelemetry/sdk/init/sdk_builder.h @@ -4,7 +4,15 @@ #pragma once #include "opentelemetry/sdk/configuration/always_off_sampler_configuration.h" +#include "opentelemetry/sdk/configuration/batch_span_processor_configuration.h" #include "opentelemetry/sdk/configuration/configuration.h" +#include "opentelemetry/sdk/configuration/extension_span_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/extension_span_processor_configuration.h" +#include "opentelemetry/sdk/configuration/otlp_span_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/trace/exporter.h" #include "opentelemetry/sdk/trace/processor.h" #include "opentelemetry/sdk/trace/sampler.h" #include "opentelemetry/trace/tracer_provider.h" @@ -40,6 +48,27 @@ class SdkBuilder static std::unique_ptr CreateSampler( const std::unique_ptr &model); + static std::unique_ptr CreateOtlpSpanExporter( + const opentelemetry::sdk::configuration::OtlpSpanExporterConfiguration *model); + + static std::unique_ptr CreateZipkinSpanExporter( + const opentelemetry::sdk::configuration::ZipkinSpanExporterConfiguration *model); + + static std::unique_ptr CreateExtensionSpanExporter( + const opentelemetry::sdk::configuration::ExtensionSpanExporterConfiguration *model); + + static std::unique_ptr CreateSpanExporter( + const std::unique_ptr &model); + + static std::unique_ptr CreateBatchSpanProcessor( + const opentelemetry::sdk::configuration::BatchSpanProcessorConfiguration *model); + + static std::unique_ptr CreateSimpleSpanProcessor( + const opentelemetry::sdk::configuration::SimpleSpanProcessorConfiguration *model); + + static std::unique_ptr CreateExtensionSpanProcessor( + const opentelemetry::sdk::configuration::ExtensionSpanProcessorConfiguration *model); + static std::unique_ptr CreateProcessor( const std::unique_ptr &model); diff --git a/sdk/src/configuration/configuration_factory.cc b/sdk/src/configuration/configuration_factory.cc index 199c646030..120d856030 100644 --- a/sdk/src/configuration/configuration_factory.cc +++ b/sdk/src/configuration/configuration_factory.cc @@ -528,7 +528,7 @@ std::unique_ptr ConfigurationFactory::ParseFile(std::string filen conf = ConfigurationFactory::Parse(in); } - return Parse(in); + return conf; } std::unique_ptr ConfigurationFactory::ParseString(std::string content) diff --git a/sdk/src/init/sdk_builder.cc b/sdk/src/init/sdk_builder.cc index 8b7d99ddb3..9f4b6744f3 100644 --- a/sdk/src/init/sdk_builder.cc +++ b/sdk/src/init/sdk_builder.cc @@ -15,17 +15,22 @@ #include "opentelemetry/sdk/configuration/parent_based_sampler_configuration.h" #include "opentelemetry/sdk/configuration/sampler_configuration_visitor.h" #include "opentelemetry/sdk/configuration/simple_span_processor_configuration.h" +#include "opentelemetry/sdk/configuration/span_exporter_configuration_visitor.h" +#include "opentelemetry/sdk/configuration/span_processor_configuration_visitor.h" #include "opentelemetry/sdk/configuration/trace_id_ratio_based_sampler_configuration.h" #include "opentelemetry/sdk/configuration/yaml_document.h" #include "opentelemetry/sdk/configuration/zipkin_span_exporter_configuration.h" #include "opentelemetry/sdk/init/configured_sdk.h" #include "opentelemetry/sdk/init/sdk_builder.h" +#include "opentelemetry/sdk/trace/batch_span_processor_factory.h" +#include "opentelemetry/sdk/trace/batch_span_processor_options.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_factory.h" #include "opentelemetry/version.h" @@ -78,6 +83,56 @@ class SamplerBuilder : public opentelemetry::sdk::configuration::SamplerConfigur std::unique_ptr sampler; }; +class SpanProcessorBuilder + : public opentelemetry::sdk::configuration::SpanProcessorConfigurationVisitor +{ +public: + void VisitBatch( + const opentelemetry::sdk::configuration::BatchSpanProcessorConfiguration *model) override + { + processor = SdkBuilder::CreateBatchSpanProcessor(model); + } + + void VisitSimple( + const opentelemetry::sdk::configuration::SimpleSpanProcessorConfiguration *model) override + { + processor = SdkBuilder::CreateSimpleSpanProcessor(model); + } + + void VisitExtension( + const opentelemetry::sdk::configuration::ExtensionSpanProcessorConfiguration *model) override + { + processor = SdkBuilder::CreateExtensionSpanProcessor(model); + } + + std::unique_ptr processor; +}; + +class SpanExporterBuilder + : public opentelemetry::sdk::configuration::SpanExporterConfigurationVisitor +{ +public: + void VisitOtlp( + const opentelemetry::sdk::configuration::OtlpSpanExporterConfiguration *model) override + { + exporter = SdkBuilder::CreateOtlpSpanExporter(model); + } + + void VisitZipkin( + const opentelemetry::sdk::configuration::ZipkinSpanExporterConfiguration *model) override + { + exporter = SdkBuilder::CreateZipkinSpanExporter(model); + } + + void VisitExtension( + const opentelemetry::sdk::configuration::ExtensionSpanExporterConfiguration *model) override + { + exporter = SdkBuilder::CreateExtensionSpanExporter(model); + } + + std::unique_ptr exporter; +}; + std::unique_ptr SdkBuilder::CreateAlwaysOffSampler( const opentelemetry::sdk::configuration::AlwaysOffSamplerConfiguration *model) { @@ -158,6 +213,95 @@ std::unique_ptr SdkBuilder::CreateSampler( return sdk; } +std::unique_ptr SdkBuilder::CreateOtlpSpanExporter( + const opentelemetry::sdk::configuration::OtlpSpanExporterConfiguration *model) +{ + std::unique_ptr sdk; + + OTEL_INTERNAL_LOG_ERROR("CreateOtlpSpanExporter: FIXME"); + + return sdk; +} + +std::unique_ptr SdkBuilder::CreateZipkinSpanExporter( + const opentelemetry::sdk::configuration::ZipkinSpanExporterConfiguration *model) +{ + std::unique_ptr sdk; + + OTEL_INTERNAL_LOG_ERROR("CreateZipkinSpanExporter: FIXME"); + + return sdk; +} + +std::unique_ptr SdkBuilder::CreateExtensionSpanExporter( + const opentelemetry::sdk::configuration::ExtensionSpanExporterConfiguration *model) +{ + std::unique_ptr sdk; + + OTEL_INTERNAL_LOG_ERROR("CreateExtensionSpanExporter: FIXME"); + + return sdk; +} + +std::unique_ptr SdkBuilder::CreateSpanExporter( + const std::unique_ptr &model) +{ + std::unique_ptr sdk; + + OTEL_INTERNAL_LOG_ERROR("CreateSpanExporter: FIXME"); + + SpanExporterBuilder builder; + model->Accept(&builder); + sdk = std::move(builder.exporter); + + return sdk; +} + +std::unique_ptr SdkBuilder::CreateBatchSpanProcessor( + const opentelemetry::sdk::configuration::BatchSpanProcessorConfiguration *model) +{ + 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); + + OTEL_INTERNAL_LOG_ERROR("CreateBatchSpanProcessor: FIXME"); + + // sdk = opentelemetry::sdk::trace::BatchSpanProcessorFactory::Create(exporter_sdk, options); + return sdk; +} + +std::unique_ptr SdkBuilder::CreateSimpleSpanProcessor( + const opentelemetry::sdk::configuration::SimpleSpanProcessorConfiguration *model) +{ + 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) +{ + std::unique_ptr sdk; + + OTEL_INTERNAL_LOG_ERROR("CreateExtensionSpanProcessor: FIXME"); + + return sdk; +} + std::unique_ptr SdkBuilder::CreateProcessor( const std::unique_ptr &model) { @@ -165,7 +309,9 @@ std::unique_ptr SdkBuilder::CreateProc OTEL_INTERNAL_LOG_ERROR("CreateProcessor: FIXME"); - // sdk = xxx; + SpanProcessorBuilder builder; + model->Accept(&builder); + sdk = std::move(builder.processor); return sdk; }