From 3af512e0ed3fd9762ba4d45debba2f6015858fdc Mon Sep 17 00:00:00 2001 From: Ehsan Saei <71217171+esigo@users.noreply.github.com> Date: Mon, 1 Aug 2022 23:02:54 +0200 Subject: [PATCH 1/2] Add configuration options for Aggregation creation (#1513) --- .../common/metrics_foo_library/foo_library.cc | 6 ++- examples/metrics_simple/metrics_ostream.cc | 10 +++- .../metrics/aggregation/aggregation_config.h | 29 ++++++++++++ .../metrics/aggregation/default_aggregation.h | 23 ++++++--- .../aggregation/histogram_aggregation.h | 6 ++- sdk/include/opentelemetry/sdk/metrics/meter.h | 6 +-- .../sdk/metrics/state/async_metric_storage.h | 4 +- .../sdk/metrics/state/sync_metric_storage.h | 6 ++- .../metrics/state/temporal_metric_storage.h | 6 ++- .../opentelemetry/sdk/metrics/view/view.h | 14 +++++- .../aggregation/histogram_aggregation.cc | 26 ++++++++-- sdk/src/metrics/meter.cc | 2 +- .../metrics/state/temporal_metric_storage.cc | 47 +++++++++++-------- sdk/test/metrics/aggregation_test.cc | 30 ++++++++++++ sdk/test/metrics/async_metric_storage_test.cc | 11 +++-- sdk/test/metrics/sync_metric_storage_test.cc | 10 ++-- 16 files changed, 182 insertions(+), 54 deletions(-) create mode 100644 sdk/include/opentelemetry/sdk/metrics/aggregation/aggregation_config.h diff --git a/examples/common/metrics_foo_library/foo_library.cc b/examples/common/metrics_foo_library/foo_library.cc index 2fcbd660e0..c46276833c 100644 --- a/examples/common/metrics_foo_library/foo_library.cc +++ b/examples/common/metrics_foo_library/foo_library.cc @@ -5,10 +5,12 @@ # include "foo_library.h" # include # include +# include # include # include # include "opentelemetry/context/context.h" # include "opentelemetry/metrics/provider.h" +# include "opentelemetry/nostd/shared_ptr.h" namespace nostd = opentelemetry::nostd; namespace metrics_api = opentelemetry::metrics; @@ -72,8 +74,8 @@ void foo_library::histogram_example(const std::string &name) std::string histogram_name = name + "_histogram"; auto provider = metrics_api::Provider::GetMeterProvider(); nostd::shared_ptr meter = provider->GetMeter(name, "1.2.0"); - auto histogram_counter = meter->CreateDoubleHistogram(histogram_name); - auto context = opentelemetry::context::Context{}; + auto histogram_counter = meter->CreateDoubleHistogram(histogram_name, "des", "unit"); + auto context = opentelemetry::context::Context{}; while (true) { double val = (rand() % 700) + 1.1; diff --git a/examples/metrics_simple/metrics_ostream.cc b/examples/metrics_simple/metrics_ostream.cc index 585856f91f..669362830b 100644 --- a/examples/metrics_simple/metrics_ostream.cc +++ b/examples/metrics_simple/metrics_ostream.cc @@ -72,8 +72,14 @@ void initMetrics(const std::string &name) new metric_sdk::InstrumentSelector(metric_sdk::InstrumentType::kHistogram, histogram_name)}; std::unique_ptr histogram_meter_selector{ new metric_sdk::MeterSelector(name, version, schema)}; - std::unique_ptr histogram_view{ - new metric_sdk::View{name, "description", metric_sdk::AggregationType::kHistogram}}; + std::shared_ptr aggregation_config{ + new opentelemetry::sdk::metrics::HistogramAggregationConfig}; + static_cast *>( + aggregation_config.get()) + ->boundaries_ = + std::list{0.0, 50.0, 100.0, 250.0, 500.0, 750.0, 1000.0, 2500.0, 5000.0, 10000.0}; + std::unique_ptr histogram_view{new metric_sdk::View{ + name, "description", metric_sdk::AggregationType::kHistogram, aggregation_config}}; p->AddView(std::move(histogram_instrument_selector), std::move(histogram_meter_selector), std::move(histogram_view)); metrics_api::Provider::SetMeterProvider(provider); diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/aggregation_config.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/aggregation_config.h new file mode 100644 index 0000000000..bd2fe55c5a --- /dev/null +++ b/sdk/include/opentelemetry/sdk/metrics/aggregation/aggregation_config.h @@ -0,0 +1,29 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#ifndef ENABLE_METRICS_PREVIEW +# include +# include "opentelemetry/version.h" +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ +class AggregationConfig +{ +public: + virtual ~AggregationConfig() = default; +}; + +template +class HistogramAggregationConfig : public AggregationConfig +{ +public: + std::list boundaries_; +}; +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE + +#endif // ENABLE_METRICS_PREVIEW \ No newline at end of file diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h index 887e1beb92..98221d9b46 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h @@ -3,12 +3,15 @@ #pragma once #ifndef ENABLE_METRICS_PREVIEW +# include # include "opentelemetry/common/spin_lock_mutex.h" # include "opentelemetry/sdk/metrics/aggregation/aggregation.h" +# include "opentelemetry/sdk/metrics/aggregation/aggregation_config.h" # include "opentelemetry/sdk/metrics/aggregation/drop_aggregation.h" # include "opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h" # include "opentelemetry/sdk/metrics/aggregation/lastvalue_aggregation.h" # include "opentelemetry/sdk/metrics/aggregation/sum_aggregation.h" +# include "opentelemetry/sdk/metrics/data/point_data.h" # include "opentelemetry/sdk/metrics/instruments.h" # include @@ -18,11 +21,13 @@ namespace sdk { namespace metrics { + class DefaultAggregation { public: static std::unique_ptr CreateAggregation( - const opentelemetry::sdk::metrics::InstrumentDescriptor &instrument_descriptor) + const opentelemetry::sdk::metrics::InstrumentDescriptor &instrument_descriptor, + const opentelemetry::sdk::metrics::AggregationConfig *aggregation_config) { switch (instrument_descriptor.type_) { @@ -34,11 +39,17 @@ class DefaultAggregation ? std::move(std::unique_ptr(new LongSumAggregation())) : std::move(std::unique_ptr(new DoubleSumAggregation())); break; - case InstrumentType::kHistogram: + case InstrumentType::kHistogram: { return (instrument_descriptor.value_type_ == InstrumentValueType::kLong) - ? std::move(std::unique_ptr(new LongHistogramAggregation())) - : std::move(std::unique_ptr(new DoubleHistogramAggregation())); + ? std::move(std::unique_ptr(new LongHistogramAggregation( + static_cast< + const opentelemetry::sdk::metrics::HistogramAggregationConfig *>( + aggregation_config)))) + : std::move(std::unique_ptr(new DoubleHistogramAggregation( + static_cast *>(aggregation_config)))); break; + } case InstrumentType::kObservableGauge: return (instrument_descriptor.value_type_ == InstrumentValueType::kLong) ? std::move(std::unique_ptr(new LongLastValueAggregation())) @@ -88,7 +99,7 @@ class DefaultAggregation } break; default: - return DefaultAggregation::CreateAggregation(instrument_descriptor); + return DefaultAggregation::CreateAggregation(instrument_descriptor, nullptr); } } @@ -135,7 +146,7 @@ class DefaultAggregation new DoubleSumAggregation(nostd::get(point_data))); } default: - return DefaultAggregation::CreateAggregation(instrument_descriptor); + return DefaultAggregation::CreateAggregation(instrument_descriptor, nullptr); } } }; diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h index e2a55fba58..e648a6a4bc 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h @@ -5,6 +5,7 @@ #ifndef ENABLE_METRICS_PREVIEW # include "opentelemetry/common/spin_lock_mutex.h" # include "opentelemetry/sdk/metrics/aggregation/aggregation.h" +# include "opentelemetry/sdk/metrics/aggregation/aggregation_config.h" # include @@ -17,7 +18,7 @@ namespace metrics class LongHistogramAggregation : public Aggregation { public: - LongHistogramAggregation(); + LongHistogramAggregation(const HistogramAggregationConfig *aggregation_config = nullptr); LongHistogramAggregation(HistogramPointData &&); LongHistogramAggregation(const HistogramPointData &); @@ -46,7 +47,8 @@ class LongHistogramAggregation : public Aggregation class DoubleHistogramAggregation : public Aggregation { public: - DoubleHistogramAggregation(); + DoubleHistogramAggregation( + const HistogramAggregationConfig *aggregation_config = nullptr); DoubleHistogramAggregation(HistogramPointData &&); DoubleHistogramAggregation(const HistogramPointData &); diff --git a/sdk/include/opentelemetry/sdk/metrics/meter.h b/sdk/include/opentelemetry/sdk/metrics/meter.h index 22608e2b05..d3df60ced0 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter.h @@ -148,9 +148,9 @@ class Meter final : public opentelemetry::metrics::Meter { view_instr_desc.description_ = view.GetDescription(); } - auto storage = std::shared_ptr>( - new AsyncMetricStorage(view_instr_desc, view.GetAggregationType(), callback, - &view.GetAttributesProcessor(), state)); + auto storage = std::shared_ptr>(new AsyncMetricStorage( + view_instr_desc, view.GetAggregationType(), callback, &view.GetAttributesProcessor(), + view.GetAggregationConfig(), state)); storage_registry_[instrument_descriptor.name_] = storage; return true; }); diff --git a/sdk/include/opentelemetry/sdk/metrics/state/async_metric_storage.h b/sdk/include/opentelemetry/sdk/metrics/state/async_metric_storage.h index e5dcbc2738..11e7d83c14 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/async_metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/async_metric_storage.h @@ -3,6 +3,7 @@ #pragma once #ifndef ENABLE_METRICS_PREVIEW +# include "opentelemetry/nostd/shared_ptr.h" # include "opentelemetry/sdk/common/attributemap_hash.h" # include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" # include "opentelemetry/sdk/metrics/instruments.h" @@ -30,6 +31,7 @@ class AsyncMetricStorage : public MetricStorage void (*measurement_callback)(opentelemetry::metrics::ObserverResult &, void *), const AttributesProcessor *attributes_processor, + nostd::shared_ptr aggregation_config, void *state = nullptr) : instrument_descriptor_(instrument_descriptor), aggregation_type_{aggregation_type}, @@ -37,7 +39,7 @@ class AsyncMetricStorage : public MetricStorage attributes_processor_{attributes_processor}, state_{state}, cumulative_hash_map_(new AttributesHashMap()), - temporal_metric_storage_(instrument_descriptor) + temporal_metric_storage_(instrument_descriptor, aggregation_config) {} bool Collect(CollectorHandle *collector, diff --git a/sdk/include/opentelemetry/sdk/metrics/state/sync_metric_storage.h b/sdk/include/opentelemetry/sdk/metrics/state/sync_metric_storage.h index 37f485997c..d547f3699f 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/sync_metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/sync_metric_storage.h @@ -3,6 +3,7 @@ #pragma once #ifndef ENABLE_METRICS_PREVIEW +# include # include "opentelemetry/common/key_value_iterable_view.h" # include "opentelemetry/sdk/common/attributemap_hash.h" # include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" @@ -29,13 +30,14 @@ class SyncMetricStorage : public MetricStorage, public WritableMetricStorage SyncMetricStorage(InstrumentDescriptor instrument_descriptor, const AggregationType aggregation_type, const AttributesProcessor *attributes_processor, - nostd::shared_ptr &&exemplar_reservoir) + nostd::shared_ptr &&exemplar_reservoir, + nostd::shared_ptr aggregation_config) : instrument_descriptor_(instrument_descriptor), aggregation_type_{aggregation_type}, attributes_hashmap_(new AttributesHashMap()), attributes_processor_{attributes_processor}, exemplar_reservoir_(exemplar_reservoir), - temporal_metric_storage_(instrument_descriptor) + temporal_metric_storage_(instrument_descriptor, aggregation_config) { create_default_aggregation_ = [&]() -> std::unique_ptr { diff --git a/sdk/include/opentelemetry/sdk/metrics/state/temporal_metric_storage.h b/sdk/include/opentelemetry/sdk/metrics/state/temporal_metric_storage.h index 16659c14f5..f8a0c36b0f 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/temporal_metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/temporal_metric_storage.h @@ -3,6 +3,8 @@ #pragma once #ifndef ENABLE_METRICS_PREVIEW +# include "opentelemetry/nostd/shared_ptr.h" +# include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" # include "opentelemetry/sdk/metrics/state/attributes_hashmap.h" # include "opentelemetry/sdk/metrics/state/metric_collector.h" @@ -23,7 +25,8 @@ struct LastReportedMetrics class TemporalMetricStorage { public: - TemporalMetricStorage(InstrumentDescriptor instrument_descriptor); + TemporalMetricStorage(InstrumentDescriptor instrument_descriptor, + nostd::shared_ptr aggregation_config); bool buildMetrics(CollectorHandle *collector, nostd::span> collectors, @@ -43,6 +46,7 @@ class TemporalMetricStorage // Lock while building metrics mutable opentelemetry::common::SpinLockMutex lock_; + const nostd::shared_ptr aggregation_config_; }; } // namespace metrics } // namespace sdk diff --git a/sdk/include/opentelemetry/sdk/metrics/view/view.h b/sdk/include/opentelemetry/sdk/metrics/view/view.h index 3cd9f850e1..a7f8edb8fc 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/view.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/view.h @@ -3,7 +3,9 @@ #pragma once #ifndef ENABLE_METRICS_PREVIEW +# include "opentelemetry/nostd/shared_ptr.h" # include "opentelemetry/nostd/string_view.h" +# include "opentelemetry/sdk/metrics/aggregation/aggregation_config.h" # include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" # include "opentelemetry/sdk/metrics/instruments.h" # include "opentelemetry/sdk/metrics/view/attributes_processor.h" @@ -22,14 +24,16 @@ class View { public: View(const std::string &name, - const std::string &description = "", - AggregationType aggregation_type = AggregationType::kDefault, + const std::string &description = "", + AggregationType aggregation_type = AggregationType::kDefault, + std::shared_ptr aggregation_config = std::shared_ptr{}, std::unique_ptr attributes_processor = std::unique_ptr( new opentelemetry::sdk::metrics::DefaultAttributesProcessor())) : name_(name), description_(description), aggregation_type_{aggregation_type}, + aggregation_config_{aggregation_config}, attributes_processor_{std::move(attributes_processor)} {} @@ -39,6 +43,11 @@ class View virtual AggregationType GetAggregationType() const noexcept { return aggregation_type_; } + virtual nostd::shared_ptr GetAggregationConfig() const noexcept + { + return aggregation_config_; + } + virtual const opentelemetry::sdk::metrics::AttributesProcessor &GetAttributesProcessor() const noexcept { @@ -49,6 +58,7 @@ class View std::string name_; std::string description_; AggregationType aggregation_type_; + nostd::shared_ptr aggregation_config_; std::unique_ptr attributes_processor_; }; } // namespace metrics diff --git a/sdk/src/metrics/aggregation/histogram_aggregation.cc b/sdk/src/metrics/aggregation/histogram_aggregation.cc index aa2be74713..79f0714b54 100644 --- a/sdk/src/metrics/aggregation/histogram_aggregation.cc +++ b/sdk/src/metrics/aggregation/histogram_aggregation.cc @@ -12,9 +12,17 @@ namespace sdk namespace metrics { -LongHistogramAggregation::LongHistogramAggregation() +LongHistogramAggregation::LongHistogramAggregation( + const HistogramAggregationConfig *aggregation_config) { - point_data_.boundaries_ = std::list{0l, 5l, 10l, 25l, 50l, 75l, 100l, 250l, 500l, 1000l}; + if (aggregation_config && aggregation_config->boundaries_.size()) + { + point_data_.boundaries_ = aggregation_config->boundaries_; + } + else + { + point_data_.boundaries_ = std::list{0l, 5l, 10l, 25l, 50l, 75l, 100l, 250l, 500l, 1000l}; + } point_data_.counts_ = std::vector(nostd::get>(point_data_.boundaries_).size() + 1, 0); point_data_.sum_ = 0l; @@ -73,10 +81,18 @@ PointType LongHistogramAggregation::ToPoint() const noexcept return point_data_; } -DoubleHistogramAggregation::DoubleHistogramAggregation() +DoubleHistogramAggregation::DoubleHistogramAggregation( + const HistogramAggregationConfig *aggregation_config) { - point_data_.boundaries_ = - std::list{0.0, 5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 250.0, 500.0, 1000.0}; + if (aggregation_config && aggregation_config->boundaries_.size()) + { + point_data_.boundaries_ = aggregation_config->boundaries_; + } + else + { + point_data_.boundaries_ = + std::list{0.0, 5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 250.0, 500.0, 1000.0}; + } point_data_.counts_ = std::vector(nostd::get>(point_data_.boundaries_).size() + 1, 0); point_data_.sum_ = 0.0; diff --git a/sdk/src/metrics/meter.cc b/sdk/src/metrics/meter.cc index d17b61f120..551d87b2bc 100644 --- a/sdk/src/metrics/meter.cc +++ b/sdk/src/metrics/meter.cc @@ -217,7 +217,7 @@ std::unique_ptr Meter::RegisterMetricStorage( } auto storage = std::shared_ptr(new SyncMetricStorage( view_instr_desc, view.GetAggregationType(), &view.GetAttributesProcessor(), - NoExemplarReservoir::GetNoExemplarReservoir())); + NoExemplarReservoir::GetNoExemplarReservoir(), view.GetAggregationConfig())); storage_registry_[instrument_descriptor.name_] = storage; auto multi_storage = static_cast(storages.get()); multi_storage->AddStorage(storage); diff --git a/sdk/src/metrics/state/temporal_metric_storage.cc b/sdk/src/metrics/state/temporal_metric_storage.cc index b208695b8a..bee2986f09 100644 --- a/sdk/src/metrics/state/temporal_metric_storage.cc +++ b/sdk/src/metrics/state/temporal_metric_storage.cc @@ -2,9 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 #ifndef ENABLE_METRICS_PREVIEW +# include +# include +# include +# include "opentelemetry/nostd/shared_ptr.h" -# include "opentelemetry/sdk/metrics/state/temporal_metric_storage.h" +# include "opentelemetry/metrics/meter.h" # include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" +# include "opentelemetry/sdk/metrics/state/temporal_metric_storage.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -12,8 +17,10 @@ namespace sdk namespace metrics { -TemporalMetricStorage::TemporalMetricStorage(InstrumentDescriptor instrument_descriptor) - : instrument_descriptor_(instrument_descriptor) +TemporalMetricStorage::TemporalMetricStorage( + InstrumentDescriptor instrument_descriptor, + nostd::shared_ptr aggregation_config) + : instrument_descriptor_(instrument_descriptor), aggregation_config_(aggregation_config) {} bool TemporalMetricStorage::buildMetrics(CollectorHandle *collector, @@ -54,9 +61,9 @@ bool TemporalMetricStorage::buildMetrics(CollectorHandle *collector, } else { - merged_metrics->Set( - attributes, - DefaultAggregation::CreateAggregation(instrument_descriptor_)->Merge(aggregation)); + merged_metrics->Set(attributes, DefaultAggregation::CreateAggregation( + instrument_descriptor_, aggregation_config_.get()) + ->Merge(aggregation)); merged_metrics->GetAllEnteries( [](const MetricAttributes &attr, Aggregation &aggr) { return true; }); } @@ -80,20 +87,20 @@ bool TemporalMetricStorage::buildMetrics(CollectorHandle *collector, if (aggregation_temporarily == AggregationTemporality::kCumulative) { // merge current delta to previous cumulative - last_aggr_hashmap->GetAllEnteries( - [&merged_metrics, this](const MetricAttributes &attributes, Aggregation &aggregation) { - auto agg = merged_metrics->Get(attributes); - if (agg) - { - merged_metrics->Set(attributes, agg->Merge(aggregation)); - } - else - { - merged_metrics->Set(attributes, - DefaultAggregation::CreateAggregation(instrument_descriptor_)); - } - return true; - }); + last_aggr_hashmap->GetAllEnteries([&merged_metrics, this](const MetricAttributes &attributes, + Aggregation &aggregation) { + auto agg = merged_metrics->Get(attributes); + if (agg) + { + merged_metrics->Set(attributes, agg->Merge(aggregation)); + } + else + { + merged_metrics->Set( + attributes, DefaultAggregation::CreateAggregation(instrument_descriptor_, nullptr)); + } + return true; + }); } last_reported_metrics_[collector] = LastReportedMetrics{std::move(merged_metrics), collection_ts}; diff --git a/sdk/test/metrics/aggregation_test.cc b/sdk/test/metrics/aggregation_test.cc index f8051776d1..3fb9d55126 100644 --- a/sdk/test/metrics/aggregation_test.cc +++ b/sdk/test/metrics/aggregation_test.cc @@ -7,6 +7,7 @@ # include "opentelemetry/sdk/metrics/aggregation/lastvalue_aggregation.h" # include "opentelemetry/sdk/metrics/aggregation/sum_aggregation.h" +# include "opentelemetry/nostd/shared_ptr.h" # include "opentelemetry/nostd/variant.h" using namespace opentelemetry::sdk::metrics; @@ -123,6 +124,35 @@ TEST(Aggregation, LongHistogramAggregation) EXPECT_EQ(histogram_data.counts_[7], 1); // aggr2(105) - aggr1(0) } +TEST(Aggregation, LongHistogramAggregationBoundaries) +{ + nostd::shared_ptr> + aggregation_config{new opentelemetry::sdk::metrics::HistogramAggregationConfig}; + std::list user_boundaries = {0, 50, 100, 250, 500, 750, 1000, 2500, 5000, 10000}; + aggregation_config->boundaries_ = user_boundaries; + LongHistogramAggregation aggr{aggregation_config.get()}; + auto data = aggr.ToPoint(); + ASSERT_TRUE(nostd::holds_alternative(data)); + auto histogram_data = nostd::get(data); + ASSERT_TRUE(nostd::holds_alternative>(histogram_data.boundaries_)); + EXPECT_EQ(nostd::get>(histogram_data.boundaries_), user_boundaries); +} + +TEST(Aggregation, DoubleHistogramAggregationBoundaries) +{ + nostd::shared_ptr> + aggregation_config{new opentelemetry::sdk::metrics::HistogramAggregationConfig}; + std::list user_boundaries = {0.0, 50.0, 100.0, 250.0, 500.0, + 750.0, 1000.0, 2500.0, 5000.0, 10000.0}; + aggregation_config->boundaries_ = user_boundaries; + DoubleHistogramAggregation aggr{aggregation_config.get()}; + auto data = aggr.ToPoint(); + ASSERT_TRUE(nostd::holds_alternative(data)); + auto histogram_data = nostd::get(data); + ASSERT_TRUE(nostd::holds_alternative>(histogram_data.boundaries_)); + EXPECT_EQ(nostd::get>(histogram_data.boundaries_), user_boundaries); +} + TEST(Aggregation, DoubleHistogramAggregation) { DoubleHistogramAggregation aggr; diff --git a/sdk/test/metrics/async_metric_storage_test.cc b/sdk/test/metrics/async_metric_storage_test.cc index 8eb55ecd7b..6e2e399e44 100644 --- a/sdk/test/metrics/async_metric_storage_test.cc +++ b/sdk/test/metrics/async_metric_storage_test.cc @@ -4,6 +4,7 @@ #ifndef ENABLE_METRICS_PREVIEW # include "opentelemetry/sdk/metrics/state/async_metric_storage.h" # include "opentelemetry/common/key_value_iterable_view.h" +# include "opentelemetry/nostd/shared_ptr.h" # include "opentelemetry/sdk/metrics/instruments.h" # include "opentelemetry/sdk/metrics/meter_context.h" # include "opentelemetry/sdk/metrics/metric_exporter.h" @@ -20,7 +21,8 @@ using namespace opentelemetry::sdk::resource; using namespace opentelemetry::sdk::metrics; using namespace opentelemetry::common; -using M = std::map; +using M = std::map; +namespace nostd = opentelemetry::nostd; class MockCollectorHandle : public CollectorHandle { @@ -96,9 +98,10 @@ TEST_P(WritableMetricStorageTestFixture, TestAggregation) std::unique_ptr default_attributes_rocessor{ new DefaultAttributesProcessor{}}; - opentelemetry::sdk::metrics::AsyncMetricStorage storage(instr_desc, AggregationType::kSum, - MeasurementFetcher::Fetcher, - default_attributes_rocessor.get()); + opentelemetry::sdk::metrics::AsyncMetricStorage storage( + instr_desc, AggregationType::kSum, MeasurementFetcher::Fetcher, + default_attributes_rocessor.get(), + std::shared_ptr{}); storage.Collect(collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData data) { diff --git a/sdk/test/metrics/sync_metric_storage_test.cc b/sdk/test/metrics/sync_metric_storage_test.cc index 8d4ee99262..cb24ae5178 100644 --- a/sdk/test/metrics/sync_metric_storage_test.cc +++ b/sdk/test/metrics/sync_metric_storage_test.cc @@ -4,6 +4,7 @@ #include #ifndef ENABLE_METRICS_PREVIEW # include "opentelemetry/common/key_value_iterable_view.h" +# include "opentelemetry/nostd/shared_ptr.h" # include "opentelemetry/sdk/metrics/exemplar/no_exemplar_reservoir.h" # include "opentelemetry/sdk/metrics/instruments.h" # include "opentelemetry/sdk/metrics/state/sync_metric_storage.h" @@ -14,7 +15,8 @@ using namespace opentelemetry::sdk::metrics; using namespace opentelemetry::common; -using M = std::map; +using M = std::map; +namespace nostd = opentelemetry::nostd; class MockCollectorHandle : public CollectorHandle { @@ -45,7 +47,8 @@ TEST_P(WritableMetricStorageTestFixture, LongSumAggregation) new DefaultAttributesProcessor{}}; opentelemetry::sdk::metrics::SyncMetricStorage storage( instr_desc, AggregationType::kSum, default_attributes_processor.get(), - NoExemplarReservoir::GetNoExemplarReservoir()); + NoExemplarReservoir::GetNoExemplarReservoir(), + std::shared_ptr{}); storage.RecordLong(10l, KeyValueIterableView>(attributes_get), opentelemetry::context::Context{}); @@ -153,7 +156,8 @@ TEST_P(WritableMetricStorageTestFixture, DoubleSumAggregation) new DefaultAttributesProcessor{}}; opentelemetry::sdk::metrics::SyncMetricStorage storage( instr_desc, AggregationType::kSum, default_attributes_processor.get(), - NoExemplarReservoir::GetNoExemplarReservoir()); + NoExemplarReservoir::GetNoExemplarReservoir(), + std::shared_ptr{}); storage.RecordDouble(10.0, KeyValueIterableView>(attributes_get), From 70fd2dcb88fbeeb205fd1ebcd36b4c0d5bc3a5e9 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 2 Aug 2022 09:17:49 +0200 Subject: [PATCH 2/2] Fix log sdk builder (#1486) (#1524) --- CHANGELOG.md | 2 + examples/otlp/grpc_log_main.cc | 21 +++--- examples/otlp/http_log_main.cc | 19 +++--- exporters/otlp/BUILD | 37 +++++++++++ exporters/otlp/CMakeLists.txt | 32 +++++++-- .../otlp/otlp_grpc_log_exporter_factory.h | 39 +++++++++++ .../exporters/otlp/otlp_http_log_exporter.h | 42 +----------- .../otlp/otlp_http_log_exporter_factory.h | 39 +++++++++++ .../otlp/otlp_http_log_exporter_options.h | 66 +++++++++++++++++++ .../src/otlp_grpc_log_exporter_factory.cc | 35 ++++++++++ .../src/otlp_http_log_exporter_factory.cc | 33 ++++++++++ .../otlp_grpc_log_exporter_factory_test.cc | 40 +++++++++++ .../otlp_http_log_exporter_factory_test.cc | 48 ++++++++++++++ .../sdk/logs/batch_log_processor.h | 22 +------ .../sdk/logs/batch_log_processor_factory.h | 35 ++++++++++ .../sdk/logs/batch_log_processor_options.h | 44 +++++++++++++ .../sdk/logs/logger_context_factory.h | 43 ++++++++++++ .../sdk/logs/logger_provider_factory.h | 66 +++++++++++++++++++ .../sdk/logs/multi_log_processor_factory.h | 33 ++++++++++ .../sdk/logs/simple_log_processor_factory.h | 32 +++++++++ .../sdk/trace/tracer_context_factory.h | 8 +-- sdk/src/logs/CMakeLists.txt | 5 ++ sdk/src/logs/batch_log_processor_factory.cc | 26 ++++++++ sdk/src/logs/logger_context_factory.cc | 36 ++++++++++ sdk/src/logs/logger_provider_factory.cc | 58 ++++++++++++++++ sdk/src/logs/multi_log_processor_factory.cc | 30 +++++++++ sdk/src/logs/simple_log_processor_factory.cc | 25 +++++++ sdk/src/trace/tracer_context_factory.cc | 16 ++--- 28 files changed, 831 insertions(+), 101 deletions(-) create mode 100644 exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_exporter_factory.h create mode 100644 exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter_factory.h create mode 100644 exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter_options.h create mode 100644 exporters/otlp/src/otlp_grpc_log_exporter_factory.cc create mode 100644 exporters/otlp/src/otlp_http_log_exporter_factory.cc create mode 100644 exporters/otlp/test/otlp_grpc_log_exporter_factory_test.cc create mode 100644 exporters/otlp/test/otlp_http_log_exporter_factory_test.cc create mode 100644 sdk/include/opentelemetry/sdk/logs/batch_log_processor_factory.h create mode 100644 sdk/include/opentelemetry/sdk/logs/batch_log_processor_options.h create mode 100644 sdk/include/opentelemetry/sdk/logs/logger_context_factory.h create mode 100644 sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h create mode 100644 sdk/include/opentelemetry/sdk/logs/multi_log_processor_factory.h create mode 100644 sdk/include/opentelemetry/sdk/logs/simple_log_processor_factory.h create mode 100644 sdk/src/logs/batch_log_processor_factory.cc create mode 100644 sdk/src/logs/logger_context_factory.cc create mode 100644 sdk/src/logs/logger_provider_factory.cc create mode 100644 sdk/src/logs/multi_log_processor_factory.cc create mode 100644 sdk/src/logs/simple_log_processor_factory.cc diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cb69faa0a..40b13e0dfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ Increment the: ## [Unreleased] +* [LOG SDK] Add log sdk builders (#1486) [#1524](https://github.com/open-telemetry/opentelemetry-cpp/pull/1524) + ## [1.5.0] 2022-07-29 * [EXPORTER BUILD] Add resources to dep list of prometheus exporter test [#1527](https://github.com/open-telemetry/opentelemetry-cpp/pull/1527) diff --git a/examples/otlp/grpc_log_main.cc b/examples/otlp/grpc_log_main.cc index 980b18e50a..b8f7441b71 100644 --- a/examples/otlp/grpc_log_main.cc +++ b/examples/otlp/grpc_log_main.cc @@ -2,15 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 #ifdef ENABLE_LOGS_PREVIEW -// Make sure to include GRPC exporter first because otherwise Abseil may create -// ambiguity with `nostd::variant`. See issue: -// https://github.com/open-telemetry/opentelemetry-cpp/issues/880 -# include "opentelemetry/exporters/otlp/otlp_grpc_log_exporter.h" - # include "opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h" +# include "opentelemetry/exporters/otlp/otlp_grpc_log_exporter_factory.h" # include "opentelemetry/logs/provider.h" -# include "opentelemetry/sdk/logs/logger_provider.h" -# include "opentelemetry/sdk/logs/simple_log_processor.h" +# include "opentelemetry/sdk/logs/logger_provider_factory.h" +# include "opentelemetry/sdk/logs/simple_log_processor_factory.h" # include "opentelemetry/sdk/trace/simple_processor_factory.h" # include "opentelemetry/sdk/trace/tracer_provider_factory.h" # include "opentelemetry/trace/provider.h" @@ -47,12 +43,11 @@ void InitTracer() void InitLogger() { // Create OTLP exporter instance - auto exporter = std::unique_ptr(new otlp::OtlpGrpcLogExporter(opts)); - auto sdkProvider = std::shared_ptr( - new logs_sdk::LoggerProvider(std::unique_ptr( - new logs_sdk::SimpleLogProcessor(std::move(exporter))))); - auto apiProvider = nostd::shared_ptr(sdkProvider); - auto provider = nostd::shared_ptr(apiProvider); + auto exporter = otlp::OtlpGrpcLogExporterFactory::Create(opts); + auto processor = logs_sdk::SimpleLogProcessorFactory::Create(std::move(exporter)); + nostd::shared_ptr provider( + logs_sdk::LoggerProviderFactory::Create(std::move(processor))); + opentelemetry::logs::Provider::SetLoggerProvider(provider); } } // namespace diff --git a/examples/otlp/http_log_main.cc b/examples/otlp/http_log_main.cc index 1789f542da..a764252aac 100644 --- a/examples/otlp/http_log_main.cc +++ b/examples/otlp/http_log_main.cc @@ -3,10 +3,11 @@ #ifdef ENABLE_LOGS_PREVIEW # include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.h" -# include "opentelemetry/exporters/otlp/otlp_http_log_exporter.h" +# include "opentelemetry/exporters/otlp/otlp_http_log_exporter_factory.h" +# include "opentelemetry/exporters/otlp/otlp_http_log_exporter_options.h" # include "opentelemetry/logs/provider.h" -# include "opentelemetry/sdk/logs/logger_provider.h" -# include "opentelemetry/sdk/logs/simple_log_processor.h" +# include "opentelemetry/sdk/logs/logger_provider_factory.h" +# include "opentelemetry/sdk/logs/simple_log_processor_factory.h" # include "opentelemetry/sdk/trace/simple_processor_factory.h" # include "opentelemetry/sdk/trace/tracer_provider_factory.h" # include "opentelemetry/trace/provider.h" @@ -46,13 +47,11 @@ void InitLogger() { logger_opts.console_debug = true; // Create OTLP exporter instance - auto exporter = - std::unique_ptr(new otlp::OtlpHttpLogExporter(logger_opts)); - auto sdkProvider = std::shared_ptr( - new logs_sdk::LoggerProvider(std::unique_ptr( - new logs_sdk::SimpleLogProcessor(std::move(exporter))))); - auto apiProvider = nostd::shared_ptr(sdkProvider); - auto provider = nostd::shared_ptr(apiProvider); + auto exporter = otlp::OtlpHttpLogExporterFactory::Create(logger_opts); + auto processor = logs_sdk::SimpleLogProcessorFactory::Create(std::move(exporter)); + std::shared_ptr provider = + logs_sdk::LoggerProviderFactory::Create(std::move(processor)); + opentelemetry::logs::Provider::SetLoggerProvider(provider); } } // namespace diff --git a/exporters/otlp/BUILD b/exporters/otlp/BUILD index 1619a010ca..c4270f47ed 100644 --- a/exporters/otlp/BUILD +++ b/exporters/otlp/BUILD @@ -144,10 +144,13 @@ cc_library( name = "otlp_http_log_exporter", srcs = [ "src/otlp_http_log_exporter.cc", + "src/otlp_http_log_exporter_factory.cc", ], hdrs = [ "include/opentelemetry/exporters/otlp/otlp_environment.h", "include/opentelemetry/exporters/otlp/otlp_http_log_exporter.h", + "include/opentelemetry/exporters/otlp/otlp_http_log_exporter_factory.h", + "include/opentelemetry/exporters/otlp/otlp_http_log_exporter_options.h", "include/opentelemetry/exporters/otlp/protobuf_include_prefix.h", "include/opentelemetry/exporters/otlp/protobuf_include_suffix.h", ], @@ -192,11 +195,13 @@ cc_library( name = "otlp_grpc_log_exporter", srcs = [ "src/otlp_grpc_log_exporter.cc", + "src/otlp_grpc_log_exporter_factory.cc", ], hdrs = [ "include/opentelemetry/exporters/otlp/otlp_environment.h", "include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h", "include/opentelemetry/exporters/otlp/otlp_grpc_log_exporter.h", + "include/opentelemetry/exporters/otlp/otlp_grpc_log_exporter_factory.h", "include/opentelemetry/exporters/otlp/protobuf_include_prefix.h", "include/opentelemetry/exporters/otlp/protobuf_include_suffix.h", ], @@ -324,6 +329,22 @@ cc_test( ], ) +cc_test( + name = "otlp_http_log_exporter_factory_test", + srcs = ["test/otlp_http_log_exporter_factory_test.cc"], + tags = [ + "otlp", + "otlp_http_log", + "test", + ], + deps = [ + ":otlp_http_log_exporter", + "//api", + "//ext/src/http/client/nosend:http_client_nosend", + "@com_google_googletest//:gtest_main", + ], +) + cc_test( name = "otlp_http_metric_exporter_test", srcs = ["test/otlp_http_metric_exporter_test.cc"], @@ -356,6 +377,22 @@ cc_test( ], ) +cc_test( + name = "otlp_grpc_log_exporter_factory_test", + srcs = ["test/otlp_grpc_log_exporter_factory_test.cc"], + tags = [ + "otlp", + "otlp_grpc_log", + "test", + ], + deps = [ + ":otlp_grpc_log_exporter", + "//api", + "//sdk/src/logs", + "@com_google_googletest//:gtest_main", + ], +) + otel_cc_benchmark( name = "otlp_grpc_exporter_benchmark", srcs = ["test/otlp_grpc_exporter_benchmark.cc"], diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index a1f6546279..c822859ee3 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -29,8 +29,9 @@ if(WITH_OTLP_GRPC) list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_grpc) - add_library(opentelemetry_exporter_otlp_grpc_log - src/otlp_grpc_log_exporter.cc) + add_library( + opentelemetry_exporter_otlp_grpc_log src/otlp_grpc_log_exporter.cc + src/otlp_grpc_log_exporter_factory.cc) set_target_properties(opentelemetry_exporter_otlp_grpc_log PROPERTIES EXPORT_NAME otlp_grpc_log_exporter) @@ -90,8 +91,9 @@ if(WITH_OTLP_HTTP) list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_http) if(WITH_LOGS_PREVIEW) - add_library(opentelemetry_exporter_otlp_http_log - src/otlp_http_log_exporter.cc) + add_library( + opentelemetry_exporter_otlp_http_log + src/otlp_http_log_exporter.cc src/otlp_http_log_exporter_factory.cc) set_target_properties(opentelemetry_exporter_otlp_http_log PROPERTIES EXPORT_NAME otlp_http_log_exporter) @@ -216,6 +218,17 @@ if(BUILD_TESTING) TARGET otlp_grpc_log_exporter_test TEST_PREFIX exporter.otlp. TEST_LIST otlp_grpc_log_exporter_test) + + add_executable(otlp_grpc_log_exporter_factory_test + test/otlp_grpc_log_exporter_factory_test.cc) + target_link_libraries( + otlp_grpc_log_exporter_factory_test ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIB} + opentelemetry_exporter_otlp_grpc_log opentelemetry_logs) + gtest_add_tests( + TARGET otlp_grpc_log_exporter_factory_test + TEST_PREFIX exporter.otlp. + TEST_LIST otlp_grpc_log_exporter_factory_test) endif() endif() @@ -254,6 +267,17 @@ if(BUILD_TESTING) TARGET otlp_http_log_exporter_test TEST_PREFIX exporter.otlp. TEST_LIST otlp_http_log_exporter_test) + + add_executable(otlp_http_log_exporter_factory_test + test/otlp_http_log_exporter_factory_test.cc) + target_link_libraries( + otlp_http_log_exporter_factory_test ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIB} + opentelemetry_exporter_otlp_http_log opentelemetry_logs) + gtest_add_tests( + TARGET otlp_http_log_exporter_factory_test + TEST_PREFIX exporter.otlp. + TEST_LIST otlp_http_log_exporter_factory_test) endif() if(NOT WITH_METRICS_PREVIEW) diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_exporter_factory.h new file mode 100644 index 0000000000..dfe3dfd6a0 --- /dev/null +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_exporter_factory.h @@ -0,0 +1,39 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#ifdef ENABLE_LOGS_PREVIEW + +# include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" +# include "opentelemetry/sdk/logs/exporter.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +/** + * Factory class for OtlpGrpcLogExporter. + */ +class OtlpGrpcLogExporterFactory +{ +public: + /** + * Create a OtlpGrpcLogExporter. + */ + static std::unique_ptr Create(); + + /** + * Create a OtlpGrpcLogExporter. + */ + static std::unique_ptr Create( + const OtlpGrpcExporterOptions &options); +}; + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE + +#endif /* ENABLE_LOGS_PREVIEW */ diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter.h index c6b2da30c3..c139b9ee6c 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter.h @@ -9,6 +9,7 @@ # include "opentelemetry/exporters/otlp/otlp_http_client.h" # include "opentelemetry/exporters/otlp/otlp_environment.h" +# include "opentelemetry/exporters/otlp/otlp_http_log_exporter_options.h" # include # include @@ -21,47 +22,6 @@ namespace exporter namespace otlp { -/** - * Struct to hold OTLP exporter options. - */ -struct OtlpHttpLogExporterOptions -{ - // The endpoint to export to. By default - // @see - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md - // @see https://github.com/open-telemetry/opentelemetry-collector/tree/main/receiver/otlpreceiver - std::string url = GetOtlpDefaultHttpLogEndpoint(); - - // By default, post json data - HttpRequestContentType content_type = HttpRequestContentType::kJson; - - // If convert bytes into hex. By default, we will convert all bytes but id into base64 - // This option is ignored if content_type is not kJson - JsonBytesMappingKind json_bytes_mapping = JsonBytesMappingKind::kHexId; - - // If using the json name of protobuf field to set the key of json. By default, we will use the - // field name just like proto files. - bool use_json_name = false; - - // Whether to print the status of the exporter in the console - bool console_debug = false; - - // TODO: Enable/disable to verify SSL certificate - std::chrono::system_clock::duration timeout = GetOtlpDefaultLogTimeout(); - - // Additional HTTP headers - OtlpHeaders http_headers = GetOtlpDefaultLogHeaders(); - -# ifdef ENABLE_ASYNC_EXPORT - // Concurrent requests - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md#otlpgrpc-concurrent-requests - std::size_t max_concurrent_requests = 64; - - // Requests per connections - std::size_t max_requests_per_connection = 8; -# endif -}; - /** * The OTLP exporter exports log data in OpenTelemetry Protocol (OTLP) format. */ diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter_factory.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter_factory.h new file mode 100644 index 0000000000..b2f509f683 --- /dev/null +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter_factory.h @@ -0,0 +1,39 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#ifdef ENABLE_LOGS_PREVIEW + +# include "opentelemetry/exporters/otlp/otlp_http_log_exporter_options.h" +# include "opentelemetry/sdk/logs/exporter.h" + +# include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +/** + * Factory class for OtlpHttpLogExporter. + */ +class OtlpHttpLogExporterFactory +{ +public: + /** + * Create a OtlpHttpLogExporter. + */ + static std::unique_ptr Create(); + + /** + * Create a OtlpHttpLogExporter. + */ + static std::unique_ptr Create( + const OtlpHttpLogExporterOptions &options); +}; + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter_options.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter_options.h new file mode 100644 index 0000000000..daea975b1c --- /dev/null +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_exporter_options.h @@ -0,0 +1,66 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#ifdef ENABLE_LOGS_PREVIEW + +# include "opentelemetry/exporters/otlp/otlp_environment.h" +# include "opentelemetry/exporters/otlp/otlp_http.h" +# include "opentelemetry/sdk/logs/exporter.h" + +# include +# include +# include +# include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +/** + * Struct to hold OTLP exporter options. + */ +struct OtlpHttpLogExporterOptions +{ + // The endpoint to export to. By default + // @see + // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md + // @see https://github.com/open-telemetry/opentelemetry-collector/tree/main/receiver/otlpreceiver + std::string url = GetOtlpDefaultHttpLogEndpoint(); + + // By default, post json data + HttpRequestContentType content_type = HttpRequestContentType::kJson; + + // If convert bytes into hex. By default, we will convert all bytes but id into base64 + // This option is ignored if content_type is not kJson + JsonBytesMappingKind json_bytes_mapping = JsonBytesMappingKind::kHexId; + + // If using the json name of protobuf field to set the key of json. By default, we will use the + // field name just like proto files. + bool use_json_name = false; + + // Whether to print the status of the exporter in the console + bool console_debug = false; + + // TODO: Enable/disable to verify SSL certificate + std::chrono::system_clock::duration timeout = GetOtlpDefaultLogTimeout(); + + // Additional HTTP headers + OtlpHeaders http_headers = GetOtlpDefaultLogHeaders(); + +# ifdef ENABLE_ASYNC_EXPORT + // Concurrent requests + // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md#otlpgrpc-concurrent-requests + std::size_t max_concurrent_requests = 64; + + // Requests per connections + std::size_t max_requests_per_connection = 8; +# endif +}; + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/exporters/otlp/src/otlp_grpc_log_exporter_factory.cc b/exporters/otlp/src/otlp_grpc_log_exporter_factory.cc new file mode 100644 index 0000000000..9e90070844 --- /dev/null +++ b/exporters/otlp/src/otlp_grpc_log_exporter_factory.cc @@ -0,0 +1,35 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifdef ENABLE_LOGS_PREVIEW + +// MUST be first (absl) +# include "opentelemetry/exporters/otlp/otlp_grpc_log_exporter.h" + +# include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" +# include "opentelemetry/exporters/otlp/otlp_grpc_log_exporter_factory.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +std::unique_ptr OtlpGrpcLogExporterFactory::Create() +{ + OtlpGrpcExporterOptions options; + return Create(options); +} + +std::unique_ptr OtlpGrpcLogExporterFactory::Create( + const OtlpGrpcExporterOptions &options) +{ + std::unique_ptr exporter(new OtlpGrpcLogExporter(options)); + return exporter; +} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE + +#endif diff --git a/exporters/otlp/src/otlp_http_log_exporter_factory.cc b/exporters/otlp/src/otlp_http_log_exporter_factory.cc new file mode 100644 index 0000000000..29e173454d --- /dev/null +++ b/exporters/otlp/src/otlp_http_log_exporter_factory.cc @@ -0,0 +1,33 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifdef ENABLE_LOGS_PREVIEW + +# include "opentelemetry/exporters/otlp/otlp_http_log_exporter_factory.h" +# include "opentelemetry/exporters/otlp/otlp_http_log_exporter.h" +# include "opentelemetry/exporters/otlp/otlp_http_log_exporter_options.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +std::unique_ptr OtlpHttpLogExporterFactory::Create() +{ + OtlpHttpLogExporterOptions options; + return Create(options); +} + +std::unique_ptr OtlpHttpLogExporterFactory::Create( + const OtlpHttpLogExporterOptions &options) +{ + std::unique_ptr exporter(new OtlpHttpLogExporter(options)); + return exporter; +} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE + +#endif diff --git a/exporters/otlp/test/otlp_grpc_log_exporter_factory_test.cc b/exporters/otlp/test/otlp_grpc_log_exporter_factory_test.cc new file mode 100644 index 0000000000..98f42721f1 --- /dev/null +++ b/exporters/otlp/test/otlp_grpc_log_exporter_factory_test.cc @@ -0,0 +1,40 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifdef ENABLE_LOGS_PREVIEW + +# include + +# include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" +# include "opentelemetry/exporters/otlp/otlp_grpc_log_exporter_factory.h" + +/* + Make sure OtlpGrpcLogExporterFactory does not require, + even indirectly, protobuf headers. +*/ +# ifdef GOOGLE_PROTOBUF_VERSION +# error "protobuf should not be included" +# endif + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +TEST(OtlpGrpcLogExporterFactoryTest, BuildTest) +{ + OtlpGrpcExporterOptions opts; + opts.endpoint = "localhost:45454"; + + std::unique_ptr exporter = + OtlpGrpcLogExporterFactory::Create(opts); + + EXPECT_TRUE(exporter != nullptr); +} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE + +#endif // ENABLE_LOGS_PREVIEW diff --git a/exporters/otlp/test/otlp_http_log_exporter_factory_test.cc b/exporters/otlp/test/otlp_http_log_exporter_factory_test.cc new file mode 100644 index 0000000000..3d54a3fa9b --- /dev/null +++ b/exporters/otlp/test/otlp_http_log_exporter_factory_test.cc @@ -0,0 +1,48 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifdef ENABLE_LOGS_PREVIEW + +# include + +# include "opentelemetry/exporters/otlp/otlp_http_log_exporter_factory.h" +# include "opentelemetry/exporters/otlp/otlp_http_log_exporter_options.h" + +/* + Make sure OtlpHttpExporterFactory does not require, + even indirectly, nlohmann/json headers. +*/ +# ifdef NLOHMANN_JSON_VERSION_MAJOR +# error "nlohmann/json should not be included" +# endif /* NLOHMANN_JSON_VERSION_MAJOR */ + +/* + Make sure OtlpHttpExporterFactory does not require, + even indirectly, protobuf headers. +*/ +# ifdef GOOGLE_PROTOBUF_VERSION +# error "protobuf should not be included" +# endif + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace otlp +{ + +TEST(OtlpHttpLogExporterFactoryTest, BuildTest) +{ + OtlpHttpLogExporterOptions opts; + opts.url = "localhost:45454"; + + std::unique_ptr exporter = + OtlpHttpLogExporterFactory::Create(opts); + + EXPECT_TRUE(exporter != nullptr); +} + +} // namespace otlp +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE + +#endif // ENABLE_LOGS_PREVIEW diff --git a/sdk/include/opentelemetry/sdk/logs/batch_log_processor.h b/sdk/include/opentelemetry/sdk/logs/batch_log_processor.h index 2a781b937c..e70b511a10 100644 --- a/sdk/include/opentelemetry/sdk/logs/batch_log_processor.h +++ b/sdk/include/opentelemetry/sdk/logs/batch_log_processor.h @@ -5,6 +5,7 @@ #ifdef ENABLE_LOGS_PREVIEW # include "opentelemetry/sdk/common/circular_buffer.h" +# include "opentelemetry/sdk/logs/batch_log_processor_options.h" # include "opentelemetry/sdk/logs/exporter.h" # include "opentelemetry/sdk/logs/processor.h" @@ -21,27 +22,6 @@ namespace sdk namespace logs { -/** - * Struct to hold batch SpanProcessor options. - */ -struct BatchLogProcessorOptions -{ - /** - * The maximum buffer/queue size. After the size is reached, spans are - * dropped. - */ - size_t max_queue_size = 2048; - - /* The time interval between two consecutive exports. */ - std::chrono::milliseconds schedule_delay_millis = std::chrono::milliseconds(5000); - - /** - * The maximum batch size of every export. It must be smaller or - * equal to max_queue_size. - */ - size_t max_export_batch_size = 512; -}; - /** * This is an implementation of the LogProcessor which creates batches of finished logs and passes * the export-friendly log data representations to the configured LogExporter. diff --git a/sdk/include/opentelemetry/sdk/logs/batch_log_processor_factory.h b/sdk/include/opentelemetry/sdk/logs/batch_log_processor_factory.h new file mode 100644 index 0000000000..6ccb8e43c0 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/logs/batch_log_processor_factory.h @@ -0,0 +1,35 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#ifdef ENABLE_LOGS_PREVIEW + +# include "opentelemetry/sdk/logs/batch_log_processor_options.h" +# include "opentelemetry/sdk/logs/exporter.h" +# include "opentelemetry/sdk/logs/processor.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ + +namespace logs +{ + +/** + * Factory class for BatchLogProcessor. + */ +class BatchLogProcessorFactory +{ +public: + /** + * Create a BatchLogProcessor. + */ + std::unique_ptr Create(std::unique_ptr &&exporter, + const BatchLogProcessorOptions &options); +}; + +} // namespace logs +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/logs/batch_log_processor_options.h b/sdk/include/opentelemetry/sdk/logs/batch_log_processor_options.h new file mode 100644 index 0000000000..591e12af72 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/logs/batch_log_processor_options.h @@ -0,0 +1,44 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#ifdef ENABLE_LOGS_PREVIEW + +# include "opentelemetry/sdk/version/version.h" + +# include +# include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ + +namespace logs +{ + +/** + * Struct to hold batch SpanProcessor options. + */ +struct BatchLogProcessorOptions +{ + /** + * The maximum buffer/queue size. After the size is reached, spans are + * dropped. + */ + size_t max_queue_size = 2048; + + /* The time interval between two consecutive exports. */ + std::chrono::milliseconds schedule_delay_millis = std::chrono::milliseconds(5000); + + /** + * The maximum batch size of every export. It must be smaller or + * equal to max_queue_size. + */ + size_t max_export_batch_size = 512; +}; + +} // namespace logs +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/logs/logger_context_factory.h b/sdk/include/opentelemetry/sdk/logs/logger_context_factory.h new file mode 100644 index 0000000000..55a5ec87fa --- /dev/null +++ b/sdk/include/opentelemetry/sdk/logs/logger_context_factory.h @@ -0,0 +1,43 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#ifdef ENABLE_LOGS_PREVIEW + +# include "opentelemetry/sdk/logs/logger_context.h" +# include "opentelemetry/sdk/logs/processor.h" +# include "opentelemetry/sdk/resource/resource.h" +# include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace logs +{ + +/** + * Factory class for LoggerContext. + */ +class LoggerContextFactory +{ +public: + /** + * Create a LoggerContext. + */ + static std::unique_ptr Create( + std::vector> &&processors); + + /** + * Create a LoggerContext. + */ + static std::unique_ptr Create( + std::vector> &&processors, + const opentelemetry::sdk::resource::Resource &resource); +}; + +} // namespace logs +} // namespace sdk + +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h b/sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h new file mode 100644 index 0000000000..eb6bee2ab1 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/logs/logger_provider_factory.h @@ -0,0 +1,66 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0/ + +#pragma once + +#ifdef ENABLE_LOGS_PREVIEW + +# include +# include + +# include "opentelemetry/logs/logger_provider.h" +# include "opentelemetry/nostd/shared_ptr.h" +# include "opentelemetry/sdk/common/atomic_shared_ptr.h" +# include "opentelemetry/sdk/logs/logger.h" +# include "opentelemetry/sdk/logs/logger_context.h" +# include "opentelemetry/sdk/logs/processor.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace logs +{ + +/** + * Factory class for LoggerProvider. + */ +class LoggerProviderFactory +{ +public: + /** + * Create a LoggerProvider. + */ + static std::unique_ptr Create( + std::unique_ptr &&processor); + + /** + * Create a LoggerProvider. + */ + static std::unique_ptr Create( + std::unique_ptr &&processor, + const opentelemetry::sdk::resource::Resource &resource); + + /** + * Create a LoggerProvider. + */ + static std::unique_ptr Create( + std::vector> &&processors); + + /** + * Create a LoggerProvider. + */ + static std::unique_ptr Create( + std::vector> &&processors, + const opentelemetry::sdk::resource::Resource &resource); + + /** + * Create a LoggerProvider. + */ + static std::unique_ptr Create( + std::shared_ptr context); +}; + +} // namespace logs +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE +#endif /* ENABLE_LOGS_PREVIEW */ diff --git a/sdk/include/opentelemetry/sdk/logs/multi_log_processor_factory.h b/sdk/include/opentelemetry/sdk/logs/multi_log_processor_factory.h new file mode 100644 index 0000000000..a61ae5522b --- /dev/null +++ b/sdk/include/opentelemetry/sdk/logs/multi_log_processor_factory.h @@ -0,0 +1,33 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#ifdef ENABLE_LOGS_PREVIEW + +# include +# include + +# include "opentelemetry/sdk/logs/processor.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace logs +{ + +/** + * Factory class for MultiLogProcessor. + */ +class MultiLogProcessorFactory +{ +public: + static std::unique_ptr Create( + std::vector> &&processors); +}; + +} // namespace logs +} // namespace sdk + +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/include/opentelemetry/sdk/logs/simple_log_processor_factory.h b/sdk/include/opentelemetry/sdk/logs/simple_log_processor_factory.h new file mode 100644 index 0000000000..2576a61eb6 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/logs/simple_log_processor_factory.h @@ -0,0 +1,32 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#ifdef ENABLE_LOGS_PREVIEW + +# include "opentelemetry/sdk/logs/exporter.h" +# include "opentelemetry/sdk/logs/processor.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace logs +{ + +/** + * Factory class for SimpleLogProcessor. + */ +class SimpleLogProcessorFactory +{ +public: + /** + * Create a SimpleLogProcessor. + */ + static std::unique_ptr Create(std::unique_ptr &&exporter); +}; + +} // namespace logs +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE +#endif /* ENABLE_LOGS_PREVIEW */ diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_context_factory.h b/sdk/include/opentelemetry/sdk/trace/tracer_context_factory.h index 447db73104..eb88707328 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_context_factory.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_context_factory.h @@ -24,20 +24,20 @@ class TracerContextFactory * Create a TracerContext. */ static std::unique_ptr Create( - std::vector> &&processor); + std::vector> &&processors); /** * Create a TracerContext. */ static std::unique_ptr Create( - std::vector> &&processor, + std::vector> &&processors, const opentelemetry::sdk::resource::Resource &resource); /** * Create a TracerContext. */ static std::unique_ptr Create( - std::vector> &&processor, + std::vector> &&processors, const opentelemetry::sdk::resource::Resource &resource, std::unique_ptr sampler); @@ -45,7 +45,7 @@ class TracerContextFactory * Create a TracerContext. */ static std::unique_ptr Create( - std::vector> &&processor, + std::vector> &&processors, const opentelemetry::sdk::resource::Resource &resource, std::unique_ptr sampler, std::unique_ptr id_generator); diff --git a/sdk/src/logs/CMakeLists.txt b/sdk/src/logs/CMakeLists.txt index 20f13324e7..ec9a3b8c79 100644 --- a/sdk/src/logs/CMakeLists.txt +++ b/sdk/src/logs/CMakeLists.txt @@ -1,11 +1,16 @@ add_library( opentelemetry_logs logger_provider.cc + logger_provider_factory.cc logger.cc simple_log_processor.cc + simple_log_processor_factory.cc batch_log_processor.cc + batch_log_processor_factory.cc logger_context.cc + logger_context_factory.cc multi_log_processor.cc + multi_log_processor_factory.cc multi_recordable.cc) set_target_properties(opentelemetry_logs PROPERTIES EXPORT_NAME logs) diff --git a/sdk/src/logs/batch_log_processor_factory.cc b/sdk/src/logs/batch_log_processor_factory.cc new file mode 100644 index 0000000000..d5e825e6f5 --- /dev/null +++ b/sdk/src/logs/batch_log_processor_factory.cc @@ -0,0 +1,26 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifdef ENABLE_LOGS_PREVIEW + +# include "opentelemetry/sdk/logs/batch_log_processor_factory.h" +# include "opentelemetry/sdk/logs/batch_log_processor.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace logs +{ + +std::unique_ptr BatchLogProcessorFactory::Create( + std::unique_ptr &&exporter, + const BatchLogProcessorOptions &options) +{ + std::unique_ptr processor(new BatchLogProcessor(std::move(exporter), options)); + return processor; +} + +} // namespace logs +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/src/logs/logger_context_factory.cc b/sdk/src/logs/logger_context_factory.cc new file mode 100644 index 0000000000..5cbe8b4510 --- /dev/null +++ b/sdk/src/logs/logger_context_factory.cc @@ -0,0 +1,36 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifdef ENABLE_LOGS_PREVIEW + +# include "opentelemetry/sdk/logs/logger_context_factory.h" + +# include +# include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace logs +{ + +std::unique_ptr LoggerContextFactory::Create( + std::vector> &&processors) +{ + auto resource = opentelemetry::sdk::resource::Resource::Create({}); + return Create(std::move(processors), resource); +} + +std::unique_ptr LoggerContextFactory::Create( + std::vector> &&processors, + const opentelemetry::sdk::resource::Resource &resource) +{ + std::unique_ptr context(new LoggerContext(std::move(processors), resource)); + return context; +} + +} // namespace logs +} // namespace sdk + +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/src/logs/logger_provider_factory.cc b/sdk/src/logs/logger_provider_factory.cc new file mode 100644 index 0000000000..8b9e6a694e --- /dev/null +++ b/sdk/src/logs/logger_provider_factory.cc @@ -0,0 +1,58 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifdef ENABLE_LOGS_PREVIEW + +# include "opentelemetry/sdk/logs/logger_provider_factory.h" +# include "opentelemetry/sdk/logs/logger_provider.h" +# include "opentelemetry/sdk/resource/resource.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace logs +{ + +std::unique_ptr LoggerProviderFactory::Create( + std::unique_ptr &&processor) +{ + auto resource = opentelemetry::sdk::resource::Resource::Create({}); + return Create(std::move(processor), resource); +} + +std::unique_ptr LoggerProviderFactory::Create( + std::unique_ptr &&processor, + const opentelemetry::sdk::resource::Resource &resource) +{ + std::unique_ptr provider( + new LoggerProvider(std::move(processor), resource)); + return provider; +} + +std::unique_ptr LoggerProviderFactory::Create( + std::vector> &&processors) +{ + auto resource = opentelemetry::sdk::resource::Resource::Create({}); + return Create(std::move(processors), resource); +} + +std::unique_ptr LoggerProviderFactory::Create( + std::vector> &&processors, + const opentelemetry::sdk::resource::Resource &resource) +{ + std::unique_ptr provider( + new LoggerProvider(std::move(processors), resource)); + return provider; +} + +std::unique_ptr LoggerProviderFactory::Create( + std::shared_ptr context) +{ + std::unique_ptr provider(new LoggerProvider(context)); + return provider; +} + +} // namespace logs +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/src/logs/multi_log_processor_factory.cc b/sdk/src/logs/multi_log_processor_factory.cc new file mode 100644 index 0000000000..a0b8a8c911 --- /dev/null +++ b/sdk/src/logs/multi_log_processor_factory.cc @@ -0,0 +1,30 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifdef ENABLE_LOGS_PREVIEW + +# include "opentelemetry/sdk/logs/multi_log_processor_factory.h" +# include "opentelemetry/sdk/logs/multi_log_processor.h" + +# include +# include +# include + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace logs +{ + +std::unique_ptr MultiLogProcessorFactory::Create( + std::vector> &&processors) +{ + std::unique_ptr processor(new MultiLogProcessor(std::move(processors))); + return processor; +} + +} // namespace logs +} // namespace sdk + +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/src/logs/simple_log_processor_factory.cc b/sdk/src/logs/simple_log_processor_factory.cc new file mode 100644 index 0000000000..25cf46521e --- /dev/null +++ b/sdk/src/logs/simple_log_processor_factory.cc @@ -0,0 +1,25 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifdef ENABLE_LOGS_PREVIEW + +# include "opentelemetry/sdk/logs/simple_log_processor_factory.h" +# include "opentelemetry/sdk/logs/simple_log_processor.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace logs +{ + +std::unique_ptr SimpleLogProcessorFactory::Create( + std::unique_ptr &&exporter) +{ + std::unique_ptr processor(new SimpleLogProcessor(std::move(exporter))); + return processor; +} + +} // namespace logs +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/sdk/src/trace/tracer_context_factory.cc b/sdk/src/trace/tracer_context_factory.cc index a966b5f5d9..df9d81a197 100644 --- a/sdk/src/trace/tracer_context_factory.cc +++ b/sdk/src/trace/tracer_context_factory.cc @@ -14,37 +14,37 @@ namespace trace { std::unique_ptr TracerContextFactory::Create( - std::vector> &&processor) + std::vector> &&processors) { auto resource = opentelemetry::sdk::resource::Resource::Create({}); - return Create(std::move(processor), resource); + return Create(std::move(processors), resource); } std::unique_ptr TracerContextFactory::Create( - std::vector> &&processor, + std::vector> &&processors, const opentelemetry::sdk::resource::Resource &resource) { auto sampler = AlwaysOnSamplerFactory::Create(); - return Create(std::move(processor), resource, std::move(sampler)); + return Create(std::move(processors), resource, std::move(sampler)); } std::unique_ptr TracerContextFactory::Create( - std::vector> &&processor, + std::vector> &&processors, const opentelemetry::sdk::resource::Resource &resource, std::unique_ptr sampler) { auto id_generator = RandomIdGeneratorFactory::Create(); - return Create(std::move(processor), resource, std::move(sampler), std::move(id_generator)); + return Create(std::move(processors), resource, std::move(sampler), std::move(id_generator)); } std::unique_ptr TracerContextFactory::Create( - std::vector> &&processor, + std::vector> &&processors, const opentelemetry::sdk::resource::Resource &resource, std::unique_ptr sampler, std::unique_ptr id_generator) { std::unique_ptr context(new TracerContext( - std::move(processor), resource, std::move(sampler), std::move(id_generator))); + std::move(processors), resource, std::move(sampler), std::move(id_generator))); return context; }