Star us on GitHub
Star
Menu

Using highlight.io with actix-web

Learn how to set up highlight.io without a framework.
1
Add `tracingOrigins` to your client Highlight snippet.

This backend SDK requires one of the Highlight frontend SDKs to be installed, so please make sure you've followed the fullstack mapping guide first.

H.init("<YOUR_PROJECT_ID>", { tracingOrigins: ['localhost', 'example.myapp.com/backend'], networkRecording: { enabled: true, recordHeadersAndBody: true, }, });
Copy
2
Install the Highlight Rust actix SDK.

Add Highlight to your Config.toml.

[dependencies] highlightio-actix = "1"
Copy
3
Initialize the Highlight Rust SDK and actix Middleware.

highlightio_actix::highlight::Highlight::init initializes the SDK, and adding the highlightio_actix::HighlightActix middleware will start tracing actix.

use actix_web::{App, Error, HttpServer}; use highlightio_actix::{highlight::{Highlight, HighlightConfig}, HighlightActix}; // ...your services... #[actix_web::main] async fn main() -> Result<(), Error> { 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"); let _h = h.clone(); HttpServer::new(move || { App::new() .wrap(HighlightActix::new(&_h)) // ... }) .bind("127.0.0.1:8080")? .run() .await?; h.shutdown(); Ok(()) }
Copy
4
Verify your errors are being recorded.

Now that you've set everything up, you can verify that the backend error handling works by throwing an error in a service. Visit the highlight errors page and check that backend errors are coming in.

// ... #[get("/error")] async fn error() -> Result<impl Responder, std::io::Error> { Err(std::io::Error::new( std::io::ErrorKind::Other, "Test error" ))?; Ok(format!("You shouldn't be able to see this.")) } // ... #[actix_web::main] async fn main() -> Result<(), Error> { // ... HttpServer::new(move || { App::new() .wrap(HighlightActix::new(&h)) .service(error) // add this }) // ... }
Copy
5
Set up logging.

Start sending logs to Highlight! Follow the logging setup guide to get started.