diff options
author | 2023-02-17 12:02:29 +0100 | |
---|---|---|
committer | 2023-02-17 12:02:29 +0100 | |
commit | 68e6d08c768b789987a753d42f66caf73ce10ee1 (patch) | |
tree | 1c9eb6da6c326266d653de80684c3aec58922638 /internal/media/processingemoji.go | |
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/media/processingemoji.go')
-rw-r--r-- | internal/media/processingemoji.go | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/internal/media/processingemoji.go b/internal/media/processingemoji.go index 0a36174b0..0c3e83e6b 100644 --- a/internal/media/processingemoji.go +++ b/internal/media/processingemoji.go @@ -67,7 +67,7 @@ func (p *ProcessingEmoji) LoadEmoji(ctx context.Context) (*gtsmodel.Emoji, error if !done { // Provided context was cancelled, e.g. request cancelled // early. Queue this item for asynchronous processing. - log.Warnf("reprocessing emoji %s after canceled ctx", p.emoji.ID) + log.Warnf(ctx, "reprocessing emoji %s after canceled ctx", p.emoji.ID) go p.mgr.state.Workers.Media.Enqueue(p.Process) } @@ -77,7 +77,7 @@ func (p *ProcessingEmoji) LoadEmoji(ctx context.Context) (*gtsmodel.Emoji, error // Process allows the receiving object to fit the runners.WorkerFunc signature. It performs a (blocking) load and logs on error. func (p *ProcessingEmoji) Process(ctx context.Context) { if _, _, err := p.load(ctx); err != nil { - log.Errorf("error processing emoji: %v", err) + log.Errorf(ctx, "error processing emoji: %v", err) } } @@ -167,7 +167,7 @@ func (p *ProcessingEmoji) store(ctx context.Context) error { // Ensure post callback gets called. if err := p.postFn(ctx); err != nil { - log.Errorf("error executing postdata function: %v", err) + log.Errorf(ctx, "error executing postdata function: %v", err) } }() @@ -180,7 +180,7 @@ func (p *ProcessingEmoji) store(ctx context.Context) error { defer func() { // Ensure data reader gets closed on return. if err := rc.Close(); err != nil { - log.Errorf("error closing data reader: %v", err) + log.Errorf(ctx, "error closing data reader: %v", err) } }() @@ -251,7 +251,7 @@ func (p *ProcessingEmoji) store(ctx context.Context) error { // This shouldn't already exist, but we do a check as it's worth logging. if have, _ := p.mgr.state.Storage.Has(ctx, p.emoji.ImagePath); have { - log.Warnf("emoji already exists at storage path: %s", p.emoji.ImagePath) + log.Warnf(ctx, "emoji already exists at storage path: %s", p.emoji.ImagePath) // Attempt to remove existing emoji at storage path (might be broken / out-of-date) if err := p.mgr.state.Storage.Delete(ctx, p.emoji.ImagePath); err != nil { @@ -267,8 +267,9 @@ func (p *ProcessingEmoji) store(ctx context.Context) error { // Once again check size in case none was provided previously. if size := bytesize.Size(sz); size > maxSize { + if err := p.mgr.state.Storage.Delete(ctx, p.emoji.ImagePath); err != nil { - log.Errorf("error removing too-large-emoji from storage: %v", err) + log.Errorf(ctx, "error removing too-large-emoji from storage: %v", err) } return fmt.Errorf("calculated emoji size %s greater than max allowed %s", size, maxSize) } @@ -308,8 +309,7 @@ func (p *ProcessingEmoji) finish(ctx context.Context) error { // This shouldn't already exist, but we do a check as it's worth logging. if have, _ := p.mgr.state.Storage.Has(ctx, p.emoji.ImageStaticPath); have { - log.Warnf("static emoji already exists at storage path: %s", p.emoji.ImagePath) - + log.Warnf(ctx, "static emoji already exists at storage path: %s", p.emoji.ImagePath) // Attempt to remove static existing emoji at storage path (might be broken / out-of-date) if err := p.mgr.state.Storage.Delete(ctx, p.emoji.ImageStaticPath); err != nil { return fmt.Errorf("error removing static emoji from storage: %v", err) |