google-cloud-error_reporting 0.27.0 → 0.28.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
- SHA1:
3
- metadata.gz: 3b8ac0c9f4b208544f69fc27cab36f0746148b8a
4
- data.tar.gz: 8445acf96064da8d26b0d37d6140d7a687cdcaa7
2
+ SHA256:
3
+ metadata.gz: 5ce7d566383abf96959435e8f9a50a02a5572c57a40b5a12b6dafe2374b0df0b
4
+ data.tar.gz: 32bc529ffd05720f2a560536d44ef1dc98295f7aa0b82e155071de9b9f62fd96
5
5
  SHA512:
6
- metadata.gz: 4d150f67b1a2255a1c2c7f6df9437b37c9ccb2d9447b43e6d020ab60440a5d69cff47174ecd5eb5b6538638c63e10ba0fae4e4925b34f46ab7568ed32abd0575
7
- data.tar.gz: 6c3ca9dc7421944c1d2ccee71d2bfaae86c20f26b50452b8ade4886b0bb05fb5ff27f9690bb93676e9a56325e8d005bd021ca725b59c74d1e4749d27d06645ac
6
+ metadata.gz: aecb1e6162d607ae4406bbfe832b82e83ec3ecf11a470f73fbe05babc38b75307aecae6a677ebc864328854c343196231c216180d2efde256d9343d9f2cf4a74
7
+ data.tar.gz: bedc1b1736c010cacd97782bc2b2dc47134087735367ae8f28eb62c460dc7f611425e4f9b6d364a49069ca2525b919b9b317ece027885d7ccca30e8730dc78cf
data/README.md CHANGED
@@ -13,63 +13,170 @@ new errors.
13
13
  - [google-cloud-error_reporting on RubyGems](https://rubygems.org/gems/google-cloud-error_reporting)
14
14
  - [Stackdriver ErrorReporting documentation](https://cloud.google.com/error-reporting/docs/)
15
15
 
16
- google-cloud-error_reporting provides an instrumentation API that makes it easy
17
- to report exceptions to the Stackdriver Error Reporting service. It also
18
- contains a full API client library for the
19
- [Stackdriver Error Reporting API](https://developers.google.com/apis-explorer/#p/clouderrorreporting/v1beta1/)
20
- (v1beta1).
21
-
22
16
  ## Quick Start
17
+
18
+ Install the gem directly:
19
+
23
20
  ```sh
24
21
  $ gem install google-cloud-error_reporting
25
22
  ```
26
23
 
27
- ## Authentication
24
+ Or install through Bundler:
28
25
 
29
- The Instrumentation client and API use Service Account credentials to connect
30
- to Google Cloud services. When running on Google Cloud Platform environments,
31
- the credentials will be discovered automatically. When running on other
32
- environments the Service Account credentials can be specified by providing the
33
- path to the JSON file, or the JSON itself, in environment variables or
34
- configuration code.
26
+ 1. Add the `google-cloud-error_reporting` gem to your Gemfile:
27
+
28
+ ```ruby
29
+ gem "google-cloud-error_reporting"
30
+ ```
31
+
32
+ 2. Use Bundler to install the gem:
33
+
34
+ ```sh
35
+ $ bundle install
36
+ ```
37
+
38
+ Alternatively, check out the [`stackdriver`](../stackdriver) gem that includes
39
+ the `google-cloud-error_reporting` gem.
40
+
41
+ ## Enable Stackdriver Error Reporting API
42
+
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
46
+ already.
35
47
 
36
- Instructions and configuration options are covered in the
37
- [Authentication Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-error_reporting/guides/authentication).
48
+ ## Reporting errors in Rack-based frameworks
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
53
+ automatically reports exceptions captured from the application's Rack stack.
54
+
55
+ ### With Ruby on Rails
56
+
57
+ You can load the Railtie that comes with the library into your Ruby
58
+ on Rails application by explicitly requiring it during the application startup:
59
+
60
+ ```ruby
61
+ # In config/application.rb
62
+ require "google/cloud/error_reporting/rails"
63
+ ```
64
+
65
+ If you're using the `stackdriver` gem, it automatically loads the Railtie into
66
+ your application when it starts.
67
+
68
+ ### With other Rack-based frameworks
69
+
70
+ Other Rack-based frameworks, such as Sinatra, can use the Rack Middleware
71
+ provided by the library:
38
72
 
39
- ## Instrumentation Example
40
73
  ```ruby
41
74
  require "google/cloud/error_reporting"
42
-
43
- # Configure Stackdriver ErrorReporting instrumentation
44
- Google::Cloud::ErrorReporting.configure do |config|
45
- config.project_id = "my-project"
46
- config.keyfile = "/path/to/keyfile.json"
47
- end
48
-
49
- # Insert a Rack Middleware to report unhanded exceptions
50
75
  use Google::Cloud::ErrorReporting::Middleware
51
-
52
- # Or explicitly submit exceptions
76
+ ```
77
+
78
+ ## Reporting errors manually
79
+
80
+ Manually reporting an error is as easy as calling the report method:
81
+
82
+ ```ruby
83
+ require "google/cloud/error_reporting"
53
84
  begin
54
- fail "Boom!"
85
+ fail "boom!"
55
86
  rescue => exception
56
87
  Google::Cloud::ErrorReporting.report exception
57
88
  end
58
89
  ```
59
90
 
60
- ## Rails and Rack Integration
91
+ ## Configuring the library
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
95
+ of possible configuration options.
96
+
97
+ ## Running on Google Cloud Platform
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
102
+ enabled on that instance.
103
+
104
+ ### App Engine
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
108
+ be used without providing credentials or a project ID.
109
+
110
+ ### Container Engine
111
+
112
+ On Google Container Engine, you must explicitly add the `cloud-platform` OAuth
113
+ scope when creating the cluster:
114
+
115
+ ```sh
116
+ $ gcloud container clusters create example-cluster-name --scopes https://www.googleapis.com/auth/cloud-platform
117
+ ```
118
+
119
+ You may also do this through the Google Cloud Platform Console. Select
120
+ **Enabled** in the **Cloud Platform** section of **Create a container cluster**.
121
+
122
+ ### Compute Engine
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
128
+ full access to all Cloud APIs" under Access scopes.
129
+
130
+ ## Running locally and elsewhere
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
137
+ section](#authentication) for instructions on how to do so.
138
+
139
+ ## Authentication
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
145
+ several ways.
146
+
147
+ The best way to provide authentication information if you're using Ruby on Rails
148
+ is through the Rails configuration interface:
61
149
 
62
- This library also provides a built-in Railtie for Ruby on Rails integration. To
63
- do this, simply add this line to config/application.rb:
64
150
  ```ruby
65
- require "google/cloud/error_reporting/rails"
151
+ # in config/environments/*.rb
152
+ Rails.application.configure do |config|
153
+ # Shared parameters
154
+ config.google_cloud.project_id = "your-project-id"
155
+ config.google_cloud.keyfile = "/path/to/key.json"
156
+ # Or Stackdriver Error Reporting specific parameters
157
+ config.google_cloud.error_reporting.project_id = "your-project-id"
158
+ config.google_cloud.error_reporting.keyfile = "/path/to/key.json"
159
+ end
66
160
  ```
67
161
 
68
- Alternatively, check out the [stackdriver](../stackdriver) gem, which includes
69
- this library and enables the Railtie by default.
162
+ Other Rack-based applications that are loading the Rack Middleware directly or
163
+ using the manually reporting interface can leverage the configration interface:
164
+
165
+ ```ruby
166
+ require "google/cloud/error_reporting"
167
+ Google::Cloud.configure do |config|
168
+ # Shared parameters
169
+ config.project_id = "your-project-id"
170
+ config.keyfile = "/path/to/key.json"
171
+ # Or Stackdriver Error Reporting specific parameters
172
+ config.error_reporting.project_id = "your-project-id"
173
+ config.error_reporting.keyfile = "/path/to/key.json"
174
+ end
175
+ ```
70
176
 
71
- For Rack integration and more examples, see the
72
- [Instrumentation Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-error_reporting/guides/instrumentation).
177
+ This library also supports the other authentication methods provided by the
178
+ `google-cloud-ruby` suite. Instructions and configuration options are covered
179
+ in the [Authentication Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-debugger/guides/authentication).
73
180
 
74
181
  ## Supported Ruby Versions
75
182
 
@@ -70,11 +70,12 @@ module Google
70
70
  # For more information on connecting to Google Cloud see the [Authentication
71
71
  # Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication)
72
72
  #
73
- # @param [String] project Google Cloud Platform project identifier for the
74
- # Stackdriver Error Reporting service you are connecting to. Use
75
- # Project.default_project if not provided.
76
- # @param [String, Hash] keyfile Keyfile downloaded from Google Cloud. If
77
- # file path the file must be readable.
73
+ # @param [String] project_id Google Cloud Platform project identifier for
74
+ # the Stackdriver Error Reporting service you are connecting to. If not
75
+ # present, the default project for the credentials is used.
76
+ # @param [String, Hash, Google::Auth::Credentials] credentials The path to
77
+ # the keyfile as a String, the contents of the keyfile as a Hash, or a
78
+ # Google::Auth::Credentials object. (See {ErrorReporting::Credentials})
78
79
  # @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the
79
80
  # set of resources and operations that the connection can access. See
80
81
  # [Using OAuth 2.0 to Access Google
@@ -102,10 +103,11 @@ module Google
102
103
  # service_version: "v8"
103
104
  # error_reporting.report error_event
104
105
  #
105
- def self.error_reporting project = nil, keyfile = nil, scope: nil,
106
+ def self.error_reporting project_id = nil, credentials = nil, scope: nil,
106
107
  timeout: nil, client_config: nil
107
108
  require "google/cloud/error_reporting"
108
- Google::Cloud::ErrorReporting.new project: project, keyfile: keyfile,
109
+ Google::Cloud::ErrorReporting.new project_id: project_id,
110
+ credentials: credentials,
109
111
  scope: scope, timeout: timeout,
110
112
  client_config: client_config
111
113
  end
@@ -91,10 +91,12 @@ module Google
91
91
  # [Authentication
92
92
  # Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
93
93
  #
94
- # @param [String] project Project identifier for the Stackdriver Error
95
- # Reporting service.
96
- # @param [String, Hash] keyfile Keyfile downloaded from Google Cloud. If
97
- # file path the file must be readable.
94
+ # @param [String] project_id Google Cloud Platform project identifier for
95
+ # the Stackdriver Error Reporting service you are connecting to. If not
96
+ # present, the default project for the credentials is used.
97
+ # @param [String, Hash, Google::Auth::Credentials] credentials The path to
98
+ # the keyfile as a String, the contents of the keyfile as a Hash, or a
99
+ # Google::Auth::Credentials object. (See {ErrorReporting::Credentials})
98
100
  # @param [String, Array<String>] scope The OAuth 2.0 scopes controlling
99
101
  # the set of resources and operations that the connection can access.
100
102
  # See [Using OAuth 2.0 to Access Google
@@ -107,6 +109,9 @@ module Google
107
109
  # @param [Integer] timeout Default timeout to use in requests. Optional.
108
110
  # @param [Hash] client_config A hash of values to override the default
109
111
  # behavior of the API client. Optional.
112
+ # @param [String] project Alias for the `project_id` argument. Deprecated.
113
+ # @param [String] keyfile Alias for the `credentials` argument.
114
+ # Deprecated.
110
115
  #
111
116
  # @return [Google::Cloud::ErrorReporting::Project]
112
117
  #
@@ -116,19 +121,23 @@ module Google
116
121
  # error_reporting = Google::Cloud::ErrorReporting.new
117
122
  # # ...
118
123
  #
119
- def self.new project: nil, keyfile: nil, scope: nil, timeout: nil,
120
- client_config: nil
121
- project ||= Google::Cloud::ErrorReporting::Project.default_project
122
- project = project.to_s
123
- fail ArgumentError, "project is missing" if project.empty?
124
+ def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil,
125
+ client_config: nil, project: nil, keyfile: nil
126
+ project_id ||= (project || ErrorReporting::Project.default_project_id)
127
+ project_id = project_id.to_s
128
+ fail ArgumentError, "project_id is missing" if project_id.empty?
124
129
 
125
- credentials =
126
- Google::Cloud::ErrorReporting::Credentials.credentials_with_scope(
127
- keyfile, scope)
130
+ credentials ||= keyfile
131
+ credentials ||= ErrorReporting::Credentials.default(scope: scope)
132
+ unless credentials.is_a? Google::Auth::Credentials
133
+ credentials = ErrorReporting::Credentials.new credentials,
134
+ scope: scope
135
+ end
128
136
 
129
- Google::Cloud::ErrorReporting::Project.new(
130
- Google::Cloud::ErrorReporting::Service.new(
131
- project, credentials, timeout: timeout, client_config: client_config
137
+ ErrorReporting::Project.new(
138
+ ErrorReporting::Service.new(
139
+ project_id, credentials, timeout: timeout,
140
+ client_config: client_config
132
141
  )
133
142
  )
134
143
  end
@@ -147,7 +156,7 @@ module Google
147
156
  # require "google/cloud/error_reporting"
148
157
  #
149
158
  # Google::Cloud::ErrorReporting.configure do |config|
150
- # config.project_id = "my-project-id"
159
+ # config.project_id = "my-project"
151
160
  # config.keyfile = "/path/to/keyfile.json"
152
161
  # config.service_name = "my-service"
153
162
  # config.service_version = "v8"
@@ -13,28 +13,44 @@
13
13
  # limitations under the License.
14
14
 
15
15
 
16
- require "google/cloud/credentials"
16
+ require "googleauth"
17
17
 
18
18
  module Google
19
19
  module Cloud
20
20
  module ErrorReporting
21
21
  ##
22
- # @private Represents the OAuth 2.0 signing logic for ErrorReporting.
23
- class Credentials < Google::Cloud::Credentials
22
+ # # Credentials
23
+ #
24
+ # Represents the authentication and authorization used to connect to the
25
+ # Stackdriver Error Reporting service.
26
+ #
27
+ # @example
28
+ # require "google/cloud/error_reporting"
29
+ #
30
+ # keyfile = "/path/to/keyfile.json"
31
+ # creds = Google::Cloud::ErrorReporting::Credentials.new keyfile
32
+ #
33
+ # error_reporting = Google::Cloud::ErrorReporting.new(
34
+ # project_id: "my-project",
35
+ # credentials: creds
36
+ # )
37
+ #
38
+ # error_reporting.project_id #=> "my-project"
39
+ #
40
+ class Credentials < Google::Auth::Credentials
24
41
  SCOPE = ["https://www.googleapis.com/auth/cloud-platform"]
25
- PATH_ENV_VARS = %w(ERROR_REPORTING_KEYFILE GOOGLE_CLOUD_KEYFILE)
26
- JSON_ENV_VARS =
27
- %w(ERROR_REPORTING_KEYFILE_JSON GOOGLE_CLOUD_KEYFILE_JSON)
28
-
29
- ##
30
- # @private Create credentials with given scope and/or keyfile.
31
- def self.credentials_with_scope keyfile, scope = nil
32
- if keyfile.nil?
33
- default(scope: scope)
34
- else
35
- new(keyfile, scope: scope)
36
- end
37
- end
42
+ PATH_ENV_VARS = %w(ERROR_REPORTING_CREDENTIALS
43
+ GOOGLE_CLOUD_CREDENTIALS
44
+ ERROR_REPORTING_KEYFILE
45
+ GOOGLE_CLOUD_KEYFILE
46
+ GCLOUD_KEYFILE)
47
+ JSON_ENV_VARS = %w(ERROR_REPORTING_CREDENTIALS_JSON
48
+ GOOGLE_CLOUD_CREDENTIALS_JSON
49
+ ERROR_REPORTING_KEYFILE_JSON
50
+ GOOGLE_CLOUD_KEYFILE_JSON
51
+ GCLOUD_KEYFILE_JSON)
52
+ DEFAULT_PATHS = \
53
+ ["~/.config/gcloud/application_default_credentials.json"]
38
54
  end
39
55
  end
40
56
  end
@@ -171,8 +171,9 @@ module Google
171
171
  ##
172
172
  # Fallback to default configuration values if not defined already
173
173
  def init_default_config
174
- configuration.project_id ||= Cloud.configure.project_id ||
175
- ErrorReporting::Project.default_project
174
+ configuration.project_id ||= \
175
+ (Cloud.configure.project_id ||
176
+ ErrorReporting::Project.default_project_id)
176
177
  configuration.keyfile ||= Cloud.configure.keyfile
177
178
  configuration.service_name ||=
178
179
  ErrorReporting::Project.default_service_name
@@ -50,11 +50,14 @@ module Google
50
50
  #
51
51
  # @return [String] default valid GCP project_id
52
52
  #
53
- def self.default_project
53
+ def self.default_project_id
54
54
  ENV["ERROR_REPORTING_PROJECT"] ||
55
55
  ENV["GOOGLE_CLOUD_PROJECT"] ||
56
56
  Google::Cloud.env.project_id
57
57
  end
58
+ class << self
59
+ alias_method :default_project, :default_project_id
60
+ end
58
61
 
59
62
  ##
60
63
  # Find default service_name from `ERROR_REPORTING_SERVICE`,
@@ -102,9 +105,10 @@ module Google
102
105
  #
103
106
  # @return [String] The current project_id
104
107
  #
105
- def project
108
+ def project_id
106
109
  service.project
107
110
  end
111
+ alias_method :project, :project_id
108
112
 
109
113
  ##
110
114
  # Report a {Google::Cloud::ErrorReporting::ErrorEvent} to Stackdriver
@@ -121,7 +121,7 @@ module Google
121
121
  # Fallback to default config values if config parameters not provided.
122
122
  def self.init_default_config
123
123
  config = ErrorReporting.configure
124
- config.project_id ||= ErrorReporting::Project.default_project
124
+ config.project_id ||= ErrorReporting::Project.default_project_id
125
125
  config.service_name ||= ErrorReporting::Project.default_service_name
126
126
  config.service_version ||=
127
127
  ErrorReporting::Project.default_service_version
@@ -129,9 +129,15 @@ module Google
129
129
 
130
130
  ##
131
131
  # @private Verify credentials
132
- def self.valid_credentials? project_id, keyfile
132
+ def self.valid_credentials? project_id, credentials
133
133
  begin
134
- ErrorReporting::Credentials.credentials_with_scope keyfile
134
+ # if credentials is nil, get default
135
+ credentials ||= ErrorReporting::Credentials.default(scope: scope)
136
+ # only create a new Credentials object if the val isn't one already
137
+ unless credentials.is_a? Google::Auth::Credentials
138
+ # if credentials is not a Credentials object, create one
139
+ ErrorReporting::Credentials.new credentials, scope: scope
140
+ end
135
141
  rescue => e
136
142
  STDOUT.puts "Note: Google::Cloud::ErrorReporting is disabled " \
137
143
  "because it failed to authorize with the service. (#{e.message})"