Loading
fix: Converts time to use rfc3339 w/ 3 precision on json logs
This converts time and datetime values to strings to enforce the RFC3339 format.
According to Elastic and Opensearch documentation, formatted date strings will be automatically parsed as a date, unless a different pattern is enforced.
Part of https://gitlab.com/gitlab-com/gl-infra/gitlab-dedicated/incident-management/-/issues/2448.
The format_message method in lib/labkit/logging/json_logger.rb was wrongly calling format_time! on data rather than in message payload. This behavior can be seen below:
[2] pry(#<Labkit::Logging::JsonLogger>)> message
=> {"checkpoint"=>"start",
"user_experience_id"=>"create_merge_request",
"feature_category"=>"code_review_workflow",
"urgency"=>"async_fast",
"start_time"=>2026-01-13 17:36:45.893111 UTC,
"elapsed_time_s"=>0.0,
"urgency_threshold_s"=>15}
[3] pry(#<Labkit::Logging::JsonLogger>)> format_time!(data)
=> {:severity=>"INFO", :time=>"2026-01-13T17:36:53.611Z"}
[4] pry(#<Labkit::Logging::JsonLogger>)> message
=> {"checkpoint"=>"start",
"user_experience_id"=>"create_merge_request",
"feature_category"=>"code_review_workflow",
"urgency"=>"async_fast",
"start_time"=>2026-01-13 17:36:45.893111 UTC,
"elapsed_time_s"=>0.0,
"urgency_threshold_s"=>15}
[5] pry(#<Labkit::Logging::JsonLogger>)> data
=> {:severity=>"INFO", :time=>"2026-01-13T17:36:53.611Z"}
[6] pry(#<Labkit::Logging::JsonLogger>)> message
=> {"checkpoint"=>"start",
"user_experience_id"=>"create_merge_request",
"feature_category"=>"code_review_workflow",
"urgency"=>"async_fast",
"start_time"=>2026-01-13 17:36:45.893111 UTC,
"elapsed_time_s"=>0.0,
"urgency_threshold_s"=>15}
[7] pry(#<Labkit::Logging::JsonLogger>)> format_time!(message)
=> {"checkpoint"=>"start",
"user_experience_id"=>"create_merge_request",
"feature_category"=>"code_review_workflow",
"urgency"=>"async_fast",
"start_time"=>"2026-01-13T17:36:45.893Z",
"elapsed_time_s"=>0.0,
"urgency_threshold_s"=>15}
Now this is fixed and specs are properly covering the method call accordingly.
Edited by Hercules Merscher