register metrics only if the prometheus Registry is initialized
@@ -199,12 +199,14 @@ func (c *Collector) InitOutput(ctx context.Context, name string) {
c.logger.Printf("starting output type %s", outType)
if initializer, ok := outputs.Outputs[outType.(string)]; ok {
out := initializer()
+ if c.reg != nil {
for _, m := range out.Metrics() {
err := c.reg.Register(m)
if err != nil {
c.logger.Printf("failed to register output '%s' metric : %v", name, err)
}
}
+ }
go out.Init(ctx, cfg, c.logger)
c.Outputs[name] = out
}
