Log slow API requests with server spans and client timing
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
||||
"g.fc.run/ai/byre/internal/store"
|
||||
"g.fc.run/ai/byre/internal/terminal"
|
||||
"g.fc.run/ai/byre/internal/todo"
|
||||
"g.fc.run/ai/byre/internal/trace"
|
||||
"g.fc.run/ai/byre/internal/workflow"
|
||||
"tailscale.com/client/local"
|
||||
"tailscale.com/tsnet"
|
||||
@@ -86,7 +87,7 @@ func New(dataDir string, portFirst int, ts *tsnet.Server, token string) (*Server
|
||||
return nil, err
|
||||
}
|
||||
for _, p := range projects {
|
||||
err = git.ConfigureNotesFetch(p.RepoPath)
|
||||
err = git.ConfigureNotesFetch(context.Background(), p.RepoPath)
|
||||
if err != nil {
|
||||
slog.Error("configure notes fetch", "project", p.Id, "repo", p.RepoPath, "err", err)
|
||||
}
|
||||
@@ -131,7 +132,7 @@ func (s *Server) Handler() http.Handler {
|
||||
writeError(w, http.StatusBadRequest, err)
|
||||
},
|
||||
})
|
||||
return http.NewCrossOriginProtection().Handler(mux)
|
||||
return timing(http.NewCrossOriginProtection().Handler(mux))
|
||||
}
|
||||
|
||||
func (s *Server) LoopbackHandler() http.Handler {
|
||||
@@ -167,7 +168,9 @@ func (s *Server) GetTailnet(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func (s *Server) identify(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
identified := trace.Start(r.Context(), "whois")
|
||||
who, err := s.tailnet.WhoIs(r.Context(), r.RemoteAddr)
|
||||
identified()
|
||||
if err != nil {
|
||||
writeError(w, http.StatusUnauthorized, fmt.Errorf("identify %s on the tailnet: %w", r.RemoteAddr, err))
|
||||
return
|
||||
@@ -301,12 +304,12 @@ func (s *Server) createProject(ctx context.Context, name, repoPath, createdBy st
|
||||
return api.Project{}, fmt.Errorf("%w: name is required", agents.ErrInvalid)
|
||||
}
|
||||
|
||||
info, err := git.Inspect(repoPath)
|
||||
info, err := git.Inspect(ctx, repoPath)
|
||||
if err != nil {
|
||||
return api.Project{}, fmt.Errorf("%w: %w", agents.ErrInvalid, err)
|
||||
}
|
||||
|
||||
err = git.ConfigureNotesFetch(info.Root)
|
||||
err = git.ConfigureNotesFetch(ctx, info.Root)
|
||||
if err != nil {
|
||||
return api.Project{}, err
|
||||
}
|
||||
@@ -439,7 +442,7 @@ func (s *Server) GetTodo(w http.ResponseWriter, r *http.Request, projectID strin
|
||||
return
|
||||
}
|
||||
|
||||
src, found, err := git.ReadFile(p.RepoPath, p.DefaultBranch, todo.File)
|
||||
src, found, err := git.ReadFile(r.Context(), p.RepoPath, p.DefaultBranch, todo.File)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusInternalServerError, err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user