-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[pkg/stanza] Improve error logs produced by transformer processors #37285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
056f7b5
deb6d42
f944b1d
fb7125e
4099adf
578aafb
3518fdf
80308d2
989f75d
2fed60d
ee9f128
bfecb95
d719743
5033e01
45366a4
d34d6ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: enhancement | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: pkg/stanza | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Add log file path and original record to errors logs from log transformers processors | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [37285] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: | | ||
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. | ||
This makes it easier to debug why certain log entries are causing issues in the processors. | ||
|
||
# If your change doesn't affect end users or the exported elements of any package, | ||
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
# Optional: The change log or logs in which this entry should be included. | ||
# e.g. '[user]' or '[user, api]' | ||
# Include 'user' if the change is relevant to end users. | ||
# Include 'api' if there is a change to a library API. | ||
# Default: '[user]' | ||
change_logs: [user] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,15 @@ package helper // import "github.com/open-telemetry/opentelemetry-collector-cont | |
import ( | ||
"context" | ||
"fmt" | ||
"slices" | ||
|
||
"github.com/expr-lang/expr/vm" | ||
"go.opentelemetry.io/collector/component" | ||
"go.uber.org/zap" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/entry" | ||
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/errors" | ||
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/fileconsumer/attrs" | ||
) | ||
|
||
// NewTransformerConfig creates a new transformer config with default values | ||
|
@@ -94,10 +96,22 @@ func (t *TransformerOperator) ProcessWith(ctx context.Context, entry *entry.Entr | |
|
||
// HandleEntryError will handle an entry error using the on_error strategy. | ||
func (t *TransformerOperator) HandleEntryError(ctx context.Context, entry *entry.Entry, err error) error { | ||
logFields := []zap.Field{ | ||
zap.Any("error", err), | ||
zap.Any("action", t.OnError), | ||
} | ||
if entry != nil { | ||
toAddFields := []zap.Field{zap.Any(attrs.LogRecordOriginal, entry.Body)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't agree we should add the body. The body could contain sensitive information and is not necessarily the reason for the failure. Maybe the timestamp is enough? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to make the Collector's log useful enough so that we could avoid looking at the real log file. I had totally overlooked the fact that the body can contain sensitive information. So I agree that we can't simply include it there. :/ Originally I wanted to include the line number of the entry, but because of the way the file scanning is working it got complicated (lots of wrapping of the scanner's splitfunc and some file position tracking is byte based instead of line based). I think the timestamp will be a good substitute for now and I can try to get the line number working later. 👍 |
||
if logFilePath, ok := entry.Attributes[attrs.LogFilePath]; ok { | ||
douglascamata marked this conversation as resolved.
Show resolved
Hide resolved
|
||
toAddFields = slices.Insert(toAddFields, 0, zap.Any(attrs.LogFilePath, logFilePath)) | ||
} | ||
logFields = slices.Insert(logFields, 0, toAddFields...) | ||
} | ||
|
||
if t.OnError == SendOnErrorQuiet || t.OnError == DropOnErrorQuiet { | ||
t.Logger().Debug("Failed to process entry", zap.Any("error", err), zap.Any("action", t.OnError)) | ||
t.Logger().Debug("Failed to process entry", logFields...) | ||
} else { | ||
t.Logger().Error("Failed to process entry", zap.Any("error", err), zap.Any("action", t.OnError)) | ||
t.Logger().Error("Failed to process entry", logFields...) | ||
} | ||
if t.OnError == SendOnError || t.OnError == SendOnErrorQuiet { | ||
writeErr := t.Write(ctx, entry) | ||
|
Uh oh!
There was an error while loading. Please reload this page.