TelemetryDeck

Struct TelemetryDeck 

Source
pub struct TelemetryDeck {
    pub app_id: String,
    pub namespace: Option<String>,
    pub salt: Option<String>,
    pub default_params: HashMap<String, String>,
    pub session_id: String,
    /* private fields */
}
Expand description

TelemetryDeck API client

This is the main entry point for sending telemetry signals to TelemetryDeck. The client handles session management, user identifier hashing, and HTTP communication.

§Examples

§Basic Usage

use telemetrydeck_wasm::TelemetryDeck;

let client = TelemetryDeck::new("YOUR-APP-ID");
client.send("userLogin", Some("user@example.com"), None, None, None);

§With Configuration

use telemetrydeck_wasm::TelemetryDeck;
use std::collections::HashMap;

let client = TelemetryDeck::new_with_config(
    "YOUR-APP-ID",
    Some("my-tenant".to_string()),  // namespace
    Some("random-salt-64-chars".to_string()),  // salt
    HashMap::new(),  // default params
);

§Platform Support

  • Native: Uses reqwest + tokio::spawn
  • WASM: Uses reqwasm + spawn_local

§Privacy

  • User identifiers are always SHA-256 hashed
  • Optional salt is concatenated after user ID before hashing
  • Session IDs are random UUIDs

Fields§

§app_id: String

Your TelemetryDeck App ID

§namespace: Option<String>

Optional namespace for multi-tenant deployments

When set, signals are sent to /v2/namespace/{namespace}/ instead of /v2/.

§salt: Option<String>

Optional salt for user identifier hashing

The salt is concatenated after the user identifier before SHA-256 hashing: hash(user_id + salt).

§Security Note

It is recommended to use a cryptographically random salt of at least 64 characters. The salt should be unique per application but consistent across all users of the same application.

§default_params: HashMap<String, String>

Default parameters appended to all outgoing signals

These are merged with per-signal parameters. The library version is automatically added as telemetryClientVersion.

§session_id: String

Current session identifier (UUID v4)

Generated automatically when the client is created. Can be reset using TelemetryDeck::reset_session.

Implementations§

Source§

impl TelemetryDeck

Source

pub fn new(app_id: &str) -> Self

Create a new instance with the specified application id

Source

pub fn new_with_config( app_id: &str, namespace: Option<String>, salt: Option<String>, params: HashMap<String, String>, ) -> Self

Create a new instance with the specified application id and configuration

§Examples
use telemetrydeck_wasm::TelemetryDeck;
use std::collections::HashMap;

// Create client with namespace for multi-tenant deployment
let client = TelemetryDeck::new_with_config(
    "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
    Some("my-namespace".to_string()),
    None,
    HashMap::new(),
);

// Create client with salt for enhanced user hashing
let client = TelemetryDeck::new_with_config(
    "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
    None,
    Some("your-64-char-random-salt-here".to_string()),
    HashMap::new(),
);

// Create client with default parameters
let mut defaults = HashMap::new();
defaults.insert("environment".to_string(), "production".to_string());
let client = TelemetryDeck::new_with_config(
    "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
    None,
    None,
    defaults,
);
Source

pub fn reset_session(&mut self, new_session_id: Option<String>)

Reset the session id for future signals

Source§

impl TelemetryDeck

Source

pub fn send( &self, signal_type: &str, client_user: Option<&str>, payload: Option<HashMap<String, String>>, is_test_mode: Option<bool>, float_value: Option<f64>, )

Send a telemetry signal (fire-and-forget)

This method spawns an async task using tokio::spawn and never returns errors. The signal is sent in the background without blocking. Use send_sync if you need error handling.

§Parameters
  • signal_type - The type/name of the signal (e.g., “userLogin”, “buttonClick”)
  • client_user - Optional user identifier. Will be SHA-256 hashed automatically. If None, defaults to “rust”.
  • payload - Optional key-value parameters to attach to the signal
  • is_test_mode - Whether to mark this as a test signal. Defaults to false if None.
  • float_value - Optional floating-point value (useful for metrics like revenue, duration, etc.)
§Examples
use telemetrydeck_wasm::TelemetryDeck;

let client = TelemetryDeck::new("YOUR-APP-ID");

// Simple signal
client.send("buttonClick", None, None, None, None);

// With user
client.send("userLogin", Some("user@example.com"), None, None, None);

// With float value for revenue tracking
client.send("purchase", Some("user123"), None, None, Some(49.99));
use telemetrydeck_wasm::TelemetryDeck;
use std::collections::HashMap;

let client = TelemetryDeck::new("YOUR-APP-ID");

let mut params = HashMap::new();
params.insert("screen".to_string(), "settings".to_string());
params.insert("action".to_string(), "toggle".to_string());

client.send("userAction", Some("user"), Some(params), None, None);
§Platform Note

On native platforms, this requires a tokio runtime to be running.

Source

pub async fn send_sync( &self, signal_type: &str, client_user: Option<&str>, payload: Option<HashMap<String, String>>, is_test_mode: Option<bool>, float_value: Option<f64>, ) -> Result<(), Box<dyn Error>>

Send a telemetry signal and return errors if any occur

This method waits for the HTTP request to complete and returns a Result. Use this when you need to know if the signal was sent successfully.

§Parameters
  • signal_type - The type/name of the signal (e.g., “userLogin”, “buttonClick”)
  • client_user - Optional user identifier. Will be SHA-256 hashed automatically. If None, defaults to “rust”.
  • payload - Optional key-value parameters to attach to the signal
  • is_test_mode - Whether to mark this as a test signal. Defaults to false if None.
  • float_value - Optional floating-point value (useful for metrics like revenue, duration, etc.)
§Returns
  • Ok(()) if the signal was sent successfully (HTTP 2xx status)
  • Err(...) if sending failed (network error, HTTP error, serialization error, etc.)
§Examples
use telemetrydeck_wasm::TelemetryDeck;

let client = TelemetryDeck::new("YOUR-APP-ID");

// Handle errors explicitly
match client.send_sync("criticalEvent", Some("user"), None, None, None).await {
    Ok(()) => println!("Signal sent successfully"),
    Err(e) => eprintln!("Failed to send: {}", e),
}

// Or use ? operator
client.send_sync("anotherEvent", None, None, None, None).await?;

Trait Implementations§

Source§

impl Debug for TelemetryDeck

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> 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: 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: 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, 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
Source§

impl<T> ErasedDestructor for T
where T: 'static,