appsignal 1.0.5.beta.2 → 1.0.5.beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4dd8c7b3fec034fcd99924f7658b6b698878c520
4
- data.tar.gz: be461d8b433726f48663e7b40a631460f0ad1a1e
3
+ metadata.gz: c11d01582a42d050f75ede7b8b0fbd0736e2c600
4
+ data.tar.gz: 049e4b5c7728b3dc1efbc3a20527b70d8b9cb5cd
5
5
  SHA512:
6
- metadata.gz: 021c29a0304e931d1a6f8df1e24d2d2c4fc9923ec43f9262cdb880d0f57a553209815e5b7a98a5169f729d5b84354e0e8dc95c63fdfc74752832528ad26f5ecc
7
- data.tar.gz: a50f561dcfc6121ed0052f918b12651017d520ce4f0ab1f2fcb4621884abf253c56146118c029146620fca60f178f240f113b701f572afbac6947563db4ec5e9
6
+ metadata.gz: d9ffe4b983a86b8b38e9d15969c9887c494311336470648f66837e0a70e4c58ae5fe92a6dd037e0bed8523befab31e0affd439515d1e9f520a29a034953f50a8
7
+ data.tar.gz: 1a808810e53ba4a781b93fc0f1c44ef4509c927df2b4f661cdff1497d0da8d41e61e1d5f5e4958644c15e42f4bef850b700aa47551c921ae529a699beca32138
@@ -2,6 +2,7 @@
2
2
  * Improved sql sanitization
3
3
  * Improved mongoid/mongodb sanitization
4
4
  * Minor performance improvements
5
+ * Better handling for non-utf8 convertable strings
5
6
 
6
7
  # 1.0.4
7
8
  * Make working dir configurable using `APPSIGNAL_WORKING_DIR_PATH` or `:working_dir_path`
@@ -46,7 +46,7 @@ module Appsignal
46
46
  transaction.transaction_index,
47
47
  'query.mongodb',
48
48
  "#{event.command_name.to_s} | #{event.database_name} | #{result}",
49
- JSON.generate(command),
49
+ Appsignal::Utils.json_generate(command),
50
50
  0
51
51
  )
52
52
  end
@@ -28,7 +28,7 @@ module Appsignal
28
28
  @transaction_index,
29
29
  @data['name'],
30
30
  @data['message'],
31
- JSON.generate(@data['backtrace'])
31
+ Appsignal::Utils.json_generate(@data['backtrace'])
32
32
  )
33
33
  end
34
34
 
@@ -43,7 +43,7 @@ module Appsignal
43
43
  Appsignal::Extension.set_transaction_sample_data(
44
44
  @transaction_index,
45
45
  key.to_s,
46
- JSON.generate(data)
46
+ Appsignal::Utils.json_generate(data)
47
47
  )
48
48
  rescue JSON::GeneratorError=>e
49
49
  Appsignal.logger.error("JSON generate error (#{e.message}) for '#{data.inspect}'")
@@ -113,7 +113,7 @@ module Appsignal
113
113
  Appsignal::Extension.set_transaction_sample_data(
114
114
  transaction_index,
115
115
  key.to_s,
116
- JSON.generate(data)
116
+ Appsignal::Utils.json_generate(data)
117
117
  )
118
118
  rescue JSON::GeneratorError=>e
119
119
  Appsignal.logger.error("JSON generate error (#{e.message}) for '#{data.inspect}'")
@@ -142,7 +142,7 @@ module Appsignal
142
142
  transaction_index,
143
143
  error.class.name,
144
144
  error.message,
145
- backtrace ? JSON.generate(backtrace) : ''
145
+ backtrace ? Appsignal::Utils.json_generate(backtrace) : ''
146
146
  )
147
147
  rescue JSON::GeneratorError=>e
148
148
  Appsignal.logger.error("JSON generate error (#{e.message}) for '#{backtrace.inspect}'")
@@ -53,7 +53,7 @@ module Appsignal
53
53
  request['Content-Type'] = CONTENT_TYPE
54
54
  request['Content-Encoding'] = CONTENT_ENCODING
55
55
  request.body = Zlib::Deflate.deflate(
56
- JSON.generate(payload, :quirks_mode => true),
56
+ Appsignal::Utils.json_generate(payload),
57
57
  Zlib::BEST_SPEED
58
58
  )
59
59
  end
@@ -32,5 +32,28 @@ module Appsignal
32
32
  else key
33
33
  end
34
34
  end
35
+
36
+ def self.json_generate(body)
37
+ JSON.generate(jsonify(body))
38
+ end
39
+
40
+ def self.jsonify(value)
41
+ case value
42
+ when String
43
+ value.encode(
44
+ 'utf-8',
45
+ :invalid => :replace,
46
+ :undef => :replace
47
+ )
48
+ when Numeric, NilClass, TrueClass, FalseClass
49
+ value
50
+ when Hash
51
+ Hash[value.map { |k, v| [jsonify(k), jsonify(v)] }]
52
+ when Array
53
+ value.map { |v| jsonify(v) }
54
+ else
55
+ jsonify(value.to_s)
56
+ end
57
+ end
35
58
  end
36
59
  end
@@ -1,5 +1,5 @@
1
1
  require 'yaml'
2
2
 
3
3
  module Appsignal
4
- VERSION = '1.0.5.beta.2'
4
+ VERSION = '1.0.5.beta.3'
5
5
  end
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Appsignal::Utils do
@@ -53,4 +55,30 @@ describe Appsignal::Utils do
53
55
  end
54
56
  end
55
57
  end
58
+
59
+ describe ".json_generate" do
60
+ subject { Appsignal::Utils.json_generate(body) }
61
+
62
+ context "with a valid body" do
63
+ let(:body) { {'the' => 'payload'} }
64
+
65
+ it { should == "{\"the\":\"payload\"}" }
66
+ end
67
+
68
+ context "with a body that contains strings with invalid utf-8 content" do
69
+ let(:string_with_invalid_utf8) { [0x61, 0x61, 0x85].pack('c*') }
70
+ let(:body) { {
71
+ 'field_one' => [0x61, 0x61].pack('c*'),
72
+ 'field_two' => string_with_invalid_utf8,
73
+ 'field_three' => [
74
+ 'one', string_with_invalid_utf8
75
+ ],
76
+ 'field_four' => {
77
+ 'one' => string_with_invalid_utf8
78
+ }
79
+ } }
80
+
81
+ it { should == "{\"field_one\":\"aa\",\"field_two\":\"aa�\",\"field_three\":[\"one\",\"aa�\"],\"field_four\":{\"one\":\"aa�\"}}" }
82
+ end
83
+ end
56
84
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appsignal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5.beta.2
4
+ version: 1.0.5.beta.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Beekman
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-03-07 00:00:00.000000000 Z
12
+ date: 2016-03-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack