diff --git a/processor/transformprocessor/internal/metrics/func_extract_count_metric.go b/processor/transformprocessor/internal/metrics/func_extract_count_metric.go index 49c218f28c1a..314adf0afc24 100644 --- a/processor/transformprocessor/internal/metrics/func_extract_count_metric.go +++ b/processor/transformprocessor/internal/metrics/func_extract_count_metric.go @@ -13,12 +13,14 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlmetric" ) +const sumCountName = "extract_count_metric" + type extractCountMetricArguments struct { Monotonic bool } func newExtractCountMetricFactory() ottl.Factory[ottlmetric.TransformContext] { - return ottl.NewFactory("extract_count_metric", &extractCountMetricArguments{}, createExtractCountMetricFunction) + return ottl.NewFactory(sumCountName, &extractCountMetricArguments{}, createExtractCountMetricFunction) } func createExtractCountMetricFunction(_ ottl.FunctionContext, oArgs ottl.Arguments) (ottl.ExprFunc[ottlmetric.TransformContext], error) { @@ -34,11 +36,10 @@ func createExtractCountMetricFunction(_ ottl.FunctionContext, oArgs ottl.Argumen func extractCountMetric(monotonic bool) (ottl.ExprFunc[ottlmetric.TransformContext], error) { return func(_ context.Context, tCtx ottlmetric.TransformContext) (any, error) { metric := tCtx.GetMetric() - invalidMetricTypeError := fmt.Errorf("extract_count_metric requires an input metric of type Histogram, ExponentialHistogram or Summary, got %s", metric.Type()) aggTemp := getAggregationTemporality(metric) if aggTemp == pmetric.AggregationTemporalityUnspecified { - return nil, invalidMetricTypeError + return nil, invalidMetricTypeError(sumCountName, metric) } countMetric := pmetric.NewMetric() @@ -66,7 +67,7 @@ func extractCountMetric(monotonic bool) (ottl.ExprFunc[ottlmetric.TransformConte addCountDataPoint(dataPoints.At(i), countMetric.Sum().DataPoints()) } default: - return nil, invalidMetricTypeError + return nil, invalidMetricTypeError(sumCountName, metric) } if countMetric.Sum().DataPoints().Len() > 0 { diff --git a/processor/transformprocessor/internal/metrics/func_extract_sum_metric.go b/processor/transformprocessor/internal/metrics/func_extract_sum_metric.go index f002260944ac..6c7d621acba8 100644 --- a/processor/transformprocessor/internal/metrics/func_extract_sum_metric.go +++ b/processor/transformprocessor/internal/metrics/func_extract_sum_metric.go @@ -14,12 +14,14 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlmetric" ) +const sumFuncName = "extract_sum_metric" + type extractSumMetricArguments struct { Monotonic bool } func newExtractSumMetricFactory() ottl.Factory[ottlmetric.TransformContext] { - return ottl.NewFactory("extract_sum_metric", &extractSumMetricArguments{}, createExtractSumMetricFunction) + return ottl.NewFactory(sumFuncName, &extractSumMetricArguments{}, createExtractSumMetricFunction) } func createExtractSumMetricFunction(_ ottl.FunctionContext, oArgs ottl.Arguments) (ottl.ExprFunc[ottlmetric.TransformContext], error) { @@ -45,11 +47,9 @@ type SumCountDataPoint interface { func extractSumMetric(monotonic bool) (ottl.ExprFunc[ottlmetric.TransformContext], error) { return func(_ context.Context, tCtx ottlmetric.TransformContext) (any, error) { metric := tCtx.GetMetric() - invalidMetricTypeError := fmt.Errorf("extract_sum_metric requires an input metric of type Histogram, ExponentialHistogram or Summary, got %s", metric.Type()) - aggTemp := getAggregationTemporality(metric) if aggTemp == pmetric.AggregationTemporalityUnspecified { - return nil, invalidMetricTypeError + return nil, invalidMetricTypeError(sumFuncName, metric) } sumMetric := pmetric.NewMetric() @@ -83,7 +83,7 @@ func extractSumMetric(monotonic bool) (ottl.ExprFunc[ottlmetric.TransformContext addSumDataPoint(dataPoints.At(i), sumMetric.Sum().DataPoints()) } default: - return nil, invalidMetricTypeError + return nil, invalidMetricTypeError(sumFuncName, metric) } if sumMetric.Sum().DataPoints().Len() > 0 { @@ -116,3 +116,7 @@ func getAggregationTemporality(metric pmetric.Metric) pmetric.AggregationTempora return pmetric.AggregationTemporalityUnspecified } } + +func invalidMetricTypeError(name string, metric pmetric.Metric) error { + return fmt.Errorf("%s requires an input metric of type Histogram, ExponentialHistogram or Summary, got %s", name, metric.Type()) +}