Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 0ebc7ad

Browse files
committed
Add httpContext.TraceIdentifier and httpContext.Response.StatusCode keywords which provide useful information for correlation.
1 parent 1e77bb6 commit 0ebc7ad

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ public class Keywords
164164
"httpContext.Request.Path;" +
165165
"httpContext.Request.QueryString" +
166166
"\n" +
167-
"Microsoft.AspNetCore/Microsoft.AspNetCore.Hosting.EndRequest@Activity1Stop:-";
167+
"Microsoft.AspNetCore/Microsoft.AspNetCore.Hosting.EndRequest@Activity1Stop:-" +
168+
"httpContext.TraceIdentifier;" +
169+
"httpContext.Response.StatusCode";
168170

169171
// Setting EntityFrameworkCoreCommands is like having this in the FilterAndPayloadSpecs string
170172
// It turns on basic SQL commands.

src/System.Diagnostics.DiagnosticSource/tests/DiagnosticSourceEventSourceBridgeTests.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,11 +586,25 @@ public void TestShortcutKeywords()
586586
eventSourceListener.ResetEventCountAndLastEvent();
587587

588588
// Stop the ASP.NET reqeust.
589-
aspNetCoreSource.Write("Microsoft.AspNetCore.Hosting.EndRequest", null);
589+
aspNetCoreSource.Write("Microsoft.AspNetCore.Hosting.EndRequest",
590+
new
591+
{
592+
httpContext = new
593+
{
594+
Response = new
595+
{
596+
StatusCode = "200"
597+
},
598+
TraceIdentifier = "MyTraceId"
599+
}
600+
});
590601
Assert.Equal(1, eventSourceListener.EventCount); // Exactly one more event has been emitted.
591602
Assert.Equal("Activity1Stop", eventSourceListener.LastEvent.EventSourceEventName);
592603
Assert.Equal("Microsoft.AspNetCore", eventSourceListener.LastEvent.SourceName);
593604
Assert.Equal("Microsoft.AspNetCore.Hosting.EndRequest", eventSourceListener.LastEvent.EventName);
605+
Assert.True(2 <= eventSourceListener.LastEvent.Arguments.Count);
606+
Assert.Equal("MyTraceId", eventSourceListener.LastEvent.Arguments["TraceIdentifier"]);
607+
Assert.Equal("200", eventSourceListener.LastEvent.Arguments["StatusCode"]);
594608
eventSourceListener.ResetEventCountAndLastEvent();
595609
}
596610
}

0 commit comments

Comments
 (0)