Description
Component(s)
pkg/ottl
What happened?
Description
Currently, it is not possible to pass a slice containing map literals to OTTL. This is because the mapGetter returns a pcommon.Map
instead of a map[string]any
:
opentelemetry-collector-contrib/pkg/ottl/expression.go
Lines 196 to 199 in 8034e0d
If a map literal then happens to be within a slice, eventually the pcommon.Slice.FromRaw()
method will be invoked, which however only can handle raw types for its elements: https://github.com/open-telemetry/opentelemetry-collector/blob/6740a28a8003a534c20c2608d760edd015657622/pdata/pcommon/value.go#L134-L178
Steps to Reproduce
Start the collector with the following config:
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
processors:
transform:
error_mode: ignore
trace_statements:
- context: span
statements:
- set(attributes["test"], {"list":[{"foo":"bar"}]})
exporters:
debug:
verbosity: detailed
service:
pipelines:
traces:
receivers: [otlp]
processors: [transform]
exporters: [debug]
And send some test data to it, e.g. with telemetrygen
:
telemetrygen traces --otlp-insecure --traces 1 --status-code Ok --span-duration 1s
Expected Result
The test
attribute should be added to the span
Actual Result
The attribute is not added, due to the following error logged by the collector:
ottl/parser.go:365 failed to execute statement {"kind": "processor", "name": "transform", "pipeline": "traces", "error": "<Invalid value type pcommon.Map>", "statement": "set(attributes[\"test\"], {\"list\":[{\"foo\":\"bar\"}]})"}
Collector version
v0.117.0
Environment information
Environment
OS: macOS
Compiler(if manually compiled): go 1.22
OpenTelemetry Collector configuration
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
processors:
transform:
error_mode: ignore
trace_statements:
- context: span
statements:
- set(attributes["test"], {"list":[{"foo":"bar"}]})
exporters:
debug:
verbosity: detailed
service:
pipelines:
traces:
receivers: [otlp]
processors: [transform]
exporters: [debug]
Log output
Additional context
I already have a draft for a fix ready that I can provide