From 7d702a31688a30cc210e6ed3e8a535e7da86b540 Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Wed, 30 Oct 2024 11:56:41 +0100 Subject: [PATCH] core: increate batch configuration This should solve the error that we start to see on some application and possibly should solve some crash that we noted somewhere ``` OpenTelemetry log error occurred. cannot send message to batch processor as the channel is full ``` Link: https://github.com/open-telemetry/opentelemetry-rust/issues/2177 Signed-off-by: Vincenzo Palazzo --- src/log.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/log.rs b/src/log.rs index 98422b9..a8aeb66 100644 --- a/src/log.rs +++ b/src/log.rs @@ -8,12 +8,14 @@ //! - `http_exporter`: Creates a new HTTP exporter builder for OpenTelemetry. use std::str::FromStr; use std::sync::Arc; +use std::time::Duration; use opentelemetry::KeyValue; use opentelemetry_appender_log::OpenTelemetryLogBridge; use opentelemetry_otlp::HttpExporterBuilder; use opentelemetry_otlp::Protocol; use opentelemetry_otlp::WithExportConfig; +use opentelemetry_sdk::logs::BatchConfigBuilder; use opentelemetry_sdk::Resource; use crate::Opentelemetry; @@ -25,12 +27,20 @@ pub fn init( level: &str, exporter_endpoint: &str, ) -> anyhow::Result<()> { + // FIXME: make this configurable from the API level + let batch_config = BatchConfigBuilder::default() + .with_max_export_timeout(Duration::from_secs(1)) + .with_max_queue_size(10_000) + .with_max_export_batch_size(100_000); + let batch_config = batch_config.build(); + let logger_provider = opentelemetry_otlp::new_pipeline() .logging() .with_resource(Resource::new(vec![KeyValue::new( opentelemetry_semantic_conventions::resource::SERVICE_NAME, tag, )])) + .with_batch_config(batch_config) .with_exporter( http_exporter() .with_protocol(Protocol::HttpBinary) //can be changed to `Protocol::HttpJson` to export in JSON format