flame-raven_context 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +13 -0
- data/LICENSE.txt +21 -0
- data/README.md +123 -0
- data/lib/flame/raven_context/version.rb +7 -0
- data/lib/flame/raven_context.rb +81 -0
- metadata +236 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 42afc9c61fd45681a0b88e20e74f8a6c8926169950dcd02d73e6966487bc5e11
|
4
|
+
data.tar.gz: c66b05abf9ec9da0bbcb49a9bc8d7d6ce70514682b988f1caf25bb026cf114b0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ac690f73b385d7b625036d8de83ac322146edee806de7af6fc1bd98608213db0041dc4b8c9310c06207ceda4487e31902186362919a69199609a6cb3d2305edf
|
7
|
+
data.tar.gz: be16c66a53029f0dab3756dc8bec4c62cf3aade080da0287c38dace6cb545447871479e13f6caaf84eea092fe5cfa528a367fe2ff1bfb9e8f0e9ab3c624d10bf
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Alexander Popov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
# Flame Raven Context
|
2
|
+
|
3
|
+
[![Cirrus CI - Base Branch Build Status](https://img.shields.io/cirrus/github/AlexWayfer/flame-raven_context?style=flat-square)](https://cirrus-ci.com/github/AlexWayfer/flame-raven_context)
|
4
|
+
[![Codecov branch](https://img.shields.io/codecov/c/github/AlexWayfer/flame-raven_context/master.svg?style=flat-square)](https://codecov.io/gh/AlexWayfer/flame-raven_context)
|
5
|
+
[![Code Climate](https://img.shields.io/codeclimate/maintainability/AlexWayfer/flame-raven_context.svg?style=flat-square)](https://codeclimate.com/github/AlexWayfer/flame-raven_context)
|
6
|
+
[![Depfu](https://img.shields.io/depfu/AlexWayfer/flame-raven_context?style=flat-square)](https://depfu.com/repos/github/AlexWayfer/flame-raven_context)
|
7
|
+
[![Inline docs](https://inch-ci.org/github/AlexWayfer/flame-raven_context.svg?branch=master)](https://inch-ci.org/github/AlexWayfer/flame-raven_context)
|
8
|
+
[![License](https://img.shields.io/github/license/AlexWayfer/flame-raven_context.svg?style=flat-square)](https://github.com/AlexWayfer/flame-raven_context/blob/master/LICENSE.txt)
|
9
|
+
[![Gem](https://img.shields.io/gem/v/flame-raven_context.svg?style=flat-square)](https://rubygems.org/gems/flame-raven_context)
|
10
|
+
|
11
|
+
Helper class for [Sentry](https://sentry.io/) reports
|
12
|
+
via [`sentry-raven` gem](https://rubygems.org/gems/sentry-raven)
|
13
|
+
from [Flame](https://github.com/AlexWayfer/flame) web applications.
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'flame-raven_context'
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
```shell
|
26
|
+
bundle install
|
27
|
+
```
|
28
|
+
|
29
|
+
Or install it yourself as:
|
30
|
+
|
31
|
+
```shell
|
32
|
+
gem install flame-raven_context
|
33
|
+
```
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
|
37
|
+
Default loggers:
|
38
|
+
|
39
|
+
* [`:puma`](https://puma.io/)
|
40
|
+
* `:server`
|
41
|
+
* `:not_found`
|
42
|
+
* `:translations` ([R18n](https://github.com/r18n/r18n))
|
43
|
+
* `:validation_errors` ([Formalism R18n Errors](https://github.com/AlexWayfer/formalism-r18n_errors))
|
44
|
+
|
45
|
+
You can change them via `Flame::RavenContext.loggers` reader.
|
46
|
+
|
47
|
+
Example from [Flame application template](https://github.com/AlexWayfer/flame-cli/tree/master/template):
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
require 'flame/raven_context'
|
51
|
+
|
52
|
+
module MyApplication
|
53
|
+
## Base controller for any others controllers
|
54
|
+
class Controller < Flame::Controller
|
55
|
+
protected
|
56
|
+
|
57
|
+
def not_found
|
58
|
+
unless request.bot?
|
59
|
+
request_context = Flame::RavenContext.new(:not_found, controller: self)
|
60
|
+
Raven.capture_message(*request_context.exception_with_context)
|
61
|
+
end
|
62
|
+
|
63
|
+
super
|
64
|
+
end
|
65
|
+
|
66
|
+
def server_error(exception)
|
67
|
+
request_context = Flame::RavenContext.new(:server, controller: self, exception: exception)
|
68
|
+
Raven.capture_exception(*request_context.exception_with_context)
|
69
|
+
|
70
|
+
super
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
## This can be used as `capture_validation_errors form_outcome.errors.translations`
|
76
|
+
## inside `else` of `if (form_outcome = @form.run).success?` condition.
|
77
|
+
def capture_validation_errors(errors)
|
78
|
+
Raven.capture_message(
|
79
|
+
*Flame::RavenContext.new(
|
80
|
+
:validation_errors,
|
81
|
+
controller: self,
|
82
|
+
form_class: @form.class,
|
83
|
+
errors: errors
|
84
|
+
).exception_with_context
|
85
|
+
)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
```
|
90
|
+
|
91
|
+
You can redefine `user` object for reports via:
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
module Flame
|
95
|
+
class RavenContext
|
96
|
+
private
|
97
|
+
|
98
|
+
def user
|
99
|
+
@controller&.send(:authenticated)&.account
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
```
|
104
|
+
|
105
|
+
## Development
|
106
|
+
|
107
|
+
After checking out the repo, run `bundle install` to install dependencies.
|
108
|
+
|
109
|
+
Then, run `toys rspec` to run the tests.
|
110
|
+
|
111
|
+
To install this gem onto your local machine, run `toys gem install`.
|
112
|
+
|
113
|
+
To release a new version, run `toys gem release %version%`.
|
114
|
+
See how it works [here](https://github.com/AlexWayfer/gem_toys#release).
|
115
|
+
|
116
|
+
## Contributing
|
117
|
+
|
118
|
+
Bug reports and pull requests are welcome on [GitHub](https://github.com/AlexWayfer/flame-raven_context).
|
119
|
+
|
120
|
+
## License
|
121
|
+
|
122
|
+
The gem is available as open source under the terms of the
|
123
|
+
[MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'raven_context/version'
|
4
|
+
|
5
|
+
require 'gorilla_patch/deep_dup'
|
6
|
+
require 'memery'
|
7
|
+
require 'sentry-raven'
|
8
|
+
|
9
|
+
module Flame
|
10
|
+
## Class for request context initialization
|
11
|
+
class RavenContext
|
12
|
+
include Memery
|
13
|
+
|
14
|
+
DEFAULT_LOGGERS = {
|
15
|
+
puma: {
|
16
|
+
level: :error
|
17
|
+
}.freeze,
|
18
|
+
server: {
|
19
|
+
level: :error
|
20
|
+
}.freeze,
|
21
|
+
not_found: {
|
22
|
+
level: :warning,
|
23
|
+
message: -> { "404: #{@controller.request.path}" }
|
24
|
+
}.freeze,
|
25
|
+
translations: {
|
26
|
+
level: :error,
|
27
|
+
message: -> { "Translation missing: #{@extra[:key]}" }
|
28
|
+
}.freeze,
|
29
|
+
validation_errors: {
|
30
|
+
level: :warning,
|
31
|
+
message: -> { "Validation errors: #{@extra[:form_class]}" }
|
32
|
+
}.freeze
|
33
|
+
}.freeze
|
34
|
+
|
35
|
+
class << self
|
36
|
+
include Memery
|
37
|
+
|
38
|
+
using GorillaPatch::DeepDup
|
39
|
+
|
40
|
+
memoize def loggers
|
41
|
+
DEFAULT_LOGGERS.deep_dup
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
attr_reader :exception
|
46
|
+
|
47
|
+
def initialize(
|
48
|
+
sentry_logger, controller: nil, env: controller&.request&.env, **extra
|
49
|
+
)
|
50
|
+
@sentry_logger = sentry_logger
|
51
|
+
@controller = controller
|
52
|
+
@env = env
|
53
|
+
@extra = extra
|
54
|
+
@logger = self.class.loggers[@sentry_logger]
|
55
|
+
@exception = @extra.delete(:exception) || instance_exec(&@logger[:message])
|
56
|
+
@extra[:sql] = exception.sql if exception.respond_to? :sql
|
57
|
+
end
|
58
|
+
|
59
|
+
memoize def exception_with_context
|
60
|
+
[exception, context]
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def user
|
66
|
+
@controller&.send(:authenticated)&.account
|
67
|
+
end
|
68
|
+
|
69
|
+
memoize def context
|
70
|
+
Raven::Context.clear!
|
71
|
+
Raven.rack_context(@env) if @env
|
72
|
+
|
73
|
+
{
|
74
|
+
level: @logger[:level],
|
75
|
+
user: user || {},
|
76
|
+
logger: @sentry_logger,
|
77
|
+
extra: @extra
|
78
|
+
}
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
metadata
ADDED
@@ -0,0 +1,236 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flame-raven_context
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Popov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-09-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: alt_memery
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: gorilla_patch
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sentry-raven
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.9'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: gem_toys
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.4.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.4.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: toys
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.11.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.11.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: codecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.2.1
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.2.1
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '3.9'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '3.9'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: simplecov
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.19.0
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.19.0
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rubocop
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 0.91.0
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 0.91.0
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: rubocop-performance
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '1.0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '1.0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: rubocop-rspec
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - "~>"
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '1.0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '1.0'
|
195
|
+
description: 'Helper class for Sentry reports via `sentry-raven` gem from Flame web
|
196
|
+
applications.
|
197
|
+
|
198
|
+
'
|
199
|
+
email:
|
200
|
+
- alex.wayfer@gmail.com
|
201
|
+
executables: []
|
202
|
+
extensions: []
|
203
|
+
extra_rdoc_files: []
|
204
|
+
files:
|
205
|
+
- CHANGELOG.md
|
206
|
+
- LICENSE.txt
|
207
|
+
- README.md
|
208
|
+
- lib/flame/raven_context.rb
|
209
|
+
- lib/flame/raven_context/version.rb
|
210
|
+
homepage: https://github.com/AlexWayfer/flame-raven_context
|
211
|
+
licenses:
|
212
|
+
- MIT
|
213
|
+
metadata:
|
214
|
+
source_code_uri: https://github.com/AlexWayfer/flame-raven_context
|
215
|
+
homepage_uri: https://github.com/AlexWayfer/flame-raven_context
|
216
|
+
changelog_uri: https://github.com/AlexWayfer/flame-raven_context/blob/master/CHANGELOG.md
|
217
|
+
post_install_message:
|
218
|
+
rdoc_options: []
|
219
|
+
require_paths:
|
220
|
+
- lib
|
221
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
222
|
+
requirements:
|
223
|
+
- - ">="
|
224
|
+
- !ruby/object:Gem::Version
|
225
|
+
version: '2.5'
|
226
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
227
|
+
requirements:
|
228
|
+
- - ">="
|
229
|
+
- !ruby/object:Gem::Version
|
230
|
+
version: '0'
|
231
|
+
requirements: []
|
232
|
+
rubygems_version: 3.1.2
|
233
|
+
signing_key:
|
234
|
+
specification_version: 4
|
235
|
+
summary: Helper class for Sentry reports from Flame web applications
|
236
|
+
test_files: []
|