Skip to content

Many telemetry commands improvements#14838

Merged
davidfowl merged 4 commits intorelease/13.2from
jamesnk/telemetry-command-cleanup
Mar 2, 2026
Merged

Many telemetry commands improvements#14838
davidfowl merged 4 commits intorelease/13.2from
jamesnk/telemetry-command-cleanup

Conversation

@JamesNK
Copy link
Member

@JamesNK JamesNK commented Mar 2, 2026

Description

  • Timestamps: Logs, spans, and traces now show human-readable local times (HH:mm:ss.fff) instead of raw epoch values.
  • Resource names: Resources with replicas now display disambiguated names (with shortened instance IDs) instead of just the service name.
  • Color-coded resources: Each resource gets a consistent color in console output for easier visual scanning.
  • Severity labels: Log severity is derived from the OTLP severity number (INFO, WARN, FAIL, etc.) rather than relying on the sometimes-empty text field.
  • Chronological ordering: Spans and traces are now displayed in time order instead of by duration.
  • Traces table columns: Changed from TraceId | Resource | Duration | Spans | Status to Timestamp | Name | Spans | Duration | Status, with Name combining resource, span name, and a short trace ID.
  • Testability: Output routed through IInteractionService instead of direct AnsiConsole calls; new test suites added for all three telemetry commands.

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
  • Does the change require an update in our Aspire docs?

Copilot AI review requested due to automatic review settings March 2, 2026 08:31
@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 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/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 14838

Or

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

Copy link
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

This PR improves the Aspire CLI telemetry commands’ console output (timestamps, resource naming/coloring, severity mapping, ordering) and adds targeted test coverage to keep the behavior stable across logs/spans/traces.

Changes:

  • Updated CLI telemetry output formatting: local human-readable timestamps, consistent resource colors, replica-disambiguated resource names, severity derived from OTLP severity number, and chronological ordering for spans/traces.
  • Refactored CLI telemetry output to consistently route through IInteractionService and added new test suites for otel logs|spans|traces.
  • Shared infrastructure updates: TimeProvider-based local-time formatting helpers, plus OTLP resource parsing support for service.instance.id.

Reviewed changes

Copilot reviewed 35 out of 36 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/Aspire.Dashboard.Tests/TelemetryRepositoryTests/TelemetryRepositoryTests.cs Adds test asserting spans are returned ordered by start time.
src/Aspire.Dashboard/Otlp/Storage/TelemetryRepository.Watchers.cs Orders initial span snapshot chronologically in WatchSpansAsync.
tests/Aspire.Cli.Tests/Utils/CliTestHelper.cs Registers ResourceColorMap in CLI test DI.
src/Aspire.Cli/Program.cs Registers ResourceColorMap in production DI.
src/Aspire.Cli/Commands/TelemetryLogsCommand.cs Uses TimeProvider + severity-number labels + resource colors; outputs via IInteractionService.
src/Aspire.Cli/Commands/TelemetrySpansCommand.cs Adds chronological ordering, local timestamps, resource colors; outputs via IInteractionService.
src/Aspire.Cli/Commands/TelemetryTracesCommand.cs Changes trace table columns/content, sorts by time, resolves resource names (including replicas), colors resources.
src/Aspire.Cli/Commands/TelemetryCommandHelpers.cs Adds severity-number label mapping and resource-name resolution helpers; routes “no data” output through IInteractionService.
src/Aspire.Cli/Commands/LogsCommand.cs / src/Aspire.Cli/Commands/DescribeCommand.cs Switches ResourceColorMap to DI-provided instance instead of per-command instantiation.
tests/Aspire.Cli.Tests/Commands/TelemetryLogsCommandTests.cs New tests validating logs output formatting and replica naming.
tests/Aspire.Cli.Tests/Commands/TelemetrySpansCommandTests.cs New tests validating spans output ordering/formatting and replica naming.
tests/Aspire.Cli.Tests/Commands/TelemetryTracesCommandTests.cs New tests validating traces table columns/order and replica naming.
tests/Aspire.Cli.Tests/Commands/TelemetryTestHelper.cs Adds shared telemetry test service setup (mock backchannel + mock HTTP).
tests/Aspire.Cli.Tests/Commands/TelemetryCommandTests.cs Moves telemetry subcommand tests into dedicated suites; adds tests for new helper methods and time formatting.
src/Shared/FormatHelpers.cs Adds FormatConsoleTime(TimeProvider, DateTime) and updates other format APIs to take TimeProvider.
src/Shared/TimeProviderExtensions.cs Generalizes extensions from BrowserTimeProvider to TimeProvider.
src/Shared/Otlp/Serialization/OtlpResourceJson.cs Adds GetServiceInstanceId() helper.
src/Shared/Otlp/OtlpHelpers.cs Removes FormatNanoTimestamp (now replaced by console-time formatter).
src/Aspire.Cli/Resources/* (resx/xlf/designer) Updates localized column headers for new traces table (Timestamp, Name).
src/Aspire.Cli/Aspire.Cli.csproj / src/Aspire.Dashboard/Aspire.Dashboard.csproj Ensures shared FormatHelpers/TimeProviderExtensions are compiled into both projects.
Files not reviewed (1)
  • src/Aspire.Cli/Resources/TelemetryCommandStrings.Designer.cs: Language not supported
Comments suppressed due to low confidence (2)

src/Aspire.Cli/Commands/TelemetryCommandHelpers.cs:269

  • The XML doc on GetSeverityText says 17-20=ERROR and 21-24=FATAL, but the method returns the abbreviations FAIL and CRIT for those ranges. Update the comment to reflect the actual output labels (and/or adjust the labels to match the documented names) so the documentation stays accurate.
    /// <summary>
    /// Gets abbreviated severity text for an OTLP severity number.
    /// OTLP severity numbers: 1-4=TRACE, 5-8=DEBUG, 9-12=INFO, 13-16=WARN, 17-20=ERROR, 21-24=FATAL
    /// </summary>
    public static string GetSeverityText(int? severityNumber)
    {
        return severityNumber switch
        {
            >= 21 => "CRIT",
            >= 17 => "FAIL",
            >= 13 => "WARN",
            >= 9 => "INFO",
            >= 5 => "DBUG",
            >= 1 => "TRCE",
            _ => "-"
        };

src/Aspire.Cli/Commands/TelemetryTracesCommand.cs:283

  • When a trace ID is seen multiple times, the code updates StartTimeNano to the earliest span start time, but it does not update the associated Resource/FirstSpanName. This can produce rows where the displayed timestamp is for the earliest span, but the displayed name (resource + span name) comes from a different (later) span/resource. Consider updating Resource and FirstSpanName whenever the earliest start time is replaced (or explicitly choose a consistent rule such as “root span name”).
                    if (traceInfos.TryGetValue(traceIdValue, out var info))
                    {
                        var maxDuration = info.Duration > duration ? info.Duration : duration;
                        // Track earliest start time across all spans in the trace
                        var earliestStart = info.StartTimeNano.HasValue && span.StartTimeUnixNano.HasValue
                            ? (info.StartTimeNano.Value < span.StartTimeUnixNano.Value ? info.StartTimeNano : span.StartTimeUnixNano)
                            : info.StartTimeNano ?? span.StartTimeUnixNano;
                        traceInfos[traceIdValue] = (info.Resource, info.FirstSpanName, info.TraceId, earliestStart, maxDuration, info.SpanCount + 1, info.HasError || hasError);
                    }
                    else
                    {
                        traceInfos[traceIdValue] = (resourceName, span.Name ?? "", traceIdValue, span.StartTimeUnixNano, duration, 1, hasError);

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

🎬 CLI E2E Test Recordings

The following terminal recordings are available for commit 536b423:

Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
AgentInitCommand_WithMalformedMcpJson_ShowsErrorAndExitsNonZero ▶️ View Recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View Recording
Banner_DisplayedOnFirstRun ▶️ View Recording
Banner_DisplayedWithExplicitFlag ▶️ View Recording
CreateAndDeployToDockerCompose ▶️ View Recording
CreateAndDeployToDockerComposeInteractive ▶️ View Recording
CreateAndPublishToKubernetes ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateAndRunTypeScriptStarterProject ▶️ View Recording
CreateEmptyAppHostProject ▶️ View Recording
CreateStartAndStopAspireProject ▶️ View Recording
CreateStartWaitAndStopAspireProject ▶️ View Recording
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DescribeCommandResolvesReplicaNames ▶️ View Recording
DescribeCommandShowsRunningResources ▶️ View Recording
DetachFormatJsonProducesValidJson ▶️ View Recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
SecretCrudOnDotNetAppHost ▶️ View Recording
SecretCrudOnTypeScriptAppHost ▶️ View Recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View Recording
StopAllAppHostsFromAppHostDirectory ▶️ View Recording
StopAllAppHostsFromUnrelatedDirectory ▶️ View Recording
StopNonInteractiveMultipleAppHostsShowsError ▶️ View Recording
StopNonInteractiveSingleAppHost ▶️ View Recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View Recording

📹 Recordings uploaded automatically from CI run #22568125444

@davidfowl davidfowl merged commit ea377a7 into release/13.2 Mar 2, 2026
682 of 685 checks passed
@davidfowl davidfowl deleted the jamesnk/telemetry-command-cleanup branch March 2, 2026 15:58
@dotnet-policy-service dotnet-policy-service bot added this to the 13.2 milestone Mar 2, 2026
mitchdenny pushed a commit that referenced this pull request Mar 5, 2026
* Many telemetry commands improvements

* Clean up

* Test cleanup

* Test cleanup
Copilot AI pushed a commit that referenced this pull request Mar 10, 2026
* Many telemetry commands improvements

* Clean up

* Test cleanup

* Test cleanup
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