|
1 | 1 | using System.Security.Claims; |
| 2 | +using System.Runtime.InteropServices; |
2 | 3 | using System.Threading.RateLimiting; |
3 | 4 | using ModelContextProtocol.Protocol; |
4 | 5 | using EssentialCSharp.Chat.Common.Extensions; |
@@ -51,6 +52,8 @@ private static void Main(string[] args) |
51 | 52 | string? appInsightsConnectionString = builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"]; |
52 | 53 | bool useAzureMonitor = !string.IsNullOrWhiteSpace(appInsightsConnectionString); |
53 | 54 | bool useOtlp = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]); |
| 55 | + bool profilerSupportedPlatform = OperatingSystem.IsWindows() || OperatingSystem.IsLinux(); |
| 56 | + bool profilerSkippedUnsupportedPlatform = false; |
54 | 57 |
|
55 | 58 | builder.Logging.AddOpenTelemetry(logging => |
56 | 59 | { |
@@ -91,7 +94,15 @@ private static void Main(string[] args) |
91 | 94 | }); |
92 | 95 |
|
93 | 96 | if (useAzureMonitor) |
94 | | - otel.UseAzureMonitor().AddAzureMonitorProfiler(); |
| 97 | + { |
| 98 | + // Azure Monitor export is supported cross-platform, but the profiler currently only |
| 99 | + // supports Windows and Linux. |
| 100 | + var azureMonitor = otel.UseAzureMonitor(); |
| 101 | + if (profilerSupportedPlatform) |
| 102 | + azureMonitor.AddAzureMonitorProfiler(); |
| 103 | + else |
| 104 | + profilerSkippedUnsupportedPlatform = true; |
| 105 | + } |
95 | 106 | else if (useOtlp) |
96 | 107 | otel.UseOtlpExporter(); |
97 | 108 |
|
@@ -127,6 +138,8 @@ private static void Main(string[] args) |
127 | 138 | var loggerFactory = LoggerFactory.Create(loggingBuilder => |
128 | 139 | loggingBuilder.AddConsole().SetMinimumLevel(LogLevel.Information)); |
129 | 140 | var initialLogger = loggerFactory.CreateLogger<Program>(); |
| 141 | + if (profilerSkippedUnsupportedPlatform) |
| 142 | + LogSkippingUnsupportedAzureMonitorProfiler(initialLogger, RuntimeInformation.OSDescription); |
130 | 143 |
|
131 | 144 | builder.Services.AddDbContext<EssentialCSharpWebContext>(options => options.UseSqlServer(connectionString, sql => sql.EnableRetryOnFailure(5))); |
132 | 145 |
|
@@ -623,4 +636,7 @@ private static bool IsMcpTransportRequest(HttpRequest request) => |
623 | 636 |
|
624 | 637 | [LoggerMessage(Level = LogLevel.Warning, Message = "Ignoring invalid TryDotNet origin in CSP: {Origin}")] |
625 | 638 | private static partial void LogIgnoringInvalidTryDotNetOrigin(ILogger logger, string origin); |
| 639 | + |
| 640 | + [LoggerMessage(Level = LogLevel.Warning, Message = "Azure Monitor profiler is not supported on this platform ({Platform}). Skipping profiler registration and continuing with Azure Monitor telemetry export.")] |
| 641 | + private static partial void LogSkippingUnsupportedAzureMonitorProfiler(ILogger<Program> logger, string platform); |
626 | 642 | } |
0 commit comments