@@ -62,7 +62,7 @@ func newClient(
6262 builder SessionBuilder ,
6363 config config.Config ,
6464) * client {
65- onDone := trace .TableOnInit (config .Trace (). Compose ( trace . ContextTable ( ctx )) , & ctx )
65+ onDone := trace .TableOnInit (config .Trace (), & ctx )
6666 if builder == nil {
6767 builder = func (ctx context.Context ) (s Session , err error ) {
6868 return newSession (ctx , cc , config )
@@ -213,7 +213,7 @@ func (c *client) createSession(ctx context.Context) (s Session, err error) {
213213 c .config .CreateSessionTimeout (),
214214 )
215215
216- onDone := trace .TableOnPoolSessionNew (c .config .Trace (). Compose ( trace . ContextTable ( ctx )) , & ctx )
216+ onDone := trace .TableOnPoolSessionNew (c .config .Trace (), & ctx )
217217
218218 defer func () {
219219 onDone (s , err )
@@ -285,15 +285,28 @@ func (c *client) createSession(ctx context.Context) (s Session, err error) {
285285 }
286286}
287287
288- // Get returns first idle session from the client and removes it from
289- // there. If no items stored in client it creates new one returns it.
290- func (c * client ) Get (ctx context.Context ) (s Session , err error ) {
288+ type getOptions struct {
289+ t trace.Table
290+ }
291+
292+ type getOption func (o * getOptions )
293+
294+ func withTrace (t trace.Table ) getOption {
295+ return func (o * getOptions ) {
296+ o .t = o .t .Compose (t )
297+ }
298+ }
299+
300+ func (c * client ) get (ctx context.Context , opts ... getOption ) (s Session , err error ) {
291301 var (
292302 i = 0
293- t = c .config .Trace (). Compose ( trace . ContextTable ( ctx ))
303+ o = getOptions { t : c .config .Trace ()}
294304 )
305+ for _ , opt := range opts {
306+ opt (& o )
307+ }
295308
296- onDone := trace .TableOnPoolGet (t , & ctx )
309+ onDone := trace .TableOnPoolGet (o . t , & ctx )
297310 defer func () {
298311 onDone (s , i , err )
299312 }()
@@ -329,7 +342,7 @@ func (c *client) Get(ctx context.Context) (s Session, err error) {
329342 // are less than maximum amount of touched session. That is, we want to
330343 // be fair here and not to lock more goroutines than we could ship
331344 // session to.
332- s , err = c .waitFromCh (ctx , t )
345+ s , err = c .waitFromCh (ctx , o . t )
333346 if err != nil {
334347 err = errors .WithStackTrace (err )
335348 }
@@ -345,6 +358,12 @@ func (c *client) Get(ctx context.Context) (s Session, err error) {
345358 return s , nil
346359}
347360
361+ // Get returns first idle session from the client and removes it from
362+ // there. If no items stored in client it creates new one returns it.
363+ func (c * client ) Get (ctx context.Context ) (s Session , err error ) {
364+ return c .get (ctx )
365+ }
366+
348367func (c * client ) waitFromCh (ctx context.Context , t trace.Table ) (s Session , err error ) {
349368 var (
350369 ch * chan Session
@@ -403,7 +422,7 @@ func (c *client) waitFromCh(ctx context.Context, t trace.Table) (s Session, err
403422// Get() or Take() calls. In other way it will produce unexpected behavior or
404423// panic.
405424func (c * client ) Put (ctx context.Context , s Session ) (err error ) {
406- onDone := trace .TableOnPoolPut (c .config .Trace (). Compose ( trace . ContextTable ( ctx )) , & ctx , s )
425+ onDone := trace .TableOnPoolPut (c .config .Trace (), & ctx , s )
407426 defer func () {
408427 onDone (err )
409428 }()
@@ -447,7 +466,7 @@ func (c *client) Put(ctx context.Context, s Session) (err error) {
447466// It returns first error occurred during stale sessions' deletion.
448467// Note that even on error it calls Close() on each session.
449468func (c * client ) Close (ctx context.Context ) (err error ) {
450- onDone := trace .TableOnClose (c .config .Trace (). Compose ( trace . ContextTable ( ctx )) , & ctx )
469+ onDone := trace .TableOnClose (c .config .Trace (), & ctx )
451470 defer func () {
452471 onDone (err )
453472 }()
@@ -851,7 +870,7 @@ func (c *client) closeSession(ctx context.Context, s Session, opts ...closeSessi
851870 }
852871
853872 if h .withTrace {
854- onDone := trace .TableOnPoolSessionClose (c .config .Trace (). Compose ( trace . ContextTable ( ctx )) , & ctx , s )
873+ onDone := trace .TableOnPoolSessionClose (c .config .Trace (), & ctx , s )
855874 defer onDone ()
856875 }
857876
0 commit comments