Skip to content

Commit 95fdf1d

Browse files
committed
trace2: align 'time' field to Trace2 Event spec
The 'time' field of the GIT_TRACE2_EVENT json logs should be UTC, per the API specification [1]. Additionally, the timestamp "seconds" field should be reported out to 6 decimal places, with trailing zeroes. Update the internal logger's time encoder to match these requirements. [1] https://git-scm.com/docs/api-trace2#Documentation/technical/api-trace2.txt-codetimelttimegtcode Signed-off-by: Victoria Dye <[email protected]>
1 parent 2bee23e commit 95fdf1d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

internal/log/trace2.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const (
2626
// Global start time
2727
var globalStart = time.Now().UTC()
2828

29-
const trace2TimeFormat string = "2006-01-02T15:04:05.999999Z"
29+
const trace2TimeFormat string = "2006-01-02T15:04:05.000000Z"
3030

3131
type ctxKey int
3232

@@ -84,7 +84,7 @@ func createTrace2ZapLogger() *zap.Logger {
8484
loggerConfig.EncoderConfig.TimeKey = "time"
8585
loggerConfig.EncoderConfig.EncodeTime = zapcore.TimeEncoder(
8686
func(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
87-
enc.AppendString(t.Format(trace2TimeFormat))
87+
enc.AppendString(t.UTC().Format(trace2TimeFormat))
8888
},
8989
)
9090

0 commit comments

Comments
 (0)