Skip to content

Commit 03d33d2

Browse files
samikshya-dbclaude
andcommitted
Add explanatory comments for immediate flush behavior
Clarify why connection events and terminal errors are flushed immediately: - Connection events: Must capture before connection closes - Terminal errors: May lead to termination, preventing future flushes Addresses review feedback on PR #320 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent ae00204 commit 03d33d2

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

telemetry/aggregator.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ func (agg *metricsAggregator) recordMetric(ctx context.Context, metric *telemetr
6464

6565
switch metric.metricType {
6666
case "connection":
67-
// Emit connection events immediately
67+
// Emit connection events immediately: connection lifecycle events must be captured
68+
// before the connection closes, as we won't have another opportunity to flush
6869
agg.batch = append(agg.batch, metric)
6970
if len(agg.batch) >= agg.batchSize {
7071
agg.flushUnlocked(ctx)
@@ -107,7 +108,8 @@ func (agg *metricsAggregator) recordMetric(ctx context.Context, metric *telemetr
107108
case "error":
108109
// Check if terminal error
109110
if metric.errorType != "" && isTerminalError(&simpleError{msg: metric.errorType}) {
110-
// Flush terminal errors immediately
111+
// Flush terminal errors immediately: terminal errors often lead to connection
112+
// termination. If we wait for the next batch/timer flush, this data may be lost
111113
agg.batch = append(agg.batch, metric)
112114
agg.flushUnlocked(ctx)
113115
} else {

0 commit comments

Comments
 (0)