Skip to content

A CLI tool written in Rust that scans JSON log files in a repository and sends WARN/ERROR/CRITICAL log entries to Sentry.

Notifications You must be signed in to change notification settings

RustedBytes/sentry-log-scanner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sentry Log Scanner

A CLI tool written in Rust that scans JSON log files in a repository and sends WARN/ERROR/CRITICAL log entries to Sentry.

Features

  • Recursively scans directories for JSON log files
  • Parses log entries in the format used by Python's Loguru logger
  • Filters for WARNING, ERROR, and CRITICAL log levels
  • Sends matching entries to Sentry with full context
  • Supports dry-run mode for testing
  • Can read Sentry DSN from environment variable

Installation

Make sure you have Rust installed (https://rustup.rs/), then:

cd sentry-log-scanner
cargo build --release

The binary will be available at target/release/sentry-log-scanner.

Usage

# Basic usage
./sentry-log-scanner --path /path/to/logs --dsn "https://your-sentry-dsn@sentry.io/project"

# Using environment variable for DSN
export SENTRY_DSN="https://your-sentry-dsn@sentry.io/project"
./sentry-log-scanner --path /path/to/logs

# Dry run mode (doesn't send to Sentry, just lists found entries)
./sentry-log-scanner --path /path/to/logs --dsn "https://your-dsn@sentry.io/project" --dry-run

Command Line Options

Option Short Description Required
--path -p Path to directory containing log files Yes
--dsn -d Sentry DSN (can also use SENTRY_DSN env var) Yes
--dry-run Test mode - don't send to Sentry No

Log Format

The tool expects JSON log files where each line is a JSON object with the following structure:

{
  "text": "2025-11-25 18:03:13.318 | WARNING  | logging:callHandlers:1762 - timeout message\n",
  "record": {
    "level": {
      "name": "WARNING",
      "no": 30
    },
    "message": "timeout message",
    "time": {
      "repr": "2025-11-25 18:03:13.318918+08:00",
      "timestamp": 1764064993.318918
    },
    "file": {
      "name": "__init__.py",
      "path": "/path/to/file.py"
    },
    "function": "functionName",
    "line": 123,
    "module": "moduleName"
  }
}

This format is compatible with Python's Loguru logger when configured with JSON serialization.

Sentry Event Data

Each Sentry event includes:

  • Level: WARNING, ERROR, or FATAL (mapped from CRITICAL)
  • Message: The log message
  • Logger: The module name
  • Extra data:
    • source_file: Path to the JSON log file
    • original_file: Original Python file that generated the log
    • function: Function name
    • line: Line number
    • log_text: Full text representation of the log entry
    • original_timestamp: Original timestamp from the log

Example Output

Scanning directory: "/path/to/logs"
Sentry DSN: https://your-dsn@...
Dry run: false

[WARNING] 2025-11-25 18:03:13.318918+08:00 - timeout waiting for GET_LIMIT_SWITCH after 0.15s (__init__.py:1762)
[ERROR] 2025-11-25 18:04:00.123456+08:00 - Connection failed (defs.py:100)

--- Summary ---
Files scanned: 100
WARN/ERROR/CRITICAL entries found: 42
Events sent to Sentry: 42

License

MIT

About

A CLI tool written in Rust that scans JSON log files in a repository and sends WARN/ERROR/CRITICAL log entries to Sentry.

Resources

Stars

Watchers

Forks

Contributors 2

  •  
  •  

Languages