11// Copyright (c) Microsoft Corporation.
22// Licensed under the MIT License.
33
4- using System . Reflection ;
54using System . Runtime . InteropServices ;
65using Azure . Mcp . Core . Configuration ;
76using 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