Skip to content

feat(logging): migrate from debug_log to tracing with production logging#1078

Open
svarlamov wants to merge 12 commits intomainfrom
feat/daemon-logging-tracing-migration
Open

feat(logging): migrate from debug_log to tracing with production logging#1078
svarlamov wants to merge 12 commits intomainfrom
feat/daemon-logging-tracing-migration

Conversation

@svarlamov
Copy link
Copy Markdown
Member

@svarlamov svarlamov commented Apr 14, 2026

Summary

  • Migrate entire codebase from hand-rolled debug_log() to the tracing crate with proper log levels (tracing::error!, tracing::warn!, tracing::info!, tracing::debug!)
  • Add production-visible logging for daemon operations that was previously invisible outside debug mode: git write ops, checkpoints, auto-updater, auto-restart, panics, socket failures
  • Add custom SentryLayer that automatically routes tracing::error!() events to Sentry via the existing telemetry worker pipeline — no manual dual-calls needed at error sites
  • Remove debug_log infrastructure entirely from utils.rs — one call pattern (tracing::*!()) across the entire codebase

What gets logged in production (INFO level):

  • Daemon started/shutdown with PID, version, OS, arch
  • Git write ops completed: commit, rebase, merge, cherry-pick, am, stash, reset, push
  • Checkpoint start/done with kind, repo, and duration
  • Auto-updater: check started, result (update available / no update), install result
  • Auto-restart trigger (24.5h uptime exceeded)
  • Shutdown reasons

What gets logged as errors (ERROR → Sentry):

  • All panic catches (trace ingest, command side-effect, checkpoint)
  • Socket listener failures (control, trace)
  • Log file setup failures

What stays debug-only:

  • All existing verbose output (authorship details, trace normalization, family state transitions)
  • Git read ops (status, diff, log, show, fetch)
  • Detailed checkpoint state dumps

Changes

  • 53 files changed, ~1400 insertions, ~1300 deletions
  • 581 debug_log() + 15 debug_performance_log() + 2 debug_performance_log_structured() calls converted
  • 16 observability::log_error() calls in daemon.rs replaced by tracing::error!() with structured context fields (SentryLayer handles forwarding)
  • New file: src/daemon/sentry_layer.rs — custom tracing Layer for Sentry error forwarding
  • New deps: tracing 0.1, tracing-subscriber 0.3 (with env-filter feature)

Test plan

  • cargo check passes
  • cargo test — all unit tests pass
  • cargo test --test daemon_mode — all 54 daemon integration tests pass
  • Zero remaining debug_log / debug_performance_log references in codebase
  • Manual: run daemon, trigger a commit, verify log file at ~/.git-ai/internal/daemon/logs/{PID}.log shows INFO-level output
  • Manual: verify git-ai bg tail shows formatted log output

Follow-up items

  • Migrate to official sentry crate with sentry-tracing Layer (replaces custom SentryLayer + custom SentryClient)
  • Convert TelemetryEnvelope::Performance events to tracing spans for standard Sentry performance monitoring
  • Add tracing subscriber initialization for non-daemon processes (CLI wrapper) for local debugging
  • Consider structured JSON log output option for machine parsing
  • Consider log rotation by size in addition to current pruning by age

🤖 Generated with Claude Code


Open with Devin

svarlamov and others added 11 commits April 13, 2026 23:02
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Migrating from hand-rolled debug_log() to tracing crate with proper
log levels, custom Sentry-forwarding Layer, and structured production
output across the entire codebase.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
10-task plan covering tracing infrastructure, SentryLayer, level
promotions, codebase-wide debug_log migration, and new production
log points for git write ops, checkpoints, and auto-updater.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Thin tracing::Layer impl that intercepts ERROR-level events and
forwards them to the existing telemetry worker as TelemetryEnvelope::Error
events, routing to both enterprise and OSS Sentry DSNs automatically.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sets up tracing with EnvFilter (info default, debug when GIT_AI_DEBUG=1),
fmt layer writing to stderr (which dup2 redirects to log file), and
SentryLayer for automatic error forwarding. Adds daemon started/shutdown
lifecycle log lines.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… promotions

Convert all 75 debug_log() calls to tracing macros with appropriate
levels: ERROR for panics/socket failures, WARN for recoverable failures,
INFO for key operations (updater, restart, lifecycle), DEBUG for everything
else. Replace 16 observability::log_error() calls with tracing::error!()
that includes structured context fields (SentryLayer handles forwarding).

Add new INFO-level log points:
- Git write ops: commit/rebase/merge/cherry-pick/am/stash/reset/push
- Checkpoint start/done with timing
- Shutdown reasons

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ase-wide

Convert 500+ debug_log/debug_performance_log/debug_performance_log_structured
calls across 42 files to tracing::debug!(). Covers authorship, commands,
hooks, git, mdm, config, observability, and telemetry_worker modules.
All calls become tracing::debug!() with no level promotions outside
of daemon.rs (which was done in a prior commit).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove debug_log(), debug_performance_log(), debug_performance_log_structured(),
and all supporting code (is_debug_enabled, DEBUG_ENABLED, DEBUG_PERFORMANCE_LEVEL,
etc.). All call sites have been migrated to tracing macros.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 6 additional findings.

Open in Devin Review

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant