@@ -65,6 +65,24 @@ func NewBeatForReceiver(settings instance.Settings, receiverConfig map[string]an
6565 ucfg .VarExp ,
6666 }
6767
68+ err = setLogger (b , receiverConfig , core )
69+ if err != nil {
70+ return nil , fmt .Errorf ("error configuring beats logger: %w" , err )
71+ }
72+
73+ // extracting it here for ease of use
74+ logger := b .Info .Logger
75+
76+ // if output is set and if output is not otelconsumer, inform users
77+ if receiverConfig ["output" ] != nil && receiverConfig ["output" ].(map [string ]any )["otelconsumer" ] == nil { //nolint: errcheck // output will always be of map type
78+ logger .Debugf ("configured output does not work with beatreceiver, please use appropriate exporter instead" )
79+ }
80+
81+ // all beatreceivers will use otelconsumer output by default
82+ receiverConfig ["output" ] = map [string ]any {
83+ "otelconsumer" : map [string ]any {},
84+ }
85+
6886 tmp , err := ucfg .NewFrom (receiverConfig , cfOpts ... )
6987 if err != nil {
7088 return nil , fmt .Errorf ("error converting receiver config to ucfg: %w" , err )
@@ -129,36 +147,12 @@ func NewBeatForReceiver(settings instance.Settings, receiverConfig map[string]an
129147 return nil , fmt .Errorf ("error unpacking config data: %w" , err )
130148 }
131149
132- logpConfig := logp.Config {}
133- logpConfig .AddCaller = true
134- logpConfig .Beat = b .Info .Beat
135- logpConfig .Files .MaxSize = 1
136-
137- if b .Config .Logging == nil {
138- b .Config .Logging = config .NewConfig ()
139- }
140-
141- if err := b .Config .Logging .Unpack (& logpConfig ); err != nil {
142- return nil , fmt .Errorf ("error unpacking beats logging config: %w\n %v" , err , b .Config .Logging )
143- }
144-
145- b .Info .Logger , err = logp .ConfigureWithCoreLocal (logpConfig , core )
146- if err != nil {
147- return nil , fmt .Errorf ("error configuring beats logp: %w" , err )
148- }
149- // extracting it here for ease of use
150- logger := b .Info .Logger
151-
152150 instrumentation , err := instrumentation .New (cfg , b .Info .Beat , b .Info .Version , logger )
153151 if err != nil {
154152 return nil , fmt .Errorf ("error setting up instrumentation: %w" , err )
155153 }
156154 b .Instrumentation = instrumentation
157155
158- if err := instance .PromoteOutputQueueSettings (b ); err != nil {
159- return nil , fmt .Errorf ("could not promote output queue settings: %w" , err )
160- }
161-
162156 if err := features .UpdateFromConfig (b .RawConfig ); err != nil {
163157 return nil , fmt .Errorf ("could not parse features: %w" , err )
164158 }
@@ -261,17 +255,6 @@ func NewBeatForReceiver(settings instance.Settings, receiverConfig map[string]an
261255 }
262256 b .SetProcessors (processors )
263257
264- // This should be replaced with static config for otel consumer
265- // but need to figure out if we want the Queue settings from here.
266- outputEnabled := b .Config .Output .IsSet () && b .Config .Output .Config ().Enabled ()
267- if ! outputEnabled {
268- if b .Manager .Enabled () {
269- logger .Info ("Output is configured through Central Management" )
270- } else {
271- return nil , fmt .Errorf ("no outputs are defined, please define one under the output section" )
272- }
273- }
274-
275258 reg := b .Monitoring .StatsRegistry ().GetOrCreateRegistry ("libbeat" )
276259
277260 monitors := pipeline.Monitors {
@@ -298,3 +281,31 @@ func NewBeatForReceiver(settings instance.Settings, receiverConfig map[string]an
298281
299282 return b , nil
300283}
284+
285+ // setLogger configures a logp logger and sets it on b.Info.Logger
286+ func setLogger (b * instance.Beat , receiverConfig map [string ]any , core zapcore.Core ) error {
287+
288+ var err error
289+ logpConfig := logp.Config {}
290+ logpConfig .AddCaller = true
291+ logpConfig .Beat = b .Info .Beat
292+ logpConfig .Files .MaxSize = 1
293+
294+ var logCfg * config.C
295+ if _ , ok := receiverConfig ["logging" ]; ! ok {
296+ logCfg = config .NewConfig ()
297+ } else {
298+ logCfg = config .MustNewConfigFrom (receiverConfig ["logging" ])
299+ }
300+
301+ if err := logCfg .Unpack (& logpConfig ); err != nil {
302+ return fmt .Errorf ("error unpacking beats logging config: %w\n %v" , err , b .Config .Logging )
303+ }
304+
305+ b .Info .Logger , err = logp .ConfigureWithCoreLocal (logpConfig , core )
306+ if err != nil {
307+ return fmt .Errorf ("error configuring beats logp: %w" , err )
308+ }
309+
310+ return nil
311+ }
0 commit comments