appflux_ruby 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +10 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +48 -0
- data/Rakefile +10 -0
- data/appflux_ruby.gemspec +37 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/appflux_ruby/bugflux_config.rb +43 -0
- data/lib/appflux_ruby/bugflux_notifier.rb +38 -0
- data/lib/appflux_ruby/delayed/plugin.rb +29 -0
- data/lib/appflux_ruby/helpers/util.rb +11 -0
- data/lib/appflux_ruby/message_builders/base.rb +23 -0
- data/lib/appflux_ruby/message_builders/bugflux.rb +154 -0
- data/lib/appflux_ruby/message_builders/custom_message.rb +24 -0
- data/lib/appflux_ruby/message_builders/delayed_job.rb +26 -0
- data/lib/appflux_ruby/rack/middleware.rb +23 -0
- data/lib/appflux_ruby/rails/active_record.rb +37 -0
- data/lib/appflux_ruby/rails/controller_methods.rb +56 -0
- data/lib/appflux_ruby/rails/railtie.rb +25 -0
- data/lib/appflux_ruby/version.rb +3 -0
- data/lib/appflux_ruby.rb +39 -0
- data/lib/generators/appflux_ruby/bugflux.rb +10 -0
- data/lib/generators/appflux_ruby/install_generator.rb +10 -0
- data/test/appflux-ruby_test.rb +11 -0
- data/test/test_helper.rb +4 -0
- metadata +34 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2e783505b000e326a643061f4ca5ed87711a811
|
4
|
+
data.tar.gz: 784bbf15113d2dc88b0f9478df27972249631132
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 841bce7a30416c02449da7a1da4404fa24eeeead44bf1d0dc44ea7f1ad24af002a9c222e06a241569d29f9d91dbac3b40c19085bfb9db5d6a8714c6b2d5fcf2b
|
7
|
+
data.tar.gz: 8e2a8f9cc34257eeb7b208b41ecf769d5df6cc300dcd4ed6ebb7efc77fe157ed9c4a85090dcda08302327ab72f0f2d09720ddb24290ce29fab102ee0521330c8
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at TODO: Write your email address. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Shubham Gupta
|
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,48 @@
|
|
1
|
+
# Appflux Ruby
|
2
|
+
|
3
|
+
---
|
4
|
+
|
5
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/64eff633689a54b902cf/maintainability)](https://codeclimate.com/github/appflux/appflux-ruby/maintainability)
|
6
|
+
|
7
|
+
|
8
|
+
The appflux-ruby gem sends notifications when an exception occurs in your Rack/Rails application. The community edition integrates nicely with your appflux.io dashboard. We also offer an enterprise version that also offers a project communication platform.
|
9
|
+
|
10
|
+
## Features
|
11
|
+
1. Automatically reports unhandled exceptions.
|
12
|
+
2. Reports handled exceptions.
|
13
|
+
3. Automagically supports Delayed Job and Sidekiq.
|
14
|
+
4. Figures out common information used to debug a Rails application.
|
15
|
+
5. Send custom diagnostic information.
|
16
|
+
6. Nicely integrates with your Appflux.io dashboard.
|
17
|
+
|
18
|
+
|
19
|
+
## Requirements
|
20
|
+
1. Ruby 1.9.3 or greater
|
21
|
+
2. Rails 3.0 or greater, Grape, Sinatra or any other Rack application.
|
22
|
+
|
23
|
+
|
24
|
+
## Setup
|
25
|
+
> Appflux is free. Basic error monitoring will always remain free.
|
26
|
+
1. Sign up on appflux.io.
|
27
|
+
2. Confirm your account and create a project.
|
28
|
+
3. Follow the instructions on the setup page.
|
29
|
+
|
30
|
+
## What's more ?
|
31
|
+
Appflux offers an integrated platform to monitor, analyze and discuss your ruby application. You can:
|
32
|
+
1. Get notified of exceptions in real-time.
|
33
|
+
2. Post messages and discuss issues with other collaborators.
|
34
|
+
3. Maintain all project related files in one location.
|
35
|
+
|
36
|
+
## What's cookin' ?
|
37
|
+
1. Support for out-of-the-box user behavior analysis for Rails applications.
|
38
|
+
2. Cohort analysis for Rails applications.
|
39
|
+
|
40
|
+
|
41
|
+
## Help
|
42
|
+
1. hi@appflux.io
|
43
|
+
2. [@_guptashubham](https://twitter.com/_guptashubham)
|
44
|
+
3. [@appfluxhq](https://www.twitter.com/appfluxhq)
|
45
|
+
|
46
|
+
## License
|
47
|
+
|
48
|
+
The Appflux ruby gem is a free software released under the MIT License. See [LICENSE.txt](https://github.com/appflux/appflux-ruby/blob/master/LICENSE.txt) for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'appflux_ruby/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'appflux_ruby'
|
8
|
+
spec.version = AppfluxRuby::VERSION
|
9
|
+
spec.date = Time.now.strftime('%Y-%m-%d')
|
10
|
+
spec.authors = ['Shubham Gupta']
|
11
|
+
spec.email = ['sgupta.89cse@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'Ruby library for integration with http://appflux.io'
|
14
|
+
spec.description = <<DESC
|
15
|
+
AppfluxRuby is a ruby library for integrating your rack based applications with
|
16
|
+
https://appflux.io/bugflux. This gem provides a basic API for automatically and
|
17
|
+
manually sending exceptions metadata from your Rack based application. The
|
18
|
+
processed exceptions data can be viewed at the error dashboard for the project
|
19
|
+
on Appflux. For Rails applications, you can also send custom data to the error
|
20
|
+
dashboard. It also integrates nicely with Delayed Job. Raise an issue on GitHub
|
21
|
+
for any feature requests or bugs. For reporting security vulnerablities, please
|
22
|
+
send an email at sgupta.89cse@gmail.com
|
23
|
+
DESC
|
24
|
+
|
25
|
+
spec.homepage = 'http://appflux.io'
|
26
|
+
spec.license = 'MIT'
|
27
|
+
|
28
|
+
spec.files = `git ls-files`.split("\n")
|
29
|
+
spec.test_files = `git ls-files -- test/*`.split("\n")
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
|
32
|
+
spec.add_dependency 'typhoeus', '>= 0.7'
|
33
|
+
spec.add_development_dependency 'bundler', '~> 1.0'
|
34
|
+
# spec.add_development_dependency 'rake'
|
35
|
+
# spec.add_development_dependency 'minitest', '~> 5.0'
|
36
|
+
# spec.add_development_dependency 'byebug', '~> 8.2'
|
37
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "appflux_ruby"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
##
|
2
|
+
# This class hold all configurations related to Bugflux. Our aim is to make this
|
3
|
+
# a generalized class that collects metrics for all the apps like: bugflux,
|
4
|
+
# perflux etc based on the host application configuration.
|
5
|
+
#
|
6
|
+
# Also, it would be better to extract the notice sending logic to its own gem.
|
7
|
+
# This is because all hook applications might not be on the same address.
|
8
|
+
module AppfluxRuby
|
9
|
+
class BugfluxConfig
|
10
|
+
##
|
11
|
+
# @return [ID] Identify the application where to send the notification.
|
12
|
+
# This value *must* be set.
|
13
|
+
attr_accessor :app_id
|
14
|
+
|
15
|
+
##
|
16
|
+
# @return [Logger] the default logger used for debug output
|
17
|
+
# attr_accessor :logger
|
18
|
+
|
19
|
+
##
|
20
|
+
# @return [String] the host, which provides the API endpoint to which
|
21
|
+
# exceptions should be sent
|
22
|
+
attr_reader :host
|
23
|
+
|
24
|
+
def initialize config = Hash.new
|
25
|
+
@host = host_name
|
26
|
+
end
|
27
|
+
|
28
|
+
##
|
29
|
+
# @return [Boolean], Whether we are using secure connection or not.
|
30
|
+
def use_ssl
|
31
|
+
false
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
# This is the URL to API that accepts notifications generated by this gem.
|
37
|
+
# Should be something like: /applications/<app_id>/notifications [POST]
|
38
|
+
def host_name
|
39
|
+
'http://appflux.io/exceptions'
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
##
|
2
|
+
# This class is specific only to sending bugflux notifications. It calls
|
3
|
+
# +MessageBuilder+ class for building the payload message and uses SSL to send
|
4
|
+
# the messages. It also implements a basic queue to send messages in batches.
|
5
|
+
# This is the default behaviour.
|
6
|
+
|
7
|
+
require 'typhoeus'
|
8
|
+
|
9
|
+
module AppfluxRuby
|
10
|
+
class BugfluxNotifier
|
11
|
+
|
12
|
+
class << self
|
13
|
+
|
14
|
+
def notify exception, environment = Hash.new
|
15
|
+
request = build_request(exception, environment)
|
16
|
+
response = request.run
|
17
|
+
|
18
|
+
unless response.code == 200
|
19
|
+
if defined?(::Rails)
|
20
|
+
::Rails.logger.fatal("[Bugflux-Failed] Failed to notify Bugflux, please check with your configuration in config/initializers/bugflux.rb. Error Code: #{ response.code }")
|
21
|
+
else
|
22
|
+
puts "[Bugflux-Failed] Failed to notify Bugflux, please check with your configuration in config/initializers/bugflux.rb. Error Code: #{ response.code }"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def build_request exception, environment
|
28
|
+
notice = ::AppfluxRuby::MessageBuilders::Bugflux.new(exception, environment).build
|
29
|
+
request = ::Typhoeus::Request.new(
|
30
|
+
::AppfluxRuby::Bugflux.config.host,
|
31
|
+
method: :post,
|
32
|
+
body: notice,
|
33
|
+
headers: { Accept: "application/json" }
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module AppfluxRuby
|
2
|
+
module Delayed
|
3
|
+
class Plugin < ::Delayed::Plugin
|
4
|
+
callbacks do |lifecycle|
|
5
|
+
lifecycle.around(:invoke_job) do |job, *args, &block|
|
6
|
+
begin
|
7
|
+
block.call(job, *args)
|
8
|
+
rescue Exception => exception
|
9
|
+
::AppfluxRuby::Bugflux.initialize_additional_data
|
10
|
+
params = job.as_json.merge(
|
11
|
+
component: 'delayed_job',
|
12
|
+
action: job.payload_object.class.name
|
13
|
+
)
|
14
|
+
|
15
|
+
# If DelayedJob is used through ActiveJob, it contains extra info.
|
16
|
+
if job.payload_object.respond_to?(:job_data)
|
17
|
+
params[:active_job] = job.payload_object.job_data
|
18
|
+
end
|
19
|
+
puts 'Sending exception notification to bugflux.'
|
20
|
+
::AppfluxRuby::BugfluxNotifier.notify(exception, params)
|
21
|
+
raise exception
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Delayed::Worker.plugins << Delayed::Plugins::AppfluxRuby
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module AppfluxRuby
|
2
|
+
module MessageBuilders
|
3
|
+
class Base
|
4
|
+
def initialize exception, rack_env
|
5
|
+
@exception = exception
|
6
|
+
@rack_env = rack_env
|
7
|
+
@request = ::Rack::Request.new(rack_env)
|
8
|
+
@session = @request.session
|
9
|
+
## TODO: Probably extract this hash into a dedicated class?
|
10
|
+
@notice = Hash.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def build
|
14
|
+
@notice
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.build exception, rack_env
|
18
|
+
new(exception, rack_env).build
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
## TODO: Add Rack Env. Current User.
|
2
|
+
##
|
3
|
+
# This class builds payload message to send to the backyard application.
|
4
|
+
# custom_tabs appear as individual tabs on Bugflux UI and are only set per
|
5
|
+
# exception occurrence.
|
6
|
+
# TODO: This might be Rails specific. Need to check for other Rack based
|
7
|
+
# frameworks.
|
8
|
+
# {
|
9
|
+
# bugflux: {
|
10
|
+
# app_id: '',
|
11
|
+
# env: {
|
12
|
+
# app_env: 'staging'
|
13
|
+
|
14
|
+
# request: {
|
15
|
+
|
16
|
+
# },
|
17
|
+
# params: {
|
18
|
+
|
19
|
+
# },
|
20
|
+
# headers: {
|
21
|
+
|
22
|
+
# },
|
23
|
+
# session: {
|
24
|
+
|
25
|
+
# }
|
26
|
+
# },
|
27
|
+
# exception: {
|
28
|
+
|
29
|
+
# }
|
30
|
+
# },
|
31
|
+
# custom_tabs: {
|
32
|
+
# tab_1: {},
|
33
|
+
# tab_2: {}
|
34
|
+
# }
|
35
|
+
# }
|
36
|
+
|
37
|
+
module AppfluxRuby
|
38
|
+
module MessageBuilders
|
39
|
+
class Bugflux < AppfluxRuby::MessageBuilders::Base
|
40
|
+
|
41
|
+
ENV_REQUEST_METHODS = %i( path host scheme user_agent port url ip
|
42
|
+
content_type request_method referrer )
|
43
|
+
ENV_REQUEST_KEYS = %i( SERVER_PROTOCOL SERVER_SOFTWARE )
|
44
|
+
|
45
|
+
ENV_EXCEPTION_METHODS = %i( backtrace message cause class )
|
46
|
+
|
47
|
+
SUPPORTED_BACKGROUND_JOB_PROCESSORS = %w(delayed_job)
|
48
|
+
|
49
|
+
def initialize exception, rack_env
|
50
|
+
super(exception, rack_env)
|
51
|
+
|
52
|
+
@notice[:bugflux] = Hash.new { |hsh, key| hsh[key] = Hash.new }
|
53
|
+
@bugflux_notice = @notice[:bugflux]
|
54
|
+
end
|
55
|
+
|
56
|
+
def build
|
57
|
+
super
|
58
|
+
add_app_id
|
59
|
+
add_request_data
|
60
|
+
add_params
|
61
|
+
add_exception_data
|
62
|
+
add_env
|
63
|
+
add_headers
|
64
|
+
add_session_data
|
65
|
+
add_background_job_info
|
66
|
+
add_custom_tabs
|
67
|
+
|
68
|
+
@notice
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.build exception, rack_env
|
72
|
+
new(exception, rack_env).build
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def add_request_data
|
78
|
+
@bugflux_notice[:env][:request] = Hash.new
|
79
|
+
_req_hash = @bugflux_notice[:env][:request]
|
80
|
+
|
81
|
+
ENV_REQUEST_METHODS.each do |_method|
|
82
|
+
_req_hash[_method.to_sym] = @request.public_send(_method)
|
83
|
+
end
|
84
|
+
|
85
|
+
ENV_REQUEST_KEYS.each do |_key|
|
86
|
+
_req_hash[_key.to_sym] = @request.env[_key.to_s]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def add_exception_data
|
91
|
+
ENV_EXCEPTION_METHODS.each do |_method|
|
92
|
+
@bugflux_notice[:exception][_method.to_sym] = @exception.public_send(_method)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def add_session_data
|
97
|
+
load_session
|
98
|
+
return unless session_loaded?
|
99
|
+
|
100
|
+
@bugflux_notice[:env][:session]= @request.env['rack.request.cookie_hash']
|
101
|
+
end
|
102
|
+
|
103
|
+
def add_headers
|
104
|
+
@bugflux_notice[:env][:headers] = Hash.new
|
105
|
+
|
106
|
+
@rack_env.keys.grep(/^HTTP_/).each do |_key|
|
107
|
+
@bugflux_notice[:env][:headers][_key] = @rack_env[_key]
|
108
|
+
end
|
109
|
+
|
110
|
+
@bugflux_notice[:env][:headers].delete('HTTP_COOKIE')
|
111
|
+
end
|
112
|
+
|
113
|
+
def add_params
|
114
|
+
@bugflux_notice[:env][:params] = @request.env['action_dispatch.request.parameters']
|
115
|
+
end
|
116
|
+
|
117
|
+
def add_app_id
|
118
|
+
@bugflux_notice[:app_id] = ::AppfluxRuby::Bugflux.config.app_id
|
119
|
+
end
|
120
|
+
|
121
|
+
def add_env
|
122
|
+
@bugflux_notice[:env][:app_env] = ::Rails.env if defined?(::Rails)
|
123
|
+
end
|
124
|
+
|
125
|
+
def add_custom_tabs
|
126
|
+
@bugflux_notice[:custom_tabs] ||= Hash.new
|
127
|
+
@bugflux_notice[:custom_tabs].merge!(::AppfluxRuby::Bugflux.additional_data)
|
128
|
+
end
|
129
|
+
|
130
|
+
## Adds background processor information as a dedicated tab on the UI.
|
131
|
+
def add_background_job_info
|
132
|
+
if @rack_env[:component].in?(SUPPORTED_BACKGROUND_JOB_PROCESSORS)
|
133
|
+
builder_klass_string = @rack_env[:component].classify#.constantize
|
134
|
+
builder_klass = "::AppfluxRuby::MessageBuilders::#{ builder_klass_string }".constantize
|
135
|
+
|
136
|
+
@bugflux_notice[:custom_tabs] ||= Hash.new
|
137
|
+
@bugflux_notice[:custom_tabs]["#{@rack_env[:component]}".to_sym] = builder_klass.to_hash(@rack_env)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
private
|
142
|
+
|
143
|
+
def load_session
|
144
|
+
unless session_loaded?
|
145
|
+
@session['___bugflux_dummy_key___'] ||= 'bugflux'
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def session_loaded?
|
150
|
+
@session.respond_to?(:loaded?) ? @session.loaded? : true
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# {
|
2
|
+
# custom_tabs:{
|
3
|
+
# tab_1: {
|
4
|
+
|
5
|
+
# },
|
6
|
+
# tab_2: {
|
7
|
+
|
8
|
+
# }
|
9
|
+
# }
|
10
|
+
# }
|
11
|
+
module AppfluxRuby
|
12
|
+
module MessageBuilders
|
13
|
+
class CustomMessage
|
14
|
+
def initialize
|
15
|
+
@custom_tabs = Array.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_tab(tab_name, options_data = {})
|
19
|
+
# @custom_tabs << { "#{ tab_name }": options_data }
|
20
|
+
::AppfluxRuby::Bugflux.additional_data[tab_name] = options_data
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module AppfluxRuby
|
2
|
+
module MessageBuilders
|
3
|
+
class DelayedJob
|
4
|
+
|
5
|
+
def initialize options
|
6
|
+
@options = options
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_hash
|
10
|
+
_handler_object = YAML.load(@options['handler'])
|
11
|
+
@options[:dj_handler] = _handler_object.inspect
|
12
|
+
@options[:object] = _handler_object.object.inspect
|
13
|
+
|
14
|
+
@options[:method_name] = _handler_object.method_name
|
15
|
+
@options[:method_arguments] = _handler_object.args
|
16
|
+
@options[:display_name] = _handler_object.display_name
|
17
|
+
|
18
|
+
@options
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.to_hash options
|
22
|
+
new(options).to_hash
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module AppfluxRuby
|
2
|
+
module Rack
|
3
|
+
class Middleware
|
4
|
+
def initialize(app)
|
5
|
+
@app = app
|
6
|
+
end
|
7
|
+
|
8
|
+
##
|
9
|
+
# Intercepts exception and sends notification to API.
|
10
|
+
def call(env)
|
11
|
+
begin
|
12
|
+
AppfluxRuby::Bugflux.initialize_additional_data
|
13
|
+
response = @app.call(env)
|
14
|
+
rescue Exception => ex
|
15
|
+
# TODO: Need to figure out a logger implementation.
|
16
|
+
puts 'Sending exception notification to bugflux.'
|
17
|
+
::AppfluxRuby::BugfluxNotifier.notify(ex, env)
|
18
|
+
raise ex
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module AppfluxRuby
|
2
|
+
module Rails
|
3
|
+
##
|
4
|
+
# ActiveRecord < 4.2 has a bug with regard to swallowing exceptions in the
|
5
|
+
# +after_commit+ and the +after_rollback+ hooks: it doesn't bubble up
|
6
|
+
# exceptions from there.
|
7
|
+
#
|
8
|
+
# This module makes it possible to report exceptions occurring there.
|
9
|
+
#
|
10
|
+
# @see https://github.com/rails/rails/pull/14488 Detailed description of the
|
11
|
+
# bug and the fix
|
12
|
+
module ActiveRecord
|
13
|
+
##
|
14
|
+
# @return [Array<Symbol>] the hooks that needs fixing
|
15
|
+
KINDS = [:commit, :rollback].freeze
|
16
|
+
|
17
|
+
##
|
18
|
+
# Patches default +run_callbacks+, which is capable of notifying about
|
19
|
+
# exceptions.
|
20
|
+
def run_callbacks(kind, *args, &block)
|
21
|
+
# Let the post process handle the exception if it's not a bugged hook.
|
22
|
+
return super unless KINDS.include?(kind)
|
23
|
+
|
24
|
+
# Handle the exception ourselves. The 'ex' exception won't be
|
25
|
+
# propagated, therefore we must notify it here.
|
26
|
+
begin
|
27
|
+
super
|
28
|
+
rescue Exception => ex
|
29
|
+
# TODO: Need to replace with Logger.
|
30
|
+
puts 'Sending exception notification to bugflux.'
|
31
|
+
::AppfluxRuby::BugfluxNotifier.notify(ex)
|
32
|
+
raise ex
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module AppfluxRuby
|
2
|
+
module Rails
|
3
|
+
module ControllerMethods
|
4
|
+
def self.included(base)
|
5
|
+
base.extend ClassMethods
|
6
|
+
base.include InstanceMethods
|
7
|
+
base.before_bugflux_notify :__send_user_info_to_bugflux__
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def before_bugflux_notify(*methods)
|
12
|
+
run_bugflux_callbacks(methods) do
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def run_bugflux_callbacks(__methods)
|
20
|
+
filtered_methods = __methods.last.is_a?(::Hash) ? __methods.pop : {}
|
21
|
+
|
22
|
+
@@custom_message = AppfluxRuby::MessageBuilders::CustomMessage.new
|
23
|
+
|
24
|
+
if respond_to?(:before_action)
|
25
|
+
before_action filtered_methods do |controller|
|
26
|
+
__methods.each do |_method|
|
27
|
+
controller.send(_method, @@custom_message)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
else
|
31
|
+
before_filter filtered_methods do |controller|
|
32
|
+
__methods.each do |_method|
|
33
|
+
controller.send(_method, @@custom_message)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
module InstanceMethods
|
43
|
+
private
|
44
|
+
def __send_user_info_to_bugflux__ notifier_object
|
45
|
+
if respond_to?(:current_user) && current_user
|
46
|
+
notifier_object.add_tab('User',
|
47
|
+
{ 'Current User Id': current_user.id,
|
48
|
+
'User Attributes': current_user.inspect
|
49
|
+
}
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module AppfluxRuby
|
2
|
+
module Rails
|
3
|
+
class Railtie < ::Rails::Railtie
|
4
|
+
initializer('appflux_ruby.middleware') do |app|
|
5
|
+
if ::Rails.version =~ /\A5\./
|
6
|
+
app.config.middleware.insert_after(
|
7
|
+
ActionDispatch::DebugExceptions, AppfluxRuby::Rack::Middleware
|
8
|
+
)
|
9
|
+
else
|
10
|
+
app.config.middleware.insert_after(
|
11
|
+
ActionDispatch::DebugExceptions, 'AppfluxRuby::Rack::Middleware'
|
12
|
+
)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
initializer('appflux_ruby.active_record') do
|
17
|
+
ActiveSupport.on_load(:active_record) do
|
18
|
+
require 'appflux_ruby/rails/active_record'
|
19
|
+
include AppfluxRuby::Rails::ActiveRecord
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/appflux_ruby.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require_relative 'appflux_ruby/version'
|
2
|
+
require_relative 'appflux_ruby/bugflux_config'
|
3
|
+
require_relative 'appflux_ruby/bugflux_notifier'
|
4
|
+
require_relative 'appflux_ruby/message_builders/base'
|
5
|
+
require_relative 'appflux_ruby/message_builders/bugflux'
|
6
|
+
require_relative 'appflux_ruby/message_builders/custom_message'
|
7
|
+
require_relative 'appflux_ruby/helpers/util'
|
8
|
+
|
9
|
+
if defined?(::Rack)
|
10
|
+
require_relative 'appflux_ruby/rack/middleware'
|
11
|
+
|
12
|
+
if defined?(::Rails)
|
13
|
+
require_relative 'appflux_ruby/rails/railtie'
|
14
|
+
require_relative 'appflux_ruby/rails/controller_methods'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
## Requires library specific files in generators. See: generators/appflux_ruby/install_generator.
|
19
|
+
## This is important to handle if appflux_ruby is present in Gemfile before Delayed Job.
|
20
|
+
|
21
|
+
module AppfluxRuby
|
22
|
+
class Bugflux
|
23
|
+
class << self
|
24
|
+
attr_accessor :config
|
25
|
+
attr_accessor :additional_data
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.configure &blk
|
29
|
+
self.config = AppfluxRuby::BugfluxConfig.new
|
30
|
+
yield self.config
|
31
|
+
end
|
32
|
+
|
33
|
+
## These methods are used to set per-request custom data.
|
34
|
+
def self.initialize_additional_data
|
35
|
+
@additional_data = Hash.new
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
AppfluxRuby::Bugflux.configure do |config|
|
2
|
+
config.app_id = '<your-app-id>'
|
3
|
+
end
|
4
|
+
|
5
|
+
if defined?(::Delayed)
|
6
|
+
require 'appflux_ruby/delayed/plugin'
|
7
|
+
require 'appflux_ruby/message_builders/delayed_job'
|
8
|
+
|
9
|
+
Delayed::Worker.plugins << ::AppfluxRuby::Delayed::Plugin
|
10
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appflux_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shubham Gupta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|
@@ -51,7 +51,35 @@ email:
|
|
51
51
|
executables: []
|
52
52
|
extensions: []
|
53
53
|
extra_rdoc_files: []
|
54
|
-
files:
|
54
|
+
files:
|
55
|
+
- ".gitignore"
|
56
|
+
- ".travis.yml"
|
57
|
+
- CODE_OF_CONDUCT.md
|
58
|
+
- Gemfile
|
59
|
+
- LICENSE.txt
|
60
|
+
- README.md
|
61
|
+
- Rakefile
|
62
|
+
- appflux_ruby.gemspec
|
63
|
+
- bin/console
|
64
|
+
- bin/setup
|
65
|
+
- lib/appflux_ruby.rb
|
66
|
+
- lib/appflux_ruby/bugflux_config.rb
|
67
|
+
- lib/appflux_ruby/bugflux_notifier.rb
|
68
|
+
- lib/appflux_ruby/delayed/plugin.rb
|
69
|
+
- lib/appflux_ruby/helpers/util.rb
|
70
|
+
- lib/appflux_ruby/message_builders/base.rb
|
71
|
+
- lib/appflux_ruby/message_builders/bugflux.rb
|
72
|
+
- lib/appflux_ruby/message_builders/custom_message.rb
|
73
|
+
- lib/appflux_ruby/message_builders/delayed_job.rb
|
74
|
+
- lib/appflux_ruby/rack/middleware.rb
|
75
|
+
- lib/appflux_ruby/rails/active_record.rb
|
76
|
+
- lib/appflux_ruby/rails/controller_methods.rb
|
77
|
+
- lib/appflux_ruby/rails/railtie.rb
|
78
|
+
- lib/appflux_ruby/version.rb
|
79
|
+
- lib/generators/appflux_ruby/bugflux.rb
|
80
|
+
- lib/generators/appflux_ruby/install_generator.rb
|
81
|
+
- test/appflux-ruby_test.rb
|
82
|
+
- test/test_helper.rb
|
55
83
|
homepage: http://appflux.io
|
56
84
|
licenses:
|
57
85
|
- MIT
|
@@ -76,4 +104,6 @@ rubygems_version: 2.2.2
|
|
76
104
|
signing_key:
|
77
105
|
specification_version: 4
|
78
106
|
summary: Ruby library for integration with http://appflux.io
|
79
|
-
test_files:
|
107
|
+
test_files:
|
108
|
+
- test/appflux-ruby_test.rb
|
109
|
+
- test/test_helper.rb
|