airbrake-user_informer 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/lib/airbrake/user_informer/version.rb +6 -0
- data/lib/airbrake/user_informer.rb +84 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 880658bfa2c986774561bdcd7d851404950f20ff
|
4
|
+
data.tar.gz: ed26530caf93e86083f04289ecf0317364055eba
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: afe2a504ef6933b4aeed35dba74aa94716f4b5d88f9858d46c81e07817d97129235733892584bc258d4685424eb6b10cb39726435a7272c229b72c2eebfa89ce
|
7
|
+
data.tar.gz: f7b5db144470a7a2811024621794bd6a03d40d20cbbde3a7deab72b3687ee07c8caa14bd073e30c2bbb2c0904814891516f210420acd74bc2c296c571b686bd8
|
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,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Airbrake
|
3
|
+
module UserInformer
|
4
|
+
module MiddlewareExtension
|
5
|
+
def notify_airbrake(_, env)
|
6
|
+
if Airbrake.user_information
|
7
|
+
env[Middleware::ENV_KEY] = super
|
8
|
+
else
|
9
|
+
super
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# stolen from https://github.com/airbrake/airbrake/blob/v4.3.8/lib/airbrake/user_informer.rb
|
15
|
+
class Middleware
|
16
|
+
ENV_KEY = "airbrake.promise"
|
17
|
+
PLACEHOLDER = "<!-- AIRBRAKE ERROR -->"
|
18
|
+
TIMEOUT = 1.0 # seconds
|
19
|
+
STEPS = 100
|
20
|
+
|
21
|
+
def initialize(app)
|
22
|
+
@app = app
|
23
|
+
end
|
24
|
+
|
25
|
+
def call(env)
|
26
|
+
status, headers, body = @app.call(env)
|
27
|
+
|
28
|
+
if (replacement = Airbrake.user_information) && error_id = wait_for_error(env[ENV_KEY])
|
29
|
+
replacement = replacement.gsub(/\{\{\s*error_id\s*\}\}/, error_id.to_s)
|
30
|
+
body = replace_placeholder(replacement, body, headers)
|
31
|
+
end
|
32
|
+
[status, headers, body]
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
# wait till airbrake is done reporting ... stop when it fails to report
|
38
|
+
# TODO: use something nicer than sleep
|
39
|
+
def wait_for_error(promise)
|
40
|
+
return unless promise
|
41
|
+
done = false
|
42
|
+
error_id = nil
|
43
|
+
promise.then { |notice| error_id = done = notice["id"] }
|
44
|
+
promise.rescue { |_notice| done = true }
|
45
|
+
STEPS.times do
|
46
|
+
break if done
|
47
|
+
sleep TIMEOUT / STEPS
|
48
|
+
end
|
49
|
+
error_id
|
50
|
+
end
|
51
|
+
|
52
|
+
# - body interface is .each so we cannot use anything else
|
53
|
+
# - always call .close on the old body so it can get garbage collected if it is a File
|
54
|
+
def replace_placeholder(replacement, body, headers)
|
55
|
+
new_body = []
|
56
|
+
body.each { |chunk| new_body << chunk.gsub(PLACEHOLDER, replacement) }
|
57
|
+
headers["Content-Length"] = new_body.inject(0) { |sum, x| sum + x.bytesize }.to_s
|
58
|
+
new_body
|
59
|
+
ensure
|
60
|
+
body.close if body && body.respond_to?(:close)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class << Airbrake
|
67
|
+
attr_accessor :user_information
|
68
|
+
end
|
69
|
+
|
70
|
+
if defined?(::Rails::Railtie)
|
71
|
+
raise "Load airbrake before airbrake-user_informer" unless defined?(Airbrake::Rack)
|
72
|
+
Airbrake::Rack::Middleware.prepend(Airbrake::UserInformer::MiddlewareExtension)
|
73
|
+
|
74
|
+
module Airbrake
|
75
|
+
module UserInformer
|
76
|
+
class Railtie < ::Rails::Railtie
|
77
|
+
initializer("airbrake.user_informer") do |app|
|
78
|
+
insertion_point = (::Rails::VERSION::MAJOR >= 5 ? ::Rack::Runtime : "Rack::Runtime")
|
79
|
+
app.config.middleware.insert_before(insertion_point, Airbrake::UserInformer::Middleware)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: airbrake-user_informer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Grosser
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: railties
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rack
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: airbrake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.7'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: airbrake-ruby
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.7'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.7'
|
69
|
+
description:
|
70
|
+
email: michael@grosser.it
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- MIT-LICENSE
|
76
|
+
- lib/airbrake/user_informer.rb
|
77
|
+
- lib/airbrake/user_informer/version.rb
|
78
|
+
homepage: https://github.com/grosser/airbrake-user_informer
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 2.2.0
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.5.1
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Show exception ids on error pages so users or support can track them down
|
102
|
+
faster
|
103
|
+
test_files: []
|