lumberjack_data_dog_device 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60c74e54590298ee33cfbb9d042360094f58277417e7ce3827fd3c65d26a0f0d
4
- data.tar.gz: 772bed3d6c5f1908b9929e55dae07479ae02ce04942cd515b6c587cc1792b044
3
+ metadata.gz: 5dc89bac640c1450fe612caa49767cc803423030e16cee302387c00466996a0f
4
+ data.tar.gz: 27947af281577cee4c4b0ca72d7aa033fd8ea13b79c076f2308baf19565b16a1
5
5
  SHA512:
6
- metadata.gz: f542690e1f9b8ad79c0673d59ab4fbf42f6733e98fda5f4845c00aad05fbb5da2a7b8db67bd19452a5b31269d48cafe015733539669527bd05e6cfc65fe4e3b7
7
- data.tar.gz: 760efdee4a408fa4b52c123a0da1f7daee2a123c657c75cf145770e19959e1e62e734d902aa54dfb86deeb5dfa926d69ab50b2d244fdace2c5b4833a35a4e8ee
6
+ metadata.gz: e2826f6ad6233b10c5ecc2578de5cf0968f86d749c1b3db03ba061c1848fbfa9c2c480126e024d50a24d1d293e895fcede3c61fc1f872570f23e177f6a84e161
7
+ data.tar.gz: 155ad680ada842234fcc9dad6dd5fa697022120586987fc0a7644c2cf6e1e49425783d1f75b6a133f28b358a771e88fc560c1e86fbabfba338c6217d8a593e92
@@ -1,3 +1,8 @@
1
+ # 1.0.1
2
+
3
+ * Format non-hashes in log messages as strings to prevent stack overflow on objects that cannot be serialized to JSON.
4
+ * Add option max_message_length to limit the length of message payload.
5
+
1
6
  # 1.0.0
2
7
 
3
8
  * Initial release
data/README.md CHANGED
@@ -23,6 +23,8 @@ This gem provides a logging device that produces JSON output that matches the st
23
23
 
24
24
  This device extends from [`Lumberjack::JsonDevice`](). It is not tied to Data Dog in any way other than that it is opinionated about how to map and format some log tags. It can be used with other services or pipelines without issue.
25
25
 
26
+ You can optionally specify a maximum message length with the `max_message_length` option on the device. Doing so will trucate the message payload to keep it under this number of characters. This option is provided because JSON payloads get messed up and cannot be parsed if they get too big.
27
+
26
28
  ## Example
27
29
 
28
30
  You could log an HTTP request to some of the DataDog standard fields like this:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
@@ -10,9 +10,9 @@ module Lumberjack
10
10
  class DataDogDevice < JsonDevice
11
11
 
12
12
  module ExceptionHash
13
-
13
+
14
14
  protected
15
-
15
+
16
16
  def exception_hash(exception, device)
17
17
  hash = {"kind" => exception.class.name}
18
18
  hash["message"] = exception.message unless exception.message.nil?
@@ -24,23 +24,32 @@ module Lumberjack
24
24
  hash
25
25
  end
26
26
  end
27
-
27
+
28
28
  # Formatter to format a messge as an error if it is an exception.
29
29
  class MessageExceptionFormatter
30
30
  include ExceptionHash
31
-
31
+
32
32
  def initialize(device = nil)
33
33
  @device = device
34
34
  end
35
-
35
+
36
36
  def call(object)
37
37
  if object.is_a?(Exception)
38
38
  {
39
39
  "message" => object.inspect,
40
40
  "error" => exception_hash(object, @device)
41
41
  }
42
- else
42
+ elsif object.is_a?(Hash)
43
43
  { "message" => object }
44
+ elsif object.nil?
45
+ { "message" => nil }
46
+ else
47
+ message = object.to_s
48
+ max_message_length = @device.max_message_length
49
+ if max_message_length && message.length > max_message_length
50
+ message = message[0, max_message_length]
51
+ end
52
+ { "message" => message }
44
53
  end
45
54
  end
46
55
  end
@@ -124,14 +133,19 @@ module Lumberjack
124
133
  # One use for it is to keep stack traces clean and prevent them from overflowing the limit on
125
134
  # the payload size for an individual log entry.
126
135
  attr_accessor :backtrace_cleaner
127
-
128
- def initialize(stream_or_device, backtrace_cleaner: nil)
136
+
137
+ # You can specify a limit on the message size. Messages over this size will be split into multiple
138
+ # log entries to prevent overflowing the limit on message size which makes the log entries unparseable.
139
+ attr_accessor :max_message_length
140
+
141
+ def initialize(stream_or_device, backtrace_cleaner: nil, max_message_length: nil)
129
142
  super(stream_or_device, mapping: data_dog_mapping)
130
143
  self.backtrace_cleaner = backtrace_cleaner
144
+ self.max_message_length = max_message_length
131
145
  end
132
-
146
+
133
147
  private
134
-
148
+
135
149
  def data_dog_mapping
136
150
  {
137
151
  time: "timestamp",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lumberjack_data_dog_device
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-21 00:00:00.000000000 Z
11
+ date: 2020-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lumberjack_json_device