Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .chloggen/enhancement_len_error_diagnostics.yaml
Original file line number Diff line number Diff line change
@@ -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"]
5 changes: 3 additions & 2 deletions pkg/ottl/ottlfuncs/func_len.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
}
}
Loading