Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pkg/ottl] Map literals within slices can not be parsed #37405

Open
bacherfl opened this issue Jan 22, 2025 · 1 comment · May be fixed by #37408
Open

[pkg/ottl] Map literals within slices can not be parsed #37405

bacherfl opened this issue Jan 22, 2025 · 1 comment · May be fixed by #37408
Assignees
Labels
bug Something isn't working needs triage New item requiring triage pkg/ottl

Comments

@bacherfl
Copy link
Contributor

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:

result := pcommon.NewMap()
if err := result.FromRaw(evaluated); err != nil {
return nil, err
}

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

@bacherfl bacherfl added bug Something isn't working needs triage New item requiring triage labels Jan 22, 2025
@bacherfl bacherfl self-assigned this Jan 22, 2025
Copy link
Contributor

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage New item requiring triage pkg/ottl
Projects
None yet
1 participant