Skip to content

Commit

Permalink
Testing tracing::instrument
Browse files Browse the repository at this point in the history
  • Loading branch information
GPeaky committed Oct 16, 2024
1 parent ce1d173 commit 6defb89
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions crates/api/src/handlers/auth/discord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::states::AppState;

const DISCORD_REDIRECT: &str = "https://intellitelemetry.live/auth/discord/callback";

#[tracing::instrument(skip(state))]
pub async fn discord_callback(
state: State<AppState>,
query: Query<OauthAuthorizationCode>,
Expand Down
5 changes: 5 additions & 0 deletions crates/api/src/handlers/auth/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::states::AppState;

// TODO: Add rate limiting to the register endpoint
#[inline]
#[tracing::instrument(skip(state), fields(email = %user_registration.email))]
pub(crate) async fn register(
state: State<AppState>,
Json(user_registration): Json<UserRegistrationData>,
Expand Down Expand Up @@ -50,6 +51,7 @@ pub(crate) async fn register(
}

#[inline]
#[tracing::instrument(skip(state, _query), fields(email = %login_credentials.email))]
pub(crate) async fn login(
state: State<AppState>,
Query(_query): Query<ClientFingerprint>,
Expand Down Expand Up @@ -95,6 +97,7 @@ pub(crate) async fn login(
}

#[inline]
#[tracing::instrument(skip(state))]
pub(crate) async fn refresh_token(
state: State<AppState>,
Query(query): Query<RefreshTokenRequest>,
Expand Down Expand Up @@ -124,6 +127,7 @@ pub(crate) async fn logout(
}

#[inline]
#[tracing::instrument(skip(state))]
pub(crate) async fn forgot_password(
state: State<AppState>,
password_reset: Json<PasswordResetRequest>,
Expand Down Expand Up @@ -161,6 +165,7 @@ pub(crate) async fn forgot_password(

// TODO: Add rate limiting to the reset password endpoint
#[inline]
#[tracing::instrument(skip(state, password_update))]
pub async fn reset_password(
state: State<AppState>,
Query(query): Query<TokenVerification>,
Expand Down
1 change: 1 addition & 0 deletions crates/api/src/handlers/auth/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use intelli_core::services::UserServiceOperations;
use structs::{EmailVerificationConfirmationTemplate, TokenVerification};

#[inline]
#[tracing::instrument(skip(state))]
pub async fn verify_email(
state: State<AppState>,
Query(query): Query<TokenVerification>,
Expand Down
5 changes: 5 additions & 0 deletions crates/api/src/handlers/championships/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub(crate) mod core {
use crate::states::AppState;

#[inline]
#[tracing::instrument(skip(req, state))]
pub async fn create(
req: HttpRequest,
state: State<AppState>,
Expand Down Expand Up @@ -56,6 +57,7 @@ pub(crate) mod core {
}

#[inline]
#[tracing::instrument(skip(req, state))]
pub async fn update(
req: HttpRequest,
state: State<AppState>,
Expand All @@ -76,6 +78,7 @@ pub(crate) mod core {
}

#[inline]
#[tracing::instrument(skip(req, state))]
pub async fn add_user(
req: HttpRequest,
state: State<AppState>,
Expand All @@ -96,6 +99,7 @@ pub(crate) mod core {
}

#[inline]
#[tracing::instrument(skip(req, state))]
pub async fn remove_user(
req: HttpRequest,
state: State<AppState>,
Expand All @@ -115,6 +119,7 @@ pub(crate) mod core {
}

#[inline]
#[tracing::instrument(skip(state))]
pub async fn get(
state: State<AppState>,
path: Path<ChampionshipId>,
Expand Down
3 changes: 3 additions & 0 deletions crates/api/src/handlers/championships/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use error::{AppResult, ChampionshipError, CommonError};
use structs::ChampionshipId;

#[inline]
#[tracing::instrument(skip(state))]
pub async fn start(state: State<AppState>, path: Path<ChampionshipId>) -> AppResult<HttpResponse> {
if path.validate().is_err() {
Err(CommonError::ValidationFailed)?
Expand All @@ -27,6 +28,7 @@ pub async fn start(state: State<AppState>, path: Path<ChampionshipId>) -> AppRes
}

#[inline]
#[tracing::instrument(skip(state))]
pub async fn status(state: State<AppState>, path: Path<ChampionshipId>) -> AppResult<HttpResponse> {
if path.validate().is_err() {
Err(CommonError::ValidationFailed)?
Expand All @@ -42,6 +44,7 @@ pub async fn status(state: State<AppState>, path: Path<ChampionshipId>) -> AppRe
}

#[inline]
#[tracing::instrument(skip(state))]
pub async fn stop(state: State<AppState>, path: Path<ChampionshipId>) -> AppResult<HttpResponse> {
if path.validate().is_err() {
Err(CommonError::ValidationFailed)?
Expand Down
2 changes: 2 additions & 0 deletions crates/api/src/handlers/championships/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl<S> Drop for CleanupStream<S> {
}

#[inline]
#[tracing::instrument(skip(state))]
pub async fn stream_live_session(
state: State<AppState>,
path: Path<ChampionshipId>,
Expand Down Expand Up @@ -89,6 +90,7 @@ pub async fn stream_live_session(
}
}

#[tracing::instrument(skip(req, state))]
pub async fn stream_telemetry_session(
req: HttpRequest,
state: State<AppState>,
Expand Down
3 changes: 3 additions & 0 deletions crates/api/src/handlers/user/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::states::AppState;
pub(crate) mod admin;

#[inline]
#[tracing::instrument(skip(req, state))]
pub(crate) async fn get(req: HttpRequest, state: State<AppState>) -> AppResult<HttpResponse> {
let user = req.user()?;
let championships = state.user_repo.championships(user.id).await?;
Expand All @@ -25,6 +26,7 @@ pub(crate) async fn get(req: HttpRequest, state: State<AppState>) -> AppResult<H
}

#[inline]
#[tracing::instrument(skip(req, state))]
pub(crate) async fn update(
req: HttpRequest,
state: State<AppState>,
Expand All @@ -40,6 +42,7 @@ pub(crate) async fn update(
}

#[inline]
#[tracing::instrument(skip(req, state))]
pub async fn get_championships(
req: HttpRequest,
state: State<AppState>,
Expand Down
6 changes: 3 additions & 3 deletions crates/structs/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use entities::Provider;
use utils::deserialize_i64_from_string;

// Authentication Structures
#[derive(Deserialize, Validate)]
#[derive(Debug, Deserialize, Validate)]
pub struct LoginCredentials {
#[garde(email)]
#[serde(deserialize_with = "string_trim")]
Expand Down Expand Up @@ -61,7 +61,7 @@ impl UserRegistrationData {
}

// Password Management
#[derive(Deserialize, Validate)]
#[derive(Debug, Deserialize, Validate)]
pub struct PasswordResetRequest {
#[garde(email)]
#[serde(deserialize_with = "string_trim")]
Expand Down Expand Up @@ -92,7 +92,7 @@ pub struct ClientFingerprint {
pub fingerprint: String,
}

#[derive(Deserialize)]
#[derive(Deserialize, Debug)]
pub struct OauthAuthorizationCode {
pub code: String,
}
Expand Down
6 changes: 3 additions & 3 deletions crates/structs/src/championship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct ChampionshipCreationData {
pub category: Category,
}

#[derive(Deserialize, Validate)]
#[derive(Debug, Deserialize, Validate)]
pub struct ChampionshipUserAddForm {
#[serde(deserialize_with = "string_trim")]
#[garde(email)]
Expand Down Expand Up @@ -44,10 +44,10 @@ pub struct ServiceStatus {
}

// Path Parameters
#[derive(Deserialize, Validate)]
#[derive(Debug, Deserialize, Validate)]
pub struct ChampionshipId(#[garde(range(min = 700000000, max = 799999999))] pub i32);

#[derive(Deserialize, Validate)]
#[derive(Debug, Deserialize, Validate)]
pub struct ChampionshipAndUserId {
#[garde(range(min = 700000000, max = 799999999))]
pub championship_id: i32,
Expand Down

0 comments on commit 6defb89

Please sign in to comment.