Skip to content

Don't throw from component telemetry context dispose if not initialized #9306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 14, 2025

Conversation

JamesNK
Copy link
Member

@JamesNK JamesNK commented May 14, 2025

Description

I noticed that ComponentTelemetryContext.Dispose() would throw if called without the context being initialized. This could happen if there is an error in a component before initialization and then the context is dispose with the component.

It's a bug but not a critical one. Requires other things to go wrong first.

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?

Copy link
Contributor

@Copilot 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 ensures that disposing a ComponentTelemetryContext without prior initialization does not throw an exception. The changes include:

  • Updated test cases to cover telemetry enabled, telemetry disabled, and disposal without initialization scenarios.
  • Modified ComponentTelemetryContext to use a safe-call operator in Dispose, preventing exceptions when the telemetry service is unassigned.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
tests/Aspire.Dashboard.Tests/Telemetry/ComponentTelemetryContextTests.cs Added test coverage for disposal behavior with and without telemetry enabled.
src/Aspire.Dashboard/Components/Pages/ComponentTelemetryContext.cs Altered property access and disposal logic to safely handle uninitialized telemetry service.

@danmoseley danmoseley merged commit 2291fb9 into main May 14, 2025
176 checks passed
@danmoseley danmoseley deleted the jamesnk/telemetrycontext-dispose-no-error branch May 14, 2025 15:37
@github-actions github-actions bot locked and limited conversation to collaborators Jun 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants