Skip to content

Commit 863b926

Browse files
committed
Added a new session plugin useful for desktop based applications that don't send very many events but are long lived.
1 parent cbf04bc commit 863b926

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

Source/Shared/Exceptionless.Portable.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<Compile Include="Dependency\TinyIoC.cs" />
6161
<Compile Include="Events\EventSubmissionEventArgsBase.cs" />
6262
<Compile Include="Events\EventSubmittedEventArgs.cs" />
63+
<Compile Include="Plugins\Default\025_SessionIdManagementPlugin.cs" />
6364
<Compile Include="Plugins\Default\030_DuplicateCheckerPlugin.cs" />
6465
<Compile Include="Plugins\ContextData.cs" />
6566
<Compile Include="Plugins\Default\1000_CancelSessionsWithNoUserPlugin.cs" />

Source/Shared/Extensions/ExceptionlessConfigurationExtensions.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Exceptionless.Logging;
99
using Exceptionless.Models;
1010
using Exceptionless.Models.Data;
11+
using Exceptionless.Plugins;
1112
using Exceptionless.Storage;
1213

1314
namespace Exceptionless {
@@ -86,11 +87,21 @@ public static string GetInstallId(this ExceptionlessConfiguration config) {
8687
return persistedClientData[INSTALL_ID_KEY];
8788
}
8889

89-
public static void UseSessions(this ExceptionlessConfiguration config, bool sendHeartbeats = true) {
90+
/// <summary>
91+
/// Automatically send session start, session heartbeats and session end events.
92+
/// </summary>
93+
/// <param name="config">Exceptionless configuration</param>
94+
/// <param name="sendHeartbeats">Controls whether heartbeat events are sent on an interval.</param>
95+
/// <param name="heartbeatInterval">The interval at which heartbeats are sent after the last sent event. The default is 30 seconds.</param>
96+
/// <param name="useSessionIdManagement">Allows you to manually control the session id. This is only recommended for single user desktop environments.</param>
97+
public static void UseSessions(this ExceptionlessConfiguration config, bool sendHeartbeats = true, TimeSpan? heartbeatInterval = null, bool useSessionIdManagement = false) {
9098
config.SessionsEnabled = true;
9199

100+
if (useSessionIdManagement)
101+
config.AddPlugin<SessionIdManagementPlugin>();
102+
92103
if (sendHeartbeats)
93-
config.AddPlugin<HeartbeatPlugin>();
104+
config.AddPlugin(new HeartbeatPlugin(heartbeatInterval));
94105
}
95106

96107
public static InMemoryExceptionlessLog UseInMemoryLogger(this ExceptionlessConfiguration config, LogLevel minLogLevel = LogLevel.Info) {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
3+
namespace Exceptionless.Plugins {
4+
[Priority(25)]
5+
public class SessionIdManagementPlugin : IEventPlugin {
6+
private string _sessionId;
7+
public void Run(EventPluginContext context) {
8+
if (context.Event.IsSessionStart() || String.IsNullOrEmpty(_sessionId))
9+
_sessionId = Guid.NewGuid().ToString("N");
10+
11+
if (context.Event.IsSessionStart())
12+
context.Event.ReferenceId = _sessionId;
13+
else
14+
context.Event.SetEventReference("session", _sessionId);
15+
16+
if (context.Event.IsSessionEnd())
17+
_sessionId = null;
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)