Skip to content
Permalink
Browse files

Strip large data values out of events

  • Loading branch information
ejsmith committed Dec 12, 2019
1 parent 05f70c7 commit b5022b91e06c7e6694117322f1c1cc5ef71a0919
Showing with 28 additions and 11 deletions.
  1. +1 −1 global.json
  2. +27 −10 src/Exceptionless.Core/Plugins/EventParser/Default/JsonEventParserPlugin.cs
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "3.1.100",
"rollForward": "latest"
"rollForward": "latestMajor"
}
}
@@ -5,32 +5,49 @@
using Exceptionless.Core.Models;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using System.IO;
using Newtonsoft.Json.Linq;
using Microsoft.Extensions.Logging;

namespace Exceptionless.Core.Plugins.EventParser {
[Priority(0)]
public class JsonEventParserPlugin : PluginBase, IEventParserPlugin {
private readonly JsonSerializerSettings _settings;
private readonly JsonSerializer _serializer;

public JsonEventParserPlugin(IOptions<AppOptions> options, JsonSerializerSettings settings) : base(options) {
_settings = settings;
_serializer = JsonSerializer.CreateDefault(_settings);
}

public List<PersistentEvent> ParseEvents(string input, int apiVersion, string userAgent) {
if (apiVersion < 2)
return null;

var events = new List<PersistentEvent>();
switch (input.GetJsonType()) {
case JsonType.Object: {
if (input.TryFromJson(out PersistentEvent ev, _settings))
events.Add(ev);
break;
}
case JsonType.Array: {
if (input.TryFromJson(out PersistentEvent[] parsedEvents, _settings))
events.AddRange(parsedEvents);

break;
var reader = new JsonTextReader(new StringReader(input));
reader.DateParseHandling = DateParseHandling.None;

while (reader.Read()) {
if (reader.TokenType == JsonToken.StartObject) {
var ev = JToken.ReadFrom(reader);

var data = ev["data"];
if (data != null) {
foreach (var property in data.Children<JProperty>()) {
// strip out large data entries
if (property.Value.ToString().Length > 50000) {
property.Value = "<Data Too Large>";
}
}
}

try {
events.Add(ev.ToObject<PersistentEvent>(_serializer));
} catch (Exception ex) {
_logger.LogError(ex, "Error deserializing event.");
}
}
}

0 comments on commit b5022b9

Please sign in to comment.
You can’t perform that action at this time.