@@ -385,6 +385,7 @@ public void Initialize()
385
385
386
386
// Allow tests to modify anything initialized by host.json
387
387
ScriptConfig . OnConfigurationApplied ? . Invoke ( ScriptConfig ) ;
388
+ TraceWriter . Verbose ( "Host configuration applied." ) ;
388
389
389
390
// only after configuration has been applied and loggers have been created, raise the initializing event
390
391
HostInitializing ? . Invoke ( this , EventArgs . Empty ) ;
@@ -406,6 +407,7 @@ public void Initialize()
406
407
includeSubdirectories : false , changeTypes : WatcherChangeTypes . Created | WatcherChangeTypes . Changed ) ;
407
408
408
409
_debugModeFileWatcher . Changed += OnDebugModeFileChanged ;
410
+ TraceWriter . Verbose ( "Debug file watch initialized." ) ;
409
411
410
412
var storageString = AmbientConnectionStringProvider . Instance . GetConnectionString ( ConnectionStringNames . Storage ) ;
411
413
if ( storageString == null )
@@ -422,8 +424,12 @@ public void Initialize()
422
424
. Where ( f => string . Equals ( f . Source , EventSources . ScriptFiles , StringComparison . Ordinal ) )
423
425
. Subscribe ( e => OnFileChanged ( e . FileChangeArguments ) ) ;
424
426
427
+ TraceWriter . Verbose ( "File event source initialized." ) ;
428
+
425
429
// take a snapshot so we can detect function additions/removals
426
430
_directorySnapshot = Directory . EnumerateDirectories ( ScriptConfig . RootScriptPath ) . ToImmutableArray ( ) ;
431
+
432
+ TraceWriter . Verbose ( "Created directory snapshot." ) ;
427
433
}
428
434
429
435
// If a file change should result in a restart, we debounce the event to
@@ -437,45 +443,62 @@ public void Initialize()
437
443
_shutdown = Shutdown ;
438
444
_shutdown = _shutdown . Debounce ( 500 ) ;
439
445
440
- // Scan the function.json early to determine the binding extensions used
441
- var functionMetadata = ReadFunctionMetadata ( ScriptConfig , TraceWriter , _startupLogger , FunctionErrors , _settingsManager ) ;
446
+ Collection < FunctionMetadata > functionMetadata ;
447
+ using ( metricsLogger . LatencyEvent ( MetricEventNames . HostStartupReadFunctionMetadataLatency ) )
448
+ {
449
+ // Scan the function.json early to determine the binding extensions used
450
+ functionMetadata = ReadFunctionMetadata ( ScriptConfig , TraceWriter , _startupLogger , FunctionErrors , _settingsManager ) ;
451
+ TraceWriter . Verbose ( "Function metadata read." ) ;
452
+ }
453
+
442
454
var extensionLoader = new ExtensionLoader ( ScriptConfig , TraceWriter , _startupLogger ) ;
443
455
var usedBindingTypes = extensionLoader . DiscoverBindingTypes ( functionMetadata ) ;
444
456
445
457
var bindingProviders = LoadBindingProviders ( ScriptConfig , hostConfigObject , TraceWriter , _startupLogger , usedBindingTypes ) ;
446
458
ScriptConfig . BindingProviders = bindingProviders ;
459
+ TraceWriter . Verbose ( "Binding providers loaded." ) ;
447
460
448
461
var coreBinder = bindingProviders . OfType < CoreExtensionsScriptBindingProvider > ( ) . First ( ) ;
449
462
coreBinder . AppDirectory = ScriptConfig . RootScriptPath ;
450
463
451
464
// Allow BindingProviders to initialize
452
- foreach ( var bindingProvider in ScriptConfig . BindingProviders )
465
+ using ( metricsLogger . LatencyEvent ( MetricEventNames . HostStartupInitializeBindingProvidersLatency ) )
453
466
{
454
- try
467
+ foreach ( var bindingProvider in ScriptConfig . BindingProviders )
455
468
{
456
- bindingProvider . Initialize ( ) ;
457
- }
458
- catch ( Exception ex )
459
- {
460
- // If we're unable to initialize a binding provider for any reason, log the error
461
- // and continue
462
- string errorMsg = string . Format ( "Error initializing binding provider '{0}'" , bindingProvider . GetType ( ) . FullName ) ;
463
- TraceWriter . Error ( errorMsg , ex ) ;
464
- _startupLogger ? . LogError ( 0 , ex , errorMsg ) ;
469
+ try
470
+ {
471
+ bindingProvider . Initialize ( ) ;
472
+ }
473
+ catch ( Exception ex )
474
+ {
475
+ // If we're unable to initialize a binding provider for any reason, log the error
476
+ // and continue
477
+ string errorMsg = string . Format ( "Error initializing binding provider '{0}'" , bindingProvider . GetType ( ) . FullName ) ;
478
+ TraceWriter . Error ( errorMsg , ex ) ;
479
+ _startupLogger ? . LogError ( 0 , ex , errorMsg ) ;
480
+ }
465
481
}
482
+ TraceWriter . Verbose ( "Binding providers initialized." ) ;
466
483
}
484
+
467
485
extensionLoader . LoadBuiltinExtensions ( usedBindingTypes ) ;
468
486
469
487
var directTypes = GetDirectTypes ( functionMetadata ) ;
470
488
extensionLoader . LoadDirectlyReferencedExtensions ( directTypes ) ;
471
489
extensionLoader . LoadCustomExtensions ( ) ;
490
+ TraceWriter . Verbose ( "Extension loading complete." ) ;
472
491
473
492
// Now all extensions have been loaded, the metadata is finalized.
474
493
// There's a single script binding instance that services all extensions.
475
494
// give that script binding the metadata for all loaded extensions so it can dispatch to them.
476
- var generalProvider = ScriptConfig . BindingProviders . OfType < GeneralScriptBindingProvider > ( ) . First ( ) ;
477
- var metadataProvider = this . CreateMetadataProvider ( ) ;
478
- generalProvider . CompleteInitialization ( metadataProvider ) ;
495
+ using ( metricsLogger . LatencyEvent ( MetricEventNames . HostStartupCreateMetadataProviderLatency ) )
496
+ {
497
+ var generalProvider = ScriptConfig . BindingProviders . OfType < GeneralScriptBindingProvider > ( ) . First ( ) ;
498
+ var metadataProvider = this . CreateMetadataProvider ( ) ;
499
+ generalProvider . CompleteInitialization ( metadataProvider ) ;
500
+ TraceWriter . Verbose ( "Metadata provider created." ) ;
501
+ }
479
502
480
503
// Do this after we've loaded the custom extensions. That gives an extension an opportunity to plug in their own implementations.
481
504
if ( storageString != null )
@@ -504,7 +527,13 @@ public void Initialize()
504
527
} ;
505
528
506
529
// read all script functions and apply to JobHostConfiguration
507
- Collection < FunctionDescriptor > functions = GetFunctionDescriptors ( functionMetadata ) ;
530
+ Collection < FunctionDescriptor > functions ;
531
+ using ( metricsLogger . LatencyEvent ( MetricEventNames . HostStartupGetFunctionDescriptorsLatency ) )
532
+ {
533
+ functions = GetFunctionDescriptors ( functionMetadata ) ;
534
+ TraceWriter . Verbose ( "Function descriptors read." ) ;
535
+ }
536
+
508
537
Collection < CustomAttributeBuilder > typeAttributes = CreateTypeAttributes ( ScriptConfig ) ;
509
538
string typeName = string . Format ( CultureInfo . InvariantCulture , "{0}.{1}" , GeneratedTypeNamespace , GeneratedTypeName ) ;
510
539
@@ -524,7 +553,11 @@ public void Initialize()
524
553
525
554
if ( ScriptConfig . FileLoggingMode != FileLoggingMode . Never )
526
555
{
527
- PurgeOldLogDirectories ( ) ;
556
+ using ( metricsLogger . LatencyEvent ( MetricEventNames . HostStartupPurgeLogDirectoriesLatency ) )
557
+ {
558
+ PurgeOldLogDirectories ( ) ;
559
+ TraceWriter . Verbose ( "Old log directories purged." ) ;
560
+ }
528
561
}
529
562
}
530
563
}
0 commit comments