-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Puma #37
Comments
I haven't used Puma, but from looking at their docs, you'll probably want to add something like this to your puma config: # config/puma.rb
on_worker_boot do
Analytics = AnalyticsRuby
Analytics.init({ secret: YOUR_SEGMENTIO_KEY })
end Let me know if that doesn't work, and I can take a closer look! |
Hi calvinfo! Thanks for the I've got it working using this: # config/puma.rb
require 'analytics-ruby'
on_worker_boot do
puts "Init segment.io analytics"
if defined? AnalyticsRuby
Analytics = AnalyticsRuby # Alias for convenience
Analytics.init({
secret: 'XXXXXX', # The write key for
on_error: Proc.new { |status, msg| print msg } # Optional error handler
})
end
end adding the /initializers/analytics.rb Analytics = AnalyticsRuby and add the -C config/puma.rb flag to your Procfile
Thanks again for the directions! |
Awesome! Yeah, we're about to completely overhaul the docs so I'll help get it in with the new re-write. Glad to hear it worked out :) |
Hey guys, I'm having trouble sending events in production. The solution outlined in this issue doesn't seem to work anymore. My understanding of the desired behavior here is that we'd want a global Once I've seen that the worker thread was dead, but haven't been able to replicate it consistently. @calvinfo is there any official way now to do this? Thanks Configuration:
class Analytics
class_attribute :backend, instance_writer: false, default: $AnalyticsBackend
def track(event:, properties: {})
# ...
end
# ...
end # initializers/analytics.rb
$AnalyticsBackend = Segment::Analytics.new({
write_key: "...",
on_error: Proc.new { |status, msg| print msg }
}) # config/puma.rb
threads 5, 5
workers 2
on_worker_shutdown do
Analytics.flush
end
preload_app!
# ... |
I'm seeing the same problem. This seems like a pretty serious issue, as puma is probably the most popular ruby app server. |
This might be completely off-topic, but in trying to debug what's going on here, I've noticed that I can't send events through from my production rails console if the |
Apologies, it looks like I was running into #180 as well. |
How to correctly implement this with a multi instances puma envirnoment?
The text was updated successfully, but these errors were encountered: