Why this matters
Improves debuggability and traceability across services.
Include request-scoped fields (method, path, request_id, deadline/canceled) in error logs. Pass context through layers.
Improves debuggability and traceability across services.
Side-by-side examples engineers can pattern-match during review.
logger.Error("failed to handle request")ctx := r.Context()
logger.Error("handler failed",
"method", r.Method,
"path", r.URL.Path,
"request_id", reqIDFrom(ctx),
"ctx_err", ctx.Err(),
)logger.Error("failed") // no contextlogger.Error("failed", "method", r.Method, "request_id", id)From the same buckets as this rule.
Check if loops use equality operators (== or !=) in termination conditions. These can lead to infinite loops if the condition is never met exactly. Instead, use relational operators like < or > for safer loop termination.