From 2eb9af1cc7e1125ba2c8644670361cad8b898364 Mon Sep 17 00:00:00 2001 From: Dawid Nowak Date: Mon, 29 Mar 2021 15:01:39 +0100 Subject: [PATCH 1/7] Adding a dynamic dispatch to Aggregator Selector --- Cargo.toml | 1 + examples/basic-otlp-with-selector/Cargo.toml | 12 ++ examples/basic-otlp-with-selector/README.md | 4 + examples/basic-otlp-with-selector/src/main.rs | 132 ++++++++++++++++++ examples/basic-otlp/src/main.rs | 4 +- opentelemetry-otlp/src/lib.rs | 5 +- opentelemetry-otlp/src/metric.rs | 37 +++-- .../src/sdk/export/metrics/stdout.rs | 2 +- .../src/sdk/metrics/controllers/push.rs | 7 +- 9 files changed, 188 insertions(+), 16 deletions(-) create mode 100644 examples/basic-otlp-with-selector/Cargo.toml create mode 100644 examples/basic-otlp-with-selector/README.md create mode 100644 examples/basic-otlp-with-selector/src/main.rs diff --git a/Cargo.toml b/Cargo.toml index 6274257ba1..22010cdf3a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ members = [ "examples/aws-xray", "examples/basic", "examples/basic-otlp", + "examples/basic-otlp-with-selector", "examples/datadog", "examples/external-otlp-tonic-tokio", "examples/grpc", diff --git a/examples/basic-otlp-with-selector/Cargo.toml b/examples/basic-otlp-with-selector/Cargo.toml new file mode 100644 index 0000000000..9224157aa2 --- /dev/null +++ b/examples/basic-otlp-with-selector/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "basic-otlp-with-selector" +version = "0.1.0" +edition = "2018" + +[dependencies] +futures = "0.3" +lazy_static = "1.4" +opentelemetry = { path = "../../opentelemetry", features = ["rt-tokio", "metrics", "serialize"] } +opentelemetry-otlp = { path = "../../opentelemetry-otlp", features = ["tonic", "metrics"] } +serde_json = "1.0" +tokio = { version = "1.0", features = ["full"] } diff --git a/examples/basic-otlp-with-selector/README.md b/examples/basic-otlp-with-selector/README.md new file mode 100644 index 0000000000..db067418cb --- /dev/null +++ b/examples/basic-otlp-with-selector/README.md @@ -0,0 +1,4 @@ +# Basic OpenTelemetry Example + +This example shows basic span and metric usage, and exports to the [OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector) via OTLP with a custom metric aggregator selector. + diff --git a/examples/basic-otlp-with-selector/src/main.rs b/examples/basic-otlp-with-selector/src/main.rs new file mode 100644 index 0000000000..d281ce116a --- /dev/null +++ b/examples/basic-otlp-with-selector/src/main.rs @@ -0,0 +1,132 @@ +use futures::stream::Stream; +use futures::StreamExt; +use opentelemetry::global::shutdown_tracer_provider; +use opentelemetry::sdk::{ + export::metrics::{Aggregator, AggregatorSelector}, + metrics::{aggregators, PushController}, +}; +use opentelemetry::trace::TraceError; +use opentelemetry::{ + baggage::BaggageExt, + metrics::{self, Descriptor, ObserverResult}, + trace::{TraceContextExt, Tracer}, + Context, Key, KeyValue, +}; +use opentelemetry::{global, sdk::trace as sdktrace}; +use opentelemetry_otlp::ExporterConfig; +use opentelemetry_otlp::Protocol; +use std::error::Error; +use std::sync::Arc; +use std::time::Duration; + +fn init_tracer() -> Result { + opentelemetry_otlp::new_pipeline() + .with_endpoint("http://localhost:4317") + .with_tonic() + .install_batch(opentelemetry::runtime::Tokio) +} + +// Skip first immediate tick from tokio, not needed for async_std. +fn delayed_interval(duration: Duration) -> impl Stream { + opentelemetry::util::tokio_interval_stream(duration).skip(1) +} + +#[derive(Debug)] +struct CustomAggregator(); + +impl AggregatorSelector for CustomAggregator { + fn aggregator_for( + &self, + descriptor: &Descriptor, + ) -> Option> { + match descriptor.name() { + "ex.com.one" => Some(Arc::new(aggregators::last_value())), + "ex.com.two" => Some(Arc::new(aggregators::array())), + _ => Some(Arc::new(aggregators::sum())), + } + } +} + +fn init_meter() -> metrics::Result { + let export_config = ExporterConfig { + endpoint: "http://localhost:4317".to_string(), + protocol: Protocol::Grpc, + ..ExporterConfig::default() + }; + opentelemetry_otlp::new_metrics_pipeline(tokio::spawn, delayed_interval) + .with_export_config(export_config) + .with_aggregator_selector(Box::new(CustomAggregator())) + .build() +} + +const FOO_KEY: Key = Key::from_static_str("ex.com/foo"); +const BAR_KEY: Key = Key::from_static_str("ex.com/bar"); +const LEMONS_KEY: Key = Key::from_static_str("lemons"); +const ANOTHER_KEY: Key = Key::from_static_str("ex.com/another"); + +lazy_static::lazy_static! { + static ref COMMON_LABELS: [KeyValue; 4] = [ + LEMONS_KEY.i64(10), + KeyValue::new("A", "1"), + KeyValue::new("B", "2"), + KeyValue::new("C", "3"), + ]; +} + +#[tokio::main] +async fn main() -> Result<(), Box> { + let _ = init_tracer()?; + let _started = init_meter()?; + + let tracer = global::tracer("ex.com/basic"); + let meter = global::meter("ex.com/basic"); + + let one_metric_callback = |res: ObserverResult| res.observe(1.0, COMMON_LABELS.as_ref()); + let _ = meter + .f64_value_observer("ex.com.one", one_metric_callback) + .with_description("A ValueObserver set to 1.0") + .init(); + + let value_recorder_two = meter.f64_value_recorder("ex.com.two").init(); + + let another_recorder = meter.f64_value_recorder("ex.com.two").init(); + another_recorder.record(5.5, COMMON_LABELS.as_ref()); + + let _baggage = + Context::current_with_baggage(vec![FOO_KEY.string("foo1"), BAR_KEY.string("bar1")]) + .attach(); + + let value_recorder = value_recorder_two.bind(COMMON_LABELS.as_ref()); + + tracer.in_span("operation", |cx| { + let span = cx.span(); + span.add_event( + "Nice operation!".to_string(), + vec![Key::new("bogons").i64(100)], + ); + span.set_attribute(ANOTHER_KEY.string("yes")); + + meter.record_batch_with_context( + // Note: call-site variables added as context Entries: + &Context::current_with_baggage(vec![ANOTHER_KEY.string("xyz")]), + COMMON_LABELS.as_ref(), + vec![value_recorder_two.measurement(2.0)], + ); + + tracer.in_span("Sub operation...", |cx| { + let span = cx.span(); + span.set_attribute(LEMONS_KEY.string("five")); + + span.add_event("Sub span event".to_string(), vec![]); + + value_recorder.record(1.3); + }); + }); + + // wait for 1 minutes so that we could see metrics being pushed via OTLP every 10 seconds. + tokio::time::sleep(Duration::from_secs(60)).await; + + shutdown_tracer_provider(); + + Ok(()) +} diff --git a/examples/basic-otlp/src/main.rs b/examples/basic-otlp/src/main.rs index 2739cdaf5d..b54ec73f1f 100644 --- a/examples/basic-otlp/src/main.rs +++ b/examples/basic-otlp/src/main.rs @@ -33,13 +33,13 @@ fn init_meter() -> metrics::Result { }; opentelemetry_otlp::new_metrics_pipeline(tokio::spawn, delayed_interval) .with_export_config(export_config) - .with_aggregator_selector(selectors::simple::Selector::Exact) + .with_aggregator_selector(Box::new(selectors::simple::Selector::Exact)) .build() } const FOO_KEY: Key = Key::from_static_str("ex.com/foo"); const BAR_KEY: Key = Key::from_static_str("ex.com/bar"); -const LEMONS_KEY: Key = Key::from_static_str("ex.com/lemons"); +const LEMONS_KEY: Key = Key::from_static_str("lemons"); const ANOTHER_KEY: Key = Key::from_static_str("ex.com/another"); lazy_static::lazy_static! { diff --git a/opentelemetry-otlp/src/lib.rs b/opentelemetry-otlp/src/lib.rs index c3b5cf721f..5aa92b3c4a 100644 --- a/opentelemetry-otlp/src/lib.rs +++ b/opentelemetry-otlp/src/lib.rs @@ -188,7 +188,10 @@ pub use crate::span::TonicConfig; pub use crate::span::GrpcioConfig; #[cfg(feature = "metrics")] -pub use crate::metric::{new_metrics_pipeline, MetricsExporter, OtlpMetricPipelineBuilder}; +pub use crate::metric::{ + new_metrics_pipeline, new_metrics_pipeline_with_selector, MetricsExporter, + OtlpMetricPipelineBuilder, +}; #[cfg(feature = "grpc-sys")] pub use crate::span::{Compression, Credentials}; diff --git a/opentelemetry-otlp/src/metric.rs b/opentelemetry-otlp/src/metric.rs index e8df777a94..c50e1d2acb 100644 --- a/opentelemetry-otlp/src/metric.rs +++ b/opentelemetry-otlp/src/metric.rs @@ -37,13 +37,33 @@ use tonic::Request; pub fn new_metrics_pipeline( spawn: SP, interval: I, -) -> OtlpMetricPipelineBuilder +) -> OtlpMetricPipelineBuilder +where + SP: Fn(PushControllerWorker) -> SO, + I: Fn(time::Duration) -> IO, +{ + new_metrics_pipeline_with_selector( + spawn, + interval, + Box::new(selectors::simple::Selector::Inexpensive), + ) +} + +/// Return a pipeline to build OTLP metrics exporter. +/// +/// Note that currently the OTLP metrics exporter only supports tonic as it's grpc layer and tokio as +/// runtime. +pub fn new_metrics_pipeline_with_selector( + spawn: SP, + interval: I, + aggregator_selector: Box, +) -> OtlpMetricPipelineBuilder where SP: Fn(PushControllerWorker) -> SO, I: Fn(time::Duration) -> IO, { OtlpMetricPipelineBuilder { - aggregator_selector: selectors::simple::Selector::Inexpensive, + aggregator_selector, export_selector: ExportKindSelector::Cumulative, spawn, interval, @@ -61,14 +81,13 @@ where /// Note that currently the OTLP metrics exporter only supports tonic as it's grpc layer and tokio as /// runtime. #[derive(Debug)] -pub struct OtlpMetricPipelineBuilder +pub struct OtlpMetricPipelineBuilder where - AS: AggregatorSelector + Send + Sync + 'static, ES: ExportKindFor + Send + Sync + Clone + 'static, SP: Fn(PushControllerWorker) -> SO, I: Fn(time::Duration) -> IO, { - aggregator_selector: AS, + aggregator_selector: Box, export_selector: ES, spawn: SP, interval: I, @@ -80,9 +99,8 @@ where timeout: Option, } -impl OtlpMetricPipelineBuilder +impl OtlpMetricPipelineBuilder where - AS: AggregatorSelector + Send + Sync + 'static, ES: ExportKindFor + Send + Sync + Clone + 'static, SP: Fn(PushControllerWorker) -> SO, I: Fn(time::Duration) -> IO, @@ -113,7 +131,10 @@ where } /// Build with the aggregator selector - pub fn with_aggregator_selector(self, aggregator_selector: AS) -> Self { + pub fn with_aggregator_selector( + self, + aggregator_selector: Box, + ) -> Self { OtlpMetricPipelineBuilder { aggregator_selector, ..self diff --git a/opentelemetry/src/sdk/export/metrics/stdout.rs b/opentelemetry/src/sdk/export/metrics/stdout.rs index 2a52e057ba..efecf12102 100644 --- a/opentelemetry/src/sdk/export/metrics/stdout.rs +++ b/opentelemetry/src/sdk/export/metrics/stdout.rs @@ -360,7 +360,7 @@ where let period = self.period.take(); let (spawn, interval, exporter) = self.try_build()?; let mut push_builder = controllers::push( - simple::Selector::Exact, + Box::new(simple::Selector::Exact), ExportKindSelector::Stateless, exporter, spawn, diff --git a/opentelemetry/src/sdk/metrics/controllers/push.rs b/opentelemetry/src/sdk/metrics/controllers/push.rs index e52bafeabb..2751d350fc 100644 --- a/opentelemetry/src/sdk/metrics/controllers/push.rs +++ b/opentelemetry/src/sdk/metrics/controllers/push.rs @@ -19,22 +19,21 @@ lazy_static::lazy_static! { } /// Create a new `PushControllerBuilder`. -pub fn push( - aggregator_selector: AS, +pub fn push( + aggregator_selector: Box, export_selector: ES, exporter: E, spawn: SP, interval: I, ) -> PushControllerBuilder where - AS: AggregatorSelector + Send + Sync + 'static, ES: ExportKindFor + Send + Sync + 'static, E: Exporter + Send + Sync + 'static, SP: Fn(PushControllerWorker) -> SO, I: Fn(time::Duration) -> IO, { PushControllerBuilder { - aggregator_selector: Box::new(aggregator_selector), + aggregator_selector: aggregator_selector, export_selector: Box::new(export_selector), exporter: Box::new(exporter), spawn, From c5cb66c92bfdc95b4afd8d0ee7ba586a13866584 Mon Sep 17 00:00:00 2001 From: Dawid Nowak Date: Mon, 29 Mar 2021 15:21:40 +0100 Subject: [PATCH 2/7] Keeping lint happy --- opentelemetry/src/sdk/metrics/controllers/push.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry/src/sdk/metrics/controllers/push.rs b/opentelemetry/src/sdk/metrics/controllers/push.rs index 2751d350fc..18d2e28a3c 100644 --- a/opentelemetry/src/sdk/metrics/controllers/push.rs +++ b/opentelemetry/src/sdk/metrics/controllers/push.rs @@ -33,7 +33,7 @@ where I: Fn(time::Duration) -> IO, { PushControllerBuilder { - aggregator_selector: aggregator_selector, + aggregator_selector, export_selector: Box::new(export_selector), exporter: Box::new(exporter), spawn, From f9791e9761a40e9b4fee93a74758a946d5acb4b5 Mon Sep 17 00:00:00 2001 From: Dawid Nowak Date: Wed, 31 Mar 2021 16:24:06 +0100 Subject: [PATCH 3/7] Removing box from with_aggregator_selector --- examples/basic-otlp-with-selector/src/main.rs | 3 +-- examples/basic-otlp/src/main.rs | 2 +- opentelemetry-otlp/src/metric.rs | 10 +++++----- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/examples/basic-otlp-with-selector/src/main.rs b/examples/basic-otlp-with-selector/src/main.rs index d281ce116a..14a197c4a4 100644 --- a/examples/basic-otlp-with-selector/src/main.rs +++ b/examples/basic-otlp-with-selector/src/main.rs @@ -55,7 +55,7 @@ fn init_meter() -> metrics::Result { }; opentelemetry_otlp::new_metrics_pipeline(tokio::spawn, delayed_interval) .with_export_config(export_config) - .with_aggregator_selector(Box::new(CustomAggregator())) + .with_aggregator_selector(CustomAggregator()) .build() } @@ -97,7 +97,6 @@ async fn main() -> Result<(), Box> { .attach(); let value_recorder = value_recorder_two.bind(COMMON_LABELS.as_ref()); - tracer.in_span("operation", |cx| { let span = cx.span(); span.add_event( diff --git a/examples/basic-otlp/src/main.rs b/examples/basic-otlp/src/main.rs index b54ec73f1f..51ac886ec4 100644 --- a/examples/basic-otlp/src/main.rs +++ b/examples/basic-otlp/src/main.rs @@ -33,7 +33,7 @@ fn init_meter() -> metrics::Result { }; opentelemetry_otlp::new_metrics_pipeline(tokio::spawn, delayed_interval) .with_export_config(export_config) - .with_aggregator_selector(Box::new(selectors::simple::Selector::Exact)) + .with_aggregator_selector(selectors::simple::Selector::Exact) .build() } diff --git a/opentelemetry-otlp/src/metric.rs b/opentelemetry-otlp/src/metric.rs index c50e1d2acb..09e6a80294 100644 --- a/opentelemetry-otlp/src/metric.rs +++ b/opentelemetry-otlp/src/metric.rs @@ -131,12 +131,12 @@ where } /// Build with the aggregator selector - pub fn with_aggregator_selector( - self, - aggregator_selector: Box, - ) -> Self { + pub fn with_aggregator_selector(self, aggregator_selector: T) -> Self + where + T: AggregatorSelector + Send + Sync + 'static, + { OtlpMetricPipelineBuilder { - aggregator_selector, + aggregator_selector: Box::new(aggregator_selector), ..self } } From 398d34b680d3f41a5f095a6985994d117ee999c4 Mon Sep 17 00:00:00 2001 From: Dawid Nowak Date: Thu, 1 Apr 2021 13:56:36 +0100 Subject: [PATCH 4/7] Removig more boxes --- opentelemetry-otlp/src/metric.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/opentelemetry-otlp/src/metric.rs b/opentelemetry-otlp/src/metric.rs index 09e6a80294..7b1726b1e6 100644 --- a/opentelemetry-otlp/src/metric.rs +++ b/opentelemetry-otlp/src/metric.rs @@ -42,28 +42,25 @@ where SP: Fn(PushControllerWorker) -> SO, I: Fn(time::Duration) -> IO, { - new_metrics_pipeline_with_selector( - spawn, - interval, - Box::new(selectors::simple::Selector::Inexpensive), - ) + new_metrics_pipeline_with_selector(spawn, interval, selectors::simple::Selector::Inexpensive) } /// Return a pipeline to build OTLP metrics exporter. /// /// Note that currently the OTLP metrics exporter only supports tonic as it's grpc layer and tokio as /// runtime. -pub fn new_metrics_pipeline_with_selector( +pub fn new_metrics_pipeline_with_selector( spawn: SP, interval: I, - aggregator_selector: Box, + aggregator_selector: AS, ) -> OtlpMetricPipelineBuilder where SP: Fn(PushControllerWorker) -> SO, I: Fn(time::Duration) -> IO, + AS: AggregatorSelector + Send + Sync + 'static, { OtlpMetricPipelineBuilder { - aggregator_selector, + aggregator_selector: Box::new(aggregator_selector), export_selector: ExportKindSelector::Cumulative, spawn, interval, From 88b1904b808ae811076eddc53a4c87e01181999a Mon Sep 17 00:00:00 2001 From: Julian Tescher Date: Sat, 3 Apr 2021 15:48:14 -0700 Subject: [PATCH 5/7] with_aggregator_selector suggestions --- opentelemetry-otlp/src/lib.rs | 5 +- opentelemetry-otlp/src/metric.rs | 46 +++++++++---------- .../src/sdk/export/metrics/stdout.rs | 2 +- .../src/sdk/metrics/controllers/push.rs | 7 +-- 4 files changed, 27 insertions(+), 33 deletions(-) diff --git a/opentelemetry-otlp/src/lib.rs b/opentelemetry-otlp/src/lib.rs index 5aa92b3c4a..c3b5cf721f 100644 --- a/opentelemetry-otlp/src/lib.rs +++ b/opentelemetry-otlp/src/lib.rs @@ -188,10 +188,7 @@ pub use crate::span::TonicConfig; pub use crate::span::GrpcioConfig; #[cfg(feature = "metrics")] -pub use crate::metric::{ - new_metrics_pipeline, new_metrics_pipeline_with_selector, MetricsExporter, - OtlpMetricPipelineBuilder, -}; +pub use crate::metric::{new_metrics_pipeline, MetricsExporter, OtlpMetricPipelineBuilder}; #[cfg(feature = "grpc-sys")] pub use crate::span::{Compression, Credentials}; diff --git a/opentelemetry-otlp/src/metric.rs b/opentelemetry-otlp/src/metric.rs index 7b1726b1e6..3f784fc510 100644 --- a/opentelemetry-otlp/src/metric.rs +++ b/opentelemetry-otlp/src/metric.rs @@ -37,30 +37,13 @@ use tonic::Request; pub fn new_metrics_pipeline( spawn: SP, interval: I, -) -> OtlpMetricPipelineBuilder +) -> OtlpMetricPipelineBuilder where SP: Fn(PushControllerWorker) -> SO, I: Fn(time::Duration) -> IO, -{ - new_metrics_pipeline_with_selector(spawn, interval, selectors::simple::Selector::Inexpensive) -} - -/// Return a pipeline to build OTLP metrics exporter. -/// -/// Note that currently the OTLP metrics exporter only supports tonic as it's grpc layer and tokio as -/// runtime. -pub fn new_metrics_pipeline_with_selector( - spawn: SP, - interval: I, - aggregator_selector: AS, -) -> OtlpMetricPipelineBuilder -where - SP: Fn(PushControllerWorker) -> SO, - I: Fn(time::Duration) -> IO, - AS: AggregatorSelector + Send + Sync + 'static, { OtlpMetricPipelineBuilder { - aggregator_selector: Box::new(aggregator_selector), + aggregator_selector: selectors::simple::Selector::Inexpensive, export_selector: ExportKindSelector::Cumulative, spawn, interval, @@ -78,13 +61,14 @@ where /// Note that currently the OTLP metrics exporter only supports tonic as it's grpc layer and tokio as /// runtime. #[derive(Debug)] -pub struct OtlpMetricPipelineBuilder +pub struct OtlpMetricPipelineBuilder where + AS: AggregatorSelector + Send + Sync + 'static, ES: ExportKindFor + Send + Sync + Clone + 'static, SP: Fn(PushControllerWorker) -> SO, I: Fn(time::Duration) -> IO, { - aggregator_selector: Box, + aggregator_selector: AS, export_selector: ES, spawn: SP, interval: I, @@ -96,8 +80,9 @@ where timeout: Option, } -impl OtlpMetricPipelineBuilder +impl OtlpMetricPipelineBuilder where + AS: AggregatorSelector + Send + Sync + 'static, ES: ExportKindFor + Send + Sync + Clone + 'static, SP: Fn(PushControllerWorker) -> SO, I: Fn(time::Duration) -> IO, @@ -128,13 +113,24 @@ where } /// Build with the aggregator selector - pub fn with_aggregator_selector(self, aggregator_selector: T) -> Self + pub fn with_aggregator_selector( + self, + aggregator_selector: T, + ) -> OtlpMetricPipelineBuilder where T: AggregatorSelector + Send + Sync + 'static, { OtlpMetricPipelineBuilder { - aggregator_selector: Box::new(aggregator_selector), - ..self + aggregator_selector, + export_selector: self.export_selector, + spawn: self.spawn, + interval: self.interval, + export_config: self.export_config, + tonic_config: self.tonic_config, + resource: self.resource, + stateful: self.stateful, + period: self.period, + timeout: self.timeout, } } diff --git a/opentelemetry/src/sdk/export/metrics/stdout.rs b/opentelemetry/src/sdk/export/metrics/stdout.rs index efecf12102..2a52e057ba 100644 --- a/opentelemetry/src/sdk/export/metrics/stdout.rs +++ b/opentelemetry/src/sdk/export/metrics/stdout.rs @@ -360,7 +360,7 @@ where let period = self.period.take(); let (spawn, interval, exporter) = self.try_build()?; let mut push_builder = controllers::push( - Box::new(simple::Selector::Exact), + simple::Selector::Exact, ExportKindSelector::Stateless, exporter, spawn, diff --git a/opentelemetry/src/sdk/metrics/controllers/push.rs b/opentelemetry/src/sdk/metrics/controllers/push.rs index 18d2e28a3c..e52bafeabb 100644 --- a/opentelemetry/src/sdk/metrics/controllers/push.rs +++ b/opentelemetry/src/sdk/metrics/controllers/push.rs @@ -19,21 +19,22 @@ lazy_static::lazy_static! { } /// Create a new `PushControllerBuilder`. -pub fn push( - aggregator_selector: Box, +pub fn push( + aggregator_selector: AS, export_selector: ES, exporter: E, spawn: SP, interval: I, ) -> PushControllerBuilder where + AS: AggregatorSelector + Send + Sync + 'static, ES: ExportKindFor + Send + Sync + 'static, E: Exporter + Send + Sync + 'static, SP: Fn(PushControllerWorker) -> SO, I: Fn(time::Duration) -> IO, { PushControllerBuilder { - aggregator_selector, + aggregator_selector: Box::new(aggregator_selector), export_selector: Box::new(export_selector), exporter: Box::new(exporter), spawn, From 14051a2c37a0b55239ad3e755f2394c33c49d45e Mon Sep 17 00:00:00 2001 From: Dawid Nowak Date: Wed, 7 Apr 2021 11:02:24 +0100 Subject: [PATCH 6/7] Added histogram to custom aggregator in examples --- examples/basic-otlp-with-selector/src/main.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/basic-otlp-with-selector/src/main.rs b/examples/basic-otlp-with-selector/src/main.rs index 14a197c4a4..ea5d4fdb42 100644 --- a/examples/basic-otlp-with-selector/src/main.rs +++ b/examples/basic-otlp-with-selector/src/main.rs @@ -41,7 +41,10 @@ impl AggregatorSelector for CustomAggregator { ) -> Option> { match descriptor.name() { "ex.com.one" => Some(Arc::new(aggregators::last_value())), - "ex.com.two" => Some(Arc::new(aggregators::array())), + "ex.com.two" => Some(Arc::new(aggregators::histogram( + descriptor, + &vec![0.0, 0.5, 1.0, 10.0], + ))), _ => Some(Arc::new(aggregators::sum())), } } From 8446a7621145e878c292b8f3b53a080e9691600c Mon Sep 17 00:00:00 2001 From: Dawid Nowak Date: Wed, 7 Apr 2021 11:16:50 +0100 Subject: [PATCH 7/7] Keeping linter happy --- examples/basic-otlp-with-selector/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/basic-otlp-with-selector/src/main.rs b/examples/basic-otlp-with-selector/src/main.rs index ea5d4fdb42..7cbc46d176 100644 --- a/examples/basic-otlp-with-selector/src/main.rs +++ b/examples/basic-otlp-with-selector/src/main.rs @@ -43,7 +43,7 @@ impl AggregatorSelector for CustomAggregator { "ex.com.one" => Some(Arc::new(aggregators::last_value())), "ex.com.two" => Some(Arc::new(aggregators::histogram( descriptor, - &vec![0.0, 0.5, 1.0, 10.0], + &[0.0, 0.5, 1.0, 10.0], ))), _ => Some(Arc::new(aggregators::sum())), }