feat(asb + cli): Redact logs + unify tracing infrastructure (#1733) (#55)

* feat(asb + cli): Redact logs + unify tracing infrastructure (#1733)

Applies the changes from https://github.com/comit-network/xmr-btc-swap/pull/1733 to this fork

---------

Co-authored-by: Einliterflasche <81313171+Einliterflasche@users.noreply.github.com>
This commit is contained in:
binarybaron 2024-09-01 18:13:43 +02:00 committed by GitHub
parent 1fe6391b7b
commit 792fbbf746
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 1780 additions and 1396 deletions

View file

@ -3,6 +3,7 @@ use crate::bitcoin::{CancelTimelock, ExpiredTimelocks, PunishTimelock, TxLock};
use crate::cli::api::tauri_bindings::{TauriEmitter, TauriSwapProgressEvent};
use crate::cli::api::Context;
use crate::cli::{list_sellers as list_sellers_impl, EventLoop, SellerStatus};
use crate::common::get_logs;
use crate::libp2p_ext::MultiAddrExt;
use crate::network::quote::{BidQuote, ZeroQuoteReceived};
use crate::network::swarm;
@ -21,6 +22,7 @@ use std::cmp::min;
use std::convert::TryInto;
use std::future::Future;
use std::net::SocketAddr;
use std::path::PathBuf;
use std::sync::Arc;
use std::time::Duration;
use tracing::Instrument;
@ -354,6 +356,36 @@ impl Request for GetSwapInfosAllArgs {
}
}
#[typeshare]
#[derive(Serialize, Deserialize, Debug)]
pub struct GetLogsArgs {
pub swap_id: Option<Uuid>,
pub redact: bool,
#[typeshare(serialized_as = "string")]
pub logs_dir: Option<PathBuf>,
}
#[typeshare]
#[derive(Serialize, Debug)]
pub struct GetLogsResponse {
logs: Vec<String>,
}
impl Request for GetLogsArgs {
type Response = GetLogsResponse;
async fn request(self, ctx: Arc<Context>) -> Result<Self::Response> {
let dir = self.logs_dir.unwrap_or(ctx.config.data_dir.join("logs"));
let logs = get_logs(dir, self.swap_id, self.redact).await?;
for msg in &logs {
println!("{msg}");
}
Ok(GetLogsResponse { logs })
}
}
#[tracing::instrument(fields(method = "suspend_current_swap"), skip(context))]
pub async fn suspend_current_swap(context: Arc<Context>) -> Result<SuspendCurrentSwapResponse> {
let swap_id = context.swap_lock.get_current_swap_id().await;