Skip to content

Commit 6bcc8a2

Browse files
author
Dan Gidman
committed
SF-6393 Adding Order to Milliseconds
1 parent 75208be commit 6bcc8a2

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Src/StackifyLib/Internal/Logs/LogClient.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using System.Net;
66
using System.Text;
7+
using System.Threading;
78
using System.Threading.Tasks;
89
//using System.Web.Configuration;
910
using Newtonsoft.Json;
@@ -123,6 +124,13 @@ public bool ErrorShouldBeSent(StackifyError error)
123124
return governor.ErrorShouldBeSent(error);
124125
}
125126

127+
128+
129+
private long? LastEpochMs = 0;
130+
private object locker = new object();
131+
private int count;
132+
133+
126134
public void QueueMessage(LogMsg msg)
127135
{
128136
if (msg == null) return;
@@ -139,6 +147,23 @@ public void QueueMessage(LogMsg msg)
139147
isError = 1;
140148
}
141149

150+
// works on the assumption that the epochMS will always be incrementing as it reaches this point
151+
if (LastEpochMs < msg.EpochMs)
152+
{
153+
// reset counter if we are no longer in the same ms
154+
lock (locker)
155+
{
156+
//https://msdn.microsoft.com/en-us/library/system.threading.interlocked_methods(v=vs.110).aspx
157+
LastEpochMs = msg.EpochMs;
158+
Interlocked.Exchange(ref count, 0);
159+
msg.Order = 0;
160+
}
161+
}
162+
else
163+
{
164+
msg.Order = Interlocked.Increment(ref count);
165+
}
166+
142167
//Used by Stackify profiler only
143168
if (Logger.PrefixEnabled())
144169
{

Src/StackifyLib/Models/LogMsgGroup.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ public LogMsg()
9595
[JsonProperty]
9696
public List<string> Tags { get; set; }
9797

98+
[JsonProperty(PropertyName = "order")]
99+
public int Order { get; set; }
100+
98101
[JsonIgnore]
99102
public LogMsgGroup AppDetails { get; set; }
100103

0 commit comments

Comments
 (0)