Skip to content

Commit 9d28262

Browse files
authored
Merge pull request #1519 from Azure/dev
Promoting dev to master for 2.3.1 release, now with fixed CI test and extra logging fields
2 parents 48aebaf + b5896e6 commit 9d28262

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

src/WebJobs.Extensions.DurableTask/LinuxAppServiceLogger.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ internal class LinuxAppServiceLogger
3535
// logging metadata
3636
private readonly JToken roleInstance;
3737
private readonly JToken tenant;
38-
private readonly JToken sourceMoniker;
3938
private readonly JToken procID;
39+
private readonly string stamp;
40+
private readonly string primaryStamp;
4041

4142
// if true, we write to console (linux consumption), else to a file (linux dedicated).
4243
private readonly bool writeToConsole;
@@ -58,9 +59,11 @@ public LinuxAppServiceLogger(
5859
this.writeToConsole = writeToConsole;
5960
this.roleInstance = JToken.FromObject("App-" + containerName);
6061
this.tenant = JToken.FromObject(tenant);
62+
this.stamp = stampName;
63+
64+
var finalCharIndex = stampName.Length - 1;
65+
this.primaryStamp = char.IsLetter(stampName[finalCharIndex]) ? stampName.Remove(finalCharIndex) : stampName;
6166

62-
this.sourceMoniker = JToken.FromObject(
63-
string.IsNullOrEmpty(stampName) ? string.Empty : "L" + stampName.Replace("-", "").ToUpperInvariant());
6467
using (var process = Process.GetCurrentProcess())
6568
{
6669
this.procID = process.Id;
@@ -97,6 +100,10 @@ private string GenerateJsonStr(EventWrittenEventArgs eventData)
97100
// We pack them into a JSON
98101
JObject json = new JObject
99102
{
103+
{ "EventStampName", this.stamp },
104+
{ "EventPrimaryStampName", this.primaryStamp },
105+
{ "ProviderName", eventData.EventSource.Name },
106+
{ "TaskName", eventData.EventName },
100107
{ "EventId", eventData.EventId },
101108
{ "TimeStamp", DateTime.UtcNow },
102109
{ "RoleInstance", this.roleInstance },
@@ -105,11 +112,23 @@ private string GenerateJsonStr(EventWrittenEventArgs eventData)
105112
{ "Tid", Thread.CurrentThread.ManagedThreadId },
106113
};
107114

115+
// Add payload elements
108116
for (int i = 0; i < values.Count; i++)
109117
{
110118
json.Add(keys[i], JToken.FromObject(values[i]));
111119
}
112120

121+
// Add ActivityId and RelatedActivityId, if non-null
122+
if (!eventData.ActivityId.Equals(Guid.Empty))
123+
{
124+
json.Add("ActivityId", eventData.ActivityId);
125+
}
126+
127+
if (!eventData.RelatedActivityId.Equals(Guid.Empty))
128+
{
129+
json.Add("RelatedActivityId", eventData.RelatedActivityId);
130+
}
131+
113132
// Generate string-representation of JSON. Also remove newlines.
114133
string jsonString = json.ToString(Newtonsoft.Json.Formatting.None);
115134
jsonString = jsonString.Replace("\n", "\\n").Replace("\r", "\\r");

test/Common/DurableTaskEndToEndTests.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,10 @@ public async Task RemovesNewlinesFromExceptions()
371371
/// this test checks our JSON logs satisfy a minimal set of requirements:
372372
/// (1) Is JSON parseable
373373
/// (2) Contains minimal expected fields: EventId, TimeStamp, RoleInstance,
374-
/// Tenant, SourceMoniker, Pid, Tid.
374+
/// Tenant, SourceMoniker, Pid, Tid, etc.
375375
/// (3) Ensure some Enums are printed correctly.
376376
/// (4) That we have logs from a variety of EventSource providers.
377+
/// (5) Ensure ActivityId and RelatedActivityId are eventually present.
377378
/// </summary>
378379
[Fact]
379380
[Trait("Category", PlatformSpecificHelpers.TestCategory)]
@@ -420,6 +421,9 @@ public async Task OutputsValidJSONLogs()
420421
bool foundEtwEventSourceLog = false;
421422
bool foundDurableTaskCoreLog = false;
422423

424+
bool foundActivityId = false;
425+
bool foundRelatedActivityId = false;
426+
423427
// Validating JSON outputs
424428
foreach (string line in lines)
425429
{
@@ -428,11 +432,14 @@ public async Task OutputsValidJSONLogs()
428432

429433
// (2) Contains minimal expected fields
430434
List<string> keys = json.Properties().Select(p => p.Name).ToList();
435+
Assert.Contains("EventStampName", keys);
436+
Assert.Contains("EventPrimaryStampName", keys);
437+
Assert.Contains("ProviderName", keys);
438+
Assert.Contains("TaskName", keys);
431439
Assert.Contains("EventId", keys);
432440
Assert.Contains("TimeStamp", keys);
433441
Assert.Contains("RoleInstance", keys);
434442
Assert.Contains("Tenant", keys);
435-
Assert.Contains("SourceMoniker", keys);
436443
Assert.Contains("Pid", keys);
437444
Assert.Contains("Tid", keys);
438445

@@ -451,6 +458,18 @@ public async Task OutputsValidJSONLogs()
451458
foundAzureStorageLog = true;
452459
}
453460

461+
// recording if ActivityId and RelatedActivityId are seen
462+
// we expect to see them, at some point, in a trivial orchestrator
463+
if (keys.Contains("ActivityId"))
464+
{
465+
foundActivityId = true;
466+
}
467+
468+
if (keys.Contains("RelatedActivityId"))
469+
{
470+
foundRelatedActivityId = true;
471+
}
472+
454473
// (3) Ensure some Enums are printed correctly: as strings
455474
string eventType = (string)json.GetValue("EventType");
456475
if (!string.IsNullOrEmpty(eventType))
@@ -464,6 +483,10 @@ public async Task OutputsValidJSONLogs()
464483
Assert.True(foundEtwEventSourceLog);
465484
Assert.True(foundDurableTaskCoreLog);
466485

486+
// (5) Ensure ActivityId and RelatedActivityId are present in logs
487+
Assert.True(foundActivityId);
488+
Assert.True(foundRelatedActivityId);
489+
467490
// To ensure other tests generate the path
468491
File.Delete(LinuxAppServiceLogger.LoggingPath);
469492
}

0 commit comments

Comments
 (0)