Skip to content

Refactor CLI telemetry JSON output to match MCP tool format#16523

Merged
JamesNK merged 5 commits intomainfrom
jamesNK/cli-telemetry-json-refactor
Apr 29, 2026
Merged

Refactor CLI telemetry JSON output to match MCP tool format#16523
JamesNK merged 5 commits intomainfrom
jamesNK/cli-telemetry-json-refactor

Conversation

@JamesNK
Copy link
Copy Markdown
Member

@JamesNK JamesNK commented Apr 28, 2026

Description

The current JSON format matches OTLP/JSON. But that JSON is very verbose, doesn't include all information, and doesn't have a way to represent traces. New JSON should work better with AI agents.


Refactor CLI telemetry JSON output to align with the MCP tool format used by the dashboard AI helpers. This is a breaking change to JSON returned from telemetry commands.

Changes

  • Shared serialization methods: Added SerializeSpansToJson, SerializeLogsToJson, SerializeTracesToJson, and SerializeTraceToJson to SharedAIHelpers so CLI commands produce identical JSON to MCP tools
  • PromptContext.ProcessValues flag: When false, AddValue returns input unchanged (CLI doesn't need AI token-limiting deduplication)
  • camelCase property names: All JSON output properties use camelCase
  • Null property stripping: StripNullProperties removes null-valued properties from JSON objects
  • dashboardUrl simplification: Replaced dashboardLink object ({url, text}) with a direct dashboardUrl string in both SharedAIHelpers and AIHelpers
  • Full IDs: spanId and traceId are no longer shortened via ToShortenedId in JSON output
  • GetTraceDto reuses GetSpanDto: Eliminated duplicated span conversion logic; inner trace spans retain traceId and timestamp
  • Test helper consolidation: Moved FormatJson to TelemetryTestHelper; added attributes to span/trace/log test data

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

Copilot AI review requested due to automatic review settings April 28, 2026 13:41
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 28, 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 -- 16523

Or

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

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

Refactors the CLI telemetry --format json output to match the JSON shape produced by the dashboard MCP tools/AI helpers (camelCase properties, null stripping, full IDs, and simplified dashboardUrl), and consolidates the serialization logic into SharedAIHelpers so both surfaces stay aligned.

Changes:

  • Centralized span/log/trace JSON serialization in SharedAIHelpers and updated CLI commands to deserialize OTLP JSON and re-emit the shared DTO JSON.
  • Updated JSON schema details (camelCase, dashboardUrl string, full traceId/spanId, null property stripping) and adjusted MCP + CLI tests accordingly.
  • Added PromptContext.ProcessValues to disable token-saving/dedup processing for CLI JSON output.

Reviewed changes

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

Show a summary per file
File Description
tests/Aspire.Cli.Tests/Mcp/ListTracesToolTests.cs Updates assertions for camelCase + full IDs + dashboardUrl.
tests/Aspire.Cli.Tests/Mcp/ListStructuredLogsToolTests.cs Updates assertions for camelCase fields and dashboardUrl.
tests/Aspire.Cli.Tests/Commands/TelemetryTracesCommandTests.cs Adds/updates CLI JSON output validation for traces.
tests/Aspire.Cli.Tests/Commands/TelemetryTestHelper.cs Adds shared JSON pretty-printing helper for tests.
tests/Aspire.Cli.Tests/Commands/TelemetrySpansCommandTests.cs Adds/updates CLI JSON output validation for spans.
tests/Aspire.Cli.Tests/Commands/TelemetryLogsCommandTests.cs Adds/updates CLI JSON output validation for logs.
src/Shared/ConsoleLogs/SharedAIHelpers.cs Adds shared CLI-oriented JSON serialization helpers; switches to camelCase properties and strips nulls.
src/Shared/ConsoleLogs/PromptContext.cs Adds ProcessValues flag so CLI can bypass value processing/dedup.
src/Aspire.Dashboard/Model/Assistant/AIHelpers.cs Changes resource graph JSON to emit dashboardUrl instead of dashboard_link.
src/Aspire.Cli/Commands/TelemetryTracesCommand.cs JSON mode now deserializes OTLP response and re-serializes via shared helpers.
src/Aspire.Cli/Commands/TelemetrySpansCommand.cs Same as traces: JSON mode re-emits shared helper JSON.
src/Aspire.Cli/Commands/TelemetryLogsCommand.cs Same approach for logs; threads “dashboardUrl” into streaming/snapshot JSON output.

Comment thread src/Aspire.Cli/Commands/TelemetryLogsCommand.cs
Comment thread src/Aspire.Cli/Commands/TelemetryTracesCommand.cs Outdated
Copy link
Copy Markdown
Member

@mitchdenny mitchdenny left a comment

Choose a reason for hiding this comment

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

Reviewed 12 changed files. Found 1 issue (naming inconsistency).

Copy link
Copy Markdown
Member

@mitchdenny mitchdenny left a comment

Choose a reason for hiding this comment

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

Reviewed 12 changed files. Found 1 naming inconsistency issue.

Comment thread src/Aspire.Dashboard/Model/Assistant/AIHelpers.cs
@github-actions
Copy link
Copy Markdown
Contributor

🎬 CLI E2E Test Recordings — 76 recordings uploaded (commit cc88997)

View all recordings
Status 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_UsesConfiguredToolchain ▶️ 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
DocsCommand_RendersInteractiveMarkdownFromLocalSource ▶️ View Recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
DoctorCommand_TypeScriptAppHostReportsMissingConfiguredToolchain ▶️ 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
InteractiveCSharpInitCreatesExpectedFiles ▶️ View Recording
InvalidAppHostPathWithComments_IsHealedOnRun ▶️ View Recording
LegacySettingsMigration_AdjustsRelativeAppHostPath ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
OtelLogsReturnsStructuredLogsFromStarterAppCore ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
PublishWithConfigureEnvFileUpdatesEnvOutput ▶️ View Recording
PublishWithDockerComposeServiceCallbackSucceeds ▶️ View Recording
PublishWithoutOutputPathUsesAppHostDirectoryDefault ▶️ View Recording
RestoreGeneratesSdkFiles ▶️ View Recording
RestoreGeneratesSdkFiles_WithConfiguredToolchain ▶️ 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 #25090901923

@JamesNK JamesNK merged commit aa066dd into main Apr 29, 2026
285 checks passed
@github-actions github-actions Bot added this to the 13.3 milestone Apr 29, 2026
@aspire-repo-bot
Copy link
Copy Markdown
Contributor

No documentation PR is required for this change.

The existing aspire otel command reference docs mention the --format Json option but do not document or show examples of the JSON output format or schema. Since the JSON output structure was never documented on [aspire.dev]((aspire.github.io/redacted), there is no docs page to update.

The PR is an internal refactoring that aligns JSON serialization with the MCP tool format — a breaking change to the JSON shape, but with no prior documentation to revise.

Generated by PR Documentation Check for issue #16523 · ● 359.3K ·

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.

3 participants