google-cloud-error_reporting 0.29.0 → 0.30.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
  SHA256:
3
- metadata.gz: 88b08940e7e30a94943a7ab3fe2f1ce9695f3b574e4e0f8e895b8e06ba1b650f
4
- data.tar.gz: 03d55257fbdd0a03e4b6ba60de5bf8511d2bf1a36ad684048c436e8de95d598c
3
+ metadata.gz: 84b5253d164ae3db6ddc1be54bfa7b9c9ce343a2324137c0c1ab08b3cdc4c66f
4
+ data.tar.gz: 64bd74a706fd71fc3f54ceacda2a6c5742f035f41d42c873121d8b8f9a23a90b
5
5
  SHA512:
6
- metadata.gz: 32665a9fd9b67bca78ba3197b61ba7bb55f6f7907e904d99cb9384aa5347a99eafa253cc4dce07c15413dee3e0fdf87d7e970afd16ab4e548837c1f80ed956e3
7
- data.tar.gz: e75022416eabb7eb6dd6b5cdc1de25f5758923093314dac7356a2dc4e48458e7154b90e9acf27edd110978a2ccb7a5c1b6b8cd848494626207df8e933330cae0
6
+ metadata.gz: 62a140a092f7b33d38c46ffe1d303b06aa12b3ad6fe2eb7781568d9a11111aba123fda5c481bdc1ae2c2a82692e086b56d1042518b99a05f9830d32e6da678df
7
+ data.tar.gz: a3d8cdfc89c1eeb7758da6fa59201dfec377b9a513570eebed212b3f9c088bcb11b3c81fee2481b522e33544faed4c971eade4e9cec276bbea226d704a7f6aee
data/README.md CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  [Stackdriver Error Reporting](https://cloud.google.com/error-reporting/) counts,
4
4
  analyzes and aggregates errors raised in your running cloud services. A
5
- centralized error management interface displays the results with sorting
6
- and filtering capabilities. A dedicated view shows the error details: time
7
- chart, occurrences, affected user count, first and last seen dates and a
8
- cleaned exception stack trace. Opt-in to receive email and mobile alerts on
5
+ centralized error management interface displays the results with sorting
6
+ and filtering capabilities. A dedicated view shows the error details: time
7
+ chart, occurrences, affected user count, first and last seen dates and a
8
+ cleaned exception stack trace. Opt-in to receive email and mobile alerts on
9
9
  new errors.
10
10
 
11
11
  - [google-cloud-error_reporting API documentation](http://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-error_reporting/latest)
@@ -35,26 +35,26 @@ gem "google-cloud-error_reporting"
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-error_reporting` gem.
40
40
 
41
41
  ## Enable Stackdriver Error Reporting API
42
42
 
43
43
  The Stackdriver Error Reporting library needs the [Stackdriver Error
44
- Reporting API](https://console.cloud.google.com/apis/library/clouderrorreporting.googleapis.com)
45
- to be enabled on your Google Cloud project. Make sure it's enabled if not
44
+ Reporting API](https://console.cloud.google.com/apis/library/clouderrorreporting.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
  ## Reporting errors in Rack-based frameworks
49
49
 
50
- The Stackdriver Error Reporting library for Ruby makes it easy to integrate
51
- Stackdriver Error Reporting into popular Rack-based Ruby web frameworks such as
52
- Ruby on Rails and Sinatra. When the library integration is enabled, it
50
+ The Stackdriver Error Reporting library for Ruby makes it easy to integrate
51
+ Stackdriver Error Reporting into popular Rack-based Ruby web frameworks such as
52
+ Ruby on Rails and Sinatra. When the library integration is enabled, it
53
53
  automatically reports exceptions captured from the application's Rack stack.
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/error_reporting/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
@@ -90,58 +90,58 @@ end
90
90
 
91
91
  ## Configuring the library
92
92
 
93
- You can customize the behavior of the Stackdriver Error Reporting library for
94
- Ruby. See the [configuration guide](../stackdriver/docs/configuration.md) for a list
93
+ You can customize the behavior of the Stackdriver Error Reporting library for
94
+ Ruby. See the [configuration guide](../stackdriver/docs/configuration.md) for a list
95
95
  of possible configuration options.
96
96
 
97
97
  ## Running on Google Cloud Platform
98
98
 
99
- The Stackdriver Error Reporting library for Ruby should work without you
100
- manually providing authentication credentials for instances running on Google
101
- Cloud Platform, as long as the Stackdriver Error Reporting API access scope is
99
+ The Stackdriver Error Reporting library for Ruby should work without you
100
+ manually providing authentication credentials for instances running on Google
101
+ Cloud Platform, as long as the Stackdriver Error Reporting API access scope is
102
102
  enabled on that instance.
103
103
 
104
104
  ### App Engine
105
105
 
106
- On Google App Engine, the Stackdriver Error Reporting API access scope is
107
- enabled by default, and the Stackdriver Error Reporting library for Ruby can
106
+ On Google App Engine, the Stackdriver Error Reporting API access scope is
107
+ enabled by default, and the Stackdriver Error Reporting library for Ruby can
108
108
  be used without providing credentials or a project ID.
109
109
 
110
110
  ### Container Engine
111
111
 
112
- On Google Container Engine, you must explicitly add the `cloud-platform` OAuth
112
+ On Google Container Engine, you must explicitly add the `cloud-platform` OAuth
113
113
  scope when creating the cluster:
114
114
 
115
115
  ```sh
116
116
  $ gcloud container clusters create example-cluster-name --scopes https://www.googleapis.com/auth/cloud-platform
117
117
  ```
118
118
 
119
- You may also do this through the Google Cloud Platform Console. Select
119
+ You may also do this through the Google Cloud Platform Console. Select
120
120
  **Enabled** in the **Cloud Platform** section of **Create a container cluster**.
121
121
 
122
122
  ### Compute Engine
123
123
 
124
- For Google Compute Engine instances, you must explicitly enable the
125
- `cloud-platform` access scope for each instance. When you create a new instance
126
- through the Google Cloud Platform Console, you can do this under Identity and
127
- API access: Use the Compute Engine default service account and select "Allow
124
+ For Google Compute Engine instances, you must explicitly enable the
125
+ `cloud-platform` access scope for each instance. When you create a new instance
126
+ through the Google Cloud Platform Console, you can do this under Identity and
127
+ API access: Use the Compute Engine default service account and select "Allow
128
128
  full access to all Cloud APIs" under Access scopes.
129
129
 
130
130
  ## Running locally and elsewhere
131
131
 
132
- To run the Stackdriver Error Reporting outside of Google Cloud Platform, you
133
- must supply your GCP project ID and appropriate service account credentials
134
- directly to the Stackdriver Error Reporting. This applies to running the
135
- library on your own workstation, on your datacenter's computers, or on the VM
136
- instances of another cloud provider. See the [Authentication
132
+ To run the Stackdriver Error Reporting outside of Google Cloud Platform, you
133
+ must supply your GCP project ID and appropriate service account credentials
134
+ directly to the Stackdriver Error Reporting. This applies to running the
135
+ library on your own workstation, on your datacenter's computers, or on the VM
136
+ instances of another cloud provider. See the [Authentication
137
137
  section](#authentication) for instructions on how to do so.
138
138
 
139
139
  ## Authentication
140
140
 
141
- The Instrumentation client and API use Service Account credentials to connect
142
- to Google Cloud services. When running on Google Cloud Platform environments,
143
- the credentials will be discovered automatically. When running on other
144
- environments the Service Account credentials can be specified by providing in
141
+ The Instrumentation client and API use Service Account credentials to connect
142
+ to Google Cloud services. When running on Google Cloud Platform environments,
143
+ the credentials will be discovered automatically. When running on other
144
+ environments the Service Account credentials can be specified by providing in
145
145
  several ways.
146
146
 
147
147
  The best way to provide authentication information if you're using Ruby on Rails
@@ -161,7 +161,7 @@ end
161
161
 
162
162
  Other Rack-based applications that are loading the Rack Middleware directly or
163
163
  using the manually reporting interface can leverage the configration interface:
164
-
164
+
165
165
  ```ruby
166
166
  require "google/cloud/error_reporting"
167
167
  Google::Cloud.configure do |config|
@@ -174,8 +174,8 @@ Google::Cloud.configure do |config|
174
174
  end
175
175
  ```
176
176
 
177
- This library also supports the other authentication methods provided by the
178
- `google-cloud-ruby` suite. Instructions and configuration options are covered
177
+ This library also supports the other authentication methods provided by the
178
+ `google-cloud-ruby` suite. Instructions and configuration options are covered
179
179
  in the [Authentication Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-debugger/guides/authentication).
180
180
 
181
181
  ## Supported Ruby Versions
@@ -186,19 +186,19 @@ This library is supported on Ruby 2.0+.
186
186
 
187
187
  This library follows [Semantic Versioning](http://semver.org/).
188
188
 
189
- It is currently in major version zero (0.y.z), which means that anything may
189
+ It is currently in major version zero (0.y.z), which means that anything may
190
190
  change at any time and the public API should not be considered stable.
191
191
 
192
192
  ## Contributing
193
193
 
194
194
  Contributions to this library are always welcome and highly encouraged.
195
195
 
196
- See the
197
- [Contributing Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/contributing)
196
+ See the
197
+ [Contributing Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/contributing)
198
198
  for more information on how to get started.
199
199
 
200
200
  Please note that this project is released with a Contributor Code of Conduct. By
201
- participating in this project you agree to abide by its terms. See
201
+ participating in this project you agree to abide by its terms. See
202
202
  [Code of Conduct](../CODE_OF_CONDUCT.md) for more information.
203
203
 
204
204
  ## License
@@ -208,9 +208,9 @@ This library is licensed under Apache 2.0. Full license text is available in
208
208
 
209
209
  ## Support
210
210
 
211
- Please
211
+ Please
212
212
  [report bugs at the project on Github](https://github.com/GoogleCloudPlatform/google-cloud-ruby/issues).
213
- Don't hesitate to
214
- [ask questions](http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby)
213
+ Don't hesitate to
214
+ [ask questions](http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby)
215
215
  about the client or APIs on [StackOverflow](http://stackoverflow.com).
216
216
 
@@ -18,6 +18,8 @@
18
18
 
19
19
  gem "google-cloud-core"
20
20
  require "google/cloud"
21
+ require "google/cloud/config"
22
+ require "googleauth"
21
23
 
22
24
  module Google
23
25
  module Cloud
@@ -36,6 +38,7 @@ module Google
36
38
  # The default scope is:
37
39
  #
38
40
  # * `https://www.googleapis.com/auth/cloud-platform`
41
+ #
39
42
  # @param [Integer] timeout Default timeout to use in requests. Optional.
40
43
  # @param [Hash] client_config A hash of values to override the default
41
44
  # behavior of the API client. Optional.
@@ -62,7 +65,6 @@ module Google
62
65
  client_config: client_config
63
66
  end
64
67
 
65
-
66
68
  ##
67
69
  # Create a new object for connecting to the Stackdriver Error Reporting
68
70
  # service. Each call creates a new connection.
@@ -84,6 +86,7 @@ module Google
84
86
  # The default scope is:
85
87
  #
86
88
  # * `https://www.googleapis.com/auth/cloud-platform`
89
+ #
87
90
  # @param [Integer] timeout Default timeout to use in requests. Optional.
88
91
  # @param [Hash] client_config A hash of values to override the default
89
92
  # behavior of the API client. Optional.
@@ -113,3 +116,50 @@ module Google
113
116
  end
114
117
  end
115
118
  end
119
+
120
+ # Add error reporting to top-level configuration
121
+ Google::Cloud.configure do |config|
122
+ unless config.field? :use_error_reporting
123
+ config.add_field! :use_error_reporting, nil, enum: [true, false]
124
+ end
125
+ unless config.field? :service_name
126
+ config.add_field! :service_name, nil, match: String
127
+ end
128
+ unless config.field? :service_version
129
+ config.add_field! :service_version, nil, match: String
130
+ end
131
+ end
132
+
133
+ # Set the default error reporting configuration
134
+ Google::Cloud.configure.add_config! :error_reporting do |config|
135
+ default_project = Google::Cloud::Config.deferred do
136
+ ENV["ERROR_REPORTING_PROJECT"]
137
+ end
138
+ default_creds = Google::Cloud::Config.deferred do
139
+ Google::Cloud::Config.credentials_from_env(
140
+ "ERROR_REPORTING_CREDENTIALS", "ERROR_REPORTING_CREDENTIALS_JSON",
141
+ "ERROR_REPORTING_KEYFILE", "ERROR_REPORTING_KEYFILE_JSON"
142
+ )
143
+ end
144
+ default_service = Google::Cloud::Config.deferred do
145
+ ENV["ERROR_REPORTING_SERVICE"]
146
+ end
147
+ default_version = Google::Cloud::Config.deferred do
148
+ ENV["ERROR_REPORTING_VERSION"]
149
+ end
150
+
151
+ config.add_field! :project_id, default_project, match: String, allow_nil: true
152
+ config.add_alias! :project, :project_id
153
+ config.add_field! :credentials, default_creds,
154
+ match: [String, Hash, Google::Auth::Credentials],
155
+ allow_nil: true
156
+ config.add_alias! :keyfile, :credentials
157
+ config.add_field! :scope, nil, match: [String, Array]
158
+ config.add_field! :timeout, nil, match: Integer
159
+ config.add_field! :client_config, nil, match: Hash
160
+ config.add_field! :service_name, default_service,
161
+ match: String, allow_nil: true
162
+ config.add_field! :service_version, default_version,
163
+ match: String, allow_nil: true
164
+ config.add_field! :ignore_classes, nil, match: Array
165
+ end
@@ -17,6 +17,8 @@ require "google-cloud-error_reporting"
17
17
  require "google/cloud/error_reporting/async_error_reporter"
18
18
  require "google/cloud/error_reporting/project"
19
19
  require "google/cloud/error_reporting/middleware"
20
+ require "google/cloud/config"
21
+ require "google/cloud/env"
20
22
  require "stackdriver/core"
21
23
 
22
24
  module Google
@@ -34,12 +36,13 @@ module Google
34
36
  # [Stackdriver Error Reporting
35
37
  # Documentation](https://cloud.google.com/error-reporting/docs/).
36
38
  #
37
- # The goal of google-cloud-ruby is to provide an API that is comfortable to
38
- # Rubyists. Authentication is handled by the client. You can provide the
39
- # project and credential information to connect to the Stackdriver Error
40
- # Reporting service, or if you are running on Google Cloud Platform this
41
- # configuration is taken care of for you. You can read more about the
42
- # options for connecting in the [Authentication
39
+ # The goal of google-cloud is to provide an API that is comfortable to
40
+ # Rubyists. Your authentication credentials are detected automatically in
41
+ # Google Cloud Platform environments such as Google Compute Engine, Google
42
+ # App Engine and Google Kubernetes Engine. In other environments you can
43
+ # configure authentication easily, either directly in your code or via
44
+ # environment variables. Read more about the options for connecting in the
45
+ # [Authentication
43
46
  # Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
44
47
  #
45
48
  # ## How to report errors
@@ -72,12 +75,6 @@ module Google
72
75
  # for more examples.
73
76
  #
74
77
  module ErrorReporting
75
- # Initialize :error_reporting as a nested Configuration under
76
- # Google::Cloud if haven't already
77
- unless Google::Cloud.configure.option? :error_reporting
78
- Google::Cloud.configure.add_options :error_reporting
79
- end
80
-
81
78
  ##
82
79
  # @private The default Google::Cloud::ErrorReporting::Project client used
83
80
  # for the Google::Cloud::ErrorReporting.report API.
@@ -125,10 +122,13 @@ module Google
125
122
  client_config: nil, project: nil, keyfile: nil
126
123
  project_id ||= (project || ErrorReporting::Project.default_project_id)
127
124
  project_id = project_id.to_s
128
- fail ArgumentError, "project_id is missing" if project_id.empty?
125
+ raise ArgumentError, "project_id is missing" if project_id.empty?
126
+
127
+ scope ||= configure.scope
128
+ timeout ||= configure.timeout
129
+ client_config ||= configure.client_config
129
130
 
130
- credentials ||= keyfile
131
- credentials ||= ErrorReporting::Credentials.default(scope: scope)
131
+ credentials ||= (keyfile || default_credentials(scope: scope))
132
132
  unless credentials.is_a? Google::Auth::Credentials
133
133
  credentials = ErrorReporting::Credentials.new credentials,
134
134
  scope: scope
@@ -147,6 +147,27 @@ module Google
147
147
  # client, allows the {.report} public method to reuse these
148
148
  # configured parameters.
149
149
  #
150
+ # The following Stackdriver ErrorReporting configuration parameters are
151
+ # supported:
152
+ #
153
+ # * `project_id` - (String) Google Cloud Platform project identifier for
154
+ # the Stackdriver Error Reporting service you are connecting to. (The
155
+ # parameter `project` is considered deprecated, but may also be used.)
156
+ # * `credentials` - (String, Hash, Google::Auth::Credentials) The path to
157
+ # the keyfile as a String, the contents of the keyfile as a Hash, or a
158
+ # Google::Auth::Credentials object. (See {ErrorReporting::Credentials})
159
+ # (The parameter `keyfile` is considered deprecated, but may also be
160
+ # used.)
161
+ # * `scope` - (String, Array<String>) The OAuth 2.0 scopes controlling
162
+ # the set of resources and operations that the connection can access.
163
+ # * `timeout` - (Integer) Default timeout to use in requests.
164
+ # * `client_config` - (Hash) A hash of values to override the default
165
+ # behavior of the API client.
166
+ # * `service_name` - (String) Name for the application.
167
+ # * `service_version` - (String) Version identifier for the application.
168
+ # * `ignore_classes` - (Array<Exception>) Array of exception types that
169
+ # should not be reported.
170
+ #
150
171
  # See the [Configuration
151
172
  # Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/stackdriver/guides/instrumentation_configuration)
152
173
  # for full configuration parameters.
@@ -157,7 +178,7 @@ module Google
157
178
  #
158
179
  # Google::Cloud::ErrorReporting.configure do |config|
159
180
  # config.project_id = "my-project"
160
- # config.keyfile = "/path/to/keyfile.json"
181
+ # config.credentials = "/path/to/keyfile.json"
161
182
  # config.service_name = "my-service"
162
183
  # config.service_version = "v8"
163
184
  # end
@@ -169,7 +190,7 @@ module Google
169
190
  # Google::Cloud::ErrorReporting.report exception
170
191
  # end
171
192
  #
172
- # @return [Stackdriver::Core::Configuration] The configuration object
193
+ # @return [Google::Cloud::Config] The configuration object
173
194
  # the Google::Cloud::ErrorReporting module uses.
174
195
  #
175
196
  def self.configure
@@ -226,10 +247,8 @@ module Google
226
247
  def self.report exception, service_name: nil, service_version: nil
227
248
  return if Google::Cloud.configure.use_error_reporting == false
228
249
 
229
- service_name ||= configure.service_name ||
230
- Project.default_service_name
231
- service_version ||= configure.service_version ||
232
- Project.default_service_version
250
+ service_name ||= Project.default_service_name
251
+ service_version ||= Project.default_service_version
233
252
 
234
253
  error_event = ErrorEvent.from_exception(exception).tap do |event|
235
254
  event.service_name = service_name
@@ -245,13 +264,11 @@ module Google
245
264
  # @private Create a private client to
246
265
  def self.default_client
247
266
  unless @@default_client
248
- project_id = configure.project_id ||
249
- Google::Cloud.configure.project_id
250
- keyfile = configure.keyfile ||
251
- Google::Cloud.configure.keyfile
267
+ project_id = Project.default_project_id
268
+ credentials = default_credentials
252
269
 
253
270
  @@default_client = AsyncErrorReporter.new(
254
- new(project: project_id, keyfile: keyfile)
271
+ new(project_id: project_id, credentials: credentials)
255
272
  )
256
273
  end
257
274
 
@@ -259,6 +276,16 @@ module Google
259
276
  end
260
277
 
261
278
  private_class_method :default_client
279
+
280
+ ##
281
+ # @private Default credentials.
282
+ def self.default_credentials scope: nil
283
+ Google::Cloud.configure.error_reporting.credentials ||
284
+ Google::Cloud.configure.credentials ||
285
+ ErrorReporting::Credentials.default(scope: scope)
286
+ end
287
+
288
+ private_class_method :default_credentials
262
289
  end
263
290
  end
264
291
  end
@@ -81,7 +81,7 @@ module Google
81
81
  return if error_event.nil?
82
82
  begin
83
83
  error_reporting.report error_event
84
- rescue => e
84
+ rescue StandardError => e
85
85
  warn error_event.message if error_event.message
86
86
  warn ["#{e.class}: #{e.message}", e.backtrace].join("\n\t")
87
87
  @last_exception = e
@@ -38,19 +38,19 @@ module Google
38
38
  # error_reporting.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(ERROR_REPORTING_CREDENTIALS
41
+ SCOPE = ["https://www.googleapis.com/auth/cloud-platform"].freeze
42
+ PATH_ENV_VARS = %w[ERROR_REPORTING_CREDENTIALS
43
43
  GOOGLE_CLOUD_CREDENTIALS
44
44
  ERROR_REPORTING_KEYFILE
45
45
  GOOGLE_CLOUD_KEYFILE
46
- GCLOUD_KEYFILE)
47
- JSON_ENV_VARS = %w(ERROR_REPORTING_CREDENTIALS_JSON
46
+ GCLOUD_KEYFILE].freeze
47
+ JSON_ENV_VARS = %w[ERROR_REPORTING_CREDENTIALS_JSON
48
48
  GOOGLE_CLOUD_CREDENTIALS_JSON
49
49
  ERROR_REPORTING_KEYFILE_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
@@ -54,7 +54,7 @@ module Google
54
54
  error_reporting ||
55
55
  ErrorReporting::AsyncErrorReporter.new(
56
56
  ErrorReporting.new(project: configuration.project_id,
57
- keyfile: configuration.keyfile)
57
+ credentials: configuration.credentials)
58
58
  )
59
59
 
60
60
  # Set module default client to reuse the same client. Update module
@@ -154,16 +154,20 @@ module Google
154
154
  # already.
155
155
  #
156
156
  def load_config **kwargs
157
- configuration.project_id = kwargs[:project_id] ||
158
- configuration.project_id
159
- configuration.keyfile = kwargs[:keyfile] ||
160
- configuration.keyfile
161
- configuration.service_name = kwargs[:service_name] ||
162
- configuration.service_name
163
- configuration.service_version = kwargs[:service_version] ||
164
- configuration.service_version
165
- configuration.ignore_classes = kwargs[:ignore_classes] ||
166
- configuration.ignore_classes
157
+ project_id = kwargs[:project] || kwargs[:project_id]
158
+ configuration.project_id = project_id unless project_id.nil?
159
+
160
+ creds = kwargs[:credentials] || kwargs[:keyfile]
161
+ configuration.credentials = creds unless creds.nil?
162
+
163
+ service_name = kwargs[:service_name]
164
+ configuration.service_name = service_name unless service_name.nil?
165
+
166
+ service_vers = kwargs[:service_version]
167
+ configuration.service_version = service_vers unless service_vers.nil?
168
+
169
+ ignores = kwargs[:ignore_classes]
170
+ configuration.ignore_classes = ignores unless ignores.nil?
167
171
 
168
172
  init_default_config
169
173
  end
@@ -171,13 +175,13 @@ module Google
171
175
  ##
172
176
  # Fallback to default configuration values if not defined already
173
177
  def init_default_config
174
- configuration.project_id ||= \
178
+ configuration.project_id ||= begin
175
179
  (Cloud.configure.project_id ||
176
180
  ErrorReporting::Project.default_project_id)
177
- configuration.keyfile ||= Cloud.configure.keyfile
181
+ end
182
+ configuration.credentials ||= Cloud.configure.credentials
178
183
  configuration.service_name ||=
179
184
  ErrorReporting::Project.default_service_name
180
-
181
185
  configuration.service_version ||=
182
186
  ErrorReporting::Project.default_service_version
183
187
  configuration.ignore_classes = Array(configuration.ignore_classes)
@@ -14,7 +14,6 @@
14
14
 
15
15
 
16
16
  require "google/cloud/errors"
17
- require "google/cloud/env"
18
17
  require "google/cloud/error_reporting/service"
19
18
  require "google/cloud/error_reporting/credentials"
20
19
  require "google/cloud/error_reporting/error_event"
@@ -44,41 +43,42 @@ module Google
44
43
  #
45
44
  class Project
46
45
  ##
47
- # Find default project_id from `ERROR_REPORTING_RPOJECT`,
48
- # `GOOGLE_CLOUD_PROJECT`, `GCLOUD_PROJECT` environment varaibles, or
49
- # query from GCE meta service.
46
+ # Find default project_id from the configuration, environment
47
+ # varaibles, or query from GCE meta service.
50
48
  #
51
49
  # @return [String] default valid GCP project_id
52
50
  #
53
51
  def self.default_project_id
54
- ENV["ERROR_REPORTING_PROJECT"] ||
55
- ENV["GOOGLE_CLOUD_PROJECT"] ||
52
+ Google::Cloud.configure.error_reporting.project_id ||
53
+ Google::Cloud.configure.project_id ||
56
54
  Google::Cloud.env.project_id
57
55
  end
58
56
  class << self
59
- alias_method :default_project, :default_project_id
57
+ alias default_project default_project_id
60
58
  end
61
59
 
62
60
  ##
63
- # Find default service_name from `ERROR_REPORTING_SERVICE`,
64
- # `GAE_SERVICE` environment Variables, or just "ruby".
61
+ # Find default service_name from the configuration, environment
62
+ # varaibles, or query from GCE meta service, or just "ruby".
65
63
  #
66
64
  # @return [String] default GCP service_name
67
65
  #
68
66
  def self.default_service_name
69
- ENV["ERROR_REPORTING_SERVICE"] ||
67
+ Google::Cloud.configure.error_reporting.service_name ||
68
+ Google::Cloud.configure.service_name ||
70
69
  Google::Cloud.env.app_engine_service_id ||
71
70
  "ruby"
72
71
  end
73
72
 
74
73
  ##
75
- # Find default service_version from `ERROR_REPORTING_VERSION` or
76
- # `GAE_VERSION` environment varaibles.
74
+ # Find default service_version from the configuration, environment
75
+ # varaibles, or query from GCE meta service.
77
76
  #
78
77
  # @return [String] default GCP service_version
79
78
  #
80
79
  def self.default_service_version
81
- ENV["ERROR_REPORTING_VERSION"] ||
80
+ Google::Cloud.configure.error_reporting.service_version ||
81
+ Google::Cloud.configure.service_version ||
82
82
  Google::Cloud.env.app_engine_service_version
83
83
  end
84
84
 
@@ -108,7 +108,7 @@ module Google
108
108
  def project_id
109
109
  service.project
110
110
  end
111
- alias_method :project, :project_id
111
+ alias project project_id
112
112
 
113
113
  ##
114
114
  # Report a {Google::Cloud::ErrorReporting::ErrorEvent} to Stackdriver
@@ -90,7 +90,7 @@ module Google
90
90
  # Verify credentials and set use_error_reporting to false if
91
91
  # credentials are invalid
92
92
  unless valid_credentials? ErrorReporting.configure.project_id,
93
- ErrorReporting.configure.keyfile
93
+ ErrorReporting.configure.credentials
94
94
  Cloud.configure.use_error_reporting = false
95
95
  return
96
96
  end
@@ -100,6 +100,8 @@ module Google
100
100
  Google::Cloud.configure.use_error_reporting ||= Rails.env.production?
101
101
  end
102
102
 
103
+ # rubocop:disable all
104
+
103
105
  ##
104
106
  # @private Merge Rails configuration into Error Reporting
105
107
  # instrumentation configuration.
@@ -109,14 +111,22 @@ module Google
109
111
 
110
112
  Cloud.configure.use_error_reporting ||= gcp_config.use_error_reporting
111
113
  ErrorReporting.configure do |config|
112
- config.project_id ||= er_config.project_id || gcp_config.project_id
113
- config.keyfile ||= er_config.keyfile || gcp_config.keyfile
114
- config.service_name ||= er_config.service_name
115
- config.service_version ||= er_config.service_version
114
+ config.project_id ||= config.project
115
+ config.project_id ||= er_config.project_id || er_config.project
116
+ config.project_id ||= gcp_config.project_id || gcp_config.project
117
+ config.credentials ||= config.keyfile
118
+ config.credentials ||= er_config.credentials || er_config.keyfile
119
+ config.credentials ||= gcp_config.credentials || gcp_config.keyfile
120
+ config.service_name ||= \
121
+ (er_config.service_name || gcp_config.service_name)
122
+ config.service_version ||= \
123
+ (er_config.service_version || gcp_config.service_version)
116
124
  config.ignore_classes ||= er_config.ignore_classes
117
125
  end
118
126
  end
119
127
 
128
+ # rubocop:enable all
129
+
120
130
  ##
121
131
  # Fallback to default config values if config parameters not provided.
122
132
  def self.init_default_config
@@ -138,7 +148,7 @@ module Google
138
148
  # if credentials is not a Credentials object, create one
139
149
  ErrorReporting::Credentials.new credentials
140
150
  end
141
- rescue => e
151
+ rescue StandardError => e
142
152
  STDOUT.puts "Note: Google::Cloud::ErrorReporting is disabled " \
143
153
  "because it failed to authorize with the service. (#{e.message})"
144
154
  return false
@@ -71,7 +71,7 @@ module Google
71
71
  #
72
72
  def report error_event
73
73
  if error_event.message.nil? || error_event.message.empty?
74
- fail ArgumentError, "Cannot report empty message"
74
+ raise ArgumentError, "Cannot report empty message"
75
75
  end
76
76
 
77
77
  error_event_grpc = error_event.to_grpc
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module ErrorReporting
19
- VERSION = "0.29.0".freeze
19
+ VERSION = "0.30.0".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.29.0
4
+ version: 0.30.0
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-12-19 00:00:00.000000000 Z
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.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.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.2'
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.2'
40
+ version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: google-gax
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -112,16 +112,16 @@ dependencies:
112
112
  name: rubocop
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "<="
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 0.35.1
117
+ version: 0.50.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - "<="
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 0.35.1
124
+ version: 0.50.0
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: railties
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -253,7 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
253
253
  version: '0'
254
254
  requirements: []
255
255
  rubyforge_project:
256
- rubygems_version: 2.7.3
256
+ rubygems_version: 2.7.6
257
257
  signing_key:
258
258
  specification_version: 4
259
259
  summary: API Client library for Stackdriver Error Reporting