google-cloud-trace 0.30.0 → 0.31.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +48 -48
- data/lib/google-cloud-trace.rb +47 -2
- data/lib/google/cloud/trace.rb +78 -27
- data/lib/google/cloud/trace/async_reporter.rb +1 -1
- data/lib/google/cloud/trace/credentials.rb +6 -6
- data/lib/google/cloud/trace/faraday_middleware.rb +1 -1
- data/lib/google/cloud/trace/label_key.rb +49 -48
- data/lib/google/cloud/trace/middleware.rb +16 -15
- data/lib/google/cloud/trace/notifications.rb +2 -2
- data/lib/google/cloud/trace/patches/active_call_with_trace.rb +1 -1
- data/lib/google/cloud/trace/project.rb +2 -11
- data/lib/google/cloud/trace/rails.rb +18 -7
- data/lib/google/cloud/trace/service.rb +12 -7
- data/lib/google/cloud/trace/span.rb +10 -7
- data/lib/google/cloud/trace/trace_record.rb +12 -11
- data/lib/google/cloud/trace/version.rb +1 -1
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e966113a0dd811127a2df67d641bcc1308a0232ed590f6f921601b955ce2fe3f
|
4
|
+
data.tar.gz: 288a292aae2e0938ae288f33409013c3f4b004f65861eacabe8ca0f95714ebce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7dd26958194e2388e6952503f9b77ef0c22e5babad557da194aa3a27b6d2579ae319f42bc1ef3a330ea511635e929b4b2e934bf5feafd917174fa922e961b1e9
|
7
|
+
data.tar.gz: e7091c7efe42d1cd5ea8c42a8dad29a4071ab6f36a135939e24d760cf22faf2efaac7b7b2c872f8b11f221583826fe32865ef09d5a330b806b4fceaad21cd0d3
|
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# google-cloud-trace
|
2
2
|
|
3
|
-
[Stackdriver Trace](https://cloud.google.com/trace/) is a distributed tracing
|
4
|
-
system that collects latency data from your applications and displays it in the
|
3
|
+
[Stackdriver Trace](https://cloud.google.com/trace/) is a distributed tracing
|
4
|
+
system that collects latency data from your applications and displays it in the
|
5
5
|
Google Cloud Platform Console. You can track how requests propagate through your
|
6
|
-
application and receive detailed near real-time performance insights.
|
7
|
-
Stackdriver Trace automatically analyzes all of your application's traces to
|
8
|
-
generate in-depth latency reports to surface performance degradations, and can
|
6
|
+
application and receive detailed near real-time performance insights.
|
7
|
+
Stackdriver Trace automatically analyzes all of your application's traces to
|
8
|
+
generate in-depth latency reports to surface performance degradations, and can
|
9
9
|
capture traces from all of your VMs, containers, or Google App Engine projects.
|
10
10
|
|
11
11
|
- [google-cloud-trace API documentation](http://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-trace/latest)
|
@@ -35,26 +35,26 @@ gem "google-cloud-trace"
|
|
35
35
|
$ bundle install
|
36
36
|
```
|
37
37
|
|
38
|
-
Alternatively, check out the [`stackdriver`](../stackdriver) gem that includes
|
38
|
+
Alternatively, check out the [`stackdriver`](../stackdriver) gem that includes
|
39
39
|
the `google-cloud-trace` gem.
|
40
40
|
|
41
41
|
## Enable Stackdriver Trace API
|
42
42
|
|
43
|
-
The Stackdriver Trace library needs the [Stackdriver Trace
|
44
|
-
API](https://console.cloud.google.com/apis/library/cloudtrace.googleapis.com)
|
45
|
-
to be enabled on your Google Cloud project. Make sure it's enabled if not
|
43
|
+
The Stackdriver Trace library needs the [Stackdriver Trace
|
44
|
+
API](https://console.cloud.google.com/apis/library/cloudtrace.googleapis.com)
|
45
|
+
to be enabled on your Google Cloud project. Make sure it's enabled if not
|
46
46
|
already.
|
47
47
|
|
48
48
|
## Tracing on Rack-based frameworks
|
49
49
|
|
50
|
-
The Stackdriver Trace library for Ruby makes it easy to integrate Stackdriver
|
51
|
-
Trace into popular Rack-based Ruby web frameworks such as Ruby on Rails and
|
52
|
-
Sinatra. When the library integration is enabled, it automatically traces
|
50
|
+
The Stackdriver Trace library for Ruby makes it easy to integrate Stackdriver
|
51
|
+
Trace into popular Rack-based Ruby web frameworks such as Ruby on Rails and
|
52
|
+
Sinatra. When the library integration is enabled, it automatically traces
|
53
53
|
incoming requests in the application.
|
54
54
|
|
55
55
|
### With Ruby on Rails
|
56
56
|
|
57
|
-
You can load the Railtie that comes with the library into your Ruby
|
57
|
+
You can load the Railtie that comes with the library into your Ruby
|
58
58
|
on Rails application by explicitly requiring it during the application startup:
|
59
59
|
|
60
60
|
```ruby
|
@@ -62,12 +62,12 @@ on Rails application by explicitly requiring it during the application startup:
|
|
62
62
|
require "google/cloud/trace/rails"
|
63
63
|
```
|
64
64
|
|
65
|
-
If you're using the `stackdriver` gem, it automatically loads the Railtie into
|
65
|
+
If you're using the `stackdriver` gem, it automatically loads the Railtie into
|
66
66
|
your application when it starts.
|
67
67
|
|
68
68
|
### With other Rack-based frameworks
|
69
69
|
|
70
|
-
Other Rack-based frameworks, such as Sinatra, can use the Rack Middleware
|
70
|
+
Other Rack-based frameworks, such as Sinatra, can use the Rack Middleware
|
71
71
|
provided by the library:
|
72
72
|
|
73
73
|
```ruby
|
@@ -78,7 +78,7 @@ use Google::Cloud::Trace::Middleware
|
|
78
78
|
### Adding Custom Trace Spans
|
79
79
|
|
80
80
|
The Stackdriver Trace Rack Middleware automatically creates a trace record for
|
81
|
-
incoming requests. You can add additional custom trace spans within each
|
81
|
+
incoming requests. You can add additional custom trace spans within each
|
82
82
|
request:
|
83
83
|
|
84
84
|
```ruby
|
@@ -93,26 +93,26 @@ end
|
|
93
93
|
|
94
94
|
### Configuring the library
|
95
95
|
|
96
|
-
You can customize the behavior of the Stackdriver Trace library for Ruby. See
|
97
|
-
the [configuration guide](../stackdriver/configuration.md) for a list of
|
96
|
+
You can customize the behavior of the Stackdriver Trace library for Ruby. See
|
97
|
+
the [configuration guide](../stackdriver/configuration.md) for a list of
|
98
98
|
possible configuration options.
|
99
99
|
|
100
100
|
## Running on Google Cloud Platform
|
101
101
|
|
102
|
-
The Stackdriver Trace library for Ruby should work without you manually
|
103
|
-
providing authentication credentials for instances running on Google Cloud
|
104
|
-
Platform, as long as the Stackdriver Trace API access scope is enabled on that
|
102
|
+
The Stackdriver Trace library for Ruby should work without you manually
|
103
|
+
providing authentication credentials for instances running on Google Cloud
|
104
|
+
Platform, as long as the Stackdriver Trace API access scope is enabled on that
|
105
105
|
instance.
|
106
106
|
|
107
107
|
### App Engine
|
108
108
|
|
109
|
-
On Google App Engine, the Stackdriver Trace API access scope is enabled by
|
110
|
-
default, and the Stackdriver Trace library for Ruby can be used without
|
109
|
+
On Google App Engine, the Stackdriver Trace API access scope is enabled by
|
110
|
+
default, and the Stackdriver Trace library for Ruby can be used without
|
111
111
|
providing credentials or a project ID
|
112
112
|
|
113
113
|
### Container Engine
|
114
114
|
|
115
|
-
On Google Container Engine, you must explicitly add the `trace.append` OAuth
|
115
|
+
On Google Container Engine, you must explicitly add the `trace.append` OAuth
|
116
116
|
scope when creating the cluster:
|
117
117
|
|
118
118
|
```sh
|
@@ -121,32 +121,32 @@ $ gcloud container clusters create example-cluster-name --scopes https://www.goo
|
|
121
121
|
|
122
122
|
### Compute Engine
|
123
123
|
|
124
|
-
For Google Compute Engine instances, you need to explicitly enable the
|
125
|
-
`trace.append` Stackdriver Trace API access scope for each instance. When
|
126
|
-
creating a new instance through the Google Cloud Platform Console, you can do
|
127
|
-
this under Identity and API access: Use the Compute Engine default service
|
124
|
+
For Google Compute Engine instances, you need to explicitly enable the
|
125
|
+
`trace.append` Stackdriver Trace API access scope for each instance. When
|
126
|
+
creating a new instance through the Google Cloud Platform Console, you can do
|
127
|
+
this under Identity and API access: Use the Compute Engine default service
|
128
128
|
account and select "Allow full access to all Cloud APIs" under Access scopes.
|
129
129
|
|
130
|
-
To use something other than the Compute Engine default service account see the
|
131
|
-
docs for Creating and Enabling Service Accounts for Instances and the Running
|
130
|
+
To use something other than the Compute Engine default service account see the
|
131
|
+
docs for Creating and Enabling Service Accounts for Instances and the Running
|
132
132
|
elsewhere section below. The important thing is that the service account you use
|
133
133
|
has the Cloud Trace Agent role.
|
134
134
|
|
135
135
|
## Running locally and elsewhere
|
136
136
|
|
137
|
-
To run the Stackdriver Trace outside of Google Cloud Platform, you must supply
|
137
|
+
To run the Stackdriver Trace outside of Google Cloud Platform, you must supply
|
138
138
|
your GCP project ID and appropriate service account credentials directly to the
|
139
|
-
Stackdriver Trace. This applies to running the library on your own workstation,
|
140
|
-
on your datacenter's computers, or on the VM instances of another cloud
|
141
|
-
provider. See the [Authentication section](#authentication) for instructions on
|
139
|
+
Stackdriver Trace. This applies to running the library on your own workstation,
|
140
|
+
on your datacenter's computers, or on the VM instances of another cloud
|
141
|
+
provider. See the [Authentication section](#authentication) for instructions on
|
142
142
|
how to do so.
|
143
143
|
|
144
144
|
## Authentication
|
145
145
|
|
146
|
-
The Instrumentation client and API use Service Account credentials to connect
|
147
|
-
to Google Cloud services. When running on Google Cloud Platform environments,
|
148
|
-
the credentials will be discovered automatically. When running on other
|
149
|
-
environments the Service Account credentials can be specified by providing in
|
146
|
+
The Instrumentation client and API use Service Account credentials to connect
|
147
|
+
to Google Cloud services. When running on Google Cloud Platform environments,
|
148
|
+
the credentials will be discovered automatically. When running on other
|
149
|
+
environments the Service Account credentials can be specified by providing in
|
150
150
|
several ways.
|
151
151
|
|
152
152
|
The best way to provide authentication information if you're using Ruby on Rails
|
@@ -166,7 +166,7 @@ end
|
|
166
166
|
|
167
167
|
Other Rack-based applications that are loading the Rack Middleware directly can use
|
168
168
|
the configration interface:
|
169
|
-
|
169
|
+
|
170
170
|
```ruby
|
171
171
|
require "google/cloud/trace"
|
172
172
|
Google::Cloud.configure do |config|
|
@@ -179,8 +179,8 @@ Google::Cloud.configure do |config|
|
|
179
179
|
end
|
180
180
|
```
|
181
181
|
|
182
|
-
This library also supports the other authentication methods provided by the
|
183
|
-
`google-cloud-ruby` suite. Instructions and configuration options are covered
|
182
|
+
This library also supports the other authentication methods provided by the
|
183
|
+
`google-cloud-ruby` suite. Instructions and configuration options are covered
|
184
184
|
in the [Authentication Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-trace/guides/authentication).
|
185
185
|
|
186
186
|
## Supported Ruby Versions
|
@@ -191,19 +191,19 @@ This library is supported on Ruby 2.0+.
|
|
191
191
|
|
192
192
|
This library follows [Semantic Versioning](http://semver.org/).
|
193
193
|
|
194
|
-
It is currently in major version zero (0.y.z), which means that anything may
|
194
|
+
It is currently in major version zero (0.y.z), which means that anything may
|
195
195
|
change at any time and the public API should not be considered stable.
|
196
196
|
|
197
197
|
## Contributing
|
198
198
|
|
199
199
|
Contributions to this library are always welcome and highly encouraged.
|
200
200
|
|
201
|
-
See the
|
202
|
-
[Contributing Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/contributing)
|
201
|
+
See the
|
202
|
+
[Contributing Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/contributing)
|
203
203
|
for more information on how to get started.
|
204
204
|
|
205
205
|
Please note that this project is released with a Contributor Code of Conduct. By
|
206
|
-
participating in this project you agree to abide by its terms. See
|
206
|
+
participating in this project you agree to abide by its terms. See
|
207
207
|
[Code of Conduct](../CODE_OF_CONDUCT.md) for more information.
|
208
208
|
|
209
209
|
## License
|
@@ -213,8 +213,8 @@ This library is licensed under Apache 2.0. Full license text is available in
|
|
213
213
|
|
214
214
|
## Support
|
215
215
|
|
216
|
-
Please
|
216
|
+
Please
|
217
217
|
[report bugs at the project on Github](https://github.com/GoogleCloudPlatform/google-cloud-ruby/issues).
|
218
|
-
Don't hesitate to
|
219
|
-
[ask questions](http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby)
|
218
|
+
Don't hesitate to
|
219
|
+
[ask questions](http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby)
|
220
220
|
about the client or APIs on [StackOverflow](http://stackoverflow.com).
|
data/lib/google-cloud-trace.rb
CHANGED
@@ -20,6 +20,8 @@
|
|
20
20
|
|
21
21
|
gem "google-cloud-core"
|
22
22
|
require "google/cloud"
|
23
|
+
require "google/cloud/config"
|
24
|
+
require "googleauth"
|
23
25
|
|
24
26
|
module Google
|
25
27
|
module Cloud
|
@@ -34,7 +36,11 @@ module Google
|
|
34
36
|
# set of resources and operations that the connection can access. See
|
35
37
|
# [Using OAuth 2.0 to Access Google
|
36
38
|
# APIs](https://developers.google.com/identity/protocols/OAuth2).
|
37
|
-
#
|
39
|
+
#
|
40
|
+
# The default scope is:
|
41
|
+
#
|
42
|
+
# * `https://www.googleapis.com/auth/cloud-platform`
|
43
|
+
#
|
38
44
|
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
39
45
|
#
|
40
46
|
# @return [Google::Cloud::Trace::Project]
|
@@ -73,7 +79,11 @@ module Google
|
|
73
79
|
# set of resources and operations that the connection can access. See
|
74
80
|
# [Using OAuth 2.0 to Access Google
|
75
81
|
# APIs](https://developers.google.com/identity/protocols/OAuth2).
|
76
|
-
#
|
82
|
+
#
|
83
|
+
# The default scope is:
|
84
|
+
#
|
85
|
+
# * `https://www.googleapis.com/auth/cloud-platform`
|
86
|
+
#
|
77
87
|
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
78
88
|
#
|
79
89
|
# @return [Google::Cloud::Trace::Project]
|
@@ -97,3 +107,38 @@ module Google
|
|
97
107
|
end
|
98
108
|
end
|
99
109
|
end
|
110
|
+
|
111
|
+
# Add trace to top-level configuration
|
112
|
+
Google::Cloud.configure do |config|
|
113
|
+
unless config.field? :use_trace
|
114
|
+
config.add_field! :use_trace, nil, enum: [true, false]
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# Set the default trace configuration
|
119
|
+
Google::Cloud.configure.add_config! :trace do |config|
|
120
|
+
default_project = Google::Cloud::Config.deferred do
|
121
|
+
ENV["TRACE_PROJECT"]
|
122
|
+
end
|
123
|
+
default_creds = Google::Cloud::Config.deferred do
|
124
|
+
Google::Cloud::Config.credentials_from_env(
|
125
|
+
"TRACE_CREDENTIALS", "TRACE_CREDENTIALS_JSON",
|
126
|
+
"TRACE_KEYFILE", "TRACE_KEYFILE_JSON"
|
127
|
+
)
|
128
|
+
end
|
129
|
+
|
130
|
+
config.add_field! :project_id, default_project, match: String, allow_nil: true
|
131
|
+
config.add_alias! :project, :project_id
|
132
|
+
config.add_field! :credentials, default_creds,
|
133
|
+
match: [String, Hash, Google::Auth::Credentials],
|
134
|
+
allow_nil: true
|
135
|
+
config.add_alias! :keyfile, :credentials
|
136
|
+
config.add_field! :scope, nil, match: [String, Array]
|
137
|
+
config.add_field! :timeout, nil, match: Integer
|
138
|
+
config.add_field! :client_config, nil, match: Hash
|
139
|
+
config.add_field! :capture_stack, nil, enum: [true, false]
|
140
|
+
config.add_field! :sampler, nil
|
141
|
+
config.add_field! :span_id_generator, nil, match: Proc
|
142
|
+
config.add_field! :notifications, nil, match: Array
|
143
|
+
config.add_field! :max_data_length, nil, match: Integer
|
144
|
+
end
|
data/lib/google/cloud/trace.rb
CHANGED
@@ -27,6 +27,8 @@ require "google/cloud/trace/span_kind"
|
|
27
27
|
require "google/cloud/trace/time_sampler"
|
28
28
|
require "google/cloud/trace/trace_record"
|
29
29
|
require "google/cloud/trace/utils"
|
30
|
+
require "google/cloud/config"
|
31
|
+
require "google/cloud/env"
|
30
32
|
require "stackdriver/core"
|
31
33
|
|
32
34
|
module Google
|
@@ -191,12 +193,6 @@ module Google
|
|
191
193
|
module Trace
|
192
194
|
THREAD_KEY = :__stackdriver_trace_span__
|
193
195
|
|
194
|
-
# Initialize :error_reporting as a nested Configuration under
|
195
|
-
# Google::Cloud if haven't already
|
196
|
-
unless Google::Cloud.configure.option? :trace
|
197
|
-
Google::Cloud.configure.add_options :trace
|
198
|
-
end
|
199
|
-
|
200
196
|
##
|
201
197
|
# Creates a new object for connecting to the Stackdriver Trace service.
|
202
198
|
# Each call creates a new connection.
|
@@ -215,7 +211,11 @@ module Google
|
|
215
211
|
# the set of resources and operations that the connection can access.
|
216
212
|
# See [Using OAuth 2.0 to Access Google
|
217
213
|
# APIs](https://developers.google.com/identity/protocols/OAuth2).
|
218
|
-
#
|
214
|
+
#
|
215
|
+
# The default scope is:
|
216
|
+
#
|
217
|
+
# * `https://www.googleapis.com/auth/cloud-platform`
|
218
|
+
#
|
219
219
|
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
220
220
|
# @param [String] project Alias for the `project_id` argument. Deprecated.
|
221
221
|
# @param [String] keyfile Alias for the `credentials` argument.
|
@@ -235,11 +235,15 @@ module Google
|
|
235
235
|
#
|
236
236
|
def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil,
|
237
237
|
client_config: nil, project: nil, keyfile: nil
|
238
|
-
project_id ||= (project ||
|
238
|
+
project_id ||= (project || default_project_id)
|
239
239
|
project_id = project_id.to_s # Always cast to a string
|
240
|
-
|
240
|
+
raise ArgumentError, "project_id is missing" if project_id.empty?
|
241
|
+
|
242
|
+
scope ||= configure.scope
|
243
|
+
timeout ||= configure.timeout
|
244
|
+
client_config ||= configure.client_config
|
241
245
|
|
242
|
-
credentials ||= (keyfile ||
|
246
|
+
credentials ||= (keyfile || default_credentials(scope: scope))
|
243
247
|
unless credentials.is_a? Google::Auth::Credentials
|
244
248
|
credentials = Trace::Credentials.new credentials, scope: scope
|
245
249
|
end
|
@@ -247,7 +251,70 @@ module Google
|
|
247
251
|
Trace::Project.new(
|
248
252
|
Trace::Service.new(
|
249
253
|
project_id, credentials, timeout: timeout,
|
250
|
-
client_config: client_config
|
254
|
+
client_config: client_config
|
255
|
+
)
|
256
|
+
)
|
257
|
+
end
|
258
|
+
|
259
|
+
##
|
260
|
+
# Configure the Stackdriver Trace instrumentation Middleware.
|
261
|
+
#
|
262
|
+
# The following Stackdriver Trace configuration parameters are
|
263
|
+
# supported:
|
264
|
+
#
|
265
|
+
# * `project_id` - (String) Project identifier for the Stackdriver
|
266
|
+
# Trace service you are connecting to. (The parameter `project` is
|
267
|
+
# considered deprecated, but may also be used.)
|
268
|
+
# * `credentials` - (String, Hash, Google::Auth::Credentials) The path to
|
269
|
+
# the keyfile as a String, the contents of the keyfile as a Hash, or a
|
270
|
+
# Google::Auth::Credentials object. (See {Trace::Credentials}) (The
|
271
|
+
# parameter `keyfile` is considered deprecated, but may also be used.)
|
272
|
+
# * `scope` - (String, Array<String>) The OAuth 2.0 scopes controlling
|
273
|
+
# the set of resources and operations that the connection can access.
|
274
|
+
# * `timeout` - (Integer) Default timeout to use in requests.
|
275
|
+
# * `client_config` - (Hash) A hash of values to override the default
|
276
|
+
# behavior of the API client.
|
277
|
+
# * `capture_stack` - (Boolean) Whether to capture stack traces for each
|
278
|
+
# span. Default: `false`
|
279
|
+
# * `sampler` - (Proc) A sampler Proc makes the decision whether to record
|
280
|
+
# a trace for each request. Default: `Google::Cloud::Trace::TimeSampler`
|
281
|
+
# * `span_id_generator` - (Proc) A generator Proc that generates the name
|
282
|
+
# String for new TraceRecord. Default: `random numbers`
|
283
|
+
# * `notifications` - (Array) An array of ActiveSupport notification types
|
284
|
+
# to include in traces. Rails-only option. Default:
|
285
|
+
# `Google::Cloud::Trace::Railtie::DEFAULT_NOTIFICATIONS`
|
286
|
+
# * `max_data_length` - (Integer) The maximum length of span properties
|
287
|
+
# recorded with ActiveSupport notification events. Rails-only option.
|
288
|
+
# Default:
|
289
|
+
# `Google::Cloud::Trace::Notifications::DEFAULT_MAX_DATA_LENGTH`
|
290
|
+
#
|
291
|
+
# See the [Configuration
|
292
|
+
# Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/stackdriver/guides/instrumentation_configuration)
|
293
|
+
# for full configuration parameters.
|
294
|
+
#
|
295
|
+
# @return [Google::Cloud::Config] The configuration object
|
296
|
+
# the Google::Cloud::Trace module uses.
|
297
|
+
#
|
298
|
+
def self.configure
|
299
|
+
yield Google::Cloud.configure.trace if block_given?
|
300
|
+
|
301
|
+
Google::Cloud.configure.trace
|
302
|
+
end
|
303
|
+
|
304
|
+
##
|
305
|
+
# @private Default project.
|
306
|
+
def self.default_project_id
|
307
|
+
Google::Cloud.configure.trace.project_id ||
|
308
|
+
Google::Cloud.configure.project_id ||
|
309
|
+
Google::Cloud.env.project_id
|
310
|
+
end
|
311
|
+
|
312
|
+
##
|
313
|
+
# @private Default credentials.
|
314
|
+
def self.default_credentials scope: nil
|
315
|
+
Google::Cloud.configure.trace.credentials ||
|
316
|
+
Google::Cloud.configure.credentials ||
|
317
|
+
Trace::Credentials.default(scope: scope)
|
251
318
|
end
|
252
319
|
|
253
320
|
##
|
@@ -347,22 +414,6 @@ module Google
|
|
347
414
|
yield nil
|
348
415
|
end
|
349
416
|
end
|
350
|
-
|
351
|
-
##
|
352
|
-
# Configure the Stackdriver Trace instrumentation Middleware.
|
353
|
-
#
|
354
|
-
# See the [Configuration
|
355
|
-
# Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/stackdriver/guides/instrumentation_configuration)
|
356
|
-
# for full configuration parameters.
|
357
|
-
#
|
358
|
-
# @return [Stackdriver::Core::Configuration] The configuration object
|
359
|
-
# the Google::Cloud::ErrorReporting module uses.
|
360
|
-
#
|
361
|
-
def self.configure
|
362
|
-
yield Google::Cloud.configure.trace if block_given?
|
363
|
-
|
364
|
-
Google::Cloud.configure.trace
|
365
|
-
end
|
366
417
|
end
|
367
418
|
end
|
368
419
|
end
|
@@ -38,19 +38,19 @@ module Google
|
|
38
38
|
# trace.project_id #=> "my-project"
|
39
39
|
#
|
40
40
|
class Credentials < Google::Auth::Credentials
|
41
|
-
SCOPE = ["https://www.googleapis.com/auth/cloud-platform"]
|
42
|
-
PATH_ENV_VARS = %w
|
41
|
+
SCOPE = ["https://www.googleapis.com/auth/cloud-platform"].freeze
|
42
|
+
PATH_ENV_VARS = %w[TRACE_CREDENTIALS
|
43
43
|
TRACE_KEYFILE
|
44
44
|
GOOGLE_CLOUD_CREDENTIALS
|
45
45
|
GOOGLE_CLOUD_KEYFILE
|
46
|
-
GCLOUD_KEYFILE
|
47
|
-
JSON_ENV_VARS = %w
|
46
|
+
GCLOUD_KEYFILE].freeze
|
47
|
+
JSON_ENV_VARS = %w[TRACE_CREDENTIALS_JSON
|
48
48
|
TRACE_KEYFILE_JSON
|
49
49
|
GOOGLE_CLOUD_CREDENTIALS_JSON
|
50
50
|
GOOGLE_CLOUD_KEYFILE_JSON
|
51
|
-
GCLOUD_KEYFILE_JSON
|
51
|
+
GCLOUD_KEYFILE_JSON].freeze
|
52
52
|
DEFAULT_PATHS = \
|
53
|
-
["~/.config/gcloud/application_default_credentials.json"]
|
53
|
+
["~/.config/gcloud/application_default_credentials.json"].freeze
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
@@ -68,7 +68,7 @@ module Google
|
|
68
68
|
response_body.bytesize.to_s
|
69
69
|
set_label labels, label_keys::HTTP_STATUS_CODE, response_status.to_s
|
70
70
|
|
71
|
-
if
|
71
|
+
if response_status >= 300 && response_status < 400 && response_url
|
72
72
|
set_label labels, label_keys::HTTP_REDIRECTED_URL, response_url
|
73
73
|
end
|
74
74
|
end
|
@@ -22,59 +22,60 @@ module Google
|
|
22
22
|
# A collection of well-known label keys for trace spans.
|
23
23
|
#
|
24
24
|
module LabelKey
|
25
|
-
AGENT = "/agent"
|
26
|
-
COMPONENT = "/component"
|
27
|
-
ERROR_MESSAGE = "/error/message"
|
28
|
-
ERROR_NAME = "/error/name"
|
29
|
-
HTTP_CLIENT_CITY = "/http/client_city"
|
30
|
-
HTTP_CLIENT_COUNTRY = "/http/client_country"
|
31
|
-
HTTP_CLIENT_PROTOCOL = "/http/client_protocol"
|
32
|
-
HTTP_CLIENT_REGION = "/http/client_region"
|
33
|
-
HTTP_HOST = "/http/host"
|
34
|
-
HTTP_METHOD = "/http/method"
|
35
|
-
HTTP_REDIRECTED_URL = "/http/redirected_url"
|
36
|
-
HTTP_REQUEST_SIZE = "/http/request/size"
|
37
|
-
HTTP_RESPONSE_SIZE = "/http/response/size"
|
38
|
-
HTTP_STATUS_CODE = "/http/status_code"
|
39
|
-
HTTP_URL = "/http/url"
|
40
|
-
HTTP_USER_AGENT = "/http/user_agent"
|
41
|
-
PID = "/pid"
|
42
|
-
STACKTRACE = "/stacktrace"
|
43
|
-
TID = "/tid"
|
25
|
+
AGENT = "/agent".freeze
|
26
|
+
COMPONENT = "/component".freeze
|
27
|
+
ERROR_MESSAGE = "/error/message".freeze
|
28
|
+
ERROR_NAME = "/error/name".freeze
|
29
|
+
HTTP_CLIENT_CITY = "/http/client_city".freeze
|
30
|
+
HTTP_CLIENT_COUNTRY = "/http/client_country".freeze
|
31
|
+
HTTP_CLIENT_PROTOCOL = "/http/client_protocol".freeze
|
32
|
+
HTTP_CLIENT_REGION = "/http/client_region".freeze
|
33
|
+
HTTP_HOST = "/http/host".freeze
|
34
|
+
HTTP_METHOD = "/http/method".freeze
|
35
|
+
HTTP_REDIRECTED_URL = "/http/redirected_url".freeze
|
36
|
+
HTTP_REQUEST_SIZE = "/http/request/size".freeze
|
37
|
+
HTTP_RESPONSE_SIZE = "/http/response/size".freeze
|
38
|
+
HTTP_STATUS_CODE = "/http/status_code".freeze
|
39
|
+
HTTP_URL = "/http/url".freeze
|
40
|
+
HTTP_USER_AGENT = "/http/user_agent".freeze
|
41
|
+
PID = "/pid".freeze
|
42
|
+
STACKTRACE = "/stacktrace".freeze
|
43
|
+
TID = "/tid".freeze
|
44
44
|
|
45
|
-
GAE_APPLICATION_ERROR = "g.co/gae/application_error"
|
46
|
-
GAE_APP_MODULE = "g.co/gae/app/module"
|
47
|
-
GAE_APP_MODULE_VERSION = "g.co/gae/app/module_version"
|
48
|
-
GAE_APP_VERSION = "g.co/gae/app/version"
|
49
|
-
GAE_DATASTORE_COUNT = "g.co/gae/datastore/count"
|
50
|
-
GAE_DATASTORE_CURSOR = "g.co/gae/datastore/cursor"
|
51
|
-
GAE_DATASTORE_ENTITY_WRITES = "g.co/gae/datastore/entity_writes"
|
52
|
-
GAE_DATASTORE_HAS_ANCESTOR = "g.co/gae/datastore/has_ancestor"
|
53
|
-
GAE_DATASTORE_HAS_CURSOR = "g.co/gae/datastore/has_cursor"
|
54
|
-
GAE_DATASTORE_HAS_TRANSACTION =
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
45
|
+
GAE_APPLICATION_ERROR = "g.co/gae/application_error".freeze
|
46
|
+
GAE_APP_MODULE = "g.co/gae/app/module".freeze
|
47
|
+
GAE_APP_MODULE_VERSION = "g.co/gae/app/module_version".freeze
|
48
|
+
GAE_APP_VERSION = "g.co/gae/app/version".freeze
|
49
|
+
GAE_DATASTORE_COUNT = "g.co/gae/datastore/count".freeze
|
50
|
+
GAE_DATASTORE_CURSOR = "g.co/gae/datastore/cursor".freeze
|
51
|
+
GAE_DATASTORE_ENTITY_WRITES = "g.co/gae/datastore/entity_writes".freeze
|
52
|
+
GAE_DATASTORE_HAS_ANCESTOR = "g.co/gae/datastore/has_ancestor".freeze
|
53
|
+
GAE_DATASTORE_HAS_CURSOR = "g.co/gae/datastore/has_cursor".freeze
|
54
|
+
GAE_DATASTORE_HAS_TRANSACTION =
|
55
|
+
"g.co/gae/datastore/has_transaction".freeze
|
56
|
+
GAE_DATASTORE_INDEX_WRITES = "g.co/gae/datastore/index_writes".freeze
|
57
|
+
GAE_DATASTORE_KIND = "g.co/gae/datastore/kind".freeze
|
58
|
+
GAE_DATASTORE_LIMIT = "g.co/gae/datastore/limit".freeze
|
59
|
+
GAE_DATASTORE_MORE_RESULTS = "g.co/gae/datastore/more_results".freeze
|
60
|
+
GAE_DATASTORE_OFFSET = "g.co/gae/datastore/offset".freeze
|
60
61
|
GAE_DATASTORE_REQUESTED_ENTITY_DELETES =
|
61
|
-
"g.co/gae/datastore/requested_entity_deletes"
|
62
|
+
"g.co/gae/datastore/requested_entity_deletes".freeze
|
62
63
|
GAE_DATASTORE_REQUESTED_ENTITY_PUTS =
|
63
|
-
"g.co/gae/datastore/requested_entity_puts"
|
64
|
-
GAE_DATASTORE_SIZE = "g.co/gae/datastore/size"
|
65
|
-
GAE_DATASTORE_SKIPPED = "g.co/gae/datastore/skipped"
|
64
|
+
"g.co/gae/datastore/requested_entity_puts".freeze
|
65
|
+
GAE_DATASTORE_SIZE = "g.co/gae/datastore/size".freeze
|
66
|
+
GAE_DATASTORE_SKIPPED = "g.co/gae/datastore/skipped".freeze
|
66
67
|
GAE_DATASTORE_TRANSACTION_HANDLE =
|
67
|
-
"g.co/gae/datastore/transaction_handle"
|
68
|
-
GAE_ERROR_MESSAGE = "g.co/gae/error_message"
|
69
|
-
GAE_MEMCACHE_COUNT = "g.co/gae/memcache/count"
|
70
|
-
GAE_MEMCACHE_SIZE = "g.co/gae/memcache/size"
|
71
|
-
GAE_REQUEST_LOG_ID = "g.co/gae/request_log_id"
|
68
|
+
"g.co/gae/datastore/transaction_handle".freeze
|
69
|
+
GAE_ERROR_MESSAGE = "g.co/gae/error_message".freeze
|
70
|
+
GAE_MEMCACHE_COUNT = "g.co/gae/memcache/count".freeze
|
71
|
+
GAE_MEMCACHE_SIZE = "g.co/gae/memcache/size".freeze
|
72
|
+
GAE_REQUEST_LOG_ID = "g.co/gae/request_log_id".freeze
|
72
73
|
|
73
|
-
RPC_HOST = "/rpc/host"
|
74
|
-
RPC_REQUEST_TYPE = "/rpc/request/type"
|
75
|
-
RPC_REQUEST_SIZE = "/rpc/request/size"
|
76
|
-
RPC_RESPONSE_SIZE = "/rpc/response/size"
|
77
|
-
RPC_STATUS_CODE = "/rpc/status_code"
|
74
|
+
RPC_HOST = "/rpc/host".freeze
|
75
|
+
RPC_REQUEST_TYPE = "/rpc/request/type".freeze
|
76
|
+
RPC_REQUEST_SIZE = "/rpc/request/size".freeze
|
77
|
+
RPC_RESPONSE_SIZE = "/rpc/response/size".freeze
|
78
|
+
RPC_STATUS_CODE = "/rpc/status_code".freeze
|
78
79
|
|
79
80
|
##
|
80
81
|
# Set the stack trace label in the given labels hash. The current call
|
@@ -131,9 +131,9 @@ module Google
|
|
131
131
|
project_id = configuration.project_id
|
132
132
|
|
133
133
|
if project_id
|
134
|
-
|
135
|
-
tracer = Google::Cloud::Trace.new
|
136
|
-
|
134
|
+
credentials = configuration.credentials
|
135
|
+
tracer = Google::Cloud::Trace.new project_id: project_id,
|
136
|
+
credentials: credentials
|
137
137
|
@service = Google::Cloud::Trace::AsyncReporter.new tracer.service
|
138
138
|
end
|
139
139
|
end
|
@@ -212,7 +212,7 @@ module Google
|
|
212
212
|
if @service && trace.trace_context.sampled?
|
213
213
|
begin
|
214
214
|
@service.patch_traces trace
|
215
|
-
rescue => ex
|
215
|
+
rescue StandardError => ex
|
216
216
|
msg = "Transmit to Stackdriver Trace failed: #{ex.inspect}"
|
217
217
|
logger = env["rack.logger"]
|
218
218
|
if logger
|
@@ -349,9 +349,9 @@ module Google
|
|
349
349
|
def configure_result span, result
|
350
350
|
if result.is_a?(::Array) && result.size == 3
|
351
351
|
span.labels[Google::Cloud::Trace::LabelKey::HTTP_STATUS_CODE] =
|
352
|
-
|
352
|
+
result[0].to_s
|
353
353
|
result[1]["X-Cloud-Trace-Context"] =
|
354
|
-
|
354
|
+
span.trace.trace_context.to_string
|
355
355
|
end
|
356
356
|
result
|
357
357
|
end
|
@@ -364,12 +364,14 @@ module Google
|
|
364
364
|
# already.
|
365
365
|
#
|
366
366
|
def load_config **kwargs
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
configuration.
|
372
|
-
|
367
|
+
capture_stack = kwargs[:capture_stack]
|
368
|
+
configuration.capture_stack = capture_stack unless capture_stack.nil?
|
369
|
+
|
370
|
+
sampler = kwargs[:sampler]
|
371
|
+
configuration.sampler = sampler unless sampler.nil?
|
372
|
+
|
373
|
+
generator = kwargs[:span_id_generator]
|
374
|
+
configuration.span_id_generator = generator unless generator.nil?
|
373
375
|
|
374
376
|
init_default_config
|
375
377
|
end
|
@@ -377,9 +379,8 @@ module Google
|
|
377
379
|
##
|
378
380
|
# Fallback to default configuration values if not defined already
|
379
381
|
def init_default_config
|
380
|
-
configuration.project_id ||=
|
381
|
-
|
382
|
-
configuration.keyfile ||= Cloud.configure.keyfile
|
382
|
+
configuration.project_id ||= Trace.default_project_id
|
383
|
+
configuration.credentials ||= Cloud.configure.credentials
|
383
384
|
configuration.capture_stack ||= false
|
384
385
|
end
|
385
386
|
|
@@ -27,7 +27,7 @@ module Google
|
|
27
27
|
|
28
28
|
##
|
29
29
|
# The default prefix for label keys
|
30
|
-
DEFAULT_LABEL_NAMESPACE = "/ruby/"
|
30
|
+
DEFAULT_LABEL_NAMESPACE = "/ruby/".freeze
|
31
31
|
|
32
32
|
##
|
33
33
|
# Stack truncation method that removes the ActiveSupport::Notifications
|
@@ -104,7 +104,7 @@ module Google
|
|
104
104
|
labels = {}
|
105
105
|
event.payload.each do |k, v|
|
106
106
|
if v.is_a? ::String
|
107
|
-
v = v[0, maxlen-3] + "..." if maxlen && v.size > maxlen
|
107
|
+
v = v[0, maxlen - 3] + "..." if maxlen && v.size > maxlen
|
108
108
|
labels["#{label_namespace}#{k}"] = v
|
109
109
|
end
|
110
110
|
end
|
@@ -21,7 +21,7 @@ module GRPC
|
|
21
21
|
# class. Intercept each GRPC request and create a Trace span with basic
|
22
22
|
# request information.
|
23
23
|
module ActiveCallWithTrace
|
24
|
-
SPAN_NAME = "gRPC request"
|
24
|
+
SPAN_NAME = "gRPC request".freeze
|
25
25
|
|
26
26
|
##
|
27
27
|
# Override GRPC::ActiveCall#request_response method. Wrap the original
|
@@ -70,7 +70,7 @@ module Google
|
|
70
70
|
def project_id
|
71
71
|
service.project
|
72
72
|
end
|
73
|
-
|
73
|
+
alias project project_id
|
74
74
|
|
75
75
|
##
|
76
76
|
# Create a new empty trace record for this project. Uses the current
|
@@ -197,22 +197,13 @@ module Google
|
|
197
197
|
page_token: page_token
|
198
198
|
end
|
199
199
|
|
200
|
-
##
|
201
|
-
# @private Default project.
|
202
|
-
def self.default_project_id
|
203
|
-
ENV["TRACE_PROJECT"] ||
|
204
|
-
ENV["GOOGLE_CLOUD_PROJECT"] ||
|
205
|
-
ENV["GCLOUD_PROJECT"] ||
|
206
|
-
Google::Cloud.env.project_id
|
207
|
-
end
|
208
|
-
|
209
200
|
protected
|
210
201
|
|
211
202
|
##
|
212
203
|
# @private Raise an error unless an active connection to the service is
|
213
204
|
# available.
|
214
205
|
def ensure_service!
|
215
|
-
|
206
|
+
raise "Must have active connection to service" unless service
|
216
207
|
end
|
217
208
|
end
|
218
209
|
end
|
@@ -131,7 +131,7 @@ module Google
|
|
131
131
|
# Verify credentials and set use_error_reporting to false if
|
132
132
|
# credentials are invalid
|
133
133
|
unless valid_credentials? Trace.configure.project_id,
|
134
|
-
Trace.configure.
|
134
|
+
Trace.configure.credentials
|
135
135
|
Cloud.configure.use_trace = false
|
136
136
|
return
|
137
137
|
end
|
@@ -140,6 +140,8 @@ module Google
|
|
140
140
|
Google::Cloud.configure.use_trace ||= Rails.env.production?
|
141
141
|
end
|
142
142
|
|
143
|
+
# rubocop:disable all
|
144
|
+
|
143
145
|
##
|
144
146
|
# @private Merge Rails configuration into Trace instrumentation
|
145
147
|
# configuration.
|
@@ -147,23 +149,32 @@ module Google
|
|
147
149
|
gcp_config = rails_config.google_cloud
|
148
150
|
trace_config = gcp_config.trace
|
149
151
|
|
150
|
-
Cloud.configure.use_trace
|
152
|
+
if Cloud.configure.use_trace.nil?
|
153
|
+
Cloud.configure.use_trace = gcp_config.use_trace
|
154
|
+
end
|
151
155
|
Trace.configure do |config|
|
152
|
-
config.project_id ||=
|
153
|
-
|
154
|
-
|
156
|
+
config.project_id ||= (config.project ||
|
157
|
+
trace_config.project_id || trace_config.project ||
|
158
|
+
gcp_config.project_id || gcp_config.project)
|
159
|
+
config.credentials ||= (config.keyfile ||
|
160
|
+
trace_config.credentials || trace_config.keyfile ||
|
161
|
+
gcp_config.credentials || gcp_config.keyfile)
|
155
162
|
config.notifications ||= trace_config.notifications
|
156
163
|
config.max_data_length ||= trace_config.max_data_length
|
157
|
-
config.capture_stack
|
164
|
+
if config.capture_stack.nil?
|
165
|
+
config.capture_stack = trace_config.capture_stack
|
166
|
+
end
|
158
167
|
config.sampler ||= trace_config.sampler
|
159
168
|
config.span_id_generator ||= trace_config.span_id_generator
|
160
169
|
end
|
161
170
|
end
|
162
171
|
|
172
|
+
# rubocop:enable all
|
173
|
+
|
163
174
|
##
|
164
175
|
# Fallback to default config values if config parameters not provided.
|
165
176
|
def self.init_default_config
|
166
|
-
Trace.configure.project_id ||= Trace
|
177
|
+
Trace.configure.project_id ||= Trace.default_project_id
|
167
178
|
end
|
168
179
|
|
169
180
|
##
|
@@ -66,7 +66,8 @@ module Google
|
|
66
66
|
timeout: timeout,
|
67
67
|
client_config: client_config,
|
68
68
|
lib_name: "gccl",
|
69
|
-
lib_version: Google::Cloud::Trace::VERSION
|
69
|
+
lib_version: Google::Cloud::Trace::VERSION
|
70
|
+
)
|
70
71
|
end
|
71
72
|
end
|
72
73
|
attr_accessor :mocked_lowlevel_client
|
@@ -94,21 +95,22 @@ module Google
|
|
94
95
|
Google::Cloud::Trace::TraceRecord.from_grpc trace_proto
|
95
96
|
end
|
96
97
|
|
98
|
+
# rubocop:disable Metrics/MethodLength
|
99
|
+
|
97
100
|
##
|
98
101
|
# Searches for traces matching the given criteria.
|
99
102
|
#
|
100
|
-
# rubocop:disable Metrics/MethodLength
|
101
103
|
def list_traces project_id, start_time, end_time,
|
102
104
|
filter: nil,
|
103
105
|
order_by: nil,
|
104
106
|
view: nil,
|
105
107
|
page_size: nil,
|
106
108
|
page_token: nil
|
107
|
-
if page_token
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
109
|
+
call_opts = if page_token
|
110
|
+
Google::Gax::CallOptions.new page_token: page_token
|
111
|
+
else
|
112
|
+
Google::Gax::CallOptions.new
|
113
|
+
end
|
112
114
|
start_proto = Google::Cloud::Trace::Utils.time_to_grpc start_time
|
113
115
|
end_proto = Google::Cloud::Trace::Utils.time_to_grpc end_time
|
114
116
|
paged_enum = execute do
|
@@ -121,6 +123,7 @@ module Google
|
|
121
123
|
order_by: order_by,
|
122
124
|
options: call_opts
|
123
125
|
end
|
126
|
+
|
124
127
|
Google::Cloud::Trace::ResultSet.from_gax_page \
|
125
128
|
self, project_id,
|
126
129
|
paged_enum.page, start_time, end_time,
|
@@ -131,6 +134,8 @@ module Google
|
|
131
134
|
page_token: page_token
|
132
135
|
end
|
133
136
|
|
137
|
+
# rubocop:enable Metrics/MethodLength
|
138
|
+
|
134
139
|
# @private
|
135
140
|
def inspect
|
136
141
|
"#{self.class}(#{@project})"
|
@@ -116,13 +116,14 @@ module Google
|
|
116
116
|
@labels = labels
|
117
117
|
end
|
118
118
|
|
119
|
+
# rubocop:disable Metrics/AbcSize
|
120
|
+
|
119
121
|
##
|
120
122
|
# Standard value equality check for this object.
|
121
123
|
#
|
122
124
|
# @param [Object] other
|
123
125
|
# @return [Boolean]
|
124
126
|
#
|
125
|
-
# rubocop:disable Metrics/AbcSize
|
126
127
|
def eql? other
|
127
128
|
other.is_a?(Google::Cloud::Trace::Span) &&
|
128
129
|
trace.trace_context == other.trace.trace_context &&
|
@@ -135,7 +136,9 @@ module Google
|
|
135
136
|
end_time == other.end_time &&
|
136
137
|
labels == other.labels
|
137
138
|
end
|
138
|
-
|
139
|
+
alias == eql?
|
140
|
+
|
141
|
+
# rubocop:enable Metrics/AbcSize
|
139
142
|
|
140
143
|
##
|
141
144
|
# Create a new Span object from a TraceSpan protobuf and insert it
|
@@ -297,7 +300,7 @@ module Google
|
|
297
300
|
# starts them if not.
|
298
301
|
#
|
299
302
|
def start!
|
300
|
-
|
303
|
+
raise "Span already started" if start_time
|
301
304
|
ensure_started
|
302
305
|
end
|
303
306
|
|
@@ -309,8 +312,8 @@ module Google
|
|
309
312
|
# finishes them if not.
|
310
313
|
#
|
311
314
|
def finish!
|
312
|
-
|
313
|
-
|
315
|
+
raise "Span not yet started" unless start_time
|
316
|
+
raise "Span already finished" if end_time
|
314
317
|
ensure_finished
|
315
318
|
end
|
316
319
|
|
@@ -417,7 +420,7 @@ module Google
|
|
417
420
|
# @private
|
418
421
|
#
|
419
422
|
def ensure_exists!
|
420
|
-
|
423
|
+
raise "Span has been deleted" unless trace
|
421
424
|
end
|
422
425
|
|
423
426
|
##
|
@@ -429,7 +432,7 @@ module Google
|
|
429
432
|
def ensure_no_cycle! new_parent
|
430
433
|
ptr = new_parent
|
431
434
|
until ptr.nil?
|
432
|
-
|
435
|
+
raise "Move would result in a cycle" if ptr.equal?(self)
|
433
436
|
ptr = ptr.parent
|
434
437
|
end
|
435
438
|
end
|
@@ -44,19 +44,20 @@ module Google
|
|
44
44
|
# Create an empty Trace object. If a trace context is provided, it is
|
45
45
|
# used to locate this trace within that context.
|
46
46
|
#
|
47
|
-
# @param [String]
|
47
|
+
# @param [String] project_id The ID of the project containing this
|
48
|
+
# trace.
|
48
49
|
# @param [Stackdriver::Core::TraceContext] trace_context The context
|
49
50
|
# within which to locate this trace (i.e. sets the trace ID and
|
50
51
|
# the context parent span, if present.) If no context is provided,
|
51
52
|
# a new trace with a new trace ID is created.
|
52
53
|
#
|
53
|
-
def initialize
|
54
|
-
@
|
54
|
+
def initialize project_id, trace_context = nil, span_id_generator: nil
|
55
|
+
@project_id = project_id
|
55
56
|
@trace_context = trace_context || Stackdriver::Core::TraceContext.new
|
56
57
|
@root_spans = []
|
57
58
|
@spans_by_id = {}
|
58
59
|
@span_id_generator =
|
59
|
-
span_id_generator || ::Proc.new { rand(0xffffffffffffffff)
|
60
|
+
span_id_generator || ::Proc.new { rand(1..0xffffffffffffffff) }
|
60
61
|
end
|
61
62
|
|
62
63
|
##
|
@@ -70,7 +71,7 @@ module Google
|
|
70
71
|
trace_context == other.trace_context &&
|
71
72
|
@spans_by_id == other.instance_variable_get(:@spans_by_id)
|
72
73
|
end
|
73
|
-
|
74
|
+
alias == eql?
|
74
75
|
|
75
76
|
##
|
76
77
|
# Create a new Trace object from a trace protobuf.
|
@@ -88,7 +89,7 @@ module Google
|
|
88
89
|
parent_span_ids = find_root_span_ids span_protos
|
89
90
|
|
90
91
|
span_id = parent_span_ids.size == 1 ? parent_span_ids.first : 0
|
91
|
-
span_id = nil if span_id
|
92
|
+
span_id = nil if span_id.zero?
|
92
93
|
tc = Stackdriver::Core::TraceContext.new trace_id: trace_id,
|
93
94
|
span_id: span_id
|
94
95
|
trace = new trace_proto.project_id, tc
|
@@ -111,7 +112,7 @@ module Google
|
|
111
112
|
span.to_grpc trace_context.span_id.to_i
|
112
113
|
end
|
113
114
|
Google::Devtools::Cloudtrace::V1::Trace.new \
|
114
|
-
project_id:
|
115
|
+
project_id: project_id,
|
115
116
|
trace_id: trace_id,
|
116
117
|
spans: span_protos
|
117
118
|
end
|
@@ -121,8 +122,8 @@ module Google
|
|
121
122
|
#
|
122
123
|
# @return [String]
|
123
124
|
#
|
124
|
-
attr_reader :
|
125
|
-
|
125
|
+
attr_reader :project_id
|
126
|
+
alias project project_id
|
126
127
|
|
127
128
|
##
|
128
129
|
# The context for this trace.
|
@@ -191,7 +192,7 @@ module Google
|
|
191
192
|
start_time: nil, end_time: nil,
|
192
193
|
labels: {}
|
193
194
|
parent_span_id = parent_span_id.to_i
|
194
|
-
parent_span_id = trace_context.span_id.to_i if parent_span_id
|
195
|
+
parent_span_id = trace_context.span_id.to_i if parent_span_id.zero?
|
195
196
|
parent_span = @spans_by_id[parent_span_id]
|
196
197
|
if parent_span
|
197
198
|
parent_span.create_span name,
|
@@ -243,7 +244,7 @@ module Google
|
|
243
244
|
start_time, end_time, labels
|
244
245
|
span_id = span_id.to_i
|
245
246
|
parent_span_id = parent_span_id.to_i
|
246
|
-
span_id = unique_span_id if span_id
|
247
|
+
span_id = unique_span_id if span_id.zero?
|
247
248
|
span = Google::Cloud::Trace::Span.new \
|
248
249
|
self, span_id, parent_span_id, parent, name, kind,
|
249
250
|
start_time, end_time, labels
|
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.31.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: 2018-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-cloud-core
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: stackdriver-core
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
33
|
+
version: '1.3'
|
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.
|
40
|
+
version: '1.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: google-gax
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -154,16 +154,16 @@ dependencies:
|
|
154
154
|
name: rubocop
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
|
-
- - "
|
157
|
+
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: 0.
|
159
|
+
version: 0.50.0
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
|
-
- - "
|
164
|
+
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: 0.
|
166
|
+
version: 0.50.0
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: simplecov
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -290,7 +290,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
290
290
|
version: '0'
|
291
291
|
requirements: []
|
292
292
|
rubyforge_project:
|
293
|
-
rubygems_version: 2.7.
|
293
|
+
rubygems_version: 2.7.6
|
294
294
|
signing_key:
|
295
295
|
specification_version: 4
|
296
296
|
summary: Application Instrumentation and API Client library for Stackdriver Trace
|