raygun4ruby 3.0.0 → 3.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.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +0 -2
  5. data/CHANGELOG.md +5 -0
  6. data/Rakefile +9 -2
  7. data/lib/raygun.rb +2 -0
  8. data/lib/raygun/configuration.rb +6 -0
  9. data/lib/raygun/javascript_tracker.rb +42 -0
  10. data/lib/raygun/middleware/javascript_exception_tracking.rb +30 -0
  11. data/lib/raygun/railtie.rb +2 -1
  12. data/lib/raygun/version.rb +1 -1
  13. data/raygun4ruby.gemspec +8 -1
  14. data/spec/dummy/.ruby-version +1 -0
  15. data/spec/dummy/Rakefile +6 -0
  16. data/spec/dummy/app/assets/config/manifest.js +3 -0
  17. data/spec/dummy/app/assets/images/.keep +0 -0
  18. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  19. data/spec/dummy/app/assets/javascripts/cable.js +13 -0
  20. data/spec/dummy/app/assets/javascripts/channels/.keep +0 -0
  21. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  22. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  23. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  24. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  25. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  26. data/spec/dummy/app/controllers/home_controller.rb +4 -0
  27. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  28. data/spec/dummy/app/jobs/application_job.rb +2 -0
  29. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  30. data/spec/dummy/app/models/application_record.rb +3 -0
  31. data/spec/dummy/app/models/concerns/.keep +0 -0
  32. data/spec/dummy/app/views/home/index.html.erb +3 -0
  33. data/spec/dummy/app/views/home/index.json.erb +1 -0
  34. data/spec/dummy/app/views/layouts/application.html.erb +15 -0
  35. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  36. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  37. data/spec/dummy/bin/bundle +3 -0
  38. data/spec/dummy/bin/rails +4 -0
  39. data/spec/dummy/bin/rake +4 -0
  40. data/spec/dummy/bin/setup +36 -0
  41. data/spec/dummy/bin/update +31 -0
  42. data/spec/dummy/bin/yarn +11 -0
  43. data/spec/dummy/config.ru +5 -0
  44. data/spec/dummy/config/application.rb +18 -0
  45. data/spec/dummy/config/boot.rb +5 -0
  46. data/spec/dummy/config/cable.yml +10 -0
  47. data/spec/dummy/config/database.yml +25 -0
  48. data/spec/dummy/config/environment.rb +5 -0
  49. data/spec/dummy/config/environments/development.rb +61 -0
  50. data/spec/dummy/config/environments/production.rb +94 -0
  51. data/spec/dummy/config/environments/test.rb +46 -0
  52. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  53. data/spec/dummy/config/initializers/assets.rb +14 -0
  54. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  55. data/spec/dummy/config/initializers/content_security_policy.rb +25 -0
  56. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  57. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  58. data/spec/dummy/config/initializers/inflections.rb +16 -0
  59. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  60. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  61. data/spec/dummy/config/locales/en.yml +33 -0
  62. data/spec/dummy/config/puma.rb +34 -0
  63. data/spec/dummy/config/routes.rb +3 -0
  64. data/spec/dummy/config/spring.rb +6 -0
  65. data/spec/dummy/config/storage.yml +34 -0
  66. data/spec/dummy/db/schema.rb +15 -0
  67. data/spec/dummy/db/test.sqlite3 +0 -0
  68. data/spec/dummy/lib/assets/.keep +0 -0
  69. data/spec/dummy/package.json +5 -0
  70. data/spec/dummy/public/404.html +67 -0
  71. data/spec/dummy/public/422.html +67 -0
  72. data/spec/dummy/public/500.html +66 -0
  73. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  74. data/spec/dummy/public/apple-touch-icon.png +0 -0
  75. data/spec/dummy/public/favicon.ico +0 -0
  76. data/spec/dummy/storage/.keep +0 -0
  77. data/spec/features/javascript_spec.rb +48 -0
  78. data/spec/rails_helper.rb +4 -0
  79. data/{specs → spec}/raygun/breadcrumbs/breadcrumb_spec.rb +19 -19
  80. data/{specs → spec}/raygun/breadcrumbs/store_spec.rb +21 -23
  81. data/{specs → spec}/raygun/raygun_spec.rb +5 -8
  82. data/{specs → spec}/services/apply_whitelist_filter_to_payload_spec.rb +9 -9
  83. data/spec/spec_helper.rb +24 -0
  84. data/spec/support/fake_logger.rb +17 -0
  85. data/test/test_helper.rb +1 -0
  86. data/test/unit/configuration_test.rb +12 -0
  87. metadata +163 -9
  88. data/specs/spec_helper.rb +0 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 61736f6afdee2839d8085205074cc3e36a0d1ab2
4
- data.tar.gz: 91f356594710741eec38c69f2e1122eb7bfdf3e9
3
+ metadata.gz: acbc458153d576b6856920cb72985952f9f6ed22
4
+ data.tar.gz: bb9976f64347bce6b6a6a6f3920564b489b478bb
5
5
  SHA512:
6
- metadata.gz: 1c5a29513ec9b6603e798381c89005802a87ac470bcfdb6e77f2287523d880f4db7dc0fe6122254e8f8722aa5e54fb5f418b72702fa1b4a2cb5defc69626556b
7
- data.tar.gz: b44748b701d56a4359644c679abe517ef9540049c9a8acd960babbe2614d68d27457ec2563298d625ed4485f6f2d6705ffc512bba0e6e4f36b3ed193b2cf0919
6
+ metadata.gz: d603e52d886065cf9cc7b26f6639a8f6c237447d2af106bd5e55b96e5d25b721b1b2607a34f25b71ef9ea5514252492dd7f584463d36a7dd2d614db1a00b66c1
7
+ data.tar.gz: 9c1f5c46f012cc003a32ed8829755f3c8321d3049c6b1c7c349063461674f6bf0a6c7114fb9bf444f8ce926c101cd9125c96f92438a34c2a6f1dd8322e650734
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ spec/dummy/log
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.travis.yml CHANGED
@@ -5,8 +5,6 @@ script:
5
5
  - bundle exec rake
6
6
 
7
7
  rvm:
8
- - 2.0.0
9
- - 2.2.5
10
8
  - 2.3.3
11
9
  - 2.4.0
12
10
 
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 3.1.0 (15/01/2019):
2
+
3
+ Feature:
4
+ - Ability to automatically configure Raygun4JS on the client side by injecting it into outbound HTML pages. Thanks @MikeRogers0 for this ([#138](https://github.com/MindscapeHQ/raygun4ruby/pull/138)])
5
+
1
6
  ## 3.0.0 (18/12/2018):
2
7
  Breaking changes:
3
8
  Parameter filters are now applied if you are using the `filter_payload_with_whitelist` functionality. Previously if this was set to true the parameter filtering was bailed out of ([#136](https://github.com/MindscapeHQ/raygun4ruby/pull/136/files))
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ namespace :test do
7
7
 
8
8
  desc "Test the basics of the adapter"
9
9
  Rake::TestTask.new(:units) do |t|
10
- t.test_files = FileList["test/unit/*_test.rb", "specs/**/*_spec.rb"]
10
+ t.test_files = FileList["test/unit/*_test.rb"]
11
11
  end
12
12
 
13
13
  desc "Run a test against the live API"
@@ -15,6 +15,13 @@ namespace :test do
15
15
  t.test_files = FileList["test/integration/*_test.rb"]
16
16
  end
17
17
 
18
+ begin
19
+ require 'rspec/core/rake_task'
20
+
21
+ RSpec::Core::RakeTask.new(:spec)
22
+
23
+ rescue LoadError
24
+ end
18
25
  end
19
26
 
20
- task default: "test:units"
27
+ task default: ["test:units", "test:spec"]
data/lib/raygun.rb CHANGED
@@ -14,8 +14,10 @@ end
14
14
  require "raygun/version"
15
15
  require "raygun/configuration"
16
16
  require "raygun/client"
17
+ require "raygun/javascript_tracker"
17
18
  require "raygun/middleware/rack_exception_interceptor"
18
19
  require "raygun/middleware/breadcrumbs_store_initializer"
20
+ require "raygun/middleware/javascript_exception_tracking"
19
21
  require "raygun/testable"
20
22
  require "raygun/error"
21
23
  require "raygun/affected_user"
@@ -25,6 +25,12 @@ module Raygun
25
25
  # Your Raygun API Key - this can be found on your dashboard at Raygun.io
26
26
  config_option :api_key
27
27
 
28
+ # Your JS Raygun API Key - Should be different to your api_key, it's best practice to separate your errors between front end and back end.
29
+ config_option :js_api_key
30
+
31
+ # Your JS Raygun API Version, defaults to latest as found on https://raygun.com/raygun-providers/javascript
32
+ config_option :js_api_version
33
+
28
34
  # Array of exception classes to ignore
29
35
  config_option :ignore
30
36
 
@@ -0,0 +1,42 @@
1
+ # Client for injecting JavaScript code for tracking front end exceptions
2
+ # https://raygun.com/docs/languages/javascript
3
+ module Raygun
4
+ class JavaScriptTracker
5
+ def head_html
6
+ return unless js_api_key?
7
+ [
8
+ '<script type="text/javascript">',
9
+ '!function(a,b,c,d,e,f,g,h){a.RaygunObject=e,a[e]=a[e]||function(){',
10
+ '(a[e].o=a[e].o||[]).push(arguments)},f=b.createElement(c),g=b.getElementsByTagName(c)[0],',
11
+ 'f.async=1,f.src=d,g.parentNode.insertBefore(f,g),h=a.onerror,a.onerror=function(b,c,d,f,g){',
12
+ 'h&&h(b,c,d,f,g),g||(g=new Error(b)),a[e].q=a[e].q||[],a[e].q.push({',
13
+ 'e:g})}}(window,document,"script","//cdn.raygun.io/raygun4js/' + js_api_version + 'raygun.min.js","rg4js");',
14
+ '</script>'
15
+ ].join('').html_safe
16
+ end
17
+
18
+ def body_html
19
+ return unless js_api_key?
20
+ [
21
+ '<script type="text/javascript">',
22
+ "rg4js('apiKey', '#{js_api_key}');",
23
+ "rg4js('enableCrashReporting', true);",
24
+ '</script>'
25
+ ].join('').html_safe
26
+ end
27
+
28
+ private
29
+
30
+ def js_api_key
31
+ @js_api_key ||= Raygun.configuration.js_api_key
32
+ end
33
+
34
+ def js_api_version
35
+ @js_api_version ||= Raygun.configuration.js_api_version ? "#{Raygun.configuration.js_api_version}/" : ''
36
+ end
37
+
38
+ def js_api_key?
39
+ js_api_key.present?
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,30 @@
1
+ module Raygun::Middleware
2
+ class JavascriptExceptionTracking
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ status, headers, response = @app.call(env)
9
+
10
+ # It's a html file, inject our JS
11
+ if headers['Content-Type'].include?('text/html')
12
+ response = inject_javascript_to_response(response)
13
+ end
14
+
15
+ [status, headers, response]
16
+ end
17
+
18
+ def inject_javascript_to_response(response)
19
+ response[0].gsub!('</head>', "#{js_tracker.head_html}</head>")
20
+ response[0].gsub!('</body>', "#{js_tracker.body_html}</body>")
21
+
22
+ response
23
+ end
24
+
25
+ private
26
+ def js_tracker
27
+ @js_tracker = Raygun::JavaScriptTracker.new
28
+ end
29
+ end
30
+ end
@@ -19,7 +19,8 @@ class Raygun::Railtie < Rails::Railtie
19
19
  raygun_middleware = [
20
20
  Raygun::Middleware::RailsInsertAffectedUser,
21
21
  Raygun::Middleware::RackExceptionInterceptor,
22
- Raygun::Middleware::BreadcrumbsStoreInitializer
22
+ Raygun::Middleware::BreadcrumbsStoreInitializer,
23
+ Raygun::Middleware::JavascriptExceptionTracking
23
24
  ]
24
25
  raygun_middleware = raygun_middleware.map(&:to_s) unless Rails::VERSION::STRING >= "5"
25
26
  raygun_middleware.each do |m|
@@ -1,3 +1,3 @@
1
1
  module Raygun
2
- VERSION = "3.0.0"
2
+ VERSION = "3.1.0"
3
3
  end
data/raygun4ruby.gemspec CHANGED
@@ -28,11 +28,18 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency "bundler", ">= 1.1"
29
29
  spec.add_development_dependency "rake", "~> 11"
30
30
  spec.add_development_dependency "timecop"
31
- spec.add_development_dependency "minitest", "~> 4.2"
31
+ spec.add_development_dependency "minitest", "~> 5.11"
32
32
  spec.add_development_dependency "redis-namespace", ">= 1.3.1"
33
33
  spec.add_development_dependency "resque"
34
34
  spec.add_development_dependency "sidekiq", [">= 3", "< 3.2.2"]
35
35
  spec.add_development_dependency "mocha"
36
36
  spec.add_development_dependency "pry"
37
37
  spec.add_development_dependency "webmock"
38
+
39
+ spec.add_development_dependency 'rails', "= 5.2"
40
+ spec.add_development_dependency 'sqlite3'
41
+ spec.add_development_dependency 'capybara'
42
+ spec.add_development_dependency "rspec-rails"
43
+ spec.add_development_dependency "launchy"
44
+ spec.add_development_dependency "simplecov"
38
45
  end
@@ -0,0 +1 @@
1
+ 2.5.1
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative 'config/application'
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,3 @@
1
+ //= link_tree ../images
2
+ //= link_directory ../javascripts .js
3
+ //= link_directory ../stylesheets .css
File without changes
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require rails-ujs
14
+ //= require activestorage
15
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ // Action Cable provides the framework to deal with WebSockets in Rails.
2
+ // You can generate new channels where WebSocket features live using the `rails generate channel` command.
3
+ //
4
+ //= require action_cable
5
+ //= require_self
6
+ //= require_tree ./channels
7
+
8
+ (function() {
9
+ this.App || (this.App = {});
10
+
11
+ App.cable = ActionCable.createConsumer();
12
+
13
+ }).call(this);
File without changes
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Channel < ActionCable::Channel::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Connection < ActionCable::Connection::Base
3
+ end
4
+ end
@@ -0,0 +1,2 @@
1
+ class ApplicationController < ActionController::Base
2
+ end
File without changes
@@ -0,0 +1,4 @@
1
+ class HomeController < ApplicationController
2
+ def index
3
+ end
4
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ class ApplicationJob < ActiveJob::Base
2
+ end
@@ -0,0 +1,4 @@
1
+ class ApplicationMailer < ActionMailer::Base
2
+ default from: 'from@example.com'
3
+ layout 'mailer'
4
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ end
File without changes
@@ -0,0 +1,3 @@
1
+ <h1>Home#index</h1>
2
+ <p>Find me in app/views/home/index.html.erb</p>
3
+ <p><%= Raygun.configuration.js_api_key %></p>
@@ -0,0 +1 @@
1
+ {}
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= stylesheet_link_tag 'application', media: 'all' %>
9
+ <%= javascript_include_tag 'application' %>
10
+ </head>
11
+
12
+ <body>
13
+ <%= yield %>
14
+ </body>
15
+ </html>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <style>
6
+ /* Email styles need to be inline */
7
+ </style>
8
+ </head>
9
+
10
+ <body>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1 @@
1
+ <%= yield %>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+ include FileUtils
4
+
5
+ # path to your application root.
6
+ APP_ROOT = File.expand_path('..', __dir__)
7
+
8
+ def system!(*args)
9
+ system(*args) || abort("\n== Command #{args} failed ==")
10
+ end
11
+
12
+ chdir APP_ROOT do
13
+ # This script is a starting point to setup your application.
14
+ # Add necessary setup steps to this file.
15
+
16
+ puts '== Installing dependencies =='
17
+ system! 'gem install bundler --conservative'
18
+ system('bundle check') || system!('bundle install')
19
+
20
+ # Install JavaScript dependencies if using Yarn
21
+ # system('bin/yarn')
22
+
23
+ # puts "\n== Copying sample files =="
24
+ # unless File.exist?('config/database.yml')
25
+ # cp 'config/database.yml.sample', 'config/database.yml'
26
+ # end
27
+
28
+ puts "\n== Preparing database =="
29
+ system! 'bin/rails db:setup'
30
+
31
+ puts "\n== Removing old logs and tempfiles =="
32
+ system! 'bin/rails log:clear tmp:clear'
33
+
34
+ puts "\n== Restarting application server =="
35
+ system! 'bin/rails restart'
36
+ end
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+ include FileUtils
4
+
5
+ # path to your application root.
6
+ APP_ROOT = File.expand_path('..', __dir__)
7
+
8
+ def system!(*args)
9
+ system(*args) || abort("\n== Command #{args} failed ==")
10
+ end
11
+
12
+ chdir APP_ROOT do
13
+ # This script is a way to update your development environment automatically.
14
+ # Add necessary update steps to this file.
15
+
16
+ puts '== Installing dependencies =='
17
+ system! 'gem install bundler --conservative'
18
+ system('bundle check') || system!('bundle install')
19
+
20
+ # Install JavaScript dependencies if using Yarn
21
+ # system('bin/yarn')
22
+
23
+ puts "\n== Updating database =="
24
+ system! 'bin/rails db:migrate'
25
+
26
+ puts "\n== Removing old logs and tempfiles =="
27
+ system! 'bin/rails log:clear tmp:clear'
28
+
29
+ puts "\n== Restarting application server =="
30
+ system! 'bin/rails restart'
31
+ end