Skip to content

Commit

Permalink
Enabling DiagnosticEvents, minor bug fixes (Azure#8370)
Browse files Browse the repository at this point in the history
  • Loading branch information
soninaren authored May 11, 2022
1 parent c1fc996 commit 4fd0de1
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Updated Java Worker Version to [2.2.3](https://github.com/Azure/azure-functions-java-worker/releases/tag/2.2.3)
- Updated Node.js Worker Version to [3.3.0](https://github.com/Azure/azure-functions-nodejs-worker/releases/tag/v3.3.0)
- Add Include minimum durable payload to sync trigger (#8292)
- Enable diagnostic events collection

**Release sprint:** Sprint 118
[ [bugs](https://github.com/Azure/azure-functions-host/issues?q=is%3Aissue+milestone%3A%22Functions+Sprint+118%22+label%3Abug+is%3Aclosed) | [features](https://github.com/Azure/azure-functions-host/issues?q=is%3Aissue+milestone%3A%22Functions+Sprint+118%22+label%3Afeature+is%3Aclosed) ]
Expand Down
2 changes: 1 addition & 1 deletion src/WebJobs.Script.WebHost/Diagnostics/DiagnosticEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public DiagnosticEvent(string hostId, DateTime timestamp)

public int HitCount { get; set; }

public DateTime LastTimeStamp { get; set; }
public DateTimeOffset TimeStamp { get; set; }

public string Message { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void WriteDiagnosticEvent(DateTime timestamp, string errorCode, LogLevel
{
ErrorCode = errorCode,
HelpLink = helpLink,
LastTimeStamp = timestamp,
TimeStamp = timestamp,
Message = message,
LogLevel = level,
Details = exception?.ToFormattedString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static IHostBuilder AddWebScriptHost(this IHostBuilder builder, IServiceP
loggingBuilder.Services.AddSingleton<ILoggerProvider, AzureMonitorDiagnosticLoggerProvider>();
}

if (FeatureFlags.IsEnabled(ScriptConstants.FeatureFlagEnableDiagnosticEventLogging))
if (!FeatureFlags.IsEnabled(ScriptConstants.FeatureFlagDisableDiagnosticEventLogging))
{
loggingBuilder.Services.AddSingleton<ILoggerProvider, DiagnosticEventLoggerProvider>();
loggingBuilder.Services.TryAddSingleton<IDiagnosticEventRepository, DiagnosticEventTableStorageRepository>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static void LogInformation(this ILogger logger, int eventId, string error

public static void LogError(this ILogger logger, int eventId, string errorCode, string message, string helpLink, Exception exception)
{
logger.LogDiagnosticEvent(LogLevel.Information, eventId, errorCode, message, helpLink, exception);
logger.LogDiagnosticEvent(LogLevel.Error, eventId, errorCode, message, helpLink, exception);
}
}
}
1 change: 1 addition & 0 deletions src/WebJobs.Script/ScriptConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public static class ScriptConstants
public const string FeatureFlagAllowSynchronousIO = "AllowSynchronousIO";
public const string FeatureFlagRelaxedAssemblyUnification = "RelaxedAssemblyUnification";
public const string FeatureFlagEnableDiagnosticEventLogging = "EnableDiagnosticEventLogging";
public const string FeatureFlagDisableDiagnosticEventLogging = "DisableDiagnosticEventLogging";
public const string FeatureFlagDisableMergedWebHostScriptHostConfiguration = "DisableMergedConfiguration";
public const string FeatureFlagEnableWorkerIndexing = "EnableWorkerIndexing";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public async Task ExecuteBatchAsync_WritesToTableStorage()

var dateTime = DateTime.UtcNow;
var diagnosticEvent = new DiagnosticEvent("hostId", dateTime);
diagnosticEvent.LastTimeStamp = dateTime;
diagnosticEvent.TimeStamp = dateTime;
var events = new ConcurrentDictionary<string, DiagnosticEvent>();
events.TryAdd("EC123", diagnosticEvent);
await repository.ExecuteBatchAsync(events, table);
Expand Down Expand Up @@ -274,7 +274,7 @@ private async Task EmptyTableAsync(CloudTable table)
{
batch.Add(TableOperation.Delete(entity));

if (batch.Count == 100)
if (batch.Count == 1)
{
var result = await table.ExecuteBatchAsync(batch);
batch = new TableBatchOperation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public void LoggerProviders_Default()
{
IEnumerable<ILoggerProvider> loggerProviders = host.Services.GetService<IEnumerable<ILoggerProvider>>();

Assert.Equal(4, loggerProviders.Count());
Assert.Equal(5, loggerProviders.Count());
loggerProviders.OfType<SystemLoggerProvider>().Single();
loggerProviders.OfType<HostFileLoggerProvider>().Single();
loggerProviders.OfType<FunctionFileLoggerProvider>().Single();
Expand All @@ -207,7 +207,7 @@ public void LoggerProviders_ConsoleEnabled_IfDevelopmentEnvironment()
{
IEnumerable<ILoggerProvider> loggerProviders = host.Services.GetService<IEnumerable<ILoggerProvider>>();

Assert.Equal(5, loggerProviders.Count());
Assert.Equal(6, loggerProviders.Count());
loggerProviders.OfType<SystemLoggerProvider>().Single();
loggerProviders.OfType<HostFileLoggerProvider>().Single();
loggerProviders.OfType<FunctionFileLoggerProvider>().Single();
Expand All @@ -233,7 +233,7 @@ public void LoggerProviders_ConsoleEnabled_InConfiguration()
{
IEnumerable<ILoggerProvider> loggerProviders = host.Services.GetService<IEnumerable<ILoggerProvider>>();

Assert.Equal(5, loggerProviders.Count());
Assert.Equal(6, loggerProviders.Count());
loggerProviders.OfType<SystemLoggerProvider>().Single();
loggerProviders.OfType<HostFileLoggerProvider>().Single();
loggerProviders.OfType<FunctionFileLoggerProvider>().Single();
Expand All @@ -259,7 +259,7 @@ public void LoggerProviders_ApplicationInsights()
{
IEnumerable<ILoggerProvider> loggerProviders = host.Services.GetService<IEnumerable<ILoggerProvider>>();

Assert.Equal(5, loggerProviders.Count());
Assert.Equal(6, loggerProviders.Count());
loggerProviders.OfType<SystemLoggerProvider>().Single();
loggerProviders.OfType<HostFileLoggerProvider>().Single();
loggerProviders.OfType<FunctionFileLoggerProvider>().Single();
Expand Down Expand Up @@ -295,7 +295,7 @@ public void LoggerProviders_AzureMonitor(string azureMonitorEnabledValue)

int expectedCount = isAzureMonitorEnabled ? 5 : 4;

Assert.Equal(4, loggerProviders.Count());
Assert.Equal(5, loggerProviders.Count());
loggerProviders.OfType<SystemLoggerProvider>().Single();
loggerProviders.OfType<HostFileLoggerProvider>().Single();
loggerProviders.OfType<FunctionFileLoggerProvider>().Single();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void WriteDiagnosticEvent(DateTime timestamp, string errorCode, LogLevel
{
_events.Add(new DiagnosticEvent("hostid", timestamp)
{
LastTimeStamp = timestamp,
TimeStamp = timestamp,
ErrorCode = errorCode,
LogLevel = level,
Message = message,
Expand Down

0 comments on commit 4fd0de1

Please sign in to comment.