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

OTTL Converter Slice Index #31482

Closed
fredyfredburger opened this issue Feb 28, 2024 · 3 comments
Closed

OTTL Converter Slice Index #31482

fredyfredburger opened this issue Feb 28, 2024 · 3 comments
Labels
bug Something isn't working needs triage New item requiring triage pkg/ottl

Comments

@fredyfredburger
Copy link

Component(s)

pkg/ottl

What happened?

Description

https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/ottl/LANGUAGE.md
Per this documentation it should be possible to do int referencing from the result of Slice(), but it is not because type []String does not support int indexing.

Steps to Reproduce

Below I am attempting to set application name by taking the body of a /var/log/messages log and indexing into the 5th value (assuming 0-base indexes)
set(resource.attributes["application_name"], Slice(body, " ")[4])

Expected Result

Since slice returns an array, I should be able to use an int to grab the nth value.

Actual Result

"type, []string, does not support int indexing"

Collector version

7ac560f

Environment information

Environment

OS: (Amazon Linux 2)
Compiler(if manually compiled): go 1.21.5

OpenTelemetry Collector configuration

receivers:
  filelog:
    include:
      - /var/log/messages
    include_file_name: true
    include_file_path: true
    operators:
      - type: syslog_parser
        protocol: rfc3164
processors:
  memory_limiter:
    check_interval: 1s
    limit_mib: 1000
    spike_limit_mib: 200
  batch:
  resourcedetection:
    detectors: [system]
    system:
      hostname_sources:
      resource_attributes:
        host.ip:
          enabled: true
  transform:
    error_mode: ignore
    log_statements:
      - context: log
        statements:
          - set(resource.attributes["application_name"], Split(body, " ")[4])
exporters:
  otlphttp:
    endpoint: https://localhost:8201
    headers:
      Authorization: "Bearer notsosecrettoken"
    tls:
      insecure_skip_verify: true
service:
  telemetry:
    metrics:
      level: none
  pipelines:
    logs:
      receivers: [filelog]
      processors: [transform, memory_limiter, resourcedetection, batch]
      exporters: [otlphttp]

Log output

2024-02-28T13:18:57.248Z        warn        ottl@v0.94.0/parser.go:273        failed to execute statement        {"kind": "processor", "name": "transform", "pipeline": "logs", "error": "type, []string, does not support int indexing", "statement": "set(resource.attributes[\"application_name\"], Split(body, \" \")[4])"}

Additional context

No response

@fredyfredburger fredyfredburger added bug Something isn't working needs triage New item requiring triage labels Feb 28, 2024
Copy link
Contributor

Pinging code owners:

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

@fredyfredburger
Copy link
Author

The documentation implies this is possible:
Split(field, ",")[1]

@TylerHelmuth
Copy link
Member

@fredyfredburger you are correct. OTTL currently has a limitation that it only knows how to index pcommon.Slice and []any. Since []any != []string, which is what Split returns, the indexing doesn't work.

See #29441 for more details. Closing this issue as a duplicate

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
Development

No branches or pull requests

2 participants