Skip to content

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

Closed
@r0mdau

Description

@r0mdau

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions