Fix error when metrics have no scope
Fixes https://github.com/dotnet/aspire/issues/8970
Checklist
- Is this feature complete?
- [x] Yes. Ready to ship.
- [ ] No. Follow-up changes expected.
- Are you including unit tests for the changes and scenario tests if relevant?
- [ ] Yes
- [x] 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
- If yes, did you have an API Review for it?
- [x] No
- [ ] Yes
- 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
- If yes, have you done a threat model and had a security review?
- [x] No
- [ ] Yes
- Does the change require an update in our Aspire docs?
- [ ] Yes
- Link to aspire-docs issue (consider using one of the following templates):
- [x] No
- [ ] Yes
Big change, no description:
This pull request introduces significant updates to the telemetry and metrics handling in the project, focusing on adding support for OTLP scopes, improving metadata handling, and refactoring the codebase for consistency. The changes affect both the TelemetryStresser in the stress testing playground and several components in the Aspire Dashboard.
Telemetry and Metrics Enhancements:
-
Added Metadata Support for OTLP API Key: Introduced metadata headers to include the OTLP API key in telemetry export requests in
TelemetryStresser. This ensures secure and authenticated communication with the metrics service. (playground/Stress/Stress.TelemetryService/TelemetryStresser.cs, [1] [2] -
Refactored Scope Handling: Replaced
OtlpMeterwithOtlpScopeto better align with OTLP's instrumentation scope model. This includes changes to dictionary structures, method parameters, and logic for handling metrics. (src/Aspire.Dashboard/Otlp/Model/OtlpApplication.cs, [1] [2] [3] [4] -
Added
TryAddScopeHelper Method: Introduced a utility method inOtlpHelpersto safely add instrumentation scopes, ensuring robust handling of scope creation and error logging. (src/Aspire.Dashboard/Otlp/Model/OtlpHelpers.cs, src/Aspire.Dashboard/Otlp/Model/OtlpHelpers.csR431-R452)
UI and ViewModel Updates:
-
Updated Scope Property References: Replaced
ScopeNameandMeterNamewithNameacross multiple Razor components to ensure consistency with the newOtlpScopemodel. (src/Aspire.Dashboard/Components/Controls/SpanDetails.razor.cs, [1];src/Aspire.Dashboard/Components/Controls/StructuredLogDetails.razor.cs, [2];src/Aspire.Dashboard/Components/Pages/Metrics.razor, [3] [4] [5] -
Refactored Tree View and Metric Selector: Updated the tree view logic to use
Nameinstead ofMeterNamefor grouping and displaying metrics in the UI. (src/Aspire.Dashboard/Components/Controls/TreeMetricSelector.razor, src/Aspire.Dashboard/Components/Controls/TreeMetricSelector.razorL17-R22)
Codebase Simplification:
-
Removed Redundant Methods: Eliminated the
GetMetermethod inOtlpApplicationsince its functionality is now covered by the newTryAddScopehelper. (src/Aspire.Dashboard/Otlp/Model/OtlpApplication.cs, src/Aspire.Dashboard/Otlp/Model/OtlpApplication.csL198-L206) -
Improved Logging and Error Handling: Enhanced logging in the
TryAddScopemethod to capture and report errors during scope addition. (src/Aspire.Dashboard/Otlp/Model/OtlpHelpers.cs, src/Aspire.Dashboard/Otlp/Model/OtlpHelpers.csR431-R452)
These changes collectively improve the project's alignment with OTLP standards, enhance telemetry export capabilities, and streamline the handling of scopes and metrics across the codebase.
The actual change is to remove redundant OtlpMeter (it's the same as OtlpScope) and use an empty scope if no scope is specified.