Remove setting value of Activity.Current in telemetry service by removing async StartActivity.#558
Merged
conniey merged 20 commits intomicrosoft:mainfrom Oct 10, 2025
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR removes the explicit setting of Activity.Current in the telemetry service by changing the StartActivity methods from asynchronous to synchronous. The change addresses the async flow issue mentioned in the .NET runtime GitHub issue #30915, where explicitly setting Activity.Current can cause problems with activity propagation in async scenarios.
Key changes:
- Converting
ITelemetryService.StartActivitymethods from async to sync - Adding explicit initialization requirement through
InitializeAsync() - Removing manual
Activity.Currentassignment in favor of letting the framework handle activity flow
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
ITelemetryService.cs |
Updated interface to make StartActivity methods synchronous and added InitializeAsync method |
TelemetryService.cs |
Implemented synchronous StartActivity methods, added initialization check, and converted async initialization to explicit InitializeAsync method |
McpRuntime.cs |
Updated to use synchronous StartActivity calls and removed explicit Activity.Current assignment |
CommandFactory.cs |
Updated to use synchronous StartActivity call |
Program.cs |
Added telemetry service initialization call before starting the service |
| Test files | Updated all test files to accommodate the new synchronous API and initialization requirement |
CHANGELOG.md |
Added entry documenting the telemetry service fix |
vukelich
requested changes
Sep 25, 2025
4880789 to
dded110
Compare
joshfree
approved these changes
Oct 8, 2025
alzimmermsft
reviewed
Oct 8, 2025
vukelich
requested changes
Oct 8, 2025
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
71f010f to
2b6f61c
Compare
vukelich
requested changes
Oct 10, 2025
vukelich
approved these changes
Oct 10, 2025
colbytimm
pushed a commit
to colbytimm/microsoft-mcp
that referenced
this pull request
Dec 8, 2025
…moving async StartActivity. (microsoft#558) * Add InitializeAsync to ITelemetryService * Add test for initialization. * Fix build break from updating ITelemetryService * Initialize TelemetryService in main method. * Update CHANGELOG. * Update core/Azure.Mcp.Core/src/Services/Telemetry/TelemetryService.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update core/Azure.Mcp.Core/src/Services/Telemetry/TelemetryService.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Use MRES to synchronize access. * Add documentation to interface. * Add test case. * Add documentation to Program.cs * Initialize services * Correct CHANGELOG * Remove OperationTimeout * Change to use SemaphoreSlim * Add tests. * Fix test assertion * Fix formatting issue. * Fix another formatting issue. * Change from ValueTask To Task --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
Currently we are explicitly setting
Activity.Currentdue to the async flow ofITelemetryService. This changes theStartActivityto synchronous.References: dotnet/runtime#30915 (comment)
GitHub issue number?
Pre-merge Checklist
servers/Azure.Mcp.Server/CHANGELOG.mdand/orservers/Fabric.Mcp.Server/CHANGELOG.mdfor product changes (features, bug fixes, UI/UX, updated dependencies)servers/Azure.Mcp.Server/README.mdand/orservers/Fabric.Mcp.Server/README.mddocumentation/docs/azmcp-commands.mdand/or/docs/fabric-commands.mdToolDescriptionEvaluatorand obtained a score of0.4or more and a top 3 ranking for all related test prompts/docs/e2eTestPrompts.mdcrypto mining, spam, data exfiltration, etc.)/azp run mcp - pullrequest - liveto run Live Test Pipeline