Skip to content

Use single ActivitySource across CLI components #9848

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 9 commits into from
Jun 16, 2025
Merged

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 12, 2025

Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.

Original issue description:

We should consider using a single ActivitySource across all commands/dependencies in the Aspire CLI pipeline.

I know you are just following the existing pattern, but it is odd for each class to have its own ActivitySource. Typically there is a single ActivitySource for an entire assembly/app/etc.

https://learn.microsoft.com/en-us/dotnet/core/diagnostics/distributed-tracing-instrumentation-walkthroughs#best-practices-1

Create the ActivitySource once, store it in a static variable and use that instance as long as needed. Each library or library subcomponent can (and often should) create its own source. Consider creating a new source rather than reusing an existing one if you anticipate app developers would appreciate being able to enable and disable the Activity telemetry in the sources independently.

I don't see devs needing to enable and disable separate commands activities.

Originally posted by @eerhardt in #9792 (comment)

Fixes #9843.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@davidfowl
Copy link
Member

Try again @copilot

Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jun 13, 2025

Try again @copilot

Done! I've consolidated all 11 individual ActivitySource instances across the CLI components into a single shared AspireCliActivitySource.Instance. The OpenTelemetry configuration has been updated to use the single "Aspire.Cli" source. Build and tests pass successfully.

Fixed in commit 019a27b.

Copilot finished work on behalf of davidfowl June 13, 2025 07:16
…DI pattern

- Rename class and file from AspireCliActivitySource to AspireCliActivityTelemetry
- Change from static singleton to non-static class
- Register in DI container and inject into all consuming services
- Update all usage sites to use injected telemetry service instead of static access
- Update test files to provide telemetry parameter in manual instantiations

Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Copilot finished work on behalf of davidfowl June 13, 2025 08:03
Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jun 13, 2025

Try again @copilot

Done! I've successfully consolidated all 11 individual ActivitySource instances across the CLI components into a single shared telemetry service. The implementation uses dependency injection and all tests pass (except for one unrelated flaky test). Fixed in commit 742c530.

Copilot finished work on behalf of davidfowl June 13, 2025 08:15
…mporary file

Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Copilot finished work on behalf of davidfowl June 13, 2025 08:26
…AspireCliTelemetry.cs

Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Copilot finished work on behalf of davidfowl June 13, 2025 08:40
@davidfowl davidfowl changed the title [WIP] Use single ActivitySource across CLI components Use single ActivitySource across CLI components Jun 13, 2025
@davidfowl davidfowl marked this pull request as ready for review June 13, 2025 08:42
@davidfowl
Copy link
Member

The activity itself should have the command name

Copy link
Contributor Author

Copilot AI commented Jun 13, 2025

The activity itself should have the command name

Updated all CLI command activities to include the command name for better tracing context. Each command (run, add, new, publish, deploy) now passes its name when starting activities. Fixed in commit coming next.

Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Copilot finished work on behalf of davidfowl June 13, 2025 09:04
@mitchdenny mitchdenny merged commit ff5c9e0 into main Jun 16, 2025
496 of 498 checks passed
@mitchdenny mitchdenny deleted the copilot/fix-9843 branch June 16, 2025 03:00
@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Error loading sessions

Retrying.

Successfully merging this pull request may close these issues.

Use single ActivitySource across CLI components
3 participants