mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-05-02 14:56:10 -04:00
feat(cli): Add span with swap_id to all logs caused by swap (#96)
* feat(cli): Add span with swap_id to all logs caused by swap
This commit is contained in:
parent
1dd35b3ae5
commit
f91255ff76
1 changed files with 18 additions and 5 deletions
|
@ -25,7 +25,9 @@ use std::net::SocketAddr;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
use tracing::debug_span;
|
||||||
use tracing::Instrument;
|
use tracing::Instrument;
|
||||||
|
use tracing::Span;
|
||||||
use typeshare::typeshare;
|
use typeshare::typeshare;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
@ -38,6 +40,11 @@ pub trait Request {
|
||||||
async fn request(self, ctx: Arc<Context>) -> Result<Self::Response>;
|
async fn request(self, ctx: Arc<Context>) -> Result<Self::Response>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This generates a tracing span which is attached to all logs caused by a swap
|
||||||
|
fn get_swap_tracing_span(swap_id: Uuid) -> Span {
|
||||||
|
debug_span!("swap", swap_id = %swap_id)
|
||||||
|
}
|
||||||
|
|
||||||
// BuyXmr
|
// BuyXmr
|
||||||
#[typeshare]
|
#[typeshare]
|
||||||
#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||||
|
@ -62,7 +69,10 @@ impl Request for BuyXmrArgs {
|
||||||
type Response = BuyXmrResponse;
|
type Response = BuyXmrResponse;
|
||||||
|
|
||||||
async fn request(self, ctx: Arc<Context>) -> Result<Self::Response> {
|
async fn request(self, ctx: Arc<Context>) -> Result<Self::Response> {
|
||||||
buy_xmr(self, ctx).await
|
let swap_id = Uuid::new_v4();
|
||||||
|
let swap_span = get_swap_tracing_span(swap_id);
|
||||||
|
|
||||||
|
buy_xmr(self, swap_id, ctx).instrument(swap_span).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +94,9 @@ impl Request for ResumeSwapArgs {
|
||||||
type Response = ResumeSwapResponse;
|
type Response = ResumeSwapResponse;
|
||||||
|
|
||||||
async fn request(self, ctx: Arc<Context>) -> Result<Self::Response> {
|
async fn request(self, ctx: Arc<Context>) -> Result<Self::Response> {
|
||||||
resume_swap(self, ctx).await
|
let swap_span = get_swap_tracing_span(self.swap_id);
|
||||||
|
|
||||||
|
resume_swap(self, ctx).instrument(swap_span).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +112,9 @@ impl Request for CancelAndRefundArgs {
|
||||||
type Response = serde_json::Value;
|
type Response = serde_json::Value;
|
||||||
|
|
||||||
async fn request(self, ctx: Arc<Context>) -> Result<Self::Response> {
|
async fn request(self, ctx: Arc<Context>) -> Result<Self::Response> {
|
||||||
cancel_and_refund(self, ctx).await
|
let swap_span = get_swap_tracing_span(self.swap_id);
|
||||||
|
|
||||||
|
cancel_and_refund(self, ctx).instrument(swap_span).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -536,6 +550,7 @@ pub async fn get_swap_info(
|
||||||
#[tracing::instrument(fields(method = "buy_xmr"), skip(context))]
|
#[tracing::instrument(fields(method = "buy_xmr"), skip(context))]
|
||||||
pub async fn buy_xmr(
|
pub async fn buy_xmr(
|
||||||
buy_xmr: BuyXmrArgs,
|
buy_xmr: BuyXmrArgs,
|
||||||
|
swap_id: Uuid,
|
||||||
context: Arc<Context>,
|
context: Arc<Context>,
|
||||||
) -> Result<BuyXmrResponse, anyhow::Error> {
|
) -> Result<BuyXmrResponse, anyhow::Error> {
|
||||||
let BuyXmrArgs {
|
let BuyXmrArgs {
|
||||||
|
@ -544,8 +559,6 @@ pub async fn buy_xmr(
|
||||||
monero_receive_address,
|
monero_receive_address,
|
||||||
} = buy_xmr;
|
} = buy_xmr;
|
||||||
|
|
||||||
let swap_id = Uuid::new_v4();
|
|
||||||
|
|
||||||
let bitcoin_wallet = Arc::clone(
|
let bitcoin_wallet = Arc::clone(
|
||||||
context
|
context
|
||||||
.bitcoin_wallet
|
.bitcoin_wallet
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue