Skip to content
This repository was archived by the owner on Sep 4, 2025. It is now read-only.

Commit 45be151

Browse files
authored
Add DevDeviceId (#810)
* Add information providers to get device id and mac address * Remove MacAddress from server configuration * Add DeviceId tag name * Remove unneeded Sha helper * Changing StartActivity to ValueTask * Fixing break from removing in Configuration * Add tests for MachineInformationProviderBase * Make GetStoragePath() public * Implement IMachineInformationProvider interface * Fix tests to use IMachineInformationProvider. * Register Machine Information Provider based on runtime. * TelemetryService uses interface. * Add InternalsVisibleTo so internal interfaces can be mocked. * Add UnixInformationProviderTests * Start initialize task * Replace mock with instantiated class. * Add MIT header. * Remove Directory existence check * Use special folder instead of getting a set env var. * Add DefaultMachineInformation. * Use DefaultMachineInformation if os does not match existing ones.
1 parent 5dea2ef commit 45be151

28 files changed

+1079
-70
lines changed

.vscode/cspell.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
"datname",
9393
"descired",
9494
"devcert",
95+
"deviceid",
9596
"doubleslash",
9697
"dyld",
9798
"eastus",
@@ -105,6 +106,8 @@
105106
"globaltool",
106107
"glsl",
107108
"Groq",
109+
"HKCU",
110+
"HKEY_CURRENT_USER",
108111
"hotmail",
109112
"Intune",
110113
"kcsb",

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ The Azure MCP Server updates automatically by default whenever a new release com
99
- Added support for providing the `--content-type` and `--tags` properties to the `azmcp-appconfig-kv-set` command. [[#459](https://github.com/Azure/azure-mcp/pull/459)]
1010
- Added `filter-path` and `recursive` capabilities to `azmcp-storage-datalake-file-system-list-paths`. [[#770](https://github.com/Azure/azure-mcp/issues/770)]
1111
- Added support for listing files and directories in Azure File Shares via the `azmcp-storage-share-file-list` command. This command recursively lists all items in a specified file share directory with metadata including size, last modified date, and content type. [[#793](https://github.com/Azure/azure-mcp/pull/793)]
12-
1312
- Added support for Azure Virtual Desktop with new commands:
1413
- `azmcp-virtualdesktop-hostpool-list` - List all host pools in a subscription
1514
- `azmcp-virtualdesktop-sessionhost-list` - List all session hosts in a host pool
1615
- `azmcp-virtualdesktop-sessionhost-usersession-list` - List all user sessions on a specific session host
16+
- Added support for creating and publishing DevDeviceId in telemetry. [[#810](https://github.com/Azure/azure-mcp/pull/810/)]
1717

1818
### Breaking Changes
1919

core/src/AzureMcp.Core/Areas/Server/Commands/Runtime/McpRuntime.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public McpRuntime(
5555
/// <returns>A result containing the output of the tool invocation.</returns>
5656
public async ValueTask<CallToolResult> CallToolHandler(RequestContext<CallToolRequestParams> request, CancellationToken cancellationToken)
5757
{
58-
using var activity = _telemetry.StartActivity(ActivityName.ToolExecuted, request?.Server?.ClientInfo);
58+
using var activity = await _telemetry.StartActivity(ActivityName.ToolExecuted, request?.Server?.ClientInfo);
5959

6060
if (request?.Params == null)
6161
{
@@ -84,7 +84,7 @@ public async ValueTask<CallToolResult> CallToolHandler(RequestContext<CallToolRe
8484
/// <returns>A result containing the list of available tools.</returns>
8585
public async ValueTask<ListToolsResult> ListToolsHandler(RequestContext<ListToolsRequestParams> request, CancellationToken cancellationToken)
8686
{
87-
using var activity = _telemetry.StartActivity(nameof(ListToolsHandler), request?.Server?.ClientInfo);
87+
using var activity = await _telemetry.StartActivity(nameof(ListToolsHandler), request?.Server?.ClientInfo);
8888
return await _toolLoader.ListToolsHandler(request!, cancellationToken);
8989
}
9090

core/src/AzureMcp.Core/Areas/Server/Commands/ToolLoading/CommandFactoryToolLoader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public ValueTask<ListToolsResult> ListToolsHandler(RequestContext<ListToolsReque
6565
/// <returns>The result of the tool call operation.</returns>
6666
public async ValueTask<CallToolResult> CallToolHandler(RequestContext<CallToolRequestParams> request, CancellationToken cancellationToken)
6767
{
68-
using var activity = _telemetry.StartActivity(ActivityName.ToolExecuted, request.Server.ClientInfo);
68+
using var activity = await _telemetry.StartActivity(ActivityName.ToolExecuted, request.Server.ClientInfo);
6969

7070
if (request.Params == null)
7171
{

core/src/AzureMcp.Core/AssemblyInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
[assembly: InternalsVisibleTo("AzureMcp.Core.UnitTests")]
77
[assembly: InternalsVisibleTo("AzureMcp.Core.LiveTests")]
88
[assembly: InternalsVisibleTo("AzureMcp.Tests")]
9+
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]

core/src/AzureMcp.Core/Commands/CommandFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ private void ConfigureCommandHandler(Command command, IBaseCommand implementatio
150150
{
151151
_logger.LogTrace("Executing '{Command}'.", command.Name);
152152

153-
using var activity = _telemetryService.StartActivity(ActivityName.CommandExecuted);
153+
using var activity = await _telemetryService.StartActivity(ActivityName.CommandExecuted);
154154

155155
var cmdContext = new CommandContext(_serviceProvider, activity);
156156
var startTime = DateTime.UtcNow;

core/src/AzureMcp.Core/Configuration/AzureMcpServerConfiguration.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,4 @@ public class AzureMcpServerConfiguration
1212
public string Version { get; set; } = "1.0.0-beta";
1313

1414
public bool IsTelemetryEnabled { get; set; } = true;
15-
16-
public string MacAddressHash { get; set; } = string.Empty;
1715
}

core/src/AzureMcp.Core/Extensions/OpenTelemetryExtensions.cs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
using System.Net.NetworkInformation;
54
using System.Reflection;
5+
using System.Runtime.InteropServices;
66
using Azure.Monitor.OpenTelemetry.Exporter;
77
using AzureMcp.Core.Configuration;
8-
using AzureMcp.Core.Helpers;
98
using AzureMcp.Core.Services.Telemetry;
109
using Microsoft.Extensions.Azure;
1110
using Microsoft.Extensions.DependencyInjection;
@@ -36,22 +35,27 @@ public static void ConfigureOpenTelemetry(this IServiceCollection services)
3635

3736
options.IsTelemetryEnabled = string.IsNullOrEmpty(collectTelemetry)
3837
|| (bool.TryParse(collectTelemetry, out var shouldCollect) && shouldCollect);
39-
40-
if (options.IsTelemetryEnabled)
41-
{
42-
var address = NetworkInterface.GetAllNetworkInterfaces()
43-
.Where(x => x.OperationalStatus == OperationalStatus.Up && x.NetworkInterfaceType != NetworkInterfaceType.Loopback)
44-
.Select(x => x.GetPhysicalAddress().ToString())
45-
.FirstOrDefault(x => !string.IsNullOrEmpty(x));
46-
47-
options.MacAddressHash = address != null
48-
? Sha256Helper.GetHashedValue(address)
49-
: "N/A";
50-
}
5138
});
5239

5340
services.AddSingleton<ITelemetryService, TelemetryService>();
5441

42+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
43+
{
44+
services.AddSingleton<IMachineInformationProvider, WindowsMachineInformationProvider>();
45+
}
46+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
47+
{
48+
services.AddSingleton<IMachineInformationProvider, MacOSXMachineInformationProvider>();
49+
}
50+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
51+
{
52+
services.AddSingleton<IMachineInformationProvider, LinuxMachineInformationProvider>();
53+
}
54+
else
55+
{
56+
services.AddSingleton<IMachineInformationProvider, DefaultMachineInformationProvider>();
57+
}
58+
5559
EnableAzureMonitor(services);
5660
}
5761

core/src/AzureMcp.Core/Helpers/Sha256Helper.cs

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
using Microsoft.Extensions.Logging;
5+
6+
namespace AzureMcp.Core.Services.Telemetry;
7+
8+
/// <summary>
9+
/// Default information provider not tied to any platform specification for DevDeviceId.
10+
/// </summary>
11+
internal class DefaultMachineInformationProvider(ILogger<MachineInformationProviderBase> logger)
12+
: MachineInformationProviderBase(logger)
13+
{
14+
/// <summary>
15+
/// Returns null.
16+
/// </summary>
17+
/// <returns></returns>
18+
public override Task<string?> GetOrCreateDeviceId() => Task.FromResult<string?>(null);
19+
}

0 commit comments

Comments
 (0)