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");
}
Highlight::capture_error
Highlight::capture_error reports an error and its corresponding stack trace to Highlight.
Method Parameters
errorError
required
The error being reported to Highlight.
let x = match do_something() {
Ok(x) => x,
Err(e) => h.capture_error(&e),
};
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
error&dyn Error
required
The error being reported to Highlight.
session_idOption<String>
optional
A randomized id representing the Highlight session in which an error was thrown. This can be parsed from the network request's headers.
request_idOption<String>
optional
A randomized id generated by the Highlight client representing the request for which an error was thrown. This can be parsed from the network request's headers.
let x = match do_something() {
Ok(x) => x,
Err(e) => h.capture_error_with_session(&e, session_id, request_id)
};
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
name string-like (impl Into<Cow<'static, str>>)
required
Custom span name
Method Return
span
Returns a span
use highlightio::SpanTrait as _;
let span = h.span("custom-span-name");
span.end();
Highlight::project_id
Highlight::project_id returns your project ID. This can help with making custom framework integrations.
Method Return
project_id
The project ID specified in the config.
let project_id = h.project_id();
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();