sentry-user_informer 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fd2992ca3d29f4d3b22055eee55f8d5f56d9a0382d74c24f18705b87f90c3f43
4
+ data.tar.gz: 21e50f2a8e5a3616a97ced8c24fc4ef1d4898918bea5b26d516e2649807fa038
5
+ SHA512:
6
+ metadata.gz: a92f5b740de1e0014b4072c2d879312b0cda05691dae65c8435dc960f103b711e7fb2c18d6d1628257ca815c7ea6ca7f1cebeaf978dad6ecc424a4bd0768186d
7
+ data.tar.gz: c9fcf001a81e34b1c143d7043c2fcbbd0de75b595412b14b412b8033d9a28f2d424ad9c2bbd9ecf79f337a4034058959637c0d9efdbd3fe8758d949323402fe1
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (C) 2013 Michael Grosser <michael@grosser.it>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+ module Sentry
3
+ module UserInformer
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sentry
4
+ module UserInformer
5
+ SENTRY_EVENT_ID = "sentry_event_id"
6
+ class << self
7
+ attr_accessor :placeholder, :template
8
+ end
9
+ self.placeholder = "<!-- SENTRY-USER-INFORMER -->"
10
+ self.template =
11
+ "<br/><br/>Error number: <a href='https://sentry.io/organizations/foo/issues/?query=%{event_id}'>%{event_id}</a>" # rubocop:disable Style/FormatStringToken
12
+
13
+ # render captured exception so users can click it
14
+ # testing: set `config.consider_all_requests_local = false` and add `raise 'testing'` to an action
15
+ class ExceptionRenderer
16
+ def initialize(app)
17
+ @app = app
18
+ end
19
+
20
+ def call(env)
21
+ Thread.current[Sentry::UserInformer::SENTRY_EVENT_ID] = nil # reset to not keep old exception around
22
+ status, headers, body = @app.call(env)
23
+ if (event_id = Thread.current[Sentry::UserInformer::SENTRY_EVENT_ID])
24
+ replacement = format(Sentry::UserInformer.template, event_id: event_id)
25
+ body = body.map { |chunk| chunk.gsub(Sentry::UserInformer.placeholder, replacement) }
26
+ headers["Content-Length"] = body.sum(&:bytesize).to_s # not sure if this is needed, but it does not hurt
27
+ end
28
+ [status, headers, body]
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ if defined?(::Rails::Railtie)
35
+ raise "Load sentry-rails before sentry-user_informer" unless defined?(Sentry::Rails)
36
+ # override capture_exception to store the exception in globally since it does not have access to any other state
37
+ Sentry::Rails::CaptureExceptions.prepend(
38
+ Module.new do
39
+ def capture_exception(_exception)
40
+ event = super
41
+ Thread.current[Sentry::UserInformer::SENTRY_EVENT_ID] = event&.event_id
42
+ event
43
+ end
44
+ end
45
+ )
46
+
47
+ module Sentry
48
+ module UserInformer
49
+ class Railtie < ::Rails::Railtie
50
+ initializer("sentry.user_informer") do |app|
51
+ app.config.middleware.insert_before ActionDispatch::ShowExceptions, Sentry::UserInformer::ExceptionRenderer
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,4 @@
1
+ # rubocop:disable Naming/FileName
2
+ # frozen_string_literal: true
3
+ require "sentry/user_informer"
4
+ # rubocop:enable Naming/FileName
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sentry-user_informer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Grosser
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-07-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: railties
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 7.0.0
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: 7.1.0
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 7.0.0
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: 7.1.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: sentry-rails
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '5.3'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '5.3'
61
+ description:
62
+ email: michael@grosser.it
63
+ executables: []
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - MIT-LICENSE
68
+ - lib/sentry-user_informer.rb
69
+ - lib/sentry/user_informer.rb
70
+ - lib/sentry/user_informer/version.rb
71
+ homepage: https://github.com/grosser/sentry-user_informer
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 2.7.0
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubygems_version: 3.1.6
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: show link to errors on exception page
94
+ test_files: []