Skip to content
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

Receive all logs if no attributes are specified #37721

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions receiver/cloudflarereceiver/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,19 +272,39 @@ func (l *logsReceiver) processLogs(now pcommon.Timestamp, logs []map[string]any)
}

attrs := logRecord.Attributes()
for field, attribute := range l.cfg.Attributes {
if v, ok := log[field]; ok {
if len(l.cfg.Attributes) != 0 {
for field, attribute := range l.cfg.Attributes {
if v, ok := log[field]; ok {
switch v := v.(type) {
case string:
attrs.PutStr(attribute, v)
case int:
attrs.PutInt(attribute, int64(v))
case int64:
attrs.PutInt(attribute, v)
case float64:
attrs.PutDouble(attribute, v)
case bool:
attrs.PutBool(attribute, v)
default:
l.logger.Warn("unable to translate field to attribute, unsupported type", zap.String("field", field), zap.Any("value", v), zap.String("type", fmt.Sprintf("%T", v)))
}
}
}
// If no attributes were specified, receive them all
} else {
for field, v := range log {
switch v := v.(type) {
case string:
attrs.PutStr(attribute, v)
attrs.PutStr(field, v)
case int:
attrs.PutInt(attribute, int64(v))
attrs.PutInt(field, int64(v))
case int64:
attrs.PutInt(attribute, v)
attrs.PutInt(field, v)
case float64:
attrs.PutDouble(attribute, v)
attrs.PutDouble(field, v)
case bool:
attrs.PutBool(attribute, v)
attrs.PutBool(field, v)
default:
l.logger.Warn("unable to translate field to attribute, unsupported type", zap.String("field", field), zap.Any("value", v), zap.String("type", fmt.Sprintf("%T", v)))
}
Expand Down
Loading