Skip to content

Add operator/agent_name to deploy/launch metrics payloads#4995

Merged
clouvet merged 7 commits into
masterfrom
metrics-client-agent-header-v2
Jul 10, 2026
Merged

Add operator/agent_name to deploy/launch metrics payloads#4995
clouvet merged 7 commits into
masterfrom
metrics-client-agent-header-v2

Conversation

@clouvet

@clouvet clouvet commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds operator and agentName fields to LaunchStatusPayload and DeployStatusPayload
  • Calls clientsignals.DetectOnce() directly in deploy and launch commands to classify the caller
  • OperatorFromSignals() helper maps signals to operator values: agent, ci, or interactive
  • When operator is agent, agentName carries the specific agent (e.g. claude-code, cursor)
  • Fields use omitempty so older flyctl-metrics versions ignore them gracefully

Companion PR

  • superfly/flyctl-metrics#67 — reads operator and agentName from the payload and uses them as Prometheus labels on deploy/launch metrics

Merge order

flyctl-metrics can be merged first — empty payload fields default to "none".

Test plan

  • go build passes
  • Run fly deploy from a terminal and verify operator=interactive in payload
  • Run fly deploy from CI and verify operator=ci
  • Run fly deploy from an agent (e.g. with CLAUDECODE=1) and verify operator=agent, agentName=claude-code

🤖 Generated with Claude Code

Uses client-signals DetectOnce() to include the agent name header
on metrics POST requests to flyctl-metrics. This enables the metrics
service to distinguish agent-driven vs human-driven CLI commands.

Works in both interactive (forked subprocess) and non-interactive
paths since env vars are inherited and DetectOnce() caches its result.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@clouvet clouvet force-pushed the metrics-client-agent-header-v2 branch from 3004ae6 to fcc9272 Compare July 9, 2026 20:52
Always detects signals via clientsignals.DetectOnce() and stores the
agent name on context — independent of the client-signals feature flag
(which only gates API request headers). Deploy and launch commands read
the agent from context to populate the new ClientAgent payload field.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@clouvet clouvet force-pushed the metrics-client-agent-header-v2 branch from fcc9272 to 54e32ff Compare July 9, 2026 20:55
Sprite and others added 2 commits July 9, 2026 21:01
Always detects client signals and stores the agent name on context,
independent of the client-signals feature flag (which only gates
API request headers). Deploy and launch commands read the agent from
context to populate the new ClientAgent payload field, which
flyctl-metrics can use as a Prometheus label.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When client signals are enabled, stores the detected agent name on
context in InitClient. Deploy and launch commands read it to populate
the new ClientAgent payload field, which flyctl-metrics uses as a
Prometheus label.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@clouvet clouvet changed the title Send Fly-Client-Agent header with metrics requests Add ClientAgent to deploy/launch metrics payloads Jul 9, 2026
@clouvet clouvet requested a review from Copilot July 9, 2026 21:39

This comment was marked as outdated.

@clouvet clouvet requested a review from dangra July 9, 2026 21:44
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>

This comment was marked as outdated.

@clouvet clouvet changed the title Add ClientAgent to deploy/launch metrics payloads Add operator/agent_name to deploy/launch metrics payloads Jul 10, 2026
@clouvet clouvet requested a review from Copilot July 10, 2026 14:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread internal/metrics/helpers.go Outdated
Comment thread internal/command/launch/cmd.go Outdated
Comment thread internal/command/deploy/deploy.go Outdated
Sprite and others added 2 commits July 10, 2026 14:47
The package already declares itself as clientsignals, so the explicit
alias is unnecessary. Matches the import style in preparers.go.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
CI now takes priority over agent (an agent running in CI is "ci").
Interactive requires the terminal check to be true. Falls back to
"unknown" when no signals match.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@clouvet clouvet merged commit 287b256 into master Jul 10, 2026
19 of 24 checks passed
@clouvet clouvet deleted the metrics-client-agent-header-v2 branch July 10, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants