From 371b9887fbedd0d30797116da5c12c59c9d37219 Mon Sep 17 00:00:00 2001 From: Sebastian Rothbucher Date: Wed, 14 Aug 2024 15:48:44 +0200 Subject: [PATCH] fix(serializers.template): Unwrap metrics if required (#15740) --- plugins/serializers/template/template.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/serializers/template/template.go b/plugins/serializers/template/template.go index a734c43839d2d..0527fd4a9ba20 100644 --- a/plugins/serializers/template/template.go +++ b/plugins/serializers/template/template.go @@ -39,9 +39,13 @@ func (s *Serializer) Init() error { } func (s *Serializer) Serialize(metric telegraf.Metric) ([]byte, error) { - m, ok := metric.(telegraf.TemplateMetric) + metricPlain := metric + if wm, ok := metric.(telegraf.UnwrappableMetric); ok { + metricPlain = wm.Unwrap() + } + m, ok := metricPlain.(telegraf.TemplateMetric) if !ok { - s.Log.Errorf("metric of type %T is not a template metric", metric) + s.Log.Errorf("metric of type %T is not a template metric", metricPlain) return nil, nil } var b bytes.Buffer