Skip to content

chore: add missing tracing for accounting module #2039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions core/accounting/src/balance_sheet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ mod chart_of_accounts_integration;
pub mod error;
pub mod ledger;

use tracing::instrument;

use audit::AuditSvc;
use authz::PermissionCheck;
use cala_ledger::CalaLedger;
Expand Down Expand Up @@ -95,6 +97,7 @@ where
}
}

#[instrument(name = "core_accounting.balance_sheet.create", skip(self), err)]
pub async fn create_balance_sheet(&self, name: String) -> Result<(), BalanceSheetError> {
let mut op = es_entity::DbOp::init(&self.pool).await?;

Expand All @@ -114,6 +117,11 @@ where
}
}

#[instrument(
name = "core_accounting.balance_sheet.get_integration_config",
skip(self),
err
)]
pub async fn get_chart_of_accounts_integration_config(
&self,
sub: &<<Perms as PermissionCheck>::Audit as AuditSvc>::Subject,
Expand All @@ -132,6 +140,11 @@ where
.await?)
}

#[instrument(
name = "core_accounting.balance_sheet.set_integration_config",
skip(self, chart),
err
)]
pub async fn set_chart_of_accounts_integration_config(
&self,
sub: &<<Perms as PermissionCheck>::Audit as AuditSvc>::Subject,
Expand Down Expand Up @@ -193,6 +206,7 @@ where
Ok(config)
}

#[instrument(name = "core_accounting.balance_sheet.balance_sheet", skip(self), err)]
pub async fn balance_sheet(
&self,
sub: &<<Perms as PermissionCheck>::Audit as AuditSvc>::Subject,
Expand Down
39 changes: 28 additions & 11 deletions core/accounting/src/chart_of_accounts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@ pub mod error;
mod repo;
pub mod tree;

pub(super) use csv::{CsvParseError, CsvParser};
pub use entity::Chart;
pub(super) use entity::*;
pub(super) use repo::*;
use tracing::instrument;

use audit::AuditSvc;
use authz::PermissionCheck;

use cala_ledger::{CalaLedger, account_set::NewAccountSet};
use tracing::instrument;

use crate::primitives::{
CalaAccountSetId, CalaJournalId, ChartId, CoreAccountingAction, CoreAccountingObject,
};

pub(super) use csv::{CsvParseError, CsvParser};
pub use entity::Chart;
pub(super) use entity::*;
use error::*;
pub(super) use repo::*;

pub struct ChartOfAccounts<Perms>
where
Expand Down Expand Up @@ -65,7 +66,11 @@ where
}
}

#[instrument(name = "chart_of_accounts.create_chart", skip(self))]
#[instrument(
name = "core_accounting.chart_of_accounts.create_chart",
skip(self),
err
)]
pub async fn create_chart(
&self,
sub: &<<Perms as PermissionCheck>::Audit as AuditSvc>::Subject,
Expand Down Expand Up @@ -98,7 +103,11 @@ where
Ok(chart)
}

#[instrument(name = "chart_of_account.import_from_csv", skip(self, data))]
#[instrument(
name = "core_accounting.chart_of_accounts.import_from_csv",
skip(self, data),
err
)]
pub async fn import_from_csv(
&self,
sub: &<<Perms as PermissionCheck>::Audit as AuditSvc>::Subject,
Expand Down Expand Up @@ -168,15 +177,19 @@ where
))
}

#[instrument(name = "chart_of_accounts.find_by_id", skip(self), err)]
#[instrument(name = "core_accounting.chart_of_accounts.find_by_id", skip(self), err)]
pub async fn find_by_id(
&self,
id: impl Into<ChartId> + std::fmt::Debug,
) -> Result<Chart, ChartOfAccountsError> {
self.repo.find_by_id(id.into()).await
}

#[instrument(name = "chart_of_accounts.find_by_reference_with_sub", skip(self))]
#[instrument(
name = "core_accounting.chart_of_accounts.find_by_reference_with_sub",
skip(self),
err
)]
pub async fn find_by_reference_with_sub(
&self,
sub: &<<Perms as PermissionCheck>::Audit as AuditSvc>::Subject,
Expand All @@ -193,7 +206,11 @@ where
self.find_by_reference(reference).await
}

#[instrument(name = "chart_of_accounts.find_by_reference", skip(self))]
#[instrument(
name = "core_accounting.chart_of_accounts.find_by_reference",
skip(self),
err
)]
pub async fn find_by_reference(
&self,
reference: &str,
Expand All @@ -208,7 +225,7 @@ where
Ok(chart)
}

#[instrument(name = "chart_of_accounts.find_all", skip(self), err)]
#[instrument(name = "core_accounting.chart_of_accounts.find_all", skip(self), err)]
pub async fn find_all<T: From<Chart>>(
&self,
ids: &[ChartId],
Expand Down
17 changes: 14 additions & 3 deletions core/accounting/src/csv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ mod job;
mod primitives;
mod repo;

use crate::Jobs;
use crate::Storage;
use tracing::instrument;

use audit::AuditSvc;
use authz::PermissionCheck;

use crate::Jobs;
use crate::Storage;

use es_entity::ListDirection;
pub use repo::accounting_csv_cursor::AccountingCsvsByCreatedAtCursor;

use super::{
CoreAccountingAction, CoreAccountingObject,
Expand All @@ -23,6 +25,7 @@ pub use entity::*;
use error::*;
use job::*;
pub use primitives::*;
pub use repo::accounting_csv_cursor::AccountingCsvsByCreatedAtCursor;
use repo::*;

#[derive(Clone)]
Expand Down Expand Up @@ -66,6 +69,7 @@ where
}
}

#[instrument(name = "core_accounting.csv.create", skip(self), err)]
pub async fn create_ledger_account_csv(
&self,
sub: &<<Perms as PermissionCheck>::Audit as AuditSvc>::Subject,
Expand Down Expand Up @@ -108,6 +112,7 @@ where
Ok(csv)
}

#[instrument(name = "core_accounting.csv.generate_download_link", skip(self), err)]
pub async fn generate_download_link(
&self,
sub: &<<Perms as PermissionCheck>::Audit as AuditSvc>::Subject,
Expand Down Expand Up @@ -137,6 +142,11 @@ where
})
}

#[instrument(
name = "core_accounting.csv.list_for_ledger_account_id",
skip(self),
err
)]
pub async fn list_for_ledger_account_id(
&self,
sub: &<<Perms as PermissionCheck>::Audit as AuditSvc>::Subject,
Expand Down Expand Up @@ -169,6 +179,7 @@ where
Ok(csvs)
}

#[instrument(name = "core_accounting.csv.find_all", skip(self), err)]
pub async fn find_all<T: From<AccountingCsv>>(
&self,
ids: &[AccountingCsvId],
Expand Down
2 changes: 1 addition & 1 deletion core/accounting/src/journal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ where
}
}

#[instrument(name = "accounting.journal.entries", skip(self))]
#[instrument(name = "core_accounting.journal.entries", skip(self), err)]
pub async fn entries(
&self,
sub: &<<Perms as PermissionCheck>::Audit as AuditSvc>::Subject,
Expand Down
42 changes: 38 additions & 4 deletions core/accounting/src/ledger_account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ where
}
}

#[instrument(name = "core_accounting.ledger_account.history", skip(self), err)]
pub async fn history(
&self,
sub: &<<Perms as PermissionCheck>::Audit as AuditSvc>::Subject,
id: impl Into<LedgerAccountId>,
id: impl Into<LedgerAccountId> + std::fmt::Debug,
args: es_entity::PaginatedQueryArgs<JournalEntryCursor>,
) -> Result<es_entity::PaginatedQueryRet<JournalEntry, JournalEntryCursor>, LedgerAccountError>
{
Expand All @@ -64,9 +65,14 @@ where
Ok(self.ledger.ledger_account_history(id, args).await?)
}

#[instrument(
name = "core_accounting.ledger_account.complete_history",
skip(self),
err
)]
pub(crate) async fn complete_history(
&self,
id: impl Into<LedgerAccountId> + Copy,
id: impl Into<LedgerAccountId> + Copy + std::fmt::Debug,
) -> Result<Vec<JournalEntry>, LedgerAccountError> {
let id = id.into();

Expand All @@ -93,7 +99,11 @@ where
Ok(all_entries)
}

#[instrument(name = "accounting.ledger_account.find_by_id", skip(self, chart), err)]
#[instrument(
name = "core_accounting.ledger_account.find_by_id",
skip(self, chart),
err
)]
pub async fn find_by_id(
&self,
sub: &<<Perms as PermissionCheck>::Audit as AuditSvc>::Subject,
Expand All @@ -112,7 +122,11 @@ where
Ok(accounts.remove(&id))
}

#[instrument(name = "accounting.ledger_account.find_by_id", skip(self, chart), err)]
#[instrument(
name = "core_accounting.ledger_account.find_by_id",
skip(self, chart),
err
)]
pub async fn find_by_code(
&self,
sub: &<<Perms as PermissionCheck>::Audit as AuditSvc>::Subject,
Expand All @@ -139,6 +153,11 @@ where
}
}

#[instrument(
name = "core_accounting.ledger_account.find_all",
skip(self, chart),
err
)]
pub async fn find_all<T: From<LedgerAccount>>(
&self,
chart: &Chart,
Expand All @@ -155,6 +174,11 @@ where
}

#[allow(clippy::too_many_arguments)]
#[instrument(
name = "core_accounting.ledger_account.list_account_children",
skip(self, chart),
err
)]
pub async fn list_account_children(
&self,
sub: &<<Perms as PermissionCheck>::Audit as AuditSvc>::Subject,
Expand Down Expand Up @@ -217,6 +241,11 @@ where
/// Pushes into `account`'s `ancestor_ids` ancestors from the chart of account. The ancestors
/// are pushed in ascending order, the root of the chart of accounts is pushed last. `account`
/// itself is not pushed.
#[instrument(
name = "core_accounting.ledger_account.populate_ancestors",
skip(self, chart, account),
err
)]
async fn populate_ancestors(
&self,
chart: &Chart,
Expand All @@ -236,6 +265,11 @@ where
Ok(())
}

#[instrument(
name = "core_accounting.ledger_account.populate_children",
skip(self, chart, account),
err
)]
async fn populate_children(
&self,
chart: &Chart,
Expand Down
12 changes: 9 additions & 3 deletions core/accounting/src/ledger_transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ mod cursor;
pub mod error;
mod value;

use tracing::instrument;

use std::collections::HashMap;

use audit::AuditSvc;
use authz::PermissionCheck;
use cala_ledger::{CalaLedger, transaction::TransactionsByCreatedAtCursor};
use tracing::instrument;

use crate::primitives::{CoreAccountingAction, CoreAccountingObject, LedgerTransactionId};

Expand Down Expand Up @@ -37,7 +38,11 @@ where
}
}

#[instrument(name = "accounting.ledger_transaction.find_by_id", skip(self), err)]
#[instrument(
name = "core_accounting.ledger_transaction.find_by_id",
skip(self),
err
)]
pub async fn find_by_id(
&self,
sub: &<<Perms as PermissionCheck>::Audit as AuditSvc>::Subject,
Expand All @@ -64,6 +69,7 @@ where
Ok(res)
}

#[instrument(name = "core_accounting.ledger_transaction.find_all", skip(self), err)]
pub async fn find_all<T: From<LedgerTransaction>>(
&self,
ids: &[LedgerTransactionId],
Expand Down Expand Up @@ -108,7 +114,7 @@ where
}

#[instrument(
name = "accounting.ledger_transaction.list_for_template_code",
name = "core_accounting.ledger_transaction.list_for_template_code",
skip(self),
err
)]
Expand Down
Loading
Loading