Skip to content
useEventStack 0.3.0 is live.Read the quickstart

Reference

Async Rust client for event ingestion and management

Use the useeventstack-sdk crate to emit typed events, query workflows, manage custom actions, and replay events from Rust.

Installation

[dependencies]
useeventstack-sdk = "0.3"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
uuid = { version = "1", features = ["v4"] }
serde_json = "1"

Crate version 0.3.0. Built on reqwest with rustls-tls, so it does not link OpenSSL. The SDK is MIT licensed; the platform itself is not open source.

Client construction

use useeventstack_sdk::UseEventStackClient;
use uuid::Uuid;

let client = UseEventStackClient::builder(std::env::var("USEEVENTSTACK_API_KEY")?)
    .base_url("http://localhost:3001")
    .project_id(Uuid::parse_str(&std::env::var("USEEVENTSTACK_PROJECT_ID")?)?)
    .organization_id(Uuid::parse_str(&std::env::var("USEEVENTSTACK_ORGANIZATION_ID")?)?)
    .build()?;

// Shorthand:
let client = UseEventStackClient::new("useeventstack_key", project_id)?;

// Sandbox copy:
let sandbox = client.sandbox();

project_id is required. Build fails with UseEventStackError::MissingProjectId or MissingApiKey if validation fails.

Emit events

Typed event

use useeventstack_sdk::DeploymentCompleted;

let event = client.emit(DeploymentCompleted {
    service: "api".to_owned(),
    version: "2.1.0".to_owned(),
    environment: "production".to_owned(),
    status: "healthy".to_owned(),
}).await?;

println!("Event: {}", event.id);

Custom event

use useeventstack_sdk::CustomEvent;
use serde_json::json;

let event = client.emit(CustomEvent {
    event_type: "order.placed".to_owned(),
    payload: json!({"order_id": "ord_123", "total": 99.99}),
}).await?;

Idempotent emission

let event = client.emit_with_idempotency_key(
    DeploymentCompleted { /* ... */ },
    "deploy-api-2.1.0",
).await?;

Query and manage

AreaMethods
Eventsemit, emit_with_idempotency_key, query_events
Workflowsquery_workflows, workflow_graph, list_workflows, get_workflow, create_workflow, update_workflow, delete_workflow, enable_workflow, disable_workflow
Custom Actionslist_custom_actions, get_custom_action, delete_custom_action, simulate_custom_action
Projectionsquery_projections
Replayreplay_single, replay_bulk
DLQlist_dead_letter_events
API Keyslist_api_keys, create_api_key, delete_api_key

Non-event methods return serde_json::Value.

Replay

use useeventstack_sdk::ReplayBulkOptions;

// Single event replay
client.replay_single(event_id).await?;

// Bulk replay
client.replay_bulk(ReplayBulkOptions {
    event_type: Some("payment.failed".to_string()),
    since: Some("2025-01-01T00:00:00Z".to_string()),
    skip_external_side_effects: true,
    limit: 50,
    ..Default::default()
}).await?;

Error handling

use useeventstack_sdk::UseEventStackError;

match client.emit(event).await {
    Ok(event) => println!("Success: {}", event.id),
    Err(UseEventStackError::Api { status, code, message, .. }) => {
        eprintln!("API error {status} ({code}): {message}");
    }
    Err(UseEventStackError::InvalidEventType(t)) => {
        eprintln!("Bad event type: {t}");
    }
    Err(e) => eprintln!("Error: {e}"),
}

Error variants: MissingApiKey, MissingProjectId, InvalidEventType, Api (with status/code/message/details), Transport, Json.