Skip to content

Commit

Permalink
chore: improve tracing naming
Browse files Browse the repository at this point in the history
  • Loading branch information
bodymindarts committed Feb 6, 2023
1 parent a26082a commit fb3c18b
Show file tree
Hide file tree
Showing 17 changed files with 96 additions and 74 deletions.
38 changes: 23 additions & 15 deletions bitfinex-client/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl BitfinexClient {
})
}

#[instrument(skip(self), err)]
#[instrument(name = "bitfinex_client.funding_info", skip(self), err)]
pub async fn funding_info(&self) -> Result<FundingInfo, BitfinexClientError> {
let body: HashMap<String, String> = HashMap::new();
let request_body = serde_json::to_string(&body)?;
Expand Down Expand Up @@ -108,7 +108,7 @@ impl BitfinexClient {
})
}

#[instrument(skip(self), err)]
#[instrument(name = "bitfinex_client.get_orders", skip(self), err)]
pub async fn get_orders(&self) -> Result<Vec<OrderDetails>, BitfinexClientError> {
let body: HashMap<String, String> = HashMap::new();
let request_body = serde_json::to_string(&body)?;
Expand Down Expand Up @@ -140,7 +140,7 @@ impl BitfinexClient {
Ok(orders)
}

#[instrument(skip(self), err)]
#[instrument(name = "bitfinex_client.get_wallets", skip(self), err)]
pub async fn get_wallets(&self) -> Result<Vec<WalletDetails>, BitfinexClientError> {
let body: HashMap<String, String> = HashMap::new();
let request_body = serde_json::to_string(&body)?;
Expand All @@ -162,7 +162,7 @@ impl BitfinexClient {
Ok(wallets)
}

#[instrument(skip(self), err)]
#[instrument(name = "bitfinex_client.get_positions", skip(self), err)]
pub async fn get_positions(&self) -> Result<Vec<PositionDetails>, BitfinexClientError> {
let body: HashMap<String, String> = HashMap::new();
let request_body = serde_json::to_string(&body)?;
Expand All @@ -184,7 +184,11 @@ impl BitfinexClient {
Ok(positions)
}

#[instrument(skip(self), err)]
#[instrument(
name = "bitfinex_client.get_btc_on_chain_deposit_address",
skip(self),
err
)]
pub async fn get_btc_on_chain_deposit_address(
&self,
) -> Result<DepositAddress, BitfinexClientError> {
Expand All @@ -210,7 +214,7 @@ impl BitfinexClient {
Ok(details.address)
}

#[instrument(skip(self), err)]
#[instrument(name = "bitfinex_client.get_ln_deposit_address", skip(self), err)]
pub async fn get_ln_deposit_address(&self) -> Result<DepositAddress, BitfinexClientError> {
let mut body: HashMap<String, String> = HashMap::new();
body.insert("wallet".to_string(), Wallet::EXCHANGE.to_string());
Expand All @@ -234,7 +238,7 @@ impl BitfinexClient {
Ok(details.address)
}

#[instrument(skip(self), err)]
#[instrument(name = "bitfinex_client.get_ln_invoice", skip(self), err)]
pub async fn get_ln_invoice(
&self,
client_id: ClientId,
Expand Down Expand Up @@ -263,7 +267,7 @@ impl BitfinexClient {
Ok(invoice)
}

#[instrument(skip(self), err)]
#[instrument(name = "bitfinex_client.transfer_funding_to_trading", skip(self), err)]
pub async fn transfer_funding_to_trading(
&self,
client_id: ClientId,
Expand Down Expand Up @@ -299,7 +303,7 @@ impl BitfinexClient {
Ok(transfer)
}

#[instrument(skip(self), err)]
#[instrument(name = "bitfinex_client.transfer_trading_to_funding", skip(self), err)]
pub async fn transfer_trading_to_funding(
&self,
client_id: ClientId,
Expand Down Expand Up @@ -335,7 +339,7 @@ impl BitfinexClient {
Ok(transfer)
}

#[instrument(skip(self), err)]
#[instrument(name = "bitfinex_client.withdraw_btc_onchain", skip(self), err)]
pub async fn withdraw_btc_onchain(
&self,
client_id: ClientId,
Expand Down Expand Up @@ -368,7 +372,7 @@ impl BitfinexClient {
Ok(transfer)
}

#[instrument(skip(self), err)]
#[instrument(name = "bitfinex_client.withdraw_btc_on_ln", skip(self), err)]
pub async fn withdraw_btc_on_ln(
&self,
client_id: ClientId,
Expand Down Expand Up @@ -398,7 +402,7 @@ impl BitfinexClient {
Ok(transfer)
}

#[instrument(skip(self), err)]
#[instrument(name = "bitfinex_client.get_ln_transactions", skip(self), err)]
pub async fn get_ln_transactions(
&self,
client_id: ClientId,
Expand All @@ -423,7 +427,11 @@ impl BitfinexClient {
Ok(transactions)
}

#[instrument(skip(self), err)]
#[instrument(
name = "bitfinex_client.get_btc_on_chain_transactions",
skip(self),
err
)]
pub async fn get_btc_on_chain_transactions(
&self,
client_id: ClientId,
Expand All @@ -448,7 +456,7 @@ impl BitfinexClient {
Ok(transactions)
}

#[instrument(skip(self), err)]
#[instrument(name = "bitfinex_client.submit_order", skip(self), err)]
pub async fn submit_order(
&self,
client_id: ClientId,
Expand Down Expand Up @@ -490,7 +498,7 @@ impl BitfinexClient {
Ok(order)
}

#[instrument(skip(self), err)]
#[instrument(name = "bitfinex_client.get_api_key_permissions", skip(self), err)]
pub async fn get_api_key_permissions(&self) -> Result<Vec<ApiKeyDetails>, BitfinexClientError> {
let body: HashMap<String, String> = HashMap::new();
let request_body = serde_json::to_string(&body)?;
Expand Down
2 changes: 1 addition & 1 deletion cli/src/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async fn health_check(
StatusCode::OK
}

#[instrument(skip_all, fields(component_name, error = true, error.level, error.message, n_errors))]
#[instrument(name = "health.health_check_error", skip_all, fields(component_name, error = true, error.level, error.message, n_errors))]
async fn health_check_error(
name: &str,
n_errors: Arc<RwLock<usize>>,
Expand Down
14 changes: 7 additions & 7 deletions galoy-client/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl GaloyClient {
})
}

#[instrument(name = "galoy_login_jwt", skip_all, err)]
#[instrument(name = "galoy_client.login_jwt", skip_all, err)]
async fn login_jwt(config: GaloyClientConfig) -> Result<StablesatsAuthToken, GaloyClientError> {
let variables = stablesats_user_login::Variables {
input: stablesats_user_login::UserLoginInput {
Expand Down Expand Up @@ -111,7 +111,7 @@ impl GaloyClient {
Ok(auth_token)
}

#[instrument(name = "galoy_wallet_ids", skip_all, err)]
#[instrument(name = "galoy_client.wallet_ids", skip_all, err)]
async fn wallet_ids(
client: ReqwestClient,
config: GaloyClientConfig,
Expand Down Expand Up @@ -147,7 +147,7 @@ impl GaloyClient {
Ok(wallet_id)
}

#[instrument(name = "galoy_transactions_list", skip(self), err)]
#[instrument(name = "galoy_client.transactions_list", skip(self), err)]
pub async fn transactions_list(
&self,
cursor: Option<TxCursor>,
Expand Down Expand Up @@ -183,7 +183,7 @@ impl GaloyClient {
GaloyTransactions::try_from(result)
}

#[instrument(name = "galoy_wallet_balances", skip(self), err)]
#[instrument(name = "galoy_client.wallet_balances", skip(self), err)]
pub async fn wallet_balances(&self) -> Result<WalletBalances, GaloyClientError> {
let variables = stablesats_wallets::Variables;
let response = GaloyClient::traced_gql_request::<StablesatsWallets, _>(
Expand Down Expand Up @@ -214,7 +214,7 @@ impl GaloyClient {
WalletBalances::try_from(result)
}

#[instrument(name = "galoy_onchain_address", skip(self), err)]
#[instrument(name = "galoy_client.onchain_address", skip(self), err)]
pub async fn onchain_address(&self) -> Result<OnchainAddress, GaloyClientError> {
let variables = stablesats_deposit_address::Variables {
input: stablesats_deposit_address::OnChainAddressCurrentInput {
Expand Down Expand Up @@ -258,7 +258,7 @@ impl GaloyClient {
Ok(OnchainAddress { address })
}

#[instrument(name = "galoy_send_onchain_payment", skip(self), err)]
#[instrument(name = "galoy_client.send_onchain_payment", skip(self), err)]
pub async fn send_onchain_payment(
&self,
address: String,
Expand Down Expand Up @@ -318,7 +318,7 @@ impl GaloyClient {
Ok(status)
}

#[instrument(name = "galoy_onchain_tx_fee", skip(self), err)]
#[instrument(name = "galoy_client.onchain_tx_fee", skip(self), err)]
pub async fn onchain_tx_fee(
&self,
address: OnChainAddress,
Expand Down
4 changes: 2 additions & 2 deletions hedging/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl HedgingApp {
if let PriceStreamPayload::OkexBtcSwapPricePayload(_) = msg.payload {
let correlation_id = msg.meta.correlation_id;
let span = info_span!(
"okex_btc_usd_swap_price_received",
"hedging.okex_btc_usd_swap_price_received",
message_type = %msg.payload_type,
correlation_id = %correlation_id,
error = tracing::field::Empty,
Expand Down Expand Up @@ -201,7 +201,7 @@ impl HedgingApp {
while let Some(msg) = stream.next().await {
let correlation_id = msg.meta.correlation_id;
let span = info_span!(
"okex_btc_usd_swap_position_received",
"hedging.okex_btc_usd_swap_position_received",
message_type = %msg.payload_type,
correlation_id = %correlation_id,
error = tracing::field::Empty,
Expand Down
2 changes: 1 addition & 1 deletion hedging/src/job/adjust_funding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{error::*, okex_transfers::*, rebalance_action::*};

const SATS_PER_BTC: Decimal = dec!(100_000_000);

#[instrument(name = "adjust_funding", skip_all, fields(correlation_id = %correlation_id,
#[instrument(name = "hedging.job.adjust_funding", skip_all, fields(correlation_id = %correlation_id,
target_liability, current_position, last_price_in_usd_cents, funding_available_balance,
trading_available_balance, onchain_fees, action, client_transfer_id,
transferred_funding) err)]
Expand Down
2 changes: 1 addition & 1 deletion hedging/src/job/adjust_hedge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use shared::pubsub::CorrelationId;

use crate::{adjustment_action::*, error::*, okex_orders::*};

#[instrument(name = "adjust_hedge", skip_all, fields(correlation_id = %correlation_id,
#[instrument(name = "hedging.job.adjust_hedge", skip_all, fields(correlation_id = %correlation_id,
target_liability, current_position, action, placed_order, client_order_id) err)]
pub(super) async fn execute(
correlation_id: CorrelationId,
Expand Down
6 changes: 3 additions & 3 deletions hedging/src/job/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub async fn start_job_runner(
.await?)
}

#[instrument(skip_all, fields(error, error.level, error.message), err)]
#[instrument(name = "hedging.job.spawn_poll_okex", skip_all, fields(error, error.level, error.message), err)]
pub async fn spawn_poll_okex(
pool: &sqlx::PgPool,
duration: std::time::Duration,
Expand Down Expand Up @@ -88,7 +88,7 @@ struct AdjustHedgeData {
tracing_data: HashMap<String, String>,
}

#[instrument(skip_all, fields(error, error.message) err)]
#[instrument(name = "hedging.job.spawn_adjust_hedge", skip_all, fields(error, error.message) err)]
pub async fn spawn_adjust_hedge<'a>(
tx: impl Executor<'a, Database = Postgres>,
trigger_id: impl Into<Uuid>,
Expand Down Expand Up @@ -170,7 +170,7 @@ struct AdjustFundingData {
tracing_data: HashMap<String, String>,
}

#[instrument(skip_all, fields(error, error.message) err)]
#[instrument(name = "hedging.job.spawn_adjust_funding", skip_all, fields(error, error.message) err)]
pub async fn spawn_adjust_funding<'a>(
tx: impl Executor<'a, Database = Postgres>,
trigger_id: impl Into<Uuid>,
Expand Down
12 changes: 10 additions & 2 deletions ledger/src/balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,20 @@ impl<'a> Balances<'a> {
.await
}

#[instrument(
name = "ledger.balances.target_liability_in_cents",
skip(self),
fields(liability),
err
)]
pub async fn target_liability_in_cents(&self) -> Result<SyntheticCentLiability, LedgerError> {
let liability = self.stablesats_liability().await?;
Ok(SyntheticCentLiability::try_from(
let res = SyntheticCentLiability::try_from(
liability.map(|l| l.settled()).unwrap_or(Decimal::ZERO) * CENTS_PER_USD,
)
.expect("usd liability has wrong sign"))
.expect("usd liability has wrong sign");
tracing::Span::current().record("liability", &tracing::field::display(res));
Ok(res)
}

pub async fn stablesats_btc_wallet(&self) -> Result<Option<AccountBalance>, LedgerError> {
Expand Down
Loading

0 comments on commit fb3c18b

Please sign in to comment.