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
impl Hook0Client
Sourcepub fn new(
api_url: Url,
application_id: Uuid,
token: &str,
) -> Result<Self, Hook0ClientError>
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.
Sourcepub fn application_id(&self) -> &Uuid
pub fn application_id(&self) -> &Uuid
Get the application ID of this client
Sourcepub fn with_retry_policy(self, retry_policy: RetryPolicy) -> Self
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.
Sourcepub fn retry_policy(&self) -> &RetryPolicy
pub fn retry_policy(&self) -> &RetryPolicy
Get the retry policy of this client
Sourcepub fn with_request_timeout(self, request_timeout: StdDuration) -> Self
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.
Sourcepub fn request_timeout(&self) -> StdDuration
pub fn request_timeout(&self) -> StdDuration
Get the timeout this client gives one attempt at reaching Hook0
Sourcepub fn with_max_payload_bytes(self, max_payload_bytes: usize) -> Self
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.
Sourcepub fn max_payload_bytes(&self) -> usize
pub fn max_payload_bytes(&self) -> usize
Get the largest event payload this client agrees to send
Sourcepub fn with_max_response_bytes(self, max_response_bytes: usize) -> Self
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.
Sourcepub fn max_response_bytes(&self) -> usize
pub fn max_response_bytes(&self) -> usize
Get the largest answer this client agrees to read off the socket
Sourcepub async fn send_event(
&self,
event: &Event<'_>,
) -> Result<Uuid, Hook0ClientError>
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.
Sourcepub async fn upsert_event_types(
&self,
event_types: &[&str],
) -> Result<Vec<String>, Hook0ClientError>
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
impl Clone for Hook0Client
Source§fn clone(&self) -> Hook0Client
fn clone(&self) -> Hook0Client
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for Hook0Client
impl !UnwindSafe for Hook0Client
impl Freeze for Hook0Client
impl Send for Hook0Client
impl Sync for Hook0Client
impl Unpin for Hook0Client
impl UnsafeUnpin for Hook0Client
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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