Skip to main content

BetterStackClient

Struct BetterStackClient 

Source
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

Source

pub fn new(config: BetterStackConfig) -> Result<Self>

Creates a client from a configuration (CONFIG when invalid).

Source

pub fn from_env() -> Result<Self>

Creates a client from GROW_BETTER_STACK_LOGS_*, BETTERSTACK_SOURCE_TOKEN, BETTERSTACK_INGESTING_HOST, BETTERSTACK_QUERY_* … environment variables.

Source

pub fn config(&self) -> &BetterStackConfig

The configuration in use.

Source

pub fn ingest_transport(&self) -> Option<&HttpTransport>

The ingest transport (None without ingest credentials).

Source

pub fn query_transport(&self) -> Option<&HttpTransport>

The SQL query transport (None without query credentials).

Source

pub fn on_close<F>(&self, f: F)
where F: FnOnce() -> BoxFuture<'static, ()> + Send + 'static,

Registers work that BetterStackClient::close runs (flush, stop tails, …).

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

pub fn otlp_exporter(&self) -> Result<BetterStackOtlpLogExporter>

The OTLP/HTTP logs exporter (protobuf). CONFIG without ingest credentials.

Source

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.

Source

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.

Source

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.

Source

pub fn query(&self) -> Result<BetterStackQuery>

The SQL query client. CONFIG without query credentials.

Source

pub async fn close(&self)

Flushes and closes every log client, stops running tails, then releases both transports. Idempotent.

Source

pub fn is_closed(&self) -> bool

Whether BetterStackClient::close was called.

Trait Implementations§

Source§

impl Clone for BetterStackClient

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl CoreTarget for BetterStackClient

Available on crate feature testing only.
Source§

fn health<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<HealthStatus>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Unauthenticated liveness check.
Source§

fn ping<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Duration>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Authenticated round trip.
Source§

fn server_version<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Server version string.
Source§

fn close<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Releases the target; idempotent.
Source§

impl Debug for BetterStackClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more