reevoo / sapience-rb

Hasslefree auto-configuration for logging, metrics and exception collection.
MIT License
10 stars 0 forks source link

Sapience error! is failing without payload #33

Open robinbortlik opened 7 years ago

robinbortlik commented 7 years ago

Hi guys,

we noticed that Aslan is not reporting any exception in last days and then discovered in the logs that sapience is failing when try to report exception to sentry. Here is example log:

{
   "name":"Sapience",
   "pid":42,
   "thread":"puma 001",
   "level":"error",
   "level_index":4,
   "host":"aslan-api-1314676901-vau89",
   "app_name":"aslan",
   "file":"/usr/src/lib/aslan/api.rb",
   "line":20,
   "tags":[
      "Grape::Exceptions::ValidationErrors",
      "tags is missing"
   ],
   "message":"Raven.capture_type failed with",
   "exception":{
      "name":"NoMethodError",
      "message":"undefined method `[]' for nil:NilClass",
      "stack_trace":[
         "/usr/local/lib/ruby/gems/2.2.0/gems/sapience-2.0.5/lib/sapience/error_handler/sentry.rb:67:in `capture'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/sapience-2.0.5/lib/sapience/error_handler/sentry.rb:40:in `capture_exception'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/sapience-2.0.5/lib/sapience/sapience.rb:300:in `capture_exception'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/sapience-2.0.5/lib/sapience/log_methods.rb:48:in `log_with_exception'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/sapience-2.0.5/lib/sapience/log_methods.rb:38:in `error!'",
         "/usr/src/lib/aslan/api.rb:20:in `block in <class:Base>'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/middleware/error.rb:76:in `instance_exec'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/middleware/error.rb:76:in `exec_handler'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/middleware/error.rb:45:in `rescue in call!'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/middleware/error.rb:32:in `call!'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/middleware/base.rb:24:in `call'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/rack-2.0.1/lib/rack/head.rb:12:in `call'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/endpoint.rb:224:in `call!'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/endpoint.rb:218:in `call'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/router/route.rb:72:in `exec'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/router.rb:119:in `process_route'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/router.rb:74:in `block in identity'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/router.rb:93:in `transaction'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/router.rb:72:in `identity'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/router.rb:57:in `block in call'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/router.rb:135:in `with_optimization'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/router.rb:56:in `call'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/api.rb:119:in `call'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/api.rb:45:in `call!'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/api.rb:40:in `call'",
         "/usr/local/lib/ruby/gems/2.2.0/bundler/gems/rack-protection-4b3dc577e770/lib/rack/protection/strict_transport.rb:31:in `call'",
         "/usr/local/lib/ruby/gems/2.2.0/bundler/gems/rack-protection-4b3dc577e770/lib/rack/protection/xss_header.rb:18:in `call'",
         "/usr/local/lib/ruby/gems/2.2.0/bundler/gems/rack-protection-4b3dc577e770/lib/rack/protection/path_traversal.rb:16:in `call'",
         "/usr/local/lib/ruby/gems/2.2.0/bundler/gems/rack-protection-4b3dc577e770/lib/rack/protection/json_csrf.rb:18:in `call'",
         "/usr/local/lib/ruby/gems/2.2.0/bundler/gems/rack-protection-4b3dc577e770/lib/rack/protection/base.rb:49:in `call'",
         "/usr/local/lib/ruby/gems/2.2.0/bundler/gems/rack-protection-4b3dc577e770/lib/rack/protection/frame_options.rb:31:in `call'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/rack-2.0.1/lib/rack/static.rb:149:in `call'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/rack-cors-0.4.1/lib/rack/cors.rb:81:in `call'",
         "/usr/src/lib/aslan/status.rb:19:in `call'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/puma-3.6.2/lib/puma/configuration.rb:225:in `call'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/puma-3.6.2/lib/puma/server.rb:578:in `handle_request'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/puma-3.6.2/lib/puma/server.rb:415:in `process_client'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/puma-3.6.2/lib/puma/server.rb:275:in `block in run'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/puma-3.6.2/lib/puma/thread_pool.rb:116:in `call'",
         "/usr/local/lib/ruby/gems/2.2.0/gems/puma-3.6.2/lib/puma/thread_pool.rb:116:in `block in spawn_thread'"
      ],
      "cause":{
         "name":"Grape::Exceptions::ValidationErrors",
         "message":"tags is missing",
         "stack_trace":[
            "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/endpoint.rb:352:in `run_validators'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/endpoint.rb:260:in `block in run'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/activesupport-5.0.1/lib/active_support/notifications.rb:164:in `block in instrument'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/activesupport-5.0.1/lib/active_support/notifications/instrumenter.rb:21:in `instrument'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/activesupport-5.0.1/lib/active_support/notifications.rb:164:in `instrument'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/endpoint.rb:240:in `run'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/endpoint.rb:309:in `block in build_stack'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/middleware/base.rb:31:in `call'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/middleware/base.rb:31:in `call!'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/middleware/base.rb:24:in `call'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/middleware/base.rb:31:in `call!'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/middleware/base.rb:24:in `call'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/sapience-2.0.5/lib/sapience/extensions/grape/middleware/logging.rb:28:in `block in call!'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/sapience-2.0.5/lib/sapience/extensions/grape/middleware/logging.rb:26:in `catch'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/sapience-2.0.5/lib/sapience/extensions/grape/middleware/logging.rb:26:in `call!'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/middleware/base.rb:24:in `call'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/middleware/error.rb:34:in `block in call!'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/middleware/error.rb:33:in `catch'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/middleware/error.rb:33:in `call!'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/middleware/base.rb:24:in `call'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/rack-2.0.1/lib/rack/head.rb:12:in `call'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/endpoint.rb:224:in `call!'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/endpoint.rb:218:in `call'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/router/route.rb:72:in `exec'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/router.rb:119:in `process_route'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/router.rb:74:in `block in identity'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/router.rb:93:in `transaction'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/router.rb:72:in `identity'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/router.rb:57:in `block in call'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/router.rb:135:in `with_optimization'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/router.rb:56:in `call'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/api.rb:119:in `call'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/api.rb:45:in `call!'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/grape-0.19.0/lib/grape/api.rb:40:in `call'",
            "/usr/local/lib/ruby/gems/2.2.0/bundler/gems/rack-protection-4b3dc577e770/lib/rack/protection/strict_transport.rb:31:in `call'",
            "/usr/local/lib/ruby/gems/2.2.0/bundler/gems/rack-protection-4b3dc577e770/lib/rack/protection/xss_header.rb:18:in `call'",
            "/usr/local/lib/ruby/gems/2.2.0/bundler/gems/rack-protection-4b3dc577e770/lib/rack/protection/path_traversal.rb:16:in `call'",
            "/usr/local/lib/ruby/gems/2.2.0/bundler/gems/rack-protection-4b3dc577e770/lib/rack/protection/json_csrf.rb:18:in `call'",
            "/usr/local/lib/ruby/gems/2.2.0/bundler/gems/rack-protection-4b3dc577e770/lib/rack/protection/base.rb:49:in `call'",
            "/usr/local/lib/ruby/gems/2.2.0/bundler/gems/rack-protection-4b3dc577e770/lib/rack/protection/frame_options.rb:31:in `call'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/rack-2.0.1/lib/rack/static.rb:149:in `call'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/rack-cors-0.4.1/lib/rack/cors.rb:81:in `call'",
            "/usr/src/lib/aslan/status.rb:19:in `call'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/puma-3.6.2/lib/puma/configuration.rb:225:in `call'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/puma-3.6.2/lib/puma/server.rb:578:in `handle_request'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/puma-3.6.2/lib/puma/server.rb:415:in `process_client'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/puma-3.6.2/lib/puma/server.rb:275:in `block in run'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/puma-3.6.2/lib/puma/thread_pool.rb:116:in `call'",
            "/usr/local/lib/ruby/gems/2.2.0/gems/puma-3.6.2/lib/puma/thread_pool.rb:116:in `block in spawn_thread'"
         ]
      }
   },
   "timestamp":"2017-05-26T10:12:37.287006Z"
}

We fixed the issue by passing payload to the error! method. You can see the fix here: https://github.com/reevoo/aslan/pull/126/files#diff-e39cb3813ea65c4fbd167c990f78b8a5L20

But still we think, that the sapience should take care of it and provide some default for the payload, like empty hash.

What do you think?