[feature] Add a request ID and include it in logs (#1476)

This adds a lightweight form of tracing to GTS. Each incoming request is
assigned a Request ID which we then pass on and log in all our log
lines. Any function that gets called downstream from an HTTP handler
should now emit a requestID=value pair whenever it logs something.

Co-authored-by: kim <grufwub@gmail.com>
This commit is contained in:
Daenney 2023-02-17 12:02:29 +01:00 committed by GitHub
commit 68e6d08c76
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
118 changed files with 813 additions and 591 deletions

View file

@ -100,11 +100,11 @@ func doMigration(ctx context.Context, db *bun.DB) error {
}
if group.ID == 0 {
log.Info("there are no new migrations to run")
log.Info(ctx, "there are no new migrations to run")
return nil
}
log.Infof("MIGRATED DATABASE TO %s", group)
log.Infof(ctx, "MIGRATED DATABASE TO %s", group)
return nil
}
@ -245,7 +245,7 @@ func pgConn(ctx context.Context) (*DBConn, error) {
return nil, fmt.Errorf("postgres ping: %s", err)
}
log.Info("connected to POSTGRES database")
log.Info(ctx, "connected to POSTGRES database")
return conn, nil
}
@ -268,7 +268,7 @@ func sqliteConn(ctx context.Context) (*DBConn, error) {
}
if address == ":memory:" {
log.Warn("using sqlite in-memory mode; all data will be deleted when gts shuts down; this mode should only be used for debugging or running tests")
log.Warn(ctx, "using sqlite in-memory mode; all data will be deleted when gts shuts down; this mode should only be used for debugging or running tests")
// Use random name for in-memory instead of ':memory:', so
// multiple in-mem databases can be created without conflict.
@ -319,7 +319,7 @@ func sqliteConn(ctx context.Context) (*DBConn, error) {
}
return nil, fmt.Errorf("sqlite ping: %s", err)
}
log.Infof("connected to SQLITE database with address %s", address)
log.Infof(ctx, "connected to SQLITE database with address %s", address)
return conn, nil
}
@ -464,7 +464,7 @@ func sqlitePragmas(ctx context.Context, conn *DBConn) error {
return fmt.Errorf("error scanning sqlite pragma %s: %w", pv, err)
}
log.Infof("sqlite pragma %s set to %s", pk, res)
log.Infof(ctx, "sqlite pragma %s set to %s", pk, res)
}
return nil