Skip to content

Commit

Permalink
Merge pull request #82 from exceptionless/feature/stacking
Browse files Browse the repository at this point in the history
Updates for custom stacking
  • Loading branch information
niemyjski committed Feb 24, 2016
2 parents fbe6c96 + 4df268f commit 3195661
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@
</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Exceptionless.DateTimeExtensions, Version=3.1.42.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Exceptionless.DateTimeExtensions.3.1.42\lib\portable-net40+win+wpa81+MonoAndroid10+xamarinios10+MonoTouch10\Exceptionless.DateTimeExtensions.dll</HintPath>
<Reference Include="Exceptionless.DateTimeExtensions, Version=3.1.44.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Exceptionless.DateTimeExtensions.3.1.44\lib\portable-net40+win+wpa81+MonoAndroid10+xamarinios10+MonoTouch10\Exceptionless.DateTimeExtensions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Exceptionless.RandomData, Version=1.0.17.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Exceptionless.RandomData.1.0.17.0\lib\net40\Exceptionless.RandomData.dll</HintPath>
<Reference Include="Exceptionless.RandomData, Version=1.0.21.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Exceptionless.RandomData.1.0.21.0\lib\net40\Exceptionless.RandomData.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="log4net, Version=1.2.15.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
Expand Down
4 changes: 2 additions & 2 deletions Source/Samples/SampleConsole/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Exceptionless.DateTimeExtensions" version="3.1.42" targetFramework="net451" />
<package id="Exceptionless.RandomData" version="1.0.17.0" targetFramework="net452" />
<package id="Exceptionless.DateTimeExtensions" version="3.1.44" targetFramework="net452" />
<package id="Exceptionless.RandomData" version="1.0.21.0" targetFramework="net452" />
<package id="log4net" version="2.0.5" targetFramework="net451" />
<package id="NLog" version="4.2.3" targetFramework="net451" />
<package id="NLog.Config" version="4.2.3" targetFramework="net451" />
Expand Down
18 changes: 18 additions & 0 deletions Source/Samples/SampleMvc/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Web;
using System.Web.Mvc;
Expand Down Expand Up @@ -32,6 +33,23 @@ public ViewResult Error() {
public ViewResult CustomError() {
return View("CustomError");
}

[HttpGet]
public ViewResult ManualStacking(string myId) {
ExceptionlessClient.Default.CreateLog(nameof(HomeController), "Random Log message")
.SetManualStackingInfo("Manual Stacked Log Messages", new Dictionary<string, string> {
{ "Controller", nameof(HomeController) },
{ "Action", nameof(ManualStacking) }
})
.Submit();

try {
throw new Exception(Guid.NewGuid().ToString());
} catch (Exception ex) {
ex.ToExceptionless().SetManualStackingKey(nameof(HomeController)).Submit();
throw;
}
}

[HttpGet]
public ViewResult FourZeroFour() {
Expand Down
7 changes: 6 additions & 1 deletion Source/Samples/SampleMvc/Controllers/ValuesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ namespace Exceptionless.SampleMvc.Controllers {
public class ValuesController : ApiController {
// GET api/values
public IEnumerable<string> Get() {
throw new ApplicationException("WebApi GET error");
try {
throw new ApplicationException("WebApi GET error");
} catch (Exception ex) {
ex.ToExceptionless().Submit();
throw;
}
}

// GET api/values/5
Expand Down
1 change: 1 addition & 0 deletions Source/Samples/SampleMvc/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@Html.ActionLink("Boom!", "Boom")
@Html.ActionLink("Custom Boom!", "CustomBoom")
@Html.ActionLink("Boom 25!", "Boom25")
@Html.ActionLink("Manual Stacking", "ManualStacking", new { myId = "123456789" })

<a href="javascript:doAjax()">Ajax Boom</a>

Expand Down
1 change: 1 addition & 0 deletions Source/Shared/Exceptionless.Portable.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<Compile Include="Dependency\TinyIoC.cs" />
<Compile Include="Events\EventSubmissionEventArgsBase.cs" />
<Compile Include="Events\EventSubmittedEventArgs.cs" />
<Compile Include="Models\Client\Data\ManualStackingInfo.cs" />
<Compile Include="Plugins\Default\025_SessionIdManagementPlugin.cs" />
<Compile Include="Plugins\Default\030_DuplicateCheckerPlugin.cs" />
<Compile Include="Plugins\ContextData.cs" />
Expand Down
33 changes: 33 additions & 0 deletions Source/Shared/Extensions/EventBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Exceptionless.Models.Data;

namespace Exceptionless {
Expand Down Expand Up @@ -55,6 +56,27 @@ public static EventBuilder SetVersion(this EventBuilder builder, string version)
return builder;
}

/// <summary>
/// Changes default stacking behavior by setting the stacking key.
/// </summary>
/// <param name="builder">The event builder object.</param>
/// <param name="signatureData">Key value pair that determines how the event is stacked.</param>
public static EventBuilder SetManualStackingInfo(this EventBuilder builder, IDictionary<string, string> signatureData) {
builder.Target.SetManualStackingInfo(signatureData);
return builder;
}

/// <summary>
/// Changes default stacking behavior by setting the stacking key.
/// </summary>
/// <param name="builder">The event builder object.</param>
/// <param name="title">The stack title.</param>
/// <param name="signatureData">Key value pair that determines how the event is stacked.</param>
public static EventBuilder SetManualStackingInfo(this EventBuilder builder, string title, IDictionary<string, string> signatureData) {
builder.Target.SetManualStackingInfo(title, signatureData);
return builder;
}

/// <summary>
/// Changes default stacking behavior by setting the stacking key.
/// </summary>
Expand All @@ -64,5 +86,16 @@ public static EventBuilder SetManualStackingKey(this EventBuilder builder, strin
builder.Target.SetManualStackingKey(manualStackingKey);
return builder;
}

/// <summary>
/// Changes default stacking behavior by setting the stacking key.
/// </summary>
/// <param name="builder">The event builder object.</param>
/// <param name="title">The stack title.</param>
/// <param name="manualStackingKey">The manual stacking key.</param>
public static EventBuilder SetManualStackingKey(this EventBuilder builder, string title, string manualStackingKey) {
builder.Target.SetManualStackingKey(title, manualStackingKey);
return builder;
}
}
}
42 changes: 40 additions & 2 deletions Source/Shared/Extensions/EventExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,53 @@ private static bool IsValidIdentifier(string value) {
}

/// <summary>
/// Sets the manual stacking key
/// Changes default stacking behavior
/// </summary>
/// <param name="ev">The event</param>
/// <param name="signatureData">Key value pair that determines how the event is stacked.</param>
public static void SetManualStackingInfo(this Event ev, IDictionary<string, string> signatureData) {
if (signatureData == null || signatureData.Count == 0)
return;

ev.Data[Event.KnownDataKeys.ManualStackingInfo] = new ManualStackingInfo(signatureData);
}

/// <summary>
/// Changes default stacking behavior
/// </summary>
/// <param name="ev">The event</param>
/// <param name="title">The stack title.</param>
/// <param name="signatureData">Key value pair that determines how the event is stacked.</param>
public static void SetManualStackingInfo(this Event ev, string title, IDictionary<string, string> signatureData) {
if (String.IsNullOrWhiteSpace(title) || signatureData == null || signatureData.Count == 0)
return;

ev.Data[Event.KnownDataKeys.ManualStackingInfo] = new ManualStackingInfo(title, signatureData);
}

/// <summary>
/// Changes default stacking behavior by setting the stacking info.
/// </summary>
/// <param name="ev">The event</param>
/// <param name="manualStackingKey">The manual stacking key.</param>
public static void SetManualStackingKey(this Event ev, string manualStackingKey) {
if (String.IsNullOrWhiteSpace(manualStackingKey))
return;

ev.Data[Event.KnownDataKeys.ManualStackingKey] = manualStackingKey.Trim();
ev.Data[Event.KnownDataKeys.ManualStackingInfo] = new ManualStackingInfo(null, new Dictionary<string, string> { { "ManualStackingKey", manualStackingKey } });
}

/// <summary>
/// Changes default stacking behavior by setting the stacking info.
/// </summary>
/// <param name="ev">The event</param>
/// <param name="title">The stack title.</param>
/// <param name="manualStackingKey">The manual stacking key.</param>
public static void SetManualStackingKey(this Event ev, string title, string manualStackingKey) {
if (String.IsNullOrWhiteSpace(title) || String.IsNullOrWhiteSpace(manualStackingKey))
return;

ev.Data[Event.KnownDataKeys.ManualStackingInfo] = new ManualStackingInfo(title, new Dictionary<string, string> { { "ManualStackingKey", manualStackingKey } });
}

public static T GetDataValue<T>(this Event ev, string key, IJsonSerializer serializer = null) {
Expand Down
33 changes: 33 additions & 0 deletions Source/Shared/Models/Client/Data/ManualStackingInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using Exceptionless.Extensions;

namespace Exceptionless.Models.Data {
public class ManualStackingInfo {
public ManualStackingInfo() {
SignatureData = new Dictionary<string, string>();
}

public ManualStackingInfo(string title) : this() {
if (!String.IsNullOrWhiteSpace(title))
Title = title.Trim();
}

public ManualStackingInfo(string title, IDictionary<string, string> signatureData) : this(title) {
if (signatureData != null && signatureData.Count > 0)
SignatureData.AddRange(signatureData);
}

public ManualStackingInfo(IDictionary<string, string> signatureData) : this(null, signatureData) {}

/// <summary>
/// Stack Title (defaults to the event message)
/// </summary>
public string Title { get; set; }

/// <summary>
/// Key value pair that determines how the event is stacked.
/// </summary>
public IDictionary<string, string> SignatureData { get; set; }
}
}
2 changes: 1 addition & 1 deletion Source/Shared/Models/Client/Event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static class KnownDataKeys {
public const string Version = "@version";
public const string Level = "@level";
public const string SubmissionMethod = "@submission_method";
public const string ManualStackingKey = "@stack";
public const string ManualStackingInfo = "@stack";
}
}
}
4 changes: 0 additions & 4 deletions Source/Shared/Serializer/ExceptionlessContractResolver.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Reflection;
using Exceptionless.Models;
using Exceptionless.Json;
using Exceptionless.Json.Serialization;
using Exceptionless.Extensions;
Expand All @@ -24,9 +23,6 @@ protected override JsonProperty CreateProperty(MemberInfo member, MemberSerializ
}

protected override JsonDictionaryContract CreateDictionaryContract(Type objectType) {
if (objectType != typeof(DataDictionary) && objectType != typeof(SettingsDictionary))
return base.CreateDictionaryContract(objectType);

JsonDictionaryContract contract = base.CreateDictionaryContract(objectType);
contract.PropertyNameResolver = propertyName => propertyName;
return contract;
Expand Down
8 changes: 4 additions & 4 deletions Source/Tests/Exceptionless.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Exceptionless.RandomData, Version=1.0.17.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Exceptionless.RandomData.1.0.17.0\lib\net40\Exceptionless.RandomData.dll</HintPath>
<Reference Include="Exceptionless.RandomData, Version=1.0.21.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Exceptionless.RandomData.1.0.21.0\lib\net40\Exceptionless.RandomData.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Foundatio, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Foundatio.3.0.629\lib\net45\Foundatio.dll</HintPath>
<Reference Include="Foundatio, Version=4.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Foundatio.4.0.672\lib\net45\Foundatio.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Owin, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
Expand Down
7 changes: 3 additions & 4 deletions Source/Tests/Plugins/PluginTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void ConfigurationDefaults_SerializedProperties() {
client.Configuration.DefaultData.Add(Event.KnownDataKeys.EnvironmentInfo, new EnvironmentInfo { MachineName = "blake" });
client.Configuration.DefaultData.Add(Event.KnownDataKeys.Error, new Error { Message = "blake" });
client.Configuration.DefaultData.Add(Event.KnownDataKeys.Level, "Debug");
client.Configuration.DefaultData.Add(Event.KnownDataKeys.ManualStackingKey, "blake");
client.Configuration.DefaultData.Add(Event.KnownDataKeys.ManualStackingInfo, "blake");
client.Configuration.DefaultData.Add(Event.KnownDataKeys.RequestInfo, new RequestInfo { Host = "blake" });
client.Configuration.DefaultData.Add(Event.KnownDataKeys.SimpleError, new SimpleError { Message = "blake" });
client.Configuration.DefaultData.Add(Event.KnownDataKeys.SubmissionMethod, "test");
Expand All @@ -87,7 +87,7 @@ public void ConfigurationDefaults_SerializedProperties() {
Assert.Equal("blake", context.Event.GetError().Message);
Assert.Equal("blake", context.Event.GetError(serializer).Message);
Assert.Equal("Debug", context.Event.Data[Event.KnownDataKeys.Level]);
Assert.Equal("blake", context.Event.Data[Event.KnownDataKeys.ManualStackingKey]);
Assert.Equal("blake", context.Event.Data[Event.KnownDataKeys.ManualStackingInfo]);
Assert.True(context.Event.Data[Event.KnownDataKeys.RequestInfo] is string);
Assert.Equal("blake", context.Event.GetRequestInfo().Host);
Assert.Equal("blake", context.Event.GetRequestInfo(serializer).Host);
Expand Down Expand Up @@ -153,8 +153,7 @@ public void HandleAggregateExceptionsPlugin_SingleInnerException() {
context = new EventPluginContext(client, new Event());
context.ContextData.SetException(new AggregateException(exceptionOne, exceptionTwo));
plugin.Run(context);
Assert.False(context.Cancel);
Assert.Equal(exceptionOne, context.ContextData.GetException());
Assert.True(context.Cancel);
}

[Fact]
Expand Down
4 changes: 2 additions & 2 deletions Source/Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Exceptionless.RandomData" version="1.0.17.0" targetFramework="net451" />
<package id="Foundatio" version="3.0.629" targetFramework="net451" />
<package id="Exceptionless.RandomData" version="1.0.21.0" targetFramework="net451" />
<package id="Foundatio" version="4.0.672" targetFramework="net451" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net451" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net451" />
<package id="Microsoft.AspNet.WebApi.Owin" version="5.2.3" targetFramework="net451" />
Expand Down

0 comments on commit 3195661

Please sign in to comment.