Skip to content

feat(config): allow disabling debug healthchecks #16

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

Merged
merged 1 commit into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/schwab-proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,17 @@ func createServer(

// Wrap the API proxy with middleware stack
// Order: CorrelationID -> Logging -> Metrics -> Tracing -> APIProxy
loggingOpts := []func(*log.LoggingOptions){}
if !cfg.DebugHealthChecks {
loggingOpts = append(loggingOpts, log.WithDebugHealthChecks(false))
}

handler := log.CorrelationIDMiddleware(
log.LoggingMiddleware(
observability.MetricsMiddleware(
observability.TracingMiddleware(apiProxy),
),
loggingOpts...,
),
)

Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type Config struct {
// Debug options
DebugLogging bool `env:"DEBUG_LOGGING" envDefault:"false"`
SendDebugMessagesToClients bool `env:"SEND_DEBUG_MESSAGES_TO_CLIENTS" envDefault:"false"`
DebugHealthChecks bool `env:"DEBUG_HEALTH_CHECKS" envDefault:"false"`

// Admin API settings (generated, not from env)
AdminAPIKey string `env:"-"`
Expand Down
34 changes: 32 additions & 2 deletions log/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,44 @@ func CorrelationIDMiddleware(next http.Handler) http.Handler {
})
}

// LoggingOptions holds configuration for the logging middleware.
type LoggingOptions struct {
DebugHealthChecks bool
}

// WithDebugHealthChecks enables or disables debug logging for health check endpoints.
func WithDebugHealthChecks(enabled bool) func(*LoggingOptions) {
return func(opts *LoggingOptions) {
opts.DebugHealthChecks = enabled
}
}

// LoggingMiddleware logs HTTP requests with structured logging.
func LoggingMiddleware(next http.Handler) http.Handler {
func LoggingMiddleware(next http.Handler, opts ...func(*LoggingOptions)) http.Handler {
// Apply default options
options := &LoggingOptions{
DebugHealthChecks: true, // Default to true for backwards compatibility
}

// Apply provided options
for _, opt := range opts {
opt(options)
}

return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
ctx := request.Context()

// Skip logging for health checks if debug is disabled
isHealthCheck := strings.HasPrefix(request.URL.Path, "/health/")
if isHealthCheck && !options.DebugHealthChecks {
next.ServeHTTP(writer, request)

return
}

// Determine log level based on path
level := LevelInfo
if strings.HasPrefix(request.URL.Path, "/health/") {
if isHealthCheck {
level = LevelDebug
}

Expand Down
Loading