Rust SDK

Install the Logdash Rust SDK, send your first log and your first metric.

Install the package, paste your API key and the first log lands in the dashboard within a second. Everything below is copied from the Rust SDK README.

Install

cargo add logdash

Initialise

Create a project in Logdash, copy its API key and keep it in an environment variable. The key identifies the project the data lands in.

// Config::default() reads LOGDASH_API_KEY from the environment.
let (logger, metrics) = logdash::create_logdash(logdash::Config::default());

Send a log

let (logger, _) = logdash::create_logdash(logdash::Config::default());

// Send an info log message
logger.info("Rust SDK example");

Send a metric

Metrics are named numbers. Set one to an absolute value or mutate it by a delta, and Logdash charts the history.

let (_, metrics) = logdash::create_logdash(logdash::Config::default());

// create a metric
metrics.set("users".into(), 0.0);

// or increment / decrement by
metrics.mutate("users".into(), 1.0);

Works with

  • Axum
  • Actix Web
  • Rocket
  • Tokio
  • CLI binaries

FAQ

Where does it read the API key from?

`logdash::Config::default()` picks up `LOGDASH_API_KEY` from the environment. To pass it explicitly, use `logdash::Config::default().api_key("your-api-key".into())`.

What does create_logdash return?

A `(logger, metrics)` tuple. Destructure the half you need and drop the other with `_`.

What types do metric names and values take?

The name is an owned string, so pass `"users".into()`, and the value is a float: `metrics.set("users".into(), 0.0)`.