Skip to main content

Hook0Client

Struct Hook0Client 

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

The Hook0 client

This struct is supposed to be initialized once and shared/reused wherever you need to send events in your app.

Implementations§

Source§

impl Hook0Client

Source

pub fn new( api_url: Url, application_id: Uuid, token: &str, ) -> Result<Self, Hook0ClientError>

Initialize a client

  • api_url - Base API URL of a Hook0 instance (example: https://app.hook0.com/api/v1).
  • application_id - UUID of your Hook0 application.
  • token - Authentication token valid for your Hook0 application.
Source

pub fn api_url(&self) -> &Url

Get the API URL of this client

Source

pub fn application_id(&self) -> &Uuid

Get the application ID of this client

Source

pub fn with_retry_policy(self, retry_policy: RetryPolicy) -> Self

Change how this client retries a send that failed in a way a repetition could fix

Pass RetryPolicy::disabled to send each event exactly once.

Source

pub fn retry_policy(&self) -> &RetryPolicy

Get the retry policy of this client

Source

pub fn with_request_timeout(self, request_timeout: StdDuration) -> Self

Change how long one attempt at reaching Hook0 is given before it is abandoned

The timeout applies to each attempt, not to the send as a whole.

Source

pub fn request_timeout(&self) -> StdDuration

Get the timeout this client gives one attempt at reaching Hook0

Source

pub fn with_max_payload_bytes(self, max_payload_bytes: usize) -> Self

Change the largest event payload this client agrees to send

An event whose payload is larger is refused before any request is issued.

Source

pub fn max_payload_bytes(&self) -> usize

Get the largest event payload this client agrees to send

Source

pub fn with_max_response_bytes(self, max_response_bytes: usize) -> Self

Change the largest answer this client agrees to read off the socket

An answer whose body is larger is abandoned where it crossed the ceiling, and the attempt fails rather than holding whatever the other end decided to write.

Source

pub fn max_response_bytes(&self) -> usize

Get the largest answer this client agrees to read off the socket

Source

pub async fn send_event( &self, event: &Event<'_>, ) -> Result<Uuid, Hook0ClientError>

Send an event to Hook0

The event is sent under an ID this client knows: the one set on the event, or a UUIDv7 this client generates when the event carries none. Because Hook0 keys events on that ID, a request that is repeated after a network failure or a server error ingests the event once, not twice — which is what makes retrying safe.

A send is bounded on five axes, each of them configurable: Hook0Client::with_max_payload_bytes rules an oversized payload out before anything is sent, Hook0Client::with_request_timeout bounds one attempt, Hook0Client::with_max_response_bytes bounds what an answer may cost to read, RetryPolicy::max_attempts bounds how many attempts are made, and RetryPolicy::max_total_delay bounds the time spent waiting between them.

A network failure, a server error and an instance that is pacing its requests are retried; anything Hook0 refuses outright — a spent quota included, which no delay this send can afford would clear — is reported as is. When the answer names how long to wait before the request becomes servable again, that delay is waited out instead of this client’s own schedule, cut down to what is left of RetryPolicy::max_total_delay.

A retried request that Hook0 answers with EventAlreadyIngested reports success: an earlier attempt of this very send reached the API, and the event carries the ID returned here. That answer to a first attempt is a genuine conflict and is reported as an error.

Source

pub async fn upsert_event_types( &self, event_types: &[&str], ) -> Result<Vec<String>, Hook0ClientError>

Ensure the configured app has the right event types or create them

Returns the list of event types that were created, if any.

Trait Implementations§

Source§

impl Clone for Hook0Client

Source§

fn clone(&self) -> Hook0Client

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 Debug for Hook0Client

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = !

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