-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Add logging.with_fields
to beatreceiver config
#42961
Changes from 9 commits
76d74c2
863fc72
c5ef3ef
9e0aefe
c144433
c62bf6d
8634ad4
21e2555
f839834
589f641
28403f4
c9a394d
2765f2d
57d4f45
528ea82
c6d6114
e657823
24df137
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 |
---|---|---|
|
@@ -346,6 +346,14 @@ func NewBeatReceiver(settings Settings, receiverConfig map[string]interface{}, u | |
return nil, fmt.Errorf("error unpacking beats logging config: %w\n%v", err, b.Config.Logging) | ||
} | ||
|
||
if logpConfig.WithFields != nil { | ||
var fields = []zapcore.Field{} | ||
for key, value := range logpConfig.WithFields { | ||
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. You should be able to write a test that ensures setting this produces logs with the expected fields. There are several system tests that run a beat and inspect the log files you could look at. 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. Since this is restricted to beatreceivers - will use the existing tests in elastic-agent to ensure this setting. Related PR on elastic-agent: elastic/elastic-agent#7062 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. This is a Beats specific change in beat.go, it doesn't make sense to me to test it in agent because a PR in agent could never break this. Agent will rely on this feature, but the elastic agent repository shouldn't be responsible for testing that it works on its own. One way to think about this is a series of contracts that must be upheld:
Those two things tested independently should guarantee this works properly. |
||
fields = append(fields, zap.Any(key, value)) | ||
} | ||
core = core.With(fields) | ||
} | ||
|
||
if err := logp.ConfigureWithCore(logpConfig, core); err != nil { | ||
return nil, fmt.Errorf("error configuring beats logp: %w", err) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree this works, but I'm wondering why
logp.ConfigureWithCore
isn't doing this? It is the logp config that has the option, I would just expect it to happen there, much like the selectors get set there.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, you are right. I will raise close this and open a separate PR on elastic-agent-libs. Thank you for pointing this