Skip to main content

ClientOptionsBuilder

Struct ClientOptionsBuilder 

Source
pub struct ClientOptionsBuilder { /* private fields */ }
Expand description

Builder for ClientOptions.

Implementations§

Source§

impl ClientOptionsBuilder

Source

pub fn host<VALUE: Into<String>>(&mut self, value: VALUE) -> &mut Self

Host URL for the PostHog API. Defaults to the US ingestion endpoint. App hosts such as https://eu.posthog.com are normalized to ingestion hosts before requests are sent.

Source

pub fn api_key(&mut self, value: String) -> &mut Self

PostHog project API key (project token). If missing or blank, the client is disabled.

Source

pub fn request_timeout_seconds(&mut self, value: u64) -> &mut Self

Request timeout in seconds for capture, batch, and local evaluation definition requests. Defaults to 30.

Source

pub fn personal_api_key<VALUE: Into<String>>( &mut self, value: VALUE, ) -> &mut Self

Personal API key for fetching flag definitions. Required when enable_local_evaluation is true.

Source

pub fn enable_local_evaluation(&mut self, value: bool) -> &mut Self

Enable local evaluation of feature flags using a background definitions poller.

Source

pub fn poll_interval_seconds(&mut self, value: u64) -> &mut Self

Interval for polling flag definitions, in seconds. Defaults to 30.

Source

pub fn disabled(&mut self, value: bool) -> &mut Self

Disable tracking and remote flag requests. Useful for development and tests.

Source

pub fn disable_geoip(&mut self, value: bool) -> &mut Self

Disable automatic GeoIP enrichment for capture and flag requests.

Source

pub fn is_server(&mut self, value: bool) -> &mut Self

Whether events originate from a server-side runtime. Defaults to true, which stamps $is_server: true so PostHog won’t attribute the host OS to the user. Set false for client/CLI use (the property is then omitted).

Source

pub fn feature_flags_request_timeout_seconds(&mut self, value: u64) -> &mut Self

Timeout in seconds for remote /flags requests. Defaults to 3.

Source

pub fn feature_flags_request_max_retries(&mut self, value: u32) -> &mut Self

Maximum number of retries after a transient remote /flags failure (transport error or HTTP 502/504). Defaults to 1. Set to 0 to disable retries.

Source

pub fn error_tracking(&mut self, value: ErrorTrackingOptions) -> &mut Self

Error tracking stacktrace and frame classification options

Source

pub fn local_evaluation_only(&mut self, value: bool) -> &mut Self

When true, never fall back to the remote API for flag evaluation. If local evaluation is inconclusive (flag not cached or missing properties), the SDK returns Ok(None) instead of making a network call. Only meaningful when enable_local_evaluation is also true.

Source

pub fn max_capture_attempts(&mut self, value: u32) -> &mut Self

Maximum number of attempts for V1 capture requests (default: 3). Includes the initial attempt, so 3 means 1 initial + 2 retries.

Source

pub fn retry_initial_backoff_ms(&mut self, value: u64) -> &mut Self

Initial retry backoff duration in milliseconds (default: 200)

Source

pub fn retry_max_backoff_ms(&mut self, value: u64) -> &mut Self

Maximum retry backoff duration in milliseconds (default: 30000)

Source

pub fn flush_at(&mut self, value: usize) -> &mut Self

Number of buffered events that triggers an automatic flush (default: 100).

Source

pub fn max_batch_size(&mut self, value: usize) -> &mut Self

Maximum number of events sent in a single batch request (default: 100). A flush of more than this many events is split into multiple requests.

Source

pub fn flush_interval_ms(&mut self, value: u64) -> &mut Self

Interval between automatic time-based flushes, in milliseconds (default: 5000).

Source

pub fn max_queue_size(&mut self, value: usize) -> &mut Self

Maximum number of events buffered before new events are dropped (default: 10000). A single warning is logged while the queue is full.

Source

pub fn shutdown_timeout_ms(&mut self, value: u64) -> &mut Self

Maximum time shutdown() and Drop spend draining buffered and retrying events before abandoning the rest, in milliseconds (default: 30000). This bounds the drain itself, including any delivery the drain starts. It does not bound work already underway: the single background worker performs one blocking send at a time, so an automatic flush or drain in progress when shutdown is requested runs to completion first — up to request_timeout_seconds per in-flight batch, so a large auto-drain can delay teardown by several request timeouts. flush() is unaffected.

Source

pub fn capture_compression(&mut self, value: CaptureCompression) -> &mut Self

Optional request-body compression. When None (default), bodies are sent uncompressed. The V0 pipeline supports Gzip only; V1 supports all variants.

Source§

impl ClientOptionsBuilder

Source

pub fn before_send<F>(&mut self, hook: F) -> &mut Self
where F: FnMut(Event) -> Option<Event> + Send + 'static,

Add a hook that can modify or discard events before they are sent.

Hooks should avoid panicking. Panics are caught and drop the current event, but any mutable state captured by the hook may be left partially updated and will be reused on subsequent calls.

Source

pub fn on_error<F>(&mut self, hook: F) -> &mut Self
where F: Fn(&PostHogError<'_>) + Send + Sync + 'static,

Add a hook invoked once per terminal failure on an SDK network surface.

The hook receives a PostHogError for a capture batch the SDK gave up delivering, a failed remote /flags request, or a failed local-evaluation poll. Multiple hooks fire in registration order.

§Observability only — never emit from the hook

The hook MUST NOT call back into the SDK (capture/capture_batch/ capture_exception, flush, or shutdown): emitting an event while handling a capture failure forms an amplification loop. The hook is Fn + Send + Sync and invoked without holding any SDK lock, so it may run concurrently on multiple threads and must be internally thread-safe. Keep it cheap and non-blocking; the capture hook runs on the background transport thread. Panics are caught and ignored.

Registering a hook silences the default WARN for terminal capture reject/exhaustion and serialization failures (the caller now owns that signal). Shutdown-timeout, queue-full, and before_send drops keep their WARN logs and do not fire the hook — they are not delivery failures. The existing /flags and poller WARN logs are unaffected.

Source

pub fn build(&self) -> Result<ClientOptions, ClientOptionsBuilderError>

Build sanitized ClientOptions.

Missing or whitespace-only API keys are allowed and disable the client so SDK initialization remains infallible while avoiding requests with an empty API key.

§Errors

Returns ClientOptionsBuilderError if a required builder value is invalid according to the generated builder.

Trait Implementations§

Source§

impl Clone for ClientOptionsBuilder

Source§

fn clone(&self) -> ClientOptionsBuilder

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 Default for ClientOptionsBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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