-
Notifications
You must be signed in to change notification settings - Fork 0
refactor(tx-submit-api): Switch logging to log/slog #397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… zap part Signed-off-by: Akhil Repala <[email protected]>
📝 WalkthroughWalkthroughThis pull request implements a comprehensive migration from Uber's zap logging library to Go's standard library slog package. Changes include: replacing all formatted logging calls (Infof, Fatalf) with structured slog methods (Info, Error) across cmd/tx-submit-api/main.go and internal/api/api.go; removing the gin-contrib/zap and go.uber.org/zap dependencies from go.mod; refactoring the core logging backend in internal/logging/logging.go from zap-based SugaredLogger to slog.Logger with a JSON handler; adding two new Gin middleware functions (GinLogger and GinRecovery) in a new internal/logging/gin.go file for HTTP request and panic recovery logging; and adjusting error handling to use explicit os.Exit(1) instead of Fatalf in several places. Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes
Pre-merge checks and finishing touches✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Signed-off-by: Akhil <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 6 files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/api/api.go (1)
75-75: Remove redundant recovery middleware.Line 75 uses
gin.Recovery()but line 94 addslogging.GinRecovery(accessLogger, true). Having both recovery middlewares is unnecessary and the custom one should fully replace the default.Apply this diff:
// Configure API router router := gin.New() - // Catch panics and return a 500 - router.Use(gin.Recovery()) // Configure CORS
🧹 Nitpick comments (1)
cmd/tx-submit-api/main.go (1)
86-90: Reconsider os.Exit(1) inside goroutine.Calling
os.Exit(1)from within a goroutine (line 89) terminates the entire process immediately, bypassing deferred cleanup and preventing graceful shutdown. Consider either:
- Returning the error to a channel and handling it in main, or
- Simply logging the error without exiting if the debug listener is optional
Since the debug listener appears to be optional (only started when configured), crashing the entire application on its failure may be too aggressive.
Example alternative approach:
go func() { debugger := &http.Server{ Addr: fmt.Sprintf( "%s:%d", cfg.Debug.ListenAddress, cfg.Debug.ListenPort, ), ReadHeaderTimeout: 60 * time.Second, } err := debugger.ListenAndServe() if err != nil { logger.Error("failed to start debug listener", "err", err) - os.Exit(1) } }()
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
go.sumis excluded by!**/*.sum
📒 Files selected for processing (5)
cmd/tx-submit-api/main.go(3 hunks)go.mod(0 hunks)internal/api/api.go(10 hunks)internal/logging/gin.go(1 hunks)internal/logging/logging.go(1 hunks)
💤 Files with no reviewable changes (1)
- go.mod
🧰 Additional context used
🧬 Code graph analysis (3)
internal/api/api.go (1)
internal/logging/gin.go (2)
GinLogger(13-47)GinRecovery(50-64)
internal/logging/logging.go (1)
internal/config/config.go (1)
LoggingConfig(36-39)
cmd/tx-submit-api/main.go (3)
internal/logging/logging.go (1)
GetLogger(55-57)internal/version/version.go (1)
GetVersionString(27-33)internal/api/api.go (1)
Start(52-179)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: cubic · AI code reviewer
🔇 Additional comments (9)
internal/api/api.go (2)
56-66: LGTM! Structured logging properly applied.The startup messages now use structured slog with appropriate key-value pairs for address and port. The distinction between TLS and non-TLS modes is clear.
210-210: LGTM! Error logging properly converted to structured format.All error logs now use structured slog with the "err" field for error objects, providing better log parsing and analysis capabilities.
Also applies to: 219-219, 233-233, 239-239, 245-245, 256-256, 294-294, 302-302, 338-338
cmd/tx-submit-api/main.go (2)
36-38: LGTM! Wrapper function appropriate for maxprocs.Logger interface.The logPrintf function wraps slog to satisfy the maxprocs.Logger interface, which requires a Printf-style function. While this loses structure, it's necessary for library integration.
60-60: LGTM! Version logging properly structured.The startup message now includes the version as a structured field, improving log parsing.
internal/logging/gin.go (2)
12-47: LGTM! GinLogger middleware correctly implemented.The middleware properly:
- Processes the request before logging (c.Next() first)
- Skips configured paths efficiently
- Captures comprehensive request metadata (status, method, path, latency, etc.)
- Uses structured logging with key-value pairs
- Includes Gin errors when present
49-64: LGTM! GinRecovery middleware correctly implemented.The panic recovery middleware properly:
- Uses defer-recover pattern for panic handling
- Logs with structured fields including the error
- Optionally includes stack trace for debugging
- Aborts the request with HTTP 500 status
- Allows request processing to continue (c.Next())
internal/logging/logging.go (3)
33-53: LGTM! slog configuration properly implemented.The Setup function correctly:
- Parses log level from config
- Configures JSON handler with custom options
- Replaces TimeKey with "timestamp" formatted as RFC3339
- Creates both standard and access loggers
- Uses log.Fatalf appropriately during bootstrap (before logger is available)
63-79: LGTM! Log level parsing correctly implemented.The parseLevel function properly:
- Defaults to Info for empty string
- Performs case-insensitive matching
- Supports both "warn" and "warning" aliases
- Handles standard levels (debug, info, warn, error)
- Returns error for invalid input
55-61: LGTM! Logger getter functions correctly implemented.Both GetLogger and GetAccessLogger return the appropriate slog.Logger instances, maintaining the public API with updated types.

Closes #325
Summary by cubic
Switched tx-submit-api logging to Go’s log/slog with JSON output and RFC3339 timestamps, replacing zap and gin-contrib/zap. Added structured Gin middleware for access logging and panic recovery. Addresses Linear #325.
Refactors
Dependencies
Written for commit e356ef4. Summary will update automatically on new commits.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.