This Rust library integrates with the Actix web framework and logs requests using FireTail's logging service. Here's a quick guide to setting it up and using it in your project.
Prerequisites:
Ensure the following environment variables are set:
- FIRETAIL_APIKEY: Your FireTail API key, which is needed to communicate with FireTail's servers. You can generate an API token on an API page in the FireTail platform. Learn how to generate an API token.
- FIRETAIL_URL: The FireTail backend URL. By default, it points to the EU platform. If you use the US platform, set it to
https://api.logging.us-east-2.prod.us.firetail.app
.
Example code with Actix
Here is a sample implementation of the FireTail logging library with Actix.
use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder};
use firetail_rust_lib::FiretailLogging;
#[get("/")]
async fn hello() -> impl Responder {
HttpResponse::Ok().body("Hello world!")
}
#[post("/echo")]
async fn echo(req_body: String) -> impl Responder {
HttpResponse::Ok().body(req_body)
}
async fn manual_hello() -> impl Responder {
HttpResponse::Ok().body("Hey there!")
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.wrap(FiretailLogging::default())
.service(hello)
.service(echo)
.route("/hey", web::get().to(manual_hello))
})
.bind(("127.0.0.1", 8080))?
.run()
.await
}
Cargo.toml setup:
Include the FireTail library by adding this line to your Cargo.toml:
firetail-rust-lib = "0.0.1"
Integrating FireTail in your Actix app:
When the library is included, add it to your main.rs file:
HttpServer::new(|| {
App::new()
.wrap(FiretailLogging::default())
.service(hello)
.service(echo)
.route("/hey", web::get().to(manual_hello))
})
Activate FireTail logging in your HTTP server code:
HttpServer::new(|| {
App::new()
.wrap(FiretailLogging::default())
.service(hello)
.service(echo)
.route("/hey", web::get().to(manual_hello))
})