Skip to content

Commit a7d8dfd

Browse files
authored
Adding event source name property to DurabilityProvider (#1710)
These changes add an event source name property to DurabilityProvider and remove the hard coded event source names for different storage backends in OnEventSourceCreated().
1 parent 85d0642 commit a7d8dfd

File tree

7 files changed

+76
-6
lines changed

7 files changed

+76
-6
lines changed

src/WebJobs.Extensions.DurableTask/AzureStorageDurabilityProvider.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public AzureStorageDurabilityProvider(
5656

5757
public override TimeSpan LongRunningTimerIntervalLength { get; set; } = TimeSpan.FromDays(3);
5858

59+
public override string EventSourceName { get; set; } = "DurableTask-AzureStorage";
60+
5961
/// <inheritdoc/>
6062
public async override Task<IList<OrchestrationState>> GetAllOrchestrationStates(CancellationToken cancellationToken)
6163
{

src/WebJobs.Extensions.DurableTask/DurabilityProvider.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ public DurabilityProvider(string storageProviderName, IOrchestrationService serv
8282
/// </summary>
8383
public virtual TimeSpan LongRunningTimerIntervalLength { get; set; }
8484

85+
/// <summary>
86+
/// Event source name (e.g. DurableTask-AzureStorage).
87+
/// </summary>
88+
public virtual string EventSourceName { get; set; }
89+
8590
/// <inheritdoc/>
8691
public int TaskOrchestrationDispatcherCount => this.GetOrchestrationService().TaskOrchestrationDispatcherCount;
8792

src/WebJobs.Extensions.DurableTask/DurableTaskExtension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ private void InitializeLinuxLogging()
382382
// Since our logging payload can be quite large, linux telemetry by default
383383
// disables verbose-level telemetry to avoid a performance hit.
384384
bool enableVerbose = this.Options.Tracing.AllowVerboseLinuxTelemetry;
385-
this.eventSourceListener = new EventSourceListener(linuxLogger, enableVerbose, this.TraceHelper);
385+
this.eventSourceListener = new EventSourceListener(linuxLogger, enableVerbose, this.TraceHelper, this.defaultDurabilityProvider.EventSourceName);
386386
}
387387
}
388388

src/WebJobs.Extensions.DurableTask/EventSourceListener.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ internal class EventSourceListener : EventListener
1515
{
1616
private readonly LinuxAppServiceLogger logger;
1717
private readonly bool disableVerbose;
18+
private readonly string durabilityProviderEventSourceName;
1819
private EndToEndTraceHelper traceHelper;
1920

2021
/// <summary>
@@ -24,11 +25,13 @@ internal class EventSourceListener : EventListener
2425
/// <param name="logger">A LinuxAppService logger configured for the current linux host.</param>
2526
/// <param name="enableVerbose">If true, durableTask.Core verbose logs are enabled. The opposite if false.</param>
2627
/// <param name="traceHelper">A tracing client to log exceptions.</param>
27-
public EventSourceListener(LinuxAppServiceLogger logger, bool enableVerbose, EndToEndTraceHelper traceHelper)
28+
/// <param name="durabilityProviderEventSourceName">The durability provider's event source name.</param>
29+
public EventSourceListener(LinuxAppServiceLogger logger, bool enableVerbose, EndToEndTraceHelper traceHelper, string durabilityProviderEventSourceName)
2830
{
2931
this.logger = logger;
3032
this.disableVerbose = !enableVerbose; // We track the opposite value ro simplify logic later
3133
this.traceHelper = traceHelper;
34+
this.durabilityProviderEventSourceName = durabilityProviderEventSourceName;
3235
}
3336

3437
/// <summary>
@@ -43,9 +46,8 @@ protected override void OnEventSourceCreated(EventSource eventSource)
4346
// so we provide extra logic to ignore it.
4447
if ((eventSource.Name == "DurableTask-Core"
4548
&& eventSource.Guid != new Guid("7DA4779A-152E-44A2-A6F2-F80D991A5BEE")) ||
46-
eventSource.Name == "DurableTask-AzureStorage" ||
4749
eventSource.Name == "WebJobs-Extensions-DurableTask" ||
48-
eventSource.Name == "DurableTask-SqlServer")
50+
eventSource.Name == this.durabilityProviderEventSourceName)
4951
{
5052
this.EnableEvents(eventSource, EventLevel.LogAlways, EventKeywords.All);
5153
}

src/WebJobs.Extensions.DurableTask/Microsoft.Azure.WebJobs.Extensions.DurableTask-net461.xml

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/WebJobs.Extensions.DurableTask/Microsoft.Azure.WebJobs.Extensions.DurableTask.xml

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/Common/DurableTaskEndToEndTests.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,55 @@ public async Task ParentInstanceId_Not_Assigned_In_Orchestrator(bool extendedSes
226226
}
227227

228228
#if !FUNCTIONS_V1
229+
/// <summary>
230+
/// By simulating the appropiate environment variables for Linux Consumption,
231+
/// this test checks that we are emitting logs from DurableTask.AzureStorage
232+
/// and reading the DurabilityProvider's EventSourceName property correctly.
233+
/// </summary>
234+
[Fact]
235+
[Trait("Category", PlatformSpecificHelpers.TestCategory)]
236+
public async Task AzureStorageEmittingLogsWithEventSourceName()
237+
{
238+
var prefix = "MS_DURABLE_FUNCTION_EVENTS_LOGS";
239+
string orchestratorName = nameof(TestOrchestrations.SayHelloInline);
240+
241+
// To capture console output in a StringWritter
242+
using (StringWriter sw = new StringWriter())
243+
{
244+
// Set console to write to StringWritter
245+
Console.SetOut(sw);
246+
247+
// Simulate enviroment variables indicating linux consumption
248+
var nameResolver = new SimpleNameResolver(new Dictionary<string, string>()
249+
{
250+
{ "CONTAINER_NAME", "val1" },
251+
{ "WEBSITE_STAMP_DEPLOYMENT_ID", "val3" },
252+
{ "WEBSITE_HOME_STAMPNAME", "val4" },
253+
});
254+
255+
// Run trivial orchestrator
256+
using (var host = TestHelpers.GetJobHost(
257+
this.loggerProvider,
258+
nameResolver: nameResolver,
259+
testName: "FiltersVerboseLogsByDefault",
260+
enableExtendedSessions: false,
261+
storageProviderType: "azure_storage"))
262+
{
263+
await host.StartAsync();
264+
var client = await host.StartOrchestratorAsync(orchestratorName, input: "World", this.output);
265+
var status = await client.WaitForCompletionAsync(this.output);
266+
await host.StopAsync();
267+
}
268+
269+
string consoleOutput = sw.ToString();
270+
271+
// Validate that the JSON has DurableTask-AzureStorage fields
272+
string[] lines = consoleOutput.Split('\n');
273+
var azureStorageLogLines = lines.Where(l => l.Contains("DurableTask-AzureStorage") && l.StartsWith(prefix));
274+
Assert.NotEmpty(azureStorageLogLines);
275+
}
276+
}
277+
229278
/// <summary>
230279
/// By simulating the appropiate enviorment variables for Linux Consumption,
231280
/// this test checks that we are writing our JSON logs to the console. It does not

0 commit comments

Comments
 (0)