Add structured error logging to OCI handlers
Every 500 response in the OCI package silently discarded the actual error, making production debugging impossible. Add slog.Error before each 500 response with the error and relevant context (repo, digest, tag, uuid). Add slog.Info for state-mutating successes (manifest push, blob upload complete, deletions). Logger is injected into the OCI Handler via constructor, falling back to slog.Default() if nil. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -59,6 +59,7 @@ func (h *Handler) resolveManifest(w http.ResponseWriter, repo, reference string)
|
||||
fmt.Sprintf("repository %q not found", repo))
|
||||
return nil, false
|
||||
}
|
||||
h.log.Error("manifest resolve: lookup repository", "error", err, "repo", repo)
|
||||
writeOCIError(w, "UNKNOWN", http.StatusInternalServerError, "internal error")
|
||||
return nil, false
|
||||
}
|
||||
@@ -75,6 +76,7 @@ func (h *Handler) resolveManifest(w http.ResponseWriter, repo, reference string)
|
||||
fmt.Sprintf("manifest %q not found", reference))
|
||||
return nil, false
|
||||
}
|
||||
h.log.Error("manifest resolve: lookup manifest", "error", err, "repo", repo, "reference", reference)
|
||||
writeOCIError(w, "UNKNOWN", http.StatusInternalServerError, "internal error")
|
||||
return nil, false
|
||||
}
|
||||
@@ -175,6 +177,7 @@ func (h *Handler) handleManifestPut(w http.ResponseWriter, r *http.Request, repo
|
||||
for _, bd := range blobDigests {
|
||||
exists, err := h.db.BlobExists(bd)
|
||||
if err != nil {
|
||||
h.log.Error("manifest push: check blob exists", "error", err, "repo", repo, "blob_digest", bd)
|
||||
writeOCIError(w, "UNKNOWN", http.StatusInternalServerError, "internal error")
|
||||
return
|
||||
}
|
||||
@@ -197,6 +200,7 @@ func (h *Handler) handleManifestPut(w http.ResponseWriter, r *http.Request, repo
|
||||
BlobDigests: blobDigests,
|
||||
}
|
||||
if err := h.db.PushManifest(params); err != nil {
|
||||
h.log.Error("manifest push: write to database", "error", err, "repo", repo, "digest", computedDigest, "tag", tag)
|
||||
writeOCIError(w, "UNKNOWN", http.StatusInternalServerError, "internal error")
|
||||
return
|
||||
}
|
||||
@@ -215,6 +219,8 @@ func (h *Handler) handleManifestPut(w http.ResponseWriter, r *http.Request, repo
|
||||
h.auditFn("manifest_pushed", actorID, repo, computedDigest, r.RemoteAddr, details)
|
||||
}
|
||||
|
||||
h.log.Info("manifest pushed", "repo", repo, "digest", computedDigest, "tag", tag, "size", len(body))
|
||||
|
||||
w.Header().Set("Location", fmt.Sprintf("/v2/%s/manifests/%s", repo, computedDigest))
|
||||
w.Header().Set("Docker-Content-Digest", computedDigest)
|
||||
w.Header().Set("Content-Type", mediaType)
|
||||
|
||||
Reference in New Issue
Block a user