Skip to content

Commit bebb280

Browse files
Fix runtime version telemetry logging (#5680) (#5693)
1 parent ede5eba commit bebb280

File tree

3 files changed

+24
-47
lines changed

3 files changed

+24
-47
lines changed

src/WebJobs.Script/Environment/EnvironmentSettingNames.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public static class EnvironmentSettingNames
2525
public const string AppInsightsConnectionString = "APPLICATIONINSIGHTS_CONNECTION_STRING";
2626
public const string AppInsightsQuickPulseAuthApiKey = "APPINSIGHTS_QUICKPULSEAUTHAPIKEY";
2727
public const string FunctionsExtensionVersion = "FUNCTIONS_EXTENSION_VERSION";
28-
public const string WebsiteNodeDefaultVersion = "WEBSITE_NODE_DEFAULT_VERSION";
2928
public const string ContainerName = "CONTAINER_NAME";
3029
public const string WebSiteHomeStampName = "WEBSITE_HOME_STAMPNAME";
3130
public const string WebSiteStampDeploymentId = "WEBSITE_STAMP_DEPLOYMENT_ID";

src/WebJobs.Script/Host/ScriptHost.cs

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,20 @@ public async Task InitializeAsync(CancellationToken cancellationToken = default)
274274

275275
if (!_environment.IsPlaceholderModeEnabled())
276276
{
277-
// Appending the runtime version is currently only enabled for linux consumption.
278-
// This will be eventually enabled for Windows Consumption as well.
279-
string runtimeStack = GetPreciseRuntimeStack(_workerRuntime);
277+
string runtimeStack = _workerRuntime;
278+
279+
if (!string.IsNullOrEmpty(_environment.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName)))
280+
{
281+
// Appending the runtime version is currently only enabled for linux consumption. This will be eventually enabled for
282+
// Windows Consumption as well.
283+
string runtimeVersion = _environment.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName);
284+
285+
if (!string.IsNullOrEmpty(runtimeVersion))
286+
{
287+
runtimeStack = string.Concat(runtimeStack, "-", runtimeVersion);
288+
}
289+
}
290+
280291
_metricsLogger.LogEvent(string.Format(MetricEventNames.HostStartupRuntimeLanguage, runtimeStack));
281292
}
282293

@@ -292,35 +303,6 @@ public async Task InitializeAsync(CancellationToken cancellationToken = default)
292303
}
293304
}
294305

295-
/// <summary>
296-
/// Appends specific functions worker runtime version after runtime stack
297-
/// </summary>
298-
/// <returns>A string contains specific runtime stack (e.g. python-3.6, dotnet-~2) or single stack</returns>
299-
private string GetPreciseRuntimeStack(string runtime)
300-
{
301-
string runtimeStack = runtime?.ToLower() ?? string.Empty;
302-
string preciseRuntime = string.Empty;
303-
switch (runtimeStack)
304-
{
305-
case "dotnet":
306-
// Get Dotnet version from FUNCTIONS_EXTENSION_VERSION
307-
preciseRuntime = $"dotnet-{_environment.GetEnvironmentVariable(EnvironmentSettingNames.FunctionsExtensionVersion)}";
308-
break;
309-
case "node":
310-
// Get Node version from WEBSITE_NODE_DEFAULT_VERSION
311-
preciseRuntime = $"node-{_environment.GetEnvironmentVariable(EnvironmentSettingNames.WebsiteNodeDefaultVersion)}";
312-
break;
313-
case "python":
314-
preciseRuntime = $"python-{_environment.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName)}";
315-
break;
316-
default:
317-
// PowerShell, Java only has single version
318-
preciseRuntime = runtimeStack;
319-
break;
320-
}
321-
return preciseRuntime.TrimEnd('-');
322-
}
323-
324306
private async Task LogInitializationAsync()
325307
{
326308
// If the host id is explicitly set, emit a warning that this could cause issues and shouldn't be done

test/WebJobs.Script.Tests/ScriptHostTests.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -406,21 +406,19 @@ public async Task Initialize_WithLatestSiteExtensionVersion_LogsWarning()
406406
}
407407

408408
[Theory]
409-
[InlineData("dotnet", "", "", "", "dotnet")]
410-
[InlineData("dotnet", "~2", "", "", "dotnet-~2")]
411-
[InlineData("python", "~2", "", "", "python")]
412-
[InlineData("python", "~2", "", "3.6", "python-3.6")]
413-
[InlineData("python", "~3", "~8", "3.7", "python-3.7")]
414-
[InlineData("node", "~3", "", "3.6", "node")]
415-
[InlineData("node", "~2", "~8", "3.6", "node-~8")]
416-
[InlineData("powershell", "~2", "", "", "powershell")]
417-
[InlineData("powershell", "~2", "~10", "3.6", "powershell")]
418-
[InlineData("java", "~3", "", "", "java")]
419-
[InlineData("java", "~3", "~8", "3.6", "java")]
409+
[InlineData("dotnet", "", "", "dotnet")]
410+
[InlineData("dotnet", "", "~2", "dotnet-~2")]
411+
[InlineData("python", "~2", "", "python")]
412+
[InlineData("python", "~2", "3.6", "python-3.6")]
413+
[InlineData("python", "~3", "3.7", "python-3.7")]
414+
[InlineData("node", "~3", "~8", "node-~8")]
415+
[InlineData("node", "~2", "~8", "node-~8")]
416+
[InlineData("powershell", "~2", "", "powershell")]
417+
[InlineData("powershell", "~2", "~7", "powershell-~7")]
418+
[InlineData("java", "~3", "", "java")]
420419
public async Task Initialize_WithRuntimeAndWorkerVersion_ReportRuntimeToMetricsTable(
421420
string functionsWorkerRuntime,
422421
string functionsExtensionVersion,
423-
string websiteNodeDefaultVersion,
424422
string functionsWorkerRuntimeVersion,
425423
string expectedRuntimeStack)
426424
{
@@ -437,8 +435,6 @@ public async Task Initialize_WithRuntimeAndWorkerVersion_ReportRuntimeToMetricsT
437435
RpcWorkerConstants.FunctionWorkerRuntimeSettingName, functionsWorkerRuntime);
438436
environment.SetEnvironmentVariable(
439437
EnvironmentSettingNames.FunctionsExtensionVersion, functionsExtensionVersion);
440-
environment.SetEnvironmentVariable(
441-
EnvironmentSettingNames.WebsiteNodeDefaultVersion, websiteNodeDefaultVersion);
442438
environment.SetEnvironmentVariable(
443439
RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName, functionsWorkerRuntimeVersion);
444440

0 commit comments

Comments
 (0)