Use instrument

This commit is contained in:
Mo 2023-02-26 16:47:29 +01:00
parent 338cadaf51
commit db01d33b0f
2 changed files with 9 additions and 4 deletions

View file

@ -91,6 +91,7 @@ impl Mailer {
.zip(persistent_field_contents.custom.iter())
.map(|(label, content)| format!("{label}:\n{content}\n\n\n"))
.fold(default_fields_content, |acc, s| acc + &s);
info!("Email body:\n{}", body.trim_end());
let email = self
.message_builder
@ -105,6 +106,8 @@ impl Mailer {
.await
.context("Failed to send email!")?;
info!("Successful contact form submission");
Ok(())
}
}

View file

@ -8,7 +8,7 @@ use std::{
collections::HashMap,
sync::{Arc, Mutex},
};
use tracing::{error, info};
use tracing::{error, info, instrument};
use crate::{
captcha_solutions::CaptchaSolutions,
@ -59,11 +59,12 @@ pub fn render_contact_form(params: ContactFormParams<'_>) -> Result<Response, Ap
}
/// Index handler.
#[instrument(skip_all)]
pub async fn index(
State(config): State<Arc<StateConfig>>,
State(captcha_solutions): State<Arc<Mutex<CaptchaSolutions>>>,
) -> Result<Response, AppError> {
info!("Visited get(index)");
info!("GET /");
render_contact_form(ContactFormParams {
config,
@ -74,12 +75,15 @@ pub async fn index(
}
/// Submit handler.
#[instrument(skip_all)]
pub async fn submit(
State(config): State<Arc<StateConfig>>,
State(captcha_solutions): State<Arc<Mutex<CaptchaSolutions>>>,
State(mailer): State<Arc<Mailer>>,
Form(map): Form<HashMap<String, String>>,
) -> Result<Response, AppError> {
info!("POST /");
let form = ContactForm::from_map(map, &config.custom_fields)?;
let right_captcha_answer = captcha_solutions
@ -114,8 +118,6 @@ pub async fn submit(
/// Called on successful contact form submission.
pub fn success(config: Arc<StateConfig>) -> Result<Response, AppError> {
info!("Successful contact form submission");
// Initialize template.
let template = templates::Success {
base: templates::Base {