Skip to content

fix(database): a trace of the audit prune shows each of its queries - #687

Draft
PiquelChips wants to merge 1 commit into
mainfrom
fix/audit-prune-spans
Draft

PiquelChips wants to merge 1 commit into
mainfrom
fix/audit-prune-spans

Conversation

@PiquelChips

@PiquelChips PiquelChips commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Part of #544 (NEW-17, the audit prune).

DatabaseTransaction::prune_audit_chain, which auth-service audit prune runs, sent its five statements straight to the connection and skipped run!. So a trace of a prune had no db.query span for any of them, and a failed statement never set otel.status_code = ERROR. They now go through run! on the transaction's AuditRepository, like every other repository query.

What changes

Only telemetry changes. Inside a trace, a prune now emits one db.query client span per statement (otel.name, otel.kind = "client", db.system.name = "postgresql", db.query.text, and otel.status_code = "ERROR" on failure):

  • SELECT set_config('sourceorigin.audit_prune', 'on', true)
  • SELECT set_config($1, $2, $3) AS "value!" (the 30-minute statement limit)
  • DELETE FROM domain_events WHERE chain_position <= $1
  • INSERT INTO audit_anchor (position) …
  • SELECT set_config('sourceorigin.audit_prune', 'off', true)

Unchanged

  • The statements, their order and the transaction they run in.
  • Their errors: run! converts with the same Into<DatabaseError> the ? used.
  • The SQL text, whitespace included, so the .sqlx cache has no diff.

Checks

  • cargo clippy --locked -p sourceorigin-repository --all-targets -- -D warnings, with and without --all-features
  • just db test: 509 passed, including the prune tests in audit::tests and the query cache check

No published crate is touched, so there is no semver check.

Note

Written by Claude Opus 5.5 in Claude Code and reviewed by Claude Opus 5.5 (via T3 Code)

prune_audit_chain ran its statements straight on the connection, bypassing
run!, so a trace of a prune showed none of them. They now go through run!
like every other repository query.
@PiquelChips PiquelChips added the bug Something isn't working label Nov 22, 2026
@github-project-automation github-project-automation Bot moved this to Needs Triage in sourceorigin.dev Nov 22, 2026
@coderabbitai

coderabbitai Bot commented Nov 22, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

1 participant