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
+5 -3
View File
@@ -14,9 +14,8 @@ import (
"sync"
"time"
_ "modernc.org/sqlite"
"g.fc.run/ai/byre/internal/api"
"g.fc.run/ai/byre/internal/trace"
)
var ErrNotFound = errors.New("not found")
@@ -85,10 +84,11 @@ type Store struct {
func Open(path string, portFirst int, onEvent func([]api.Event)) (*Store, error) {
dsn := "file:" + path + "?_pragma=journal_mode(WAL)&_pragma=busy_timeout(5000)&_pragma=foreign_keys(1)&_txlock=immediate"
db, err := sql.Open("sqlite", dsn)
connector, err := newTracedConnector(dsn)
if err != nil {
return nil, err
}
db := sql.OpenDB(connector)
err = migrate(db, filepath.Dir(path))
if err != nil {
@@ -1505,7 +1505,9 @@ func (s *Store) Counts(ctx context.Context) (Counts, error) {
type emitFunc func(api.Event) error
func (s *Store) write(ctx context.Context, fn func(tx *sql.Tx, emit emitFunc) error) error {
locked := trace.Start(ctx, "store lock")
s.writeMu.Lock()
locked()
defer s.writeMu.Unlock()
tx, err := s.db.BeginTx(ctx, nil)