opentelemetry_sdk/export/logs/
mod.rs

1//! Log exporters
2use crate::logs::LogRecord;
3use crate::Resource;
4use async_trait::async_trait;
5#[cfg(feature = "logs_level_enabled")]
6use opentelemetry::logs::Severity;
7use opentelemetry::{
8    logs::{LogError, LogResult},
9    InstrumentationLibrary,
10};
11use std::borrow::Cow;
12use std::fmt::Debug;
13
14/// `LogExporter` defines the interface that log exporters should implement.
15#[async_trait]
16pub trait LogExporter: Send + Sync + Debug {
17    /// Exports a batch of [`LogData`].
18    async fn export<'a>(&mut self, batch: Vec<Cow<'a, LogData>>) -> LogResult<()>;
19    /// Shuts down the exporter.
20    fn shutdown(&mut self) {}
21    #[cfg(feature = "logs_level_enabled")]
22    /// Chek if logs are enabled.
23    fn event_enabled(&self, _level: Severity, _target: &str, _name: &str) -> bool {
24        true
25    }
26    /// Set the resource for the exporter.
27    fn set_resource(&mut self, _resource: &Resource) {}
28}
29
30/// `LogData` represents a single log event without resource context.
31#[derive(Clone, Debug)]
32pub struct LogData {
33    /// Log record
34    pub record: LogRecord,
35    /// Instrumentation details for the emitter who produced this `LogEvent`.
36    pub instrumentation: InstrumentationLibrary,
37}
38
39/// Describes the result of an export.
40pub type ExportResult = Result<(), LogError>;