[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
parent b5993095fa
commit 68e6d08c76
118 changed files with 813 additions and 591 deletions

View File

@@ -66,7 +66,7 @@ func NewWorkerPool[MsgType any](workers int, queueRatio int) *WorkerPool[MsgType
}
// Log new worker creation with worker type prefix
log.Infof("%s created with workers=%d queue=%d",
log.Infof(nil, "%s created with workers=%d queue=%d",
w.wtype,
workers,
workers*queueRatio,
@@ -77,7 +77,7 @@ func NewWorkerPool[MsgType any](workers int, queueRatio int) *WorkerPool[MsgType
// Start will attempt to start the underlying worker pool, or return error.
func (w *WorkerPool[MsgType]) Start() error {
log.Infof("%s starting", w.wtype)
log.Infof(nil, "%s starting", w.wtype)
// Check processor was set
if w.process == nil {
@@ -94,7 +94,7 @@ func (w *WorkerPool[MsgType]) Start() error {
// Stop will attempt to stop the underlying worker pool, or return error.
func (w *WorkerPool[MsgType]) Stop() error {
log.Infof("%s stopping", w.wtype)
log.Infof(nil, "%s stopping", w.wtype)
// Attempt to stop pool
if !w.workers.Stop() {
@@ -107,14 +107,14 @@ func (w *WorkerPool[MsgType]) Stop() error {
// SetProcessor will set the Worker's processor function, which is called for each queued message.
func (w *WorkerPool[MsgType]) SetProcessor(fn func(context.Context, MsgType) error) {
if w.process != nil {
log.Panicf("%s Worker.process is already set", w.wtype)
log.Panicf(nil, "%s Worker.process is already set", w.wtype)
}
w.process = fn
}
// Queue will queue provided message to be processed with there's a free worker.
func (w *WorkerPool[MsgType]) Queue(msg MsgType) {
log.Tracef("%s queueing message: %+v", w.wtype, msg)
log.Tracef(nil, "%s queueing message: %+v", w.wtype, msg)
// Create new process function for msg
process := func(ctx context.Context) {