@@ -296,7 +296,7 @@ func (api *API) updaterLoop() {
296
296
if err := api .cleanupSubAgents (api .ctx );err != nil {
297
297
api .logger .Error (api .ctx ,"cleanup subagents failed" ,slog .Error (err ))
298
298
}else {
299
- api .logger .Debug (api .ctx ,"subagent cleanup complete" )
299
+ api .logger .Debug (api .ctx ,"cleanup subagents complete" )
300
300
}
301
301
302
302
// Perform an initial update to populate the container list, this
@@ -440,6 +440,20 @@ func (api *API) updateContainers(ctx context.Context) error {
440
440
// on the latest list of containers. This method assumes that api.mu is
441
441
// held.
442
442
func (api * API )processUpdatedContainersLocked (ctx context.Context ,updated codersdk.WorkspaceAgentListContainersResponse ) {
443
+ dcFields := func (dc codersdk.WorkspaceAgentDevcontainer ) []slog.Field {
444
+ f := []slog.Field {
445
+ slog .F ("devcontainer_id" ,dc .ID ),
446
+ slog .F ("devcontainer_name" ,dc .Name ),
447
+ slog .F ("workspace_folder" ,dc .WorkspaceFolder ),
448
+ slog .F ("config_path" ,dc .ConfigPath ),
449
+ }
450
+ if dc .Container != nil {
451
+ f = append (f ,slog .F ("container_id" ,dc .Container .ID ))
452
+ f = append (f ,slog .F ("container_name" ,dc .Container .FriendlyName ))
453
+ }
454
+ return f
455
+ }
456
+
443
457
// Reset the container links in known devcontainers to detect if
444
458
// they still exist.
445
459
for _ ,dc := range api .knownDevcontainers {
@@ -460,6 +474,13 @@ func (api *API) processUpdatedContainersLocked(ctx context.Context, updated code
460
474
continue
461
475
}
462
476
477
+ logger := api .logger .With (
478
+ slog .F ("container_id" ,updated .Containers [i ].ID ),
479
+ slog .F ("container_name" ,updated .Containers [i ].FriendlyName ),
480
+ slog .F ("workspace_folder" ,workspaceFolder ),
481
+ slog .F ("config_file" ,configFile ),
482
+ )
483
+
463
484
if dc ,ok := api .knownDevcontainers [workspaceFolder ];ok {
464
485
// If no config path is set, this devcontainer was defined
465
486
// in Terraform without the optional config file. Assume the
@@ -468,7 +489,7 @@ func (api *API) processUpdatedContainersLocked(ctx context.Context, updated code
468
489
if dc .ConfigPath == "" && configFile != "" {
469
490
dc .ConfigPath = configFile
470
491
if err := api .watcher .Add (configFile );err != nil {
471
- api . logger .Error (ctx ,"watch devcontainer config file failed" ,slog .Error (err ), slog . F ( "file" , configFile ))
492
+ logger .With ( dcFields ( dc ) ... ). Error (ctx ,"watch devcontainer config file failed" ,slog .Error (err ))
472
493
}
473
494
}
474
495
@@ -477,13 +498,7 @@ func (api *API) processUpdatedContainersLocked(ctx context.Context, updated code
477
498
continue
478
499
}
479
500
480
- if configFile != "" {
481
- if err := api .watcher .Add (configFile );err != nil {
482
- api .logger .Error (ctx ,"watch devcontainer config file failed" ,slog .Error (err ),slog .F ("file" ,configFile ))
483
- }
484
- }
485
-
486
- api .knownDevcontainers [workspaceFolder ]= codersdk.WorkspaceAgentDevcontainer {
501
+ dc := codersdk.WorkspaceAgentDevcontainer {
487
502
ID :uuid .New (),
488
503
Name :"" ,// Updated later based on container state.
489
504
WorkspaceFolder :workspaceFolder ,
@@ -492,11 +507,21 @@ func (api *API) processUpdatedContainersLocked(ctx context.Context, updated code
492
507
Dirty :false ,// Updated later based on config file changes.
493
508
Container :container ,
494
509
}
510
+
511
+ if configFile != "" {
512
+ if err := api .watcher .Add (configFile );err != nil {
513
+ logger .With (dcFields (dc )... ).Error (ctx ,"watch devcontainer config file failed" ,slog .Error (err ))
514
+ }
515
+ }
516
+
517
+ api .knownDevcontainers [workspaceFolder ]= dc
495
518
}
496
519
497
520
// Iterate through all known devcontainers and update their status
498
521
// based on the current state of the containers.
499
522
for _ ,dc := range api .knownDevcontainers {
523
+ logger := api .logger .With (dcFields (dc )... )
524
+
500
525
if dc .Container != nil {
501
526
if ! api .devcontainerNames [dc .Name ] {
502
527
// If the devcontainer name wasn't set via terraform, we
@@ -532,7 +557,7 @@ func (api *API) processUpdatedContainersLocked(ctx context.Context, updated code
532
557
if _ ,injected := api .injectedSubAgentProcs [dc .Container .ID ];! injected && dc .Status == codersdk .WorkspaceAgentDevcontainerStatusRunning {
533
558
err := api .injectSubAgentIntoContainerLocked (ctx ,dc )
534
559
if err != nil {
535
- api . logger .Error (ctx ,"inject subagent into container failed" ,slog .Error (err ))
560
+ logger .Error (ctx ,"inject subagent into container failed" ,slog .Error (err ))
536
561
}
537
562
}
538
563