open-telemetry / opentelemetry-collector-contrib

Contrib repository for the OpenTelemetry Collector
https://opentelemetry.io
Apache License 2.0
3.07k stars 2.37k forks source link

set always uses UTC #34161

Open agardnerIT opened 3 months ago

agardnerIT commented 3 months ago

Component(s)

processor/transform

What happened?

Description

Opening at the request of @TylerHelmuth as per this Slack thread.

I'm using set(time, Now()) in the transform processor but it's setting time to UTC (+0000) while my system time is +1000

Steps to Reproduce

Expected Result

The transform processor / OTTL should either:

  1. Respect system time
  2. Have the ability to set a timezone eg. set(time, Now().Timezone("AEST")

Actual Result

Collector version

v0.103.0

Environment information

Environment

OS: (e.g., "Ubuntu 20.04") Compiler(if manually compiled): (e.g., "go 14.2")

OpenTelemetry Collector configuration

...
processors:
  transform/add_timestamp:
    log_statements:
      - context: log
        statements:
          - set(observed_time, Now())
          - set(time, Now())
...

Log output

No response

Additional context

No response

github-actions[bot] commented 3 months ago

Pinging code owners:

github-actions[bot] commented 3 months ago

Pinging code owners for pkg/ottl: @TylerHelmuth @kentquirk @bogdandrutu @evan-bradley. See Adding Labels via Comments if you do not have permissions to add labels yourself.

TylerHelmuth commented 3 months ago

This is happening because all our time setters, such as https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/d865b6e7c113dcad1cbb3259eb7cb08855a48fb7/pkg/ottl/contexts/ottllog/log.go#L326, use pcommon.NewTimeStampFromTime which uses the UTC value of the time.

TylerHelmuth commented 3 months ago

@agardnerIT can you confirm that the UTC representation of the time.Time value is the correct UTC value for your local time?

agardnerIT commented 3 months ago

I'm not really sure I follow you but my system clock right now is 20:04 and time.is/UTC says 10:04

Output from a few seconds ago (so that tallies):

ObservedTimestamp: 2024-07-19 10:03:47.556182 +0000 UTC
Timestamp: 2024-07-19 10:03:47.55651 +0000 UTC
github-actions[bot] commented 1 month ago

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

Pinging code owners:

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