fix: set log timestamp as soon as they are received instead of when the batch is sent
Brijesh Wawdhane ops@brijesh.dev
Sat, 28 Dec 2024 16:39:36 +0530
1 files changed,
7 insertions(+),
5 deletions(-)
jump to
M
client.go
→
client.go
@@ -44,8 +44,9 @@ LevelFatal LogLevel = LogLevel(logs.LogLevel_FATAL)
) type LogEntry struct { - Level LogLevel - Message string + Level LogLevel + Message string + Timestamp string } func (c *Client) SendLogs(entries []LogEntry) error {@@ -62,7 +63,7 @@
for i, entry := range entries { pbLogs[i] = &logs.LogEntry{ LogId: uuid.New().String(), - Timestamp: time.Now().Format(time.RFC3339), + Timestamp: entry.Timestamp, Level: logs.LogLevel(entry.Level), Message: entry.Message, }@@ -136,8 +137,9 @@ slog.LevelError: LevelError,
}[record.Level] entry := LogEntry{ - Level: level, - Message: record.Message, + Level: level, + Message: record.Message, + Timestamp: time.Now().Format(time.RFC3339), } h.bufferMutex.Lock()