Comments (7)
Apologies, it looks like I was running into #180 as well.
from analytics-ruby.
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.
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.
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.
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.
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.
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)
- Introduce sub millisecond timestamps
- Update Travis CI to test supported Ruby versions
- Convert from Travis CI to CircleCI HOT 2
- Enable Logging HOT 1
- at_exit question HOT 1
- Error in documentation HOT 2
- Issues with sending several events at the same moment HOT 1
- anonymous_id HOT 2
- Adding message_id to track call using js2.0 style messageId fails to process HOT 2
- Using `Analytics.flush` to ensure event delivery order? HOT 4
- Empty string user id's silently fail to send events HOT 1
- window._cio.page is not a function HOT 2
- override listid for mailchimp HOT 5
- Modify timestamp to have 3 fractional digits
- Convert project to Github Actions
- Missing some tracked events in debugger HOT 2
- ::Segment is too generic a namespace HOT 1
- API returns a 200 with wrong auth key HOT 6
- Convert to Github Actions HOT 1
- wrong argument type nil (expected String) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from analytics-ruby.