Skip to content

Commit 5c33b01

Browse files
committed
Fix build breaks from rebase.
1 parent f7abb2b commit 5c33b01

File tree

2 files changed

+11
-62
lines changed

2 files changed

+11
-62
lines changed

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,13 @@ public static void ConfigureMcpServerOptions(this IServiceCollection services)
272272
var isStdioTransport = string.IsNullOrEmpty(transport)
273273
|| string.Equals(transport, TransportTypes.StdIo, StringComparison.OrdinalIgnoreCase);
274274

275-
options.Version = GetServerVersion(Assembly.GetEntryAssembly());
275+
var entryAssembly = Assembly.GetEntryAssembly();
276+
if (entryAssembly == null)
277+
{
278+
throw new InvalidOperationException("Should be a managed assembly as entry assembly.");
279+
}
280+
281+
options.Version = GetServerVersion(entryAssembly);
276282
options.ApplicationInsightsConnectionString = applicationInsightsString;
277283

278284
// if transport is not set (default to stdio) or is set to stdio, enable telemetry
@@ -291,20 +297,15 @@ public static void ConfigureMcpServerOptions(this IServiceCollection services)
291297
/// https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/System.ClientModel/src/Pipeline/UserAgentPolicy.cs#L91
292298
/// For example, an informational version of "6.14.0-rc.116+54d611f7" will return "6.14.0-rc.116"
293299
/// </summary>
294-
/// <param name="callerAssembly">The caller assembly to extract name and version information from.</param>
300+
/// <param name="entryAssembly">The caller assembly to extract name and version information from.</param>
295301
/// <returns>A version string.</returns>
296-
internal static string GetServerVersion(Assembly? callerAssembly)
302+
internal static string GetServerVersion(Assembly entryAssembly)
297303
{
298-
if (callerAssembly == null)
299-
{
300-
throw new InvalidOperationException("Should be a managed assembly as entry assembly.");
301-
}
302-
303-
AssemblyInformationalVersionAttribute? versionAttribute = callerAssembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
304+
AssemblyInformationalVersionAttribute? versionAttribute = entryAssembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
304305
if (versionAttribute == null)
305306
{
306307
throw new InvalidOperationException(
307-
$"{nameof(AssemblyInformationalVersionAttribute)} is required on client SDK assembly '{callerAssembly.FullName}'.");
308+
$"{nameof(AssemblyInformationalVersionAttribute)} is required on client SDK assembly '{entryAssembly.FullName}'.");
308309
}
309310

310311
string version = versionAttribute.InformationalVersion;

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

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

4-
using System.Reflection;
54
using System.Runtime.InteropServices;
65
using Azure.Mcp.Core.Configuration;
76
using Azure.Mcp.Core.Services.Telemetry;
@@ -24,30 +23,6 @@ public static class OpenTelemetryExtensions
2423
public static void ConfigureTelemetryServices(this IServiceCollection services,
2524
IHostEnvironment hostEnvironment, IConfiguration configuration)
2625
{
27-
services.AddOptions<AzureMcpServerConfiguration>()
28-
.Configure<IOptions<ServiceStartOptions>>((options, serviceStartOptions) =>
29-
{
30-
// Assembly.GetEntryAssembly is used to retrieve the version of the server application as that is
31-
// the assembly that will run the tool calls.
32-
var entryAssembly = Assembly.GetEntryAssembly();
33-
if (entryAssembly != null)
34-
{
35-
options.Version = GetServerVersion(entryAssembly);
36-
}
37-
38-
var collectTelemetry = Environment.GetEnvironmentVariable("AZURE_MCP_COLLECT_TELEMETRY");
39-
40-
var transport = serviceStartOptions.Value.Transport;
41-
42-
bool isTelemetryEnabledEnvironment = string.IsNullOrEmpty(collectTelemetry) || (bool.TryParse(collectTelemetry, out var shouldCollect) && shouldCollect);
43-
44-
bool isStdioTransport = string.IsNullOrEmpty(transport) || string.Equals(transport, "stdio", StringComparison.OrdinalIgnoreCase);
45-
46-
// if transport is not set (default to stdio) or is set to stdio, enable telemetry
47-
// telemetry is disabled for HTTP transport
48-
options.IsTelemetryEnabled = isTelemetryEnabledEnvironment && isStdioTransport;
49-
});
50-
5126
services.AddSingleton<ITelemetryService, TelemetryService>();
5227

5328
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
@@ -167,31 +142,4 @@ private static void ConfigureOpenTelemetry(this IServiceCollection services,
167142
}
168143
});
169144
}
170-
171-
/// <summary>
172-
/// Gets the version information for the server. Uses logic from Azure SDK for .NET to generate the same version string.
173-
/// https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/System.ClientModel/src/Pipeline/UserAgentPolicy.cs#L91
174-
/// For example, an informational version of "6.14.0-rc.116+54d611f7" will return "6.14.0-rc.116"
175-
/// </summary>
176-
/// <param name="entryAssembly">The entry assembly to extract name and version information from.</param>
177-
/// <returns>A version string.</returns>
178-
internal static string GetServerVersion(Assembly entryAssembly)
179-
{
180-
AssemblyInformationalVersionAttribute? versionAttribute = entryAssembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
181-
if (versionAttribute == null)
182-
{
183-
throw new InvalidOperationException(
184-
$"{nameof(AssemblyInformationalVersionAttribute)} is required on client SDK assembly '{entryAssembly.FullName}'.");
185-
}
186-
187-
string version = versionAttribute.InformationalVersion;
188-
189-
int hashSeparator = version.IndexOf('+');
190-
if (hashSeparator != -1)
191-
{
192-
version = version.Substring(0, hashSeparator);
193-
}
194-
195-
return version;
196-
}
197145
}

0 commit comments

Comments
 (0)