opener-webservice 2.1.3 → 2.2.0

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
  SHA1:
3
- metadata.gz: 0b9a0d7f72b7b86539f4a3dd8b04610a7cf90dce
4
- data.tar.gz: f1b8a5540c7938cfee71a5afbb055bd66b325167
3
+ metadata.gz: 60efcf46d3e5c00cd804fbaace65fe4ac22d5a42
4
+ data.tar.gz: 2c59b1584c51702482b03a6c86d60939a2b2f0dc
5
5
  SHA512:
6
- metadata.gz: 1955c6e951925ca16b085bc3db87c4b3181eecef36f800a6fa7af07a0d95d8d199dbe613cbed745da62b1d92ee5070d6d1c4b3a22a87a41158bf2b2b7ed52368
7
- data.tar.gz: 8105f3b2517aa72a2fbfdbd789ba0cc2ffcd4991b81f9fa3f786ec02fb7cf4e2fa5e834e758cecdd58ab00a3fbe740a7c04f2f8b803895ae6a200ebc665297b6
6
+ metadata.gz: aa3ffd21a7473bd15a595466709b01c7f84210c816d5746c36e138f43d5aee591c85f741e54af6d2d474cceab6ddd919c6f845d1c94d0b7ceeca511900bc6919
7
+ data.tar.gz: 7747fcad14b44ffd8afaab6ca0d14a307ca5c3c0f74c90e294f384f3859250f43513ed250bfdd62ce21e2a2081f3832c9e4a5fb482d049e5298732ef50f747c1
@@ -17,3 +17,4 @@ require_relative 'webservice/error_handler'
17
17
  require_relative 'webservice/input_extractor'
18
18
  require_relative 'webservice/input_sanitizer'
19
19
  require_relative 'webservice/option_parser'
20
+ require_relative 'webservice/transaction'
@@ -68,6 +68,15 @@ module Opener
68
68
  return !!ENV['ROLLBAR_TOKEN']
69
69
  end
70
70
 
71
+ ##
72
+ # Returns `true` if New Relic monitoring should be enabled.
73
+ #
74
+ # @return [TrueClass|FalseClass]
75
+ #
76
+ def self.newrelic?
77
+ return !!ENV['NEWRELIC_TOKEN']
78
+ end
79
+
71
80
  ##
72
81
  # Configures Rollbar.
73
82
  #
@@ -56,7 +56,12 @@ module Opener
56
56
  end
57
57
 
58
58
  error do
59
- Rollbar.report_exception(env['sinatra.error'])
59
+ Rollbar.error(
60
+ env['sinatra.error'],
61
+ :parameters => Transaction.current.parameters
62
+ )
63
+
64
+ Transaction.reset_current
60
65
 
61
66
  halt(
62
67
  500,
@@ -145,6 +150,8 @@ module Opener
145
150
 
146
151
  content_type(ctype)
147
152
 
153
+ Transaction.reset_current
154
+
148
155
  return output
149
156
  end
150
157
 
@@ -182,6 +189,8 @@ module Opener
182
189
  # @return [Array]
183
190
  #
184
191
  def analyze(options)
192
+ add_transaction_parameters(options)
193
+
185
194
  comp_options = InputSanitizer.new.whitelist_options(
186
195
  options,
187
196
  self.class.accepted_params
@@ -262,6 +271,22 @@ module Opener
262
271
  CallbackHandler.new.post(next_url, new_payload)
263
272
  end
264
273
 
274
+ ##
275
+ # @param [Hash] options
276
+ #
277
+ def add_transaction_parameters(options)
278
+ # If raw input is given we'll trim it so the payload isn't too large for
279
+ # Rollbar/New Relic. This uses Hash#merge so we don't modify the
280
+ # original options variable.
281
+ if options['input']
282
+ options = options.merge(
283
+ 'input' => options['input'].byteslice(0, 256)
284
+ )
285
+ end
286
+
287
+ Transaction.current.add_parameters(options)
288
+ end
289
+
265
290
  ##
266
291
  # Returns a Hash containing the parameters from a JSON payload. The keys
267
292
  # of this Hash are returned as _strings_ to prevent Symbol DOS attacks.
@@ -0,0 +1,56 @@
1
+ module Opener
2
+ module Webservice
3
+ ##
4
+ # Class for storing information of a single transaction in a thread.
5
+ #
6
+ # @!attribute [r] parameters
7
+ # @return [Hash]
8
+ #
9
+ class Transaction
10
+ attr_reader :parameters
11
+
12
+ ##
13
+ # The name of the key to store the current transaction in.
14
+ #
15
+ # @return [Symbol]
16
+ #
17
+ THREAD_KEY = :opener_webservices_transaction
18
+
19
+ ##
20
+ # Returns the current transaction.
21
+ #
22
+ # @return [Opener::Daemons::Transaction]
23
+ #
24
+ def self.current
25
+ return Thread.current[THREAD_KEY] ||= new
26
+ end
27
+
28
+ ##
29
+ # Removes the current transaction
30
+ #
31
+ def self.reset_current
32
+ Thread.current[THREAD_KEY] = nil
33
+ end
34
+
35
+ def initialize
36
+ @parameters = {}
37
+ end
38
+
39
+ ##
40
+ # Merges the given parameters with the existing ones.
41
+ #
42
+ # If New Relic is enabled the parameters are also added to the current
43
+ # New Relic transaction.
44
+ #
45
+ # @param [Hash] parameters
46
+ #
47
+ def add_parameters(parameters = {})
48
+ @parameters = @parameters.merge(parameters)
49
+
50
+ if Configuration.newrelic?
51
+ NewRelic::Agent.add_custom_parameters(parameters)
52
+ end
53
+ end
54
+ end # Transaction
55
+ end # Webservice
56
+ end # Opener
@@ -1,5 +1,5 @@
1
1
  module Opener
2
2
  module Webservice
3
- VERSION = '2.1.3'
3
+ VERSION = '2.2.0'
4
4
  end # Webservice
5
5
  end # Opener
@@ -18,11 +18,10 @@ Gem::Specification.new do |spec|
18
18
  ]).select { |file| File.file?(file) }
19
19
 
20
20
  spec.add_dependency 'sinatra', '~> 1.4.3'
21
- spec.add_dependency 'uuidtools'
22
21
  spec.add_dependency 'json'
23
22
  spec.add_dependency 'opener-callback-handler', '~> 1.0'
24
23
  spec.add_dependency 'httpclient', ['~> 2.0', '>= 2.5.3.3']
25
- spec.add_dependency 'opener-core', '~> 2.0'
24
+ spec.add_dependency 'opener-core', '~> 2.3'
26
25
  spec.add_dependency 'puma'
27
26
  spec.add_dependency 'slop', '~> 3.0'
28
27
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opener-webservice
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - development@olery.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-03 00:00:00.000000000 Z
11
+ date: 2014-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.4.3
27
- - !ruby/object:Gem::Dependency
28
- name: uuidtools
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: json
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -92,14 +78,14 @@ dependencies:
92
78
  requirements:
93
79
  - - "~>"
94
80
  - !ruby/object:Gem::Version
95
- version: '2.0'
81
+ version: '2.3'
96
82
  type: :runtime
97
83
  prerelease: false
98
84
  version_requirements: !ruby/object:Gem::Requirement
99
85
  requirements:
100
86
  - - "~>"
101
87
  - !ruby/object:Gem::Version
102
- version: '2.0'
88
+ version: '2.3'
103
89
  - !ruby/object:Gem::Dependency
104
90
  name: puma
105
91
  requirement: !ruby/object:Gem::Requirement
@@ -242,6 +228,7 @@ files:
242
228
  - lib/opener/webservice/input_sanitizer.rb
243
229
  - lib/opener/webservice/option_parser.rb
244
230
  - lib/opener/webservice/server.rb
231
+ - lib/opener/webservice/transaction.rb
245
232
  - lib/opener/webservice/uploader.rb
246
233
  - lib/opener/webservice/version.rb
247
234
  - opener-webservice.gemspec