rawls238 / PlanOut.js

A JavaScript port of Facebook's PlanOut Experimentation Framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Do not parse assign function source code to get parameter names

TimBeyer opened this issue · comments

I just spent several hours trying to debug a mistake in my code, when I noticed that experiment.experimentParameters was returning weird data.

So I looked up the code and realized what's going on: https://github.com/HubSpot/PlanOut.js/blob/0d26ab31a3995cd490d01c271984629ec2051954/es6/experiment.js#L32-L40

You are parsing the actual code of the assign function to find this.set('foo', bar) so you'd know that 'foo' is being set. Sadly, this does not work at all if the parameter name that is being set is actually coming from a variable, which broke the library for me.

I'd suggest to not do this magic by default and instead require this function to be overridden. It's absolutely opaque that such kind of logic could happen and the library fails in a completely unpredictable way without any error messages. It just never finds your parameters if they are within a namespace.

hm that is a good point, I didn't think of that usecase when this was added. Originally this was added to prevent this issue: facebookarchive/planout#69

We can potentially add a metadata function for each experiment where you define the range of experimental parameters that the experiment can take and the namespace can evaluate the metadata function with the key passed into the get function to determine whether or not exposure should be logged / the parameter should be retrieved. I'll sketch out a solution to this this weekend and tag you on the PR

Awesome, thanks @rawls238