MCPcopy Index your code
hub / github.com/coder/coder / Middleware

Function Middleware

agent/agentchat/log.go:56–72  ·  view source on GitHub ↗

Middleware tags agent logs for requests that originate from chatd. Agent log lines emitted while serving a request with Coder-Chat-Id, or by background work started by such a request, should include chat_id. Install after loggermw.Logger so access-log enrichment can run.

(next http.Handler)

Source from the content-addressed store, hash-verified

54// or by background work started by such a request, should include chat_id.
55// Install after loggermw.Logger so access-log enrichment can run.
56func Middleware(next http.Handler) http.Handler {
57 return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
58 chatID, ancestorIDs, ok := extractContext(r)
59 if !ok {
60 next.ServeHTTP(rw, r)
61 return
62 }
63
64 fields := chatFields(chatID, ancestorIDs)
65 if requestLogger := loggermw.RequestLoggerFromContext(r.Context()); requestLogger != nil {
66 requestLogger.WithFields(fields...)
67 }
68
69 ctx := WithContext(r.Context(), chatID, ancestorIDs)
70 next.ServeHTTP(rw, r.WithContext(ctx))
71 })
72}
73
74func chatFields(chatID uuid.UUID, ancestorIDs []uuid.UUID) []slog.Field {
75 fields := []slog.Field{slog.F("chat_id", chatID.String())}

Calls 8

RequestLoggerFromContextFunction · 0.92
extractContextFunction · 0.85
chatFieldsFunction · 0.85
WithContextFunction · 0.85
WithContextMethod · 0.80
ContextMethod · 0.65
WithFieldsMethod · 0.65
ServeHTTPMethod · 0.45