Skip to content

Conversation

rohitpaulk
Copy link
Collaborator

@rohitpaulk rohitpaulk commented Jun 12, 2018

Fixes #161

This bug only occurs when both oj and rails are loaded. The code works fine with either oj or rails. I've added tests for these conflicts, they run in sub-processes so that they're isolated.

The issue here is that a custom to_json definition isn't honored when objects are in an array. The 'ideal' fix for this must be applied in either oj or rails. After a bit of experimentation, I think the simplest solution on our end is to just circumvent the problem. This PR removes the Message class so that we're relying solely on Ruby core classes for JSON generation. This way, if either oj or rails (or any other gem that monkey patches JSON generation) misbehave, it'll be a widespread problem (affects either Array or Hash) and not just local to our use case.

One downside here is that we'll be generating json for each message twice - once for checking the size, and another time when actually sending the message to segment. This wasn't the case with the earlier solution because our custom to_json definition cached this value. I think this is acceptable though, it isn't a huge penalty and working around it wouldn't be trivial.

@rohitpaulk rohitpaulk force-pushed the rohitpaulk/oj-rails-conflict-test-cases branch from cf487e1 to 5d88c4d Compare June 13, 2018 12:48
@rohitpaulk rohitpaulk changed the title [WIP] Add tests for oj/rails conflict [WIP] Fix oj/rails conflict Jun 13, 2018
@rohitpaulk rohitpaulk force-pushed the rohitpaulk/oj-rails-conflict-test-cases branch 2 times, most recently from df7fa15 to 9db3cc4 Compare June 13, 2018 13:16
@codecov-io

This comment has been minimized.

@rohitpaulk rohitpaulk force-pushed the rohitpaulk/oj-rails-conflict-test-cases branch from 9db3cc4 to 13b75bc Compare June 13, 2018 13:31
@rohitpaulk rohitpaulk force-pushed the rohitpaulk/oj-rails-conflict-test-cases branch from 13b75bc to 220011d Compare June 13, 2018 13:38
@rohitpaulk rohitpaulk requested a review from f2prateek June 13, 2018 13:58
@rohitpaulk rohitpaulk changed the title [WIP] Fix oj/rails conflict Fix oj/rails conflict Jun 13, 2018
@f2prateek f2prateek merged commit efbb754 into master Jun 13, 2018
@rohitpaulk rohitpaulk deleted the rohitpaulk/oj-rails-conflict-test-cases branch June 14, 2018 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upgrade from 2.2.2 to 2.2.5 caused loss of event track calls
3 participants