|
9 | 9 | using Resgrid.Web.Tts.Configuration; |
10 | 10 | using Resgrid.Web.Tts.Health; |
11 | 11 | using Resgrid.Web.Tts.Services; |
| 12 | +using System.Reflection; |
12 | 13 | using System.Text.Json; |
13 | 14 | using System.Threading.RateLimiting; |
| 15 | +using Sentry.Profiling; |
14 | 16 |
|
15 | 17 | var builder = WebApplication.CreateBuilder(args); |
16 | 18 |
|
17 | 19 | ConfigProcessor.LoadAndProcessConfig(builder.Configuration["AppOptions:ConfigPath"]); |
18 | 20 | ConfigProcessor.LoadAndProcessEnvVariables(builder.Configuration.AsEnumerable()); |
19 | 21 |
|
| 22 | +// Configure Sentry error tracking and performance monitoring |
| 23 | +if (!string.IsNullOrWhiteSpace(ExternalErrorConfig.ExternalErrorServiceUrlForTts)) |
| 24 | +{ |
| 25 | + builder.WebHost.UseSentry(options => |
| 26 | + { |
| 27 | + options.Dsn = ExternalErrorConfig.ExternalErrorServiceUrlForTts; |
| 28 | + options.AttachStacktrace = true; |
| 29 | + options.SendDefaultPii = true; |
| 30 | + options.AutoSessionTracking = true; |
| 31 | + options.TracesSampleRate = ExternalErrorConfig.SentryPerfSampleRate; |
| 32 | + options.Environment = ExternalErrorConfig.Environment; |
| 33 | + options.Release = Assembly.GetEntryAssembly()?.GetName().Version?.ToString(); |
| 34 | + options.ProfilesSampleRate = ExternalErrorConfig.SentryProfilingSampleRate; |
| 35 | + |
| 36 | + // Add profiling integration for performance tracing |
| 37 | + options.AddIntegration(new ProfilingIntegration()); |
| 38 | + |
| 39 | + options.TracesSampler = samplingContext => |
| 40 | + { |
| 41 | + if (samplingContext?.CustomSamplingContext != null) |
| 42 | + { |
| 43 | + if (samplingContext.CustomSamplingContext.TryGetValue("__HttpPath", out var httpPath)) |
| 44 | + { |
| 45 | + var pathValue = httpPath?.ToString(); |
| 46 | + if (string.Equals(pathValue, "/health", StringComparison.OrdinalIgnoreCase) || |
| 47 | + string.Equals(pathValue, "/livez", StringComparison.OrdinalIgnoreCase) || |
| 48 | + string.Equals(pathValue, "/readyz", StringComparison.OrdinalIgnoreCase)) |
| 49 | + { |
| 50 | + return 0; |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + return ExternalErrorConfig.SentryPerfSampleRate; |
| 56 | + }; |
| 57 | + }); |
| 58 | +} |
| 59 | + |
20 | 60 | builder.Logging.ClearProviders(); |
21 | 61 | builder.Logging.AddJsonConsole(); |
22 | 62 |
|
|
0 commit comments