open-telemetry / opentelemetry-collector-contrib

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

[pkg/ottl] Improve Time converter error messages #35176

Open edmocosta opened 1 month ago

edmocosta commented 1 month ago

Component(s)

pkg/ottl

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

The Time converter errors messages currently refer to the Go's layout elements instead of the ctime-like substitutes. It might be confusing for users not familiar with the Go layout and/or non-developers.

For example, when converter Time(attributes["time.attribute"], "%B %g %A, %Y, %r") receives the value Invalid 25 Thursday, 1993, 02:03:04 pm , it results into the following error:

parsing time "Invalid 25 Thursday, 1993, 02:03:04 pm" as "January 2 Monday, 2006, 03:04:05 pm": cannot parse "Invalid 25 Thursday, 1993, 02:03:04 pm" as "January"

IMO, there's no clear relation between the Time configured format and the error message details.

Describe the solution you'd like

Considering the ctime-like directives are first citizens for the Time converter format, reflecting those delimiters on the errors message would be helpful for users. For example, the above error message could be changed to something like:

parsing time "Invalid 25 Thursday, 1993, 02:03:04 pm" as "%B %g %A, %Y, %r": cannot parse "Invalid 25 Thursday, 1993, 02:03:04 pm" as "%B"

The Go's time.ParseError does provide all necessary pieces to build the message like that, so the change could be proxying the standard parse functions errors and provide customised messages.

type ParseError struct {
    Layout     string
    Value      string
    LayoutElem string
    ValueElem  string
    Message    string
}

Describe alternatives you've considered

No response

Additional context

No response

github-actions[bot] commented 1 month ago

Pinging code owners: