Skip to content

Emit diagnostic event upon Host Id collision #9061

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Feb 2, 2023
Merged
13 changes: 11 additions & 2 deletions src/WebJobs.Script/Host/HostIdValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Azure;
using Azure.Storage.Blobs;
using Microsoft.Azure.WebJobs.Host.Storage;
using Microsoft.Azure.WebJobs.Script.Diagnostics;
using Microsoft.Azure.WebJobs.Script.Properties;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
Expand All @@ -27,6 +28,8 @@ namespace Microsoft.Azure.WebJobs.Script
public class HostIdValidator
{
public const string BlobPathFormat = "ids/usage/{0}";
private const string HostIdCollisionErrorCode = "AZFD004";
private const string HostIdCollisionHelpLink = "https://go.microsoft.com/fwlink/?linkid=2224100";
private const LogLevel DefaultLevel = LogLevel.Error;

private readonly IEnvironment _environment;
Expand Down Expand Up @@ -117,15 +120,21 @@ private void HandleCollision(string hostId)
}

string message = string.Format(Resources.HostIdCollisionFormat, hostId);

if (level == LogLevel.Warning)
{
_logger.LogWarning(message);

DiagnosticEventLoggerExtensions.LogDiagnosticEventInformation(_logger, HostIdCollisionErrorCode, message, HostIdCollisionHelpLink);
}
else
{
// we only allow Warning/Error levels to be specified, so anything other than
// Warning is treated as Error
// We only allow Warning/Error levels to be specified,
// so anything other than Warning is treated as Error.
_logger.LogError(message);

DiagnosticEventLoggerExtensions.LogDiagnosticEventError(_logger, HostIdCollisionErrorCode, message, HostIdCollisionHelpLink, new InvalidOperationException(message));

_applicationLifetime.StopApplication();
}
}
Expand Down