Log slow API requests with server spans and client timing

This commit is contained in:
Ian Gulliver
2026-10-21 14:45:19 -07:00
parent 671165ec71
commit b4c1dbab37
31 changed files with 458 additions and 185 deletions
+15 -14
View File
@@ -1,6 +1,7 @@
package git
import (
"context"
"fmt"
"os"
"path/filepath"
@@ -12,9 +13,9 @@ const NotesRef = "refs/notes/byre"
const notesFetch = NotesRef + "*:" + NotesRef + "*"
func ConfigureNotesFetch(repo string) error {
func ConfigureNotesFetch(ctx context.Context, repo string) error {
key := "remote." + Remote + ".fetch"
out, stderr, code, err := runCode(repo, nil, "config", "--get-all", key)
out, stderr, code, err := runCode(ctx, repo, nil, "config", "--get-all", key)
if err != nil {
return err
}
@@ -24,17 +25,17 @@ func ConfigureNotesFetch(repo string) error {
if slices.Contains(strings.Split(out, "\n"), notesFetch) {
return nil
}
_, err = run(repo, "config", "--add", key, notesFetch)
_, err = run(ctx, repo, "config", "--add", key, notesFetch)
return err
}
func NoteCommit(repo, commit, note string, env []string) (string, error) {
blob, err := runInput(repo, nil, note, "hash-object", "-w", "--stdin")
func NoteCommit(ctx context.Context, repo, commit, note string, env []string) (string, error) {
blob, err := runInput(ctx, repo, nil, note, "hash-object", "-w", "--stdin")
if err != nil {
return "", err
}
parent, stderr, code, err := runCode(repo, nil, "rev-parse", "--verify", "--quiet", NotesRef)
parent, stderr, code, err := runCode(ctx, repo, nil, "rev-parse", "--verify", "--quiet", NotesRef)
if err != nil {
return "", err
}
@@ -51,26 +52,26 @@ func NoteCommit(repo, commit, note string, env []string) (string, error) {
commitArgs := []string{"commit-tree", "-m", "Notes added by byre"}
if code == 0 {
_, err = runEnv(repo, index, "read-tree", parent)
_, err = runEnv(ctx, repo, index, "read-tree", parent)
if err != nil {
return "", err
}
commitArgs = append(commitArgs, "-p", parent)
}
_, err = runEnv(repo, index, "update-index", "--add", "--cacheinfo", "100644,"+blob+","+commit)
_, err = runEnv(ctx, repo, index, "update-index", "--add", "--cacheinfo", "100644,"+blob+","+commit)
if err != nil {
return "", err
}
tree, err := runEnv(repo, index, "write-tree")
tree, err := runEnv(ctx, repo, index, "write-tree")
if err != nil {
return "", err
}
return runEnv(repo, env, append(commitArgs, tree)...)
return runEnv(ctx, repo, env, append(commitArgs, tree)...)
}
func AdvanceNotes(repo, notes string) error {
current, stderr, code, err := runCode(repo, nil, "rev-parse", "--verify", "--quiet", NotesRef)
func AdvanceNotes(ctx context.Context, repo, notes string) error {
current, stderr, code, err := runCode(ctx, repo, nil, "rev-parse", "--verify", "--quiet", NotesRef)
if err != nil {
return err
}
@@ -78,7 +79,7 @@ func AdvanceNotes(repo, notes string) error {
return fmt.Errorf("git rev-parse %s: exit status %d: %s", NotesRef, code, stderr)
}
if code == 0 {
contained, err := IsAncestor(repo, notes, current)
contained, err := IsAncestor(ctx, repo, notes, current)
if err != nil {
return err
}
@@ -86,6 +87,6 @@ func AdvanceNotes(repo, notes string) error {
return nil
}
}
_, err = run(repo, "update-ref", NotesRef, notes)
_, err = run(ctx, repo, "update-ref", NotesRef, notes)
return err
}