[LRUG] Rails log_tags in production

Andrew Stewart boss at airbladesoftware.com
Mon Jul 18 02:19:19 PDT 2016


Hello LRUG!

I am trying to log the current user id in a Rails app via the following configuration:

  # config/environments/{development,production}.rb
  config.log_tags = [
    lambda { |request|
      session_key = Rails.application.config.session_options[:key]
      session_data = request.cookie_jar.signed[session_key]
      user_id = session_data['current_person_id']
      user_id || 'public'
    }
  ]

This works fine in development but in production, although the site works perfectly for a user, Pingdom immediately reports a 500 error and unicorn.stderr.log shows:

  app error: undefined method `[]' for nil:NilClass (NoMethodError)
  /path/to/my/app/releases/20160717162528/config/environments/production.rb:49

Line 49 is the `user_id = session_data['current_person_id']` one above.

In production I'm using Rails 3.2 and Unicorn 4.2.0 (behind Nginx 1.6.2).

Does anyone know why this doesn't work in production for Pingdom's bot?

Many thanks in advance!

Yours,

Andy Stewart


More information about the Chat mailing list