github.com/Jeffail/benthos/v3@v3.65.0/internal/bundle/tracing/bundle.go (about) 1 package tracing 2 3 import ( 4 "github.com/Jeffail/benthos/v3/internal/bundle" 5 "github.com/Jeffail/benthos/v3/lib/input" 6 "github.com/Jeffail/benthos/v3/lib/output" 7 "github.com/Jeffail/benthos/v3/lib/processor" 8 "github.com/Jeffail/benthos/v3/lib/types" 9 ) 10 11 // TracedBundle modifies a provided bundle environment so that traceable 12 // components are wrapped by components that add trace events to the returned 13 // summary. 14 func TracedBundle(b *bundle.Environment) (*bundle.Environment, *Summary) { 15 summary := NewSummary() 16 tracedEnv := b.Clone() 17 18 for _, spec := range b.InputDocs() { 19 _ = tracedEnv.InputAdd(func(batchedInput bool, conf input.Config, nm bundle.NewManagement, pcf ...types.PipelineConstructorFunc) (input.Type, error) { 20 i, err := b.InputInit(batchedInput, conf, nm, pcf...) 21 if err != nil { 22 return nil, err 23 } 24 iEvents, ctr := summary.wInputEvents(nm.Label()) 25 i = traceInput(iEvents, ctr, i) 26 return i, err 27 }, spec) 28 } 29 30 for _, spec := range b.ProcessorDocs() { 31 _ = tracedEnv.ProcessorAdd(func(conf processor.Config, nm bundle.NewManagement) (processor.Type, error) { 32 i, err := b.ProcessorInit(conf, nm) 33 if err != nil { 34 return nil, err 35 } 36 pEvents, errCtr := summary.wProcessorEvents(nm.Label()) 37 i = traceProcessor(pEvents, errCtr, i) 38 return i, err 39 }, spec) 40 } 41 42 for _, spec := range b.OutputDocs() { 43 _ = tracedEnv.OutputAdd(func(conf output.Config, nm bundle.NewManagement, pcf ...types.PipelineConstructorFunc) (output.Type, error) { 44 pcf = output.AppendProcessorsFromConfig(conf, nm, nm.Logger(), nm.Metrics(), pcf...) 45 conf.Processors = nil 46 47 o, err := b.OutputInit(conf, nm) 48 if err != nil { 49 return nil, err 50 } 51 52 oEvents, ctr := summary.wOutputEvents(nm.Label()) 53 o = traceOutput(oEvents, ctr, o) 54 55 return output.WrapWithPipelines(o, pcf...) 56 }, spec) 57 } 58 59 return tracedEnv, summary 60 }