summaryrefslogtreecommitdiff
path: root/internal/typeutils
diff options
context:
space:
mode:
authorLibravatar Daenney <daenney@users.noreply.github.com>2023-02-17 12:02:29 +0100
committerLibravatar GitHub <noreply@github.com>2023-02-17 12:02:29 +0100
commit68e6d08c768b789987a753d42f66caf73ce10ee1 (patch)
tree1c9eb6da6c326266d653de80684c3aec58922638 /internal/typeutils
parent[bugfix] Set 'discoverable' properly on API accounts (#1511) (diff)
downloadgotosocial-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/typeutils')
-rw-r--r--internal/typeutils/astointernal.go8
-rw-r--r--internal/typeutils/defaulticons.go4
-rw-r--r--internal/typeutils/internaltoas.go4
-rw-r--r--internal/typeutils/internaltofrontend.go16
-rw-r--r--internal/typeutils/internaltorss.go6
5 files changed, 19 insertions, 19 deletions
diff --git a/internal/typeutils/astointernal.go b/internal/typeutils/astointernal.go
index fff9c807a..2ed1d52d3 100644
--- a/internal/typeutils/astointernal.go
+++ b/internal/typeutils/astointernal.go
@@ -82,7 +82,7 @@ func (c *converter) ASRepresentationToAccount(ctx context.Context, accountable a
// account emojis (used in bio, display name, fields)
if emojis, err := ap.ExtractEmojis(accountable); err != nil {
- log.Infof("ASRepresentationToAccount: error extracting account emojis: %s", err)
+ log.Infof(nil, "error extracting account emojis: %s", err)
} else {
acct.Emojis = emojis
}
@@ -217,13 +217,13 @@ func (c *converter) extractAttachments(i ap.WithAttachment) []*gtsmodel.MediaAtt
attachmentable, ok := t.(ap.Attachmentable)
if !ok {
- log.Error("ap attachment was not attachmentable")
+ log.Error(nil, "ap attachment was not attachmentable")
continue
}
attachment, err := ap.ExtractAttachment(attachmentable)
if err != nil {
- log.Errorf("error extracting attachment: %s", err)
+ log.Errorf(nil, "error extracting attachment: %s", err)
continue
}
@@ -684,7 +684,7 @@ func (c *converter) ASFlagToReport(ctx context.Context, flaggable ap.Flaggable)
return nil, fmt.Errorf("ASFlagToReport: db error getting status with url %s: %w", statusURIString, err)
}
- log.Warnf("ASFlagToReport: reported status %s could not be found in the db, skipping it", statusURIString)
+ log.Warnf(nil, "reported status %s could not be found in the db, skipping it", statusURIString)
continue
}
}
diff --git a/internal/typeutils/defaulticons.go b/internal/typeutils/defaulticons.go
index 8ce715b31..e7d683dba 100644
--- a/internal/typeutils/defaulticons.go
+++ b/internal/typeutils/defaulticons.go
@@ -41,13 +41,13 @@ const defaultHeaderPath = "/assets/default_header.png"
func populateDefaultAvatars() (defaultAvatars []string) {
webAssetsAbsFilePath, err := filepath.Abs(config.GetWebAssetBaseDir())
if err != nil {
- log.Panicf("populateDefaultAvatars: error getting abs path for web assets: %s", err)
+ log.Panicf(nil, "error getting abs path for web assets: %s", err)
}
defaultAvatarsAbsFilePath := filepath.Join(webAssetsAbsFilePath, "default_avatars")
defaultAvatarFiles, err := os.ReadDir(defaultAvatarsAbsFilePath)
if err != nil {
- log.Warnf("populateDefaultAvatars: error reading default avatars at %s: %s", defaultAvatarsAbsFilePath, err)
+ log.Warnf(nil, "error reading default avatars at %s: %s", defaultAvatarsAbsFilePath, err)
return
}
diff --git a/internal/typeutils/internaltoas.go b/internal/typeutils/internaltoas.go
index 2ae58b317..06b49c18f 100644
--- a/internal/typeutils/internaltoas.go
+++ b/internal/typeutils/internaltoas.go
@@ -252,7 +252,7 @@ func (c *converter) AccountToAS(ctx context.Context, a *gtsmodel.Account) (vocab
if err == nil {
a.AvatarMediaAttachment = avatar
} else {
- log.Errorf("AccountToAS: error getting Avatar with id %s: %s", a.AvatarMediaAttachmentID, err)
+ log.Errorf(ctx, "error getting Avatar with id %s: %s", a.AvatarMediaAttachmentID, err)
}
}
@@ -286,7 +286,7 @@ func (c *converter) AccountToAS(ctx context.Context, a *gtsmodel.Account) (vocab
if err == nil {
a.HeaderMediaAttachment = header
} else {
- log.Errorf("AccountToAS: error getting Header with id %s: %s", a.HeaderMediaAttachmentID, err)
+ log.Errorf(ctx, "error getting Header with id %s: %s", a.HeaderMediaAttachmentID, err)
}
}
diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go
index 738155532..6e6bc381e 100644
--- a/internal/typeutils/internaltofrontend.go
+++ b/internal/typeutils/internaltofrontend.go
@@ -119,7 +119,7 @@ func (c *converter) AccountToAPIAccountPublic(ctx context.Context, a *gtsmodel.A
if a.AvatarMediaAttachment == nil {
avi, err := c.db.GetAttachmentByID(ctx, a.AvatarMediaAttachmentID)
if err != nil {
- log.Errorf("AccountToAPIAccountPublic: error getting Avatar with id %s: %s", a.AvatarMediaAttachmentID, err)
+ log.Errorf(ctx, "error getting Avatar with id %s: %s", a.AvatarMediaAttachmentID, err)
}
a.AvatarMediaAttachment = avi
}
@@ -136,7 +136,7 @@ func (c *converter) AccountToAPIAccountPublic(ctx context.Context, a *gtsmodel.A
if a.HeaderMediaAttachment == nil {
avi, err := c.db.GetAttachmentByID(ctx, a.HeaderMediaAttachmentID)
if err != nil {
- log.Errorf("AccountToAPIAccountPublic: error getting Header with id %s: %s", a.HeaderMediaAttachmentID, err)
+ log.Errorf(ctx, "error getting Header with id %s: %s", a.HeaderMediaAttachmentID, err)
}
a.HeaderMediaAttachment = avi
}
@@ -164,7 +164,7 @@ func (c *converter) AccountToAPIAccountPublic(ctx context.Context, a *gtsmodel.A
// convert account gts model emojis to frontend api model emojis
apiEmojis, err := c.convertEmojisToAPIEmojis(ctx, a.Emojis, a.EmojiIDs)
if err != nil {
- log.Errorf("error converting account emojis: %v", err)
+ log.Errorf(ctx, "error converting account emojis: %v", err)
}
var (
@@ -577,31 +577,31 @@ func (c *converter) StatusToAPIStatus(ctx context.Context, s *gtsmodel.Status, r
// convert status gts model attachments to frontend api model attachments
apiAttachments, err := c.convertAttachmentsToAPIAttachments(ctx, s.Attachments, s.AttachmentIDs)
if err != nil {
- log.Errorf("error converting status attachments: %v", err)
+ log.Errorf(ctx, "error converting status attachments: %v", err)
}
// convert status gts model mentions to frontend api model mentions
apiMentions, err := c.convertMentionsToAPIMentions(ctx, s.Mentions, s.MentionIDs)
if err != nil {
- log.Errorf("error converting status mentions: %v", err)
+ log.Errorf(ctx, "error converting status mentions: %v", err)
}
// convert status gts model tags to frontend api model tags
apiTags, err := c.convertTagsToAPITags(ctx, s.Tags, s.TagIDs)
if err != nil {
- log.Errorf("error converting status tags: %v", err)
+ log.Errorf(ctx, "error converting status tags: %v", err)
}
// convert status gts model emojis to frontend api model emojis
apiEmojis, err := c.convertEmojisToAPIEmojis(ctx, s.Emojis, s.EmojiIDs)
if err != nil {
- log.Errorf("error converting status emojis: %v", err)
+ log.Errorf(ctx, "error converting status emojis: %v", err)
}
// Fetch status interaction flags for acccount
interacts, err := c.interactionsWithStatusForAccount(ctx, s, requestingAccount)
if err != nil {
- log.Errorf("error getting interactions for status %s for account %s: %v", s.ID, requestingAccount.ID, err)
+ log.Errorf(ctx, "error getting interactions for status %s for account %s: %v", s.ID, requestingAccount.ID, err)
// Ensure a non nil object
interacts = &statusInteractions{}
diff --git a/internal/typeutils/internaltorss.go b/internal/typeutils/internaltorss.go
index 64cfa1211..cc241e0b9 100644
--- a/internal/typeutils/internaltorss.go
+++ b/internal/typeutils/internaltorss.go
@@ -130,7 +130,7 @@ func (c *converter) StatusToRSSItem(ctx context.Context, s *gtsmodel.Status) (*f
for _, gtsEmoji := range s.Emojis {
apiEmoji, err := c.EmojiToAPIEmoji(ctx, gtsEmoji)
if err != nil {
- log.Errorf("error converting emoji with id %s: %s", gtsEmoji.ID, err)
+ log.Errorf(ctx, "error converting emoji with id %s: %s", gtsEmoji.ID, err)
continue
}
apiEmojis = append(apiEmojis, apiEmoji)
@@ -141,12 +141,12 @@ func (c *converter) StatusToRSSItem(ctx context.Context, s *gtsmodel.Status) (*f
for _, e := range s.EmojiIDs {
gtsEmoji := &gtsmodel.Emoji{}
if err := c.db.GetByID(ctx, e, gtsEmoji); err != nil {
- log.Errorf("error getting emoji with id %s: %s", e, err)
+ log.Errorf(ctx, "error getting emoji with id %s: %s", e, err)
continue
}
apiEmoji, err := c.EmojiToAPIEmoji(ctx, gtsEmoji)
if err != nil {
- log.Errorf("error converting emoji with id %s: %s", gtsEmoji.ID, err)
+ log.Errorf(ctx, "error converting emoji with id %s: %s", gtsEmoji.ID, err)
continue
}
apiEmojis = append(apiEmojis, apiEmoji)