@@ -112,6 +112,7 @@ type ClientParams struct {
112112
113113// NewClientWithOptions generates a new client and allows overriding options in the default profile configuration.
114114func NewClientWithOptions (params * ClientParams ) (* Client , error ) {
115+ ctx := context .Background ()
115116 if params == nil {
116117 params = & ClientParams {}
117118 }
@@ -161,15 +162,15 @@ func NewClientWithOptions(params *ClientParams) (*Client, error) {
161162 additionalStreamInterceptors : params .GRPCStreamInterceptors ,
162163 }
163164
164- logger .Debug ( "Initializing Modal client" , "version" , sdkVersion (), "server_url" , profile .ServerURL )
165+ logger .DebugContext ( ctx , "Initializing Modal client" , "version" , sdkVersion (), "server_url" , profile .ServerURL )
165166
166167 if params .ControlPlaneClient != nil {
167168 c .cpClient = & clientWithConn {
168169 ModalClientClient : params .ControlPlaneClient ,
169170 conn : params .ControlPlaneConn ,
170171 }
171172 } else {
172- conn , client , err := newClient (profile , c , c .additionalUnaryInterceptors , c .additionalStreamInterceptors )
173+ conn , client , err := newClient (ctx , profile , c , c .additionalUnaryInterceptors , c .additionalStreamInterceptors )
173174 if err != nil {
174175 return nil , fmt .Errorf ("failed to create control plane client: %w" , err )
175176 }
@@ -181,7 +182,7 @@ func NewClientWithOptions(params *ClientParams) (*Client, error) {
181182 return nil , fmt .Errorf ("failed to start auth token manager: %w" , err )
182183 }
183184
184- logger .Debug ( "Modal client initialized successfully" )
185+ logger .DebugContext ( ctx , "Modal client initialized successfully" )
185186
186187 c .Apps = & appServiceImpl {client : c }
187188 c .CloudBucketMounts = & cloudBucketMountServiceImpl {client : c }
@@ -200,7 +201,7 @@ func NewClientWithOptions(params *ClientParams) (*Client, error) {
200201
201202// ipClient returns the input plane client for the given server URL.
202203// It creates a new client if one doesn't exist for that specific server URL, otherwise it returns the existing client.
203- func (c * Client ) ipClient (serverURL string ) (pb.ModalClientClient , error ) {
204+ func (c * Client ) ipClient (ctx context. Context , serverURL string ) (pb.ModalClientClient , error ) {
204205 c .mu .RLock ()
205206 if client , ok := c .ipClients [serverURL ]; ok {
206207 c .mu .RUnlock ()
@@ -215,10 +216,10 @@ func (c *Client) ipClient(serverURL string) (pb.ModalClientClient, error) {
215216 return client , nil
216217 }
217218
218- c .logger .Debug ( "Creating input plane client" , "server_url" , serverURL )
219+ c .logger .DebugContext ( ctx , "Creating input plane client" , "server_url" , serverURL )
219220 prof := c .profile
220221 prof .ServerURL = serverURL
221- conn , client , err := newClient (prof , c , c .additionalUnaryInterceptors , c .additionalStreamInterceptors )
222+ conn , client , err := newClient (ctx , prof , c , c .additionalUnaryInterceptors , c .additionalStreamInterceptors )
222223 if err != nil {
223224 return nil , err
224225 }
@@ -228,25 +229,26 @@ func (c *Client) ipClient(serverURL string) (pb.ModalClientClient, error) {
228229
229230// Close stops the background auth token refresh and closes all gRPC connections.
230231func (c * Client ) Close () {
231- c .logger .Debug ("Closing Modal client" )
232+ ctx := context .Background ()
233+ c .logger .DebugContext (ctx , "Closing Modal client" )
232234 c .authTokenManager .Stop ()
233235
234236 if c .cpClient != nil {
235237 if err := c .cpClient .Close (); err != nil {
236- c .logger .Warn ( "Failed to close control plane connection" , "error" , err )
238+ c .logger .WarnContext ( ctx , "Failed to close control plane connection" , "error" , err )
237239 }
238240 }
239241
240242 c .mu .Lock ()
241243 for serverURL , client := range c .ipClients {
242244 if err := client .Close (); err != nil {
243- c .logger .Warn ( "Failed to close input plane connection" , "server_url" , serverURL , "error" , err )
245+ c .logger .WarnContext ( ctx , "Failed to close input plane connection" , "server_url" , serverURL , "error" , err )
244246 }
245247 }
246248 c .ipClients = map [string ]* clientWithConn {}
247249 c .mu .Unlock ()
248250
249- c .logger .Debug ( "Modal client closed" )
251+ c .logger .DebugContext ( ctx , "Modal client closed" )
250252}
251253
252254// Version returns the SDK version.
@@ -298,7 +300,7 @@ func isRetryableGrpc(err error) bool {
298300
299301// newClient dials the given server URL with auth/timeout/retry interceptors installed.
300302// It returns (conn, stub). Close the conn when done.
301- func newClient (profile Profile , c * Client , customUnaryInterceptors []grpc.UnaryClientInterceptor , customStreamInterceptors []grpc.StreamClientInterceptor ) (* grpc.ClientConn , pb.ModalClientClient , error ) {
303+ func newClient (ctx context. Context , profile Profile , c * Client , customUnaryInterceptors []grpc.UnaryClientInterceptor , customStreamInterceptors []grpc.StreamClientInterceptor ) (* grpc.ClientConn , pb.ModalClientClient , error ) {
302304 var target string
303305 var creds credentials.TransportCredentials
304306 var scheme string
@@ -314,7 +316,7 @@ func newClient(profile Profile, c *Client, customUnaryInterceptors []grpc.UnaryC
314316 return nil , nil , status .Errorf (codes .InvalidArgument , "invalid server URL: %s" , profile .ServerURL )
315317 }
316318
317- c .logger .Debug ( "Connecting to Modal server" , "target" , target , "scheme" , scheme )
319+ c .logger .DebugContext ( ctx , "Connecting to Modal server" , "target" , target , "scheme" , scheme )
318320
319321 unaryInterceptors := []grpc.UnaryClientInterceptor {
320322 headerInjectorUnaryInterceptor (profile , c .sdkVersion ),
0 commit comments