Skip to content

feat: add --user-agent flag for caller-identified telemetry#1102

Merged
patrikbraborec merged 4 commits into
masterfrom
feat/user-agent-telemetry-flag
Apr 24, 2026
Merged

feat: add --user-agent flag for caller-identified telemetry#1102
patrikbraborec merged 4 commits into
masterfrom
feat/user-agent-telemetry-flag

Conversation

@patrikbraborec
Copy link
Copy Markdown
Contributor

@patrikbraborec patrikbraborec commented Apr 22, 2026

Summary

  • Adds an opt-in caller identifier (--user-agent flag / APIFY_CLI_USER_AGENT env var) so skills, plugins, and integrations that wrap the CLI can be distinguished from direct human usage in telemetry.
  • Flag wins over env. Value is sanitized (ASCII control chars stripped, capped at 256 chars) and attached to telemetry as userAgent.
  • Scoped to the public apify entrypoint only; the actor entrypoint (which runs inside Actor Docker images) rejects it.

Test plan

  • yarn lint
  • yarn build
  • yarn test:local — 21 new unit tests for resolveUserAgentForTelemetry, flag registration, and end-to-end telemetry wiring all pass. (Two pre-existing Python fixture failures are unrelated.)
  • Reviewer: confirm properties.userAgent coexistence with context.userAgent in Segment payloads is acceptable (different objects, distinct meaning).

Closes: #1100

patrikbraborec and others added 2 commits April 22, 2026 14:53
Adds an opt-in caller identifier so skills, plugins, and integrations
that wrap the CLI can be distinguished from direct human usage. Exposed
as `--user-agent` on every command under the `apify` entrypoint and
via the `APIFY_CLI_USER_AGENT` env var (flag wins over env). The
resolved value is sanitized (control chars stripped, capped at 256
chars) and attached to telemetry as `callerAgent` — named to avoid
collision with Segment's existing `context.userAgent`. Scoped to the
public `apify` entrypoint only; the `actor` entrypoint rejects it.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The flag is --user-agent and env var is APIFY_CLI_USER_AGENT, so the
telemetry field should match. Collision with Segment's context.userAgent
is not a concern because the two live in distinct objects
(properties vs context).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added this to the 139th sprint - DX team milestone Apr 22, 2026
@github-actions github-actions Bot added t-dx Issues owned by the DX team. tested Temporary label used only programatically for some analytics. labels Apr 22, 2026
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@l2ysho l2ysho left a comment

Choose a reason for hiding this comment

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

some small nits (nonblocking), but no opinion over context.userAgent vs. properties.userAgent, lets wait for @vladfrangu with this one

Comment thread test/local/lib/command-framework/user-agent.test.ts
Comment thread src/lib/command-framework/apify-command.ts Outdated
…scope

Why: test-cli is set by testRunCommand() for test harnessing, but no test
exercises --user-agent through that path. Keeping it in the Set contradicts
the comment above scoping the flag to the public apify entrypoint.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@vladfrangu vladfrangu left a comment

Choose a reason for hiding this comment

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

I guess its fine in properties but ask the analytics team

@patrikbraborec patrikbraborec merged commit 5d1fe06 into master Apr 24, 2026
23 of 25 checks passed
@patrikbraborec patrikbraborec deleted the feat/user-agent-telemetry-flag branch April 24, 2026 10:01
vystrcild pushed a commit to apify/agent-skills that referenced this pull request Apr 28, 2026
…emetry attribution

Adds --user-agent apify-agent-skills/apify-ultimate-scraper to every apify CLI
example in the apify-ultimate-scraper skill (SKILL.md, gotchas.md, actor-index.md,
and four workflow guidance files), plus a top-level rule in SKILL.md documenting
the convention. Bumps the CLI prerequisite to v1.5.0+ since the flag was
introduced in apify/apify-cli#1102.

This lets us distinguish skill-driven CLI invocations from generic human usage
in Mixpanel/Segment via properties.userAgent, and aligns with the existing
apify-agent-skills/<slug> naming convention used in actor_run.meta_user_agent
data feeding dashboards.apify.com/dashboards/276.

Refs: apify/apify-cli#1102

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-dx Issues owned by the DX team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add caller identification flag for telemetry (e.g. --user-agent)

4 participants