Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V6 example updates #374

Merged
merged 38 commits into from
Oct 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ff8317a
Fixed incorrect path to bugsnag lib
Cawllec Aug 16, 2017
f6ca3bf
Ensured local bugsnag references correct library location
Cawllec Aug 16, 2017
6d8e174
Updated padrino example
Cawllec Sep 28, 2017
b8d421f
Removed favicon
Cawllec Sep 28, 2017
0427409
Updated to readme
Cawllec Sep 28, 2017
8534770
Updated rack example
Cawllec Sep 28, 2017
b5a4941
Updated rails server
Cawllec Sep 28, 2017
846a588
Fixed name
Cawllec Sep 28, 2017
4b48ab2
Updated error reasons
Cawllec Sep 28, 2017
05521af
Updated error reasons
Cawllec Sep 28, 2017
ad9959e
Updated resque example
Cawllec Sep 28, 2017
c258ac2
Removed API KEY
Cawllec Sep 29, 2017
42bd1e3
Remove ref
Cawllec Sep 29, 2017
7a12445
Updated resque/sidekiq examples
Cawllec Sep 29, 2017
7aaa01f
Updated sinatra example and sidekiq
Cawllec Sep 29, 2017
c994b16
Updated rails 4.2 example
Cawllec Sep 29, 2017
57331fe
Added rails 5.1 example
Cawllec Oct 3, 2017
cc9d267
Fixed incorrect path to bugsnag lib
Cawllec Aug 16, 2017
75e3b1b
Ensured local bugsnag references correct library location
Cawllec Aug 16, 2017
c0ee41b
Updated padrino example
Cawllec Sep 28, 2017
edb64da
Removed favicon
Cawllec Sep 28, 2017
e5d2d2f
Updated to readme
Cawllec Sep 28, 2017
1fd5ebb
Updated rack example
Cawllec Sep 28, 2017
0dd81d3
Updated rails server
Cawllec Sep 28, 2017
cc59789
Fixed name
Cawllec Sep 28, 2017
33b40ba
Updated error reasons
Cawllec Sep 28, 2017
425c947
Updated error reasons
Cawllec Sep 28, 2017
4d52ac5
Updated resque example
Cawllec Sep 28, 2017
4a926cc
Removed API KEY
Cawllec Sep 29, 2017
ab2e5c9
Remove ref
Cawllec Sep 29, 2017
0005ee0
Updated resque/sidekiq examples
Cawllec Sep 29, 2017
ad1a4aa
Updated sinatra example and sidekiq
Cawllec Sep 29, 2017
83834fa
Updated rails 4.2 example
Cawllec Sep 29, 2017
b1512fe
Added rails 5.1 example
Cawllec Oct 3, 2017
2342d8d
Merge branch 'v5-example-updates' of github.com:bugsnag/bugsnag-ruby …
Cawllec Oct 3, 2017
f61f948
Updated rails-42 example with delayed_job
Cawllec Oct 6, 2017
91d860a
Ensured correct commands mentioned
Cawllec Oct 6, 2017
54775b0
Ensured helper works correctly
Cawllec Oct 6, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/padrino/Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source 'https://rubygems.org'

if ENV['INTEGRATION_LANGUAGE']
gem 'bugsnag', path: '../../../../'
gem 'bugsnag', path: '../../'
else
gem 'bugsnag'
end
Expand Down Expand Up @@ -38,7 +38,7 @@ gem 'riot', :group => 'test'
gem 'rack-test', :require => 'rack/test', :group => 'test'

# Padrino Stable Gem
gem 'padrino', '0.12.2'
gem 'padrino'

# Or Padrino Edge
# gem 'padrino', :github => 'padrino/padrino-framework'
Expand Down
100 changes: 27 additions & 73 deletions example/padrino/README.md
Original file line number Diff line number Diff line change
@@ -1,90 +1,44 @@
# Bugsnag Padrino demo

This Padrino application demonstrates how to use Bugsnag with Padrino. Before
testing it, open up the `config/boot.rb` file configure your API key inside
`Padrino.before_load`.
This Padrino application demonstrates how to use Bugsnag with Padrino.
Further details about integrating Bugsnag with Rack applications can be found [here.](https://docs.bugsnag.com/platforms/ruby/rack/)

```
Padrino.before_load do
Bugsnag.configure do |config|
config.api_key = '0a6f5add590596f93a8d601ea89af841'
end
end
Install dependencies

```shell
bundle install
```

In the same file activate the Bugsnag Rack middleware.
## Configuring Bugsnag and Padrino

```
Padrino.after_load do
Padrino.use Bugsnag::Rack
end
```
1. Set up the Padrino Bugsnag configuration in ```config/boot.rb``` in the `before_load` call according to the [available configuration options](https://docs.bugsnag.com/platforms/ruby/rack/configuration-options/):
```ruby
Padrino.before_load do
Bugsnag.configure do |config|
config.api_key = 'YOUR_API_KEY'
end
end
```

Open up `app/app.rb`, find two options and set them as follows: `raise_errors`
to `true` and `show_exceptions` to `false`. This enables automatic notifications
in the development environment. By default Padrino swallows exceptions from
Bugsnag (only in development, though).
2. Register the Rack middleware in ```config/boot.rb``` in the `after_load` call:
```ruby
Padrino.after_load do
Padrino.use Bugsnag::Rack
end
```

```
3. In `production` automatic notification of exceptions and errors will be enabled by default. If you want to enable notifications in `development`, open ```app/app.rb``` and set the following options:
```ruby
set :raise_errors, true
set :show_exceptions, false
```

If you would like to use custom error handlers, then you need to notify Bugsnag
explicitly.

```
error 500 do
Bugsnag.notify($!) do |report|
report.severity = "error"
end

erb :'errors/500'
end
```

Install dependencies.

```
bundle install
```
## Running the example

Launch the Padrino application.
Run the example using:

```
```shell
bundle exec padrino start
```

Next, open your project's dashboard on Bugsnag.

1. [crash](http://localhost:9292/crash)
<br/>
Crashes the application and sends a notification about the nature of the crash.
Basically, almost any unhandled exception sends a notification to Bugsnag. See
the line mentioning `get '/crash'` in `app/app.rb`.

1. [crash and use callbacks](http://localhost:9292/crash_with_callback)
<br/>
Before crashing, the application would append the Diagnostics tab with some
predefined information, attached by means of a callback. See the line mentioning
`get '/crash_with_callback'` in `app/app.rb`.

1. [notify](http://localhost:9292/notify)
<br/>
Bugsnag Ruby provides a way to send notifications on demand by means of
`Bugsnag.notify`. This API allows to send notifications manually, without
crashing your application. See the line mentioning `get '/notify'` in
`app/app.rb`.

1. [notify with meta data](http://localhost:9292/notify_meta)
<br/>
Same as `notify`, but also attaches meta data. The meta data is any additional
information you want to attach to an exception. In this artificial case
additional information with be sent and displayed in a new tab called
"Diagnostics". See the line mentioning `get '/notify_meta'` in `app/app.rb`.

1. [severity](http://localhost:9292/severity)
<br/>
Bugsnag supports three severities: 'error', 'warning' and 'info'. You can set
the severity by passing one of these objects as a string to '#notify'. See the
line mentioning `get '/severity'` in `app/app.rb`.
Once the server is running head to the default path for more information on Bugsnag logging examples.
30 changes: 15 additions & 15 deletions example/padrino/app/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class App < Padrino::Application
fenced_code_blocks: true
}
renderer = Redcarpet::Markdown.new(Redcarpet::Render::HTML, opts)
renderer.render(File.read(File.expand_path('README.md')))
renderer.render(File.read(File.expand_path('app/templates/index.md')))
end

get '/crash' do
Expand All @@ -76,12 +76,12 @@ class App < Padrino::Application
end

get '/crash_with_callback' do
Bugsnag.before_notify_callbacks << proc { |notification|
Bugsnag.before_notify_callbacks << proc { |report|
new_tab = {
message: 'Padrino demo says: Everything is great',
code: 200
}
notification.add_tab(:diagnostics, new_tab)
report.add_tab(:diagnostics, new_tab)
}

msg = 'Bugsnag Padrino demo says: It crashed! But, due to the attached callback' +
Expand All @@ -98,31 +98,31 @@ class App < Padrino::Application
' for a new notification.'
end

get '/notify_meta' do
meta_data = {
:user => {
get '/notify_data' do
error = RuntimeError.new("Bugsnag Padrino demo says: False alarm, your application didn't crash")
Bugsnag.notify error do |report|
report.add_tab(:user, {
:username => "bob-hoskins",
:email => 'bugsnag@bugsnag.com',
:registered_user => true
},

:diagnostics => {
})
report.add_tab(:diagnostics, {
:message => 'Padrino demo says: Everything is great',
:code => 200
}
}
error = RuntimeError.new("Bugsnag Padrino demo says: False alarm, your application didn't crash")
Bugsnag.notify(error, meta_data)
})
end

"Bugsnag Padrino demo says: It didn't crash! " +
'But still go check <a href="https://bugsnag.com">https://bugsnag.com</a>' +
' for a new notification. Check out the User tab for the meta data'
end

get '/severity' do
get '/notify_severity' do
msg = "Bugsnag Padrino demo says: Look at the circle on the right side. It's different"
error = RuntimeError.new(msg)
Bugsnag.notify(error, severity: 'info')
Bugsnag.notify error do |report|
report.severity = 'info'
end
msg
end
end
Expand Down
25 changes: 25 additions & 0 deletions example/padrino/app/templates/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Bugsnag Padrino demo

This application demonstrates the use of Bugsnag with the Padrino web framework.

While testing the examples open [your dashboard](https://app.bugsnag.com) in order to see the example errors and exceptions being received.

1. [Crash](/crash)
<br/>
Raises an error within the framework, generating a report in the Bugsnag dashboard.

2. [Crash and use callbacks](/crash_with_callback)
<br/>
Raises an exception within the framework, but with additional data attached to the report. By registering a callback before the error occurs useful data can be attached as a tab in the Bugsnag dashboard.

3. [Notify](/notify)
<br/>
Sends Bugsnag a report on demand using `bugsnag.notify`. Allows details of handled errors or information to be sent to the Bugsnag dashboard without crashing your code.

4. [Notify with data](/notify_data)
<br/>
Same as `notify` but allows you to attach additional data within a `block`, similar to the `before_notify_callbacks` example above. In this case we're adding information about the user to go into the `user` tab, and additional diagnostics as a `diagnostics` tab.

5. [Set the severity](/notify_severity)
<br/>
This uses the same mechanism as adding meta-data, but allows you to set he `severity` when notifying Bugsnag of the error. Valid severities are `error`, `warning`, and `info`. Have a look on the dashboard to see the difference in these severities.
2 changes: 1 addition & 1 deletion example/padrino/config/boot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#
Padrino.before_load do
Bugsnag.configure do |config|
config.api_key = 'f35a2472bd230ac0ab0f52715bbdc65d'
config.api_key = 'YOUR_API_KEY'
end
end

Expand Down
40 changes: 0 additions & 40 deletions example/padrino/config/database.rb

This file was deleted.

Binary file removed example/padrino/public/favicon.ico
Binary file not shown.
1 change: 0 additions & 1 deletion example/padrino/public/javascripts/application.js

This file was deleted.

109 changes: 0 additions & 109 deletions example/padrino/public/javascripts/jquery-ujs.js

This file was deleted.

4 changes: 0 additions & 4 deletions example/padrino/public/javascripts/jquery.js

This file was deleted.

Loading