google-cloud-trace 0.33.6 → 0.34.0
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 +4 -4
- data/CHANGELOG.md +19 -0
- data/lib/google-cloud-trace.rb +1 -0
- data/lib/google/cloud/trace.rb +13 -7
- data/lib/google/cloud/trace/async_reporter.rb +281 -54
- data/lib/google/cloud/trace/errors.rb +59 -0
- data/lib/google/cloud/trace/middleware.rb +63 -7
- data/lib/google/cloud/trace/v1/credentials.rb +1 -1
- data/lib/google/cloud/trace/v1/doc/google/devtools/cloudtrace/v1/trace.rb +1 -1
- data/lib/google/cloud/trace/v1/doc/google/protobuf/empty.rb +1 -1
- data/lib/google/cloud/trace/v1/doc/google/protobuf/timestamp.rb +1 -1
- data/lib/google/cloud/trace/v1/trace_service_client.rb +1 -1
- data/lib/google/cloud/trace/v2/credentials.rb +1 -1
- data/lib/google/cloud/trace/v2/doc/google/devtools/cloudtrace/v2/trace.rb +1 -1
- data/lib/google/cloud/trace/v2/doc/google/devtools/cloudtrace/v2/tracing.rb +1 -1
- data/lib/google/cloud/trace/v2/doc/google/protobuf/any.rb +1 -1
- data/lib/google/cloud/trace/v2/doc/google/protobuf/empty.rb +1 -1
- data/lib/google/cloud/trace/v2/doc/google/protobuf/timestamp.rb +1 -1
- data/lib/google/cloud/trace/v2/doc/google/protobuf/wrappers.rb +1 -57
- data/lib/google/cloud/trace/v2/doc/google/rpc/status.rb +1 -1
- data/lib/google/cloud/trace/v2/trace_service_client.rb +1 -1
- data/lib/google/cloud/trace/version.rb +1 -1
- metadata +20 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: eb8915f1cc8c21d81193ea87120b752ad050f0198149b7697db1f05ff13a0447
|
|
4
|
+
data.tar.gz: 6a8f3e593cf1cd53662e4032b6fbd659e6ada906fc526bad792c4cf3175a453d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bd71d0cb5a855f6fc56133633f8c1ebb5dfff7b8b7dc26fc7f15993287cf282eb292df30a2ad0bd922e1ec07392c0deb4fdca84897a97d93452add0bf46b3d7c
|
|
7
|
+
data.tar.gz: 6eed64250b5cb8aa7381193e07c54c36e57b2843fcc9b837538f7512bd9b022e09d69215653dad9fed8f7dc2f5375f206d6ab73d8f2d873f2b19c0c0cf11d948
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Release History
|
|
2
2
|
|
|
3
|
+
### 0.34.0 / 2019-02-07
|
|
4
|
+
|
|
5
|
+
* Add Trace `on_error` configuration.
|
|
6
|
+
* Middleware improvements:
|
|
7
|
+
* Buffer traces and make batch API calls.
|
|
8
|
+
* Back pressure is applied by limiting the number of queued API calls.
|
|
9
|
+
* Errors will now be raised when there are not enough resources.
|
|
10
|
+
* Errors are reported by calling the `on_error` callback.
|
|
11
|
+
* Make use of `Credentials#project_id`
|
|
12
|
+
* Use `Credentials#project_id`
|
|
13
|
+
If a `project_id` is not provided, use the value on the Credentials object.
|
|
14
|
+
This value was added in googleauth 0.7.0.
|
|
15
|
+
* Loosen googleauth dependency
|
|
16
|
+
Allow for new releases up to 0.10.
|
|
17
|
+
The googleauth devs have committed to maintaining the current API
|
|
18
|
+
and will not make backwards compatible changes before 0.10.
|
|
19
|
+
* Update Trace documentation
|
|
20
|
+
* Correct the C-code's comments.
|
|
21
|
+
|
|
3
22
|
### 0.33.6 / 2018-11-15
|
|
4
23
|
|
|
5
24
|
* Update network configuration.
|
data/lib/google-cloud-trace.rb
CHANGED
|
@@ -142,4 +142,5 @@ Google::Cloud.configure.add_config! :trace do |config|
|
|
|
142
142
|
config.add_field! :span_id_generator, nil, match: Proc
|
|
143
143
|
config.add_field! :notifications, nil, match: Array
|
|
144
144
|
config.add_field! :max_data_length, nil, match: Integer
|
|
145
|
+
config.add_field! :on_error, nil, match: Proc
|
|
145
146
|
end
|
data/lib/google/cloud/trace.rb
CHANGED
|
@@ -86,19 +86,22 @@ module Google
|
|
|
86
86
|
#
|
|
87
87
|
def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil,
|
|
88
88
|
client_config: nil, project: nil, keyfile: nil
|
|
89
|
-
project_id
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
scope ||= configure.scope
|
|
94
|
-
timeout ||= configure.timeout
|
|
89
|
+
project_id ||= (project || default_project_id)
|
|
90
|
+
scope ||= configure.scope
|
|
91
|
+
timeout ||= configure.timeout
|
|
95
92
|
client_config ||= configure.client_config
|
|
93
|
+
credentials ||= (keyfile || default_credentials(scope: scope))
|
|
96
94
|
|
|
97
|
-
credentials ||= (keyfile || default_credentials(scope: scope))
|
|
98
95
|
unless credentials.is_a? Google::Auth::Credentials
|
|
99
96
|
credentials = Trace::Credentials.new credentials, scope: scope
|
|
100
97
|
end
|
|
101
98
|
|
|
99
|
+
if credentials.respond_to? :project_id
|
|
100
|
+
project_id ||= credentials.project_id
|
|
101
|
+
end
|
|
102
|
+
project_id = project_id.to_s # Always cast to a string
|
|
103
|
+
raise ArgumentError, "project_id is missing" if project_id.empty?
|
|
104
|
+
|
|
102
105
|
Trace::Project.new(
|
|
103
106
|
Trace::Service.new(
|
|
104
107
|
project_id, credentials, timeout: timeout,
|
|
@@ -138,6 +141,9 @@ module Google
|
|
|
138
141
|
# recorded with ActiveSupport notification events. Rails-only option.
|
|
139
142
|
# Default:
|
|
140
143
|
# `Google::Cloud::Trace::Notifications::DEFAULT_MAX_DATA_LENGTH`
|
|
144
|
+
# * `on_error` - (Proc) A Proc to be run when an error is encountered
|
|
145
|
+
# during the reporting of traces by the middleware. The Proc must take
|
|
146
|
+
# the error object as the single argument.
|
|
141
147
|
#
|
|
142
148
|
# See the {file:INSTRUMENTATION.md Configuration Guide} for full
|
|
143
149
|
# configuration parameters.
|
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
require "
|
|
16
|
+
require "monitor"
|
|
17
|
+
require "concurrent"
|
|
18
|
+
require "google/cloud/trace/errors"
|
|
17
19
|
|
|
18
20
|
module Google
|
|
19
21
|
module Cloud
|
|
@@ -22,101 +24,326 @@ module Google
|
|
|
22
24
|
# # AsyncReporter
|
|
23
25
|
#
|
|
24
26
|
# @private Used by the {Google::Cloud::Trace::Middleware} to
|
|
25
|
-
# asynchronously
|
|
26
|
-
# a Rack-based application.
|
|
27
|
+
# asynchronously buffer traces and push batches to Stackdriver Trace
|
|
28
|
+
# service when used in a Rack-based application.
|
|
27
29
|
class AsyncReporter
|
|
28
|
-
include
|
|
30
|
+
include MonitorMixin
|
|
29
31
|
|
|
30
32
|
##
|
|
31
|
-
# @private
|
|
32
|
-
|
|
33
|
+
# @private Implementation accessors
|
|
34
|
+
attr_reader :service, :max_bytes, :max_count, :max_queue, :interval,
|
|
35
|
+
:threads
|
|
33
36
|
|
|
34
37
|
##
|
|
35
|
-
#
|
|
36
|
-
|
|
38
|
+
# @private Creates a new AsyncReporter instance.
|
|
39
|
+
def initialize service, max_count: 1000, max_bytes: 4000000,
|
|
40
|
+
max_queue: 100, interval: 5, threads: 10
|
|
41
|
+
@service = service
|
|
37
42
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
@max_count = max_count
|
|
44
|
+
@max_bytes = max_bytes
|
|
45
|
+
@max_queue = max_queue
|
|
46
|
+
@interval = interval
|
|
47
|
+
@threads = threads
|
|
41
48
|
|
|
42
|
-
|
|
43
|
-
# @private Construct a new instance of AsyncReporter
|
|
44
|
-
def initialize service, max_queue_size = DEFAULT_MAX_QUEUE_SIZE
|
|
45
|
-
super()
|
|
49
|
+
@error_callbacks = []
|
|
46
50
|
|
|
47
|
-
@
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
@cond = new_cond
|
|
52
|
+
|
|
53
|
+
# Make sure all buffered messages are sent when process exits.
|
|
54
|
+
at_exit { stop! }
|
|
55
|
+
|
|
56
|
+
# init MonitorMixin
|
|
57
|
+
super()
|
|
51
58
|
end
|
|
52
59
|
|
|
53
60
|
##
|
|
54
61
|
# Add the traces to the queue to be reported to Stackdriver Trace
|
|
55
62
|
# asynchronously. Signal the child thread to start processing the queue.
|
|
63
|
+
#
|
|
64
|
+
# @param [Google::Cloud::Trace::TraceRecord,
|
|
65
|
+
# Array{Google::Cloud::Trace::TraceRecord}] traces Either a single
|
|
66
|
+
# trace object or an array of trace objects.
|
|
56
67
|
def patch_traces traces
|
|
57
|
-
|
|
68
|
+
if synchronize { @stopped }
|
|
69
|
+
raise_stopped_error traces
|
|
70
|
+
return
|
|
71
|
+
end
|
|
58
72
|
|
|
59
73
|
synchronize do
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
@queue_resource.wait 1
|
|
74
|
+
Array(traces).each do |trace|
|
|
75
|
+
# Add the trace to the batch
|
|
76
|
+
@batch ||= Batch.new self
|
|
77
|
+
next if @batch.try_add trace
|
|
65
78
|
|
|
66
|
-
|
|
79
|
+
# If we can't add to the batch, publish and create a new batch
|
|
80
|
+
patch_batch!
|
|
81
|
+
@batch = Batch.new self
|
|
82
|
+
@batch.add trace
|
|
67
83
|
end
|
|
84
|
+
|
|
85
|
+
init_resources!
|
|
86
|
+
|
|
87
|
+
patch_batch! if @batch.ready?
|
|
88
|
+
|
|
89
|
+
@cond.broadcast
|
|
90
|
+
end
|
|
91
|
+
self
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
##
|
|
95
|
+
# Get the project id from underlying service object.
|
|
96
|
+
def project
|
|
97
|
+
service.project
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
##
|
|
101
|
+
# Begins the process of stopping the reporter. Traces already in the
|
|
102
|
+
# queue will be published, but no new traces can be added. Use {#wait!}
|
|
103
|
+
# to block until the reporter is fully stopped and all pending traces
|
|
104
|
+
# have been pushed to the API.
|
|
105
|
+
#
|
|
106
|
+
# @return [AsyncReporter] returns self so calls can be chained.
|
|
107
|
+
def stop
|
|
108
|
+
synchronize do
|
|
109
|
+
break if @stopped
|
|
110
|
+
|
|
111
|
+
@stopped = true
|
|
112
|
+
patch_batch!
|
|
113
|
+
@cond.broadcast
|
|
114
|
+
@thread_pool.shutdown if @thread_pool
|
|
68
115
|
end
|
|
116
|
+
|
|
117
|
+
self
|
|
69
118
|
end
|
|
70
119
|
|
|
71
120
|
##
|
|
72
|
-
#
|
|
73
|
-
#
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
121
|
+
# Stop this asynchronous reporter and block until it has been stopped.
|
|
122
|
+
#
|
|
123
|
+
# @param [Number] timeout Timeout in seconds.
|
|
124
|
+
#
|
|
125
|
+
def stop! timeout = nil
|
|
126
|
+
stop
|
|
127
|
+
wait! timeout
|
|
128
|
+
end
|
|
77
129
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
130
|
+
##
|
|
131
|
+
# Blocks until the reporter is fully stopped, all pending traces have
|
|
132
|
+
# been published, and all callbacks have completed. Does not stop the
|
|
133
|
+
# reporter. To stop the reporter, first call {#stop} and then call
|
|
134
|
+
# {#wait!} to block until the reporter is stopped.
|
|
135
|
+
#
|
|
136
|
+
# @return [AsyncReporter] returns self so calls can be chained.
|
|
137
|
+
def wait! timeout = nil
|
|
138
|
+
synchronize do
|
|
139
|
+
if @thread_pool
|
|
140
|
+
@thread_pool.shutdown
|
|
141
|
+
@thread_pool.wait_for_termination timeout
|
|
142
|
+
end
|
|
83
143
|
end
|
|
144
|
+
|
|
145
|
+
self
|
|
84
146
|
end
|
|
85
147
|
|
|
86
148
|
##
|
|
87
|
-
#
|
|
88
|
-
|
|
149
|
+
# Forces all traces in the current batch to be patched to the API
|
|
150
|
+
# immediately.
|
|
151
|
+
#
|
|
152
|
+
# @return [AsyncReporter] returns self so calls can be chained.
|
|
153
|
+
#
|
|
154
|
+
def flush!
|
|
89
155
|
synchronize do
|
|
90
|
-
|
|
156
|
+
patch_batch!
|
|
157
|
+
@cond.broadcast
|
|
91
158
|
end
|
|
159
|
+
|
|
160
|
+
self
|
|
92
161
|
end
|
|
93
162
|
|
|
94
163
|
##
|
|
95
|
-
#
|
|
96
|
-
|
|
97
|
-
|
|
164
|
+
# Whether the reporter has been started.
|
|
165
|
+
#
|
|
166
|
+
# @return [boolean] `true` when started, `false` otherwise.
|
|
167
|
+
#
|
|
168
|
+
def started?
|
|
169
|
+
!stopped?
|
|
98
170
|
end
|
|
99
171
|
|
|
100
|
-
|
|
172
|
+
##
|
|
173
|
+
# Whether the reporter has been stopped.
|
|
174
|
+
#
|
|
175
|
+
# @return [boolean] `true` when stopped, `false` otherwise.
|
|
176
|
+
#
|
|
177
|
+
def stopped?
|
|
178
|
+
synchronize { @stopped }
|
|
179
|
+
end
|
|
101
180
|
|
|
102
181
|
##
|
|
103
|
-
#
|
|
104
|
-
#
|
|
105
|
-
|
|
182
|
+
# Register to be notified of errors when raised.
|
|
183
|
+
#
|
|
184
|
+
# If an unhandled error has occurred the reporter will attempt to
|
|
185
|
+
# recover from the error and resume buffering, batching, and patching
|
|
186
|
+
# traces.
|
|
187
|
+
#
|
|
188
|
+
# Multiple error handlers can be added.
|
|
189
|
+
#
|
|
190
|
+
# @yield [callback] The block to be called when an error is raised.
|
|
191
|
+
# @yieldparam [Exception] error The error raised.
|
|
192
|
+
#
|
|
193
|
+
def on_error &block
|
|
194
|
+
synchronize do
|
|
195
|
+
@error_callbacks << block
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
protected
|
|
200
|
+
|
|
201
|
+
def init_resources!
|
|
202
|
+
@thread_pool ||= \
|
|
203
|
+
Concurrent::CachedThreadPool.new max_threads: @threads,
|
|
204
|
+
max_queue: @max_queue
|
|
205
|
+
@thread ||= Thread.new { run_background }
|
|
206
|
+
nil # returning nil because of rubocop...
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def run_background
|
|
106
210
|
synchronize do
|
|
107
|
-
@
|
|
108
|
-
|
|
211
|
+
until @stopped
|
|
212
|
+
if @batch.nil?
|
|
213
|
+
@cond.wait
|
|
214
|
+
next
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
if @batch.ready?
|
|
218
|
+
# interval met, publish the batch...
|
|
219
|
+
patch_batch!
|
|
220
|
+
@cond.wait
|
|
221
|
+
else
|
|
222
|
+
# still waiting for the interval to publish the batch...
|
|
223
|
+
@cond.wait(@batch.publish_wait)
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
def patch_batch!
|
|
230
|
+
return unless @batch
|
|
231
|
+
|
|
232
|
+
batch_to_be_patched = @batch
|
|
233
|
+
@batch = nil
|
|
234
|
+
patch_traces_async batch_to_be_patched
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
def patch_traces_async batch
|
|
238
|
+
Concurrent::Promises.future_on(
|
|
239
|
+
@thread_pool, batch.traces
|
|
240
|
+
) do |traces|
|
|
241
|
+
patch_traces_with traces
|
|
242
|
+
end
|
|
243
|
+
rescue Concurrent::RejectedExecutionError => e
|
|
244
|
+
async_error = AsyncReporterError.new(
|
|
245
|
+
"Error writing traces: #{e.message}",
|
|
246
|
+
batch.traces
|
|
247
|
+
)
|
|
248
|
+
# Manually set backtrace so we don't have to raise
|
|
249
|
+
async_error.set_backtrace caller
|
|
250
|
+
error! async_error
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
def patch_traces_with traces
|
|
254
|
+
service.patch_traces traces
|
|
255
|
+
rescue StandardError => e
|
|
256
|
+
patch_error = AsyncPatchTracesError.new(
|
|
257
|
+
"Error writing traces: #{e.message}",
|
|
258
|
+
traces
|
|
259
|
+
)
|
|
260
|
+
# Manually set backtrace so we don't have to raise
|
|
261
|
+
patch_error.set_backtrace caller
|
|
262
|
+
error! patch_error
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
def raise_stopped_error traces
|
|
266
|
+
stopped_error = AsyncReporterError.new(
|
|
267
|
+
"AsyncReporter is stopped. Cannot patch traces.",
|
|
268
|
+
traces
|
|
269
|
+
)
|
|
270
|
+
# Manually set backtrace so we don't have to raise
|
|
271
|
+
stopped_error.set_backtrace caller
|
|
272
|
+
error! stopped_error
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
# Calls all error callbacks.
|
|
276
|
+
def error! error
|
|
277
|
+
# We shouldn't need to synchronize getting the callbacks.
|
|
278
|
+
error_callbacks = @error_callbacks
|
|
279
|
+
error_callbacks = default_error_callbacks if error_callbacks.empty?
|
|
280
|
+
error_callbacks.each { |error_callback| error_callback.call error }
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
def default_error_callbacks
|
|
284
|
+
# This is memoized to reduce calls to the configuration.
|
|
285
|
+
@default_error_callbacks ||= begin
|
|
286
|
+
error_callback = Google::Cloud::Pubsub.configuration.on_error
|
|
287
|
+
error_callback ||= Google::Cloud.configure.on_error
|
|
288
|
+
if error_callback
|
|
289
|
+
[error_callback]
|
|
290
|
+
else
|
|
291
|
+
[]
|
|
109
292
|
end
|
|
110
|
-
@queue.pop
|
|
111
293
|
end
|
|
112
294
|
end
|
|
113
295
|
|
|
114
296
|
##
|
|
115
|
-
# @private
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
297
|
+
# @private
|
|
298
|
+
class Batch
|
|
299
|
+
attr_reader :created_at, :traces
|
|
300
|
+
|
|
301
|
+
def initialize reporter
|
|
302
|
+
@reporter = reporter
|
|
303
|
+
@traces = []
|
|
304
|
+
@traces_bytes = reporter.project.bytesize + 4 # initial size
|
|
305
|
+
@created_at = nil
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
def add trace, addl_bytes: nil
|
|
309
|
+
addl_bytes ||= addl_bytes_for trace
|
|
310
|
+
@traces << trace
|
|
311
|
+
@traces_bytes += addl_bytes
|
|
312
|
+
@created_at ||= Time.now
|
|
313
|
+
nil
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
def try_add trace
|
|
317
|
+
addl_bytes = addl_bytes_for trace
|
|
318
|
+
new_message_count = @traces.count + 1
|
|
319
|
+
new_message_bytes = @traces_bytes + addl_bytes
|
|
320
|
+
if new_message_count > @reporter.max_count ||
|
|
321
|
+
new_message_bytes >= @reporter.max_bytes
|
|
322
|
+
return false
|
|
323
|
+
end
|
|
324
|
+
add trace, addl_bytes: addl_bytes
|
|
325
|
+
true
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
def ready?
|
|
329
|
+
@traces.count >= @reporter.max_count ||
|
|
330
|
+
@traces_bytes >= @reporter.max_bytes ||
|
|
331
|
+
(@created_at.nil? || (publish_at < Time.now))
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
def publish_at
|
|
335
|
+
return nil if @created_at.nil?
|
|
336
|
+
@created_at + @reporter.interval
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
def publish_wait
|
|
340
|
+
publish_wait = publish_at - Time.now
|
|
341
|
+
return 0 if publish_wait < 0
|
|
342
|
+
publish_wait
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
def addl_bytes_for trace
|
|
346
|
+
trace.to_grpc.to_proto.bytesize + 2
|
|
120
347
|
end
|
|
121
348
|
end
|
|
122
349
|
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Copyright 2018 Google LLC
|
|
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
|
+
# https://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 "google/cloud/errors"
|
|
17
|
+
|
|
18
|
+
module Google
|
|
19
|
+
module Cloud
|
|
20
|
+
module Trace
|
|
21
|
+
##
|
|
22
|
+
# # AsyncReporterError
|
|
23
|
+
#
|
|
24
|
+
# Used to indicate a problem preventing traces from being buffered
|
|
25
|
+
# asynchronously. This can occur when there are not enough resources
|
|
26
|
+
# allocated for the amount of usage.
|
|
27
|
+
#
|
|
28
|
+
class AsyncReporterError < Google::Cloud::Error
|
|
29
|
+
# @!attribute [r] count
|
|
30
|
+
# @return [Array<Google::Cloud::Trace::TraceRecord>] traces The trace
|
|
31
|
+
# objects that were not written to the API due to the error.
|
|
32
|
+
attr_reader :traces
|
|
33
|
+
|
|
34
|
+
def initialize message, traces = nil
|
|
35
|
+
super(message)
|
|
36
|
+
@traces = traces if traces
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
##
|
|
41
|
+
# # AsyncPatchTracesError
|
|
42
|
+
#
|
|
43
|
+
# Used to indicate a problem when patching traces to the API. This can
|
|
44
|
+
# occur when the API returns an error.
|
|
45
|
+
#
|
|
46
|
+
class AsyncPatchTracesError < Google::Cloud::Error
|
|
47
|
+
# @!attribute [r] count
|
|
48
|
+
# @return [Array<Google::Cloud::Trace::TraceRecord>] traces The trace
|
|
49
|
+
# objects that were not written to the API due to the error.
|
|
50
|
+
attr_reader :traces
|
|
51
|
+
|
|
52
|
+
def initialize message, traces = nil
|
|
53
|
+
super(message)
|
|
54
|
+
@traces = traces if traces
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -93,6 +93,36 @@ module Google
|
|
|
93
93
|
# end
|
|
94
94
|
# ```
|
|
95
95
|
#
|
|
96
|
+
# ## Error handling
|
|
97
|
+
#
|
|
98
|
+
# An error encountered during the reporting of traces by the middleware
|
|
99
|
+
# can be handled using a Proc set in the `on_error` configuration. (See
|
|
100
|
+
# {Google::Cloud::Trace.configure}.) The Proc must take the error object
|
|
101
|
+
# as the single argument.
|
|
102
|
+
#
|
|
103
|
+
# ```ruby
|
|
104
|
+
# # Configure error handling
|
|
105
|
+
#
|
|
106
|
+
# require "sinatra"
|
|
107
|
+
# require "google/cloud/trace"
|
|
108
|
+
# require "google/cloud/error_reporting"
|
|
109
|
+
#
|
|
110
|
+
# Google::Cloud::Trace.configure do |config|
|
|
111
|
+
# config.on_error = lambda do |error|
|
|
112
|
+
# Google::Cloud::ErrorReporting.report error
|
|
113
|
+
# end
|
|
114
|
+
# end
|
|
115
|
+
#
|
|
116
|
+
# use Google::Cloud::Trace::Middleware
|
|
117
|
+
#
|
|
118
|
+
# get "/" do
|
|
119
|
+
# Google::Cloud::Trace.in_span "Sleeping on the job!" do
|
|
120
|
+
# sleep rand
|
|
121
|
+
# end
|
|
122
|
+
# "Hello World!"
|
|
123
|
+
# end
|
|
124
|
+
# ```
|
|
125
|
+
#
|
|
96
126
|
# ## Sampling and blacklisting
|
|
97
127
|
#
|
|
98
128
|
# A sampler makes the decision whether to record a trace for each
|
|
@@ -214,13 +244,7 @@ module Google
|
|
|
214
244
|
begin
|
|
215
245
|
@service.patch_traces trace
|
|
216
246
|
rescue StandardError => ex
|
|
217
|
-
|
|
218
|
-
logger = env["rack.logger"]
|
|
219
|
-
if logger
|
|
220
|
-
logger.error msg
|
|
221
|
-
else
|
|
222
|
-
warn msg
|
|
223
|
-
end
|
|
247
|
+
handle_error ex, logger: env["rack.logger"]
|
|
224
248
|
end
|
|
225
249
|
end
|
|
226
250
|
end
|
|
@@ -390,6 +414,38 @@ module Google
|
|
|
390
414
|
def configuration
|
|
391
415
|
Google::Cloud::Trace.configure
|
|
392
416
|
end
|
|
417
|
+
|
|
418
|
+
##
|
|
419
|
+
# @private Get the error callback from the configuration.
|
|
420
|
+
# This value is memoized to reduce calls to the configuration.
|
|
421
|
+
def error_callback
|
|
422
|
+
if @error_callback.nil?
|
|
423
|
+
@error_callback = :unset
|
|
424
|
+
configuration_callback = configuration.on_error
|
|
425
|
+
configuration_callback ||= Cloud.configure.on_error
|
|
426
|
+
@error_callback = configuration_callback if configuration_callback
|
|
427
|
+
end
|
|
428
|
+
|
|
429
|
+
return nil if @error_callback == :unset
|
|
430
|
+
@error_callback
|
|
431
|
+
end
|
|
432
|
+
|
|
433
|
+
##
|
|
434
|
+
# @private Handle errors raised when making patch_traces API calls.
|
|
435
|
+
def handle_error error, logger: nil
|
|
436
|
+
# Use on_error from configuration
|
|
437
|
+
if error_callback
|
|
438
|
+
error_callback.call error
|
|
439
|
+
else
|
|
440
|
+
# log error
|
|
441
|
+
msg = "Transmit to Stackdriver Trace failed: #{error.inspect}"
|
|
442
|
+
if logger
|
|
443
|
+
logger.error msg
|
|
444
|
+
else
|
|
445
|
+
warn msg
|
|
446
|
+
end
|
|
447
|
+
end
|
|
448
|
+
end
|
|
393
449
|
end
|
|
394
450
|
end
|
|
395
451
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright
|
|
1
|
+
# Copyright 2019 Google LLC
|
|
2
2
|
#
|
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
# you may not use this file except in compliance with the License.
|
|
@@ -15,38 +15,6 @@
|
|
|
15
15
|
|
|
16
16
|
module Google
|
|
17
17
|
module Protobuf
|
|
18
|
-
# Wrapper message for `double`.
|
|
19
|
-
#
|
|
20
|
-
# The JSON representation for `DoubleValue` is JSON number.
|
|
21
|
-
# @!attribute [rw] value
|
|
22
|
-
# @return [Float]
|
|
23
|
-
# The double value.
|
|
24
|
-
class DoubleValue; end
|
|
25
|
-
|
|
26
|
-
# Wrapper message for `float`.
|
|
27
|
-
#
|
|
28
|
-
# The JSON representation for `FloatValue` is JSON number.
|
|
29
|
-
# @!attribute [rw] value
|
|
30
|
-
# @return [Float]
|
|
31
|
-
# The float value.
|
|
32
|
-
class FloatValue; end
|
|
33
|
-
|
|
34
|
-
# Wrapper message for `int64`.
|
|
35
|
-
#
|
|
36
|
-
# The JSON representation for `Int64Value` is JSON string.
|
|
37
|
-
# @!attribute [rw] value
|
|
38
|
-
# @return [Integer]
|
|
39
|
-
# The int64 value.
|
|
40
|
-
class Int64Value; end
|
|
41
|
-
|
|
42
|
-
# Wrapper message for `uint64`.
|
|
43
|
-
#
|
|
44
|
-
# The JSON representation for `UInt64Value` is JSON string.
|
|
45
|
-
# @!attribute [rw] value
|
|
46
|
-
# @return [Integer]
|
|
47
|
-
# The uint64 value.
|
|
48
|
-
class UInt64Value; end
|
|
49
|
-
|
|
50
18
|
# Wrapper message for `int32`.
|
|
51
19
|
#
|
|
52
20
|
# The JSON representation for `Int32Value` is JSON number.
|
|
@@ -55,14 +23,6 @@ module Google
|
|
|
55
23
|
# The int32 value.
|
|
56
24
|
class Int32Value; end
|
|
57
25
|
|
|
58
|
-
# Wrapper message for `uint32`.
|
|
59
|
-
#
|
|
60
|
-
# The JSON representation for `UInt32Value` is JSON number.
|
|
61
|
-
# @!attribute [rw] value
|
|
62
|
-
# @return [Integer]
|
|
63
|
-
# The uint32 value.
|
|
64
|
-
class UInt32Value; end
|
|
65
|
-
|
|
66
26
|
# Wrapper message for `bool`.
|
|
67
27
|
#
|
|
68
28
|
# The JSON representation for `BoolValue` is JSON `true` and `false`.
|
|
@@ -70,21 +30,5 @@ module Google
|
|
|
70
30
|
# @return [true, false]
|
|
71
31
|
# The bool value.
|
|
72
32
|
class BoolValue; end
|
|
73
|
-
|
|
74
|
-
# Wrapper message for `string`.
|
|
75
|
-
#
|
|
76
|
-
# The JSON representation for `StringValue` is JSON string.
|
|
77
|
-
# @!attribute [rw] value
|
|
78
|
-
# @return [String]
|
|
79
|
-
# The string value.
|
|
80
|
-
class StringValue; end
|
|
81
|
-
|
|
82
|
-
# Wrapper message for `bytes`.
|
|
83
|
-
#
|
|
84
|
-
# The JSON representation for `BytesValue` is JSON string.
|
|
85
|
-
# @!attribute [rw] value
|
|
86
|
-
# @return [String]
|
|
87
|
-
# The bytes value.
|
|
88
|
-
class BytesValue; end
|
|
89
33
|
end
|
|
90
34
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: google-cloud-trace
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.34.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel Azuma
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2019-02-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: google-cloud-core
|
|
@@ -52,6 +52,20 @@ dependencies:
|
|
|
52
52
|
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '1.3'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: concurrent-ruby
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '1.1'
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '1.1'
|
|
55
69
|
- !ruby/object:Gem::Dependency
|
|
56
70
|
name: minitest
|
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -170,14 +184,14 @@ dependencies:
|
|
|
170
184
|
requirements:
|
|
171
185
|
- - "~>"
|
|
172
186
|
- !ruby/object:Gem::Version
|
|
173
|
-
version: 0.
|
|
187
|
+
version: 0.61.0
|
|
174
188
|
type: :development
|
|
175
189
|
prerelease: false
|
|
176
190
|
version_requirements: !ruby/object:Gem::Requirement
|
|
177
191
|
requirements:
|
|
178
192
|
- - "~>"
|
|
179
193
|
- !ruby/object:Gem::Version
|
|
180
|
-
version: 0.
|
|
194
|
+
version: 0.61.0
|
|
181
195
|
- !ruby/object:Gem::Dependency
|
|
182
196
|
name: simplecov
|
|
183
197
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -255,6 +269,7 @@ files:
|
|
|
255
269
|
- lib/google/cloud/trace.rb
|
|
256
270
|
- lib/google/cloud/trace/async_reporter.rb
|
|
257
271
|
- lib/google/cloud/trace/credentials.rb
|
|
272
|
+
- lib/google/cloud/trace/errors.rb
|
|
258
273
|
- lib/google/cloud/trace/faraday_middleware.rb
|
|
259
274
|
- lib/google/cloud/trace/label_key.rb
|
|
260
275
|
- lib/google/cloud/trace/middleware.rb
|
|
@@ -314,7 +329,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
314
329
|
version: '0'
|
|
315
330
|
requirements: []
|
|
316
331
|
rubyforge_project:
|
|
317
|
-
rubygems_version: 2.7.
|
|
332
|
+
rubygems_version: 2.7.6
|
|
318
333
|
signing_key:
|
|
319
334
|
specification_version: 4
|
|
320
335
|
summary: Application Instrumentation and API Client library for Stackdriver Trace
|