gruf-sentry 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +7 -0
- data/CODE_OF_CONDUCT.md +46 -0
- data/README.md +57 -0
- data/gruf-sentry.gemspec +50 -0
- data/lib/gruf/sentry.rb +36 -0
- data/lib/gruf/sentry/client_interceptor.rb +53 -0
- data/lib/gruf/sentry/configuration.rb +79 -0
- data/lib/gruf/sentry/error_parser.rb +47 -0
- data/lib/gruf/sentry/server_interceptor.rb +64 -0
- data/lib/gruf/sentry/version.rb +22 -0
- metadata +213 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3096afc353c0bbea66eb299bfb4d4154873499f9490dd52126a09b7fd1b9d7a5
|
4
|
+
data.tar.gz: ab6e2983fa862209974163387651b1feb0194623d9d931541b0f9fec7c02a8e7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 73a51eddc891abd338cf39384fbe088d3fba6e090bcd14dc6ae4d154cd16186c08026787e67393ab4f0690da17920755465de196206a52adc65c711f58f25fcc
|
7
|
+
data.tar.gz: f3331751706b29c69469442ed7a760d26102239eab26a3c01fed03cc0a46ab80f6b51f12a002b8072d6593cf11444c6508efc952dbaf3d6f4d5ad47f9c536848
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
## Our Standards
|
8
|
+
|
9
|
+
Examples of behavior that contributes to creating a positive environment include:
|
10
|
+
|
11
|
+
* Using welcoming and inclusive language
|
12
|
+
* Being respectful of differing viewpoints and experiences
|
13
|
+
* Gracefully accepting constructive criticism
|
14
|
+
* Focusing on what is best for the community
|
15
|
+
* Showing empathy towards other community members
|
16
|
+
|
17
|
+
Examples of unacceptable behavior by participants include:
|
18
|
+
|
19
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
20
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
21
|
+
* Public or private harassment
|
22
|
+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
23
|
+
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
24
|
+
|
25
|
+
## Our Responsibilities
|
26
|
+
|
27
|
+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
28
|
+
|
29
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
30
|
+
|
31
|
+
## Scope
|
32
|
+
|
33
|
+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
34
|
+
|
35
|
+
## Enforcement
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at engineering@bigcommerce.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
38
|
+
|
39
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
40
|
+
|
41
|
+
## Attribution
|
42
|
+
|
43
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
44
|
+
|
45
|
+
[homepage]: http://contributor-covenant.org
|
46
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# gruf-sentry - Sentry reporting for gruf
|
2
|
+
|
3
|
+
[![CircleCI](https://circleci.com/gh/bigcommerce/gruf-sentry/tree/master.svg?style=svg)](https://circleci.com/gh/bigcommerce/gruf-sentry/tree/master) [![Gem Version](https://badge.fury.io/rb/gruf-sentry.svg)](https://badge.fury.io/rb/gruf-sentry) [![Inline docs](http://inch-ci.org/github/bigcommerce/gruf-sentry.svg?branch=master)](http://inch-ci.org/github/bigcommerce/gruf-sentry)
|
4
|
+
|
5
|
+
Adds Sentry error reporting support for [gruf](https://github.com/bigcommerce/gruf) 2.7.0+.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Simply install the gem:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'gruf-sentry'
|
13
|
+
```
|
14
|
+
|
15
|
+
Then after, in your gruf initializer:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
Gruf.configure do |c|
|
19
|
+
c.interceptors.use(Gruf::Sentry::ServerInterceptor)
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
It comes with a few more options as well:
|
24
|
+
|
25
|
+
| Option | Description | Default |
|
26
|
+
| ------ | ----------- | ------- |
|
27
|
+
| ignore_methods | An array of method names to ignore from logging. E.g. `['namespace.health.check']` | `[]` |
|
28
|
+
|
29
|
+
### Client Interceptors
|
30
|
+
|
31
|
+
To automatically report errors in your Gruf clients, pass the client interceptor to your `Gruf::Client` initializer:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
Gruf::Client.new(
|
35
|
+
service: MyService,
|
36
|
+
client_options: {
|
37
|
+
interceptors: [Gruf::Sentry::ClientInterceptor.new]
|
38
|
+
}
|
39
|
+
)
|
40
|
+
```
|
41
|
+
|
42
|
+
## License
|
43
|
+
|
44
|
+
Copyright (c) 2020-present, BigCommerce Pty. Ltd. All rights reserved
|
45
|
+
|
46
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
47
|
+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
48
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
49
|
+
persons to whom the Software is furnished to do so, subject to the following conditions:
|
50
|
+
|
51
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
52
|
+
Software.
|
53
|
+
|
54
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
55
|
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
56
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
57
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/gruf-sentry.gemspec
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2020-present, BigCommerce Pty. Ltd. All rights reserved
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
6
|
+
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
7
|
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
8
|
+
# persons to whom the Software is furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
11
|
+
# Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
14
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
15
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
16
|
+
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
17
|
+
#
|
18
|
+
lib = File.expand_path('../lib', __FILE__)
|
19
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
20
|
+
require 'gruf/sentry/version'
|
21
|
+
|
22
|
+
Gem::Specification.new do |spec|
|
23
|
+
spec.name = 'gruf-sentry'
|
24
|
+
spec.version = Gruf::Sentry::VERSION
|
25
|
+
spec.authors = ['Shaun McCormick']
|
26
|
+
spec.email = ['splittingred@gmail.com']
|
27
|
+
spec.license = 'MIT'
|
28
|
+
|
29
|
+
spec.summary = %q{Automatically report gruf failures as sentry errors}
|
30
|
+
spec.description = spec.summary
|
31
|
+
spec.homepage = 'https://github.com/bigcommerce/gruf-sentry'
|
32
|
+
|
33
|
+
spec.required_ruby_version = '~> 2.4'
|
34
|
+
|
35
|
+
spec.files = Dir['README.md', 'CHANGELOG.md', 'CODE_OF_CONDUCT.md', 'lib/**/*', 'gruf-sentry.gemspec']
|
36
|
+
spec.require_paths = ['lib']
|
37
|
+
|
38
|
+
spec.add_development_dependency 'bundler', '~> 1.17'
|
39
|
+
spec.add_development_dependency 'bundler-audit', '~> 0.6'
|
40
|
+
spec.add_development_dependency 'null-logger', '~> 0.1'
|
41
|
+
spec.add_development_dependency 'rake', '>= 12.3'
|
42
|
+
spec.add_development_dependency 'rubocop', '~> 0.80'
|
43
|
+
spec.add_development_dependency 'pry'
|
44
|
+
spec.add_development_dependency 'rspec', '>= 3.8'
|
45
|
+
spec.add_development_dependency 'rspec_junit_formatter', '~> 0.4'
|
46
|
+
spec.add_development_dependency 'simplecov', '~> 0.16'
|
47
|
+
|
48
|
+
spec.add_dependency 'gruf', '~> 2.5', '>= 2.5.1'
|
49
|
+
spec.add_dependency 'sentry-raven', '>= 2.13'
|
50
|
+
end
|
data/lib/gruf/sentry.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2020-present, BigCommerce Pty. Ltd. All rights reserved
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
6
|
+
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
7
|
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
8
|
+
# persons to whom the Software is furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
11
|
+
# Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
14
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
15
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
16
|
+
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
17
|
+
#
|
18
|
+
require 'gruf'
|
19
|
+
require 'raven'
|
20
|
+
require_relative 'sentry/version'
|
21
|
+
require_relative 'sentry/configuration'
|
22
|
+
require_relative 'sentry/error_parser'
|
23
|
+
require_relative 'sentry/server_interceptor'
|
24
|
+
require_relative 'sentry/client_interceptor'
|
25
|
+
|
26
|
+
##
|
27
|
+
# Base gruf module
|
28
|
+
#
|
29
|
+
module Gruf
|
30
|
+
##
|
31
|
+
# Base gruf-sentry module
|
32
|
+
#
|
33
|
+
module Sentry
|
34
|
+
extend Gruf::Sentry::Configuration
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2020-present, BigCommerce Pty. Ltd. All rights reserved
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
6
|
+
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
7
|
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
8
|
+
# persons to whom the Software is furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
11
|
+
# Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
14
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
15
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
16
|
+
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
17
|
+
#
|
18
|
+
module Gruf
|
19
|
+
module Sentry
|
20
|
+
##
|
21
|
+
# Intercepts outbound calls to provide Sentry reporting
|
22
|
+
#
|
23
|
+
class ClientInterceptor < Gruf::Interceptors::ClientInterceptor
|
24
|
+
include Gruf::Sentry::ErrorParser
|
25
|
+
|
26
|
+
##
|
27
|
+
# @param [Gruf::Outbound::RequestContext]
|
28
|
+
#
|
29
|
+
def call(request_context:)
|
30
|
+
return yield if Gruf::Sentry.ignore_methods.include?(request_context.method_name)
|
31
|
+
|
32
|
+
begin
|
33
|
+
yield
|
34
|
+
rescue StandardError, GRPC::BadStatus => e
|
35
|
+
if error?(e) # only capture
|
36
|
+
::Raven.capture_exception(
|
37
|
+
e,
|
38
|
+
message: e.message,
|
39
|
+
extra: {
|
40
|
+
grpc_method_name: request_context.method_name,
|
41
|
+
grpc_route_key: request_context.route_key,
|
42
|
+
grpc_call_type: request_context.type,
|
43
|
+
grpc_error_code: code_for(e),
|
44
|
+
grpc_error_class: e.class
|
45
|
+
}
|
46
|
+
)
|
47
|
+
end
|
48
|
+
raise # passthrough
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2020-present, BigCommerce Pty. Ltd. All rights reserved
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
6
|
+
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
7
|
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
8
|
+
# persons to whom the Software is furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
11
|
+
# Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
14
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
15
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
16
|
+
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
17
|
+
#
|
18
|
+
module Gruf
|
19
|
+
module Sentry
|
20
|
+
##
|
21
|
+
# Configuration module for gruf-sentry
|
22
|
+
#
|
23
|
+
module Configuration
|
24
|
+
VALID_CONFIG_KEYS = {
|
25
|
+
grpc_error_classes: ::ENV.fetch(
|
26
|
+
'GRUF_SENTRY_GRPC_ERROR_CLASSES',
|
27
|
+
'GRPC::Unknown,GRPC::Internal,GRPC::DataLoss,GRPC::FailedPrecondition,GRPC::Unavailable,GRPC::DeadlineExceeded,GRPC::Cancelled'
|
28
|
+
).to_s.split(',').map(&:strip),
|
29
|
+
default_error_code: ::ENV.fetch('GRUF_SENTRY_DEFAULT_ERROR_CODE', GRPC::Core::StatusCodes::INTERNAL).to_i,
|
30
|
+
ignore_methods: ::ENV.fetch('GRUF_SENTRY_IGNORE_METHODS', '').split(',').map(&:strip) || []
|
31
|
+
}.freeze
|
32
|
+
|
33
|
+
attr_accessor *VALID_CONFIG_KEYS.keys
|
34
|
+
|
35
|
+
##
|
36
|
+
# Whenever this is extended into a class, setup the defaults
|
37
|
+
#
|
38
|
+
def self.extended(base)
|
39
|
+
base.reset
|
40
|
+
end
|
41
|
+
|
42
|
+
##
|
43
|
+
# Yield self for ruby-style initialization
|
44
|
+
#
|
45
|
+
# @yields [Gruf::Sentry::Configuration]
|
46
|
+
# @return [Gruf::Sentry::Configuration]
|
47
|
+
#
|
48
|
+
def configure
|
49
|
+
yield self
|
50
|
+
end
|
51
|
+
|
52
|
+
##
|
53
|
+
# Return the current configuration options as a Hash
|
54
|
+
#
|
55
|
+
# @return [Hash]
|
56
|
+
#
|
57
|
+
def options
|
58
|
+
opts = {}
|
59
|
+
VALID_CONFIG_KEYS.each_key do |k|
|
60
|
+
opts.merge!(k => send(k))
|
61
|
+
end
|
62
|
+
opts
|
63
|
+
end
|
64
|
+
|
65
|
+
##
|
66
|
+
# Set the default configuration onto the extended class
|
67
|
+
#
|
68
|
+
# @return [Hash] options The reset options hash
|
69
|
+
#
|
70
|
+
def reset
|
71
|
+
VALID_CONFIG_KEYS.each do |k, v|
|
72
|
+
send("#{k}=".to_sym, v)
|
73
|
+
end
|
74
|
+
|
75
|
+
options
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2020-present, BigCommerce Pty. Ltd. All rights reserved
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
6
|
+
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
7
|
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
8
|
+
# persons to whom the Software is furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
11
|
+
# Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
14
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
15
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
16
|
+
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
17
|
+
#
|
18
|
+
module Gruf
|
19
|
+
module Sentry
|
20
|
+
##
|
21
|
+
# Mixin for error parsing
|
22
|
+
#
|
23
|
+
module ErrorParser
|
24
|
+
##
|
25
|
+
# @param [StandardError]
|
26
|
+
# @return [Number] that maps to one of the GRPC::Core::StatusCodes or Gruf::Sentry.default_error_code
|
27
|
+
#
|
28
|
+
def code_for(error)
|
29
|
+
error.respond_to?(:code) ? error.code : Gruf::Sentry.default_error_code
|
30
|
+
end
|
31
|
+
|
32
|
+
##
|
33
|
+
# @return [Boolean]
|
34
|
+
#
|
35
|
+
def error?(exception)
|
36
|
+
error_classes.include?(exception.class.to_s)
|
37
|
+
end
|
38
|
+
|
39
|
+
##
|
40
|
+
# @return [Array]
|
41
|
+
#
|
42
|
+
def error_classes
|
43
|
+
options.fetch(:error_classes, Gruf::Sentry.grpc_error_classes)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
6
|
+
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
7
|
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
8
|
+
# persons to whom the Software is furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
11
|
+
# Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
14
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
15
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
16
|
+
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
17
|
+
#
|
18
|
+
module Gruf
|
19
|
+
module Sentry
|
20
|
+
##
|
21
|
+
# Intercepts inbound calls to provide Sentry error reporting
|
22
|
+
#
|
23
|
+
class ServerInterceptor < Gruf::Interceptors::ServerInterceptor
|
24
|
+
include Gruf::Sentry::ErrorParser
|
25
|
+
|
26
|
+
##
|
27
|
+
# Handle the gruf around hook and capture errors
|
28
|
+
#
|
29
|
+
def call(&_block)
|
30
|
+
return yield if Gruf::Sentry.ignore_methods.include?(request.method_name)
|
31
|
+
|
32
|
+
begin
|
33
|
+
yield
|
34
|
+
rescue StandardError, GRPC::BadStatus => e
|
35
|
+
if error?(e) # only capture
|
36
|
+
::Raven.capture_exception(
|
37
|
+
e,
|
38
|
+
message: e.message,
|
39
|
+
extra: {
|
40
|
+
grpc_method: request.method_key,
|
41
|
+
grpc_request_class: request.request_class,
|
42
|
+
grpc_service_key: request.service_key,
|
43
|
+
grpc_error_code: code_for(e),
|
44
|
+
grpc_error_class: e.class
|
45
|
+
}
|
46
|
+
)
|
47
|
+
end
|
48
|
+
raise # passthrough
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
##
|
55
|
+
# @return [Hash]
|
56
|
+
#
|
57
|
+
def request_message_params
|
58
|
+
return {} if request.client_streamer? || !request.message.respond_to?(:to_h)
|
59
|
+
|
60
|
+
request.message.to_h
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2020-present, BigCommerce Pty. Ltd. All rights reserved
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
6
|
+
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
7
|
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
8
|
+
# persons to whom the Software is furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
11
|
+
# Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
14
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
15
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
16
|
+
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
17
|
+
#
|
18
|
+
module Gruf
|
19
|
+
module Sentry
|
20
|
+
VERSION = '0.0.1'
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,213 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gruf-sentry
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shaun McCormick
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-03-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler-audit
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: null-logger
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '12.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '12.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.80'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.80'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.8'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.8'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec_junit_formatter
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.4'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.4'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: simplecov
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.16'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.16'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: gruf
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '2.5'
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: 2.5.1
|
149
|
+
type: :runtime
|
150
|
+
prerelease: false
|
151
|
+
version_requirements: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - "~>"
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '2.5'
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: 2.5.1
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
name: sentry-raven
|
161
|
+
requirement: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '2.13'
|
166
|
+
type: :runtime
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '2.13'
|
173
|
+
description: Automatically report gruf failures as sentry errors
|
174
|
+
email:
|
175
|
+
- splittingred@gmail.com
|
176
|
+
executables: []
|
177
|
+
extensions: []
|
178
|
+
extra_rdoc_files: []
|
179
|
+
files:
|
180
|
+
- CHANGELOG.md
|
181
|
+
- CODE_OF_CONDUCT.md
|
182
|
+
- README.md
|
183
|
+
- gruf-sentry.gemspec
|
184
|
+
- lib/gruf/sentry.rb
|
185
|
+
- lib/gruf/sentry/client_interceptor.rb
|
186
|
+
- lib/gruf/sentry/configuration.rb
|
187
|
+
- lib/gruf/sentry/error_parser.rb
|
188
|
+
- lib/gruf/sentry/server_interceptor.rb
|
189
|
+
- lib/gruf/sentry/version.rb
|
190
|
+
homepage: https://github.com/bigcommerce/gruf-sentry
|
191
|
+
licenses:
|
192
|
+
- MIT
|
193
|
+
metadata: {}
|
194
|
+
post_install_message:
|
195
|
+
rdoc_options: []
|
196
|
+
require_paths:
|
197
|
+
- lib
|
198
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
199
|
+
requirements:
|
200
|
+
- - "~>"
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
version: '2.4'
|
203
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
204
|
+
requirements:
|
205
|
+
- - ">="
|
206
|
+
- !ruby/object:Gem::Version
|
207
|
+
version: '0'
|
208
|
+
requirements: []
|
209
|
+
rubygems_version: 3.0.6
|
210
|
+
signing_key:
|
211
|
+
specification_version: 4
|
212
|
+
summary: Automatically report gruf failures as sentry errors
|
213
|
+
test_files: []
|