Add CLI telemetry commands (logs, spans, traces)#14256
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 14256Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 14256" |
There was a problem hiding this comment.
Pull request overview
This pull request adds comprehensive CLI telemetry commands that integrate with the Aspire Dashboard's Telemetry HTTP API, enabling users to query and stream telemetry data directly from the command line.
Changes:
- Adds three new CLI commands:
aspire telemetry logs,aspire telemetry spans, andaspire telemetry traceswith filtering, pagination, and streaming support - Implements Dashboard API authentication via new
DashboardApiKeyconfiguration that is auto-generated and stored in user secrets - Refactors backchannel infrastructure to consolidate capability detection and connection initialization through a single factory method
- Enhances Dashboard resource resolution to support both exact and base name matching for replica filtering
Reviewed changes
Copilot reviewed 35 out of 36 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Aspire.Cli.Tests/Utils/CliTestHelper.cs | Adds test service registrations for telemetry commands with test doubles for HTTP client and docs fetcher |
| tests/Aspire.Cli.Tests/TestServices/TestHttpClientFactory.cs | New test double providing basic HttpClient instances for testing |
| tests/Aspire.Cli.Tests/TestServices/TestDocsFetcher.cs | New test double returning empty docs content for testing |
| tests/Aspire.Cli.Tests/Commands/TelemetryCommandTests.cs | Comprehensive test coverage for all telemetry command variations and option combinations |
| src/Aspire.Hosting/DistributedApplicationBuilder.cs | Generates and stores DashboardApiKey in user secrets for API authentication |
| src/Aspire.Hosting/Dashboard/DashboardOptions.cs | Adds ApiKey property to dashboard configuration |
| src/Aspire.Hosting/Dashboard/DashboardEventHandlers.cs | Configures Dashboard API authentication with ApiKey fallback logic |
| src/Aspire.Hosting/Backchannel/DashboardUrlsHelper.cs | Refactored to return complete connection info including API endpoints and tokens |
| src/Aspire.Hosting/Backchannel/BackchannelDataTypes.cs | Adds ApiBaseUrl and ApiToken properties to dashboard info response |
| src/Aspire.Hosting/Backchannel/AuxiliaryBackchannelRpcTarget.cs | Updated to provide API connection info via v2 backchannel |
| src/Aspire.Dashboard/Model/Assistant/AIHelpers.cs | Enhanced resource resolution supporting base name matching for replica filtering |
| src/Aspire.Dashboard/Configuration/PostConfigureDashboardOptions.cs | Implements unidirectional API key fallback from Api to Mcp configuration |
| src/Aspire.Cli/Resources/TelemetryCommandStrings.* | Complete localization support with resource strings for all supported languages |
| src/Aspire.Cli/Program.cs | Registers new telemetry command services |
| src/Aspire.Cli/Commands/TelemetryCommand.cs | Parent command providing telemetry subcommand structure |
| src/Aspire.Cli/Commands/TelemetryLogsCommand.cs | Implements logs viewing with filtering, streaming, and table/JSON output |
| src/Aspire.Cli/Commands/TelemetrySpansCommand.cs | Implements spans viewing with trace correlation and real-time streaming |
| src/Aspire.Cli/Commands/TelemetryTracesCommand.cs | Implements trace visualization with hierarchical span tree display |
| src/Aspire.Cli/Commands/TelemetryCommandHelpers.cs | Shared utilities for API client creation, OTLP parsing, and stream processing |
| src/Aspire.Cli/Commands/RootCommand.cs | Integrates telemetry command into root command structure |
| src/Aspire.Cli/Backchannel/AuxiliaryBackchannelMonitor.cs | Refactored connection logic to use centralized factory method |
| src/Aspire.Cli/Backchannel/AppHostAuxiliaryBackchannel.cs | Consolidated connection creation with automatic capability detection via factory pattern |
Files not reviewed (1)
- src/Aspire.Cli/Resources/TelemetryCommandStrings.Designer.cs: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
🎬 CLI E2E Test RecordingsThe following terminal recordings are available for commit
📹 Recordings uploaded automatically from CI run #21581626488 |
|
|
||
| if (!TryGetResource(resources, resourceName, out var resource)) | ||
| // First, try exact match on a single resource | ||
| if (TryGetResource(resources, resourceName, out var resource)) |
There was a problem hiding this comment.
This is the only dubious part of this change. Do we need to handle returning multiple replicas?
There was a problem hiding this comment.
If the resource name is catalogservice and there are multiple instances then there should be an error and tell the user to be more specific. They need to specify catalogservice-abc123.
There was a problem hiding this comment.
How would they know what the name is 😄. We need to take another look at replicate support
|
|
||
| if (format == OutputFormat.Json) | ||
| { | ||
| _interactionService.DisplayRawText(json); |
There was a problem hiding this comment.
Should the CLI validate the content-type is text/json? Or double check that text was returned.
davidfowl
left a comment
There was a problem hiding this comment.
Done - moved to shared OtlpHelpers.cs with ToShortenedId using 7 chars.
24015b4 to
b043b13
Compare
8f0767b to
8108732
Compare
- Add 'aspire telemetry logs' command to view structured logs - Add 'aspire telemetry spans' command to view span details - Add 'aspire telemetry traces' command to view trace summaries - Support --follow for streaming logs and spans - Support --format json for machine-readable output - Consolidate Dashboard API URL builders in DashboardUrls.cs - Unify backchannel connection factory in CreateFromSocketAsync - Fix streaming API to filter all data when resource not found - Add tests for invalid resource streaming behavior
8108732 to
7cb1f04
Compare
Description
Adds new
aspire telemetrycommands to the CLI that consume the Dashboard Telemetry HTTP API, allowing users to query and stream telemetry data from the command line.New Commands
aspire telemetry logs- View structured logsaspire telemetry spans- View distributed trace spansaspire telemetry traces- View distributed traces summaryFeatures
--limitoption to control number of results--followoption for real-time telemetry updates--format json)Example Usage
Implementation Details
TelemetryCommandHelpers.cswith shared code for all telemetry commandsReadLinesAsyncextension method onStreamReaderfor streaming supportChecklist