google-cloud-error_reporting 0.25.0 → 0.26.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
  SHA1:
3
- metadata.gz: 2f57b6c70aad426eb8b82902378418d095dcb7df
4
- data.tar.gz: 68844ca432aa4fea4ccf1846928ba9ede67b175c
3
+ metadata.gz: 95eeb57ecd15fd08ecd122259beaefb06afc9eab
4
+ data.tar.gz: d77c448cde21c23c922fcd0c456618723fe6ed2a
5
5
  SHA512:
6
- metadata.gz: 1fc21b526bdb71e683f6a17d8eea04ff90f19d5f16b4344de4ff9ad1e039ad0a0db5a45a7e5b2370d6ddc36a210d682f166e120bb2e0b6367fb35a91b5c600c5
7
- data.tar.gz: 9d7b384e32d1c9b25b61305cd00d3c594db0d625ee94eeff1791c703bf3d023569a5844c3df5eaf59809d1948b358e9323cea9e0e40fdf9f8479aee7a0a9e800
6
+ metadata.gz: 07d4e2e0e62f24b647d026014198c593edba2c6b3e187995102095d69147ef09917b9087907a912c96f7ca12c24c5ce9a5a661d732944da48332b8e1bf6c4dfd
7
+ data.tar.gz: 2610858723c8d1aa8fc18dc138f7c4ee549e3d82f6334b078bd9a4fb6b3cc858b8b21ea1321d07ca85fe841d722d591f3ce1b781ee8cddfdc6ed589c487a274b
@@ -14,6 +14,7 @@
14
14
 
15
15
 
16
16
  require "google-cloud-error_reporting"
17
+ require "google/cloud/error_reporting/async_error_reporter"
17
18
  require "google/cloud/error_reporting/project"
18
19
  require "google/cloud/error_reporting/middleware"
19
20
  require "stackdriver/core"
@@ -213,26 +214,42 @@ module Google
213
214
  # @param [String] service_version A version identifier for running
214
215
  # service.
215
216
  #
216
- def self.report exception, service_name: nil, service_version: nil, &block
217
+ def self.report exception, service_name: nil, service_version: nil
217
218
  return if Google::Cloud.configure.use_error_reporting == false
218
219
 
220
+ service_name ||= configure.service_name ||
221
+ Project.default_service_name
222
+ service_version ||= configure.service_version ||
223
+ Project.default_service_version
224
+
225
+ error_event = ErrorEvent.from_exception(exception).tap do |event|
226
+ event.service_name = service_name
227
+ event.service_version = service_version
228
+ end
229
+
230
+ yield error_event if block_given?
231
+
232
+ default_client.report error_event
233
+ end
234
+
235
+ ##
236
+ # @private Create a private client to
237
+ def self.default_client
219
238
  unless @@default_client
220
239
  project_id = configure.project_id ||
221
240
  Google::Cloud.configure.project_id
222
241
  keyfile = configure.keyfile ||
223
242
  Google::Cloud.configure.keyfile
224
243
 
225
- @@default_client = new project: project_id, keyfile: keyfile
244
+ @@default_client = AsyncErrorReporter.new(
245
+ new(project: project_id, keyfile: keyfile)
246
+ )
226
247
  end
227
248
 
228
- service_name ||= configure.service_name
229
- service_version ||= configure.service_version
230
-
231
- @@default_client.report_exception exception,
232
- service_name: service_name,
233
- service_version: service_version,
234
- &block
249
+ @@default_client
235
250
  end
251
+
252
+ private_class_method :default_client
236
253
  end
237
254
  end
238
255
  end
@@ -0,0 +1,124 @@
1
+ # Copyright 2016 Google Inc. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ require "stackdriver/core/async_actor"
17
+
18
+
19
+ module Google
20
+ module Cloud
21
+ module ErrorReporting
22
+ ##
23
+ # # AsyncErrorReporter
24
+ #
25
+ # @private Used by {Google::Cloud::ErrorReporting} and
26
+ # {Google::Cloud::ErrorReporting::Middleware} to asynchronously submit
27
+ # error events to Stackdriver Error Reporting service when used in
28
+ # Ruby applications.
29
+ class AsyncErrorReporter
30
+ include Stackdriver::Core::AsyncActor
31
+
32
+ ##
33
+ # @private Default maximum backlog size for the job queue
34
+ DEFAULT_MAX_QUEUE_SIZE = 1000
35
+
36
+ ##
37
+ # The {Google::Cloud::ErrorReporting::Project} object to submit events
38
+ # with.
39
+ attr_accessor :error_reporting
40
+
41
+ ##
42
+ # The max number of items the queue holds
43
+ attr_accessor :max_queue_size
44
+
45
+ ##
46
+ # @private Construct a new instance of AsyncErrorReporter
47
+ def initialize error_reporting, max_queue_size = DEFAULT_MAX_QUEUE_SIZE
48
+ super()
49
+ @error_reporting = error_reporting
50
+ @max_queue_size = max_queue_size
51
+ @queue = []
52
+ @queue_resource = new_cond
53
+ end
54
+
55
+ ##
56
+ # Add the error event to the queue. Signal the child thread an item
57
+ # has been added.
58
+ def report error_event
59
+ async_start
60
+
61
+ synchronize do
62
+ @queue.push error_event
63
+ @queue_resource.broadcast
64
+
65
+ retries = 0
66
+ while @max_queue_size && @queue.size > @max_queue_size
67
+ retries += 1
68
+ @queue_resource.wait 1
69
+
70
+ # Drop early queue entries when have waited long enough.
71
+ @queue.pop while @queue.size > @max_queue_size && retries > 3
72
+ end
73
+ end
74
+ end
75
+
76
+ ##
77
+ # @private Callback fucntion for AsyncActor module to run the async
78
+ # job in a loop
79
+ def run_backgrounder
80
+ error_event = wait_next_item
81
+ return if error_event.nil?
82
+ begin
83
+ error_reporting.report error_event
84
+ rescue => e
85
+ @last_exception = e
86
+ end
87
+ end
88
+
89
+ ##
90
+ # @private Callback function when the async actor thread state changes
91
+ def on_async_state_change
92
+ synchronize do
93
+ @queue_resource.broadcast
94
+ end
95
+ end
96
+
97
+ private
98
+
99
+ ##
100
+ # @private The the next item from the reporter queue. If there are
101
+ # no more item, it blocks the reporter thread until an item is
102
+ # enqueued
103
+ def wait_next_item
104
+ synchronize do
105
+ @queue_resource.wait_while do
106
+ async_suspended? || (async_running? && @queue.empty?)
107
+ end
108
+ @queue.pop
109
+ end
110
+ end
111
+
112
+ ##
113
+ # @private Override the #backgrounder_stoppable? method from AsyncActor
114
+ # module. The actor can be gracefully stopped when queue is
115
+ # empty.
116
+ def backgrounder_stoppable?
117
+ synchronize do
118
+ @queue.empty?
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
@@ -52,8 +52,10 @@ module Google
52
52
 
53
53
  @error_reporting =
54
54
  error_reporting ||
55
- ErrorReporting.new(project: configuration.project_id,
56
- keyfile: configuration.keyfile)
55
+ ErrorReporting::AsyncErrorReporter.new(
56
+ ErrorReporting.new(project: configuration.project_id,
57
+ keyfile: configuration.keyfile)
58
+ )
57
59
 
58
60
  # Set module default client to reuse the same client. Update module
59
61
  # configuration parameters.
@@ -6,9 +6,7 @@
6
6
  "DEADLINE_EXCEEDED",
7
7
  "UNAVAILABLE"
8
8
  ],
9
- "non_idempotent": [
10
- "UNAVAILABLE"
11
- ]
9
+ "non_idempotent": []
12
10
  },
13
11
  "retry_params": {
14
12
  "default": {
@@ -6,9 +6,7 @@
6
6
  "DEADLINE_EXCEEDED",
7
7
  "UNAVAILABLE"
8
8
  ],
9
- "non_idempotent": [
10
- "UNAVAILABLE"
11
- ]
9
+ "non_idempotent": []
12
10
  },
13
11
  "retry_params": {
14
12
  "default": {
@@ -6,9 +6,7 @@
6
6
  "DEADLINE_EXCEEDED",
7
7
  "UNAVAILABLE"
8
8
  ],
9
- "non_idempotent": [
10
- "UNAVAILABLE"
11
- ]
9
+ "non_idempotent": []
12
10
  },
13
11
  "retry_params": {
14
12
  "default": {
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module ErrorReporting
19
- VERSION = "0.25.0".freeze
19
+ VERSION = "0.26.1".freeze
20
20
  end
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-error_reporting
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.25.0
4
+ version: 0.26.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Google Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-26 00:00:00.000000000 Z
11
+ date: 2017-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-cloud-core
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.1'
33
+ version: '1.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.1'
40
+ version: '1.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: google-gax
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -205,6 +205,7 @@ files:
205
205
  - README.md
206
206
  - lib/google-cloud-error_reporting.rb
207
207
  - lib/google/cloud/error_reporting.rb
208
+ - lib/google/cloud/error_reporting/async_error_reporter.rb
208
209
  - lib/google/cloud/error_reporting/credentials.rb
209
210
  - lib/google/cloud/error_reporting/error_event.rb
210
211
  - lib/google/cloud/error_reporting/middleware.rb