refactor(service): migrate auth, git service, agent from slog to tracing
- Remove all use slog::* imports and slog::Logger fields/parameters - Replace slog::info!/warn!/error! with tracing::info!/warn!/error! - AppService: remove pub logs: slog::Logger field, update callers of AppEmail::init(), MessageProducer::new(), RoomService::new(), start_email_worker(), start_room_workers() - auth/: captcha, email, login, logout, password, register, rsa, totp - git/: archive, blame, blob, branch, commit, contributors, diff, refs, star, tag, tree, watch - agent/: billing (ai_usage_recorded), code_review, pr_summary, sync - project/activity.rs, workspace/alert.rs
This commit is contained in:
parent
b4024aa690
commit
773da34fab
@ -20,7 +20,6 @@ use models::workspaces::workspace_billing_history;
|
||||
use rust_decimal::Decimal;
|
||||
use sea_orm::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use slog::info;
|
||||
use utoipa::ToSchema;
|
||||
use uuid::Uuid;
|
||||
|
||||
@ -137,14 +136,15 @@ impl AppService {
|
||||
updated.updated_at = Set(now);
|
||||
updated.update(&self.db).await?;
|
||||
|
||||
info!(self.logs, "ai_usage_recorded";
|
||||
"project_id" => %project_uid,
|
||||
"model_id" => %model_id,
|
||||
"input_tokens" => input_tokens,
|
||||
"output_tokens" => output_tokens,
|
||||
"cost" => total_cost,
|
||||
"currency" => %currency,
|
||||
"workspace_id" => %workspace_id.to_string()
|
||||
tracing::info!(
|
||||
project_id = %project_uid,
|
||||
model_id = %model_id,
|
||||
input_tokens = input_tokens,
|
||||
output_tokens = output_tokens,
|
||||
cost = %total_cost,
|
||||
currency = %currency,
|
||||
workspace_id = %workspace_id.to_string(),
|
||||
"ai_usage_recorded"
|
||||
);
|
||||
|
||||
Ok(BillingRecord {
|
||||
@ -197,13 +197,14 @@ impl AppService {
|
||||
updated.balance = Set(new_balance);
|
||||
updated.update(&self.db).await?;
|
||||
|
||||
info!(self.logs, "ai_usage_recorded";
|
||||
"project_id" => %project_uid,
|
||||
"model_id" => %model_id,
|
||||
"input_tokens" => input_tokens,
|
||||
"output_tokens" => output_tokens,
|
||||
"cost" => total_cost,
|
||||
"currency" => %currency
|
||||
tracing::info!(
|
||||
project_id = %project_uid,
|
||||
model_id = %model_id,
|
||||
input_tokens = input_tokens,
|
||||
output_tokens = output_tokens,
|
||||
cost = %total_cost,
|
||||
currency = %currency,
|
||||
"ai_usage_recorded"
|
||||
);
|
||||
|
||||
Ok(BillingRecord {
|
||||
|
||||
@ -149,7 +149,7 @@ impl AppService {
|
||||
|
||||
let prompt = build_code_review_prompt(&pr, &diff);
|
||||
|
||||
let ai_response = call_ai_model(&model.name, &prompt, &self.config, self.logs.clone()).await?;
|
||||
let ai_response = call_ai_model(&model.name, &prompt, &self.config).await?;
|
||||
|
||||
// Record billing (non-fatal — log warning but don't fail the review).
|
||||
let billing = self
|
||||
@ -161,11 +161,10 @@ impl AppService {
|
||||
)
|
||||
.await
|
||||
.inspect_err(|e| {
|
||||
slog::warn!(
|
||||
self.logs,
|
||||
"failed to record AI billing for code review";
|
||||
"project" => %repo.project,
|
||||
"error" => ?e
|
||||
tracing::warn!(
|
||||
project = %repo.project,
|
||||
error = ?e,
|
||||
"failed to record AI billing for code review"
|
||||
);
|
||||
})
|
||||
.ok();
|
||||
@ -226,11 +225,10 @@ impl AppService {
|
||||
});
|
||||
}
|
||||
Err(e) => {
|
||||
slog::warn!(
|
||||
self.logs,
|
||||
"failed to create AI review comment";
|
||||
"path" => %comment.path,
|
||||
"error" => ?e
|
||||
tracing::warn!(
|
||||
path = %comment.path,
|
||||
error = ?e,
|
||||
"failed to create AI review comment"
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -392,7 +390,6 @@ async fn call_ai_model(
|
||||
model_name: &str,
|
||||
prompt: &str,
|
||||
app_config: &config::AppConfig,
|
||||
logger: slog::Logger,
|
||||
) -> Result<agent::AiCallResponse, AppError> {
|
||||
let api_key = app_config
|
||||
.ai_api_key()
|
||||
@ -402,7 +399,7 @@ async fn call_ai_model(
|
||||
.ai_basic_url()
|
||||
.unwrap_or_else(|_| "https://api.openai.com".into());
|
||||
|
||||
let client_config = agent::AiClientConfig::new(api_key, logger).with_base_url(base_url);
|
||||
let client_config = agent::AiClientConfig::new(api_key).with_base_url(base_url);
|
||||
|
||||
let messages = vec![
|
||||
async_openai::types::chat::ChatCompletionRequestMessage::User(
|
||||
|
||||
@ -125,7 +125,6 @@ async fn call_ai_model_for_description(
|
||||
model_name: &str,
|
||||
prompt: &str,
|
||||
app_config: &config::AppConfig,
|
||||
logger: slog::Logger,
|
||||
) -> Result<agent::AiCallResponse, AppError> {
|
||||
let api_key = app_config
|
||||
.ai_api_key()
|
||||
@ -135,7 +134,7 @@ async fn call_ai_model_for_description(
|
||||
.ai_basic_url()
|
||||
.unwrap_or_else(|_| "https://api.openai.com".into());
|
||||
|
||||
let client_config = agent::AiClientConfig::new(api_key, logger).with_base_url(base_url);
|
||||
let client_config = agent::AiClientConfig::new(api_key).with_base_url(base_url);
|
||||
|
||||
let messages = vec![
|
||||
async_openai::types::chat::ChatCompletionRequestMessage::User(
|
||||
@ -240,7 +239,7 @@ impl AppService {
|
||||
|
||||
// Build prompt and call AI
|
||||
let prompt = build_description_prompt(&pr.title, pr.body.as_deref(), &diff);
|
||||
let ai_response = call_ai_model_for_description(&model.name, &prompt, &self.config, self.logs.clone()).await?;
|
||||
let ai_response = call_ai_model_for_description(&model.name, &prompt, &self.config).await?;
|
||||
|
||||
// Record billing (non-fatal).
|
||||
let billing = self
|
||||
@ -252,11 +251,10 @@ impl AppService {
|
||||
)
|
||||
.await
|
||||
.inspect_err(|e| {
|
||||
slog::warn!(
|
||||
self.logs,
|
||||
"failed to record AI billing for PR description";
|
||||
"project" => %repo.project,
|
||||
"error" => ?e
|
||||
tracing::warn!(
|
||||
project = %repo.project,
|
||||
error = ?e,
|
||||
"failed to record AI billing for PR description"
|
||||
);
|
||||
})
|
||||
.ok();
|
||||
|
||||
@ -15,7 +15,6 @@
|
||||
use async_openai::Client;
|
||||
use async_openai::config::OpenAIConfig;
|
||||
use async_openai::types::models::Model as OpenAiModel;
|
||||
use slog::Logger;
|
||||
use std::time::Duration;
|
||||
use tokio::task::JoinHandle;
|
||||
use tokio::time::interval;
|
||||
@ -524,16 +523,12 @@ async fn upsert_parameter_profile(
|
||||
/// This handles non-OpenRouter endpoints (e.g. Bailian, MiniMax) gracefully.
|
||||
async fn sync_models_direct(
|
||||
db: &AppDatabase,
|
||||
log: &Logger,
|
||||
available_ids: &std::collections::HashSet<String>,
|
||||
) -> SyncModelsResponse {
|
||||
slog::info!(
|
||||
log,
|
||||
"{}",
|
||||
format!(
|
||||
tracing::info!(
|
||||
model_count = available_ids.len(),
|
||||
"sync_models_direct: {} models from endpoint (no OpenRouter metadata)",
|
||||
available_ids.len()
|
||||
)
|
||||
);
|
||||
|
||||
let mut models_created = 0i64;
|
||||
@ -548,13 +543,10 @@ async fn sync_models_direct(
|
||||
let provider = match upsert_provider(db, provider_slug).await {
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
slog::warn!(
|
||||
log,
|
||||
"{}",
|
||||
format!(
|
||||
"sync_models_direct: upsert_provider error provider={} {:?}",
|
||||
provider_slug, e
|
||||
)
|
||||
tracing::warn!(
|
||||
provider = %provider_slug,
|
||||
error = ?e,
|
||||
"sync_models_direct: upsert_provider error"
|
||||
);
|
||||
continue;
|
||||
}
|
||||
@ -571,13 +563,10 @@ async fn sync_models_direct(
|
||||
(m, n)
|
||||
}
|
||||
Err(e) => {
|
||||
slog::warn!(
|
||||
log,
|
||||
"{}",
|
||||
format!(
|
||||
"sync_models_direct: upsert_model_direct error model={} {:?}",
|
||||
model_id, e
|
||||
)
|
||||
tracing::warn!(
|
||||
model = %model_id,
|
||||
error = ?e,
|
||||
"sync_models_direct: upsert_model_direct error"
|
||||
);
|
||||
continue;
|
||||
}
|
||||
@ -587,13 +576,10 @@ async fn sync_models_direct(
|
||||
match upsert_version(db, model_record.id).await {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
slog::warn!(
|
||||
log,
|
||||
"{}",
|
||||
format!(
|
||||
"sync_models_direct: upsert_version error model={} {:?}",
|
||||
model_id, e
|
||||
)
|
||||
tracing::warn!(
|
||||
model = %model_id,
|
||||
error = ?e,
|
||||
"sync_models_direct: upsert_version error"
|
||||
);
|
||||
continue;
|
||||
}
|
||||
@ -617,20 +603,15 @@ async fn sync_models_direct(
|
||||
}
|
||||
}
|
||||
|
||||
slog::info!(
|
||||
log,
|
||||
"{}",
|
||||
format!(
|
||||
"sync_models_direct complete: matched={} created={} updated={} \
|
||||
versions={} pricing={} capabilities={} profiles={}",
|
||||
available_ids.len(),
|
||||
tracing::info!(
|
||||
matched = available_ids.len(),
|
||||
models_created,
|
||||
models_updated,
|
||||
versions_created,
|
||||
pricing_created,
|
||||
capabilities_created,
|
||||
profiles_created
|
||||
)
|
||||
profiles_created,
|
||||
"sync_models_direct complete"
|
||||
);
|
||||
|
||||
SyncModelsResponse {
|
||||
@ -647,7 +628,6 @@ async fn sync_models_direct(
|
||||
|
||||
async fn fetch_openrouter_models(
|
||||
client: &reqwest::Client,
|
||||
log: &Logger,
|
||||
) -> Result<OpenRouterResponse, String> {
|
||||
const MAX_RETRIES: u32 = 3;
|
||||
const BASE_DELAY_MS: u64 = 1_000;
|
||||
@ -695,13 +675,14 @@ async fn fetch_openrouter_models(
|
||||
));
|
||||
}
|
||||
let delay_ms = BASE_DELAY_MS * (1 << (attempt - 1));
|
||||
slog::warn!(
|
||||
log,
|
||||
"{}",
|
||||
format!(
|
||||
"OpenRouter connection attempt {}/{} failed: [{}] url={} error={:?}. retrying in {}ms",
|
||||
attempt, MAX_RETRIES, kind, url, e, delay_ms
|
||||
)
|
||||
tracing::warn!(
|
||||
attempt = attempt,
|
||||
max_retries = MAX_RETRIES,
|
||||
kind = %kind,
|
||||
url = %url,
|
||||
error = ?e,
|
||||
retry_delay_ms = delay_ms,
|
||||
"OpenRouter connection attempt failed, retrying"
|
||||
);
|
||||
sleep(Duration::from_millis(delay_ms)).await;
|
||||
}
|
||||
@ -754,18 +735,15 @@ impl AppService {
|
||||
.map(|m: OpenAiModel| m.id)
|
||||
.collect();
|
||||
|
||||
slog::info!(
|
||||
self.logs,
|
||||
"{}",
|
||||
format!(
|
||||
tracing::info!(
|
||||
model_count = available_ids.len(),
|
||||
"sync_upstream_models: {} accessible models found",
|
||||
available_ids.len()
|
||||
)
|
||||
);
|
||||
|
||||
// Step 2: fetch OpenRouter metadata.
|
||||
let http_client = reqwest::Client::new();
|
||||
let or_resp: OpenRouterResponse = fetch_openrouter_models(&http_client, &self.logs)
|
||||
let or_resp: OpenRouterResponse = fetch_openrouter_models(&http_client)
|
||||
.await
|
||||
.map_err(AppError::InternalServerError)?;
|
||||
|
||||
@ -782,15 +760,11 @@ impl AppService {
|
||||
// Fallback: if no OpenRouter metadata matches, sync models directly from
|
||||
// the user's endpoint (handles Bailian/MiniMax and other non-OpenRouter providers).
|
||||
if filtered_count == 0 && !available_ids.is_empty() {
|
||||
slog::info!(
|
||||
self.logs,
|
||||
"{}",
|
||||
format!(
|
||||
"sync_upstream_models: no OpenRouter matches, falling back to direct sync for {} models",
|
||||
available_ids.len()
|
||||
)
|
||||
tracing::info!(
|
||||
model_count = available_ids.len(),
|
||||
"sync_upstream_models: no OpenRouter matches, falling back to direct sync"
|
||||
);
|
||||
return Ok(sync_models_direct(&self.db, &self.logs, &available_ids).await);
|
||||
return Ok(sync_models_direct(&self.db, &available_ids).await);
|
||||
}
|
||||
|
||||
let mut models_created = 0i64;
|
||||
@ -805,13 +779,10 @@ impl AppService {
|
||||
let provider = match upsert_provider(&self.db, provider_slug).await {
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
slog::warn!(
|
||||
self.logs,
|
||||
"{}",
|
||||
format!(
|
||||
"sync_upstream_models: upsert_provider error provider={} {:?}",
|
||||
provider_slug, e
|
||||
)
|
||||
tracing::warn!(
|
||||
provider = %provider_slug,
|
||||
error = ?e,
|
||||
"sync_upstream_models: upsert_provider error"
|
||||
);
|
||||
continue;
|
||||
}
|
||||
@ -828,13 +799,10 @@ impl AppService {
|
||||
(m, n)
|
||||
}
|
||||
Err(e) => {
|
||||
slog::warn!(
|
||||
self.logs,
|
||||
"{}",
|
||||
format!(
|
||||
"sync_upstream_models: upsert_model error model={} {:?}",
|
||||
or_model.id, e
|
||||
)
|
||||
tracing::warn!(
|
||||
model = %or_model.id,
|
||||
error = ?e,
|
||||
"sync_upstream_models: upsert_model error"
|
||||
);
|
||||
continue;
|
||||
}
|
||||
@ -844,13 +812,10 @@ impl AppService {
|
||||
match upsert_version(&self.db, model_record.id).await {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
slog::warn!(
|
||||
self.logs,
|
||||
"{}",
|
||||
format!(
|
||||
"sync_upstream_models: upsert_version error model={} {:?}",
|
||||
or_model.id, e
|
||||
)
|
||||
tracing::warn!(
|
||||
model = %or_model.id,
|
||||
error = ?e,
|
||||
"sync_upstream_models: upsert_version error"
|
||||
);
|
||||
continue;
|
||||
}
|
||||
@ -862,13 +827,10 @@ impl AppService {
|
||||
if let Err(e) =
|
||||
upsert_pricing(&self.db, version_record.id, or_model.pricing.as_ref()).await
|
||||
{
|
||||
slog::warn!(
|
||||
self.logs,
|
||||
"{}",
|
||||
format!(
|
||||
"sync_upstream_models: upsert_pricing error model={} {:?}",
|
||||
or_model.id, e
|
||||
)
|
||||
tracing::warn!(
|
||||
model = %or_model.id,
|
||||
error = ?e,
|
||||
"sync_upstream_models: upsert_pricing error"
|
||||
);
|
||||
} else {
|
||||
pricing_created += 1;
|
||||
@ -887,15 +849,12 @@ impl AppService {
|
||||
}
|
||||
}
|
||||
|
||||
slog::info!(
|
||||
self.logs,
|
||||
"{}",
|
||||
format!(
|
||||
"sync_upstream_models: synced {} accessible models ({}/{} new/updated)",
|
||||
tracing::info!(
|
||||
filtered_count,
|
||||
models_created,
|
||||
models_updated
|
||||
)
|
||||
models_updated,
|
||||
"sync_upstream_models: synced {} accessible models",
|
||||
filtered_count
|
||||
);
|
||||
|
||||
Ok(SyncModelsResponse {
|
||||
@ -914,18 +873,17 @@ impl AppService {
|
||||
/// Failures are logged but do not stop the task — it keeps retrying.
|
||||
pub fn start_sync_task(self) -> JoinHandle<()> {
|
||||
let db = self.db.clone();
|
||||
let log = self.logs.clone();
|
||||
let ai_api_key = self.config.ai_api_key().ok();
|
||||
let ai_base_url = self.config.ai_basic_url().ok();
|
||||
|
||||
tokio::spawn(async move {
|
||||
// Run once immediately on startup before taking traffic.
|
||||
Self::sync_once(&db, &log, ai_api_key.clone(), ai_base_url.clone()).await;
|
||||
Self::sync_once(&db, ai_api_key.clone(), ai_base_url.clone()).await;
|
||||
|
||||
let mut tick = interval(Duration::from_secs(60 * 10));
|
||||
loop {
|
||||
tick.tick().await;
|
||||
Self::sync_once(&db, &log, ai_api_key.clone(), ai_base_url.clone()).await;
|
||||
Self::sync_once(&db, ai_api_key.clone(), ai_base_url.clone()).await;
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -934,7 +892,6 @@ impl AppService {
|
||||
/// so the periodic task never stops.
|
||||
async fn sync_once(
|
||||
db: &AppDatabase,
|
||||
log: &Logger,
|
||||
ai_api_key: Option<String>,
|
||||
ai_base_url: Option<String>,
|
||||
) {
|
||||
@ -942,7 +899,7 @@ impl AppService {
|
||||
let ai_client = match build_ai_client_from_parts(ai_api_key, ai_base_url) {
|
||||
Ok(c) => c,
|
||||
Err(msg) => {
|
||||
slog::warn!(log, "{}", format!("OpenRouter model sync: {}", msg));
|
||||
tracing::warn!(error = %msg, "OpenRouter model sync");
|
||||
return;
|
||||
}
|
||||
};
|
||||
@ -950,20 +907,16 @@ impl AppService {
|
||||
let available_ids: std::collections::HashSet<String> = match ai_client.models().list().await {
|
||||
Ok(resp) => resp.data.into_iter().map(|m: OpenAiModel| m.id).collect(),
|
||||
Err(e) => {
|
||||
slog::warn!(
|
||||
log,
|
||||
"{}",
|
||||
format!("OpenRouter model sync: failed to list available models: {}", e)
|
||||
);
|
||||
tracing::warn!(error = ?e, "OpenRouter model sync: failed to list available models");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let http_client = reqwest::Client::new();
|
||||
let or_resp = match fetch_openrouter_models(&http_client, log).await {
|
||||
let or_resp = match fetch_openrouter_models(&http_client).await {
|
||||
Ok(r) => r,
|
||||
Err(msg) => {
|
||||
slog::warn!(log, "{}", format!("OpenRouter model sync: {}", msg));
|
||||
tracing::warn!(error = %msg, "OpenRouter model sync");
|
||||
return;
|
||||
}
|
||||
};
|
||||
@ -980,15 +933,11 @@ impl AppService {
|
||||
// Fallback: if no OpenRouter metadata matches, sync models directly from
|
||||
// the user's endpoint (handles Bailian/MiniMax and other non-OpenRouter providers).
|
||||
if filtered_count == 0 && !available_ids.is_empty() {
|
||||
slog::info!(
|
||||
log,
|
||||
"{}",
|
||||
format!(
|
||||
"OpenRouter model sync: no matches, falling back to direct sync for {} models",
|
||||
available_ids.len()
|
||||
)
|
||||
tracing::info!(
|
||||
model_count = available_ids.len(),
|
||||
"OpenRouter model sync: no matches, falling back to direct sync"
|
||||
);
|
||||
sync_models_direct(db, log, &available_ids).await;
|
||||
sync_models_direct(db, &available_ids).await;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1004,13 +953,10 @@ impl AppService {
|
||||
let provider = match upsert_provider(db, provider_slug).await {
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
slog::warn!(
|
||||
log,
|
||||
"{}",
|
||||
format!(
|
||||
"OpenRouter model sync: upsert_provider error provider={} {:?}",
|
||||
provider_slug, e
|
||||
)
|
||||
tracing::warn!(
|
||||
provider = %provider_slug,
|
||||
error = ?e,
|
||||
"OpenRouter model sync: upsert_provider error"
|
||||
);
|
||||
continue;
|
||||
}
|
||||
@ -1027,13 +973,10 @@ impl AppService {
|
||||
(m, false)
|
||||
}
|
||||
Err(e) => {
|
||||
slog::warn!(
|
||||
log,
|
||||
"{}",
|
||||
format!(
|
||||
"OpenRouter model sync: upsert_model error model={} {:?}",
|
||||
or_model.id, e
|
||||
)
|
||||
tracing::warn!(
|
||||
model = %or_model.id,
|
||||
error = ?e,
|
||||
"OpenRouter model sync: upsert_model error"
|
||||
);
|
||||
continue;
|
||||
}
|
||||
@ -1043,13 +986,10 @@ impl AppService {
|
||||
match upsert_version(db, model_record.id).await {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
slog::warn!(
|
||||
log,
|
||||
"{}",
|
||||
format!(
|
||||
"OpenRouter model sync: upsert_version error model={} {:?}",
|
||||
or_model.id, e
|
||||
)
|
||||
tracing::warn!(
|
||||
model = %or_model.id,
|
||||
error = ?e,
|
||||
"OpenRouter model sync: upsert_version error"
|
||||
);
|
||||
continue;
|
||||
}
|
||||
@ -1078,20 +1018,15 @@ impl AppService {
|
||||
}
|
||||
}
|
||||
|
||||
slog::info!(
|
||||
log,
|
||||
"{}",
|
||||
format!(
|
||||
"OpenRouter model sync complete: matched={} created={} updated={} \
|
||||
versions={} pricing={} capabilities={} profiles={}",
|
||||
filtered_count,
|
||||
tracing::info!(
|
||||
matched = filtered_count,
|
||||
models_created,
|
||||
models_updated,
|
||||
versions_created,
|
||||
pricing_created,
|
||||
capabilities_created,
|
||||
profiles_created
|
||||
)
|
||||
profiles_created,
|
||||
"OpenRouter model sync complete"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ impl AppService {
|
||||
.ok_or(AppError::CaptchaError)?;
|
||||
if text.to_lowercase() != captcha.to_lowercase() {
|
||||
context.remove(Self::CAPTCHA_KEY);
|
||||
slog::warn!(self.logs, "Captcha verification failed"; "ip" => context.ip_address());
|
||||
tracing::warn!(ip = ?context.ip_address(), "Captcha verification failed");
|
||||
return Err(AppError::CaptchaError);
|
||||
}
|
||||
context.remove(Self::CAPTCHA_KEY);
|
||||
|
||||
@ -125,7 +125,7 @@ impl AppService {
|
||||
.await
|
||||
.map_err(|e| AppError::InternalServerError(e.to_string()))?;
|
||||
|
||||
slog::info!(self.logs, "Email change verification queued"; "new_email" => %params.new_email, "user_uid" => %user_uid);
|
||||
tracing::info!(new_email = %params.new_email, user_uid = %user_uid, "Email change verification queued");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -179,7 +179,7 @@ impl AppService {
|
||||
.await
|
||||
.map_err(|e| AppError::DatabaseError(e.to_string()))?;
|
||||
|
||||
slog::info!(self.logs, "Email changed successfully"; "new_email" => %new_email, "user_uid" => %user_uid);
|
||||
tracing::info!(new_email = %new_email, user_uid = %user_uid, "Email changed successfully");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ impl AppService {
|
||||
PasswordHash::new(&user_password.password_hash).map_err(|_| AppError::UserNotFound)?;
|
||||
|
||||
if let Err(_e) = Argon2::default().verify_password(password.as_bytes(), &password_hash) {
|
||||
slog::warn!(self.logs, "Login failed: invalid password"; "username" => ¶ms.username, "ip" => context.ip_address());
|
||||
tracing::warn!(username = %params.username, ip = ?context.ip_address(), "Login failed: invalid password");
|
||||
return Err(AppError::UserNotFound);
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ impl AppService {
|
||||
// if needs_totp_verification {
|
||||
// if let Some(ref totp_code) = params.totp_code {
|
||||
// if !self.auth_2fa_verify_login(&context, totp_code).await? {
|
||||
// slog::warn!(self.logs, "Login failed: invalid 2FA code"; "username" => ¶ms.username, "ip" => context.ip_address());
|
||||
// tracing::warn!(username = %params.username, ip = %context.ip_address(), "Login failed: invalid 2FA code");
|
||||
// return Err(AppError::InvalidTwoFactorCode);
|
||||
// }
|
||||
// }
|
||||
@ -87,7 +87,7 @@ impl AppService {
|
||||
// .await
|
||||
// .ok();
|
||||
// }
|
||||
// slog::info!(self.logs, "Login 2FA triggered for new 2FA user"; "username" => ¶ms.username, "ip" => context.ip_address());
|
||||
// tracing::info!(username = %params.username, ip = %context.ip_address(), "Login 2FA triggered for new 2FA user");
|
||||
// return Err(AppError::TwoFactorRequired);
|
||||
// }
|
||||
// }
|
||||
@ -117,7 +117,7 @@ impl AppService {
|
||||
context.set_user(user.uid);
|
||||
context.remove(Self::RSA_PRIVATE_KEY);
|
||||
context.remove(Self::RSA_PUBLIC_KEY);
|
||||
slog::info!(self.logs, "User logged in successfully"; "user_uid" => %user.uid, "username" => &user.username, "ip" => context.ip_address());
|
||||
tracing::info!(user_uid = %user.uid, username = %user.username, ip = ?context.ip_address(), "User logged in successfully");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ use session::Session;
|
||||
impl AppService {
|
||||
pub async fn auth_logout(&self, context: &Session) -> Result<(), AppError> {
|
||||
if let Some(user_uid) = context.user() {
|
||||
slog::info!(self.logs, "User logged out"; "user_uid" => %user_uid, "ip" => context.ip_address());
|
||||
tracing::info!(user_uid = %user_uid, ip = ?context.ip_address(), "User logged out");
|
||||
let _ = user_activity_log::ActiveModel {
|
||||
user_uid: Set(Option::from(user_uid)),
|
||||
action: Set("logout".to_string()),
|
||||
|
||||
@ -69,7 +69,7 @@ impl AppService {
|
||||
.await
|
||||
.map_err(|_| AppError::UserNotFound)?;
|
||||
|
||||
slog::info!(self.logs, "Password changed"; "user_uid" => %user_uid, "ip" => context.ip_address());
|
||||
tracing::info!(user_uid = %user_uid, ip = ?context.ip_address(), "Password changed");
|
||||
let _ = user_activity_log::ActiveModel {
|
||||
user_uid: Set(Option::from(user_uid)),
|
||||
action: Set("password_change".to_string()),
|
||||
@ -146,7 +146,7 @@ impl AppService {
|
||||
.await
|
||||
.map_err(|_| AppError::UserNotFound)?;
|
||||
|
||||
slog::info!(self.logs, "Password reset email queued"; "email" => email_address);
|
||||
tracing::info!(email = %email_address, "Password reset email queued");
|
||||
Ok(())
|
||||
}
|
||||
pub fn validate_password_strength(password: &str) -> Result<(), AppError> {
|
||||
@ -232,7 +232,7 @@ impl AppService {
|
||||
|
||||
txn.commit().await.map_err(|_| AppError::TxnError)?;
|
||||
|
||||
slog::info!(self.logs, "Password reset confirmed"; "user_uid" => %reset_token.user_uid);
|
||||
tracing::info!(user_uid = %reset_token.user_uid, "Password reset confirmed");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -245,7 +245,7 @@ impl AppService {
|
||||
.await
|
||||
.map_err(|_| AppError::UserNotFound)?;
|
||||
|
||||
slog::info!(self.logs, "Expired password reset tokens cleaned up"; "count" => result.rows_affected);
|
||||
tracing::info!(count = result.rows_affected, "Expired password reset tokens cleaned up");
|
||||
Ok(result.rows_affected)
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ impl AppService {
|
||||
.await
|
||||
.is_ok()
|
||||
{
|
||||
slog::warn!(self.logs, "Registration failed: username already exists"; "username" => ¶ms.username);
|
||||
tracing::warn!(username = %params.username, "Registration failed: username already exists");
|
||||
return Err(AppError::UserNameExists);
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ impl AppService {
|
||||
.await
|
||||
.is_ok()
|
||||
{
|
||||
slog::warn!(self.logs, "Registration failed: email already exists"; "email" => ¶ms.email);
|
||||
tracing::warn!(email = %params.email, "Registration failed: email already exists");
|
||||
return Err(AppError::EmailExists);
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ impl AppService {
|
||||
};
|
||||
|
||||
let user = user_model.insert(&txn).await.map_err(|e| {
|
||||
slog::error!(self.logs, "{}", format!("Failed to insert user: {:?}", e));
|
||||
tracing::error!(error = ?e, "Failed to insert user");
|
||||
AppError::UserNotFound
|
||||
})?;
|
||||
|
||||
@ -71,11 +71,7 @@ impl AppService {
|
||||
};
|
||||
|
||||
user_email_model.insert(&txn).await.map_err(|e| {
|
||||
slog::error!(
|
||||
self.logs,
|
||||
"{}",
|
||||
format!("Failed to insert user email: {:?}", e)
|
||||
);
|
||||
tracing::error!(error = ?e, "Failed to insert user email");
|
||||
AppError::UserNotFound
|
||||
})?;
|
||||
|
||||
@ -83,7 +79,7 @@ impl AppService {
|
||||
let password_hash = Argon2::default()
|
||||
.hash_password(password.as_bytes(), Salt::from_b64(&*salt.to_string())?)
|
||||
.map_err(|e| {
|
||||
slog::error!(self.logs, "{}", format!("Failed to hash password: {:?}", e));
|
||||
tracing::error!(error = ?e, "Failed to hash password");
|
||||
AppError::UserNotFound
|
||||
})?
|
||||
.to_string();
|
||||
@ -97,11 +93,7 @@ impl AppService {
|
||||
};
|
||||
|
||||
user_password_model.insert(&txn).await.map_err(|e| {
|
||||
slog::error!(
|
||||
self.logs,
|
||||
"{}",
|
||||
format!("Failed to insert user password: {:?}", e)
|
||||
);
|
||||
tracing::error!(error = ?e, "Failed to insert user password");
|
||||
AppError::UserNotFound
|
||||
})?;
|
||||
|
||||
@ -139,11 +131,7 @@ impl AppService {
|
||||
updated_at: Set(now),
|
||||
};
|
||||
let ws = ws.insert(&txn).await.map_err(|e| {
|
||||
slog::error!(
|
||||
self.logs,
|
||||
"{}",
|
||||
format!("Failed to insert personal workspace: {:?}", e)
|
||||
);
|
||||
tracing::error!(error = ?e, "Failed to insert personal workspace");
|
||||
AppError::UserNotFound
|
||||
})?;
|
||||
|
||||
@ -165,7 +153,7 @@ impl AppService {
|
||||
context.set_current_workspace_id(ws.id);
|
||||
context.remove(Self::RSA_PRIVATE_KEY);
|
||||
context.remove(Self::RSA_PUBLIC_KEY);
|
||||
slog::info!(self.logs, "User registered successfully"; "user_uid" => %user_uid, "username" => &user.username);
|
||||
tracing::info!(user_uid = %user_uid, username = %user.username, "User registered successfully");
|
||||
Ok(user)
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ impl AppService {
|
||||
#[allow(deprecated)]
|
||||
let mut rng = rsa::rand_core::OsRng::default();
|
||||
let Ok(priv_key) = RsaPrivateKey::new(&mut rng, Self::RSA_BIT_SIZE) else {
|
||||
slog::error!(self.logs, "RSA key generation failed");
|
||||
tracing::error!("RSA key generation failed");
|
||||
return Err(AppError::RsaGenerationError);
|
||||
};
|
||||
let pub_key = RsaPublicKey::from(&priv_key);
|
||||
@ -51,14 +51,14 @@ impl AppService {
|
||||
.map_err(|_| AppError::RsaDecodeError)?
|
||||
.ok_or(AppError::RsaDecodeError)?;
|
||||
let Ok(priv_key) = RsaPrivateKey::from_pkcs1_pem(&priv_key) else {
|
||||
slog::warn!(self.logs, "RSA decode failed: invalid private key"; "ip" => context.ip_address());
|
||||
tracing::warn!(ip = ?context.ip_address(), "RSA decode failed: invalid private key");
|
||||
return Err(AppError::RsaDecodeError);
|
||||
};
|
||||
let cipher = base64::engine::general_purpose::STANDARD
|
||||
.decode(&data)
|
||||
.map_err(|_| AppError::RsaDecodeError)?;
|
||||
let Ok(decrypted) = priv_key.decrypt(Pkcs1v15Encrypt, &cipher) else {
|
||||
slog::warn!(self.logs, "RSA decrypt failed"; "ip" => context.ip_address());
|
||||
tracing::warn!(ip = ?context.ip_address(), "RSA decrypt failed");
|
||||
return Err(AppError::RsaDecodeError);
|
||||
};
|
||||
Ok(String::from_utf8_lossy(&decrypted).to_string())
|
||||
|
||||
@ -75,7 +75,7 @@ impl AppService {
|
||||
model.insert(&self.db).await?;
|
||||
}
|
||||
|
||||
slog::info!(self.logs, "2FA setup initiated"; "user_uid" => %user_uid);
|
||||
tracing::info!(user_uid = %user_uid, "2FA setup initiated");
|
||||
Ok(Enable2FAResponse {
|
||||
secret,
|
||||
qr_code: qr_data,
|
||||
@ -102,7 +102,7 @@ impl AppService {
|
||||
let secret = two_fa.secret.as_ref().ok_or(AppError::TwoFactorNotSetup)?;
|
||||
|
||||
if !self.verify_totp_code(secret, ¶ms.code)? {
|
||||
slog::warn!(self.logs, "2FA verification failed during setup"; "user_uid" => %user_uid, "ip" => context.ip_address());
|
||||
tracing::warn!(user_uid = %user_uid, ip = ?context.ip_address(), "2FA verification failed during setup");
|
||||
return Err(AppError::InvalidTwoFactorCode);
|
||||
}
|
||||
|
||||
@ -111,7 +111,7 @@ impl AppService {
|
||||
active_model.updated_at = Set(chrono::Utc::now());
|
||||
active_model.update(&self.db).await?;
|
||||
|
||||
slog::info!(self.logs, "2FA enabled"; "user_uid" => %user_uid, "ip" => context.ip_address());
|
||||
tracing::info!(user_uid = %user_uid, ip = ?context.ip_address(), "2FA enabled");
|
||||
let _ = user_activity_log::ActiveModel {
|
||||
user_uid: Set(Option::from(user_uid)),
|
||||
action: Set("2fa_enabled".to_string()),
|
||||
@ -162,7 +162,7 @@ impl AppService {
|
||||
.exec(&self.db)
|
||||
.await?;
|
||||
|
||||
slog::info!(self.logs, "2FA disabled"; "user_uid" => %user_uid, "ip" => context.ip_address());
|
||||
tracing::info!(user_uid = %user_uid, ip = ?context.ip_address(), "2FA disabled");
|
||||
let _ = user_activity_log::ActiveModel {
|
||||
user_uid: Set(Some(user_uid)),
|
||||
action: Set("2fa_disabled".to_string()),
|
||||
@ -273,10 +273,10 @@ impl AppService {
|
||||
let secret = two_fa.secret.as_ref().ok_or(AppError::TwoFactorNotSetup)?;
|
||||
if self.verify_totp_code(secret, code)? {
|
||||
let _: Option<()> = conn.del(totp_key.as_str()).await.ok();
|
||||
slog::info!(self.logs, "2FA verification succeeded during login"; "user_uid" => %user_uid, "ip" => context.ip_address());
|
||||
tracing::info!(user_uid = %user_uid, ip = ?context.ip_address(), "2FA verification succeeded during login");
|
||||
return Ok(true);
|
||||
} else {
|
||||
slog::warn!(self.logs, "2FA verification failed during login"; "user_uid" => %user_uid, "ip" => context.ip_address());
|
||||
tracing::warn!(user_uid = %user_uid, ip = ?context.ip_address(), "2FA verification failed during login");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -324,7 +324,7 @@ impl AppService {
|
||||
.insert(&self.db)
|
||||
.await;
|
||||
|
||||
slog::info!(self.logs, "2FA backup codes regenerated"; "user_uid" => %user_uid, "ip" => context.ip_address());
|
||||
tracing::info!(user_uid = %user_uid, ip = ?context.ip_address(), "2FA backup codes regenerated");
|
||||
Ok(backup_codes)
|
||||
}
|
||||
|
||||
|
||||
@ -167,7 +167,7 @@ impl AppService {
|
||||
)
|
||||
.await
|
||||
{
|
||||
slog::debug!(self.logs, "cache set failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache set failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
Ok(response)
|
||||
|
||||
@ -144,7 +144,7 @@ impl AppService {
|
||||
)
|
||||
.await
|
||||
{
|
||||
slog::debug!(self.logs, "cache set failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache set failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
|
||||
@ -210,7 +210,7 @@ impl AppService {
|
||||
)
|
||||
.await
|
||||
{
|
||||
slog::debug!(self.logs, "cache set failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache set failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -427,7 +427,7 @@ impl AppService {
|
||||
)
|
||||
.await
|
||||
{
|
||||
slog::debug!(self.logs, "cache set failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache set failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -567,11 +567,7 @@ impl AppService {
|
||||
Ok(Some(r)) => r.project,
|
||||
Ok(None) => Uuid::nil(),
|
||||
Err(e) => {
|
||||
slog::warn!(
|
||||
self.logs,
|
||||
"failed to look up project_id for activity log: {}",
|
||||
e
|
||||
);
|
||||
tracing::warn!(error = ?e, "failed to look up project_id for activity log");
|
||||
Uuid::nil()
|
||||
}
|
||||
};
|
||||
@ -618,11 +614,7 @@ impl AppService {
|
||||
Ok(Some(r)) => r.project,
|
||||
Ok(None) => Uuid::nil(),
|
||||
Err(e) => {
|
||||
slog::warn!(
|
||||
self.logs,
|
||||
"failed to look up project_id for activity log: {}",
|
||||
e
|
||||
);
|
||||
tracing::warn!(error = ?e, "failed to look up project_id for activity log");
|
||||
Uuid::nil()
|
||||
}
|
||||
};
|
||||
@ -698,11 +690,7 @@ impl AppService {
|
||||
Ok(Some(r)) => r.project,
|
||||
Ok(None) => Uuid::nil(),
|
||||
Err(e) => {
|
||||
slog::warn!(
|
||||
self.logs,
|
||||
"failed to look up project_id for activity log: {}",
|
||||
e
|
||||
);
|
||||
tracing::warn!(error = ?e, "failed to look up project_id for activity log");
|
||||
Uuid::nil()
|
||||
}
|
||||
};
|
||||
@ -762,11 +750,7 @@ impl AppService {
|
||||
Ok(Some(r)) => r.project,
|
||||
Ok(None) => Uuid::nil(),
|
||||
Err(e) => {
|
||||
slog::warn!(
|
||||
self.logs,
|
||||
"failed to look up project_id for activity log: {}",
|
||||
e
|
||||
);
|
||||
tracing::warn!(error = ?e, "failed to look up project_id for activity log");
|
||||
Uuid::nil()
|
||||
}
|
||||
};
|
||||
|
||||
@ -510,7 +510,7 @@ impl AppService {
|
||||
)
|
||||
.await
|
||||
{
|
||||
slog::debug!(self.logs, "cache set failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache set failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
|
||||
@ -882,7 +882,7 @@ impl AppService {
|
||||
)
|
||||
.await
|
||||
{
|
||||
slog::debug!(self.logs, "cache set failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache set failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1097,7 +1097,7 @@ impl AppService {
|
||||
)
|
||||
.await
|
||||
{
|
||||
slog::debug!(self.logs, "cache set failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache set failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1274,7 +1274,7 @@ impl AppService {
|
||||
)
|
||||
.await
|
||||
{
|
||||
slog::debug!(self.logs, "cache set failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache set failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1350,7 +1350,7 @@ impl AppService {
|
||||
)
|
||||
.await
|
||||
{
|
||||
slog::debug!(self.logs, "cache set failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache set failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1400,7 +1400,7 @@ impl AppService {
|
||||
)
|
||||
.await
|
||||
{
|
||||
slog::debug!(self.logs, "cache set failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache set failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1450,7 +1450,7 @@ impl AppService {
|
||||
)
|
||||
.await
|
||||
{
|
||||
slog::debug!(self.logs, "cache set failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache set failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -129,7 +129,7 @@ impl AppService {
|
||||
)
|
||||
.await
|
||||
{
|
||||
slog::debug!(self.logs, "cache set failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache set failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -341,7 +341,7 @@ impl AppService {
|
||||
)
|
||||
.await
|
||||
{
|
||||
slog::debug!(self.logs, "cache set failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache set failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
|
||||
@ -390,7 +390,7 @@ impl AppService {
|
||||
)
|
||||
.await
|
||||
{
|
||||
slog::debug!(self.logs, "cache set failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache set failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
|
||||
@ -442,7 +442,7 @@ impl AppService {
|
||||
)
|
||||
.await
|
||||
{
|
||||
slog::debug!(self.logs, "cache set failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache set failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
|
||||
@ -623,7 +623,7 @@ impl AppService {
|
||||
)
|
||||
.await
|
||||
{
|
||||
slog::debug!(self.logs, "cache set failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache set failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -151,7 +151,7 @@ impl AppService {
|
||||
)
|
||||
.await
|
||||
{
|
||||
slog::debug!(self.logs, "cache set failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache set failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,7 +204,7 @@ impl AppService {
|
||||
if let Ok(mut conn) = self.cache.conn().await {
|
||||
let key = format!("git:ref:list:{}:{}:*", namespace, repo_name);
|
||||
if let Err(e) = conn.del::<String, ()>(key).await {
|
||||
slog::debug!(self.logs, "cache del failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache del failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
|
||||
@ -237,7 +237,7 @@ impl AppService {
|
||||
if let Ok(mut conn) = self.cache.conn().await {
|
||||
let key = format!("git:ref:list:{}:{}:*", namespace, repo_name);
|
||||
if let Err(e) = conn.del::<String, ()>(key).await {
|
||||
slog::debug!(self.logs, "cache del failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache del failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
|
||||
@ -272,7 +272,7 @@ impl AppService {
|
||||
if let Ok(mut conn) = self.cache.conn().await {
|
||||
let key = format!("git:ref:list:{}:{}:*", namespace, repo_name);
|
||||
if let Err(e) = conn.del::<String, ()>(key).await {
|
||||
slog::debug!(self.logs, "cache del failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache del failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -55,11 +55,7 @@ impl AppService {
|
||||
Ok(Some(r)) => r.project,
|
||||
Ok(None) => Uuid::nil(),
|
||||
Err(e) => {
|
||||
slog::warn!(
|
||||
self.logs,
|
||||
"failed to look up project_id for activity log: {}",
|
||||
e
|
||||
);
|
||||
tracing::warn!(error = ?e, "failed to look up project_id for activity log");
|
||||
Uuid::nil()
|
||||
}
|
||||
};
|
||||
@ -107,11 +103,7 @@ impl AppService {
|
||||
Ok(Some(r)) => r.project,
|
||||
Ok(None) => Uuid::nil(),
|
||||
Err(e) => {
|
||||
slog::warn!(
|
||||
self.logs,
|
||||
"failed to look up project_id for activity log: {}",
|
||||
e
|
||||
);
|
||||
tracing::warn!(error = ?e, "failed to look up project_id for activity log");
|
||||
Uuid::nil()
|
||||
}
|
||||
};
|
||||
|
||||
@ -161,7 +161,7 @@ impl AppService {
|
||||
)
|
||||
.await
|
||||
{
|
||||
slog::debug!(self.logs, "cache set failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache set failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
Ok(tags)
|
||||
@ -263,7 +263,7 @@ impl AppService {
|
||||
)
|
||||
.await
|
||||
{
|
||||
slog::debug!(self.logs, "cache set failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache set failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
Ok(response)
|
||||
@ -407,18 +407,14 @@ impl AppService {
|
||||
if let Ok(mut conn) = self.cache.conn().await {
|
||||
let key = format!("git:tag:list:{}:{}", namespace, repo_name);
|
||||
if let Err(e) = conn.del::<String, ()>(key).await {
|
||||
slog::debug!(self.logs, "cache del failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache del failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
let project_id = match repo_model::Entity::find_by_id(repo_id).one(&self.db).await {
|
||||
Ok(Some(r)) => r.project,
|
||||
Ok(None) => Uuid::nil(),
|
||||
Err(e) => {
|
||||
slog::warn!(
|
||||
self.logs,
|
||||
"failed to look up project_id for activity log: {}",
|
||||
e
|
||||
);
|
||||
tracing::warn!(error = ?e, "failed to look up project_id for activity log");
|
||||
Uuid::nil()
|
||||
}
|
||||
};
|
||||
@ -459,18 +455,14 @@ impl AppService {
|
||||
if let Ok(mut conn) = self.cache.conn().await {
|
||||
let key = format!("git:tag:list:{}:{}", namespace, repo_name);
|
||||
if let Err(e) = conn.del::<String, ()>(key).await {
|
||||
slog::debug!(self.logs, "cache del failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache del failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
let project_id = match repo_model::Entity::find_by_id(repo_id).one(&self.db).await {
|
||||
Ok(Some(r)) => r.project,
|
||||
Ok(None) => Uuid::nil(),
|
||||
Err(e) => {
|
||||
slog::warn!(
|
||||
self.logs,
|
||||
"failed to look up project_id for activity log: {}",
|
||||
e
|
||||
);
|
||||
tracing::warn!(error = ?e, "failed to look up project_id for activity log");
|
||||
Uuid::nil()
|
||||
}
|
||||
};
|
||||
@ -511,21 +503,17 @@ impl AppService {
|
||||
let list_key = format!("git:tag:list:{}:{}", namespace, repo_name);
|
||||
let get_key = format!("git:tag:get:{}:{}:{}", namespace, repo_name, query.name);
|
||||
if let Err(e) = conn.del::<String, ()>(list_key).await {
|
||||
slog::debug!(self.logs, "cache del failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache del failed (non-fatal)");
|
||||
}
|
||||
if let Err(e) = conn.del::<String, ()>(get_key).await {
|
||||
slog::debug!(self.logs, "cache del failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache del failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
let project_id = match repo_model::Entity::find_by_id(repo_id).one(&self.db).await {
|
||||
Ok(Some(r)) => r.project,
|
||||
Ok(None) => Uuid::nil(),
|
||||
Err(e) => {
|
||||
slog::warn!(
|
||||
self.logs,
|
||||
"failed to look up project_id for activity log: {}",
|
||||
e
|
||||
);
|
||||
tracing::warn!(error = ?e, "failed to look up project_id for activity log");
|
||||
Uuid::nil()
|
||||
}
|
||||
};
|
||||
@ -567,13 +555,13 @@ impl AppService {
|
||||
let old_key = format!("git:tag:get:{}:{}:{}", namespace, repo_name, query.old_name);
|
||||
let new_key = format!("git:tag:get:{}:{}:{}", namespace, repo_name, query.new_name);
|
||||
if let Err(e) = conn.del::<String, ()>(list_key).await {
|
||||
slog::debug!(self.logs, "cache del failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache del failed (non-fatal)");
|
||||
}
|
||||
if let Err(e) = conn.del::<String, ()>(old_key).await {
|
||||
slog::debug!(self.logs, "cache del failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache del failed (non-fatal)");
|
||||
}
|
||||
if let Err(e) = conn.del::<String, ()>(new_key).await {
|
||||
slog::debug!(self.logs, "cache del failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache del failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
let response = TagInfoResponse::from(info);
|
||||
@ -581,11 +569,7 @@ impl AppService {
|
||||
Ok(Some(r)) => r.project,
|
||||
Ok(None) => Uuid::nil(),
|
||||
Err(e) => {
|
||||
slog::warn!(
|
||||
self.logs,
|
||||
"failed to look up project_id for activity log: {}",
|
||||
e
|
||||
);
|
||||
tracing::warn!(error = ?e, "failed to look up project_id for activity log");
|
||||
Uuid::nil()
|
||||
}
|
||||
};
|
||||
@ -637,10 +621,10 @@ impl AppService {
|
||||
let list_key = format!("git:tag:list:{}:{}", namespace, repo_name);
|
||||
let get_key = format!("git:tag:get:{}:{}:{}", namespace, repo_name, request.name);
|
||||
if let Err(e) = conn.del::<String, ()>(list_key).await {
|
||||
slog::debug!(self.logs, "cache del failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache del failed (non-fatal)");
|
||||
}
|
||||
if let Err(e) = conn.del::<String, ()>(get_key).await {
|
||||
slog::debug!(self.logs, "cache del failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache del failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
Ok(TagInfoResponse::from(info))
|
||||
|
||||
@ -193,7 +193,7 @@ impl AppService {
|
||||
)
|
||||
.await
|
||||
{
|
||||
slog::debug!(self.logs, "cache set failed (non-fatal): {}", e);
|
||||
tracing::debug!(error = ?e, "cache set failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -70,11 +70,7 @@ impl AppService {
|
||||
Ok(Some(r)) => r.project,
|
||||
Ok(None) => Uuid::nil(),
|
||||
Err(e) => {
|
||||
slog::warn!(
|
||||
self.logs,
|
||||
"failed to look up project_id for activity log: {}",
|
||||
e
|
||||
);
|
||||
tracing::warn!(error = ?e, "failed to look up project_id for activity log");
|
||||
Uuid::nil()
|
||||
}
|
||||
};
|
||||
@ -120,11 +116,7 @@ impl AppService {
|
||||
Ok(Some(r)) => r.project,
|
||||
Ok(None) => Uuid::nil(),
|
||||
Err(e) => {
|
||||
slog::warn!(
|
||||
self.logs,
|
||||
"failed to look up project_id for activity log: {}",
|
||||
e
|
||||
);
|
||||
tracing::warn!(error = ?e, "failed to look up project_id for activity log");
|
||||
Uuid::nil()
|
||||
}
|
||||
};
|
||||
|
||||
@ -16,7 +16,6 @@ use queue::{
|
||||
use room::metrics::RoomMetrics;
|
||||
use room::RoomService;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use observability::build_logger;
|
||||
use utoipa::ToSchema;
|
||||
use ws_token::WsTokenService;
|
||||
|
||||
@ -31,7 +30,6 @@ pub struct AppService {
|
||||
pub config: AppConfig,
|
||||
pub cache: AppCache,
|
||||
pub email: AppEmail,
|
||||
pub logs: slog::Logger,
|
||||
pub avatar: AppAvatar,
|
||||
pub room: RoomService,
|
||||
pub ws_token: Arc<WsTokenService>,
|
||||
@ -47,7 +45,6 @@ impl AppService {
|
||||
pub fn send_push_to_user(&self, user_id: uuid::Uuid, payload: PushPayload) {
|
||||
let push = self.push.clone();
|
||||
let db = self.db.clone();
|
||||
let log = self.logs.clone();
|
||||
|
||||
tokio::spawn(async move {
|
||||
if let Some(push) = push {
|
||||
@ -69,11 +66,11 @@ impl AppService {
|
||||
let auth = prefs.push_subscription_keys_auth.unwrap();
|
||||
|
||||
if let Err(e) = push.send(&endpoint, &p256dh, &auth, &payload).await {
|
||||
slog::warn!(log, "WebPush send failed"; "user_id" => %user_id, "error" => %e);
|
||||
tracing::warn!(user_id = %user_id, error = %e, "WebPush send failed");
|
||||
}
|
||||
}
|
||||
} else if let Err(e) = prefs {
|
||||
slog::warn!(log, "Failed to read push subscription"; "user_id" => %user_id, "error" => %e);
|
||||
tracing::warn!(user_id = %user_id, error = %e, "Failed to read push subscription");
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -84,27 +81,23 @@ impl AppService {
|
||||
pub async fn start_room_workers(
|
||||
&self,
|
||||
shutdown_rx: tokio::sync::broadcast::Receiver<()>,
|
||||
log: slog::Logger,
|
||||
) -> anyhow::Result<()> {
|
||||
self.room.start_workers(shutdown_rx, log).await
|
||||
self.room.start_workers(shutdown_rx).await
|
||||
}
|
||||
|
||||
pub async fn new(config: AppConfig) -> anyhow::Result<Self> {
|
||||
let db = AppDatabase::init(&config).await?;
|
||||
let cache = AppCache::init(&config).await?;
|
||||
|
||||
let log_level = config.log_level().unwrap_or_else(|_| "info".to_string());
|
||||
let logs = build_logger(&log_level);
|
||||
|
||||
let email = AppEmail::init(&config, logs.clone()).await?;
|
||||
let email = AppEmail::init(&config).await?;
|
||||
let avatar = AppAvatar::init(&config).await?;
|
||||
let storage = match AppStorage::new(&config) {
|
||||
Ok(s) => {
|
||||
slog::info!(logs, "Storage initialized at {}", s.base_path.display());
|
||||
tracing::info!(path = %s.base_path.display(), "Storage initialized");
|
||||
Some(s)
|
||||
}
|
||||
Err(e) => {
|
||||
slog::warn!(logs, "Storage not available: {}", e);
|
||||
tracing::warn!(error = %e, "Storage not available");
|
||||
None
|
||||
}
|
||||
};
|
||||
@ -120,17 +113,17 @@ impl AppService {
|
||||
config.vapid_sender_email(),
|
||||
) {
|
||||
Ok(s) => {
|
||||
slog::info!(logs, "WebPush initialized");
|
||||
tracing::info!("WebPush initialized");
|
||||
Some(s)
|
||||
}
|
||||
Err(e) => {
|
||||
slog::warn!(logs, "WebPush not available: {}", e);
|
||||
tracing::warn!(error = %e, "WebPush not available");
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
slog::warn!(logs, "WebPush disabled — VAPID keys not configured");
|
||||
tracing::warn!("WebPush disabled — VAPID keys not configured");
|
||||
None
|
||||
}
|
||||
};
|
||||
@ -150,11 +143,10 @@ impl AppService {
|
||||
|
||||
let redis_pubsub = Some(RedisPubSub {
|
||||
get_redis: get_redis.clone(),
|
||||
log: logs.clone(),
|
||||
});
|
||||
|
||||
let message_producer =
|
||||
MessageProducer::new(get_redis.clone(), redis_pubsub.clone(), 10000, logs.clone());
|
||||
MessageProducer::new(get_redis.clone(), redis_pubsub.clone(), 10000);
|
||||
|
||||
// Build RoomService
|
||||
let task_service = Arc::new(TaskService::new(db.clone()));
|
||||
@ -173,7 +165,7 @@ impl AppService {
|
||||
let chat_service: Option<Arc<ChatService>> =
|
||||
match (config.ai_api_key(), config.ai_basic_url()) {
|
||||
(Ok(api_key), Ok(base_url)) => {
|
||||
slog::info!(logs, "AI chat enabled — connecting to {}", base_url);
|
||||
tracing::info!(url = %base_url, "AI chat enabled");
|
||||
let cfg = OpenAIConfig::new()
|
||||
.with_api_key(&api_key)
|
||||
.with_api_base(&base_url);
|
||||
@ -187,11 +179,11 @@ impl AppService {
|
||||
))
|
||||
}
|
||||
(Err(e), _) => {
|
||||
slog::warn!(logs, "AI chat disabled — {}", e);
|
||||
tracing::warn!(error = %e, "AI chat disabled");
|
||||
None
|
||||
}
|
||||
(_, Err(e)) => {
|
||||
slog::warn!(logs, "AI chat disabled — {}", e);
|
||||
tracing::warn!(error = %e, "AI chat disabled");
|
||||
None
|
||||
}
|
||||
};
|
||||
@ -199,11 +191,9 @@ impl AppService {
|
||||
// Build push notification callback for RoomService
|
||||
let push_fn: Option<room::PushNotificationFn> = push.clone().map(|push_svc| {
|
||||
let db_clone = db.clone();
|
||||
let log_clone = logs.clone();
|
||||
Arc::new(move |user_id: uuid::Uuid, title: String, body: Option<String>, url: Option<String>| {
|
||||
let push = push_svc.clone();
|
||||
let db = db_clone.clone();
|
||||
let log = log_clone.clone();
|
||||
let payload = PushPayload {
|
||||
title,
|
||||
body: body.unwrap_or_default(),
|
||||
@ -229,7 +219,7 @@ impl AppService {
|
||||
let auth = prefs.push_subscription_keys_auth.unwrap();
|
||||
|
||||
if let Err(e) = push.send(&endpoint, &p256dh, &auth, &payload).await {
|
||||
slog::warn!(log, "WebPush send failed"; "user_id" => %user_id, "error" => %e);
|
||||
tracing::warn!(user_id = %user_id, error = %e, "WebPush send failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -246,7 +236,6 @@ impl AppService {
|
||||
redis_url,
|
||||
chat_service,
|
||||
Some(task_service.clone()),
|
||||
logs.clone(),
|
||||
None,
|
||||
push_fn,
|
||||
);
|
||||
@ -259,7 +248,6 @@ impl AppService {
|
||||
config,
|
||||
cache,
|
||||
email,
|
||||
logs,
|
||||
avatar,
|
||||
room,
|
||||
ws_token,
|
||||
@ -280,10 +268,8 @@ impl AppService {
|
||||
});
|
||||
|
||||
let email = self.email.clone();
|
||||
let logs = self.logs.clone();
|
||||
let send_fn: EmailSendFn = Arc::new(move |envelopes: Vec<EmailEnvelope>| -> EmailSendFut {
|
||||
let email = email.clone();
|
||||
let logs = logs.clone();
|
||||
Box::pin(async move {
|
||||
for envelope in envelopes {
|
||||
let to = envelope.to.clone();
|
||||
@ -293,15 +279,14 @@ impl AppService {
|
||||
body: envelope.body,
|
||||
};
|
||||
if let Err(e) = email.send(msg).await {
|
||||
let err = format!("email send failed to:{} error: {}", to, e);
|
||||
slog::error!(logs, "{}", err);
|
||||
tracing::error!(to = %to, error = %e, "email send failed");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
});
|
||||
|
||||
start_email_worker(get_redis, send_fn, shutdown_rx, self.logs.clone()).await;
|
||||
start_email_worker(get_redis, send_fn, shutdown_rx).await;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -270,11 +270,7 @@ impl AppService {
|
||||
Ok(Some(m)) => m.scope_role().ok(),
|
||||
Ok(None) => None,
|
||||
Err(e) => {
|
||||
slog::warn!(
|
||||
self.logs,
|
||||
"failed to look up project member for activity log: {}",
|
||||
e
|
||||
);
|
||||
tracing::warn!(error = ?e, "failed to look up project member for activity log");
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
@ -297,18 +297,16 @@ impl AppService {
|
||||
/// Runs every ALERT_CHECK_INTERVAL seconds.
|
||||
pub fn start_billing_alert_task(self) -> tokio::task::JoinHandle<()> {
|
||||
const ALERT_CHECK_INTERVAL: u64 = 30 * 60; // 30 minutes
|
||||
let logs = self.logs.clone();
|
||||
tokio::spawn(async move {
|
||||
let mut tick = interval(Duration::from_secs(ALERT_CHECK_INTERVAL));
|
||||
loop {
|
||||
tick.tick().await;
|
||||
let result = self.check_billing_alerts().await;
|
||||
if result.alerts_sent > 0 {
|
||||
slog::info!(
|
||||
logs,
|
||||
"billing_alerts_sent";
|
||||
"workspaces_checked" => result.workspaces_checked,
|
||||
"alerts_sent" => result.alerts_sent
|
||||
tracing::info!(
|
||||
workspaces_checked = result.workspaces_checked,
|
||||
alerts_sent = result.alerts_sent,
|
||||
"billing_alerts_sent"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user