Struct BatchLogProcessor
pub struct BatchLogProcessor { /* private fields */ }Expand description
The BatchLogProcessor collects finished logs in a buffer and exports them
in batches to the configured LogExporter. This processor is ideal for
high-throughput environments, as it minimizes the overhead of exporting logs
individually. It uses a dedicated background thread to manage and export logs
asynchronously, ensuring that the application’s main execution flow is not blocked.
This processor supports the following configurations:
- Queue size: Maximum number of log records that can be buffered.
- Batch size: Maximum number of log records to include in a single export.
- Scheduled delay: Frequency at which the batch is exported.
When using this processor with the OTLP Exporter, the following exporter features are supported:
grpc-tonic: RequiresLoggerProviderto be created within a tokio runtime.reqwest-blocking-client: Works with a regularmainortokio::main.
In other words, other clients like reqwest and hyper are not supported.
BatchLogProcessor buffers logs in memory and exports them in batches. An
export is triggered when max_export_batch_size is reached or every
scheduled_delay milliseconds. Users can explicitly trigger an export using
the force_flush method. Shutdown also triggers an export of all buffered
logs and is recommended to be called before the application exits to ensure
all buffered logs are exported.
Warning: When using tokio’s current-thread runtime, shutdown(), which
is a blocking call ,should not be called from your main thread. This can
cause deadlock. Instead, call shutdown() from a separate thread or use
tokio’s spawn_blocking.
§Using a BatchLogProcessor:
use opentelemetry_sdk::logs::{BatchLogProcessor, BatchConfigBuilder, SdkLoggerProvider};
use opentelemetry::global;
use std::time::Duration;
use opentelemetry_sdk::logs::InMemoryLogExporter;
let exporter = InMemoryLogExporter::default(); // Replace with an actual exporter
let processor = BatchLogProcessor::builder(exporter)
.with_batch_config(
BatchConfigBuilder::default()
.with_max_queue_size(2048)
.with_max_export_batch_size(512)
.with_scheduled_delay(Duration::from_secs(5))
.build(),
)
.build();
let provider = SdkLoggerProvider::builder()
.with_log_processor(processor)
.build();Implementations§
§impl BatchLogProcessor
impl BatchLogProcessor
pub fn builder<E>(exporter: E) -> BatchLogProcessorBuilder<E>where
E: LogExporter,
pub fn builder<E>(exporter: E) -> BatchLogProcessorBuilder<E>where
E: LogExporter,
Create a new batch processor builder
Trait Implementations§
§impl Debug for BatchLogProcessor
impl Debug for BatchLogProcessor
§impl LogProcessor for BatchLogProcessor
impl LogProcessor for BatchLogProcessor
§fn emit(
&self,
record: &mut SdkLogRecord,
instrumentation: &InstrumentationScope,
)
fn emit( &self, record: &mut SdkLogRecord, instrumentation: &InstrumentationScope, )
§fn force_flush(&self) -> Result<(), OTelSdkError>
fn force_flush(&self) -> Result<(), OTelSdkError>
§fn shutdown_with_timeout(&self, timeout: Duration) -> Result<(), OTelSdkError>
fn shutdown_with_timeout(&self, timeout: Duration) -> Result<(), OTelSdkError>
§fn set_resource(&mut self, resource: &Resource)
fn set_resource(&mut self, resource: &Resource)
§fn shutdown(&self) -> Result<(), OTelSdkError>
fn shutdown(&self) -> Result<(), OTelSdkError>
Auto Trait Implementations§
impl !Freeze for BatchLogProcessor
impl RefUnwindSafe for BatchLogProcessor
impl Send for BatchLogProcessor
impl Sync for BatchLogProcessor
impl Unpin for BatchLogProcessor
impl UnwindSafe for BatchLogProcessor
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy that returns Action::Follow only if self and other return
Action::Follow. Read more