Skip to content

Commit 14f7d69

Browse files
authored
Runtime language metrics (#3837)
* Runtime language metrics * Addressing CR comments
1 parent 2ef5d72 commit 14f7d69

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/WebJobs.Script/Diagnostics/MetricEventNames.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public static class MetricEventNames
1515
public const string HostStartupCreateMetadataProviderLatency = "host.startup.createmetadataprovider.latency";
1616
public const string HostStartupGetFunctionDescriptorsLatency = "host.startup.getfunctiondescriptors.latency";
1717
public const string HostStartupGrpcServerLatency = "host.startup.outofproc.grpcserver.initialize.latency";
18+
public const string HostStartupRuntimeLanguage = "host.startup.runtime.language.{0}";
1819

1920
// language worker level events
2021
public const string WorkerInitializeLatency = "host.startup.outofproc.{0}worker.initialize.attempt{1}.latency";

src/WebJobs.Script/Host/ScriptHost.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class ScriptHost : JobHost, IScriptJobHost
5151
private readonly IMetricsLogger _metricsLogger = null;
5252
private readonly string _hostLogPath;
5353
private readonly Stopwatch _stopwatch = new Stopwatch();
54-
private readonly string _currentRuntimelanguage;
54+
private readonly string _currentRuntimeLanguage;
5555
private readonly IOptions<JobHostOptions> _hostOptions;
5656
private readonly IConfiguration _configuration;
5757
private readonly ScriptTypeLocator _typeLocator;
@@ -125,7 +125,7 @@ public ScriptHost(IOptions<JobHostOptions> options,
125125

126126
_hostLogPath = Path.Combine(ScriptOptions.RootLogPath, "Host");
127127

128-
_currentRuntimelanguage = _environment.GetEnvironmentVariable(LanguageWorkerConstants.FunctionWorkerRuntimeSettingName);
128+
_currentRuntimeLanguage = _environment.GetEnvironmentVariable(LanguageWorkerConstants.FunctionWorkerRuntimeSettingName);
129129

130130
_loggerFactory = loggerFactory;
131131
_logger = loggerFactory.CreateLogger(LogCategories.Startup);
@@ -260,14 +260,19 @@ protected override async Task StartAsyncCore(CancellationToken cancellationToken
260260
public async Task InitializeAsync()
261261
{
262262
_stopwatch.Start();
263+
if (!_environment.IsPlaceholderModeEnabled())
264+
{
265+
string runtimeLanguage = string.IsNullOrEmpty(_currentRuntimeLanguage) ? "none" : _currentRuntimeLanguage;
266+
_metricsLogger.LogEvent(string.Format(MetricEventNames.HostStartupRuntimeLanguage, runtimeLanguage));
267+
}
263268
using (_metricsLogger.LatencyEvent(MetricEventNames.HostStartupLatency))
264269
{
265270
PreInitialize();
266271
HostInitializing?.Invoke(this, EventArgs.Empty);
267272

268273
// Generate Functions
269274
IEnumerable<FunctionMetadata> functions = GetFunctionsMetadata();
270-
if (Utility.ShouldInitiliazeLanguageWorkers(functions, _currentRuntimelanguage))
275+
if (Utility.ShouldInitiliazeLanguageWorkers(functions, _currentRuntimeLanguage))
271276
{
272277
await InitializeWorkersAsync();
273278
}
@@ -471,16 +476,16 @@ private void GenerateFunctions(IEnumerable<Type> directTypes)
471476
/// </summary>
472477
internal async Task InitializeFunctionDescriptorsAsync(IEnumerable<FunctionMetadata> functionMetadata)
473478
{
474-
if (string.IsNullOrEmpty(_currentRuntimelanguage))
479+
if (string.IsNullOrEmpty(_currentRuntimeLanguage))
475480
{
476481
_logger.LogDebug("Adding Function descriptor providers for all languages.");
477482
_descriptorProviders.Add(new DotNetFunctionDescriptorProvider(this, ScriptOptions, _bindingProviders, _metricsLogger, _loggerFactory));
478483
_descriptorProviders.Add(new WorkerFunctionDescriptorProvider(this, ScriptOptions, _bindingProviders, _functionDispatcher, _loggerFactory));
479484
}
480485
else
481486
{
482-
_logger.LogDebug($"Adding Function descriptor provider for language {_currentRuntimelanguage}.");
483-
if (string.Equals(_currentRuntimelanguage, LanguageWorkerConstants.DotNetLanguageWorkerName, StringComparison.OrdinalIgnoreCase))
487+
_logger.LogDebug($"Adding Function descriptor provider for language {_currentRuntimeLanguage}.");
488+
if (string.Equals(_currentRuntimeLanguage, LanguageWorkerConstants.DotNetLanguageWorkerName, StringComparison.OrdinalIgnoreCase))
484489
{
485490
_descriptorProviders.Add(new DotNetFunctionDescriptorProvider(this, ScriptOptions, _bindingProviders, _metricsLogger, _loggerFactory));
486491
}
@@ -531,7 +536,7 @@ private async Task InitializeWorkersAsync()
531536
attemptCount);
532537
};
533538

534-
_functionDispatcher = new FunctionDispatcher(EventManager, _rpcService, channelFactory, _workerConfigs, _currentRuntimelanguage);
539+
_functionDispatcher = new FunctionDispatcher(EventManager, _rpcService, channelFactory, _workerConfigs, _currentRuntimeLanguage);
535540

536541
_eventSubscriptions.Add(EventManager.OfType<WorkerProcessErrorEvent>()
537542
.Subscribe(evt =>
@@ -709,7 +714,7 @@ internal async Task<Collection<FunctionDescriptor>> GetFunctionDescriptorsAsync(
709714
Collection<FunctionDescriptor> functionDescriptors = new Collection<FunctionDescriptor>();
710715
var httpFunctions = new Dictionary<string, HttpTriggerAttribute>();
711716

712-
if (!_scriptHostEnvironment.IsDevelopment() && !Utility.IsSingleLanguage(functions, _currentRuntimelanguage))
717+
if (!_scriptHostEnvironment.IsDevelopment() && !Utility.IsSingleLanguage(functions, _currentRuntimeLanguage))
713718
{
714719
throw new HostInitializationException($"Found functions with more than one language. Select a language for your function app by specifying {LanguageWorkerConstants.FunctionWorkerRuntimeSettingName} AppSetting");
715720
}

0 commit comments

Comments
 (0)