Giter Site home page Giter Site logo

Puma about analytics-ruby HOT 7 CLOSED

segmentio avatar segmentio commented on July 23, 2024
Puma

from analytics-ruby.

Comments (7)

ajsharp avatar ajsharp commented on July 23, 2024 1

Apologies, it looks like I was running into #180 as well.

from analytics-ruby.

calvinfo avatar calvinfo commented on July 23, 2024

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!

from analytics-ruby.

recyclerobot avatar recyclerobot commented on July 23, 2024

Hi calvinfo!

Thanks for the on_worker_boot

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

bundle exec puma -t 8:32 -w 2 --preload -e $RACK_ENV -b tcp://0.0.0.0:$PORT -C config/puma.rb

Thanks again for the directions!
Ps: maybe you can add it this in the documentation after the unicorn and passenger parts :)

from analytics-ruby.

calvinfo avatar calvinfo commented on July 23, 2024

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 :)

from analytics-ruby.

phildionne avatar phildionne commented on July 23, 2024

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 $AnalyticsBackend instance that is shared across threads.

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:

  • Rails 5.2.2
  • Ruby 2.5.3
  • Puma 3.12.0
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!

# ...

from analytics-ruby.

ajsharp avatar ajsharp commented on July 23, 2024

I'm seeing the same problem. This seems like a pretty serious issue, as puma is probably the most popular ruby app server.

from analytics-ruby.

ajsharp avatar ajsharp commented on July 23, 2024

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 user_id is a BSON::ObjectId. However, if I to_s that object, it succeeds and I see the event in the segment debugger.

from analytics-ruby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.