Skip to content

Commit 737a7ef

Browse files
authored
Disable telemetry for HTTP transport (#1072)
* Disable telemetry when server runs in HTTP mode * pr feedback * move telemetry disabling logic to OpenTelemetryExtensions * improve readability * Update changelog
1 parent f22d0f6 commit 737a7ef

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

core/Azure.Mcp.Core/src/Areas/Server/Commands/ServiceStartCommand.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
using Microsoft.Extensions.Logging;
2020
using Microsoft.Extensions.Options;
2121
using Microsoft.Identity.Web;
22-
using Microsoft.IdentityModel.Tokens;
2322
using OpenTelemetry.Logs;
2423
using OpenTelemetry.Metrics;
2524
using OpenTelemetry.Trace;

core/Azure.Mcp.Core/src/Extensions/OpenTelemetryExtensions.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33

44
using System.Reflection;
55
using System.Runtime.InteropServices;
6+
using Azure.Mcp.Core.Areas.Server.Options;
67
using Azure.Mcp.Core.Configuration;
78
using Azure.Mcp.Core.Services.Telemetry;
8-
using Azure.Monitor.OpenTelemetry.Exporter;
99
using Microsoft.Extensions.Azure;
1010
using Microsoft.Extensions.DependencyInjection;
1111
using Microsoft.Extensions.Logging;
1212
using Microsoft.Extensions.Options;
13-
using OpenTelemetry;
1413
using OpenTelemetry.Logs;
1514
using OpenTelemetry.Metrics;
1615
using OpenTelemetry.Resources;
@@ -25,14 +24,21 @@ public static class OpenTelemetryExtensions
2524
public static void ConfigureOpenTelemetry(this IServiceCollection services)
2625
{
2726
services.AddOptions<AzureMcpServerConfiguration>()
28-
.Configure(options =>
27+
.Configure<IOptions<ServiceStartOptions>>((options, serviceStartOptions) =>
2928
{
3029
options.Version = GetServerVersion(Assembly.GetCallingAssembly());
3130

3231
var collectTelemetry = Environment.GetEnvironmentVariable("AZURE_MCP_COLLECT_TELEMETRY");
3332

34-
options.IsTelemetryEnabled = string.IsNullOrEmpty(collectTelemetry)
35-
|| (bool.TryParse(collectTelemetry, out var shouldCollect) && shouldCollect);
33+
var transport = serviceStartOptions.Value.Transport;
34+
35+
bool isTelemetryEnabledEnvironment = string.IsNullOrEmpty(collectTelemetry) || (bool.TryParse(collectTelemetry, out var shouldCollect) && shouldCollect);
36+
37+
bool isStdioTransport = string.IsNullOrEmpty(transport) || string.Equals(transport, "stdio", StringComparison.OrdinalIgnoreCase);
38+
39+
// if transport is not set (default to stdio) or is set to stdio, enable telemetry
40+
// telemetry is disabled for HTTP transport
41+
options.IsTelemetryEnabled = isTelemetryEnabledEnvironment && isStdioTransport;
3642
});
3743

3844
services.AddSingleton<ITelemetryService, TelemetryService>();

servers/Azure.Mcp.Server/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ The Azure MCP Server updates automatically by default whenever a new release com
3535
- Updates `AzureMcpServerConfiguration.Version` to use value from `AssemblyInformationalVersionAttribute` rather than file version to support semver conventions such as -beta.1. [[#1040](https://github.com/microsoft/mcp/pull/1040)]
3636
- Added a `CancellationToken` parameter `IBaseCommand.ExecuteAsync()` [[#1056](https://github.com/microsoft/mcp/pull/1056)]
3737
- Added a `CancellationToken` parameter to async methods to many, but not yet all, `I[SomeService]` interfaces [[#1056](https://github.com/microsoft/mcp/pull/1056)]
38+
- Disabled telemetry for HTTP transport [[#1072](https://github.com/microsoft/mcp/pull/1072)]
3839

3940
## 2.0.0-beta.1 (2025-10-29)
4041

servers/Azure.Mcp.Server/src/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"profiles": {
44
"debug-remotemcp": {
55
"commandName": "Project",
6-
"commandLineArgs": "server start --run-as-remote-http-service --outgoing-auth-strategy UseHostingEnvironmentIdentity",
6+
"commandLineArgs": "server start --transport http --outgoing-auth-strategy UseHostingEnvironmentIdentity",
77
"dotnetRunMessages": true,
88
"environmentVariables": {
99
"ASPNETCORE_ENVIRONMENT": "Development",

0 commit comments

Comments
 (0)