Skip to content

[pkg/ottl] OTTL Base64Encode function#46075

Merged
atoulme merged 4 commits intoopen-telemetry:mainfrom
alexcams:create-base64encode-function
Feb 23, 2026
Merged

[pkg/ottl] OTTL Base64Encode function#46075
atoulme merged 4 commits intoopen-telemetry:mainfrom
alexcams:create-base64encode-function

Conversation

@alexcams
Copy link
Copy Markdown
Contributor

@alexcams alexcams commented Feb 13, 2026

Description

Add Base64Encode OTTL converter function to encode strings into base64 format with support for multiple variants (base64, base64-raw, base64-url, base64-raw-url). This function addresses the need to handle characters not allowed by certain exporters like NATS Core.

Link to tracking issue

Fixes #46071

Testing

Tested manually and added unit and e2e tests.
Test config:

processors:
  transform:
    log_statements:
      - context: log
        statements:
          - set(attributes["encoded_default"], Base64Encode(attributes["plain_text"]))
          
          - set(attributes["encoded_base64_raw"], Base64Encode(attributes["plain_text"], "base64-raw"))
          
          - set(attributes["encoded_base64_url"], Base64Encode(attributes["plain_text"], "base64-url"))
          
          - set(attributes["encoded_base64_raw_url"], Base64Encode(attributes["plain_text"], "base64-raw-url"))

Test input:

{"plain_text": "test string"}
{"plain_text": "hello world"}
{"plain_text": "special chars: @#$%"}
{"plain_text": "URL encoding test: https://example.com?param=value&other=123"}

Test result:

LogRecord #0
Body: Str({"plain_text": "test string"})
Attributes:
     -> log.file.name: Str(test_data.log)
     -> plain_text: Str(test string)
     -> encoded_default: Str(dGVzdCBzdHJpbmc=)
     -> encoded_base64_raw: Str(dGVzdCBzdHJpbmc)
     -> encoded_base64_url: Str(dGVzdCBzdHJpbmc=)
     -> encoded_base64_raw_url: Str(dGVzdCBzdHJpbmc)
LogRecord #1
Body: Str({"plain_text": "hello world"})
Attributes:
     -> log.file.name: Str(test_data.log)
     -> plain_text: Str(hello world)
     -> encoded_default: Str(aGVsbG8gd29ybGQ=)
     -> encoded_base64_raw: Str(aGVsbG8gd29ybGQ)
     -> encoded_base64_url: Str(aGVsbG8gd29ybGQ=)
     -> encoded_base64_raw_url: Str(aGVsbG8gd29ybGQ)
LogRecord #2
Body: Str({"plain_text": "special chars: @#$%"})
Attributes:
     -> log.file.name: Str(test_data.log)
     -> plain_text: Str(special chars: @#$%)
     -> encoded_default: Str(c3BlY2lhbCBjaGFyczogQCMkJQ==)
     -> encoded_base64_raw: Str(c3BlY2lhbCBjaGFyczogQCMkJQ)
     -> encoded_base64_url: Str(c3BlY2lhbCBjaGFyczogQCMkJQ==)
     -> encoded_base64_raw_url: Str(c3BlY2lhbCBjaGFyczogQCMkJQ)
LogRecord #3
Body: Str({"plain_text": "URL encoding test: https://example.com?param=value&other=123"})
Attributes:
     -> log.file.name: Str(test_data.log)
     -> plain_text: Str(URL encoding test: https://example.com?param=value&other=123)
     -> encoded_default: Str(VVJMIGVuY29kaW5nIHRlc3Q6IGh0dHBzOi8vZXhhbXBsZS5jb20/cGFyYW09dmFsdWUmb3RoZXI9MTIz)
     -> encoded_base64_raw: Str(VVJMIGVuY29kaW5nIHRlc3Q6IGh0dHBzOi8vZXhhbXBsZS5jb20/cGFyYW09dmFsdWUmb3RoZXI9MTIz)
     -> encoded_base64_url: Str(VVJMIGVuY29kaW5nIHRlc3Q6IGh0dHBzOi8vZXhhbXBsZS5jb20_cGFyYW09dmFsdWUmb3RoZXI9MTIz)
     -> encoded_base64_raw_url: Str(VVJMIGVuY29kaW5nIHRlc3Q6IGh0dHBzOi8vZXhhbXBsZS5jb20_cGFyYW09dmFsdWUmb3RoZXI9MTIz)

Documentation

Updated README.md with function documentation, usage examples, and supported variants.

@alexcams
Copy link
Copy Markdown
Contributor Author

/rerun

@alexcams alexcams marked this pull request as draft February 16, 2026 09:20
@alexcams alexcams marked this pull request as ready for review February 16, 2026 09:28
@alexcams alexcams force-pushed the create-base64encode-function branch from ca541d7 to 537d59f Compare February 16, 2026 09:59
@alexcams
Copy link
Copy Markdown
Contributor Author

/rerun

Comment thread pkg/ottl/ottlfuncs/func_base64encode.go Outdated
Comment thread pkg/ottl/ottlfuncs/func_base64encode.go Outdated
Comment thread pkg/ottl/ottlfuncs/func_base64encode_test.go Outdated
Comment thread pkg/ottl/ottlfuncs/func_base64encode_test.go Outdated
@alexcams alexcams force-pushed the create-base64encode-function branch from 537d59f to a2bd9e6 Compare February 19, 2026 14:06
@edmocosta
Copy link
Copy Markdown
Contributor

Hi @alexcams, could you please address the lint issues and re-request review when it's done? Thanks!

@alexcams alexcams force-pushed the create-base64encode-function branch from a2bd9e6 to 55d1f5c Compare February 19, 2026 16:02
@alexcams
Copy link
Copy Markdown
Contributor Author

/rerun

@alexcams alexcams requested a review from edmocosta February 19, 2026 16:38
@atoulme atoulme merged commit 6f65082 into open-telemetry:main Feb 23, 2026
197 checks passed
@otelbot
Copy link
Copy Markdown
Contributor

otelbot bot commented Feb 23, 2026

Thank you for your contribution @alexcams! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey. If you are getting started contributing, you can also join the CNCF Slack channel #opentelemetry-new-contributors to ask for guidance and get help.

@agardnerIT
Copy link
Copy Markdown
Contributor

Hi all. Nothing to do with the functionality of this PR but I thought I'd mention (here in context) a pain point in relation to finding which release this PR takes effect in.

It'd be great for each PR to have a tag saying "first available in collector version X.Y.Z".

This would also help AIs detect when people think there's a bug (feature X doesn't work) the AI could say "please run otelcol-contrib --version and provide the output" then "ahh you're using X.Y.Z and this functionality isn't available until version Z.Y.X"

For example, I know that this was merged 5 days ago. Now I need to jump to the releases repo and check when the last collector release was ("last week"). OK so maybe I'm in luck because 5 days could be "last week". I download 0.146.0 and it doesn't seem to have this. Looking at the release notes I don't see it, so I assume I just need to wait?

@edmocosta
Copy link
Copy Markdown
Contributor

Hi @agardnerIT, thanks for the feedback, that's a fair request, and I agree those labels could be very helpful. Please feel free to open an issue and bring this topic into discussion. Regarding this specific OTTL feature, it was merged after v0.146.0 was released, so it will only be available on next release (v0.147.0), which BTW is today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[pkg/ottl] OTTL Base64Encode function

5 participants