@@ -28,6 +28,7 @@ import (
28
28
29
29
"cdr.dev/slog"
30
30
"cdr.dev/slog/sloggers/sloghuman"
31
+ "github.com/coder/coder/v2/agent/agentssh"
31
32
"github.com/coder/coder/v2/cli/cliui"
32
33
"github.com/coder/coder/v2/cli/cliutil"
33
34
"github.com/coder/coder/v2/coderd/autobuild/notify"
@@ -58,6 +59,7 @@ func (r *RootCmd) ssh() *serpent.Command {
58
59
remoteForwards []string
59
60
env []string
60
61
disableAutostart bool
62
+ noUsageTracking bool
61
63
)
62
64
client := new (codersdk.Client )
63
65
cmd := & serpent.Command {
@@ -408,12 +410,27 @@ func (r *RootCmd) ssh() *serpent.Command {
408
410
return xerrors .Errorf ("start shell: %w" , err )
409
411
}
410
412
411
- // track workspace usage while connection is open
412
- closeUsage := client .UpdateWorkspaceUsageWithBodyContext (ctx , workspace .ID , codersdk.PostWorkspaceUsageRequest {
413
- AgentID : workspaceAgent .ID ,
414
- AppName : codersdk .UsageAppNameSSH ,
415
- })
416
- defer closeUsage ()
413
+ if ! noUsageTracking {
414
+ // check env for magic variable to determine the session type
415
+ appName := codersdk .UsageAppNameSSH
416
+ for _ , kv := range parsedEnv {
417
+ if kv [0 ] == agentssh .MagicSessionTypeEnvironmentVariable {
418
+ switch kv [1 ] {
419
+ case agentssh .MagicSessionTypeJetBrains :
420
+ appName = codersdk .UsageAppNameJetbrains
421
+ case agentssh .MagicSessionTypeVSCode :
422
+ appName = codersdk .UsageAppNameVscode
423
+ }
424
+ }
425
+ }
426
+
427
+ // track workspace usage while connection is open
428
+ closeUsage := client .UpdateWorkspaceUsageWithBodyContext (ctx , workspace .ID , codersdk.PostWorkspaceUsageRequest {
429
+ AgentID : workspaceAgent .ID ,
430
+ AppName : appName ,
431
+ })
432
+ defer closeUsage ()
433
+ }
417
434
418
435
// Put cancel at the top of the defer stack to initiate
419
436
// shutdown of services.
@@ -517,6 +534,12 @@ func (r *RootCmd) ssh() *serpent.Command {
517
534
Value : serpent .StringArrayOf (& env ),
518
535
},
519
536
sshDisableAutostartOption (serpent .BoolOf (& disableAutostart )),
537
+ {
538
+ Flag : "no-usage-tracking" ,
539
+ Description : "Disables tracking of workspace usage." ,
540
+ Env : "CODER_SSH_NO_USAGE_TRACKING" ,
541
+ Value : serpent .BoolOf (& noUsageTracking ),
542
+ },
520
543
}
521
544
return cmd
522
545
}
0 commit comments