refactor(logging): log with the caller's context so records carry trace ids

This commit is contained in:
sam committed 2026-10-25 23:30:01 +11:00
1 parent 0611e00330
commit 656feab2a4
118 files changed
+512 -511

No files matched your search

+14 -14
View File
@@ -51,19 +51,19 @@ func (s *Server) handleBindingsList(w http.ResponseWriter, r *http.Request) {
}
bindings, err := s.Bindings.ListBindings(r.Context())
if err != nil {
s.Log.Error("list bindings", "err", err)
s.Log.ErrorContext(r.Context(), "list bindings", "err", err)
http.Error(w, "list bindings failed", http.StatusInternalServerError)
return
}
unsigned, err := s.unsignedSources(r.Context())
if err != nil {
s.Log.Error("list sources", "err", err)
s.Log.ErrorContext(r.Context(), "list sources", "err", err)
http.Error(w, "list bindings failed", http.StatusInternalServerError)
return
}
enablement, _, err := s.workflowEnablement(r.Context())
if err != nil {
s.Log.Error("workflow enablement", "err", err)
s.Log.ErrorContext(r.Context(), "workflow enablement", "err", err)
http.Error(w, "list bindings failed", http.StatusInternalServerError)
return
}
@@ -88,7 +88,7 @@ func (s *Server) lastOutcome(ctx context.Context, bindingID string) *storecontra
}
rows, err := s.Dispatches.ListDispatches(ctx, storecontract.DispatchFilter{BindingID: bindingID, Limit: 1})
if err != nil {
s.Log.Warn("binding last outcome", "binding", bindingID, "err", err)
s.Log.WarnContext(ctx, "binding last outcome", "binding", bindingID, "err", err)
return nil
}
if len(rows) == 0 {
@@ -115,13 +115,13 @@ func (s *Server) handleBindingCreate(w http.ResponseWriter, r *http.Request) {
}
id, err := s.Bindings.InsertBinding(r.Context(), b)
if err != nil {
s.Log.Error("insert binding", "err", err)
s.Log.ErrorContext(r.Context(), "insert binding", "err", err)
http.Error(w, "create binding failed", http.StatusInternalServerError)
return
}
created, err := s.Bindings.GetBinding(r.Context(), id)
if err != nil || created == nil {
s.Log.Error("get binding after insert", "err", err, "id", id)
s.Log.ErrorContext(r.Context(), "get binding after insert", "err", err, "id", id)
http.Error(w, "create binding failed", http.StatusInternalServerError)
return
}
@@ -141,7 +141,7 @@ func (s *Server) handleBindingGet(w http.ResponseWriter, r *http.Request) {
}
b, err := s.Bindings.GetBinding(r.Context(), id)
if err != nil {
s.Log.Error("get binding", "err", err, "id", id)
s.Log.ErrorContext(r.Context(), "get binding", "err", err, "id", id)
http.Error(w, "get binding failed", http.StatusInternalServerError)
return
}
@@ -168,7 +168,7 @@ func (s *Server) handleDispatches(filterFor func(id string) (storecontract.Dispa
filter.Limit = 50
dispatches, err := s.Dispatches.ListDispatches(r.Context(), filter)
if err != nil {
s.Log.Error("list dispatches", "err", err)
s.Log.ErrorContext(r.Context(), "list dispatches", "err", err)
http.Error(w, "list dispatches failed", http.StatusInternalServerError)
return
}
@@ -202,14 +202,14 @@ func (s *Server) handleBindingUpdate(w http.ResponseWriter, r *http.Request) {
case errors.Is(err, storecontract.ErrBindingNotFound):
http.Error(w, "binding not found", http.StatusNotFound)
default:
s.Log.Error("update binding", "err", err, "id", id)
s.Log.ErrorContext(r.Context(), "update binding", "err", err, "id", id)
http.Error(w, "update binding failed", http.StatusInternalServerError)
}
return
}
updated, err := s.Bindings.GetBinding(r.Context(), id)
if err != nil || updated == nil {
s.Log.Error("get binding after update", "err", err, "id", id)
s.Log.ErrorContext(r.Context(), "get binding after update", "err", err, "id", id)
http.Error(w, "update binding failed", http.StatusInternalServerError)
return
}
@@ -234,7 +234,7 @@ func (s *Server) handleBindingDelete(w http.ResponseWriter, r *http.Request) {
http.Error(w, "binding not found", http.StatusNotFound)
return
}
s.Log.Error("delete binding", "err", err, "id", id)
s.Log.ErrorContext(r.Context(), "delete binding", "err", err, "id", id)
http.Error(w, "delete binding failed", http.StatusInternalServerError)
return
}
@@ -264,14 +264,14 @@ func (s *Server) handleBindingTransition(verb string, apply func(storecontract.B
case errors.Is(err, storecontract.ErrBindingTransition):
http.Error(w, "binding cannot "+verb+" from its current state", http.StatusConflict)
default:
s.Log.Error(verb+" binding", "err", err, "id", id)
s.Log.ErrorContext(r.Context(), verb+" binding", "err", err, "id", id)
http.Error(w, verb+" binding failed", http.StatusInternalServerError)
}
return
}
updated, err := s.Bindings.GetBinding(r.Context(), id)
if err != nil || updated == nil {
s.Log.Error("get binding after "+verb, "err", err, "id", id)
s.Log.ErrorContext(r.Context(), "get binding after "+verb, "err", err, "id", id)
http.Error(w, verb+" binding failed", http.StatusInternalServerError)
return
}
@@ -330,7 +330,7 @@ func (s *Server) checkedBinding(w http.ResponseWriter, r *http.Request, id strin
}
m, err := s.Mappings.GetMapping(r.Context(), b.MappingID)
if err != nil {
s.Log.Error("get mapping for binding", "err", err, "mapping", b.MappingID)
s.Log.ErrorContext(r.Context(), "get mapping for binding", "err", err, "mapping", b.MappingID)
http.Error(w, "get mapping failed", http.StatusInternalServerError)
return binding.Binding{}, false
}