<div dir="ltr">My gut feel is that Pingdom is probably not sending any session cookies, so session_data will be returning nil.</div><br><div class="gmail_quote"><div dir="ltr">On Mon, 18 Jul 2016 at 10:19 Andrew Stewart <<a href="mailto:boss@airbladesoftware.com">boss@airbladesoftware.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello LRUG!<br>
<br>
I am trying to log the current user id in a Rails app via the following configuration:<br>
<br>
  # config/environments/{development,production}.rb<br>
  config.log_tags = [<br>
    lambda { |request|<br>
      session_key = Rails.application.config.session_options[:key]<br>
      session_data = request.cookie_jar.signed[session_key]<br>
      user_id = session_data['current_person_id']<br>
      user_id || 'public'<br>
    }<br>
  ]<br>
<br>
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:<br>
<br>
  app error: undefined method `[]' for nil:NilClass (NoMethodError)<br>
  /path/to/my/app/releases/20160717162528/config/environments/production.rb:49<br>
<br>
Line 49 is the `user_id = session_data['current_person_id']` one above.<br>
<br>
In production I'm using Rails 3.2 and Unicorn 4.2.0 (behind Nginx 1.6.2).<br>
<br>
Does anyone know why this doesn't work in production for Pingdom's bot?<br>
<br>
Many thanks in advance!<br>
<br>
Yours,<br>
<br>
Andy Stewart<br>
_______________________________________________<br>
Chat mailing list<br>
<a href="mailto:Chat@lists.lrug.org" target="_blank">Chat@lists.lrug.org</a><br>
Archives: <a href="http://lists.lrug.org/pipermail/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/pipermail/chat-lrug.org</a><br>
Manage your subscription: <a href="http://lists.lrug.org/options.cgi/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/options.cgi/chat-lrug.org</a><br>
List info: <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>
</blockquote></div>