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]: func_replace_all_patterns does not work with log body string #35681

Closed
jsirianni opened this issue Oct 8, 2024 · 2 comments
Closed
Labels
bug Something isn't working needs triage New item requiring triage pkg/ottl

Comments

@jsirianni
Copy link
Member

Component(s)

No response

What happened?

Description

Log bodies can be a string or a map. The func_replace_all_patterns works when body is a map, but does not work when body is a string.

Steps to Reproduce

Configure the collector to read a log file without parsing. This will result in a string body.

Use the Transform processor + replace_all_patterns to replace a sub string. In my example, I have an escaped json string that I want to remove the \ from. {\"key\":\"value\"} --> {"key":"value"}.

transform/remove-escape:
  error_mode: ignore
  log_statements:
    - context: log
      statements:
        - replace_all_patterns(body, "value", "\\\\", "")

Expected Result

Because body can be a string, I would expect ottl functions to support them.

Actual Result

It works if my log message is at body.message but does not work if it is at body (string).

Alternatives Considered

I wrote an ottl function that wraps strings.ReplaceAll(). It supports the operation I am performing. I suspect this function would not be accepted as it overlaps with replace_all_patterns.

Collector version

v0.111.0

Environment information

Environment

OS: Debian 12
Compiler: Go 1.22.6

OpenTelemetry Collector configuration

No response

Log output

No response

Additional context

No response

@jsirianni jsirianni added bug Something isn't working needs triage New item requiring triage labels Oct 8, 2024
Copy link
Contributor

github-actions bot commented Oct 8, 2024

Pinging code owners:

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

@TylerHelmuth
Copy link
Member

TylerHelmuth commented Oct 8, 2024

The func_replace_all_patterns works when body is a map, but does not work when body is a string.

Yes, this is by design. If you want to replace the the characters in a single string use replace_pattern

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