aspire icon indicating copy to clipboard operation
aspire copied to clipboard

Fix error when metrics have no scope

Open JamesNK opened this issue 8 months ago • 2 comments

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

JamesNK avatar Apr 30 '25 01:04 JamesNK

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 OtlpMeter with OtlpScope to 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 TryAddScope Helper Method: Introduced a utility method in OtlpHelpers to 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 ScopeName and MeterName with Name across multiple Razor components to ensure consistency with the new OtlpScope model. (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 Name instead of MeterName for 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 GetMeter method in OtlpApplication since its functionality is now covered by the new TryAddScope helper. (src/Aspire.Dashboard/Otlp/Model/OtlpApplication.cs, src/Aspire.Dashboard/Otlp/Model/OtlpApplication.csL198-L206)

  • Improved Logging and Error Handling: Enhanced logging in the TryAddScope method 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.

davidfowl avatar Apr 30 '25 05:04 davidfowl

The actual change is to remove redundant OtlpMeter (it's the same as OtlpScope) and use an empty scope if no scope is specified.

JamesNK avatar Apr 30 '25 05:04 JamesNK