diff --git a/.chloggen/enhancement_len_error_diagnostics.yaml b/.chloggen/enhancement_len_error_diagnostics.yaml new file mode 100644 index 0000000000000..029a29b254bac --- /dev/null +++ b/.chloggen/enhancement_len_error_diagnostics.yaml @@ -0,0 +1,9 @@ +change_type: "enhancement" + +component: "pkg/ottl" + +note: "Improve unsupported type error diagnostics in the Len() OTTL function by including the runtime type in error messages." + +issues: [46476] + +change_logs: ["user"] \ No newline at end of file diff --git a/pkg/ottl/ottlfuncs/func_len.go b/pkg/ottl/ottlfuncs/func_len.go index e9c7c912aebb0..fed1868d78b23 100644 --- a/pkg/ottl/ottlfuncs/func_len.go +++ b/pkg/ottl/ottlfuncs/func_len.go @@ -6,6 +6,7 @@ package ottlfuncs // import "github.com/open-telemetry/opentelemetry-collector-c import ( "context" "errors" + "fmt" "reflect" "go.opentelemetry.io/collector/pdata/pcommon" @@ -55,7 +56,7 @@ func computeLen[K any](target ottl.Getter[K]) ottl.ExprFunc[K] { case pcommon.ValueTypeMap: return int64(valType.Map().Len()), nil } - return nil, errors.New(typeError) + return nil, fmt.Errorf("Len: unsupported target type %T. %s", val, typeError) case pcommon.Map: return int64(valType.Len()), nil case pcommon.Slice: @@ -105,6 +106,6 @@ func computeLen[K any](target ottl.Getter[K]) ottl.ExprFunc[K] { return int64(v.Len()), nil } - return nil, errors.New(typeError) + return nil, fmt.Errorf("Len: unsupported target type %T. %s", val, typeError) } }