Add aspire export command for telemetry and resource data#14969
Add aspire export command for telemetry and resource data#14969JamesNK merged 11 commits intorelease/13.2from
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 14969Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 14969" |
🎬 CLI E2E Test RecordingsThe following terminal recordings are available for commit
📹 Recordings uploaded automatically from CI run #22752687294 |
There was a problem hiding this comment.
Pull request overview
Adds a new aspire export CLI command to collect resource snapshots, console logs, and OTLP telemetry (logs/traces) from a running AppHost/Dashboard API and package the results into a zip archive. This also refactors OTLP JSON types/serializer context and log serialization into shared code so both the CLI and Dashboard can reuse the same export/serialization pipeline.
Changes:
- Introduces
aspire exportcommand, DI wiring, localization resources, and unit tests for zip output and replica grouping. - Adds shared
ExportArchivezip writer and consolidates OTLP JSON source-gen serialization context + shared telemetry/resource DTOs. - Refactors Dashboard telemetry export and telemetry API serialization to use the shared archive + serializer context.
Reviewed changes
Copilot reviewed 55 out of 56 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Aspire.Dashboard.Tests/Model/TelemetryImportServiceTests.cs | Updates test imports to use shared OTLP serialization namespace. |
| tests/Aspire.Dashboard.Tests/Model/TelemetryExportServiceTests.cs | Updates test imports/serialization to shared OTLP serializer context. |
| tests/Aspire.Dashboard.Tests/Integration/TelemetryApiTests.cs | Switches JSON parsing to shared TelemetryApiResponse type info. |
| tests/Aspire.Dashboard.Tests/Integration/OtlpHttpJsonTests.cs | Updates OTLP serialization imports to shared namespace. |
| tests/Aspire.Cli.Tests/Utils/CliTestHelper.cs | Registers ExportCommand in test DI. |
| tests/Aspire.Cli.Tests/Mcp/ListTracesToolTests.cs | Updates MCP tool tests to shared OTLP types/context (ResourceInfo, OtlpTelemetryDataJson). |
| tests/Aspire.Cli.Tests/Mcp/ListStructuredLogsToolTests.cs | Updates MCP tool tests to shared OTLP types/context. |
| tests/Aspire.Cli.Tests/Commands/TelemetryTracesCommandTests.cs | Updates telemetry command tests to shared OTLP types/context. |
| tests/Aspire.Cli.Tests/Commands/TelemetryTestHelper.cs | Updates helper to serialize ResourceInfo[] via shared context. |
| tests/Aspire.Cli.Tests/Commands/TelemetrySpansCommandTests.cs | Updates telemetry command tests to shared OTLP types/context. |
| tests/Aspire.Cli.Tests/Commands/TelemetryLogsCommandTests.cs | Updates telemetry command tests to shared OTLP types/context. |
| tests/Aspire.Cli.Tests/Commands/TelemetryCommandTests.cs | Renames/updates resource conversion test to ResourceInfo. |
| tests/Aspire.Cli.Tests/Commands/ExportCommandTests.cs | Adds new unit tests covering aspire export zip output, output path handling, apphost option, auto-connection selection, and replica grouping. |
| src/Shared/Otlp/Serialization/TelemetryApiResponse.cs | Adds shared telemetry API response wrapper DTO for OTLP payloads. |
| src/Shared/Otlp/Serialization/ResourceInfo.cs | Adds shared telemetry resource DTO (ResourceInfo) for Dashboard API interop. |
| src/Shared/Otlp/Serialization/OtlpMetricsJson.cs | Moves OTLP metrics JSON model types into shared code. |
| src/Shared/Otlp/Serialization/OtlpJsonSerializerContext.cs | Consolidates source-gen JSON context into shared namespace with #if CLI guards. |
| src/Shared/Otlp/Serialization/OtlpCommonJson.cs | Moves OtlpTelemetryDataJson into shared OTLP common types. |
| src/Shared/Export/ExportArchive.cs | Adds shared zip archive writer for exporting resources/telemetry (CLI + Dashboard reuse). |
| src/Shared/ConsoleLogs/LogEntrySerializer.cs | Moves/renames namespace to shared console log serializer. |
| src/Aspire.Dashboard/Otlp/Model/Serialization/OtlpMetricsJson.cs | Removes Dashboard-local OTLP metrics JSON types (now shared). |
| src/Aspire.Dashboard/Otlp/Model/Serialization/OtlpCommonJson.cs | Removes Dashboard-local OtlpTelemetryDataJson (now shared). |
| src/Aspire.Dashboard/Otlp/Http/OtlpJsonConverters.cs | Updates imports to shared OTLP serialization types. |
| src/Aspire.Dashboard/Model/TelemetryExportService.cs | Refactors Dashboard export flow to populate ExportArchive instead of writing ZipArchive directly. |
| src/Aspire.Dashboard/Model/Assistant/AIHelpers.cs | Updates imports to shared OTLP serialization namespace. |
| src/Aspire.Dashboard/DashboardEndpointsBuilder.cs | Updates telemetry API endpoints to serialize responses using shared TelemetryApiResponse type info. |
| src/Aspire.Dashboard/Components/Pages/ConsoleLogs.razor.cs | Updates console log serializer namespace usage to shared. |
| src/Aspire.Dashboard/Aspire.Dashboard.csproj | Links new shared export + OTLP serialization files into Dashboard build. |
| src/Aspire.Dashboard/Api/TelemetryApiService.cs | Switches telemetry API service to shared TelemetryApiResponse and removes old local DTO definitions. |
| src/Aspire.Cli/Resources/xlf/ExportCommandStrings.cs.xlf | Adds localization entries for export command (cs). |
| src/Aspire.Cli/Resources/xlf/ExportCommandStrings.de.xlf | Adds localization entries for export command (de). |
| src/Aspire.Cli/Resources/xlf/ExportCommandStrings.es.xlf | Adds localization entries for export command (es). |
| src/Aspire.Cli/Resources/xlf/ExportCommandStrings.fr.xlf | Adds localization entries for export command (fr). |
| src/Aspire.Cli/Resources/xlf/ExportCommandStrings.it.xlf | Adds localization entries for export command (it). |
| src/Aspire.Cli/Resources/xlf/ExportCommandStrings.ja.xlf | Adds localization entries for export command (ja). |
| src/Aspire.Cli/Resources/xlf/ExportCommandStrings.ko.xlf | Adds localization entries for export command (ko). |
| src/Aspire.Cli/Resources/xlf/ExportCommandStrings.pl.xlf | Adds localization entries for export command (pl). |
| src/Aspire.Cli/Resources/xlf/ExportCommandStrings.pt-BR.xlf | Adds localization entries for export command (pt-BR). |
| src/Aspire.Cli/Resources/xlf/ExportCommandStrings.ru.xlf | Adds localization entries for export command (ru). |
| src/Aspire.Cli/Resources/xlf/ExportCommandStrings.tr.xlf | Adds localization entries for export command (tr). |
| src/Aspire.Cli/Resources/xlf/ExportCommandStrings.zh-Hans.xlf | Adds localization entries for export command (zh-Hans). |
| src/Aspire.Cli/Resources/xlf/ExportCommandStrings.zh-Hant.xlf | Adds localization entries for export command (zh-Hant). |
| src/Aspire.Cli/Resources/ExportCommandStrings.resx | Adds CLI resource strings for export command. |
| src/Aspire.Cli/Resources/ExportCommandStrings.Designer.cs | Adds generated strongly-typed resource wrapper for export command strings. |
| src/Aspire.Cli/Program.cs | Registers ExportCommand in CLI host DI. |
| src/Aspire.Cli/Otlp/OtlpCliJsonSerializerContext.cs | Removes CLI-specific serializer context (replaced by shared context). |
| src/Aspire.Cli/Mcp/Tools/ListTracesTool.cs | Updates MCP traces tool to shared OtlpJsonSerializerContext and DTOs. |
| src/Aspire.Cli/Mcp/Tools/ListTraceStructuredLogsTool.cs | Updates MCP structured logs tool to shared OtlpJsonSerializerContext and DTOs. |
| src/Aspire.Cli/Mcp/Tools/ListStructuredLogsTool.cs | Updates MCP structured logs tool to shared OtlpJsonSerializerContext and DTOs. |
| src/Aspire.Cli/Commands/TelemetryTracesCommand.cs | Updates deserialization to shared OtlpJsonSerializerContext. |
| src/Aspire.Cli/Commands/TelemetrySpansCommand.cs | Updates deserialization to shared OtlpJsonSerializerContext. |
| src/Aspire.Cli/Commands/TelemetryLogsCommand.cs | Updates deserialization to shared OtlpJsonSerializerContext. |
| src/Aspire.Cli/Commands/TelemetryCommandHelpers.cs | Updates telemetry resource DTO usage to shared ResourceInfo and shared serializer context. |
| src/Aspire.Cli/Commands/RootCommand.cs | Adds export as a root subcommand. |
| src/Aspire.Cli/Commands/ExportCommand.cs | Adds new aspire export command implementation (resource + telemetry export to zip). |
| src/Aspire.Cli/Aspire.Cli.csproj | Links shared export/OTLP serialization files + adds resx integration for export strings. |
Files not reviewed (1)
- src/Aspire.Cli/Resources/ExportCommandStrings.Designer.cs: Language not supported
PR Testing Report - aspire export E2E ValidationCLI Version: Full E2E Lifecycle TestCreated a TypeScript starter project (
Export Content VerificationExtracted and inspected zip contents:
No Result: All scenarios passed |
Adds a new 'aspire export' CLI command that saves telemetry and resource data to a zip file. The command connects to a running AppHost via the backchannel, fetches resource snapshots, console logs, structured logs, and traces from the Dashboard API, and writes them into an organized zip archive. Changes: - Add ExportCommand with --output, --apphost, and resource argument - Add TelemetryArchiveWriter shared utility for zip archive writing - Move OTLP metrics/telemetry JSON types to shared code for CLI reuse - Add ExportCommandStrings resource files with localization support - Add ExportCommandTests with 4 unit tests covering zip output, --output path, --apphost option, and connection auto-selection - Register ExportCommand in CLI test DI container
- Move TelemetryApiResponse and ResourceInfo to src/Shared/Otlp/Serialization - Remove duplicate type definitions from Dashboard (TelemetryApiService.cs) and CLI (OtlpCliJsonSerializerContext.cs) - Delete redundant Dashboard partial OtlpJsonSerializerContext.cs, consolidate into shared file with #if !CLI for Dashboard-specific types - Add [JsonPropertyName] attributes for consistency with other shared OTLP types - Update all references in source and test files
…d code, use TimeProvider, broaden error handling
ad59466 to
c6fd421
Compare
Fixes #14820
Description
Add a new
aspire exportCLI command that exports telemetry and resource data from a running Aspire AppHost to a zip file.The command connects to a running AppHost via the backchannel, fetches resource snapshots, console logs, structured logs, and traces from the Dashboard API, and organizes them into a zip archive. Data is grouped per resource using resolved resource names (handling replicas correctly):
For replica resources, each replica gets its own files using its resolved name (e.g.,
apiservice-abc,apiservice-def).Key changes
src/Aspire.Cli/Commands/ExportCommand.cs) — New CLI command with--output,--apphost, and optionalresourceargument. Groups structured logs and traces per resource by resolved name viaTelemetryCommandHelpers.ResolveResourceName.src/Shared/Export/ExportArchive.cs) — Shared utility for writing telemetry data to zip archives (reusable by Dashboard and CLI). UsesUtf8JsonWriterwith indented output andUnsafeRelaxedJsonEscapingfor AOT-compatible serialization that preserves non-ASCII characters.src/Shared/Otlp/Serialization/OtlpJsonSerializerContext.cs) — Single shared source-generated JSON serializer context with#if CLI/#elseguards for project-specific types, replacing separate CLI and Dashboard serializer contexts.OtlpTelemetryDataJson, metrics JSON types,OtlpCommonJsonextensions, andLogEntrySerializerto shared code for cross-project reuse.ExportCommandStrings.resxwith xlf files for all 13 supported languages.--outputpath handling with nested directory creation--apphostoption behavior when AppHost is not runningFiles changed (54 files, +3068 / -826)
ExportCommand.cs,RootCommand.cs,Program.csTelemetryCommandHelpers.cs,TelemetryLogsCommand.cs,TelemetrySpansCommand.cs,TelemetryTracesCommand.csList*Tool.csfilesOtlpCliJsonSerializerContext.csExportCommandStrings.resx,.Designer.cs, 13.xlffilesTelemetryExportService.cs,TelemetryApiService.cs,LogEntrySerializer.cs, etc.ExportArchiveand serializer contextExportArchive.cs,LogEntrySerializer.cs,OtlpJsonSerializerContext.cs,OtlpCommonJson.cs,OtlpMetricsJson.csExportCommandTests.cs+ 6 other test filesChecklist
aspire.devissue: