Include login in connection-related tracing spans/events

Also, include metadata on more events and add an event called "signing out" with all this metadata to make it easier to search for.
This commit is contained in:
Nathan Sobo 2022-05-12 12:06:06 -06:00
parent 3226e07dcc
commit a3b9ad75b0
2 changed files with 27 additions and 15 deletions

View file

@ -2,7 +2,7 @@ use std::sync::Arc;
use super::db::{self, UserId};
use crate::{AppState, Error};
use anyhow::{Context, Result};
use anyhow::{anyhow, Context, Result};
use axum::{
http::{self, Request, StatusCode},
middleware::Next,
@ -51,7 +51,12 @@ pub async fn validate_header<B>(mut req: Request<B>, next: Next<B>) -> impl Into
}
if credentials_valid {
req.extensions_mut().insert(user_id);
let user = state
.db
.get_user_by_id(user_id)
.await?
.ok_or_else(|| anyhow!("user {} not found", user_id))?;
req.extensions_mut().insert(user);
Ok::<_, Error>(next.run(req).await)
} else {
Err(Error::Http(