raygun4ruby 3.2.6 → 4.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +48 -0
- data/.gitignore +22 -21
- data/.rspec +1 -1
- data/Appraisals +19 -0
- data/CHANGELOG.md +169 -133
- data/Gemfile +4 -4
- data/LICENSE.txt +22 -22
- data/README.md +424 -420
- data/Rakefile +32 -27
- data/examples/sinatras_raygun.rb +17 -17
- data/gemfiles/rails_6.gemfile +9 -0
- data/gemfiles/rails_7.gemfile +10 -0
- data/gemfiles/rails_7_sidekiq_6.gemfile +10 -0
- data/lib/generators/raygun/install_generator.rb +26 -26
- data/lib/raygun/affected_user.rb +59 -59
- data/lib/raygun/breadcrumbs/breadcrumb.rb +34 -34
- data/lib/raygun/breadcrumbs/store.rb +86 -86
- data/lib/raygun/breadcrumbs.rb +34 -34
- data/lib/raygun/client.rb +313 -308
- data/lib/raygun/configuration.rb +197 -194
- data/lib/raygun/demo_exception.rb +22 -22
- data/lib/raygun/error.rb +10 -10
- data/lib/raygun/error_subscriber.rb +21 -0
- data/lib/raygun/javascript_tracker.rb +42 -42
- data/lib/raygun/middleware/breadcrumbs_store_initializer.rb +19 -19
- data/lib/raygun/middleware/javascript_exception_tracking.rb +40 -32
- data/lib/raygun/middleware/rack_exception_interceptor.rb +18 -18
- data/lib/raygun/middleware/rails_insert_affected_user.rb +26 -26
- data/lib/raygun/railtie.rb +47 -39
- data/lib/raygun/services/apply_whitelist_filter_to_payload.rb +27 -27
- data/lib/raygun/sidekiq.rb +51 -71
- data/lib/raygun/version.rb +3 -3
- data/lib/raygun.rb +197 -179
- data/lib/raygun4ruby.rb +1 -1
- data/lib/resque/failure/raygun.rb +25 -25
- data/lib/tasks/raygun.tasks +7 -7
- data/raygun4ruby.gemspec +43 -45
- data/spec/features/javascript_spec.rb +48 -48
- data/spec/rails_applications/6.1.4/Gemfile +56 -0
- data/spec/{dummy/README.rdoc → rails_applications/6.1.4/README.md} +24 -28
- data/spec/{dummy → rails_applications/6.1.4}/Rakefile +6 -6
- data/spec/rails_applications/6.1.4/app/assets/config/manifest.js +2 -0
- data/spec/{dummy → rails_applications/6.1.4}/app/assets/images/.keep +0 -0
- data/spec/{dummy → rails_applications/6.1.4}/app/assets/stylesheets/application.css +15 -15
- data/spec/rails_applications/6.1.4/app/channels/application_cable/channel.rb +4 -0
- data/spec/rails_applications/6.1.4/app/channels/application_cable/connection.rb +4 -0
- data/spec/rails_applications/6.1.4/app/controllers/application_controller.rb +2 -0
- data/spec/{dummy → rails_applications/6.1.4}/app/controllers/concerns/.keep +0 -0
- data/spec/{dummy → rails_applications/6.1.4}/app/controllers/home_controller.rb +4 -4
- data/spec/{dummy → rails_applications/6.1.4}/app/helpers/application_helper.rb +2 -2
- data/spec/rails_applications/6.1.4/app/javascript/channels/consumer.js +6 -0
- data/spec/rails_applications/6.1.4/app/javascript/channels/index.js +5 -0
- data/spec/rails_applications/6.1.4/app/javascript/packs/application.js +13 -0
- data/spec/rails_applications/6.1.4/app/jobs/application_job.rb +7 -0
- data/spec/rails_applications/6.1.4/app/mailers/application_mailer.rb +4 -0
- data/spec/rails_applications/6.1.4/app/models/application_record.rb +3 -0
- data/spec/{dummy/app/mailers → rails_applications/6.1.4/app/models/concerns}/.keep +0 -0
- data/spec/{dummy → rails_applications/6.1.4}/app/views/home/index.html.erb +3 -3
- data/spec/{dummy → rails_applications/6.1.4}/app/views/home/index.json.erb +1 -1
- data/spec/rails_applications/6.1.4/app/views/layouts/application.html.erb +13 -0
- data/spec/rails_applications/6.1.4/app/views/layouts/mailer.html.erb +13 -0
- data/spec/rails_applications/6.1.4/app/views/layouts/mailer.text.erb +1 -0
- data/spec/rails_applications/6.1.4/bin/rails +5 -0
- data/spec/rails_applications/6.1.4/bin/rake +5 -0
- data/spec/rails_applications/6.1.4/bin/setup +36 -0
- data/spec/rails_applications/6.1.4/bin/spring +14 -0
- data/spec/rails_applications/6.1.4/bin/yarn +17 -0
- data/spec/rails_applications/6.1.4/config/application.rb +22 -0
- data/spec/rails_applications/6.1.4/config/boot.rb +3 -0
- data/spec/rails_applications/6.1.4/config/cable.yml +10 -0
- data/spec/rails_applications/6.1.4/config/credentials.yml.enc +1 -0
- data/spec/{dummy → rails_applications/6.1.4}/config/database.yml +25 -25
- data/spec/{dummy → rails_applications/6.1.4}/config/environment.rb +5 -5
- data/spec/rails_applications/6.1.4/config/environments/development.rb +76 -0
- data/spec/rails_applications/6.1.4/config/environments/production.rb +120 -0
- data/spec/rails_applications/6.1.4/config/environments/test.rb +60 -0
- data/spec/rails_applications/6.1.4/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/rails_applications/6.1.4/config/initializers/assets.rb +14 -0
- data/spec/rails_applications/6.1.4/config/initializers/backtrace_silencers.rb +8 -0
- data/spec/rails_applications/6.1.4/config/initializers/content_security_policy.rb +30 -0
- data/spec/{dummy → rails_applications/6.1.4}/config/initializers/cookies_serializer.rb +5 -3
- data/spec/{dummy → rails_applications/6.1.4}/config/initializers/filter_parameter_logging.rb +6 -4
- data/spec/{dummy → rails_applications/6.1.4}/config/initializers/inflections.rb +16 -16
- data/spec/{dummy → rails_applications/6.1.4}/config/initializers/mime_types.rb +4 -4
- data/spec/rails_applications/6.1.4/config/initializers/permissions_policy.rb +11 -0
- data/spec/{dummy → rails_applications/6.1.4}/config/initializers/wrap_parameters.rb +14 -14
- data/spec/{dummy → rails_applications/6.1.4}/config/locales/en.yml +33 -23
- data/spec/rails_applications/6.1.4/config/master.key +1 -0
- data/spec/rails_applications/6.1.4/config/puma.rb +43 -0
- data/spec/rails_applications/6.1.4/config/routes.rb +4 -0
- data/spec/rails_applications/6.1.4/config/spring.rb +6 -0
- data/spec/rails_applications/6.1.4/config/storage.yml +34 -0
- data/spec/{dummy → rails_applications/6.1.4}/config.ru +6 -4
- data/spec/rails_applications/6.1.4/db/seeds.rb +7 -0
- data/spec/{dummy → rails_applications/6.1.4}/db/test.sqlite3 +0 -0
- data/spec/{dummy/app/models → rails_applications/6.1.4/lib/assets}/.keep +0 -0
- data/spec/{dummy/app/models/concerns → rails_applications/6.1.4/lib/tasks}/.keep +0 -0
- data/spec/rails_applications/6.1.4/package.json +11 -0
- data/spec/{dummy → rails_applications/6.1.4}/public/404.html +67 -67
- data/spec/{dummy → rails_applications/6.1.4}/public/422.html +67 -67
- data/spec/{dummy → rails_applications/6.1.4}/public/500.html +66 -66
- data/spec/{dummy/lib/assets/.keep → rails_applications/6.1.4/public/apple-touch-icon-precomposed.png} +0 -0
- data/spec/{dummy/lib/tasks/.keep → rails_applications/6.1.4/public/apple-touch-icon.png} +0 -0
- data/spec/{dummy → rails_applications/6.1.4}/public/favicon.ico +0 -0
- data/spec/rails_applications/6.1.4/public/robots.txt +1 -0
- data/spec/{dummy/log → rails_applications/6.1.4/storage}/.keep +0 -0
- data/spec/rails_applications/7.1.3/.dockerignore +37 -0
- data/spec/rails_applications/7.1.3/.gitattributes +9 -0
- data/spec/rails_applications/7.1.3/.gitignore +35 -0
- data/spec/rails_applications/7.1.3/.ruby-version +1 -0
- data/spec/rails_applications/7.1.3/Dockerfile +62 -0
- data/spec/rails_applications/7.1.3/Gemfile +67 -0
- data/spec/rails_applications/7.1.3/README.md +24 -0
- data/spec/rails_applications/7.1.3/Rakefile +6 -0
- data/spec/rails_applications/7.1.3/app/assets/config/manifest.js +4 -0
- data/spec/{dummy/test/controllers → rails_applications/7.1.3/app/assets/images}/.keep +0 -0
- data/spec/rails_applications/7.1.3/app/assets/stylesheets/application.css +15 -0
- data/spec/rails_applications/7.1.3/app/channels/application_cable/channel.rb +4 -0
- data/spec/rails_applications/7.1.3/app/channels/application_cable/connection.rb +4 -0
- data/spec/rails_applications/7.1.3/app/controllers/application_controller.rb +2 -0
- data/spec/{dummy/test/fixtures → rails_applications/7.1.3/app/controllers/concerns}/.keep +0 -0
- data/spec/rails_applications/7.1.3/app/controllers/home_controller.rb +2 -0
- data/spec/rails_applications/7.1.3/app/helpers/application_helper.rb +2 -0
- data/spec/rails_applications/7.1.3/app/helpers/home_helper.rb +2 -0
- data/spec/rails_applications/7.1.3/app/javascript/application.js +3 -0
- data/spec/rails_applications/7.1.3/app/javascript/controllers/application.js +9 -0
- data/spec/rails_applications/7.1.3/app/javascript/controllers/hello_controller.js +7 -0
- data/spec/rails_applications/7.1.3/app/javascript/controllers/index.js +11 -0
- data/spec/rails_applications/7.1.3/app/jobs/application_job.rb +7 -0
- data/spec/rails_applications/7.1.3/app/mailers/application_mailer.rb +4 -0
- data/spec/rails_applications/7.1.3/app/models/application_record.rb +3 -0
- data/spec/{dummy/test/helpers → rails_applications/7.1.3/app/models/concerns}/.keep +0 -0
- data/spec/rails_applications/7.1.3/app/views/home/index.html.erb +3 -0
- data/spec/rails_applications/7.1.3/app/views/home/index.json.erb +1 -0
- data/spec/rails_applications/7.1.3/app/views/layouts/application.html.erb +16 -0
- data/spec/rails_applications/7.1.3/app/views/layouts/mailer.html.erb +13 -0
- data/spec/rails_applications/7.1.3/app/views/layouts/mailer.text.erb +1 -0
- data/spec/rails_applications/7.1.3/bin/bundle +109 -0
- data/spec/rails_applications/7.1.3/bin/docker-entrypoint +8 -0
- data/spec/rails_applications/7.1.3/bin/importmap +4 -0
- data/spec/rails_applications/7.1.3/bin/rails +4 -0
- data/spec/rails_applications/7.1.3/bin/rake +4 -0
- data/spec/rails_applications/7.1.3/bin/setup +33 -0
- data/spec/rails_applications/7.1.3/config/application.rb +27 -0
- data/spec/rails_applications/7.1.3/config/boot.rb +4 -0
- data/spec/rails_applications/7.1.3/config/cable.yml +11 -0
- data/spec/rails_applications/7.1.3/config/credentials.yml.enc +1 -0
- data/spec/rails_applications/7.1.3/config/database.yml +25 -0
- data/spec/rails_applications/7.1.3/config/environment.rb +5 -0
- data/spec/rails_applications/7.1.3/config/environments/development.rb +76 -0
- data/spec/rails_applications/7.1.3/config/environments/production.rb +97 -0
- data/spec/rails_applications/7.1.3/config/environments/test.rb +64 -0
- data/spec/rails_applications/7.1.3/config/importmap.rb +7 -0
- data/spec/rails_applications/7.1.3/config/initializers/assets.rb +12 -0
- data/spec/rails_applications/7.1.3/config/initializers/content_security_policy.rb +25 -0
- data/spec/rails_applications/7.1.3/config/initializers/filter_parameter_logging.rb +8 -0
- data/spec/rails_applications/7.1.3/config/initializers/inflections.rb +16 -0
- data/spec/rails_applications/7.1.3/config/initializers/permissions_policy.rb +13 -0
- data/spec/rails_applications/7.1.3/config/locales/en.yml +31 -0
- data/spec/rails_applications/7.1.3/config/puma.rb +35 -0
- data/spec/rails_applications/7.1.3/config/routes.rb +11 -0
- data/spec/rails_applications/7.1.3/config/storage.yml +34 -0
- data/spec/rails_applications/7.1.3/config.ru +6 -0
- data/spec/rails_applications/7.1.3/db/seeds.rb +9 -0
- data/spec/{dummy/test/integration → rails_applications/7.1.3/lib/assets}/.keep +0 -0
- data/spec/{dummy/test/mailers → rails_applications/7.1.3/lib/tasks}/.keep +0 -0
- data/spec/rails_applications/7.1.3/public/404.html +67 -0
- data/spec/rails_applications/7.1.3/public/422.html +67 -0
- data/spec/rails_applications/7.1.3/public/500.html +66 -0
- data/spec/{dummy/test/models/.keep → rails_applications/7.1.3/public/apple-touch-icon-precomposed.png} +0 -0
- data/spec/{dummy/vendor/assets/javascripts/.keep → rails_applications/7.1.3/public/apple-touch-icon.png} +0 -0
- data/spec/{dummy/vendor/assets/stylesheets/.keep → rails_applications/7.1.3/public/favicon.ico} +0 -0
- data/spec/rails_applications/7.1.3/public/robots.txt +1 -0
- data/spec/rails_applications/7.1.3/storage/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/application_system_test_case.rb +5 -0
- data/spec/rails_applications/7.1.3/test/channels/application_cable/connection_test.rb +13 -0
- data/spec/rails_applications/7.1.3/test/controllers/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/controllers/home_controller_test.rb +7 -0
- data/spec/rails_applications/7.1.3/test/fixtures/files/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/helpers/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/integration/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/mailers/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/models/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/system/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/test_helper.rb +15 -0
- data/spec/rails_applications/7.1.3/vendor/.keep +0 -0
- data/spec/rails_applications/7.1.3/vendor/javascript/.keep +0 -0
- data/spec/rails_helper.rb +8 -4
- data/spec/raygun/breadcrumbs/breadcrumb_spec.rb +171 -171
- data/spec/raygun/breadcrumbs/store_spec.rb +170 -170
- data/spec/services/apply_whitelist_filter_to_payload_spec.rb +251 -251
- data/spec/spec_helper.rb +24 -24
- data/spec/support/fake_logger.rb +17 -17
- data/test/integration/client_test.rb +19 -19
- data/test/rails_helper.rb +6 -0
- data/test/test_helper.rb +76 -72
- data/test/unit/affected_user_test.rb +136 -136
- data/test/unit/client_test.rb +812 -812
- data/test/unit/configuration_test.rb +202 -206
- data/test/unit/error_subscriber_test.rb +43 -0
- data/test/unit/raygun_test.rb +106 -25
- data/test/unit/resque_failure_test.rb +27 -24
- data/test/unit/sidekiq_failure_test.rb +42 -32
- metadata +186 -125
- data/.travis.yml +0 -20
- data/spec/dummy/.gitignore +0 -17
- data/spec/dummy/Gemfile +0 -47
- data/spec/dummy/app/assets/config/manifest.js +0 -3
- data/spec/dummy/app/assets/javascripts/application.js +0 -13
- data/spec/dummy/app/controllers/application_controller.rb +0 -5
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/bin/bundle +0 -3
- data/spec/dummy/bin/rails +0 -9
- data/spec/dummy/bin/rake +0 -9
- data/spec/dummy/bin/setup +0 -29
- data/spec/dummy/bin/spring +0 -17
- data/spec/dummy/config/application.rb +0 -26
- data/spec/dummy/config/boot.rb +0 -3
- data/spec/dummy/config/environments/development.rb +0 -41
- data/spec/dummy/config/environments/production.rb +0 -79
- data/spec/dummy/config/environments/test.rb +0 -42
- data/spec/dummy/config/initializers/assets.rb +0 -11
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/initializers/to_time_preserves_timezone.rb +0 -10
- data/spec/dummy/config/routes.rb +0 -58
- data/spec/dummy/config/secrets.yml +0 -22
- data/spec/dummy/db/seeds.rb +0 -7
- data/spec/dummy/public/robots.txt +0 -5
- data/spec/dummy/test/test_helper.rb +0 -10
- data/spec/raygun/raygun_spec.rb +0 -47
data/lib/raygun/client.rb
CHANGED
@@ -1,308 +1,313 @@
|
|
1
|
-
module Raygun
|
2
|
-
# client for the Raygun REST APIv1
|
3
|
-
# as per https://raygun.com/documentation/product-guides/crash-reporting/api/
|
4
|
-
class Client
|
5
|
-
|
6
|
-
ENV_IP_ADDRESS_KEYS = %w(action_dispatch.remote_ip raygun.remote_ip REMOTE_ADDR)
|
7
|
-
NO_API_KEY_MESSAGE = "[RAYGUN] Just a note, you've got no API Key configured, which means we can't report exceptions. Specify your Raygun API key using Raygun#setup (find yours at https://app.raygun.com)"
|
8
|
-
MAX_BREADCRUMBS_SIZE = 100_000
|
9
|
-
|
10
|
-
include HTTParty
|
11
|
-
|
12
|
-
def initialize
|
13
|
-
@api_key = require_api_key
|
14
|
-
@headers = {
|
15
|
-
"X-ApiKey" => @api_key
|
16
|
-
}
|
17
|
-
|
18
|
-
enable_http_proxy if Raygun.configuration.proxy_settings[:address]
|
19
|
-
self.class.base_uri Raygun.configuration.api_url
|
20
|
-
self.class.default_timeout(Raygun.configuration.error_report_send_timeout)
|
21
|
-
end
|
22
|
-
|
23
|
-
def require_api_key
|
24
|
-
Raygun.configuration.api_key || print_api_key_warning
|
25
|
-
end
|
26
|
-
|
27
|
-
def track_exception(exception_instance, env = {}, user = nil)
|
28
|
-
create_entry(build_payload_hash(exception_instance, env, user))
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def enable_http_proxy
|
34
|
-
self.class.http_proxy(Raygun.configuration.proxy_settings[:address],
|
35
|
-
Raygun.configuration.proxy_settings[:port] || "80",
|
36
|
-
Raygun.configuration.proxy_settings[:username],
|
37
|
-
Raygun.configuration.proxy_settings[:password])
|
38
|
-
end
|
39
|
-
|
40
|
-
def client_details
|
41
|
-
{
|
42
|
-
name: Raygun::CLIENT_NAME,
|
43
|
-
version: Raygun::VERSION,
|
44
|
-
clientUrl: Raygun::CLIENT_URL
|
45
|
-
}
|
46
|
-
end
|
47
|
-
|
48
|
-
def error_details(exception)
|
49
|
-
details = {
|
50
|
-
className: exception.class.to_s,
|
51
|
-
message: exception.message.to_s.encode('UTF-16', :undef => :replace, :invalid => :replace).encode('UTF-8'),
|
52
|
-
stackTrace: (exception.backtrace || []).map { |line| stack_trace_for(line) },
|
53
|
-
}
|
54
|
-
|
55
|
-
details.update(innerError: error_details(exception.cause)) if exception.respond_to?(:cause) && exception.cause
|
56
|
-
|
57
|
-
details
|
58
|
-
end
|
59
|
-
|
60
|
-
def stack_trace_for(line)
|
61
|
-
# see http://www.ruby-doc.org/core-2.0/Exception.html#method-i-backtrace
|
62
|
-
file_name, line_number, method = line.split(":")
|
63
|
-
{
|
64
|
-
lineNumber: line_number,
|
65
|
-
fileName: file_name,
|
66
|
-
methodName: method ? method.gsub(/^in `(.*?)'$/, "\\1") : "(none)"
|
67
|
-
}
|
68
|
-
end
|
69
|
-
|
70
|
-
def hostname
|
71
|
-
Socket.gethostname
|
72
|
-
end
|
73
|
-
|
74
|
-
def version
|
75
|
-
Raygun.configuration.version
|
76
|
-
end
|
77
|
-
|
78
|
-
def user_information(env)
|
79
|
-
env["raygun.affected_user"]
|
80
|
-
end
|
81
|
-
|
82
|
-
def affected_user_present?(env)
|
83
|
-
!!env["raygun.affected_user"]
|
84
|
-
end
|
85
|
-
|
86
|
-
def rack_env
|
87
|
-
ENV["RACK_ENV"]
|
88
|
-
end
|
89
|
-
|
90
|
-
def rails_env
|
91
|
-
ENV["RAILS_ENV"]
|
92
|
-
end
|
93
|
-
|
94
|
-
def request_information(env)
|
95
|
-
Raygun.log('retrieving request information')
|
96
|
-
|
97
|
-
return {} if env.nil? || env.empty?
|
98
|
-
{
|
99
|
-
hostName: env["SERVER_NAME"],
|
100
|
-
url: env["PATH_INFO"],
|
101
|
-
httpMethod: env["REQUEST_METHOD"],
|
102
|
-
iPAddress: "#{ip_address_from(env)}",
|
103
|
-
queryString: Rack::Utils.parse_nested_query(env["QUERY_STRING"]),
|
104
|
-
headers: headers(env),
|
105
|
-
form: form_params(env),
|
106
|
-
rawData: raw_data(env)
|
107
|
-
}
|
108
|
-
end
|
109
|
-
|
110
|
-
def headers(rack_env)
|
111
|
-
rack_env.select { |k, v| k.to_s.start_with?("HTTP_") }.inject({}) do |hsh, (k, v)|
|
112
|
-
hsh[normalize_raygun_header_key(k)] = v
|
113
|
-
hsh
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def normalize_raygun_header_key(key)
|
118
|
-
key.sub(/^HTTP_/, '')
|
119
|
-
.sub(/_/, ' ')
|
120
|
-
.split.map(&:capitalize).join(' ')
|
121
|
-
.sub(/ /, '-')
|
122
|
-
end
|
123
|
-
|
124
|
-
def form_params(env)
|
125
|
-
Raygun.log('retrieving form params')
|
126
|
-
|
127
|
-
params = action_dispatch_params(env) || rack_params(env) || {}
|
128
|
-
filter_params_with_blacklist(params, env["action_dispatch.parameter_filter"])
|
129
|
-
end
|
130
|
-
|
131
|
-
def action_dispatch_params(env)
|
132
|
-
env["action_dispatch.request.parameters"]
|
133
|
-
end
|
134
|
-
|
135
|
-
def rack_params(env)
|
136
|
-
request = Rack::Request.new(env)
|
137
|
-
request.params if env["rack.input"]
|
138
|
-
end
|
139
|
-
|
140
|
-
def raw_data(rack_env)
|
141
|
-
Raygun.log('retrieving raw data')
|
142
|
-
request = Rack::Request.new(rack_env)
|
143
|
-
|
144
|
-
return unless Raygun.configuration.record_raw_data
|
145
|
-
return if request.get?
|
146
|
-
Raygun.log('passed raw_data checks')
|
147
|
-
|
148
|
-
input = rack_env['rack.input']
|
149
|
-
|
150
|
-
if input && !request.form_data?
|
151
|
-
input.rewind
|
152
|
-
|
153
|
-
body = input.read(4096) || ''
|
154
|
-
input.rewind
|
155
|
-
|
156
|
-
body
|
157
|
-
else
|
158
|
-
{}
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
def filter_custom_data(env)
|
163
|
-
params = env.delete(:custom_data) || {}
|
164
|
-
filter_params_with_blacklist(params, env["action_dispatch.parameter_filter"])
|
165
|
-
end
|
166
|
-
|
167
|
-
# see https://raygun.com/documentation/product-guides/crash-reporting/api/
|
168
|
-
def build_payload_hash(exception_instance, env = {}, user = nil)
|
169
|
-
Raygun.log('building payload hash')
|
170
|
-
custom_data = filter_custom_data(env) || {}
|
171
|
-
exception_custom_data = if exception_instance.respond_to?(:raygun_custom_data)
|
172
|
-
exception_instance.raygun_custom_data
|
173
|
-
else
|
174
|
-
{}
|
175
|
-
end
|
176
|
-
|
177
|
-
tags = env.delete(:tags) || []
|
178
|
-
|
179
|
-
if rails_env
|
180
|
-
tags << rails_env
|
181
|
-
else
|
182
|
-
tags << rack_env
|
183
|
-
end
|
184
|
-
|
185
|
-
combined_tags = []
|
186
|
-
|
187
|
-
if Raygun.configuration.tags.is_a?(Proc)
|
188
|
-
configuration_tags = Raygun.configuration.tags.call(exception_instance, env)
|
189
|
-
else
|
190
|
-
configuration_tags = Raygun.configuration.tags
|
191
|
-
end
|
192
|
-
|
193
|
-
combined_tags.concat(configuration_tags)
|
194
|
-
|
195
|
-
Raygun.log('set tags')
|
196
|
-
|
197
|
-
grouping_key = env.delete(:grouping_key)
|
198
|
-
correlation_id = env.delete(:correlation_id)
|
199
|
-
|
200
|
-
configuration_custom_data = Raygun.configuration.custom_data
|
201
|
-
configured_custom_data = if configuration_custom_data.is_a?(Proc)
|
202
|
-
configuration_custom_data.call(exception_instance, env)
|
203
|
-
else
|
204
|
-
configuration_custom_data
|
205
|
-
end
|
206
|
-
|
207
|
-
Raygun.log('set custom data')
|
208
|
-
|
209
|
-
error_details = {
|
210
|
-
machineName: hostname,
|
211
|
-
version: version,
|
212
|
-
client: client_details,
|
213
|
-
error: error_details(exception_instance),
|
214
|
-
userCustomData: exception_custom_data.merge(custom_data).merge(configured_custom_data),
|
215
|
-
tags: combined_tags.concat(tags).compact.uniq,
|
216
|
-
request: request_information(env),
|
217
|
-
environment: {
|
218
|
-
utcOffset: Time.now.utc_offset / 3600
|
219
|
-
}
|
220
|
-
}
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
Raygun.
|
225
|
-
|
226
|
-
|
227
|
-
error_details.
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
1
|
+
module Raygun
|
2
|
+
# client for the Raygun REST APIv1
|
3
|
+
# as per https://raygun.com/documentation/product-guides/crash-reporting/api/
|
4
|
+
class Client
|
5
|
+
|
6
|
+
ENV_IP_ADDRESS_KEYS = %w(action_dispatch.remote_ip raygun.remote_ip REMOTE_ADDR)
|
7
|
+
NO_API_KEY_MESSAGE = "[RAYGUN] Just a note, you've got no API Key configured, which means we can't report exceptions. Specify your Raygun API key using Raygun#setup (find yours at https://app.raygun.com)"
|
8
|
+
MAX_BREADCRUMBS_SIZE = 100_000
|
9
|
+
|
10
|
+
include HTTParty
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@api_key = require_api_key
|
14
|
+
@headers = {
|
15
|
+
"X-ApiKey" => @api_key
|
16
|
+
}
|
17
|
+
|
18
|
+
enable_http_proxy if Raygun.configuration.proxy_settings[:address]
|
19
|
+
self.class.base_uri Raygun.configuration.api_url
|
20
|
+
self.class.default_timeout(Raygun.configuration.error_report_send_timeout)
|
21
|
+
end
|
22
|
+
|
23
|
+
def require_api_key
|
24
|
+
Raygun.configuration.api_key || print_api_key_warning
|
25
|
+
end
|
26
|
+
|
27
|
+
def track_exception(exception_instance, env = {}, user = nil)
|
28
|
+
create_entry(build_payload_hash(exception_instance, env, user))
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def enable_http_proxy
|
34
|
+
self.class.http_proxy(Raygun.configuration.proxy_settings[:address],
|
35
|
+
Raygun.configuration.proxy_settings[:port] || "80",
|
36
|
+
Raygun.configuration.proxy_settings[:username],
|
37
|
+
Raygun.configuration.proxy_settings[:password])
|
38
|
+
end
|
39
|
+
|
40
|
+
def client_details
|
41
|
+
{
|
42
|
+
name: Raygun::CLIENT_NAME,
|
43
|
+
version: Raygun::VERSION,
|
44
|
+
clientUrl: Raygun::CLIENT_URL
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def error_details(exception)
|
49
|
+
details = {
|
50
|
+
className: exception.class.to_s,
|
51
|
+
message: exception.message.to_s.encode('UTF-16', :undef => :replace, :invalid => :replace).encode('UTF-8'),
|
52
|
+
stackTrace: (exception.backtrace || []).map { |line| stack_trace_for(line) },
|
53
|
+
}
|
54
|
+
|
55
|
+
details.update(innerError: error_details(exception.cause)) if exception.respond_to?(:cause) && exception.cause
|
56
|
+
|
57
|
+
details
|
58
|
+
end
|
59
|
+
|
60
|
+
def stack_trace_for(line)
|
61
|
+
# see http://www.ruby-doc.org/core-2.0/Exception.html#method-i-backtrace
|
62
|
+
file_name, line_number, method = line.split(":")
|
63
|
+
{
|
64
|
+
lineNumber: line_number,
|
65
|
+
fileName: file_name,
|
66
|
+
methodName: method ? method.gsub(/^in `(.*?)'$/, "\\1") : "(none)"
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
def hostname
|
71
|
+
Socket.gethostname
|
72
|
+
end
|
73
|
+
|
74
|
+
def version
|
75
|
+
Raygun.configuration.version
|
76
|
+
end
|
77
|
+
|
78
|
+
def user_information(env)
|
79
|
+
env["raygun.affected_user"]
|
80
|
+
end
|
81
|
+
|
82
|
+
def affected_user_present?(env)
|
83
|
+
!!env["raygun.affected_user"]
|
84
|
+
end
|
85
|
+
|
86
|
+
def rack_env
|
87
|
+
ENV["RACK_ENV"]
|
88
|
+
end
|
89
|
+
|
90
|
+
def rails_env
|
91
|
+
ENV["RAILS_ENV"]
|
92
|
+
end
|
93
|
+
|
94
|
+
def request_information(env)
|
95
|
+
Raygun.log('retrieving request information')
|
96
|
+
|
97
|
+
return {} if env.nil? || env.empty?
|
98
|
+
{
|
99
|
+
hostName: env["SERVER_NAME"],
|
100
|
+
url: env["PATH_INFO"],
|
101
|
+
httpMethod: env["REQUEST_METHOD"],
|
102
|
+
iPAddress: "#{ip_address_from(env)}",
|
103
|
+
queryString: Rack::Utils.parse_nested_query(env["QUERY_STRING"]),
|
104
|
+
headers: headers(env),
|
105
|
+
form: form_params(env),
|
106
|
+
rawData: raw_data(env)
|
107
|
+
}
|
108
|
+
end
|
109
|
+
|
110
|
+
def headers(rack_env)
|
111
|
+
rack_env.select { |k, v| k.to_s.start_with?("HTTP_") }.inject({}) do |hsh, (k, v)|
|
112
|
+
hsh[normalize_raygun_header_key(k)] = v
|
113
|
+
hsh
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def normalize_raygun_header_key(key)
|
118
|
+
key.sub(/^HTTP_/, '')
|
119
|
+
.sub(/_/, ' ')
|
120
|
+
.split.map(&:capitalize).join(' ')
|
121
|
+
.sub(/ /, '-')
|
122
|
+
end
|
123
|
+
|
124
|
+
def form_params(env)
|
125
|
+
Raygun.log('retrieving form params')
|
126
|
+
|
127
|
+
params = action_dispatch_params(env) || rack_params(env) || {}
|
128
|
+
filter_params_with_blacklist(params, env["action_dispatch.parameter_filter"])
|
129
|
+
end
|
130
|
+
|
131
|
+
def action_dispatch_params(env)
|
132
|
+
env["action_dispatch.request.parameters"]
|
133
|
+
end
|
134
|
+
|
135
|
+
def rack_params(env)
|
136
|
+
request = Rack::Request.new(env)
|
137
|
+
request.params if env["rack.input"]
|
138
|
+
end
|
139
|
+
|
140
|
+
def raw_data(rack_env)
|
141
|
+
Raygun.log('retrieving raw data')
|
142
|
+
request = Rack::Request.new(rack_env)
|
143
|
+
|
144
|
+
return unless Raygun.configuration.record_raw_data
|
145
|
+
return if request.get?
|
146
|
+
Raygun.log('passed raw_data checks')
|
147
|
+
|
148
|
+
input = rack_env['rack.input']
|
149
|
+
|
150
|
+
if input && !request.form_data?
|
151
|
+
input.rewind
|
152
|
+
|
153
|
+
body = input.read(4096) || ''
|
154
|
+
input.rewind
|
155
|
+
|
156
|
+
body
|
157
|
+
else
|
158
|
+
{}
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def filter_custom_data(env)
|
163
|
+
params = env.delete(:custom_data) || {}
|
164
|
+
filter_params_with_blacklist(params, env["action_dispatch.parameter_filter"])
|
165
|
+
end
|
166
|
+
|
167
|
+
# see https://raygun.com/documentation/product-guides/crash-reporting/api/
|
168
|
+
def build_payload_hash(exception_instance, env = {}, user = nil)
|
169
|
+
Raygun.log('building payload hash')
|
170
|
+
custom_data = filter_custom_data(env) || {}
|
171
|
+
exception_custom_data = if exception_instance.respond_to?(:raygun_custom_data)
|
172
|
+
exception_instance.raygun_custom_data
|
173
|
+
else
|
174
|
+
{}
|
175
|
+
end
|
176
|
+
|
177
|
+
tags = env.delete(:tags) || []
|
178
|
+
|
179
|
+
if rails_env
|
180
|
+
tags << rails_env
|
181
|
+
else
|
182
|
+
tags << rack_env
|
183
|
+
end
|
184
|
+
|
185
|
+
combined_tags = []
|
186
|
+
|
187
|
+
if Raygun.configuration.tags.is_a?(Proc)
|
188
|
+
configuration_tags = Raygun.configuration.tags.call(exception_instance, env)
|
189
|
+
else
|
190
|
+
configuration_tags = Raygun.configuration.tags
|
191
|
+
end
|
192
|
+
|
193
|
+
combined_tags.concat(configuration_tags)
|
194
|
+
|
195
|
+
Raygun.log('set tags')
|
196
|
+
|
197
|
+
grouping_key = env.delete(:grouping_key)
|
198
|
+
correlation_id = env.delete(:correlation_id)
|
199
|
+
|
200
|
+
configuration_custom_data = Raygun.configuration.custom_data
|
201
|
+
configured_custom_data = if configuration_custom_data.is_a?(Proc)
|
202
|
+
configuration_custom_data.call(exception_instance, env)
|
203
|
+
else
|
204
|
+
configuration_custom_data
|
205
|
+
end
|
206
|
+
|
207
|
+
Raygun.log('set custom data')
|
208
|
+
|
209
|
+
error_details = {
|
210
|
+
machineName: hostname,
|
211
|
+
version: version,
|
212
|
+
client: client_details,
|
213
|
+
error: error_details(exception_instance),
|
214
|
+
userCustomData: exception_custom_data.merge(custom_data).merge(configured_custom_data),
|
215
|
+
tags: combined_tags.concat(tags).compact.uniq,
|
216
|
+
request: request_information(env),
|
217
|
+
environment: {
|
218
|
+
utcOffset: Time.now.utc_offset / 3600
|
219
|
+
}
|
220
|
+
}
|
221
|
+
|
222
|
+
# If we have breadcrumbs passed to us as context from another thread, then include them
|
223
|
+
# Otherwise, use the default store (which is thread-local)
|
224
|
+
::Raygun::Breadcrumbs::Store.initialize(with: env.delete(:rg_breadcrumb_store)) if env.key?(:rg_breadcrumb_store)
|
225
|
+
|
226
|
+
store = ::Raygun::Breadcrumbs::Store
|
227
|
+
error_details[:breadcrumbs] = store.take_until_size(MAX_BREADCRUMBS_SIZE).map(&:build_payload) if store.any?
|
228
|
+
|
229
|
+
Raygun.log('set details and breadcrumbs')
|
230
|
+
|
231
|
+
error_details.merge!(groupingKey: grouping_key) if grouping_key
|
232
|
+
error_details.merge!(correlationId: correlation_id) if correlation_id
|
233
|
+
|
234
|
+
user_details = if affected_user_present?(env)
|
235
|
+
user_information(env)
|
236
|
+
elsif user != nil
|
237
|
+
AffectedUser.information_hash(user)
|
238
|
+
end
|
239
|
+
error_details.merge!(user: user_details) unless user_details == nil
|
240
|
+
|
241
|
+
Raygun.log('set user details')
|
242
|
+
|
243
|
+
if Raygun.configuration.filter_payload_with_whitelist
|
244
|
+
Raygun.log('filtering payload with whitelist')
|
245
|
+
error_details = filter_payload_with_whitelist(error_details)
|
246
|
+
end
|
247
|
+
|
248
|
+
{
|
249
|
+
occurredOn: Time.now.utc.iso8601,
|
250
|
+
details: error_details
|
251
|
+
}
|
252
|
+
end
|
253
|
+
|
254
|
+
def create_entry(payload_hash)
|
255
|
+
Raygun.log('sending payload to api')
|
256
|
+
|
257
|
+
self.class.post(
|
258
|
+
"/entries",
|
259
|
+
verify_peer: true,
|
260
|
+
verify: true,
|
261
|
+
headers: @headers,
|
262
|
+
body: JSON.generate(payload_hash),
|
263
|
+
)
|
264
|
+
end
|
265
|
+
|
266
|
+
def filter_params_with_blacklist(params_hash = {}, extra_filter_keys = nil)
|
267
|
+
filter_parameters = Raygun.configuration.filter_parameters
|
268
|
+
|
269
|
+
if filter_parameters.is_a? Proc
|
270
|
+
filter_parameters.call(params_hash)
|
271
|
+
else
|
272
|
+
filter_keys = (Array(extra_filter_keys) + filter_parameters).map(&:to_s)
|
273
|
+
|
274
|
+
filter_params_with_array(params_hash, filter_keys)
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
def filter_payload_with_whitelist(payload_hash)
|
279
|
+
shape = Raygun.configuration.whitelist_payload_shape
|
280
|
+
|
281
|
+
if shape.is_a? Proc
|
282
|
+
shape.call(payload_hash)
|
283
|
+
else
|
284
|
+
# Always keep the client hash, so force it to true here
|
285
|
+
Services::ApplyWhitelistFilterToPayload.new.call(shape.merge(client: true), payload_hash)
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
def filter_params_with_array(params_hash, filter_keys)
|
290
|
+
# Recursive filtering of (nested) hashes
|
291
|
+
(params_hash || {}).inject({}) do |result, (k, v)|
|
292
|
+
result[k] = case v
|
293
|
+
when Hash
|
294
|
+
filter_params_with_array(v, filter_keys)
|
295
|
+
else
|
296
|
+
filter_keys.any? { |fk| /#{fk}/i === k.to_s } ? "[FILTERED]" : v
|
297
|
+
end
|
298
|
+
result
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
def ip_address_from(env_hash)
|
303
|
+
ENV_IP_ADDRESS_KEYS.each do |key_to_try|
|
304
|
+
return env_hash[key_to_try] unless env_hash[key_to_try].nil? || env_hash[key_to_try] == ""
|
305
|
+
end
|
306
|
+
"(Not Available)"
|
307
|
+
end
|
308
|
+
|
309
|
+
def print_api_key_warning
|
310
|
+
$stderr.puts(NO_API_KEY_MESSAGE)
|
311
|
+
end
|
312
|
+
end
|
313
|
+
end
|