Skip to content

Commit

Permalink
rust: switch to batch exporter for telemetry
Browse files Browse the repository at this point in the history
SimpleExporter sends Span once they end and does not seem to be
compatible from Tokio runtime
Switch to BatchedSpanProcessor using Tokio runtime to fix the runtime
errors when using mobility pipeline and to enhance performances

Signed-off-by: Nicolas Buffon <[email protected]>
  • Loading branch information
nbuffon committed Sep 20, 2024
1 parent b4a98e2 commit 0c5938c
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions rust/src/transport/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ use opentelemetry::trace::{Link, TraceContextExt, Tracer};
use opentelemetry::{global, Context, KeyValue};
use opentelemetry_otlp::WithExportConfig;
use opentelemetry_sdk::propagation::TraceContextPropagator;
use opentelemetry_sdk::trace::{RandomIdGenerator, Sampler, TracerProvider};
use opentelemetry_sdk::runtime;
use opentelemetry_sdk::trace::{
BatchConfigBuilder, BatchSpanProcessor, RandomIdGenerator, Sampler, TracerProvider,
};
use opentelemetry_sdk::Resource;

use crate::client::configuration::telemetry_configuration::TelemetryConfiguration;
Expand Down Expand Up @@ -47,8 +50,16 @@ pub fn init_tracer(
.with_timeout(Duration::from_secs(3))
.build_span_exporter()?;

let batch_processor = BatchSpanProcessor::builder(http_exporter, runtime::Tokio)
.with_batch_config(
BatchConfigBuilder::default()
.with_max_queue_size(configuration.batch_size)
.build(),
)
.build();

let tracer_provider = TracerProvider::builder()
.with_simple_exporter(http_exporter)
.with_span_processor(batch_processor)
.with_config(
opentelemetry_sdk::trace::config()
.with_sampler(Sampler::AlwaysOn)
Expand Down

0 comments on commit 0c5938c

Please sign in to comment.