Skip to content

Commit

Permalink
Merge pull request #1620 from brianrob/issue-1618
Browse files Browse the repository at this point in the history
Properly quote JSON keys in DynamicTraceEventParser StructValue
  • Loading branch information
brianrob authored Apr 20, 2022
2 parents d7a1bd7 + 4715c88 commit 65a4b1b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/TraceEvent/DynamicTraceEventParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,9 @@ private static StringBuilder WriteAsJSon(StringBuilder sb, object value)
first = false;
}

sb.Append(keyvalue.Key).Append(":");
sb.Append("\"");
Quote(sb, keyvalue.Key);
sb.Append("\":");
WriteAsJSon(sb, keyvalue.Value);
}
sb.Append(" }");
Expand Down
28 changes: 28 additions & 0 deletions src/TraceEvent/TraceEvent.Tests/Regression/Issue1618.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.IO;
using Microsoft.Diagnostics.Tracing;
using Xunit;

namespace TraceEventTests
{
public class Issue1618
{
[Fact]
public void DynamicParserStructSerialization()
{
string expectedValue = "{ \"b\":\"Hello\", \"c\":\"World!\" }";
string inputTraceFile = Path.Combine("inputs", "Regression", "SelfDescribingSingleEvent.etl");

using(ETWTraceEventSource source = new ETWTraceEventSource(inputTraceFile))
{
source.Dynamic.AddCallbackForProviderEvent("MySource", "TestEvent", (data) =>
{
string jsonStructValue = data.PayloadValue(0).ToString();
Assert.Equal(expectedValue, jsonStructValue);
});

source.Process();
}
}
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MySource/SendEmptyEvent, 1, <Event MSec= "1344.7359" PID="12365" PName="Process(12365)" TID="12365" EventName="SendEmptyEvent" ProviderName="MySource"/>
MySource/TestEmptyEvent, 2, <Event MSec= "1343.0440" PID="12365" PName="Process(12365)" TID="12365" EventName="TestEmptyEvent" ProviderName="MySource"/>
MySource/TestEvent, 1, <Event MSec= "1450.9500" PID="12365" PName="Process(12365)" TID="12365" EventName="TestEvent" ProviderName="MySource" ="{ field1:&quot;Hello&quot;, field2:3, field3:6 }"/>
MySource/TestEvent1, 3, <Event MSec= "1421.1897" PID="12365" PName="Process(12365)" TID="12365" EventName="TestEvent1" ProviderName="MySource" ="{ field1:&quot;Hello&quot; }"/>
MySource/TestEvent2, 3, <Event MSec= "1421.7060" PID="12365" PName="Process(12365)" TID="12365" EventName="TestEvent2" ProviderName="MySource" ="{ field1:&quot;Hello&quot; }"/>
MySource/TestEvent, 1, <Event MSec= "1450.9500" PID="12365" PName="Process(12365)" TID="12365" EventName="TestEvent" ProviderName="MySource" ="{ &quot;field1&quot;:&quot;Hello&quot;, &quot;field2&quot;:3, &quot;field3&quot;:6 }"/>
MySource/TestEvent1, 3, <Event MSec= "1421.1897" PID="12365" PName="Process(12365)" TID="12365" EventName="TestEvent1" ProviderName="MySource" ="{ &quot;field1&quot;:&quot;Hello&quot; }"/>
MySource/TestEvent2, 3, <Event MSec= "1421.7060" PID="12365" PName="Process(12365)" TID="12365" EventName="TestEvent2" ProviderName="MySource" ="{ &quot;field1&quot;:&quot;Hello&quot; }"/>
MySource/TestEventMethod, 1, <Event MSec= "1340.6720" PID="12365" PName="Process(12365)" TID="12365" EventName="TestEventMethod" ProviderName="MySource" i="1" s="Hello World!"/>
MySource/TestNestedStructs, 1, <Event MSec= "1499.5145" PID="12365" PName="Process(12365)" TID="12365" EventName="TestNestedStructs" ProviderName="MySource" ="{ structVal:{ field17:&quot;hello world!&quot; }, i:42 }"/>
MySource/TestNestedStructs, 1, <Event MSec= "1499.5145" PID="12365" PName="Process(12365)" TID="12365" EventName="TestNestedStructs" ProviderName="MySource" ="{ &quot;structVal&quot;:{ &quot;field17&quot;:&quot;hello world!&quot; }, &quot;i&quot;:42 }"/>
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ EVENT 449.122: Microsoft-JScript/Jscript_GC_DecommitConcurrentCollectPageAllocat
EVENT 449.383: Microsoft-JScript/Jscript_GC_SweepWeakRef/Start PID=17836; TID=6692; PName=MicrosoftEdgeCP; ProceNum=3; DataLen=8; RecyclerID=0x1d42ab93f30;
EVENT 450.222: Microsoft-JScript/Jscript_GC_SweepWeakRef/Stop PID=17836; TID=6692; PName=MicrosoftEdgeCP; ProceNum=3; DataLen=8; RecyclerID=0x1d42ab93f30;
EVENT 450.223: Microsoft-JScript/Jscript_GC_SetupBackgroundSweep/Start PID=17836; TID=6692; PName=MicrosoftEdgeCP; ProceNum=3; DataLen=8; RecyclerID=0x1d42ab93f30;
EVENT 450.317: Microsoft-JScript/Jscript_Recycler_Allocation/Free_Memory PID=17836; TID=6692; PName=MicrosoftEdgeCP; ProceNum=3; DataLen=6404; Values=[{ MemoryAddress:"20...;
EVENT 450.357: Microsoft-JScript/Jscript_Recycler_Allocation/Free_Memory PID=17836; TID=6692; PName=MicrosoftEdgeCP; ProceNum=3; DataLen=6404; Values=[{ MemoryAddress:"20...;
EVENT 450.393: Microsoft-JScript/Jscript_Recycler_Allocation/Free_Memory PID=17836; TID=6692; PName=MicrosoftEdgeCP; ProceNum=3; DataLen=6404; Values=[{ MemoryAddress:"20...;
EVENT 450.427: Microsoft-JScript/Jscript_Recycler_Allocation/Free_Memory PID=17836; TID=6692; PName=MicrosoftEdgeCP; ProceNum=3; DataLen=6404; Values=[{ MemoryAddress:"20...;
EVENT 450.464: Microsoft-JScript/Jscript_Recycler_Allocation/Free_Memory PID=17836; TID=6692; PName=MicrosoftEdgeCP; ProceNum=3; DataLen=6404; Values=[{ MemoryAddress:"20...;
EVENT 450.317: Microsoft-JScript/Jscript_Recycler_Allocation/Free_Memory PID=17836; TID=6692; PName=MicrosoftEdgeCP; ProceNum=3; DataLen=6404; Values=[{ "MemoryAddress":"...;
EVENT 450.357: Microsoft-JScript/Jscript_Recycler_Allocation/Free_Memory PID=17836; TID=6692; PName=MicrosoftEdgeCP; ProceNum=3; DataLen=6404; Values=[{ "MemoryAddress":"...;
EVENT 450.393: Microsoft-JScript/Jscript_Recycler_Allocation/Free_Memory PID=17836; TID=6692; PName=MicrosoftEdgeCP; ProceNum=3; DataLen=6404; Values=[{ "MemoryAddress":"...;
EVENT 450.427: Microsoft-JScript/Jscript_Recycler_Allocation/Free_Memory PID=17836; TID=6692; PName=MicrosoftEdgeCP; ProceNum=3; DataLen=6404; Values=[{ "MemoryAddress":"...;
EVENT 450.464: Microsoft-JScript/Jscript_Recycler_Allocation/Free_Memory PID=17836; TID=6692; PName=MicrosoftEdgeCP; ProceNum=3; DataLen=6404; Values=[{ "MemoryAddress":"...;
EVENT 450.560: Microsoft-JScript/Jscript_Recycler_Allocation/Free_Memory_Block PID=17836; TID=6692; PName=MicrosoftEdgeCP; ProceNum=3; DataLen=16; MemoryAddress=0x1dc44db4000; BlockSize=16,384; ObjectSize=128;
EVENT 450.667: Microsoft-JScript/Jscript_GC_SetupBackgroundSweep/Stop PID=17836; TID=6692; PName=MicrosoftEdgeCP; ProceNum=3; DataLen=8; RecyclerID=0x1d42ab93f30;
EVENT 450.684: Microsoft-IE/Mshtml_CWindow_Script/Start PID=17836; TID=6692; PName=MicrosoftEdgeCP; ProceNum=3; DataLen=12; CDoc=0x1dc2c938000; Nesting=1;
Expand Down

0 comments on commit 65a4b1b

Please sign in to comment.