Skip to content

Commit 575b234

Browse files
committed
chore: add client_ip, user_agent and response_size_bytes to slow client log
1 parent f5c9701 commit 575b234

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

intercept/eventstream/eventstream.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,13 @@ func (s *EventStream) Start(w http.ResponseWriter, r *http.Request) {
145145
return
146146
}
147147
if d := s.clk.Since(flushStart); d > SlowFlushThreshold {
148-
s.logger.Warn(ctx, "slow client detected", slog.F("flush_duration", d))
148+
clientIP, _, _ := net.SplitHostPort(r.RemoteAddr)
149+
s.logger.Warn(ctx, "slow client detected",
150+
slog.F("flush_duration", d),
151+
slog.F("client_ip", clientIP),
152+
slog.F("user_agent", r.Header.Get("User-Agent")),
153+
slog.F("response_size_bytes", len(ev)),
154+
)
149155
}
150156

151157
// Reset the timer once we've flushed some data to the stream, since it's already fresh.

intercept/eventstream/eventstream_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ func TestEventStream_LogsWarning_WhenFlushIsSlow(t *testing.T) {
5656

5757
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "/", nil)
5858
require.NoError(t, err)
59+
req.RemoteAddr = "192.0.2.1:12345"
60+
req.Header.Set("User-Agent", "test-agent/1.0")
5961

6062
done := make(chan struct{})
6163
go func() {
@@ -69,6 +71,9 @@ func TestEventStream_LogsWarning_WhenFlushIsSlow(t *testing.T) {
6971
<-done
7072

7173
require.Contains(t, buf.String(), "slow client detected")
74+
require.Contains(t, buf.String(), "192.0.2.1")
75+
require.Contains(t, buf.String(), "test-agent/1.0")
76+
require.Contains(t, buf.String(), "response_size_bytes=13")
7277
}
7378

7479
func TestEventStream_NoWarning_WhenFlushIsFast(t *testing.T) {

0 commit comments

Comments
 (0)