Rails rake rollbar:test didn't pass - ruby-on-rails

I was trying to use rollbar gem to monitor error message.
I followed its document.
Add gem 'rollbar', and rails generate rollbar POST_SERVER_ITEM_ACCESS_TOKEN.
(I did changed the POST_SERVER_ITEM_ACCESS_TOKEN to my key)
But after I run rake rollbar:test, it only threw Test error from rollbar:test in dashboard.
Update
initializers/rollbar
Rollbar.configure do |config|
if Rails.env.test?
config.enabled = false
end
In console
rake rollbar:test 16:21:14
Testing manual report...
[Rollbar] Scheduling item
[Rollbar] Sending item
[Rollbar] Success
[Rollbar] Details: https://rollbar.com/instance/uuid?uuid=1f4c4e35-df5f-4606-916d-d97341b01dc7 (only available if report was successful)
Setting up the controller.
Processing...
Started GET "/verify" for at 2016-12-02 16:21:21 +0800

Check your rollbar config, probably it's disabled in development mode.
https://github.com/rollbar/rollbar-gem/blob/master/lib/generators/rollbar/templates/initializer.rb#L7

Related

How to setup error 404 page in Ruby on Rails system testing

Rails 5.1 introduced system testing that uses Capybara with Selenium to test the UI of Rails application.
I'm wondering to how to use this system testing to test the UI of error pages.
For standard controller tests, we can do something like below to assert response to be 404.
test 'should get not_found' do
get errors_not_found_url
assert_response :not_found
end
But for system tests, if I go to a 404 page, exception will be thrown in controller level and tests terminate immediately without rendering the page.
test '404 page should render with the correct title' do
# act.
visit NOT_FOUND_URL
# assert.
assert_equal("#{APP_NAME} - #{TITLE_404}", page.title)
end
Exception is thrown in controller level.
$ rails test test/system/error/error_page_test.rb
Run options: --seed 30076
# Running:
Puma starting in single mode...
* Version 3.9.1 (ruby 2.3.1-p112), codename: Private Caller
* Min threads: 0, max threads: 1
* Environment: test
* Listening on tcp://0.0.0.0:55237
Use Ctrl-C to stop
2017-07-09 11:10:45 +1200: Rack app error handling request { GET /books/12345678 }
#<ActionController::RoutingError: Could not find book '12345678' by id or name>
/myapp/app/controllers/books_controller.rb:7:in `index'
/Users/yze14/.rvm/gems/ruby-2.3.1/gems/actionpack-5.1.2/lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
/Users/yze14/.rvm/gems/ruby-2.3.1/gems/actionpack-5.1.2/lib/abstract_controller/base.rb:186:in `process_action'
...
Under development/test environment, config.consider_all_requests_local can be set to false in order to show error page instead of stracktrace. But this doesn't swallow exception during system tests.
If you don't want Capybara to re-raise server exceptions in the tests you can set Capybara.raise_server_errors = false.
Secondly, you should check your Gemfile and make sure any gems like web-console,better-errrors, etc are only loaded in the development environment (not in the test environment)
Finally, you shouldn't be using assert_equal with title, you should be using the Capybara provided assert_title which includes waiting/retrying behavior and will reduce potential flakiness in tests.
assert_title("#{APP_NAME} - #{TITLE_404}")

mixpanel gem breaks cucumber tests

i'm using cucumber+capybara to test my app. But after adding mixpanel to my code i've got errors
Mixpanel::ConnectionError at /users =================================== > Could not write to Mixpanel, server responded with 200 returning: '{"status": 0, "error": "distinct_id, missing or empty"}'
how can i fix it?

Why is Mongoid/Moped throwing Timeout::Error to Airbrake in production Rake tasks?

I'm having a problem on my production installation. I have several scheduled rake tasks that run successfully. However, I've been getting MANY Timeout::Error: execution expired emails from Airbrake.
But, here's the weird part: the Rake tasks all complete successfully. I'm capturing the stdout/stderr in the cron command, and the errors don't appear in the logs. I've also added simple print statements to the end of the rake tasks to verify their completion.
How can I further troubleshoot this?
Here is a stacktrace from one of the emails:
[GEM_ROOT]/gems/moped-1.2.5/lib/moped/connection.rb:203
[GEM_ROOT]/gems/moped-1.2.5/lib/moped/connection.rb:203
[GEM_ROOT]/gems/moped-1.2.5/lib/moped/connection.rb:235
[GEM_ROOT]/gems/moped-1.2.5/lib/moped/connection.rb:203
[GEM_ROOT]/gems/moped-1.2.5/lib/moped/connection.rb:260
[GEM_ROOT]/gems/moped-1.2.5/lib/moped/connection.rb:260
[GEM_ROOT]/gems/moped-1.2.5/lib/moped/connection.rb:259
[GEM_ROOT]/gems/moped-1.2.5/lib/moped/connection.rb:153
[GEM_ROOT]/gems/moped-1.2.5/lib/moped/connection.rb:30
[GEM_ROOT]/gems/moped-1.2.5/lib/moped/node.rb:507
[GEM_ROOT]/gems/moped-1.2.5/lib/moped/node.rb:122
[GEM_ROOT]/gems/moped-1.2.5/lib/moped/node.rb:527
[GEM_ROOT]/gems/moped-1.2.5/lib/moped/node.rb:542
[GEM_ROOT]/gems/moped-1.2.5/lib/moped/node.rb:526
[GEM_ROOT]/gems/moped-1.2.5/lib/moped/node.rb:515
[GEM_ROOT]/gems/newrelic_moped-0.0.3/lib/newrelic_moped/instrumentation.rb:24
[GEM_ROOT]/gems/newrelic_rpm-3.4.2.1/lib/new_relic/agent/method_tracer.rb:242
[GEM_ROOT]/gems/newrelic_moped-0.0.3/lib/newrelic_moped/instrumentation.rb:20
[GEM_ROOT]/gems/moped-1.2.5/lib/moped/node.rb:70
[GEM_ROOT]/gems/moped-1.2.5/lib/moped/node.rb:376
[GEM_ROOT]/gems/moped-1.2.5/lib/moped/cluster.rb:112
[GEM_ROOT]/gems/moped-1.2.5/lib/moped/cluster.rb:125
[GEM_ROOT]/gems/moped-1.2.5/lib/moped/cluster.rb:125
[GEM_ROOT]/gems/moped-1.2.5/lib/moped/cluster.rb:78
[GEM_ROOT]/gems/moped-1.2.5/lib/moped/cluster.rb:147
[GEM_ROOT]/gems/moped-1.2.5/lib/moped/session/context.rb:108
[GEM_ROOT]/gems/moped-1.2.5/lib/moped/session/context.rb:50
[GEM_ROOT]/gems/moped-1.2.5/lib/moped/database.rb:76
[GEM_ROOT]/gems/moped-1.2.5/lib/moped/query.rb:36
[GEM_ROOT]/gems/mongoid-3.0.5/lib/mongoid/contextual/mongo.rb:69
[GEM_ROOT]/gems/mongoid-3.0.5/lib/mongoid/contextual.rb:18
[PROJECT_ROOT]/lib/tasks/reminders.rake:7
[GEM_ROOT]/gems/rake-0.9.2.2/lib/rake/task.rb:205
[GEM_ROOT]/gems/rake-0.9.2.2/lib/rake/task.rb:205
[GEM_ROOT]/gems/rake-0.9.2.2/lib/rake/task.rb:200
[GEM_ROOT]/gems/rake-0.9.2.2/lib/rake/task.rb:200
[GEM_ROOT]/gems/rake-0.9.2.2/lib/rake/task.rb:158
/usr/lib/ruby/1.9.1/monitor.rb:211
[GEM_ROOT]/gems/rake-0.9.2.2/lib/rake/task.rb:151
[GEM_ROOT]/gems/rake-0.9.2.2/lib/rake/task.rb:144
[GEM_ROOT]/gems/rake-0.9.2.2/lib/rake/application.rb:116
[GEM_ROOT]/gems/rake-0.9.2.2/lib/rake/application.rb:94
[GEM_ROOT]/gems/rake-0.9.2.2/lib/rake/application.rb:94
[GEM_ROOT]/gems/rake-0.9.2.2/lib/rake/application.rb:94
[GEM_ROOT]/gems/rake-0.9.2.2/lib/rake/application.rb:133
[GEM_ROOT]/gems/rake-0.9.2.2/lib/rake/application.rb:88
[GEM_ROOT]/gems/rake-0.9.2.2/lib/rake/application.rb:66
[GEM_ROOT]/gems/rake-0.9.2.2/lib/rake/application.rb:133
[GEM_ROOT]/gems/rake-0.9.2.2/lib/rake/application.rb:63
[GEM_ROOT]/gems/rake-0.9.2.2/bin/rake:33
[GEM_ROOT]/bin/rake:19
[GEM_ROOT]/bin/rake:19

Heroku: see params and sql activity in logs?

When i view my heroku logs on the server (with heroku logs --tail --app myapp) i see something like this:
2011-06-21T14:09:25+00:00 app[web.1]: Started PUT "/reports/19.xml" for 77.89.149.137 at 2011-06-21 07:09:25 -0700
2011-06-21T14:09:25+00:00 heroku[router]: PUT myapp.heroku.com/reports/19.xml dyno=web.1 queue=0 wait=0ms service=7ms status=401 bytes=28
2011-06-21T14:09:26+00:00 heroku[nginx]: PUT /reports/19.xml HTTP/1.1 | 77.89.149.137 | 656 | http | 401
While in my local log i'd see something like this:
Started PUT "/reports/19" for 127.0.0.1 at 2011-06-21 15:27:01 +0100
Processing by ReportsController#update as XML
Parameters: {"report"=>{"workflow_status"=>"3"}, "id"=>"19"}
Person Load (0.9ms) SELECT "people".* FROM "people" WHERE "people"."email" = 'madeupemai#lkklj.com' LIMIT 1
Report Load (0.4ms) SELECT "reports".* FROM "reports" WHERE "reports"."id" = 19 LIMIT 1
DEPRECATION WARNING: Object#returning has been deprecated in favor of Object#tap. (called from update_report at /home/max/work/rails_apps/flamingo_container/flamingo/vendor/plugins/resource_this/lib/resource_this.rb:135)
Creating scope :open. Overwriting existing method Task.open.
Task Load (2.0ms) SELECT "tasks".* FROM "tasks" WHERE "tasks"."id" = 14 LIMIT 1
Completed 200 OK in 1648ms (Views: 568.2ms | ActiveRecord: 3.2ms)
Ie with a lot more information, particularly the params, info from the router, generated sql, any templates rendered etc etc.
Does anyone know how i can get my heroku log to be as verbose as my development one? I've done the following already:
1) Set the log level in the relevant (rails 3) environment file:
config.log_level = :debug
2) Told heroku to use a different logger level, as described on http://devcenter.heroku.com/articles/logging
heroku config:add LOG_LEVEL=DEBUG --app myapp #from CLI
Neither has made any difference...any ideas anyone?
thanks, max
You're essentially wanting to show the SQL / params output in the Heroku logs. You can do this by adding the line shown below to the config block within your production.rb file:
MyAppNameHere::Application.configure do
# add this line
config.logger = Logger.new(STDOUT)
end
By the way, setting the log level to debug just means that Rails.logger.debug will output to the logs when you're on Heroku
In your production.rb add config.log_level = :debug and redeploy. That will give you the same logs as development mode :)
The detailed log you want is generated by the function start_processing in log_subscriber.rb.
action_controller/log_subscriber.rb:
def start_processing(event)
payload = event.payload
params = payload[:params].except(*INTERNAL_PARAMS)
info " Processing by #{payload[:controller]}##{payload[:action]} as #{payload[:formats].first.to_s.upcase}"
info " Parameters: #{params.inspect}" unless params.empty?
end
I checked with rails 3.0.4 in development and production environment. In both environments, we have the detailed logs.
This is an info level log. That's why the debug log level is not changing the output.
I installed the plugin used by heroku rails_log_stdout (Heroku logging) but I still have the desired output.
Right now, I can't test with heroku to find out why you don't have all the logs.
In the heroku example (see Heroku logging, section log retrieval), we don't see the "Processing" and "Parameters" lines. I think that either this method is not called when the app is running on heroku (it is somehow disabled) or heroku skips logs starting with whitespaces. Could you try to log messages starting with whitespaces and see if heroku is showing them?
Rails doesn't generate those logs when in production mode. http://groups.google.com/group/heroku/browse_thread/thread/d778fafedc9a378a
The real problem is actually due to the way Heroku works in conjunction with rails. The right way to solve this is to add: gem 'rails_12factor', group: :production
See https://devcenter.heroku.com/articles/rails-integration-gems for more info on the matter
Looks like the puma server doesn't play well with Heroku. In my project, I tried everything, but it still wouldn't log. I then replaced Puma with Unicorn, and bam, full logs are being shown.

SMTP error with Rails Exception Notifier plugin

Working on OS X, trying to get Rails Exception Notifier plugin to send out emails. I have verified the following:
I can successfully send email from my app
I am creating a test error (1/0 in one of my actions).
Current plugin installed...
script/plugin install git://github.com/rails/exception_notification.git
In ApplicationController...
include ExceptionNotifiable
local_addresses.clear
In environment.rb...
Rails::Initializer.run do |config|
# ...
config.after_initialize do
ExceptionNotifier.exception_recipients = %w(abc#gmail.com abc#abc.gov)
ExceptionNotifier.sender_address = %("Contact DB error" <abc#abc.gov>)
ExceptionNotifier.email_prefix = "[Contact DB error] "
end
end
In addition to the intentionally-created test error, I'm seeing this error on the console...
Processing ApplicationController#index (for 127.0.0.1 at 2009-10-02 14:40:55) [GET]
Net::SMTPFatalError (555 5.5.2 Syntax error. 3sm30577fge.12
):
/usr/local/lib/ruby/1.8/net/smtp.rb:680:in `check_response'
/usr/local/lib/ruby/1.8/net/smtp.rb:653:in `getok'
/usr/local/lib/ruby/1.8/net/smtp.rb:631:in `mailfrom'
/usr/local/lib/ruby/1.8/net/smtp.rb:544:in `send0'
/usr/local/lib/ruby/1.8/net/smtp.rb:472:in `sendmail'
/usr/local/lib/ruby/1.8/net/smtp.rb:379:in `start'
haml (2.2.6) rails/./lib/sass/plugin/rails.rb:19:in `process'
Then it tries to send an exception notification for the SMTP error...
Subject: [Contact DB error] application#index (Net::SMTPFatalError) "555 5.5.2 Syntax error. 3sm30577fge.12\n"
This page seems to indicate it is related to your from address. Try changing it to just abc#abc.gov.

Resources