Skip to content

Commit 2fed60d

Browse files
committed
Remove entry body logging, use timestamp instead
1 parent 989f75d commit 2fed60d

File tree

5 files changed

+18
-14
lines changed

5 files changed

+18
-14
lines changed

.chloggen/improve-log-transformers-logs.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ change_type: enhancement
77
component: pkg/stanza
88

99
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10-
note: Add log file path and original record to errors logs from log transformers processors
10+
note: Add log file path and entry timestamp to errors logs from log transformers processors
1111

1212
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
1313
issues: [37285]
@@ -16,8 +16,8 @@ issues: [37285]
1616
# These lines will be padded with 2 spaces and then inserted directly into the document.
1717
# Use pipe (|) for multiline entries.
1818
subtext: |
19-
When a log transformer processor fails to process an log entry it will include the log file path and the entry's body in its own logs.
20-
This makes it easier to debug why certain log entries are causing issues in the processors.
19+
When a log transformer processor fails to process an log entry it will include the log file path and the entry's timestamp in its own logs.
20+
With this information the user can access the log file and find the entry that's having issues.
2121
2222
# If your change doesn't affect end users or the exported elements of any package,
2323
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.

pkg/stanza/fileconsumer/attrs/attrs.go

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const (
1818
LogFileOwnerName = "log.file.owner.name"
1919
LogFileOwnerGroupName = "log.file.owner.group.name"
2020
LogFileRecordNumber = "log.file.record_number"
21-
LogRecordOriginal = "log.record.original"
2221
)
2322

2423
type Resolver struct {

pkg/stanza/operator/helper/transformer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (t *TransformerOperator) HandleEntryError(ctx context.Context, entry *entry
101101
zap.Any("action", t.OnError),
102102
}
103103
if entry != nil {
104-
toAddFields := []zap.Field{zap.Any(attrs.LogRecordOriginal, entry.Body)}
104+
toAddFields := []zap.Field{zap.Any("entry.timestamp", entry.Timestamp)}
105105
if logFilePath, ok := entry.Attributes[attrs.LogFilePath]; ok {
106106
toAddFields = slices.Insert(toAddFields, 0, zap.Any(attrs.LogFilePath, logFilePath))
107107
}

pkg/stanza/operator/helper/transformer_test.go

+13-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"fmt"
99
"testing"
10+
"time"
1011

1112
"github.com/stretchr/testify/mock"
1213
"github.com/stretchr/testify/require"
@@ -92,7 +93,8 @@ func TestTransformerDropOnError(t *testing.T) {
9293
}
9394
ctx := context.Background()
9495
testEntry := entry.New()
95-
testEntry.Body = "test"
96+
now := time.Now()
97+
testEntry.Timestamp = now
9698
testEntry.AddAttribute(attrs.LogFilePath, "/test/file")
9799
transform := func(_ *entry.Entry) error {
98100
return fmt.Errorf("Failure")
@@ -108,7 +110,7 @@ func TestTransformerDropOnError(t *testing.T) {
108110
Entry: zapcore.Entry{Level: zap.ErrorLevel, Message: "Failed to process entry"},
109111
Context: []zapcore.Field{
110112
zap.Any(attrs.LogFilePath, "/test/file"),
111-
zap.Any(attrs.LogRecordOriginal, "test"),
113+
zap.Any("entry.timestamp", now),
112114
{Key: "error", Type: zapcore.ErrorType, Interface: fmt.Errorf("Failure")},
113115
zap.Any("action", "drop"),
114116
},
@@ -141,7 +143,8 @@ func TestTransformerDropOnErrorQuiet(t *testing.T) {
141143
}
142144
ctx := context.Background()
143145
testEntry := entry.New()
144-
testEntry.Body = "test"
146+
now := time.Now()
147+
testEntry.Timestamp = now
145148
testEntry.AddAttribute(attrs.LogFilePath, "/test/file")
146149
transform := func(_ *entry.Entry) error {
147150
return fmt.Errorf("Failure")
@@ -157,7 +160,7 @@ func TestTransformerDropOnErrorQuiet(t *testing.T) {
157160
Entry: zapcore.Entry{Level: zap.DebugLevel, Message: "Failed to process entry"},
158161
Context: []zapcore.Field{
159162
zap.Any(attrs.LogFilePath, "/test/file"),
160-
zap.Any(attrs.LogRecordOriginal, "test"),
163+
zap.Any("entry.timestamp", now),
161164
{Key: "error", Type: 26, Interface: fmt.Errorf("Failure")},
162165
zap.Any("action", "drop_quiet"),
163166
},
@@ -190,7 +193,8 @@ func TestTransformerSendOnError(t *testing.T) {
190193
}
191194
ctx := context.Background()
192195
testEntry := entry.New()
193-
testEntry.Body = "test"
196+
now := time.Now()
197+
testEntry.Timestamp = now
194198
testEntry.AddAttribute(attrs.LogFilePath, "/test/file")
195199
transform := func(_ *entry.Entry) error {
196200
return fmt.Errorf("Failure")
@@ -206,7 +210,7 @@ func TestTransformerSendOnError(t *testing.T) {
206210
Entry: zapcore.Entry{Level: zap.ErrorLevel, Message: "Failed to process entry"},
207211
Context: []zapcore.Field{
208212
zap.Any(attrs.LogFilePath, "/test/file"),
209-
zap.Any(attrs.LogRecordOriginal, "test"),
213+
zap.Any("entry.timestamp", now),
210214
{Key: "error", Type: 26, Interface: fmt.Errorf("Failure")},
211215
zap.Any("action", "send"),
212216
},
@@ -239,7 +243,8 @@ func TestTransformerSendOnErrorQuiet(t *testing.T) {
239243
}
240244
ctx := context.Background()
241245
testEntry := entry.New()
242-
testEntry.Body = "test"
246+
now := time.Now()
247+
testEntry.Timestamp = now
243248
testEntry.AddAttribute(attrs.LogFilePath, "/test/file")
244249
transform := func(_ *entry.Entry) error {
245250
return fmt.Errorf("Failure")
@@ -255,7 +260,7 @@ func TestTransformerSendOnErrorQuiet(t *testing.T) {
255260
Entry: zapcore.Entry{Level: zap.DebugLevel, Message: "Failed to process entry"},
256261
Context: []zapcore.Field{
257262
zap.Any(attrs.LogFilePath, "/test/file"),
258-
zap.Any(attrs.LogRecordOriginal, "test"),
263+
zap.Any("entry.timestamp", now),
259264
{Key: "error", Type: 26, Interface: fmt.Errorf("Failure")},
260265
zap.Any("action", "send_quiet"),
261266
},

pkg/stanza/operator/transformer/router/transformer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (t *Transformer) Process(ctx context.Context, entry *entry.Entry) error {
4343

4444
logger := t.Logger()
4545
if entry != nil {
46-
toAddFields := []zap.Field{zap.Any(attrs.LogRecordOriginal, entry.Body)}
46+
toAddFields := []zap.Field{zap.Any("entry.timestamp", entry.Timestamp)}
4747
if logFilePath, ok := entry.Attributes[attrs.LogFilePath]; ok {
4848
toAddFields = slices.Insert(toAddFields, 0, zap.Any(attrs.LogFilePath, logFilePath))
4949
}

0 commit comments

Comments
 (0)