@@ -2,16 +2,11 @@ package middleware
22
33import (
44 "bytes"
5- "context"
65 "log/slog"
76 "net"
87 "net/http"
9- "net/url"
10- "strings"
118 "time"
129
13- "github.com/SigNoz/signoz/pkg/query-service/common"
14- "github.com/SigNoz/signoz/pkg/types/authtypes"
1510 "github.com/gorilla/mux"
1611 semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
1712)
@@ -55,9 +50,6 @@ func (middleware *Logging) Wrap(next http.Handler) http.Handler {
5550 string (semconv .HTTPRouteKey ), path ,
5651 }
5752
58- logCommentKVs := middleware .getLogCommentKVs (req )
59- req = req .WithContext (context .WithValue (req .Context (), common .LogCommentKey , logCommentKVs ))
60-
6153 badResponseBuffer := new (bytes.Buffer )
6254 writer := newBadResponseLoggingWriter (rw , badResponseBuffer )
6355 next .ServeHTTP (writer , req )
@@ -85,67 +77,3 @@ func (middleware *Logging) Wrap(next http.Handler) http.Handler {
8577 }
8678 })
8779}
88-
89- func (middleware * Logging ) getLogCommentKVs (r * http.Request ) map [string ]string {
90- referrer := r .Header .Get ("Referer" )
91-
92- var path , dashboardID , alertID , page , client , viewName , tab string
93-
94- if referrer != "" {
95- referrerURL , _ := url .Parse (referrer )
96- client = "browser"
97- path = referrerURL .Path
98-
99- if strings .Contains (path , "/dashboard" ) {
100- // Split the path into segments
101- pathSegments := strings .Split (referrerURL .Path , "/" )
102- // The dashboard ID should be the segment after "/dashboard/"
103- // Loop through pathSegments to find "dashboard" and then take the next segment as the ID
104- for i , segment := range pathSegments {
105- if segment == "dashboard" && i < len (pathSegments )- 1 {
106- // Return the next segment, which should be the dashboard ID
107- dashboardID = pathSegments [i + 1 ]
108- }
109- }
110- page = "dashboards"
111- } else if strings .Contains (path , "/alerts" ) {
112- urlParams := referrerURL .Query ()
113- alertID = urlParams .Get ("ruleId" )
114- page = "alerts"
115- } else if strings .Contains (path , "logs" ) && strings .Contains (path , "explorer" ) {
116- page = "logs-explorer"
117- viewName = referrerURL .Query ().Get ("viewName" )
118- } else if strings .Contains (path , "/trace" ) || strings .Contains (path , "traces-explorer" ) {
119- page = "traces-explorer"
120- viewName = referrerURL .Query ().Get ("viewName" )
121- } else if strings .Contains (path , "/services" ) {
122- page = "services"
123- tab = referrerURL .Query ().Get ("tab" )
124- if tab == "" {
125- tab = "OVER_METRICS"
126- }
127- } else if strings .Contains (path , "/metrics" ) {
128- page = "metrics-explorer"
129- }
130- } else {
131- client = "api"
132- }
133-
134- var email string
135- claims , err := authtypes .ClaimsFromContext (r .Context ())
136- if err == nil {
137- email = claims .Email
138- }
139-
140- kvs := map [string ]string {
141- "path" : path ,
142- "dashboardID" : dashboardID ,
143- "alertID" : alertID ,
144- "source" : page ,
145- "client" : client ,
146- "viewName" : viewName ,
147- "servicesTab" : tab ,
148- "email" : email ,
149- }
150- return kvs
151- }
0 commit comments