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

View file

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