Tools
Debug Fiber APIs Like a Pro with GoRequestTracer: JSON Logging, DB Queries, and Panic Tracking
2025-12-15
0 views
admin
Why You Need This ## Installation ## Usage Example ## Example Log Output ## Key Features ## Contributing ## Why Star This Repo? If you’re building APIs or microservices in Go using Fiber, you know how hard it is to track HTTP requests, database queries, and unexpected panics. Meet GoRequestTracer, a lightweight Fiber middleware that: Imagine a production API receiving hundreds of requests per second. GoRequestTracer solves all this by centralizing request and DB tracking in a structured JSON log, making debugging faster and simpler. If using SQLite, ensure CGO is enabled. GoRequestTracer is open to contributions! Fork, create a branch, and submit a Pull Request. Check the repo here: GoRequestTracer on GitHub If you’re building Go APIs with Fiber or just want to monitor DB queries and panics in production efficiently, this repo will save you hours of debugging. 🌟 Star the repo to support it and stay updated! Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse COMMAND_BLOCK:
# Clone the repo
git clone https://github.com/Patidar-Ops/GoRequestTracer.git # Enter directory
cd GoRequestTracer # Download dependencies
go mod tidy Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
# Clone the repo
git clone https://github.com/Patidar-Ops/GoRequestTracer.git # Enter directory
cd GoRequestTracer # Download dependencies
go mod tidy COMMAND_BLOCK:
# Clone the repo
git clone https://github.com/Patidar-Ops/GoRequestTracer.git # Enter directory
cd GoRequestTracer # Download dependencies
go mod tidy CODE_BLOCK:
package main import ( "database/sql" "log" "github.com/gofiber/fiber/v2" _ "github.com/mattn/go-sqlite3" "github.com/Patidar-Ops/GoRequestTracer/tracer"
) func main() { app := fiber.New() db, err := sql.Open("sqlite3", ":memory:") if err != nil { log.Fatal(err) } defer db.Close() app.Use(tracer.New(db)) // Fiber middleware app.Get("/", func(c *fiber.Ctx) error { return c.SendString("Hello, GoRequestTracer!") }) app.Listen(":3000")
} Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
package main import ( "database/sql" "log" "github.com/gofiber/fiber/v2" _ "github.com/mattn/go-sqlite3" "github.com/Patidar-Ops/GoRequestTracer/tracer"
) func main() { app := fiber.New() db, err := sql.Open("sqlite3", ":memory:") if err != nil { log.Fatal(err) } defer db.Close() app.Use(tracer.New(db)) // Fiber middleware app.Get("/", func(c *fiber.Ctx) error { return c.SendString("Hello, GoRequestTracer!") }) app.Listen(":3000")
} CODE_BLOCK:
package main import ( "database/sql" "log" "github.com/gofiber/fiber/v2" _ "github.com/mattn/go-sqlite3" "github.com/Patidar-Ops/GoRequestTracer/tracer"
) func main() { app := fiber.New() db, err := sql.Open("sqlite3", ":memory:") if err != nil { log.Fatal(err) } defer db.Close() app.Use(tracer.New(db)) // Fiber middleware app.Get("/", func(c *fiber.Ctx) error { return c.SendString("Hello, GoRequestTracer!") }) app.Listen(":3000")
} CODE_BLOCK:
{ "request_id": "1165699a-a262-40e9-a903-997c5bb783c1", "method": "GET", "path": "/", "status": 200, "total_ms": 5
} Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
{ "request_id": "1165699a-a262-40e9-a903-997c5bb783c1", "method": "GET", "path": "/", "status": 200, "total_ms": 5
} CODE_BLOCK:
{ "request_id": "1165699a-a262-40e9-a903-997c5bb783c1", "method": "GET", "path": "/", "status": 200, "total_ms": 5
} CODE_BLOCK:
{ "request_id": "b6099617-802c-4b3f-a128-3040a22862e0", "method": "GET", "path": "/panic", "status": 500, "total_ms": 0, "panic_stack": "runtime error: invalid memory address or nil pointer dereference\n..."
} Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
{ "request_id": "b6099617-802c-4b3f-a128-3040a22862e0", "method": "GET", "path": "/panic", "status": 500, "total_ms": 0, "panic_stack": "runtime error: invalid memory address or nil pointer dereference\n..."
} CODE_BLOCK:
{ "request_id": "b6099617-802c-4b3f-a128-3040a22862e0", "method": "GET", "path": "/panic", "status": 500, "total_ms": 0, "panic_stack": "runtime error: invalid memory address or nil pointer dereference\n..."
} - Logs HTTP requests in JSON
- Tracks DB queries
- Monitors HTTP client calls
- Captures panic stack traces
- Generates a unique request ID for every request
All this without changing your existing code too much. - Which request failed?
- What DB query caused the delay?
- Did an unexpected panic happen? - ✅ **Unique Request ID **per request
- ✅ JSON structured logging
- ✅ DB query tracking (DBTracer)
- ✅ HTTP client call logging
- ✅ Panic recovery with stack trace
- ✅ Works with any database/sql driver
how-totutorialguidedev.toaidatabasegitgithub