log-session-id-at-sessionid #251
@ -28,7 +28,7 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	logg           = logging.NewVanilla().WithDomain("ussdmenuhandler").WithContextKey("session-id")
 | 
			
		||||
	logg           = logging.NewVanilla().WithDomain("ussdmenuhandler").WithContextKey("SessionId")
 | 
			
		||||
	scriptDir      = path.Join("services", "registration")
 | 
			
		||||
	translationDir = path.Join(scriptDir, "locale")
 | 
			
		||||
)
 | 
			
		||||
@ -124,7 +124,7 @@ func (h *Handlers) Init(ctx context.Context, sym string, input []byte) (resource
 | 
			
		||||
 | 
			
		||||
	sessionId, ok := ctx.Value("SessionId").(string)
 | 
			
		||||
	if ok {
 | 
			
		||||
		context.WithValue(ctx, "session-id", sessionId)
 | 
			
		||||
		ctx = context.WithValue(ctx, "SessionId", sessionId)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	flag_admin_privilege, _ := h.flagManager.GetFlag("flag_admin_privilege")
 | 
			
		||||
 | 
			
		||||
@ -15,16 +15,14 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type ATRequestParser struct {
 | 
			
		||||
	Context context.Context
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (arp *ATRequestParser) GetSessionId(rq any) (string, error) {
 | 
			
		||||
func (arp *ATRequestParser) GetSessionId(ctx context.Context, rq any) (string, error) {
 | 
			
		||||
	rqv, ok := rq.(*http.Request)
 | 
			
		||||
	if !ok {
 | 
			
		||||
		logg.Warnf("got an invalid request", "req", rq)
 | 
			
		||||
		return "", handlers.ErrInvalidRequest
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Capture body (if any) for logging
 | 
			
		||||
	body, err := io.ReadAll(rqv.Body)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@ -43,9 +41,9 @@ func (arp *ATRequestParser) GetSessionId(rq any) (string, error) {
 | 
			
		||||
		decodedStr := string(logBytes)
 | 
			
		||||
		sessionId, err := extractATSessionId(decodedStr)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			context.WithValue(arp.Context, "at-session-id", sessionId)
 | 
			
		||||
			ctx = context.WithValue(ctx, "AT-SessionId", sessionId)
 | 
			
		||||
		}
 | 
			
		||||
		logg.Debugf("Received request:", decodedStr)
 | 
			
		||||
		logg.DebugCtxf(ctx, "Received request:", decodedStr)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if err := rqv.ParseForm(); err != nil {
 | 
			
		||||
 | 
			
		||||
@ -10,7 +10,7 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	logg = logging.NewVanilla().WithDomain("atserver")
 | 
			
		||||
	logg = logging.NewVanilla().WithDomain("atserver").WithContextKey("AT-SessionId")
 | 
			
		||||
| 
					
	
	
	
	
	
	
	
	 | 
			||||
)
 | 
			
		||||
 | 
			
		||||
type ATSessionHandler struct {
 | 
			
		||||
@ -34,7 +34,7 @@ func (ash *ATSessionHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)
 | 
			
		||||
 | 
			
		||||
	rp := ash.GetRequestParser()
 | 
			
		||||
	cfg := ash.GetConfig()
 | 
			
		||||
	cfg.SessionId, err = rp.GetSessionId(req)
 | 
			
		||||
	cfg.SessionId, err = rp.GetSessionId(req.Context(), req)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		logg.ErrorCtxf(rqs.Ctx, "", "header processing error", err)
 | 
			
		||||
		ash.WriteError(w, 400, err)
 | 
			
		||||
@ -48,7 +48,7 @@ func (ash *ATSessionHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	rqs, err = ash.Process(rqs) 
 | 
			
		||||
	rqs, err = ash.Process(rqs)
 | 
			
		||||
	switch err {
 | 
			
		||||
	case nil: // set code to 200 if no err
 | 
			
		||||
		code = 200
 | 
			
		||||
 | 
			
		||||
@ -10,7 +10,7 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	logg = logging.NewVanilla().WithDomain("httpserver")
 | 
			
		||||
	logg = logging.NewVanilla().WithDomain("httpserver").WithContextKey("at-session-id")
 | 
			
		||||
| 
					
	
	
	
	
	
	
	
	 
				
					
						lash
						commented  
			
		And then this is wrong.. And then this is wrong.. 
			
			
		 | 
			||||
)
 | 
			
		||||
 | 
			
		||||
type SessionHandler struct {
 | 
			
		||||
@ -46,7 +46,7 @@ func (f *SessionHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
 | 
			
		||||
 | 
			
		||||
	rp := f.GetRequestParser()
 | 
			
		||||
	cfg := f.GetConfig()
 | 
			
		||||
	cfg.SessionId, err = rp.GetSessionId(req)
 | 
			
		||||
	cfg.SessionId, err = rp.GetSessionId(req.Context(), req)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		logg.ErrorCtxf(rqs.Ctx, "", "header processing error", err)
 | 
			
		||||
		f.WriteError(w, 400, err)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	
We will need both SessionId and AT-Sessionid in the AT part, otherwise SessionId will not be logged.