From 329db6234a4a3b2da898498fc1cd09751bf5119a Mon Sep 17 00:00:00 2001 From: Danny Kopping Date: Thu, 5 Mar 2026 13:01:56 +0000 Subject: [PATCH] fix: capture timestamps at AsyncRecorder call-time AsyncRecorder dispatches records asynchronously via goroutines. Previously, timestamps (CreatedAt/EndedAt) were not set before the goroutine launch, meaning the timestamp would reflect when the record was eventually persisted rather than when the event actually occurred. This captures timestamps at method call-time, before the goroutine is launched, ensuring they accurately reflect when the event happened regardless of async dispatch delays. --- recorder/recorder.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/recorder/recorder.go b/recorder/recorder.go index 3814488..4fbf21a 100644 --- a/recorder/recorder.go +++ b/recorder/recorder.go @@ -35,7 +35,7 @@ func (r *RecorderWrapper) RecordInterception(ctx context.Context, req *Intercept return fmt.Errorf("acquire client: %w", err) } - req.StartedAt = time.Now() + req.StartedAt = time.Now().UTC() if err = client.RecordInterception(ctx, req); err == nil { return nil } @@ -71,7 +71,7 @@ func (r *RecorderWrapper) RecordPromptUsage(ctx context.Context, req *PromptUsag return fmt.Errorf("acquire client: %w", err) } - req.CreatedAt = time.Now() + req.CreatedAt = time.Now().UTC() if err = client.RecordPromptUsage(ctx, req); err == nil { return nil } @@ -89,7 +89,7 @@ func (r *RecorderWrapper) RecordTokenUsage(ctx context.Context, req *TokenUsageR return fmt.Errorf("acquire client: %w", err) } - req.CreatedAt = time.Now() + req.CreatedAt = time.Now().UTC() if err = client.RecordTokenUsage(ctx, req); err == nil { return nil } @@ -107,7 +107,7 @@ func (r *RecorderWrapper) RecordToolUsage(ctx context.Context, req *ToolUsageRec return fmt.Errorf("acquire client: %w", err) } - req.CreatedAt = time.Now() + req.CreatedAt = time.Now().UTC() if err = client.RecordToolUsage(ctx, req); err == nil { return nil } @@ -165,6 +165,7 @@ func (a *AsyncRecorder) RecordInterception(ctx context.Context, req *Interceptio } func (a *AsyncRecorder) RecordInterceptionEnded(ctx context.Context, req *InterceptionRecordEnded) error { + req.EndedAt = time.Now().UTC() a.wg.Add(1) go func() { defer a.wg.Done() @@ -181,6 +182,7 @@ func (a *AsyncRecorder) RecordInterceptionEnded(ctx context.Context, req *Interc } func (a *AsyncRecorder) RecordPromptUsage(ctx context.Context, req *PromptUsageRecord) error { + req.CreatedAt = time.Now().UTC() a.wg.Add(1) go func() { defer a.wg.Done() @@ -201,6 +203,7 @@ func (a *AsyncRecorder) RecordPromptUsage(ctx context.Context, req *PromptUsageR } func (a *AsyncRecorder) RecordTokenUsage(ctx context.Context, req *TokenUsageRecord) error { + req.CreatedAt = time.Now().UTC() a.wg.Add(1) go func() { defer a.wg.Done() @@ -225,6 +228,7 @@ func (a *AsyncRecorder) RecordTokenUsage(ctx context.Context, req *TokenUsageRec } func (a *AsyncRecorder) RecordToolUsage(ctx context.Context, req *ToolUsageRecord) error { + req.CreatedAt = time.Now().UTC() a.wg.Add(1) go func() { defer a.wg.Done()