Skip to content

Commit 1386a0c

Browse files
Spriteclaude
andcommitted
Add operator and agent_name to deploy/launch metrics payloads
Call clientsignals.DetectOnce() directly in deploy and launch commands to classify the operator as interactive/ci/agent, and capture the agent name when present. Revert the context-plumbing approach in preparers. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e57e5cc commit 1386a0c

4 files changed

Lines changed: 20 additions & 15 deletions

File tree

internal/cmdutil/preparers/preparers.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"github.com/superfly/flyctl/internal/instrument"
2020
"github.com/superfly/flyctl/internal/launchdarkly"
2121
"github.com/superfly/flyctl/internal/logger"
22-
"github.com/superfly/flyctl/internal/metrics"
2322
"github.com/superfly/flyctl/internal/state"
2423
"github.com/superfly/flyctl/internal/uiex"
2524
mpgv1 "github.com/superfly/flyctl/internal/uiex/mpg/v1"
@@ -71,7 +70,6 @@ func InitClient(ctx context.Context) (context.Context, error) {
7170
if clientSignalsEnabled {
7271
s := clientsignals.DetectOnce()
7372
signals = &s
74-
ctx = metrics.WithClientAgent(ctx, s.Agent)
7573
}
7674

7775
if flyutil.ClientFromContext(ctx) == nil {

internal/command/deploy/deploy.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/logrusorgru/aurora"
1111
"github.com/spf13/cobra"
12+
clientsignals "github.com/superfly/client-signals/go"
1213
"github.com/superfly/fly-go/flaps"
1314
"github.com/superfly/flyctl/internal/appconfig"
1415
"github.com/superfly/flyctl/internal/build/imgsrc"
@@ -517,7 +518,7 @@ func deployToMachines(
517518

518519
startTime := time.Now()
519520
var status metrics.DeployStatusPayload
520-
status.ClientAgent = metrics.ClientAgentFromContext(ctx)
521+
status.Operator, status.AgentName = metrics.OperatorFromSignals(clientsignals.DetectOnce())
521522

522523
metrics.Started(ctx, "deploy")
523524
// TODO: remove this once there is nothing upstream using it

internal/command/launch/cmd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/logrusorgru/aurora"
1616
"github.com/samber/lo"
1717
"github.com/spf13/cobra"
18+
clientsignals "github.com/superfly/client-signals/go"
1819
"github.com/superfly/flyctl/gql"
1920
"github.com/superfly/flyctl/internal/appconfig"
2021
"github.com/superfly/flyctl/internal/appsecrets"
@@ -303,7 +304,7 @@ func run(ctx context.Context) (err error) {
303304

304305
startTime := time.Now()
305306
var status metrics.LaunchStatusPayload
306-
status.ClientAgent = metrics.ClientAgentFromContext(ctx)
307+
status.Operator, status.AgentName = metrics.OperatorFromSignals(clientsignals.DetectOnce())
307308
metrics.Started(ctx, "launch")
308309

309310
var state *launchState = nil

internal/metrics/helpers.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"sync"
77
"time"
88

9+
clientsignals "github.com/superfly/client-signals/go"
910
"github.com/superfly/flyctl/terminal"
1011
)
1112

@@ -80,7 +81,8 @@ type LaunchStatusPayload struct {
8081

8182
ScannerFamily string `json:"scanner_family"`
8283
FlyctlVersion string `json:"flyctlVersion"`
83-
ClientAgent string `json:"clientAgent,omitempty"`
84+
Operator string `json:"operator,omitempty"`
85+
AgentName string `json:"agentName,omitempty"`
8486
}
8587

8688
func LaunchStatus(ctx context.Context, payload LaunchStatusPayload) {
@@ -114,7 +116,8 @@ type DeployStatusPayload struct {
114116
Strategy string `json:"strategy"`
115117

116118
FlyctlVersion string `json:"flyctlVersion"`
117-
ClientAgent string `json:"clientAgent,omitempty"`
119+
Operator string `json:"operator,omitempty"`
120+
AgentName string `json:"agentName,omitempty"`
118121
}
119122

120123
func DeployStatus(ctx context.Context, payload DeployStatusPayload) {
@@ -161,15 +164,17 @@ func StartTiming(ctx context.Context, metricSlug string) func() {
161164
}
162165
}
163166

164-
type clientAgentKey struct{}
165-
166-
func WithClientAgent(ctx context.Context, agent string) context.Context {
167-
return context.WithValue(ctx, clientAgentKey{}, agent)
168-
}
169-
170-
func ClientAgentFromContext(ctx context.Context) string {
171-
val, _ := ctx.Value(clientAgentKey{}).(string)
172-
return val
167+
// OperatorFromSignals returns an operator classification and, when the
168+
// operator is "agent", the agent name. Precedence: agent > ci > interactive.
169+
func OperatorFromSignals(s clientsignals.Signals) (operator, agentName string) {
170+
switch {
171+
case s.Agent != "":
172+
return "agent", s.Agent
173+
case s.CI:
174+
return "ci", ""
175+
default:
176+
return "interactive", ""
177+
}
173178
}
174179

175180
type disableFlushMetricsKey struct{}

0 commit comments

Comments
 (0)