Star us on GitHub
Star
Menu

Rust SDK API Reference

Rust SDK

Highlight's Rust SDK makes it easy to monitor errors and metrics on your Rust backend.

Just getting started?

Check out our getting started guide to get up and running quickly.

Highlight::init

Highlight::init() initializes the Highlight backend SDK.

Method Parameters
use highlightio::{Highlight, HighlightConfig}; fn main() { let h = Highlight::init(HighlightConfig { project_id: "<YOUR_PROJECT_ID>".to_string(), service_name: "my-rust-app".to_string(), service_version: "git-sha".to_string(), ..Default::default() }).expect("Failed to initialize Highlight.io"); }
Copy

Highlight::capture_error

Highlight::capture_error reports an error and its corresponding stack trace to Highlight.

Method Parameters
let x = match do_something() { Ok(x) => x, Err(e) => h.capture_error(&e), };
Copy

Highlight::capture_error_with_session

Highlight::capture_error_with_session reports an error and its corresponding stack trace to Highlight, along with the specified session_id and request_id properties.. The session_id and request_id properties are Highlight ids used to link an error to the session in which the error was thrown. These properties are sent via a header and included in every request to your backend once the Highlight client is initialized.

Method Parameters
let x = match do_something() { Ok(x) => x, Err(e) => h.capture_error_with_session(&e, session_id, request_id) };
Copy

Highlight::span

Highlight::span returns a span that carries all of the current Open Telemetry context as its parent span. You can end it with end() by importing highlightio::SpanTrait.

Method Parameters
Method Return
use highlightio::SpanTrait as _; let span = h.span("custom-span-name"); span.end();
Copy

Highlight::project_id

Highlight::project_id returns your project ID. This can help with making custom framework integrations.

Method Return
let project_id = h.project_id();
Copy

Highlight::shutdown

Highlight::shutdown gracefully shuts down the Highlight loggers and tracers, making sure that all your logs and traces get delivered to the server before your app exists. You should always call Highlight::shutdown before your app is exited.

h.shutdown();
Copy