-
Notifications
You must be signed in to change notification settings - Fork 3k
Labels
bugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needednever staleIssues marked with this label will be never staled and automatically removedIssues marked with this label will be never staled and automatically removedpkg/ottlpriority:p2MediumMedium
Description
I was just shown the scenario
set(resource.attributes["my.environment.2"], Split(resource.attributes["host.name"],"-")[1])
that produces an error:
{"kind": "processor", "name": "transform", "pipeline": "logs", "error": "type, []string, does not support int indexing", "statement": "set(resource.attributes[\"my.environment.2\"], Split(resource.attributes[\"host.name\"],\"-\")[1])"}
Although the language does support indexing the return value of the Converter, it only supports indexing pcommon.Slice
and []any
, but Split
returns a []string
. We need to make indexing slices more generic. This might need to be its own issue. Related code:
opentelemetry-collector-contrib/pkg/ottl/expression.go
Lines 98 to 112 in 60430e1
case k.Int != nil: | |
switch r := result.(type) { | |
case pcommon.Slice: | |
if int(*k.Int) >= r.Len() || int(*k.Int) < 0 { | |
return nil, fmt.Errorf("index %v out of bounds", *k.Int) | |
} | |
result = ottlcommon.GetValue(r.At(int(*k.Int))) | |
case []any: | |
if int(*k.Int) >= len(r) || int(*k.Int) < 0 { | |
return nil, fmt.Errorf("index %v out of bounds", *k.Int) | |
} | |
result = r[*k.Int] | |
default: | |
return nil, fmt.Errorf("type, %T, does not support int indexing", result) | |
} |
Originally posted by @TylerHelmuth in #26108 (comment)
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needednever staleIssues marked with this label will be never staled and automatically removedIssues marked with this label will be never staled and automatically removedpkg/ottlpriority:p2MediumMedium