gruf-rollbar 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 48ee4ba3cf754c3bf4dce75434d43a4b69b2896e1e2c4ec3bde8f3e87e4cd8d5
4
+ data.tar.gz: 01a3c1a6fd02d3ed73d568ea950386cbab2b65ef81d7fd6c3f1a5d2b1fe68ae8
5
+ SHA512:
6
+ metadata.gz: 8592f18d2acb307e752000e3fd1957fcaa8f08d706939c34c477a96b7a6618d76ed828892f29510fff8861fae85d9062d40bfc2d574498acea3f05d6fda8735d
7
+ data.tar.gz: f9171a43316226457726857bc9f30fc02a91862ab1fef2704b3e09d8fb1cf5cd388b62d45b9d2e6c8f8bf1eabede8e86400ce957878fadbe2a212dae19c2a8f9
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+
5
+ - [PLAT-816] Fix github action
6
+
7
+ ## 0.0.1
8
+
9
+ - [PLAT-787] Gruf rollbar reporting
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # gruf-rollbar - Rollbar reporting for gruf
2
+
3
+ Adds Rollbar error reporting support for [gruf](https://github.com/bigcommerce/gruf) 2.7.0+
4
+ and [sentry-ruby](https://github.com/rollbar/rollbar-gem)
5
+
6
+ This gem will automatically report grpc failures and Gruf errors into Rollbar as they happen in servers and clients.
7
+
8
+ ## Installation
9
+
10
+ Simply install the gem:
11
+
12
+ ```ruby
13
+ gem 'gruf-rollbar'
14
+ ```
15
+
16
+ Then after, in your gruf initializer:
17
+
18
+ ```ruby
19
+ Gruf.configure do |c|
20
+ c.interceptors.use(Gruf::Rollbar::ServerInterceptor)
21
+ end
22
+ ```
23
+
24
+ It comes with a few more options as well:
25
+
26
+ | Option | Description | Default | ENV Key |
27
+ | ------------------ | ---------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- |
28
+ | ignore_methods | A list of method names to ignore from logging. E.g. `['namespace.health.check']` | `[]` | GRUF_ROLLBAR_IGNORE_METHODS |
29
+ | grpc_error_classes | A list of gRPC error classes that will be used for detecting errors (as opposed to validation) | `GRPC::Unknown,GRPC::Internal,GRPC::DataLoss,GRPC::FailedPrecondition,GRPC::Unavailable,GRPC::DeadlineExceeded,GRPC::Cancelled` | GRUF_ROLLBAR_GRPC_ERROR_CLASSES |
30
+ | default_error_code | The default gRPC error code to use (int value) | `GRPC::Core::StatusCodes::INTERNAL` | `GRUF_ROLLBAR_DEFAULT_ERROR_CODE` |
31
+
32
+ ### Client Interceptors
33
+
34
+ To automatically report errors in your Gruf clients, pass the client interceptor to your `Gruf::Client` initializer:
35
+
36
+ ```ruby
37
+ Gruf::Client.new(
38
+ service: MyService,
39
+ client_options: {
40
+ interceptors: [Gruf::Rollbar::ClientInterceptor.new]
41
+ }
42
+ )
43
+ ```
44
+
45
+ This gem is inspired by https://github.com/bigcommerce/gruf-sentry.
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'gruf/rollbar/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'gruf-rollbar'
9
+ spec.version = Gruf::Rollbar::VERSION
10
+ spec.authors = ['SeaLink']
11
+ spec.email = ['john.zhao@kelsian.com']
12
+ spec.license = 'MIT'
13
+
14
+ spec.summary = %q{Automatically report gruf failures as rollbar errors}
15
+ spec.description = spec.summary
16
+ spec.homepage = 'https://github.com/sealink/gruf-rollbar'
17
+
18
+ spec.required_ruby_version = '>= 2.7'
19
+
20
+ spec.files = Dir['README.md', 'CHANGELOG.md', 'CODE_OF_CONDUCT.md', 'lib/**/*', 'gruf-rollbar.gemspec']
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency 'bundler-audit', '>= 0.6'
24
+ spec.add_development_dependency 'rake', '>= 12.3'
25
+ spec.add_development_dependency 'rubocop', '>= 1.27'
26
+ spec.add_development_dependency 'pry', '>= 0.14'
27
+ spec.add_development_dependency 'rspec', '>= 3.8'
28
+ spec.add_development_dependency 'rspec_junit_formatter', '~> 0.4'
29
+ spec.add_development_dependency 'simplecov', '>= 0.16'
30
+
31
+ spec.add_runtime_dependency 'gruf', '~> 2.5', '>= 2.5.1'
32
+ spec.add_runtime_dependency 'rollbar'
33
+ spec.add_runtime_dependency 'zeitwerk', '~> 2'
34
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gruf
4
+ module Rollbar
5
+ ##
6
+ # Intercepts outbound calls to provide Rollbar reporting
7
+ #
8
+ class ClientInterceptor < Gruf::Interceptors::ClientInterceptor
9
+ include Gruf::Rollbar::ErrorParser
10
+
11
+ ##
12
+ # @param [Gruf::Outbound::RequestContext]
13
+ #
14
+ def call(request_context:)
15
+ return yield if Gruf::Rollbar.ignore_methods.include?(request_context.method_name)
16
+
17
+ begin
18
+ yield
19
+ rescue StandardError, GRPC::BadStatus => e
20
+ if error?(e) # only capture
21
+ ::Rollbar.scoped({
22
+ grpc_method_name: request_context.method_name,
23
+ grpc_route_key: request_context.route_key,
24
+ grpc_call_type: request_context.type,
25
+ grpc_error_code: code_for(e),
26
+ grpc_error_class: e.class.name
27
+ }) do
28
+ ::Rollbar.error(e)
29
+ end
30
+ end
31
+ raise # passthrough
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gruf
4
+ module Rollbar
5
+ ##
6
+ # Configuration module for gruf-rollbar
7
+ #
8
+ module Configuration
9
+ VALID_CONFIG_KEYS = {
10
+ grpc_error_classes: ::ENV.fetch(
11
+ 'GRUF_ROLLBAR_GRPC_ERROR_CLASSES',
12
+ 'GRPC::Unknown,GRPC::Internal,GRPC::DataLoss,GRPC::FailedPrecondition,GRPC::Unavailable,GRPC::DeadlineExceeded,GRPC::Cancelled'
13
+ ).to_s.split(',').map(&:strip),
14
+ default_error_code: ::ENV.fetch('GRUF_ROLLBAR_DEFAULT_ERROR_CODE', GRPC::Core::StatusCodes::INTERNAL).to_i,
15
+ ignore_methods: ::ENV.fetch('GRUF_ROLLBAR_IGNORE_METHODS', '').split(',').map(&:strip) || []
16
+ }.freeze
17
+
18
+ attr_accessor *VALID_CONFIG_KEYS.keys
19
+
20
+ ##
21
+ # Whenever this is extended into a class, setup the defaults
22
+ #
23
+ def self.extended(base)
24
+ base.reset
25
+ end
26
+
27
+ ##
28
+ # Yield self for ruby-style initialization
29
+ #
30
+ # @yields [Gruf::Rollbar::Configuration]
31
+ # @return [Gruf::Rollbar::Configuration]
32
+ #
33
+ def configure
34
+ yield self
35
+ end
36
+
37
+ ##
38
+ # Return the current configuration options as a Hash
39
+ #
40
+ # @return [Hash]
41
+ #
42
+ def options
43
+ opts = {}
44
+ VALID_CONFIG_KEYS.each_key do |k|
45
+ opts.merge!(k => send(k))
46
+ end
47
+ opts
48
+ end
49
+
50
+ ##
51
+ # Set the default configuration onto the extended class
52
+ #
53
+ # @return [Hash] options The reset options hash
54
+ #
55
+ def reset
56
+ VALID_CONFIG_KEYS.each do |k, v|
57
+ send("#{k}=".to_sym, v)
58
+ end
59
+
60
+ options
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gruf
4
+ module Rollbar
5
+ ##
6
+ # Mixin for error parsing
7
+ #
8
+ module ErrorParser
9
+ ##
10
+ # @param [StandardError]
11
+ # @return [Number] that maps to one of the GRPC::Core::StatusCodes or Gruf::Rollbar.default_error_code
12
+ #
13
+ def code_for(error)
14
+ error.respond_to?(:code) ? error.code : Gruf::Rollbar.default_error_code
15
+ end
16
+
17
+ ##
18
+ # @return [Boolean]
19
+ #
20
+ def error?(exception)
21
+ error_classes.include?(exception.class.to_s)
22
+ end
23
+
24
+ ##
25
+ # @return [Array]
26
+ #
27
+ def error_classes
28
+ @options.fetch(:error_classes, Gruf::Rollbar.grpc_error_classes)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gruf
4
+ module Rollbar
5
+ ##
6
+ # Intercepts inbound calls to provide Rollbar error reporting
7
+ #
8
+ class ServerInterceptor < Gruf::Interceptors::ServerInterceptor
9
+ include Gruf::Rollbar::ErrorParser
10
+
11
+ ##
12
+ # Handle the gruf around hook and capture errors
13
+ #
14
+ def call(&_block)
15
+ return yield if Gruf::Rollbar.ignore_methods.include?(request.method_name)
16
+
17
+ begin
18
+ yield
19
+ rescue StandardError, GRPC::BadStatus => e
20
+ if error?(e) # only capture
21
+ ::Rollbar.scoped({
22
+ grpc_method: request.method_key,
23
+ grpc_request_class: request.request_class.name,
24
+ grpc_service_key: request.service_key,
25
+ grpc_error_code: code_for(e),
26
+ grpc_error_class: e.class.name
27
+ }) do
28
+ ::Rollbar.error(e)
29
+ end
30
+ end
31
+ raise # passthrough
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ ##
38
+ # @return [Hash]
39
+ #
40
+ def request_message_params
41
+ return {} if request.client_streamer? || !request.message.respond_to?(:to_h)
42
+
43
+ request.message.to_h
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gruf
4
+ module Rollbar
5
+ VERSION = '0.0.1'
6
+ end
7
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'gruf'
4
+ require 'rollbar'
5
+
6
+ # use Zeitwerk to lazily autoload all the files in the lib directory
7
+ require 'zeitwerk'
8
+ root_path = File.dirname(__dir__)
9
+ loader = ::Zeitwerk::Loader.new
10
+ loader.tag = File.basename(__FILE__, '.rb')
11
+ loader.inflector = ::Zeitwerk::GemInflector.new(__FILE__)
12
+ loader.ignore(File.join(root_path, 'gruf-rollbar.rb'))
13
+ loader.push_dir(root_path)
14
+ loader.setup
15
+
16
+ module Gruf
17
+ module Rollbar
18
+ extend Gruf::Rollbar::Configuration
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'gruf/rollbar'
metadata ADDED
@@ -0,0 +1,199 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gruf-rollbar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - SeaLink
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-10-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler-audit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '12.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '12.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '1.27'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '1.27'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '3.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '3.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec_junit_formatter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.4'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0.16'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0.16'
111
+ - !ruby/object:Gem::Dependency
112
+ name: gruf
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.5'
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: 2.5.1
121
+ type: :runtime
122
+ prerelease: false
123
+ version_requirements: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - "~>"
126
+ - !ruby/object:Gem::Version
127
+ version: '2.5'
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: 2.5.1
131
+ - !ruby/object:Gem::Dependency
132
+ name: rollbar
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ type: :runtime
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ - !ruby/object:Gem::Dependency
146
+ name: zeitwerk
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: '2'
152
+ type: :runtime
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: '2'
159
+ description: Automatically report gruf failures as rollbar errors
160
+ email:
161
+ - john.zhao@kelsian.com
162
+ executables: []
163
+ extensions: []
164
+ extra_rdoc_files: []
165
+ files:
166
+ - CHANGELOG.md
167
+ - README.md
168
+ - gruf-rollbar.gemspec
169
+ - lib/gruf-rollbar.rb
170
+ - lib/gruf/rollbar.rb
171
+ - lib/gruf/rollbar/client_interceptor.rb
172
+ - lib/gruf/rollbar/configuration.rb
173
+ - lib/gruf/rollbar/error_parser.rb
174
+ - lib/gruf/rollbar/server_interceptor.rb
175
+ - lib/gruf/rollbar/version.rb
176
+ homepage: https://github.com/sealink/gruf-rollbar
177
+ licenses:
178
+ - MIT
179
+ metadata: {}
180
+ post_install_message:
181
+ rdoc_options: []
182
+ require_paths:
183
+ - lib
184
+ required_ruby_version: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ version: '2.7'
189
+ required_rubygems_version: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ requirements: []
195
+ rubygems_version: 3.3.7
196
+ signing_key:
197
+ specification_version: 4
198
+ summary: Automatically report gruf failures as rollbar errors
199
+ test_files: []