Improve span details percentage calculation#10310
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug where spans with zero duration would cause NaN percentage values in the dashboard's waterfall visualization. The fix introduces a helper method to safely calculate percentages by returning 0 when the total duration is 0, preventing division by zero errors.
Key changes:
- Added a
CalculatePercenthelper method to handle division by zero scenarios - Enhanced test helper methods to support creating spans and logs with zero duration
- Added comprehensive test coverage for the zero duration scenario
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/Aspire.Dashboard/Model/Otlp/SpanWaterfallViewModel.cs | Added CalculatePercent helper method and replaced direct percentage calculations to prevent NaN values |
| tests/Aspire.Dashboard.Tests/Model/SpanWaterfallViewModelTests.cs | Added test case to verify zero duration spans are handled correctly |
| tests/Shared/Telemetry/TelemetryTestHelpers.cs | Enhanced test helpers with additional parameters and utility methods for better test support |
eerhardt
approved these changes
Jul 10, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Spans could have zero duration. This will cause
NaNvalues (floating point divide by zero), which when used in Blazor view will productNaN%strings.This wouldn't break the page - the browser will ignore it - but it will avoid browser writing CSS warning.
Checklist
<remarks />and<code />elements on your triple slash comments?doc-ideatemplatebreaking-changetemplatediagnostictemplate