Skip to main content

grow_better_stack_logs/
lib.rs

1// Skeleton created by sdk-kit 0.1.0; owned by this repository (edit freely).
2//! # grow-better-stack-logs
3//!
4//! Rust SDK for [Better Stack Logs](https://grow-codes-packages.github.io/better-stack-logs/) by
5//! Grow Codes. Not affiliated with Better Stack, Inc.
6//!
7//! Better Stack has two hosts with separate credentials: the source's **ingesting host**
8//! (source token, `POST /` with JSON / NDJSON / MessagePack, or OTLP `/v1/logs`) and the
9//! **SQL query host** (ClickHouse HTTP interface with a connection's username and password).
10//!
11//! ```no_run
12//! # async fn demo() -> grow_better_stack_logs::Result<()> {
13//! use grow_better_stack_logs::logging::{attrs, LogClient};
14//! use grow_better_stack_logs::{BetterStackClient, LogClientOptions, SearchLogsOptions};
15//!
16//! let client = BetterStackClient::from_env()?;
17//! let logs = client.log_client(LogClientOptions::default())?;
18//! logs.logger(None, attrs! {}).info("order placed", attrs! { "order_id" => 42 });
19//! logs.flush(None).await?;
20//!
21//! let found = client
22//!     .query()?
23//!     .search_logs(SearchLogsOptions::default().contains("order placed"))
24//!     .await?;
25//! println!("{} records", found.records.len());
26//! client.close().await;
27//! # Ok(())
28//! # }
29//! ```
30//!
31//! Features: `blocking` (a blocking client), `testing` (in-memory fakes and the conformance
32//! runner), `tracing-layer` and `log-bridge` (logging adapters, on by default).
33#![cfg_attr(docsrs, feature(doc_cfg))]
34
35pub mod core;
36
37mod client;
38mod config;
39mod encoding;
40mod exporter;
41mod http;
42mod otlp;
43mod query;
44
45#[cfg(feature = "blocking")]
46#[cfg_attr(docsrs, doc(cfg(feature = "blocking")))]
47pub mod blocking;
48
49#[cfg(feature = "testing")]
50#[cfg_attr(docsrs, doc(cfg(feature = "testing")))]
51pub mod testing;
52
53pub mod logging;
54
55pub use crate::core::{Error, ErrorCode, HealthStatus, Result, RetryPolicy, Secret};
56
57pub use crate::client::{BetterStackClient, BetterStackLogClient, LogClientOptions, LogProtocol};
58pub use crate::config::{
59    is_valid_identifier, normalize_base_url, BetterStackConfig, BetterStackConfigBuilder, Encoding,
60    DEFAULT_URL, VENDOR_QUERY_PASSWORD_VARS, VENDOR_QUERY_URL_VARS, VENDOR_QUERY_USERNAME_VARS,
61    VENDOR_SOURCE_TABLE_VARS, VENDOR_SOURCE_TOKEN_VARS, VENDOR_URL_VARS,
62};
63pub use crate::encoding::{
64    encode_event, encode_msgpack, encode_record, format_event_time, frame, to_better_stack_event,
65};
66pub use crate::exporter::{
67    BetterStackLogExporter, IngestExporterOptions, SendEventsOptions, MAX_RECORD_BYTES,
68    MAX_REQUEST_BYTES,
69};
70pub use crate::http::{
71    clickhouse_code, code_for_clickhouse, error_for_clickhouse, map_ingest_error, map_query_error,
72};
73pub use crate::otlp::{
74    encode_otlp_protobuf, otlp_json_request, parse_partial_success, BetterStackOtlpLogExporter,
75    OtlpExporterOptions, OtlpPartialSuccess, OtlpProtocol, DEFAULT_SCOPE_NAME, OTLP_LOGS_PATH,
76};
77pub use crate::query::{
78    escape_param_value, format_datetime64, json_escape, log_record_from_row, parse_datetime,
79    parse_rows, sql_string, BetterStackQuery, QueryOptions, QueryParam, QueryParams, QueryRow,
80    SearchLogsOptions, DEFAULT_SEARCH_LIMIT, MAX_SEARCH_LIMIT,
81};
82
83/// Service-prefixed alias of [`Error`].
84pub type BetterStackError = Error;