Skip to main content

On This Page

Micrologs: A Self-Hostable Analytics and Error Tracking Alternative for Shared Hosting

3 min read
Share

These articles are AI-generated summaries. Please check the original sources for full details.

I Built a Self-Hostable Plausible + Sentry Alternative in One Day - That Runs on Shared Hosting

Om Dongaonkar developed Micrologs, an analytics and error tracking tool designed to run specifically on shared hosting environments with no root access. The system uses a ~3KB vanilla JS snippet to capture pageviews, sessions, and JavaScript errors directly into a self-hosted MySQL database.

Why This Matters

Modern observability tools like Plausible or Sentry often assume access to VPS infrastructure, Docker containers, or Redis for high-performance data ingestion. However, many production projects still reside on shared hosting where only PHP and MySQL are available, creating a tooling gap for privacy-conscious developers who cannot use third-party SaaS due to data sovereignty requirements. Micrologs addresses this by replacing memory-intensive daemons with file-based rate limiting and local GeoIP lookups, proving that robust tracking can exist without high infrastructure overhead. This architecture ensures that even the most constrained environments can maintain comprehensive telemetry without incurring SaaS costs or complex server management.

Key Insights

  • File-based rate limiting: Micrologs utilizes append-only .req files and probabilistic cleanup (1% chance) to manage request volume without Redis or database locks (Dongaonkar, 2026).
  • Local Geolocation: The system uses a MaxMind GeoLite2 .mmdb file for local lookups, eliminating runtime API latencies and external service dependencies.
  • Privacy-First Identification: IP addresses are SHA-256 hashed with a salt immediately on ingestion, while visitor tracking uses a 365-day cookie with canvas fingerprinting as a fallback.
  • Error Fingerprinting: JavaScript and backend errors are grouped into a single SHA-256 fingerprint generated from project_id, error_type, message, file, and line.
  • SPA Navigation Support: The JS snippet patches history.pushState and history.replaceState to capture pageviews in single-page applications without full page reloads.
  • Bot Filtering Logic: Micrologs identifies bots by checking for missing Accept-Language and Accept headers, which real browsers always include regardless of the User-Agent string.

Working Examples

The JS snippet for automated pageview and error tracking.

<script src="https://yourdomain.com/snippet/micrologs.js" data-public-key="your_public_key" data-environment="production" async></script>

File-based rate limiting logic for shared hosting environments.

foreach (glob($userDir . "/*.req") as $file) { if ($now - filemtime($file) <= $windowSeconds) { $attempts++; } else { @unlink($file); } }

Error grouping logic using SHA-256 fingerprinting.

$fingerprint = hash("sha256", $projectId . $errorType . $message . $file . ($line ?? ""));

Practical Applications

  • Use case: Deploying privacy-compliant analytics on shared hosting environments (PHP/MySQL) where Docker or Redis is unavailable. Pitfall: Using standard Docker-based tools on restricted hosts leads to deployment failure.
  • Use case: Internal audit logging and error tracking for sensitive projects where third-party data processing is prohibited. Pitfall: Relying solely on User-Agent strings for bot filtering leads to skewed data from sophisticated scripts.
  • Use case: Managing multiple projects with a single self-hosted install using public/secret key pairs. Pitfall: Exposing secret keys in frontend code allows unauthorized analytics queries or link management.

References:

Continue reading

Next article

Mastering Nginx Configuration: Manual Validation and Automated AI Troubleshooting

Related Content