Skip to content

Limit telemetry hooks to Aspire-configured agents - #22078

Merged
Ella Hathaway (ellahathaway) merged 17 commits into
mainfrom
ellahathaway-clarify-telemetry-hook-message
Nov 13, 2026
Merged

Ella Hathaway (ellahathaway) merged 17 commits into
mainfrom
ellahathaway-clarify-telemetry-hook-message

Conversation

@ellahathaway

@ellahathaway Ella Hathaway (ellahathaway) commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixed #20014

aspire agent init now registers telemetry hooks per selected agent client instead of per detected environment. The install message names each client by its display name, so the Copilot App and Copilot CLI no longer appear as separate entries.

Installed Aspire agent telemetry hooks for: GitHub Copilot, Claude Code.

Hook locations:

  • GitHub Copilot: <COPILOT_HOME>\hooks\aspire-telemetry.json. One registration covers the Copilot App, the Copilot CLI, and VS Code.
  • Claude Code: a PostToolUse hook in <CLAUDE_CONFIG_DIR>\settings.json.
  • OpenCode: no hooks, because it has no verified hook schema.

When hooks install:

  • Only for global scope, which is the existing rule because hooks write to user-level locations. Project scope is handled later in the stack.
  • Only for selected clients that have the aspire@aspire-skills plugin or the Aspire MCP server configured, either from a previous run or from this one. Existing Aspire setup refreshes the hook even when both the skills and MCP choices are skipped. The hooks only report on that plugin's skills and Aspire MCP tools, so third-party skills alone produce no events, and ASPIRE_CLI_TELEMETRY_OPTOUT still disables reporting.

Re-running aspire agent init refreshes Aspire's hook and preserves unrelated user hooks and settings.

Validation: dotnet test --project tests\Aspire.Cli.Tests\Aspire.Cli.Tests.csproj --no-launch-profile -- --filter-class "*AgentInit*" --filter-class "*NewCommand*" --filter-class "*InitCommand*" --filter-class "*McpInit*" --filter-class "*TelemetryHook*" --filter-class "*AgentTelemetry*" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true" passed (1257 run; 3 flaky failures passed on rerun).

Fixes #20014

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 22078

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 22078"

@github-actions

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the client-based telemetry hook changes.

No open issues 🎉

What changed in this PR

This PR addresses #20014 by making aspire agent init report telemetry hooks by agent client display name rather than detected environment, clarifying that Copilot App and CLI share one registration.

Changes:

  • Tracks hook support, installation results, and skip messages per selected client.
  • Installs user-level hooks in either configuration scope when Aspire skills or MCP are configured.
  • Updates tests and documentation for client selection, VS Code detection, and display-name messages.
File Description
tests/​Aspire.Cli.Tests/​TestServices/​TestTelemetryHookConfigurator.cs Tracks selected clients and supports configurable results.
tests/​Aspire.Cli.Tests/​Commands/​AgentInitCommandTests.cs Verifies client display names in installation and skip messages.
tests/​Aspire.Cli.Tests/​Commands/​AgentInitClientSelectionTests.cs Covers both scopes and Aspire skills/MCP eligibility.
tests/​Aspire.Cli.Tests/​Agents/​TelemetryHookConfiguratorTests.cs Updates client-based assertions and adds selection and VS Code coverage.
src/​Aspire.Cli/​Commands/​AgentInitCommand.cs Passes selected clients, adjusts hook eligibility, and displays client names.
src/​Aspire.Cli/​Agents/​OpenCode/​OpenCodeAgentClient.cs Explicitly declares telemetry hooks unsupported.
src/​Aspire.Cli/​Agents/​IAgentClient.cs Defines client-level hook support and registration.
src/​Aspire.Cli/​Agents/​Hooks/​TelemetryHookConfigurator.cs Registers hooks for selected, supported, detected clients.
src/​Aspire.Cli/​Agents/​Hooks/​ITelemetryHookConfigurator.cs Models configured and skipped clients instead of environments.
src/​Aspire.Cli/​Agents/​Copilot/​CopilotAgentClient.cs Reports the shared Copilot registration as one client.
src/​Aspire.Cli/​Agents/​ClaudeCode/​ClaudeCodeAgentClient.cs Adopts client-based hook results.
docs/​specs/​aspire-product-telemetry.md Documents installation conditions and user-level placement in both scopes.

Review effort: Balanced

@github-actions

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Telemetry hooks can be installed and reported as successful when neither skills nor MCP was configured for a client, and cross-process deduplication lacks automated regression coverage.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Report telemetry hooks only for successfully configured clients

src/​Aspire.Cli/​Commands/​AgentInitCommand.cs:706

For a detected Copilot client, --scope project --skills none --mcp with malformed project .mcp.json reaches this call after MCP configuration fails. Passing all selectedClients still creates the global telemetry hook and reports it as installed, although neither Aspire skills nor MCP was configured for that client. Track successful Aspire skills/MCP configuration per client and pass only those clients here, including successful no-op configurations.

1 file not reviewed
  • src/Aspire.Cli/Resources/AgentCommandStrings.Designer.cs: Generated file

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block the client-focused telemetry hook changes.

1 open issue

Review effort: Balanced

@github-actions

This comment has been minimized.

@ellahathaway Ella Hathaway (ellahathaway) changed the title Name telemetry hooks by agent display name in aspire agent init Name telemetry hooks by agent display name Nov 10, 2026
@ellahathaway Ella Hathaway (ellahathaway) changed the title Name telemetry hooks by agent display name Install telemetry hooks only for Aspire-configured agents and name them in output Nov 10, 2026
@ellahathaway Ella Hathaway (ellahathaway) changed the title Install telemetry hooks only for Aspire-configured agents and name them in output Limit telemetry hooks to Aspire-configured agents Nov 10, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the changes limiting telemetry hook registration to selected, Aspire-configured clients.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@github-actions

This comment has been minimized.

Each agent client declares the environments that make it eligible for a telemetry hook, and the configurator registers one hook per eligible client instead of per detected environment.

Co-authored-by: Copilot App <[email protected]>
VS Code's Copilot harness reads user hooks from ~/.copilot/hooks, the same location the Copilot App and CLI use.

Co-authored-by: Copilot App <[email protected]>
Pass the selected clients to the telemetry hook configurator so detected but
unselected clients are not modified, and cover the per-client skip messages
at the command level.

Co-authored-by: Copilot App <[email protected]>
Install hooks only for selected clients whose aspire-skills plugin registered or MCP setup succeeded, keep the global-only rule, and drop the unverified VS Code agent marker.

Co-authored-by: Copilot App <[email protected]>
Re-running agent init now refreshes the telemetry hook for selected clients that already have the Aspire plugin or MCP server configured, even when this run does not configure them again.

Co-authored-by: Copilot App <[email protected]>
With --scope global and no skills or MCP selected, agent init returned at the
no-configuration guard before refreshing hooks for clients whose Aspire setup
already exists. Refresh those hooks before the early return; project scope is
unchanged.

Co-authored-by: Copilot App <[email protected]>
Global agent init now treats an aspire server in the VS Code or VS Code Insiders
user mcp.json (default and named profiles) as existing Aspire setup, so reruns
refresh the telemetry hook. These files are read-only and unreadable files are ignored.

Co-authored-by: Copilot App <[email protected]>
Directory enumeration of VS Code profile mcp.json files is lazy, so access errors can surface while iterating. Catch them so the best-effort existing-setup probe never fails agent init.

Co-authored-by: Copilot App <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

Tests selector

2 / 101 PR test projects · 4 PR jobs, from 17 changed files.

Selected PR test projects (2 / 101)

Aspire.Cli.EndToEnd.Tests, Aspire.Cli.Tests

Selected PR jobs (4)

cli-starter-validation, extension-e2e, polyglot, typescript-api-compat


How these were chosen — grouped by what changed

📦 affected project Aspire.Cli
→ 1 test: Aspire.Cli.EndToEnd.Tests

🧪 tests/Aspire.Cli.Tests/Agents/TelemetryHookConfiguratorTests.cs (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Commands/AgentInitClientSelectionTests.cs (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Commands/AgentInitCommandTests.cs (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Commands/NewCommandTests.cs (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Snapshots/AgentInitClientSelectionTests.AgentInit_InstallationLocations_ShowSelectedAssetsAndSharedConsumers_scope=global_installSkills=False_configureMcp=True.verified.txt (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Snapshots/AgentInitClientSelectionTests.AgentInit_InstallationLocations_ShowSelectedAssetsAndSharedConsumers_scope=global_installSkills=True_configureMcp=True.verified.txt (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/TestServices/TestTelemetryHookConfigurator.cs (changed test)
→ 1 directly: Aspire.Cli.Tests

Job reasons

Job Triggered by
cli-starter-validation affected project Aspire.Cli
extension-e2e • src/Aspire.Cli/Agents/AspireSkills/AspireSkillsRemoteConfiguration.cs, src/Aspire.Cli/Agents/ClaudeCode/ClaudeCodeAgentClient.cs, src/Aspire.Cli/Agents/Copilot/CopilotAgentClient.cs, src/Aspire.Cli/Agents/Hooks/AgentTelemetryHook.cs, src/Aspire.Cli/Agents/Hooks/ITelemetryHookConfigurator.cs, src/Aspire.Cli/Agents/Hooks/TelemetryHookConfigurator.cs, src/Aspire.Cli/Agents/IAgentClient.cs, src/Aspire.Cli/Agents/McpConfigFileHelper.cs, src/Aspire.Cli/Agents/OpenCode/OpenCodeAgentClient.cs, src/Aspire.Cli/Commands/AgentInitCommand.cs
• affected project Aspire.Cli
polyglot affected project Aspire.Cli
typescript-api-compat affected project Aspire.Cli

Selection computed for commit 4e3cc90.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the client-based telemetry-hook registration changes.

No open issues 🎉

Review effort: Balanced

@ellahathaway
Ella Hathaway (ellahathaway) enabled stacked auto-merge (squash) November 12, 2026 23:15
@ellahathaway
Ella Hathaway (ellahathaway) merged commit f720bae into main Nov 13, 2026
432 of 436 checks passed
Ella Hathaway (ellahathaway) added a commit that referenced this pull request Nov 13, 2026
## Description

Stack 3/3, on #22084. `aspire agent init --scope project` now installs
telemetry hooks too. The hooks are written at user scope
(`~/.copilot/hooks` and `~/.claude/settings.json`) no matter which scope
was requested. Skills and MCP configuration still follow the requested
scope, and #22078's per-client gating still decides which clients get
hooks.

Because the hooks live in user-level configuration, they apply in every
repository where that client runs, not only the one where `aspire agent
init` was run. The PostToolUse matcher from #22084 makes the client
launch `aspire` only for matching tool calls, and only Aspire skill, MCP
tool, and reference-file usage is reported. Users can opt out with
`ASPIRE_CLI_TELEMETRY_OPTOUT=true`. The install message now says the
hooks were written to user-level configuration.

### Why we can't install project-level hooks today

Every hook launches a separate `aspire` process, so it must fire exactly
once per event. Today a project-level hook would make it fire more than
once (see #20480):

- **Copilot runs hooks from every source and doesn't dedupe them.** It
loads the repo's `.github/hooks/*.json`, `~/.copilot/hooks`,
`.github/copilot/settings(.local).json`, `~/.copilot/settings.json`, and
plugins, then runs all of them. A project hook in `.github/hooks` plus
the user hook that global init installs would launch `aspire` twice for
each event. Claude Code dedupes identical handlers across its settings
files, so this is a Copilot problem.
- **Copilot also runs Claude's project hooks.** Copilot reads the repo's
`.claude/settings(.local).json` and runs those hooks too, ignoring
Claude-only fields such as `if`. A Claude project hook would fire in
Copilot sessions on top of Copilot's own hook, even if the user set up
only Claude for the project.
- **Install time can't avoid the duplicates.** Project hook files are
committed and shared, but user hooks belong to each machine. We can't
delete a user hook to make room for a project hook, because it also
serves the user's other repos. Skipping the project hook when a user
hook exists only helps the developer who ran init, not teammates who
clone the repo with their own user hooks.
- **Runtime dedupe is heavy.** Each invocation is an independent process
with no shared event ID. Deduping would mean hook processes coordinating
through shared state on every tool call, which is the hot path.

Installing hooks only at user scope gives exactly one hook per client on
each machine. We can revisit project hooks if Copilot starts deduping
identical hook commands or applying precedence across hook sources.

Validation: `dotnet test --project
tests\Aspire.Cli.Tests\Aspire.Cli.Tests.csproj --no-launch-profile --
--filter-class "*.AgentInit*" --filter-class "*.TelemetryHook*"
--filter-class "*.AgentTelemetry*" --filter-not-trait "quarantined=true"
--filter-not-trait "outerloop=true"` passed (464/464). The E2E tests
were not run.

## Checklist

- Is this feature complete?
  - [x] Yes. Ready to ship.
  - [ ] No. Follow-up changes expected.
- Are you including unit tests for the changes and scenario tests if
relevant?
  - [x] Yes
  - [ ] No
- Did you add public API?
  - [ ] Yes
    - If yes, did you have an API Review for it?
      - [ ] Yes
      - [ ] No
- Did you add `<remarks />` and `<code />` elements on your triple slash
comments?
      - [ ] Yes
      - [ ] No
  - [x] No
- Does the change make any security assumptions or guarantees?
  - [ ] Yes
    - If yes, have you done a threat model and had a security review?
      - [ ] Yes
      - [ ] No
  - [x] No

---------

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: b39716fb-e8ff-45f3-a048-a710d4f3052e
@microsoft-github-policy-service microsoft-github-policy-service Bot added this to the 17.1 milestone Nov 13, 2026
Jose Perez Rodriguez (joperezr) pushed a commit that referenced this pull request Nov 13, 2026
## Description

Backports of the PRs from
https://github.com/microsoft/aspire/stack/22118:
- #22078
- #22084
- #22093

## Checklist

- Is this feature complete?
  - [ ] Yes. Ready to ship.
  - [ ] No. Follow-up changes expected.
- Are you including unit tests for the changes and scenario tests if
relevant?
  - [ ] Yes
  - [ ] No
- Did you add public API?
  - [ ] Yes
    - If yes, did you have an API Review for it?
      - [ ] Yes
      - [ ] No
- Did you add `<remarks />` and `<code />` elements on your triple slash
comments?
      - [ ] Yes
      - [ ] No
  - [ ] No
- Does the change make any security assumptions or guarantees?
  - [ ] Yes
    - If yes, have you done a threat model and had a security review?
      - [ ] Yes
      - [ ] No
  - [ ] No

---------

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: b39716fb-e8ff-45f3-a048-a710d4f3052e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clarify telemetry hook message when Copilot App and CLI are detected

3 participants