Skip to content

Add telemetry activity for running app host in CLI#16346

Merged
JamesNK merged 5 commits intomainfrom
cli/run-telemetry
Apr 21, 2026
Merged

Add telemetry activity for running app host in CLI#16346
JamesNK merged 5 commits intomainfrom
cli/run-telemetry

Conversation

@JamesNK
Copy link
Copy Markdown
Member

@JamesNK JamesNK commented Apr 21, 2026

Description

Add a reported telemetry activity (aspire/cli/run_apphost) to RunCommand that tracks app host runs with the following tags:

  • aspire.cli.apphost.language – the app host language (e.g. CSharp, TypeScript). Only set when the project is successfully resolved.
  • aspire.cli.apphost.detached – whether the run is in detached mode
  • aspire.cli.apphost.isolated – whether the run is in isolated mode
  • error.type – friendly error category for known failure modes (project_not_found, build_failed, incompatible_version, certificate_trust_failed, backchannel_connection_failed, dashboard_failed, canceled), or the exception type for unexpected errors. Absence of this tag indicates success.

The activity is started early (before project discovery) so that all failure paths are captured in telemetry.

The activity uses StartReportedActivity so it is exported to the telemetry backend.

To support detached mode telemetry, the ASPIRE_CLI_RUN_DETACHED environment variable is passed to the child process via DetachedProcessLauncher.Start's additionalEnvironmentVariables parameter (no parent-process mutation), and read from IConfiguration in RunCommand.

DetachedProcessLauncher.Start gains an optional additionalEnvironmentVariables dictionary parameter that is applied to the child process environment on both Windows (via the custom environment block) and Unix (via ProcessStartInfo.Environment).

Includes a parameterized test (Theory) covering all 4 combinations of (detached, isolated).

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
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
    • No
  • Does the change require an update in our Aspire docs?
    • Yes
    • No

JamesNK added 2 commits April 21, 2026 07:26
Show shortened trace ID as a dashboard hyperlink in the trace detail
header instead of the full trace ID as plain text. Hoists the link
computation so it is shared between the empty-trace and normal paths.
Add a reported telemetry activity to RunCommand that records:
- App host language (csharp, typescript, etc.)
- Whether the run is detached or isolated
- error.type with friendly names for known failure modes

Also add ASPIRE_CLI_RUN_DETACHED env var so the detached child
process can report its mode accurately via telemetry.

Includes a parameterized test covering all combinations of
detached and isolated modes.
Copilot AI review requested due to automatic review settings April 21, 2026 00:32
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 21, 2026

🚀 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 -- 16346

Or

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new reported telemetry activity around CLI AppHost runs so telemetry backend can track run attempts, mode (detached/isolated), language, and categorized failure reasons.

Changes:

  • Introduces aspire/cli/run_apphost reported activity with new AppHost-related tags (language, detached, isolated, error.type).
  • Plumbs detached-mode detection into the child process via ASPIRE_CLI_RUN_DETACHED and reads it from IConfiguration in RunCommand.
  • Adds a parameterized unit test covering the detached/isolated combinations.

Reviewed changes

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

Show a summary per file
File Description
tests/Aspire.Cli.Tests/Commands/RunCommandTests.cs Adds a theory validating the new reported activity and tags.
src/Shared/KnownConfigNames.cs Adds ASPIRE_CLI_RUN_DETACHED config/environment variable name constant.
src/Aspire.Cli/Telemetry/TelemetryConstants.cs Adds new tags and the aspire/cli/run_apphost activity name.
src/Aspire.Cli/Commands/TelemetryTracesCommand.cs Minor UX tweak to use a shortened trace id in the “Trace:” header.
src/Aspire.Cli/Commands/RunCommand.cs Starts the reported activity and populates tags / error.type on failure paths.
src/Aspire.Cli/Commands/AppHostLauncher.cs Sets/clears detached env var around spawning the detached child process.

Comment thread src/Aspire.Cli/Commands/RunCommand.cs
Comment thread src/Aspire.Cli/Commands/AppHostLauncher.cs Outdated
Comment thread src/Aspire.Cli/Commands/AppHostLauncher.cs Outdated
JamesNK added 3 commits April 21, 2026 09:18
…cess

- Start runActivity before project discovery so all failure paths are captured
- Set error.type on early-return project_not_found and canceled paths
- Pass ASPIRE_CLI_RUN_DETACHED via DetachedProcessLauncher additionalEnvironmentVariables instead of mutating parent process global state
- Add IReadOnlyDictionary<string, string>? additionalEnvironmentVariables parameter to DetachedProcessLauncher.Start
@github-actions
Copy link
Copy Markdown
Contributor

🎬 CLI E2E Test Recordings — 72 recordings uploaded (commit 6c1ef39)

View recordings
Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_DefaultSelection_InstallsSkillOnly ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
AspireAddPackageVersionToDirectoryPackagesProps ▶️ View Recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View Recording
Banner_DisplayedOnFirstRun ▶️ View Recording
Banner_DisplayedWithExplicitFlag ▶️ View Recording
Banner_NotDisplayedWithNoLogoFlag ▶️ View Recording
CertificatesClean_RemovesCertificates ▶️ View Recording
CertificatesTrust_WithNoCert_CreatesAndTrustsCertificate ▶️ View Recording
CertificatesTrust_WithUntrustedCert_TrustsCertificate ▶️ View Recording
ConfigSetGet_CreatesNestedJsonFormat ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
CreateAndRunEmptyAppHostProject ▶️ View Recording
CreateAndRunJavaEmptyAppHostProject ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateAndRunTypeScriptEmptyAppHostProject ▶️ View Recording
CreateAndRunTypeScriptStarterProject ▶️ View Recording
CreateJavaAppHostWithViteApp ▶️ View Recording
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DashboardRunWithOtelTracesReturnsNoTraces ▶️ View Recording
DeployK8sBasicApiService ▶️ View Recording
DeployK8sWithGarnet ▶️ View Recording
DeployK8sWithMongoDB ▶️ View Recording
DeployK8sWithMySql ▶️ View Recording
DeployK8sWithPostgres ▶️ View Recording
DeployK8sWithRabbitMQ ▶️ View Recording
DeployK8sWithRedis ▶️ View Recording
DeployK8sWithSqlServer ▶️ View Recording
DeployK8sWithValkey ▶️ View Recording
DeployTypeScriptAppToKubernetes ▶️ View Recording
DescribeCommandResolvesReplicaNames ▶️ View Recording
DescribeCommandShowsRunningResources ▶️ View Recording
DetachFormatJsonProducesValidJson ▶️ View Recording
DetachFormatJsonProducesValidJsonWhenRestartingExistingInstance ▶️ View Recording
DoListStepsShowsPipelineSteps ▶️ View Recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
GlobalMigration_HandlesCommentsAndTrailingCommas ▶️ View Recording
GlobalMigration_HandlesMalformedLegacyJson ▶️ View Recording
GlobalMigration_PreservesAllValueTypes ▶️ View Recording
GlobalMigration_SkipsWhenNewConfigExists ▶️ View Recording
GlobalSettings_MigratedFromLegacyFormat ▶️ View Recording
InitTypeScriptAppHost_AugmentsExistingViteRepoAtRoot ▶️ View Recording
InvalidAppHostPathWithComments_IsHealedOnRun ▶️ View Recording
LegacySettingsMigration_AdjustsRelativeAppHostPath ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
OtelLogsReturnsStructuredLogsFromStarterApp ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
PublishWithConfigureEnvFileUpdatesEnvOutput ▶️ View Recording
PublishWithDockerComposeServiceCallbackSucceeds ▶️ View Recording
PublishWithoutOutputPathUsesAppHostDirectoryDefault ▶️ View Recording
RestoreGeneratesSdkFiles ▶️ View Recording
RestoreRefreshesGeneratedSdkAfterAddingIntegration ▶️ View Recording
RestoreSupportsConfigOnlyHelperPackageAndCrossPackageTypes ▶️ View Recording
RunFromParentDirectory_UsesExistingConfigNearAppHost ▶️ View Recording
SecretCrudOnDotNetAppHost ▶️ View Recording
SecretCrudOnTypeScriptAppHost ▶️ View Recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View Recording
StartAndWaitForTypeScriptSqlServerAppHostWithNativeAssets ▶️ View Recording
StopAllAppHostsFromAppHostDirectory ▶️ View Recording
StopAllAppHostsFromUnrelatedDirectory ▶️ View Recording
StopNonInteractiveMultipleAppHostsShowsError ▶️ View Recording
StopNonInteractiveSingleAppHost ▶️ View Recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View Recording
UnAwaitedChainsCompileWithAutoResolvePromises ▶️ View Recording

📹 Recordings uploaded automatically from CI run #24699171752

@JamesNK JamesNK merged commit affc370 into main Apr 21, 2026
562 of 565 checks passed
@JamesNK JamesNK deleted the cli/run-telemetry branch April 21, 2026 23:28
@github-actions github-actions Bot added this to the 13.3 milestone Apr 21, 2026
@aspire-repo-bot
Copy link
Copy Markdown
Contributor

No documentation PR is required for this change.

This PR adds internal telemetry instrumentation (aspire/cli/run_apphost activity) to the CLI run command. The telemetry tags and activity tracking are internal implementation details with no user-facing behavior, public API, or configuration changes. The existing CLI documentation does not need to be updated.

Generated by PR Documentation Check for issue #16346 · ● 143.9K ·

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.

4 participants