Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow users to use custom export kind selector. #526

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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