I vibe-coded a non-blocking stats library with a lock-free ring buffer (and somehow it actually works?)
Hey folks,
So I built this stats/metrics library for Go, and I'm honestly surprised it turned out as well as it did. Started as a "let me figure out this lock-free ring buffer thing" project and evolved into something I actually use in production.
What it does: - Non-blocking UDP stats collection (your app never waits on metrics, I promise) - Lock-free ring buffer with atomic CAS operations (sounds fancy, mostly just me reading a lot of blog posts) - Supports multiple backends: Datadog, Prometheus, CloudWatch, and OTLP - Dual API: legacy convenience methods OR full OpenTelemetry SDK compliance - Performance targets that I set aspirationally and then had to actually hit (p99 latency <100ns, >100k ops/sec)
The honest parts: - Test coverage is... mixed. Serializers are at 94%, but some packages are at 0% (don't @ me) - I spent WAY too much time on the ring buffer and probably should've just used a channel - The CI is fresh (like, just added it fresh) - Documentation exists but was mostly written in a caffeine-fueled sprint - There's a test that used to fail randomly until I fixed it literally today
What I'm proud of: - It actually handles backpressure gracefully with adaptive batching - Exporters run in parallel so one slow backend doesn't block others - Panic recovery means a bad exporter won't crash your app - The OTel integration was harder than expected but it works - It's fast enough that I stopped worrying about it
Why share this? Honestly? I think it's useful, but also I want to know if I'm doing something terribly wrong with the lock-free stuff. The ring buffer seems solid but concurrent programming is where my imposter syndrome lives.
Also, if you need metrics in Go and don't want to vendor a massive library, this might work for you. Or don't use it, that's cool too.
Repo: https://github.com/convoy-road-trips-app/stats
Open to feedback, roasts, or suggestions. Especially if you've built something similar and can tell me what I screwed up.
submitted by /u/yodebu
[link] [comments]