Skip to content

Conversation

@guillaumetorresani
Copy link

@guillaumetorresani guillaumetorresani commented Oct 12, 2025

🧠 Context

Currently, when Supercronic reports job failures to Sentry using the -sentry-dsn flag, the job’s stdout and stderr outputs are not included in the event data.
This makes it difficult to diagnose failed jobs because important execution context is missing.

💡 Proposal

Introduce a new optional flag:

-sentry-extra-trace

When enabled, Supercronic will capture and attach the latest stdout and stderr output of failed jobs to the Sentry event’s extra field.
This provides additional context for debugging without altering the normal logging behavior.

✅ Example usage

$ ./supercronic -sentry-dsn https://examplePublicKey@o0.ingest.sentry.io/0 -sentry-extra-trace true

🧰 Technical changes

  • Added new flag -sentry-extra-trace in main.go.
  • Updated cron.go:
    • Implemented a ringBuffer to capture recent stdout and stderr lines (64 KB buffer).
    • Updated runJob() to return captured logs, exit code, and execution duration.
    • Added conditional inclusion of captured logs in Sentry fields when -sentry-extra-trace is enabled.
  • Refactored process error handling (exec.Command.Start/Wait) into a helper function handleExecError().
  • Updated README.md and dependencies (go.mod, go.sum).

🚀 Benefits

  • Greatly improves Sentry error diagnostics.
  • No performance or output regressions.
  • Backward-compatible — no changes needed for existing jobs.

📦 Example Sentry payload

{
  "extra": {
    "job.exit_code": 1,
    "job.duration": "5.32s",
    "job.stdout": "Starting backup...\nConnecting to database...",
    "job.stderr": "pg_dump: connection failed: timeout"
  }
}

Closes #202

- Introduced `-sentry-extra-trace` flag for including stdout and stderr of failed jobs in Sentry events.
- Updated README with examples of the new flag.
- Enhanced logging to support additional trace information.
- Added a `ringBuffer` implementation for capturing and retaining job outputs efficiently.
- Updated dependencies and switched to `go 1.25.2`.
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.

Add -sentry-extra-trace flag for enhanced Sentry error tracing

1 participant