@@ -419,6 +419,11 @@ func (p *DBTokenProvider) auditInitRequest(ctx context.Context, w http.ResponseW
419
419
return
420
420
}
421
421
422
+ userID := uuid.NullUUID {}
423
+ if aReq .apiKey != nil {
424
+ userID = uuid.NullUUID {Valid : true , UUID : aReq .apiKey .UserID }
425
+ }
426
+
422
427
type additionalFields struct {
423
428
audit.AdditionalFields
424
429
SlugOrPort string `json:"slug_or_port,omitempty"`
@@ -438,14 +443,17 @@ func (p *DBTokenProvider) auditInitRequest(ctx context.Context, w http.ResponseW
438
443
appInfo .SlugOrPort = aReq .dbReq .AppSlugOrPort
439
444
}
440
445
446
+ logger := p .Logger .With (
447
+ slog .F ("workspace_id" , aReq .dbReq .Workspace .ID ),
448
+ slog .F ("agent_id" , aReq .dbReq .Agent .ID ),
449
+ slog .F ("app_id" , aReq .dbReq .App .ID ),
450
+ slog .F ("user_id" , userID .UUID ),
451
+ slog .F ("app_slug_or_port" , appInfo .SlugOrPort ),
452
+ )
453
+
441
454
appInfoBytes , err := json .Marshal (appInfo )
442
455
if err != nil {
443
- p .Logger .Error (ctx , "marshal additional fields failed" , slog .Error (err ))
444
- }
445
-
446
- userID := uuid.NullUUID {}
447
- if aReq .apiKey != nil {
448
- userID = uuid.NullUUID {Valid : true , UUID : aReq .apiKey .UserID }
456
+ logger .Error (ctx , "marshal additional fields failed" , slog .Error (err ))
449
457
}
450
458
451
459
var (
@@ -489,7 +497,7 @@ func (p *DBTokenProvider) auditInitRequest(ctx context.Context, w http.ResponseW
489
497
return nil
490
498
}, nil )
491
499
if err != nil {
492
- p . Logger .Error (ctx , "update workspace app audit session failed" , slog .Error (err ))
500
+ logger .Error (ctx , "update workspace app audit session failed" , slog .Error (err ))
493
501
494
502
// Avoid spamming the audit log if deduplication failed, this should
495
503
// only happen if there are problems communicating with the database.
@@ -528,7 +536,7 @@ func (p *DBTokenProvider) auditInitRequest(ctx context.Context, w http.ResponseW
528
536
case aReq .dbReq .App .ID != uuid .Nil :
529
537
audit .BackgroundAudit (ctx , & audit.BackgroundAuditParams [database.WorkspaceApp ]{
530
538
Audit : auditor ,
531
- Log : p . Logger ,
539
+ Log : logger ,
532
540
533
541
Action : database .AuditActionOpen ,
534
542
OrganizationID : aReq .dbReq .Workspace .OrganizationID ,
@@ -545,7 +553,7 @@ func (p *DBTokenProvider) auditInitRequest(ctx context.Context, w http.ResponseW
545
553
// Web terminal, port app, etc.
546
554
audit .BackgroundAudit (ctx , & audit.BackgroundAuditParams [database.WorkspaceAgent ]{
547
555
Audit : auditor ,
548
- Log : p . Logger ,
556
+ Log : logger ,
549
557
550
558
Action : database .AuditActionOpen ,
551
559
OrganizationID : aReq .dbReq .Workspace .OrganizationID ,
0 commit comments