Skip to content

Commit

Permalink
Make standard properties use standard names always
Browse files Browse the repository at this point in the history
Payload properties will have property names augmented as necessary to alleviate conflicts.
For more information on this change see #40
  • Loading branch information
karolz-ms committed Feb 4, 2017
1 parent 4ba53fa commit 15be2f3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,26 @@ public static EventData ToEventData(this EventWrittenEventArgs eventSourceEvent,
Keywords = (long)eventSourceEvent.Keywords
};

eventSourceEvent.ExtractPayloadData(eventData);

eventData.AddPayloadProperty("EventId", eventSourceEvent.EventId, healthReporter, context);
eventData.AddPayloadProperty("EventName", eventSourceEvent.EventName, healthReporter, context);
eventData.AddPayloadProperty("ActivityID", ActivityPathString(eventSourceEvent.ActivityId), healthReporter, context);
IDictionary<string, object> payloadData = eventData.Payload;
payloadData.Add("EventId", eventSourceEvent.EventId);
payloadData.Add("EventName", eventSourceEvent.EventName);
payloadData.Add("ActivityID", ActivityPathString(eventSourceEvent.ActivityId));
try
{
if (eventSourceEvent.Message != null)
{
// If the event has a badly formatted manifest, the FormattedMessage property getter might throw
eventData.AddPayloadProperty("Message",
string.Format(CultureInfo.InvariantCulture, eventSourceEvent.Message, eventSourceEvent.Payload.ToArray()),
healthReporter,
context);
payloadData.Add("Message", string.Format(CultureInfo.InvariantCulture, eventSourceEvent.Message, eventSourceEvent.Payload.ToArray()));
}
}
catch { }

eventSourceEvent.ExtractPayloadData(eventData, healthReporter, context);

return eventData;
}

private static void ExtractPayloadData(this EventWrittenEventArgs eventSourceEvent, EventData eventData)
private static void ExtractPayloadData(this EventWrittenEventArgs eventSourceEvent, EventData eventData, IHealthReporter healthReporter, string context)
{
if (eventSourceEvent.Payload == null || eventSourceEvent.PayloadNames == null)
{
Expand All @@ -62,7 +60,7 @@ private static void ExtractPayloadData(this EventWrittenEventArgs eventSourceEve
while (payloadEnumerator.MoveNext())
{
payloadNamesEnunmerator.MoveNext();
payloadData.Add(payloadNamesEnunmerator.Current, payloadEnumerator.Current);
eventData.AddPayloadProperty(payloadNamesEnunmerator.Current, payloadEnumerator.Current, healthReporter, context);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.0-*",
"version": "1.0.1-*",

"dependencies": {
"Microsoft.Diagnostics.EventFlow.Core": { "target": "project" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,17 @@ internal void SubmitEventData(string message, LogLevel level, EventId eventId, E
Level = level
};

AddPayloadProperty(eventEntry, "Message", message);
AddPayloadProperty(eventEntry, "EventId", eventId.Id);
IDictionary<string, object> payloadData = eventEntry.Payload;
payloadData.Add("Message", message);
payloadData.Add("EventId", eventId.Id);

if (eventId.Name != null)
{
AddPayloadProperty(eventEntry, "EventName", eventId.Name);
payloadData.Add("EventName", eventId.Name);
}
if (exception != null)
{
AddPayloadProperty(eventEntry, "Exception", exception);
payloadData.Add("Exception", exception);
}
if (payload != null)
{
Expand Down
4 changes: 3 additions & 1 deletion test/Microsoft.Diagnostics.EventFlow.Core.Tests/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@
"debugType": "portable"
},
"dependencies": {
"Elasticsearch.Net": "5.0.0",
"dotnet-test-xunit": "2.2.0-preview2-build1029",
"Microsoft.Diagnostics.EventFlow.Core": { "target": "project" },
"Microsoft.Diagnostics.EventFlow.Inputs.EventSource": { "target": "project" },
"Microsoft.Diagnostics.EventFlow.Inputs.Trace": { "target": "project" },
"Microsoft.Diagnostics.EventFlow.Inputs.MicrosoftLogging": { "target": "project" },
"Microsoft.Diagnostics.EventFlow.Inputs.Serilog": { "target": "project" },
"Microsoft.Diagnostics.EventFlow.Outputs.StdOutput": { "target": "project" },
"Microsoft.Diagnostics.EventFlow.Outputs.ElasticSearch": { "target": "project" },
"Microsoft.Diagnostics.EventFlow.Outputs.ElasticSearch": { "target": "project" },
"Microsoft.Diagnostics.EventFlow.Outputs.Oms": { "target": "project" },
"Microsoft.Extensions.Configuration": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Moq": "4.6.36-alpha",
"NEST": "5.0.0",
"System.ComponentModel.Primitives": "4.1.0",
"System.Runtime.Serialization.Primitives": "4.1.1",
"xunit": "2.2.0-beta2-build3300",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public void HandlesDuplicatePropertyNames()
EventSourceInputTestSource.Log.Tricky(7, "TrickyEvent", "Actual message");

observer.Verify(s => s.OnNext(It.Is<EventData>(data =>
data.Payload["Message"].Equals("Actual message")
&& data.Payload["EventId"].Equals(7)
&& data.Payload["EventName"].Equals("TrickyEvent")
&& data.Payload[data.Payload.Keys.First(key => key.StartsWith("Message") && key != "Message")].Equals("Manifest message")
&& data.Payload[data.Payload.Keys.First(key => key.StartsWith("EventId") && key != "EventId")].Equals(1)
&& data.Payload[data.Payload.Keys.First(key => key.StartsWith("EventName") && key != "EventName")].Equals("Tricky")
data.Payload["Message"].Equals("Manifest message")
&& data.Payload["EventId"].Equals(1)
&& data.Payload["EventName"].Equals("Tricky")
&& data.Payload[data.Payload.Keys.First(key => key.StartsWith("Message") && key != "Message")].Equals("Actual message")
&& data.Payload[data.Payload.Keys.First(key => key.StartsWith("EventId") && key != "EventId")].Equals(7)
&& data.Payload[data.Payload.Keys.First(key => key.StartsWith("EventName") && key != "EventName")].Equals("TrickyEvent")
)), Times.Exactly(1));

healthReporterMock.Verify(o => o.ReportWarning(
Expand Down

0 comments on commit 15be2f3

Please sign in to comment.