@@ -25,6 +25,7 @@ import (
2525 "github.com/open-telemetry/opentelemetry-collector/config/configmodels"
2626 "github.com/open-telemetry/opentelemetry-collector/consumer"
2727 "github.com/open-telemetry/opentelemetry-collector/consumer/consumerdata"
28+ "github.com/open-telemetry/opentelemetry-collector/internal/data"
2829)
2930
3031// ExampleReceiver is for testing purposes. We are defining an example config and factory
@@ -60,7 +61,8 @@ func (f *ExampleReceiverFactory) CustomUnmarshaler() component.CustomUnmarshaler
6061func (f * ExampleReceiverFactory ) CreateDefaultConfig () configmodels.Receiver {
6162 return & ExampleReceiver {
6263 ReceiverSettings : configmodels.ReceiverSettings {
63- TypeVal : "examplereceiver" ,
64+ TypeVal : f .Type (),
65+ NameVal : string (f .Type ()),
6466 Endpoint : "localhost:1000" ,
6567 },
6668 ExtraSetting : "some string" ,
@@ -80,7 +82,7 @@ func (f *ExampleReceiverFactory) CreateTraceReceiver(
8082 return nil , configerror .ErrDataTypeIsNotSupported
8183 }
8284
83- // There must be one receiver for both metrics and traces . We maintain a map of
85+ // There must be one receiver for all data types . We maintain a map of
8486 // receivers per config.
8587
8688 // Check to see if there is already a receiver for this config.
@@ -105,7 +107,7 @@ func (f *ExampleReceiverFactory) CreateMetricsReceiver(
105107 return nil , configerror .ErrDataTypeIsNotSupported
106108 }
107109
108- // There must be one receiver for both metrics and traces . We maintain a map of
110+ // There must be one receiver for all data types . We maintain a map of
109111 // receivers per config.
110112
111113 // Check to see if there is already a receiver for this config.
@@ -120,12 +122,35 @@ func (f *ExampleReceiverFactory) CreateMetricsReceiver(
120122 return receiver , nil
121123}
122124
125+ func (f * ExampleReceiverFactory ) CreateLogReceiver (
126+ ctx context.Context ,
127+ params component.ReceiverCreateParams ,
128+ cfg configmodels.Receiver ,
129+ nextConsumer consumer.LogConsumer ,
130+ ) (component.LogReceiver , error ) {
131+ // There must be one receiver for all data types. We maintain a map of
132+ // receivers per config.
133+
134+ // Check to see if there is already a receiver for this config.
135+ receiver , ok := exampleReceivers [cfg ]
136+ if ! ok {
137+ receiver = & ExampleReceiverProducer {}
138+ // Remember the receiver in the map
139+ exampleReceivers [cfg ] = receiver
140+ }
141+ receiver .LogConsumer = nextConsumer
142+
143+ return receiver , nil
144+
145+ }
146+
123147// ExampleReceiverProducer allows producing traces and metrics for testing purposes.
124148type ExampleReceiverProducer struct {
125- TraceConsumer consumer.TraceConsumerOld
126149 Started bool
127150 Stopped bool
151+ TraceConsumer consumer.TraceConsumerOld
128152 MetricsConsumer consumer.MetricsConsumerOld
153+ LogConsumer consumer.LogConsumer
129154}
130155
131156// Start tells the receiver to start its processing.
@@ -199,7 +224,8 @@ func (f *MultiProtoReceiverFactory) CustomUnmarshaler() component.CustomUnmarsha
199224// CreateDefaultConfig creates the default configuration for the Receiver.
200225func (f * MultiProtoReceiverFactory ) CreateDefaultConfig () configmodels.Receiver {
201226 return & MultiProtoReceiver {
202- TypeVal : "multireceiver" ,
227+ TypeVal : f .Type (),
228+ NameVal : string (f .Type ()),
203229 Protocols : map [string ]MultiProtoReceiverOneCfg {
204230 "http" : {
205231 Endpoint : "example.com:8888" ,
@@ -256,7 +282,10 @@ func (f *ExampleExporterFactory) Type() configmodels.Type {
256282// CreateDefaultConfig creates the default configuration for the Exporter.
257283func (f * ExampleExporterFactory ) CreateDefaultConfig () configmodels.Exporter {
258284 return & ExampleExporter {
259- ExporterSettings : configmodels.ExporterSettings {TypeVal : f .Type ()},
285+ ExporterSettings : configmodels.ExporterSettings {
286+ TypeVal : f .Type (),
287+ NameVal : string (f .Type ()),
288+ },
260289 ExtraSetting : "some export string" ,
261290 ExtraMapSetting : nil ,
262291 ExtraListSetting : nil ,
@@ -273,10 +302,19 @@ func (f *ExampleExporterFactory) CreateMetricsExporter(logger *zap.Logger, cfg c
273302 return & ExampleExporterConsumer {}, nil
274303}
275304
305+ func (f * ExampleExporterFactory ) CreateLogExporter (
306+ ctx context.Context ,
307+ params component.ExporterCreateParams ,
308+ cfg configmodels.Exporter ,
309+ ) (component.LogExporter , error ) {
310+ return & ExampleExporterConsumer {}, nil
311+ }
312+
276313// ExampleExporterConsumer stores consumed traces and metrics for testing purposes.
277314type ExampleExporterConsumer struct {
278315 Traces []consumerdata.TraceData
279316 Metrics []consumerdata.MetricsData
317+ Logs []data.Logs
280318 ExporterStarted bool
281319 ExporterShutdown bool
282320}
@@ -301,6 +339,11 @@ func (exp *ExampleExporterConsumer) ConsumeMetricsData(ctx context.Context, md c
301339 return nil
302340}
303341
342+ func (exp * ExampleExporterConsumer ) ConsumeLogs (ctx context.Context , ld data.Logs ) error {
343+ exp .Logs = append (exp .Logs , ld )
344+ return nil
345+ }
346+
304347// Name returns the name of the exporter.
305348func (exp * ExampleExporterConsumer ) Name () string {
306349 return "exampleexporter"
@@ -312,9 +355,9 @@ func (exp *ExampleExporterConsumer) Shutdown(context.Context) error {
312355 return nil
313356}
314357
315- // ExampleProcessor is for testing purposes. We are defining an example config and factory
358+ // ExampleProcessorCfg is for testing purposes. We are defining an example config and factory
316359// for "exampleprocessor" processor type.
317- type ExampleProcessor struct {
360+ type ExampleProcessorCfg struct {
318361 configmodels.ProcessorSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
319362 ExtraSetting string `mapstructure:"extra"`
320363 ExtraMapSetting map [string ]string `mapstructure:"extra_map"`
@@ -332,11 +375,14 @@ func (f *ExampleProcessorFactory) Type() configmodels.Type {
332375
333376// CreateDefaultConfig creates the default configuration for the Processor.
334377func (f * ExampleProcessorFactory ) CreateDefaultConfig () configmodels.Processor {
335- return & ExampleProcessor {
336- ProcessorSettings : configmodels.ProcessorSettings {},
337- ExtraSetting : "some export string" ,
338- ExtraMapSetting : nil ,
339- ExtraListSetting : nil ,
378+ return & ExampleProcessorCfg {
379+ ProcessorSettings : configmodels.ProcessorSettings {
380+ TypeVal : f .Type (),
381+ NameVal : string (f .Type ()),
382+ },
383+ ExtraSetting : "some export string" ,
384+ ExtraMapSetting : nil ,
385+ ExtraListSetting : nil ,
340386 }
341387}
342388
@@ -358,6 +404,35 @@ func (f *ExampleProcessorFactory) CreateMetricsProcessor(
358404 return nil , configerror .ErrDataTypeIsNotSupported
359405}
360406
407+ func (f * ExampleProcessorFactory ) CreateLogProcessor (
408+ ctx context.Context ,
409+ params component.ProcessorCreateParams ,
410+ cfg configmodels.Processor ,
411+ nextConsumer consumer.LogConsumer ,
412+ ) (component.LogProcessor , error ) {
413+ return & ExampleProcessor {nextConsumer }, nil
414+ }
415+
416+ type ExampleProcessor struct {
417+ nextConsumer consumer.LogConsumer
418+ }
419+
420+ func (ep * ExampleProcessor ) Start (ctx context.Context , host component.Host ) error {
421+ return nil
422+ }
423+
424+ func (ep * ExampleProcessor ) Shutdown (ctx context.Context ) error {
425+ return nil
426+ }
427+
428+ func (ep * ExampleProcessor ) GetCapabilities () component.ProcessorCapabilities {
429+ return component.ProcessorCapabilities {MutatesConsumedData : false }
430+ }
431+
432+ func (ep * ExampleProcessor ) ConsumeLogs (ctx context.Context , ld data.Logs ) error {
433+ return ep .nextConsumer .ConsumeLogs (ctx , ld )
434+ }
435+
361436// ExampleExtensionCfg is for testing purposes. We are defining an example config and factory
362437// for "exampleextension" extension type.
363438type ExampleExtensionCfg struct {
@@ -387,10 +462,13 @@ func (f *ExampleExtensionFactory) Type() configmodels.Type {
387462// CreateDefaultConfig creates the default configuration for the Extension.
388463func (f * ExampleExtensionFactory ) CreateDefaultConfig () configmodels.Extension {
389464 return & ExampleExtensionCfg {
390- ExtensionSettings : configmodels.ExtensionSettings {TypeVal : f .Type ()},
391- ExtraSetting : "extra string setting" ,
392- ExtraMapSetting : nil ,
393- ExtraListSetting : nil ,
465+ ExtensionSettings : configmodels.ExtensionSettings {
466+ TypeVal : f .Type (),
467+ NameVal : string (f .Type ()),
468+ },
469+ ExtraSetting : "extra string setting" ,
470+ ExtraMapSetting : nil ,
471+ ExtraListSetting : nil ,
394472 }
395473}
396474
0 commit comments