diff --git a/session.go b/session.go index 709c81f0..7e8b19cb 100644 --- a/session.go +++ b/session.go @@ -100,8 +100,17 @@ func newSessionID() string { } func newSession(engine *Engine) *Session { + var ctx context.Context + var sessionID string + if engine.logSessionID { + sessionID = newSessionID() + ctx = context.WithValue(engine.defaultContext, log.SessionIDKey, sessionID) + } else { + ctx = engine.defaultContext + } + session := &Session{ - ctx: engine.defaultContext, + ctx: ctx, engine: engine, tx: nil, statement: statements.NewStatement( @@ -130,7 +139,7 @@ func newSession(engine *Engine) *Session { sessionType: engineSession, } if engine.logSessionID { - session.ctx = context.WithValue(session.ctx, log.SessionIDKey, session) + session.ctx = context.WithValue(session.ctx, sessionID, session) } return session }