Skip to content

Remove setting value of Activity.Current in telemetry service by removing async StartActivity.#558

Merged
conniey merged 20 commits intomicrosoft:mainfrom
conniey:async-telemetry-initialization
Oct 10, 2025
Merged

Remove setting value of Activity.Current in telemetry service by removing async StartActivity.#558
conniey merged 20 commits intomicrosoft:mainfrom
conniey:async-telemetry-initialization

Conversation

@conniey
Copy link
Copy Markdown
Member

@conniey conniey commented Sep 24, 2025

What does this PR do?

Currently we are explicitly setting Activity.Current due to the async flow of ITelemetryService. This changes the StartActivity to synchronous.

References: dotnet/runtime#30915 (comment)

GitHub issue number?

Pre-merge Checklist

  • Required for All PRs
    • Read contribution guidelines
    • PR title clearly describes the change
    • Commit history is clean with descriptive messages (cleanup guide)
    • Added comprehensive tests for new/modified functionality
    • Updated servers/Azure.Mcp.Server/CHANGELOG.md and/or servers/Fabric.Mcp.Server/CHANGELOG.md for product changes (features, bug fixes, UI/UX, updated dependencies)
  • For MCP tool changes:
    • One tool per PR: This PR adds or modifies only one MCP tool for faster review cycles
    • Updated servers/Azure.Mcp.Server/README.md and/or servers/Fabric.Mcp.Server/README.md documentation
    • Updated command list in /docs/azmcp-commands.md and/or /docs/fabric-commands.md
    • For new or modified tool descriptions, ran ToolDescriptionEvaluator and obtained a score of 0.4 or more and a top 3 ranking for all related test prompts
  • Extra steps for Azure MCP Server tool changes:
    • Updated test prompts in /docs/e2eTestPrompts.md
    • 👉 For Community (non-Microsoft team member) PRs:
      • Security review: Reviewed code for security vulnerabilities, malicious code, or suspicious activities before running tests (crypto mining, spam, data exfiltration, etc.)
      • Manual tests run: added comment /azp run mcp - pullrequest - live to run Live Test Pipeline

@conniey conniey requested a review from a team as a code owner September 24, 2025 18:40
Copilot AI review requested due to automatic review settings September 24, 2025 18:52
Copy link
Copy Markdown
Contributor

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 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.StartActivity methods from async to sync
  • Adding explicit initialization requirement through InitializeAsync()
  • Removing manual Activity.Current assignment 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

Comment thread core/Azure.Mcp.Core/src/Services/Telemetry/TelemetryService.cs Outdated
Comment thread core/Azure.Mcp.Core/src/Services/Telemetry/TelemetryService.cs Outdated
Comment thread core/Azure.Mcp.Core/src/Services/Telemetry/TelemetryService.cs Outdated
Comment thread core/Azure.Mcp.Core/src/Services/Telemetry/TelemetryService.cs Outdated
Comment thread core/Azure.Mcp.Core/src/Services/Telemetry/TelemetryService.cs Outdated
Comment thread core/Azure.Mcp.Core/src/Services/Telemetry/TelemetryService.cs Outdated
@github-project-automation github-project-automation Bot moved this from Untriaged to In Progress in Azure MCP Server Sep 25, 2025
@conniey conniey force-pushed the async-telemetry-initialization branch 2 times, most recently from 4880789 to dded110 Compare October 7, 2025 15:01
@conniey conniey requested a review from vukelich October 8, 2025 12:41
Comment thread servers/Azure.Mcp.Server/CHANGELOG.md Outdated
Comment thread core/Azure.Mcp.Core/src/Services/Telemetry/ITelemetryService.cs Outdated
Comment thread core/Azure.Mcp.Core/src/Services/Telemetry/ITelemetryService.cs Outdated
Comment thread core/Azure.Mcp.Core/src/Services/Telemetry/TelemetryService.cs Outdated
Comment thread core/Azure.Mcp.Core/src/Services/Telemetry/TelemetryService.cs Outdated
@conniey conniey force-pushed the async-telemetry-initialization branch from 71f010f to 2b6f61c Compare October 10, 2025 16:32
Comment thread core/Azure.Mcp.Core/src/Services/Telemetry/ITelemetryService.cs Outdated
@conniey conniey merged commit 6f9c52b into microsoft:main Oct 10, 2025
26 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Azure MCP Server Oct 10, 2025
@conniey conniey deleted the async-telemetry-initialization branch October 10, 2025 19:55
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants