Skip to content

Commit

Permalink
fix: allow users to use custom export kind selector.
Browse files Browse the repository at this point in the history
Follow up on open-telemetry#497, which allows users to bring their own aggregator selector.

Also updated the name of examples.
  • Loading branch information
TommyCpp committed Apr 20, 2021
1 parent 32f34fb commit c5bffdd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
7 changes: 5 additions & 2 deletions examples/basic-otlp-with-selector/README.md
@@ -1,4 +1,7 @@
# Basic OpenTelemetry Example
# Basic OTLP exporter 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.
This example shows how to configure OTLP metrics exporter to use custom aggregator selectors and custom export kind selectors.

## Prerequisite
You should first start a `opentelemetry-collector` on localhost using the default configuration.

11 changes: 11 additions & 0 deletions examples/basic-otlp-with-selector/src/main.rs
@@ -1,6 +1,7 @@
use futures::stream::Stream;
use futures::StreamExt;
use opentelemetry::global::shutdown_tracer_provider;
use opentelemetry::sdk::export::metrics::{ExportKind, ExportKindFor};
use opentelemetry::sdk::{
export::metrics::{Aggregator, AggregatorSelector},
metrics::{aggregators, PushController},
Expand Down Expand Up @@ -50,6 +51,15 @@ impl AggregatorSelector for CustomAggregator {
}
}

#[derive(Debug, Clone)]
struct CustomExportKindFor();

impl ExportKindFor for CustomExportKindFor {
fn export_kind_for(&self, _descriptor: &Descriptor) -> ExportKind {
ExportKind::Delta
}
}

fn init_meter() -> metrics::Result<PushController> {
let export_config = ExporterConfig {
endpoint: "http://localhost:4317".to_string(),
Expand All @@ -58,6 +68,7 @@ fn init_meter() -> metrics::Result<PushController> {
};
opentelemetry_otlp::new_metrics_pipeline(tokio::spawn, delayed_interval)
.with_export_config(export_config)
.with_export_kind(CustomExportKindFor())
.with_aggregator_selector(CustomAggregator())
.build()
}
Expand Down
4 changes: 3 additions & 1 deletion examples/basic-otlp/README.md
@@ -1,4 +1,6 @@
# Basic OpenTelemetry Example
# Basic OTLP exporter Example

This example shows basic span and metric usage, and exports to the [OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector) via OTLP.

## Prerequisite
You should first start a `opentelemetry-collector` on localhost using the default configuration.
18 changes: 16 additions & 2 deletions opentelemetry-otlp/src/metric.rs
Expand Up @@ -169,10 +169,24 @@ where
}

/// Build with export kind selector
pub fn with_export_kind(self, export_selector: ES) -> Self {
pub fn with_export_kind<E>(
self,
export_selector: E,
) -> OtlpMetricPipelineBuilder<AS, E, SP, SO, I, IO>
where
E: ExportKindFor + Send + Sync + Clone + 'static,
{
OtlpMetricPipelineBuilder {
aggregator_selector: self.aggregator_selector,
export_selector,
..self
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,
}
}

Expand Down

0 comments on commit c5bffdd

Please sign in to comment.