diff options
author | 2023-02-17 12:02:29 +0100 | |
---|---|---|
committer | 2023-02-17 12:02:29 +0100 | |
commit | 68e6d08c768b789987a753d42f66caf73ce10ee1 (patch) | |
tree | 1c9eb6da6c326266d653de80684c3aec58922638 /internal/concurrency | |
parent | [bugfix] Set 'discoverable' properly on API accounts (#1511) (diff) | |
download | gotosocial-68e6d08c768b789987a753d42f66caf73ce10ee1.tar.xz |
[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>
Diffstat (limited to 'internal/concurrency')
-rw-r--r-- | internal/concurrency/workers.go | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/internal/concurrency/workers.go b/internal/concurrency/workers.go index a27e5d115..d782d3f42 100644 --- a/internal/concurrency/workers.go +++ b/internal/concurrency/workers.go @@ -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) { |