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] Add ottlfuncs to support time.Second and time.Nanosecond #37042

Open
r0mdau opened this issue Jan 6, 2025 · 5 comments
Open

[pkg/ottl] Add ottlfuncs to support time.Second and time.Nanosecond #37042

r0mdau opened this issue Jan 6, 2025 · 5 comments
Labels
enhancement New feature or request pkg/ottl

Comments

@r0mdau
Copy link
Contributor

r0mdau commented Jan 6, 2025

Component(s)

pkg/ottl

Is your feature request related to a problem? Please describe.

Be able to add the current time generated by function Now() as a string in an attribute in a log context.

Example configuration:

  transform:
    error_mode: ignore
    log_statements:
      - context: log
        statements:
          - set(attributes["otelTime"], Format("%04d-%02d-%02dT%02d:%02d:%02d.%09d", [Year(Now()), Month(Now()), Day(Now()), Hour(Now()), Minute(Now()), Second(Now()), Nanosecond(Now())]))

Describe the solution you'd like

Create 2 new OTTL functions:

Describe alternatives you've considered

As an alternative, I am using the following configuration

          - set(attributes["eventForwarderTimestampUnixSeconds"], UnixSeconds(Now()))

But it does not help to have a custom string format like needed by some systems I work with.

Additional context

If this change is accepted, I would like to contribute.

@r0mdau r0mdau added enhancement New feature or request needs triage New item requiring triage labels Jan 6, 2025
Copy link
Contributor

github-actions bot commented Jan 6, 2025

Pinging code owners:

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

@edmocosta
Copy link
Contributor

Be able to add the current time generated by function Now() as a string in an attribute in a log context.

Hi @r0mdau, would #36870 solve this issue? It seems the goal is the same, supporting time formatting similar to https://pkg.go.dev/time#Time.Format.

@r0mdau
Copy link
Contributor Author

r0mdau commented Jan 7, 2025

Be able to add the current time generated by function Now() as a string in an attribute in a log context.

Hi @r0mdau, would #36870 solve this issue? It seems the goal is the same, supporting time formatting similar to https://pkg.go.dev/time#Time.Format.

Hi @edmocosta yes that would do the trick for my use case. In the other hand, why not implementing those 2 missing converters ?

ps: I have them working in an internal fork Second converter Nanosecond converter

@edmocosta
Copy link
Contributor

I agree with you, I think those converters might be useful. Let's wait for the code owners thoughts.

@TylerHelmuth
Copy link
Member

We definitely need to do #36870, but since we already have Minute, Day, Month, and Year we can also add Second and Nanosecond.

@TylerHelmuth TylerHelmuth removed the needs triage New item requiring triage label Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pkg/ottl
Projects
None yet
Development

No branches or pull requests

3 participants