bugsnag 6.10.0 → 6.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +4 -0
  3. data/CHANGELOG.md +20 -0
  4. data/Gemfile +1 -0
  5. data/README.md +1 -0
  6. data/VERSION +1 -1
  7. data/features/fixtures/docker-compose.yml +13 -0
  8. data/features/fixtures/rails3/app/app/controllers/breadcrumbs_controller.rb +19 -0
  9. data/features/fixtures/rails3/app/app/controllers/session_tracking_controller.rb +10 -6
  10. data/features/fixtures/rails3/app/config/initializers/bugsnag.rb +8 -2
  11. data/features/fixtures/rails3/app/config/routes.rb +1 -0
  12. data/features/fixtures/rails4/app/Gemfile +5 -1
  13. data/features/fixtures/rails4/app/app/controllers/breadcrumbs_controller.rb +26 -0
  14. data/features/fixtures/rails4/app/app/controllers/mongo_controller.rb +23 -0
  15. data/features/fixtures/rails4/app/app/controllers/session_tracking_controller.rb +9 -5
  16. data/features/fixtures/rails4/app/app/jobs/application_job.rb +2 -0
  17. data/features/fixtures/rails4/app/app/jobs/notify_job.rb +5 -0
  18. data/features/fixtures/rails4/app/app/models/mongo_model.rb +6 -0
  19. data/features/fixtures/rails4/app/config/initializers/bugsnag.rb +7 -1
  20. data/features/fixtures/rails4/app/config/mongoid.yml +22 -0
  21. data/features/fixtures/rails4/app/config/routes.rb +2 -0
  22. data/features/fixtures/rails5/app/Gemfile +4 -0
  23. data/features/fixtures/rails5/app/app/controllers/breadcrumbs_controller.rb +24 -0
  24. data/features/fixtures/rails5/app/app/controllers/mongo_controller.rb +22 -0
  25. data/features/fixtures/rails5/app/app/controllers/session_tracking_controller.rb +9 -5
  26. data/features/fixtures/rails5/app/app/jobs/notify_job.rb +5 -0
  27. data/features/fixtures/rails5/app/app/models/mongo_model.rb +6 -0
  28. data/features/fixtures/rails5/app/config/initializers/bugsnag.rb +7 -1
  29. data/features/fixtures/rails5/app/config/mongoid.yml +23 -0
  30. data/features/fixtures/rails5/app/config/routes.rb +11 -1
  31. data/features/rails_features/auto_capture_sessions.feature +55 -5
  32. data/features/rails_features/breadcrumbs.feature +135 -0
  33. data/features/rails_features/mongo_breadcrumbs.feature +100 -0
  34. data/features/steps/ruby_notifier_steps.rb +6 -0
  35. data/lib/bugsnag.rb +59 -3
  36. data/lib/bugsnag/breadcrumbs/breadcrumb.rb +76 -0
  37. data/lib/bugsnag/breadcrumbs/breadcrumbs.rb +14 -0
  38. data/lib/bugsnag/breadcrumbs/validator.rb +59 -0
  39. data/lib/bugsnag/configuration.rb +103 -6
  40. data/lib/bugsnag/integrations/mongo.rb +132 -0
  41. data/lib/bugsnag/integrations/rails/rails_breadcrumbs.rb +118 -0
  42. data/lib/bugsnag/integrations/railtie.rb +28 -1
  43. data/lib/bugsnag/middleware/breadcrumbs.rb +21 -0
  44. data/lib/bugsnag/report.rb +30 -1
  45. data/lib/bugsnag/session_tracker.rb +1 -0
  46. data/lib/bugsnag/utility/circular_buffer.rb +62 -0
  47. data/spec/breadcrumbs/breadcrumb_spec.rb +93 -0
  48. data/spec/breadcrumbs/validator_spec.rb +200 -0
  49. data/spec/bugsnag_spec.rb +230 -0
  50. data/spec/configuration_spec.rb +176 -2
  51. data/spec/integrations/mongo_spec.rb +262 -0
  52. data/spec/report_spec.rb +149 -0
  53. data/spec/session_tracker_spec.rb +24 -2
  54. data/spec/utility/circular_buffer_spec.rb +98 -0
  55. metadata +27 -2
@@ -7,8 +7,14 @@ Bugsnag.configure do |config|
7
7
  config.auto_notify = ENV["BUGSNAG_AUTO_NOTIFY"] != "false"
8
8
  config.project_root = ENV["BUGSNAG_PROJECT_ROOT"] if ENV.include? "BUGSNAG_PROJECT_ROOT"
9
9
  config.ignore_classes << lambda { |ex| ex.class.to_s == ENV["BUGSNAG_IGNORE_CLASS"] } if ENV.include? "BUGSNAG_IGNORE_CLASS"
10
- config.auto_capture_sessions = ENV["BUGSNAG_AUTO_CAPTURE_SESSIONS"] == "true"
10
+ config.auto_capture_sessions = ENV["BUGSNAG_AUTO_CAPTURE_SESSIONS"] == "true" unless ENV["USE_DEFAULT_AUTO_CAPTURE_SESSIONS"]
11
11
  config.release_stage = ENV["BUGSNAG_RELEASE_STAGE"] if ENV.include? "BUGSNAG_RELEASE_STAGE"
12
12
  config.send_code = ENV["BUGSNAG_SEND_CODE"] != "false"
13
13
  config.send_environment = ENV["BUGSNAG_SEND_ENVIRONMENT"] == "true"
14
+
15
+ if ENV["SQL_ONLY_BREADCRUMBS"] == "true"
16
+ config.before_breadcrumb_callbacks << Proc.new do |breadcrumb|
17
+ breadcrumb.ignore! unless breadcrumb.meta_data[:event_name] == "sql.active_record" && breadcrumb.meta_data[:name] == "User Load"
18
+ end
19
+ end
14
20
  end
@@ -0,0 +1,23 @@
1
+ development:
2
+ # Configure available database clients. (required)
3
+ clients:
4
+ # Defines the default client. (required)
5
+ default:
6
+ # Defines the name of the default database that Mongoid can connect to.
7
+ # (required).
8
+ database: rails5_development
9
+ # Provides the hosts the default client can connect to. Must be an array
10
+ # of host:port pairs. (required)
11
+ hosts:
12
+ - mongo:27017
13
+
14
+ test:
15
+ clients:
16
+ default:
17
+ database: rails5_test
18
+ hosts:
19
+ - mongo:27017
20
+ options:
21
+ read:
22
+ mode: :primary
23
+ max_pool_size: 1
@@ -36,7 +36,8 @@ Rails.application.routes.draw do
36
36
  get 'metadata_filters/filter', to: 'metadata_filters#filter'
37
37
 
38
38
  get 'session_tracking/initializer', to: 'session_tracking#initializer'
39
- get 'session_tracking/after', to: 'session_tracking#after'
39
+ get 'session_tracking/manual', to: 'session_tracking#manual'
40
+ get 'session_tracking/multi_sessions', to: 'session_tracking#multi_sessions'
40
41
 
41
42
  get 'release_stage/default', to: 'release_stage#default'
42
43
  get 'release_stage/after', to: 'release_stage#after'
@@ -49,4 +50,13 @@ Rails.application.routes.draw do
49
50
  get 'clearance/create', to: 'clearance#create'
50
51
  get 'clearance/unhandled', to: 'clearance#unhandled'
51
52
  get 'clearance/handled', to: 'clearance#handled'
53
+
54
+ get 'breadcrumbs/handled', to: 'breadcrumbs#handled'
55
+ get 'breadcrumbs/sql_breadcrumb', to: 'breadcrumbs#sql_breadcrumb'
56
+ get 'breadcrumbs/active_job', to: 'breadcrumbs#active_job'
57
+ get 'breadcrumbs/cache_read', to: 'breadcrumbs#cache_read'
58
+
59
+ get 'mongo/success_crash', to: 'mongo#success_crash'
60
+ get 'mongo/get_crash', to: 'mongo#get_crash'
61
+ get 'mongo/failure_crash', to: 'mongo#failure_crash'
52
62
  end
@@ -5,9 +5,9 @@ Background:
5
5
  And I set environment variable "APP_PATH" to "/usr/src"
6
6
  And I configure the bugsnag endpoint
7
7
 
8
- Scenario Outline: Auto_capture_sessions can be set to true in the initializer
8
+ Scenario Outline: Auto_capture_sessions defaults to true
9
9
  Given I set environment variable "RUBY_VERSION" to "<ruby_version>"
10
- And I set environment variable "BUGSNAG_AUTO_CAPTURE_SESSIONS" to "true"
10
+ And I set environment variable "USE_DEFAULT_AUTO_CAPTURE_SESSIONS" to "true"
11
11
  And I start the service "rails<rails_version>"
12
12
  And I wait for the app to respond on port "6128<rails_version>"
13
13
  When I navigate to the route "/session_tracking/initializer" on port "6128<rails_version>"
@@ -32,18 +32,68 @@ Scenario Outline: Auto_capture_sessions can be set to true in the initializer
32
32
  | 2.5 | 3 |
33
33
  | 2.5 | 5 |
34
34
 
35
- Scenario Outline: Auto_capture_sessions can be set to true after the initializer
35
+ Scenario Outline: Auto_capture_sessions can be set to false in the initializer
36
36
  Given I set environment variable "RUBY_VERSION" to "<ruby_version>"
37
+ And I set environment variable "BUGSNAG_AUTO_CAPTURE_SESSIONS" to "false"
37
38
  And I start the service "rails<rails_version>"
38
39
  And I wait for the app to respond on port "6128<rails_version>"
39
- When I navigate to the route "/session_tracking/after" on port "6128<rails_version>"
40
- Then I should receive 0 requests
41
40
  When I navigate to the route "/session_tracking/initializer" on port "6128<rails_version>"
41
+ Then I should receive 0 requests
42
+
43
+ Examples:
44
+ | ruby_version | rails_version |
45
+ | 2.0 | 3 |
46
+ | 2.1 | 3 |
47
+ | 2.2 | 3 |
48
+ | 2.2 | 4 |
49
+ | 2.2 | 5 |
50
+ | 2.3 | 3 |
51
+ | 2.3 | 4 |
52
+ | 2.3 | 5 |
53
+ | 2.4 | 3 |
54
+ | 2.4 | 5 |
55
+ | 2.5 | 3 |
56
+ | 2.5 | 5 |
57
+
58
+ Scenario Outline: Manual sessions are still sent if Auto_capture_sessions is false
59
+ Given I set environment variable "RUBY_VERSION" to "<ruby_version>"
60
+ And I set environment variable "BUGSNAG_AUTO_CAPTURE_SESSIONS" to "false"
61
+ And I start the service "rails<rails_version>"
62
+ And I wait for the app to respond on port "6128<rails_version>"
63
+ When I navigate to the route "/session_tracking/manual" on port "6128<rails_version>"
64
+ Then I should receive a request
65
+ And the request is a valid for the session tracking API
66
+ And the request used the "Ruby Bugsnag Notifier" notifier
67
+ And the "Bugsnag-API-Key" header equals "a35a2a72bd230ac0aa0f52715bbdc6aa"
68
+ And the sessionCount "startedAt" is a timestamp
69
+
70
+ Examples:
71
+ | ruby_version | rails_version |
72
+ | 2.0 | 3 |
73
+ | 2.1 | 3 |
74
+ | 2.2 | 3 |
75
+ | 2.2 | 4 |
76
+ | 2.2 | 5 |
77
+ | 2.3 | 3 |
78
+ | 2.3 | 4 |
79
+ | 2.3 | 5 |
80
+ | 2.4 | 3 |
81
+ | 2.4 | 5 |
82
+ | 2.5 | 3 |
83
+ | 2.5 | 5 |
84
+
85
+ Scenario Outline: 100 session calls results in 100 sessions
86
+ Given I set environment variable "RUBY_VERSION" to "<ruby_version>"
87
+ And I set environment variable "BUGSNAG_AUTO_CAPTURE_SESSIONS" to "false"
88
+ And I start the service "rails<rails_version>"
89
+ And I wait for the app to respond on port "6128<rails_version>"
90
+ When I navigate to the route "/session_tracking/multi_sessions" on port "6128<rails_version>"
42
91
  Then I should receive a request
43
92
  And the request is a valid for the session tracking API
44
93
  And the request used the "Ruby Bugsnag Notifier" notifier
45
94
  And the "Bugsnag-API-Key" header equals "a35a2a72bd230ac0aa0f52715bbdc6aa"
46
95
  And the sessionCount "startedAt" is a timestamp
96
+ And the total sessionStarted count equals 100
47
97
 
48
98
  Examples:
49
99
  | ruby_version | rails_version |
@@ -0,0 +1,135 @@
1
+ Feature: Rails automatic breadcrumbs
2
+
3
+ Background:
4
+ Given I set environment variable "BUGSNAG_API_KEY" to "a35a2a72bd230ac0aa0f52715bbdc6aa"
5
+ And I set environment variable "APP_PATH" to "/usr/src"
6
+ And I configure the bugsnag endpoint
7
+
8
+ Scenario Outline: Request breadcrumb
9
+ Given I set environment variable "RUBY_VERSION" to "<ruby_version>"
10
+ And I start the service "rails<rails_version>"
11
+ And I wait for the app to respond on port "6128<rails_version>"
12
+ When I navigate to the route "/breadcrumbs/handled" on port "6128<rails_version>"
13
+ Then I should receive a request
14
+ And the request is a valid for the error reporting API
15
+ And the request used the "Ruby Bugsnag Notifier" notifier
16
+ And the request contained the api key "a35a2a72bd230ac0aa0f52715bbdc6aa"
17
+ And the event has a "request" breadcrumb named "Controller started processing"
18
+ And the event "breadcrumbs.0.timestamp" is a timestamp
19
+ And the event "breadcrumbs.0.metaData.controller" equals "BreadcrumbsController"
20
+ And the event "breadcrumbs.0.metaData.action" equals "handled"
21
+ And the event "breadcrumbs.0.metaData.method" equals "GET"
22
+ And the event "breadcrumbs.0.metaData.path" equals "/breadcrumbs/handled"
23
+ And the event "breadcrumbs.0.metaData.event_name" equals "start_processing.action_controller"
24
+ And the event "breadcrumbs.0.metaData.event_id" is not null
25
+
26
+ Examples:
27
+ | ruby_version | rails_version |
28
+ | 2.0 | 3 |
29
+ | 2.1 | 3 |
30
+ | 2.2 | 3 |
31
+ | 2.2 | 4 |
32
+ | 2.2 | 5 |
33
+ | 2.3 | 3 |
34
+ | 2.3 | 4 |
35
+ | 2.3 | 5 |
36
+ | 2.4 | 3 |
37
+ | 2.4 | 5 |
38
+ | 2.5 | 3 |
39
+ | 2.5 | 5 |
40
+
41
+ Scenario Outline: SQL Breadcrumb without bindings
42
+ Given I set environment variable "RUBY_VERSION" to "<ruby_version>"
43
+ And I set environment variable "SQL_ONLY_BREADCRUMBS" to "true"
44
+ And I start the service "rails<rails_version>"
45
+ And I wait for the app to respond on port "6128<rails_version>"
46
+ When I navigate to the route "/breadcrumbs/sql_breadcrumb" on port "6128<rails_version>"
47
+ Then I should receive a request
48
+ And the request is a valid for the error reporting API
49
+ And the request used the "Ruby Bugsnag Notifier" notifier
50
+ And the request contained the api key "a35a2a72bd230ac0aa0f52715bbdc6aa"
51
+ And the event has a "process" breadcrumb named "ActiveRecord SQL query"
52
+ And the event "breadcrumbs.0.timestamp" is a timestamp
53
+ And the event "breadcrumbs.0.metaData.name" equals "User Load"
54
+ And the event "breadcrumbs.0.metaData.connection_id" is not null
55
+ And the event "breadcrumbs.0.metaData.event_name" equals "sql.active_record"
56
+ And the event "breadcrumbs.0.metaData.event_id" is not null
57
+
58
+ Examples:
59
+ | ruby_version | rails_version |
60
+ | 2.0 | 3 |
61
+ | 2.1 | 3 |
62
+ | 2.2 | 3 |
63
+ | 2.2 | 4 |
64
+ | 2.3 | 3 |
65
+ | 2.3 | 4 |
66
+ | 2.4 | 3 |
67
+ | 2.5 | 3 |
68
+
69
+ Scenario Outline: SQL Breadcrumb with bindings
70
+ Given I set environment variable "RUBY_VERSION" to "<ruby_version>"
71
+ And I set environment variable "SQL_ONLY_BREADCRUMBS" to "true"
72
+ And I start the service "rails<rails_version>"
73
+ And I wait for the app to respond on port "6128<rails_version>"
74
+ When I navigate to the route "/breadcrumbs/sql_breadcrumb" on port "6128<rails_version>"
75
+ Then I should receive a request
76
+ And the request is a valid for the error reporting API
77
+ And the request used the "Ruby Bugsnag Notifier" notifier
78
+ And the request contained the api key "a35a2a72bd230ac0aa0f52715bbdc6aa"
79
+ And the event has a "process" breadcrumb named "ActiveRecord SQL query"
80
+ And the event "breadcrumbs.0.timestamp" is a timestamp
81
+ And the event "breadcrumbs.0.metaData.name" equals "User Load"
82
+ And the event "breadcrumbs.0.metaData.connection_id" is not null
83
+ And the event "breadcrumbs.0.metaData.event_name" equals "sql.active_record"
84
+ And the event "breadcrumbs.0.metaData.event_id" is not null
85
+ And the event "breadcrumbs.0.metaData.binds" equals "{"email":"?","LIMIT":"?"}"
86
+
87
+ Examples:
88
+ | ruby_version | rails_version |
89
+ | 2.2 | 5 |
90
+ | 2.3 | 5 |
91
+ | 2.4 | 5 |
92
+ | 2.5 | 5 |
93
+
94
+ Scenario Outline: Active job breadcrumb
95
+ Given I set environment variable "RUBY_VERSION" to "<ruby_version>"
96
+ And I start the service "rails<rails_version>"
97
+ And I wait for the app to respond on port "6128<rails_version>"
98
+ When I navigate to the route "/breadcrumbs/active_job" on port "6128<rails_version>"
99
+ Then I should receive a request
100
+ And the request is a valid for the error reporting API
101
+ And the request used the "Ruby Bugsnag Notifier" notifier
102
+ And the request contained the api key "a35a2a72bd230ac0aa0f52715bbdc6aa"
103
+ And the event has a "process" breadcrumb named "Start perform ActiveJob"
104
+ And the event "breadcrumbs.0.timestamp" is a timestamp
105
+ And the event "breadcrumbs.0.metaData.event_name" equals "perform_start.active_job"
106
+ And the event "breadcrumbs.0.metaData.event_id" is not null
107
+
108
+ Examples:
109
+ | ruby_version | rails_version |
110
+ | 2.2 | 4 |
111
+ | 2.2 | 5 |
112
+ | 2.3 | 4 |
113
+ | 2.3 | 5 |
114
+ | 2.4 | 5 |
115
+ | 2.5 | 5 |
116
+
117
+ Scenario Outline: Cache read
118
+ Given I set environment variable "RUBY_VERSION" to "<ruby_version>"
119
+ And I start the service "rails<rails_version>"
120
+ And I wait for the app to respond on port "6128<rails_version>"
121
+ When I navigate to the route "/breadcrumbs/cache_read" on port "6128<rails_version>"
122
+ Then I should receive a request
123
+ And the request is a valid for the error reporting API
124
+ And the request used the "Ruby Bugsnag Notifier" notifier
125
+ And the request contained the api key "a35a2a72bd230ac0aa0f52715bbdc6aa"
126
+ And the event has a "process" breadcrumb named "Read cache"
127
+
128
+ Examples:
129
+ | ruby_version | rails_version |
130
+ | 2.2 | 4 |
131
+ | 2.2 | 5 |
132
+ | 2.3 | 4 |
133
+ | 2.3 | 5 |
134
+ | 2.4 | 5 |
135
+ | 2.5 | 5 |
@@ -0,0 +1,100 @@
1
+ Feature: Mongo automatic breadcrumbs
2
+
3
+ Background:
4
+ Given I set environment variable "BUGSNAG_API_KEY" to "a35a2a72bd230ac0aa0f52715bbdc6aa"
5
+ And I set environment variable "APP_PATH" to "/usr/src"
6
+ And I configure the bugsnag endpoint
7
+
8
+ Scenario Outline: Successful breadcrumbs
9
+ Given I set environment variable "RUBY_VERSION" to "<ruby_version>"
10
+ And I start the service "rails<rails_version>"
11
+ And I wait for the app to respond on port "6128<rails_version>"
12
+ When I navigate to the route "/mongo/success_crash" on port "6128<rails_version>"
13
+ Then I should receive a request
14
+ And the request is a valid for the error reporting API
15
+ And the request used the "Ruby Bugsnag Notifier" notifier
16
+ And the request contained the api key "a35a2a72bd230ac0aa0f52715bbdc6aa"
17
+ And the event has a "process" breadcrumb named "Mongo query succeeded"
18
+ And the event "breadcrumbs.1.timestamp" is a timestamp
19
+ And the event "breadcrumbs.1.metaData.event_name" equals "mongo.succeeded"
20
+ And the event "breadcrumbs.1.metaData.command_name" equals "insert"
21
+ And the event "breadcrumbs.1.metaData.database_name" equals "rails<rails_version>_development"
22
+ And the event "breadcrumbs.1.metaData.operation_id" is not null
23
+ And the event "breadcrumbs.1.metaData.request_id" is not null
24
+ And the event "breadcrumbs.1.metaData.duration" is not null
25
+ And the event "breadcrumbs.1.metaData.collection" equals "mongo_models"
26
+
27
+ Examples:
28
+ | ruby_version | rails_version |
29
+ | 2.2 | 4 |
30
+ | 2.2 | 5 |
31
+ | 2.3 | 4 |
32
+ | 2.3 | 5 |
33
+ | 2.4 | 5 |
34
+ | 2.5 | 5 |
35
+
36
+ Scenario Outline: Breadcrumb with filter parameters
37
+ Given I set environment variable "RUBY_VERSION" to "<ruby_version>"
38
+ And I start the service "rails<rails_version>"
39
+ And I wait for the app to respond on port "6128<rails_version>"
40
+ When I navigate to the route "/mongo/get_crash" on port "6128<rails_version>"
41
+ Then I should receive a request
42
+ And the request is a valid for the error reporting API
43
+ And the request used the "Ruby Bugsnag Notifier" notifier
44
+ And the request contained the api key "a35a2a72bd230ac0aa0f52715bbdc6aa"
45
+ And the event has a "process" breadcrumb named "Mongo query succeeded"
46
+ And the event "breadcrumbs.1.timestamp" is a timestamp
47
+ And the event "breadcrumbs.1.metaData.event_name" equals "mongo.succeeded"
48
+ And the event "breadcrumbs.1.metaData.command_name" equals "find"
49
+ And the event "breadcrumbs.1.metaData.database_name" equals "rails<rails_version>_development"
50
+ And the event "breadcrumbs.1.metaData.operation_id" is not null
51
+ And the event "breadcrumbs.1.metaData.request_id" is not null
52
+ And the event "breadcrumbs.1.metaData.duration" is not null
53
+ And the event "breadcrumbs.1.metaData.collection" equals "mongo_models"
54
+ And the event "breadcrumbs.1.metaData.filter" equals "{"string_field":"?"}"
55
+ And the event "breadcrumbs.2.timestamp" is a timestamp
56
+ And the event "breadcrumbs.2.metaData.event_name" equals "mongo.succeeded"
57
+ And the event "breadcrumbs.2.metaData.command_name" equals "find"
58
+ And the event "breadcrumbs.2.metaData.database_name" equals "rails<rails_version>_development"
59
+ And the event "breadcrumbs.2.metaData.operation_id" is not null
60
+ And the event "breadcrumbs.2.metaData.request_id" is not null
61
+ And the event "breadcrumbs.2.metaData.duration" is not null
62
+ And the event "breadcrumbs.2.metaData.collection" equals "mongo_models"
63
+ And the event "breadcrumbs.2.metaData.filter" equals "{"$or":[{"string_field":"?"},{"numeric_field":"?"}]}"
64
+
65
+ Examples:
66
+ | ruby_version | rails_version |
67
+ | 2.2 | 4 |
68
+ | 2.2 | 5 |
69
+ | 2.3 | 4 |
70
+ | 2.3 | 5 |
71
+ | 2.4 | 5 |
72
+ | 2.5 | 5 |
73
+
74
+ Scenario Outline: Failure breadcrumbs
75
+ Given I set environment variable "RUBY_VERSION" to "<ruby_version>"
76
+ And I start the service "rails<rails_version>"
77
+ And I wait for the app to respond on port "6128<rails_version>"
78
+ When I navigate to the route "/mongo/failure_crash" on port "6128<rails_version>"
79
+ Then I should receive a request
80
+ And the request is a valid for the error reporting API
81
+ And the request used the "Ruby Bugsnag Notifier" notifier
82
+ And the request contained the api key "a35a2a72bd230ac0aa0f52715bbdc6aa"
83
+ And the event has a "process" breadcrumb named "Mongo query failed"
84
+ And the event "breadcrumbs.1.timestamp" is a timestamp
85
+ And the event "breadcrumbs.1.metaData.event_name" equals "mongo.failed"
86
+ And the event "breadcrumbs.1.metaData.command_name" equals "bogus"
87
+ And the event "breadcrumbs.1.metaData.database_name" equals "rails<rails_version>_development"
88
+ And the event "breadcrumbs.1.metaData.operation_id" is not null
89
+ And the event "breadcrumbs.1.metaData.request_id" is not null
90
+ And the event "breadcrumbs.1.metaData.duration" is not null
91
+ And the event "breadcrumbs.1.metaData.collection" equals 1
92
+
93
+ Examples:
94
+ | ruby_version | rails_version |
95
+ | 2.2 | 4 |
96
+ | 2.2 | 5 |
97
+ | 2.3 | 4 |
98
+ | 2.3 | 5 |
99
+ | 2.4 | 5 |
100
+ | 2.5 | 5 |
@@ -22,4 +22,10 @@ Then(/^the "(.+)" of the top non-bugsnag stackframe equals (\d+|".+")(?: for req
22
22
  steps %Q{
23
23
  the "#{element}" of stack frame #{frame_index} equals #{value}
24
24
  }
25
+ end
26
+
27
+ Then(/^the total sessionStarted count equals (\d+)(?: for request (\d+))?$/) do |value, request_index|
28
+ session_counts = read_key_path(find_request(request_index)[:body], "sessionCounts")
29
+ total_count = session_counts.inject(0) { |count, session| count += session["sessionsStarted"] }
30
+ assert_equal(value, total_count)
25
31
  end
@@ -29,9 +29,13 @@ require "bugsnag/middleware/callbacks"
29
29
  require "bugsnag/middleware/classify_error"
30
30
  require "bugsnag/middleware/delayed_job"
31
31
 
32
+ require "bugsnag/breadcrumbs/validator"
33
+ require "bugsnag/breadcrumbs/breadcrumb"
34
+ require "bugsnag/breadcrumbs/breadcrumbs"
35
+
32
36
  module Bugsnag
33
37
  LOCK = Mutex.new
34
- INTEGRATIONS = [:resque, :sidekiq, :mailman, :delayed_job, :shoryuken, :que]
38
+ INTEGRATIONS = [:resque, :sidekiq, :mailman, :delayed_job, :shoryuken, :que, :mongo]
35
39
 
36
40
  NIL_EXCEPTION_DESCRIPTION = "'nil' was notified as an exception"
37
41
 
@@ -44,6 +48,7 @@ module Bugsnag
44
48
  yield(configuration) if block_given?
45
49
 
46
50
  check_key_valid if validate_api_key
51
+ check_endpoint_setup
47
52
 
48
53
  register_at_exit
49
54
  end
@@ -107,10 +112,12 @@ module Bugsnag
107
112
  end
108
113
 
109
114
  # Deliver
110
- configuration.info("Notifying #{configuration.endpoint} of #{report.exceptions.last[:errorClass]}")
115
+ configuration.info("Notifying #{configuration.notify_endpoint} of #{report.exceptions.last[:errorClass]}")
111
116
  options = {:headers => report.headers}
112
117
  payload = ::JSON.dump(Bugsnag::Helpers.trim_if_needed(report.as_json))
113
- Bugsnag::Delivery[configuration.delivery_method].deliver(configuration.endpoint, payload, configuration, options)
118
+ Bugsnag::Delivery[configuration.delivery_method].deliver(configuration.notify_endpoint, payload, configuration, options)
119
+ report_summary = report.summary
120
+ leave_breadcrumb(report_summary[:error_class], report_summary, Bugsnag::Breadcrumbs::ERROR_BREADCRUMB_TYPE, :auto)
114
121
  end
115
122
  end
116
123
 
@@ -189,6 +196,39 @@ module Bugsnag
189
196
  end
190
197
  end
191
198
 
199
+ ##
200
+ # Leave a breadcrumb to be attached to subsequent reports
201
+ #
202
+ # @param name [String] the main breadcrumb name/message
203
+ # @param meta_data [Hash] String, Numeric, or Boolean meta data to attach
204
+ # @param type [String] the breadcrumb type, from Bugsnag::Breadcrumbs::VALID_BREADCRUMB_TYPES
205
+ # @param auto [Symbol] set to :auto if the breadcrumb is automatically created
206
+ def leave_breadcrumb(name, meta_data={}, type=Bugsnag::Breadcrumbs::MANUAL_BREADCRUMB_TYPE, auto=:manual)
207
+ breadcrumb = Bugsnag::Breadcrumbs::Breadcrumb.new(name, type, meta_data, auto)
208
+ validator = Bugsnag::Breadcrumbs::Validator.new(configuration)
209
+
210
+ # Initial validation
211
+ validator.validate(breadcrumb)
212
+
213
+ # Skip if it's already invalid
214
+ unless breadcrumb.ignore?
215
+ # Run callbacks
216
+ configuration.before_breadcrumb_callbacks.each do |c|
217
+ c.arity > 0 ? c.call(breadcrumb) : c.call
218
+ break if breadcrumb.ignore?
219
+ end
220
+
221
+ # Return early if ignored
222
+ return if breadcrumb.ignore?
223
+
224
+ # Validate again in case of callback alteration
225
+ validator.validate(breadcrumb)
226
+
227
+ # Add to breadcrumbs buffer if still valid
228
+ configuration.breadcrumbs << breadcrumb unless breadcrumb.ignore?
229
+ end
230
+ end
231
+
192
232
  private
193
233
 
194
234
  def deliver_notification?(exception, auto_notify)
@@ -217,6 +257,22 @@ module Bugsnag
217
257
  @key_warning = true
218
258
  end
219
259
  end
260
+
261
+ ##
262
+ # Verifies the current endpoint setup
263
+ #
264
+ # If only a notify_endpoint has been set, session tracking will be disabled
265
+ # If only a session_endpoint has been set, and ArgumentError will be raised
266
+ def check_endpoint_setup
267
+ notify_set = configuration.notify_endpoint && configuration.notify_endpoint != Bugsnag::Configuration::DEFAULT_NOTIFY_ENDPOINT
268
+ session_set = configuration.session_endpoint && configuration.session_endpoint != Bugsnag::Configuration::DEFAULT_SESSION_ENDPOINT
269
+ if notify_set && !session_set
270
+ configuration.warn("The session endpoint has not been set, all further session capturing will be disabled")
271
+ configuration.disable_sessions
272
+ elsif !notify_set && session_set
273
+ raise ArgumentError, "The session endpoint cannot be modified without the notify endpoint"
274
+ end
275
+ end
220
276
  end
221
277
  end
222
278