pub struct BetterStackClient { /* private fields */ }Expand description
Async client for Better Stack Logs. Cheap to clone (clones share the connections).
It talks to two hosts with separate credentials and transports: the source’s ingesting host
(log_client, exporter,
otlp_exporter) and the SQL query host (query). A
source token is never sent to the query host and SQL credentials never to the ingest host.
use grow_better_stack_logs::logging::{attrs, LogClient};
use grow_better_stack_logs::{BetterStackClient, LogClientOptions};
let client = BetterStackClient::from_env()?;
let logs = client.log_client(LogClientOptions::default().resource_attribute("service.name", "checkout"))?;
logs.logger(None, attrs! {}).info("order placed", attrs! { "order_id" => 42 });
client.close().await;Implementations§
Source§impl BetterStackClient
impl BetterStackClient
Sourcepub fn new(config: BetterStackConfig) -> Result<Self>
pub fn new(config: BetterStackConfig) -> Result<Self>
Creates a client from a configuration (CONFIG when invalid).
Sourcepub fn from_env() -> Result<Self>
pub fn from_env() -> Result<Self>
Creates a client from GROW_BETTER_STACK_LOGS_*, BETTERSTACK_SOURCE_TOKEN,
BETTERSTACK_INGESTING_HOST, BETTERSTACK_QUERY_* … environment variables.
Sourcepub fn config(&self) -> &BetterStackConfig
pub fn config(&self) -> &BetterStackConfig
The configuration in use.
Sourcepub fn ingest_transport(&self) -> Option<&HttpTransport>
pub fn ingest_transport(&self) -> Option<&HttpTransport>
The ingest transport (None without ingest credentials).
Sourcepub fn query_transport(&self) -> Option<&HttpTransport>
pub fn query_transport(&self) -> Option<&HttpTransport>
The SQL query transport (None without query credentials).
Sourcepub fn on_close<F>(&self, f: F)
pub fn on_close<F>(&self, f: F)
Registers work that BetterStackClient::close runs (flush, stop tails, …).
Sourcepub async fn health(&self) -> Result<HealthStatus>
pub async fn health(&self) -> Result<HealthStatus>
Unauthenticated liveness, without sending data. With a query host:
GET {query_url}/ping (Ok. → ok). Ingest-only: GET {url}/ without credentials;
any answer below 500 proves the host is reachable. details.endpoint is query or
ingest. Never fails except for CANCELLED and CONFIG.
Sourcepub async fn ping(&self) -> Result<Duration>
pub async fn ping(&self) -> Result<Duration>
Authenticated round trip; returns the latency. With query credentials:
SELECT count() AS c FROM remote(<source_table>_logs) WHERE 1 = 0 (or SELECT 1
without a source_table). Ingest-only: posts an empty batch [] (no event is stored).
Bad credentials → AUTHENTICATION.
Sourcepub async fn server_version(&self) -> Result<String>
pub async fn server_version(&self) -> Result<String>
Always UNSUPPORTED: Better Stack is a SaaS and exposes no service version (the query
host’s ClickHouse version is not one).
Sourcepub fn exporter(&self) -> Result<BetterStackLogExporter>
pub fn exporter(&self) -> Result<BetterStackLogExporter>
The HTTP ingest exporter with the configured encoding and default limits. CONFIG
without ingest credentials. Most users call log_client instead.
Sourcepub fn new_exporter(
&self,
opts: IngestExporterOptions,
) -> Result<BetterStackLogExporter>
pub fn new_exporter( &self, opts: IngestExporterOptions, ) -> Result<BetterStackLogExporter>
An HTTP ingest exporter with its own encoding and limits (use it with
log_client_with). CONFIG without ingest credentials,
VALIDATION for limits outside 1..=10 MiB.
Sourcepub fn otlp_exporter(&self) -> Result<BetterStackOtlpLogExporter>
pub fn otlp_exporter(&self) -> Result<BetterStackOtlpLogExporter>
The OTLP/HTTP logs exporter (protobuf). CONFIG without ingest credentials.
Sourcepub fn new_otlp_exporter(
&self,
opts: OtlpExporterOptions,
) -> Result<BetterStackOtlpLogExporter>
pub fn new_otlp_exporter( &self, opts: OtlpExporterOptions, ) -> Result<BetterStackOtlpLogExporter>
An OTLP/HTTP logs exporter with its own protocol (protobuf or JSON), scope and limit.
Sourcepub fn log_client(&self, opts: LogClientOptions) -> Result<BetterStackLogClient>
pub fn log_client(&self, opts: LogClientOptions) -> Result<BetterStackLogClient>
A batching BetterStackLogClient over the HTTP ingest API (default) or OTLP;
close flushes and closes it. Must be called inside a tokio runtime.
CONFIG without ingest credentials, CANCELLED after close.
Sourcepub fn log_client_with(
&self,
exporter: Arc<dyn LogExporter>,
opts: LogClientOptions,
) -> Result<BetterStackLogClient>
pub fn log_client_with( &self, exporter: Arc<dyn LogExporter>, opts: LogClientOptions, ) -> Result<BetterStackLogClient>
A batching BetterStackLogClient over any exporter (for example
otlp_exporter); close flushes and closes it.
Sourcepub fn query(&self) -> Result<BetterStackQuery>
pub fn query(&self) -> Result<BetterStackQuery>
The SQL query client. CONFIG without query credentials.
Sourcepub async fn close(&self)
pub async fn close(&self)
Flushes and closes every log client, stops running tails, then releases both transports. Idempotent.
Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
Whether BetterStackClient::close was called.
Trait Implementations§
Source§impl Clone for BetterStackClient
impl Clone for BetterStackClient
Source§impl CoreTarget for BetterStackClient
Available on crate feature testing only.
impl CoreTarget for BetterStackClient
testing only.