Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

feat: added status code of api calls

Ankit Nayan961dc7e814bc
diff --git a/pkg/query-service/app/server.go b/pkg/query-service/app/server.go
index 054c8113c7..8399e543d3 100644
--- a/pkg/query-service/app/server.go
+++ b/pkg/query-service/app/server.go
@@ -159,18 +159,36 @@ func loggingMiddleware(next http.Handler) http.Handler {
})
}
+type loggingResponseWriter struct {
+ http.ResponseWriter
+ statusCode int
+}
+
+func NewLoggingResponseWriter(w http.ResponseWriter) *loggingResponseWriter {
+ // WriteHeader(int) is not called if our response implicitly returns 200 OK, so
+ // we default to that status code.
+ return &loggingResponseWriter{w, http.StatusOK}
+}
+
+func (lrw *loggingResponseWriter) WriteHeader(code int) {
+ lrw.statusCode = code
+ lrw.ResponseWriter.WriteHeader(code)
+}
+
func (s *Server) analyticsMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
route := mux.CurrentRoute(r)
path, _ := route.GetPathTemplate()
- data := map[string]interface{}{"path": path}
+ lrw := NewLoggingResponseWriter(w)
+ next.ServeHTTP(lrw, r)
+
+ data := map[string]interface{}{"path": path, "statusCode": lrw.statusCode}
if _, ok := telemetry.IgnoredPaths()[path]; !ok {
telemetry.GetInstance().SendEvent(telemetry.TELEMETRY_EVENT_PATH, data)
}
- next.ServeHTTP(w, r)
})
}