Skip to content

Commit 0936a12

Browse files
committed
Fixed #110 Submitted event handler wasn't being called on deduplicated events.
@ejsmith I changed this to just copy the extra info instead of using event handlers.
1 parent f17ff18 commit 0936a12

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

src/Exceptionless.Tests/Plugins/PluginTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,30 @@ public void VerifyDeduplication() {
724724
Thread.Sleep(50);
725725
Assert.Equal(9, mergedContext.Event.Count.GetValueOrDefault());
726726
}
727+
728+
[Fact]
729+
public void VerifyDeduplicationPluginWillCallSubmittingHandler() {
730+
var client = CreateClient();
731+
foreach (var plugin in client.Configuration.Plugins)
732+
client.Configuration.RemovePlugin(plugin.Key);
733+
client.Configuration.AddPlugin(new DuplicateCheckerPlugin(TimeSpan.FromMilliseconds(75)));
734+
735+
int submittingEventHandlerCalls = 0;
736+
client.SubmittingEvent += (sender, args) => {
737+
Interlocked.Increment(ref submittingEventHandlerCalls);
738+
};
739+
740+
for (int index = 0; index < 3; index++) {
741+
client.SubmitLog("test");
742+
if (index > 0)
743+
continue;
744+
745+
Assert.Equal(1, submittingEventHandlerCalls);
746+
}
747+
748+
Thread.Sleep(100);
749+
Assert.Equal(2, submittingEventHandlerCalls);
750+
}
727751

728752
[Fact]
729753
public void VerifyDeduplicationMultithreaded() {

src/Exceptionless/ExceptionlessClient.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public string GetLastReferenceId() {
233233
/// </summary>
234234
public event EventHandler<EventSubmittingEventArgs> SubmittingEvent;
235235

236-
private bool OnSubmittingEvent(Event ev, ContextData pluginContextData) {
236+
protected internal bool OnSubmittingEvent(Event ev, ContextData pluginContextData) {
237237
var args = new EventSubmittingEventArgs(this, ev, pluginContextData);
238238
OnSubmittingEvent(args);
239239
return !args.Cancel;
@@ -243,7 +243,7 @@ private bool OnSubmittingEvent(Event ev, ContextData pluginContextData) {
243243
/// Raises the <see cref="SubmittingEvent" /> event.
244244
/// </summary>
245245
/// <param name="e">The <see cref="EventSubmittingEventArgs" /> instance containing the event data.</param>
246-
protected void OnSubmittingEvent(EventSubmittingEventArgs e) {
246+
protected internal void OnSubmittingEvent(EventSubmittingEventArgs e) {
247247
if (SubmittingEvent == null)
248248
return;
249249

@@ -268,7 +268,7 @@ protected void OnSubmittingEvent(EventSubmittingEventArgs e) {
268268
/// Raises the <see cref="SubmittedEvent" /> event.
269269
/// </summary>
270270
/// <param name="e">The <see cref="EventSubmittedEventArgs" /> instance containing the event data.</param>
271-
protected void OnSubmittedEvent(EventSubmittedEventArgs e) {
271+
protected internal void OnSubmittedEvent(EventSubmittedEventArgs e) {
272272
if (SubmittedEvent == null)
273273
return;
274274

src/Exceptionless/Plugins/Default/1010_DuplicateCheckerPlugin.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Exceptionless.Dependency;
55
using System.Collections.Generic;
66
using System.Linq;
7+
using Exceptionless.Models;
78

89
namespace Exceptionless.Plugins.Default {
910
[Priority(1010)]
@@ -99,7 +100,27 @@ public void IncrementCount(int value) {
99100

100101
public void Resubmit() {
101102
_context.Event.Count = _count;
103+
104+
// ensure all required data
105+
if (String.IsNullOrEmpty(_context.Event.Type))
106+
_context.Event.Type = Event.KnownTypes.Log;
107+
if (_context.Event.Date == DateTimeOffset.MinValue)
108+
_context.Event.Date = DateTimeOffset.Now;
109+
110+
if (!_context.Client.OnSubmittingEvent(_context.Event, _context.ContextData)) {
111+
_context.Log.FormattedInfo(typeof(DuplicateCheckerPlugin), "Event submission cancelled by event handler: id={0} type={1}", _context.Event.ReferenceId, _context.Event.Type);
112+
return;
113+
}
114+
115+
_context.Log.FormattedTrace(typeof(DuplicateCheckerPlugin), "Submitting event: type={0}{1}", _context.Event.Type, !String.IsNullOrEmpty(_context.Event.ReferenceId) ? " refid=" + _context.Event.ReferenceId : String.Empty);
102116
_context.Resolver.GetEventQueue().Enqueue(_context.Event);
117+
118+
if (!String.IsNullOrEmpty(_context.Event.ReferenceId)) {
119+
_context.Log.FormattedTrace(typeof(DuplicateCheckerPlugin), "Setting last reference id '{0}'", _context.Event.ReferenceId);
120+
_context.Resolver.GetLastReferenceIdManager().SetLast(_context.Event.ReferenceId);
121+
}
122+
123+
_context.Client.OnSubmittedEvent(new EventSubmittedEventArgs(_context.Client, _context.Event, _context.ContextData));
103124
}
104125

105126
public void UpdateDate(DateTimeOffset date) {

0 commit comments

Comments
 (0)