[log] Add debug logging to response_writer.go#636
Conversation
- Added logger declaration with namespace server:response_writer - Added logging for response writer creation - Added logging for status code changes and body writes
There was a problem hiding this comment.
Pull request overview
This PR adds debug logging to the response_writer.go file to improve troubleshooting capabilities for HTTP response handling. The changes introduce a logger with the namespace server:response_writer and add logging statements to track response writer creation, status code setting, body writes, and data retrieval operations.
Changes:
- Added logger initialization following the project's
pkg:filenamenaming convention - Added debug logging to
newResponseWriter,WriteHeader,Write,Body, andStatusCodemethods - Modified
Body()method to store body bytes in intermediate variable for logging
Comments suppressed due to low confidence (3)
internal/server/response_writer.go:22
- The
newResponseWriter()function is called for every HTTP request (as seen insdk_logging.goline 79 andtransport.goline 49). This logging adds function call overhead on every single request. While minimal, this is on the critical path for all HTTP requests. The information logged here has limited debugging value since it's a constant message that doesn't include any request-specific context. Consider removing this logging to minimize overhead on the hot path.
logResponseWriter.Print("Creating new response writer with default status 200")
internal/server/response_writer.go:45
- The
Body()method adds logging that requires storing the body bytes in an intermediate variable just for logging purposes. This is unnecessary overhead. The logging adds minimal value since the body bytes are already logged at a higher level by callers (e.g., insdk_logging.goandtransport.go). Additionally, this method may be called multiple times per request (as seen intransport.goline 51-52 where bothlw.Body()andstring(lw.Body())are called), resulting in duplicate log messages for the same data. Consider removing this logging statement.
bodyBytes := w.body.Bytes()
logResponseWriter.Printf("Retrieving captured body: %d bytes", len(bodyBytes))
return bodyBytes
internal/server/response_writer.go:51
- The
StatusCode()method is called multiple times per request (e.g., insdk_logging.goit's called 4 times - lines 95, 136, 147, 156). Each call will generate a separate log message, creating noise without providing additional useful information. The status code value is already logged at a higher level by callers. Consider removing this logging statement to reduce log verbosity.
logResponseWriter.Printf("Retrieving captured status code: %d", w.statusCode)
return w.statusCode
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| func (w *responseWriter) Write(b []byte) (int, error) { | ||
| logResponseWriter.Printf("Writing response body: %d bytes", len(b)) |
There was a problem hiding this comment.
The Write() method is called on every response body write operation, which can happen multiple times per request. For large responses written in chunks, this will generate excessive log messages. This is a hot path in HTTP request handling. While the logger only outputs when DEBUG is enabled, the function call overhead and string formatting still occur. Consider using log.Enabled() check before logging, or remove this logging entirely since response bodies are already logged at a higher level by the callers (e.g., sdk_logging.go and transport.go).
This issue also appears in the following locations of the same file:
- line 22
- line 43
- line 50
Changes
Enhanced the
internal/server/response_writer.gofile with debug logging to improve troubleshooting capabilities for HTTP response handling.What was added:
logResponseWriterwith namespaceserver:response_writerfollowing project conventionsBenefits:
pkg:filename)Testing:
The changes follow Go best practices and the project's logging guidelines from AGENTS.md. To see the debug output:
Or enable all server logs:
DEBUG=server:* ./awmg --config config.tomlQuality checklist:
pkg:filenamenaming convention