@@ -44,131 +44,44 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
4444 {
4545 webBuilder . UseSentry ( options =>
4646 {
47- //options.MinimumBreadcrumbLevel = LogEventLevel.Debug;
48- //options.MinimumEventLevel = LogEventLevel.Error;
4947 options . Dsn = ExternalErrorConfig . ExternalErrorServiceUrlForMcp ;
5048 options . AttachStacktrace = true ;
5149 options . SendDefaultPii = true ;
5250 options . AutoSessionTracking = true ;
53-
54- //if (ExternalErrorConfig.SentryPerfSampleRate > 0)
55- // options.EnableTracing = true;
56-
5751 options . TracesSampleRate = ExternalErrorConfig . SentryPerfSampleRate ;
5852 options . Environment = ExternalErrorConfig . Environment ;
59- options . Release = Assembly . GetEntryAssembly ( ) . GetName ( ) . Version . ToString ( ) ;
53+ options . Release = Assembly . GetEntryAssembly ( ) ? . GetName ( ) . Version ? . ToString ( ) ;
6054 options . ProfilesSampleRate = ExternalErrorConfig . SentryProfilingSampleRate ;
6155
62- // Requires NuGet package: Sentry.Profiling
63- // Note: By default, the profiler is initialized asynchronously. This can be tuned by passing a desired initialization timeout to the constructor.
64- options . AddIntegration ( new ProfilingIntegration (
65- // During startup, wait up to 500ms to profile the app startup code. This could make launching the app a bit slower so comment it out if your prefer profiling to start asynchronously
66- //TimeSpan.FromMilliseconds(500)
67- ) ) ;
56+ // Add profiling integration
57+ options . AddIntegration ( new ProfilingIntegration ( ) ) ;
6858
69- options . TracesSampler = samplingContext =>
70- {
71- if ( samplingContext != null && samplingContext . CustomSamplingContext != null )
59+ options . TracesSampler = samplingContext =>
7260 {
73- if ( samplingContext . CustomSamplingContext . TryGetValue ( "__HttpPath" , out var httpPath ) )
61+ if ( samplingContext ? . CustomSamplingContext != null )
7462 {
75- var pathValue = httpPath ? . ToString ( ) ;
76- if ( string . Equals ( pathValue , "/health/getcurrent" , StringComparison . OrdinalIgnoreCase ) )
63+ if ( samplingContext . CustomSamplingContext . TryGetValue ( "__HttpPath" , out var httpPath ) )
7764 {
78- return 0 ;
65+ var pathValue = httpPath ? . ToString ( ) ;
66+ if ( string . Equals ( pathValue , "/health/getcurrent" , StringComparison . OrdinalIgnoreCase ) )
67+ {
68+ return 0 ;
69+ }
7970 }
8071 }
81- }
8272
83- return ExternalErrorConfig . SentryPerfSampleRate ;
84- } ;
73+ return ExternalErrorConfig . SentryPerfSampleRate ;
74+ } ;
8575 } ) ;
8676 }
8777
8878 webBuilder . UseKestrel ( serverOptions =>
8979 {
9080 // Configure Kestrel to listen on a specific port for health checks
91- serverOptions . ListenAnyIP ( 5050 ) ; // Health check port
92- } ) ;
93- webBuilder . Configure ( app =>
94- {
95- app . UseRouting ( ) ;
96- app . UseSentryTracing ( ) ;
97- app . UseEndpoints ( endpoints =>
98- {
99- endpoints . MapControllers ( ) ;
100- } ) ;
81+ serverOptions . ListenAnyIP ( 5050 ) ;
10182 } ) ;
102- } )
103- . ConfigureAppConfiguration ( ( _ , config ) =>
104- {
105- config . SetBasePath ( Directory . GetCurrentDirectory ( ) )
106- . AddJsonFile ( "appsettings.json" , optional : true , reloadOnChange : false )
107- . AddEnvironmentVariables ( )
108- . AddCommandLine ( args ) ;
109- } )
110- . ConfigureServices ( ( hostContext , services ) =>
111- {
112- var configuration = hostContext . Configuration ;
113-
114- // Configuration is already loaded in ConfigureWebHostDefaults
115- // Initialize Resgrid logging framework with Sentry if available
116- if ( ! string . IsNullOrWhiteSpace ( ExternalErrorConfig . ExternalErrorServiceUrlForMcp ) )
117- {
118- Framework . Logging . Initialize ( ExternalErrorConfig . ExternalErrorServiceUrlForMcp ) ;
119- }
120-
121- // Register MCP server
122- services . AddHostedService < McpServerHost > ( ) ;
123-
124- // Add MVC controllers for health check endpoint
125- services . AddControllers ( )
126- . AddNewtonsoftJson ( ) ;
127-
128- // Register infrastructure services
129- services . AddMemoryCache ( ) ;
130- services . AddSingleton < Infrastructure . IResponseCache , Infrastructure . ResponseCache > ( ) ;
131- services . AddSingleton < Infrastructure . IRateLimiter , Infrastructure . RateLimiter > ( ) ;
132- services . AddSingleton < Infrastructure . ITokenRefreshService , Infrastructure . TokenRefreshService > ( ) ;
133- services . AddSingleton < Infrastructure . IAuditLogger , Infrastructure . AuditLogger > ( ) ;
134-
135- // Validate required API configuration from SystemBehaviorConfig
136- if ( string . IsNullOrWhiteSpace ( SystemBehaviorConfig . ResgridApiBaseUrl ) )
137- {
138- throw new InvalidOperationException (
139- "SystemBehaviorConfig.ResgridApiBaseUrl is required but not configured. " +
140- "Configure this setting via the Resgrid configuration file or environment variables (RESGRID:SystemBehaviorConfig:ResgridApiBaseUrl)." ) ;
141- }
142-
143- // Register HTTP client for API calls with connection pooling
144- services . AddHttpClient ( "ResgridApi" , client =>
145- {
146- client . BaseAddress = new Uri ( SystemBehaviorConfig . ResgridApiBaseUrl ) ;
147- client . DefaultRequestHeaders . Add ( "Accept" , "application/json" ) ;
148- client . Timeout = TimeSpan . FromSeconds ( 30 ) ;
149- } )
150- . ConfigurePrimaryHttpMessageHandler ( ( ) => new System . Net . Http . SocketsHttpHandler
151- {
152- PooledConnectionLifetime = TimeSpan . FromMinutes ( 5 ) ,
153- PooledConnectionIdleTimeout = TimeSpan . FromMinutes ( 2 ) ,
154- MaxConnectionsPerServer = 10
155- } ) ;
156-
157- // Register API client
158- services . AddSingleton < IApiClient , ApiClient > ( ) ;
15983
160- // Register tool providers
161- services . AddSingleton < Tools . AuthenticationToolProvider > ( ) ;
162- services . AddSingleton < Tools . CallsToolProvider > ( ) ;
163- services . AddSingleton < Tools . DispatchToolProvider > ( ) ;
164- services . AddSingleton < Tools . PersonnelToolProvider > ( ) ;
165- services . AddSingleton < Tools . UnitsToolProvider > ( ) ;
166- services . AddSingleton < Tools . MessagesToolProvider > ( ) ;
167- services . AddSingleton < Tools . CalendarToolProvider > ( ) ;
168- services . AddSingleton < Tools . ShiftsToolProvider > ( ) ;
169- services . AddSingleton < Tools . InventoryToolProvider > ( ) ;
170- services . AddSingleton < Tools . ReportsToolProvider > ( ) ;
171- services . AddSingleton < McpToolRegistry > ( ) ;
84+ webBuilder . UseStartup < Startup > ( ) ;
17285 } ) ;
17386 }
17487}
0 commit comments