forked from 2sys/shoutdotdev
fix tracing spans across awaits
This commit is contained in:
parent
e30c610de4
commit
c9e64e5f0b
2 changed files with 21 additions and 15 deletions
30
src/auth.rs
30
src/auth.rs
|
@ -13,7 +13,7 @@ use oauth2::{
|
|||
ClientSecret, CsrfToken, RedirectUrl, RefreshToken, TokenResponse, TokenUrl,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tracing::trace_span;
|
||||
use tracing::{trace_span, Instrument};
|
||||
|
||||
use crate::{
|
||||
app_error::AppError,
|
||||
|
@ -197,17 +197,21 @@ impl FromRequestParts<AppState> for AuthInfo {
|
|||
parts: &mut Parts,
|
||||
state: &AppState,
|
||||
) -> Result<Self, <Self as FromRequestParts<AppState>>::Rejection> {
|
||||
let _ = trace_span!("AuthInfo from_request_parts()").enter();
|
||||
let session = parts
|
||||
.extract_with_state::<AppSession, AppState>(state)
|
||||
.await?
|
||||
.0
|
||||
.ok_or(AppError::auth_redirect_from_base_path(
|
||||
state.settings.base_path.clone(),
|
||||
))?;
|
||||
let user = session.get::<AuthInfo>(SESSION_KEY_AUTH_INFO).ok_or(
|
||||
AppError::auth_redirect_from_base_path(state.settings.base_path.clone()),
|
||||
)?;
|
||||
Ok(user)
|
||||
async move {
|
||||
let session = parts
|
||||
.extract_with_state::<AppSession, AppState>(state)
|
||||
.await?
|
||||
.0
|
||||
.ok_or(AppError::auth_redirect_from_base_path(
|
||||
state.settings.base_path.clone(),
|
||||
))?;
|
||||
let user = session.get::<AuthInfo>(SESSION_KEY_AUTH_INFO).ok_or(
|
||||
AppError::auth_redirect_from_base_path(state.settings.base_path.clone()),
|
||||
)?;
|
||||
Ok(user)
|
||||
}
|
||||
// The Span.enter() guard pattern doesn't play nicely async
|
||||
.instrument(trace_span!("AuthInfo from_request_parts()"))
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ use axum::{
|
|||
use axum_extra::extract::CookieJar;
|
||||
use chrono::{DateTime, TimeDelta, Utc};
|
||||
use diesel::{pg::Pg, prelude::*, upsert::excluded};
|
||||
use tracing::trace_span;
|
||||
use tracing::{trace_span, Instrument};
|
||||
|
||||
use crate::{app_error::AppError, app_state::AppState, schema::browser_sessions};
|
||||
|
||||
|
@ -134,7 +134,7 @@ impl FromRequestParts<AppState> for AppSession {
|
|||
parts: &mut Parts,
|
||||
state: &AppState,
|
||||
) -> Result<Self, <Self as FromRequestParts<AppState>>::Rejection> {
|
||||
let _ = trace_span!("AppSession::from_request_parts()").enter();
|
||||
async move {
|
||||
let jar = parts.extract::<CookieJar>().await.unwrap();
|
||||
let session_cookie = match jar.get(&state.settings.auth.cookie_name) {
|
||||
Some(cookie) => cookie,
|
||||
|
@ -167,5 +167,7 @@ impl FromRequestParts<AppState> for AppSession {
|
|||
tracing::debug!("no matching session found in database");
|
||||
Ok(AppSession(None))
|
||||
}
|
||||
// The Span.enter() guard pattern doesn't play nicely async
|
||||
}.instrument(trace_span!("AppSession::from_request_parts()")).await
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue