From f362e325bf569f60e778733a74b86de724804633 Mon Sep 17 00:00:00 2001 From: Jacquin Antoine Date: Fri, 27 Feb 2026 00:20:40 +0100 Subject: [PATCH] feat(api): add timestamp field to LogRecord - Add Timestamp field (int64, nanoseconds since Unix epoch) to LogRecord - Import time package in api/types.go - Set timestamp using time.Now().UnixNano() in NewLogRecord() - Add test assertion to verify timestamp is set The timestamp is now included in all JSON log outputs Co-authored-by: Qwen-Coder --- api/types.go | 6 ++++++ api/types_test.go | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/api/types.go b/api/types.go index 7ae85bc..d455903 100644 --- a/api/types.go +++ b/api/types.go @@ -1,5 +1,7 @@ package api +import "time" + // ServiceLog represents internal service logging for diagnostics type ServiceLog struct { Level string `json:"level"` @@ -85,6 +87,9 @@ type LogRecord struct { JA4Hash string `json:"ja4_hash"` JA3 string `json:"ja3,omitempty"` JA3Hash string `json:"ja3_hash,omitempty"` + + // Timestamp in nanoseconds since Unix epoch + Timestamp int64 `json:"timestamp"` } // OutputConfig defines configuration for a single log output @@ -212,6 +217,7 @@ func NewLogRecord(ch TLSClientHello, fp *Fingerprints) LogRecord { TCPMSS: mssPtr, TCPWScale: wScalePtr, TCPOptions: opts, + Timestamp: time.Now().UnixNano(), } if fp != nil { diff --git a/api/types_test.go b/api/types_test.go index fc3e7c3..25d4b98 100644 --- a/api/types_test.go +++ b/api/types_test.go @@ -91,6 +91,11 @@ func TestNewLogRecord(t *testing.T) { t.Run(tt.name, func(t *testing.T) { rec := NewLogRecord(tt.clientHello, tt.fingerprints) + // Verify timestamp is set + if rec.Timestamp == 0 { + t.Error("Timestamp should be set") + } + // Verify basic fields if rec.SrcIP != tt.clientHello.SrcIP { t.Errorf("SrcIP = %v, want %v", rec.SrcIP, tt.clientHello.SrcIP)