grow-graylog 0.2.0

Rust SDK for Graylog Open by Grow Codes
Documentation
// Generated by sdk-kit 0.3.0 — do not edit; change sdk-kit and run "sdk-kit sync"
//! Logging category (SPEC §4): records, batching, redaction, the [`Logger`] facade, the query
//! model and framework adapters.
//!
//! A service package implements [`LogExporter`] (and [`LogQueryClient`] when the service can be
//! queried); this module turns it into a [`LogClient`] through [`BatchingLogClient`].
//!
//! ```no_run
//! # use std::sync::Arc;
//! # use grow_graylog::logging::*;
//! # async fn demo(exporter: Arc<dyn LogExporter>) -> grow_graylog::Result<()> {
//! let client = BatchingLogClient::builder(exporter)
//!     .resource_attribute("service.name", "checkout")
//!     .build()?;
//! let log = client.logger(Some("http"), Attributes::new());
//! log.info("listening", attrs! { "port" => 8080 });
//! client.close().await?;
//! # Ok(()) }
//! ```

mod batch;
mod client;
mod exporter;
mod init;
mod query;
pub mod record;
mod redaction;

#[cfg(feature = "log-bridge")]
mod bridge;
#[cfg(feature = "tracing-layer")]
mod layer;

pub use batch::{
    BatchOptions, BatchProcessor, BatchStats, DropCallback, DropPolicy, DropReason, ErrorCallback,
};
pub use client::{BatchingLogClient, BatchingLogClientBuilder, LogClient, LogEntry, Logger};
pub use exporter::{ExportOptions, ExportResult, LogExporter};
pub use init::{
    connect_log_client, current_request_id, init_logging, with_request_id, InitOptions, LineWriter,
    LogConnection, LogConnector, LoggingHandle, LOG_SHIPPED_FIELD,
};
pub use query::{
    poll_tail, wait_for_log, LogQueryClient, LogSearchResult, RecordCallback, RecordPredicate,
    SearchOptions, SortOrder, TailHandle, TailOptions, WaitOptions,
};
pub use record::{
    format_timestamp, parse_timestamp, AttrValue, Attributes, LogInput, LogRecord, Severity,
};
pub use redaction::{RedactionProcessor, DEFAULT_REDACT_KEYS};

#[cfg(feature = "log-bridge")]
pub use bridge::LogBridge;
#[cfg(feature = "tracing-layer")]
pub use layer::LogLayer;

/// Builds an [`Attributes`] map: `attrs! { "user" => "ada", "n" => 3 }`.
#[macro_export]
macro_rules! attrs {
    () => { $crate::logging::Attributes::new() };
    ($($k:expr => $v:expr),+ $(,)?) => {{
        let mut m = $crate::logging::Attributes::new();
        $( m.insert(::std::string::String::from($k), $crate::logging::AttrValue::from($v)); )+
        m
    }};
}
pub use crate::attrs;

/// Returns `(traceId, spanId, traceFlags)` of the active OpenTelemetry span, if any.
pub(crate) fn active_trace_context() -> Option<(String, String, u8)> {
    use opentelemetry::trace::TraceContextExt;
    let cx = opentelemetry::Context::current();
    let span = cx.span();
    let sc = span.span_context();
    if !sc.is_valid() {
        return None;
    }
    Some((
        sc.trace_id().to_string(),
        sc.span_id().to_string(),
        sc.trace_flags().to_u8(),
    ))
}