Skip to content

Commit 9de8b81

Browse files
Merge pull request #94 from rakista112/develop
Attach TransactionID in Net Core logs
2 parents 3397f8e + 9e5cf98 commit 9de8b81

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Src/StackifyLib/Internal/Logs/LogQueue.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
using System;
44
using System.Collections.Concurrent;
55
using System.Collections.Generic;
6+
using System.Diagnostics;
67
using System.Linq;
8+
using System.Reflection;
9+
using System.Threading;
710
using System.Threading.Tasks;
811

912
#if NETFULL
@@ -99,6 +102,7 @@ public void QueueLogMessage(Models.LogMsg msg)
99102
// ignore
100103
}
101104

105+
102106
#if NETFULL
103107
try
104108
{
@@ -177,6 +181,34 @@ public void QueueLogMessage(Models.LogMsg msg)
177181
}
178182
}
179183
}
184+
#else
185+
// else if .Net Core
186+
// get RequestID
187+
if (string.IsNullOrEmpty(msg.TransID))
188+
{
189+
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
190+
191+
var agentAssemblyQry = assemblies.Where(assembly => assembly.FullName.Contains("Stackify.Agent"));
192+
if(agentAssemblyQry.Count() > 0)
193+
{
194+
var middleware = agentAssemblyQry.First();
195+
var callContextType = middleware.GetType("Stackify.Agent.Threading.StackifyCallContext");
196+
if (callContextType != null)
197+
{
198+
var traceCtxType = middleware.GetType("Stackify.Agent.Tracing.ITraceContext");
199+
if(traceCtxType != null)
200+
{
201+
var traceContextProp = callContextType.GetProperty("TraceContext")?.GetValue(null);
202+
if (traceContextProp != null)
203+
{
204+
var reqIdProp = traceCtxType.GetProperty("RequestId")?.GetValue(traceContextProp)?.ToString();
205+
if(!string.IsNullOrEmpty(reqIdProp))
206+
msg.TransID = reqIdProp;
207+
}
208+
}
209+
}
210+
}
211+
}
180212
#endif
181213

182214
_MessageBuffer.Enqueue(msg);

0 commit comments

Comments
 (0)