Enable priority sampling by default#654
Conversation
There was a problem hiding this comment.
Added this check because if you configured the tracer twice, it would wrap the previous PrioritySampler with another PrioritySampler, and that seems problematic...
There was a problem hiding this comment.
yeah, we have a weird thing in dd-trace-py where we have priority_sampling default to nil so that we only try to update the sampler if the option has been provided, rather than defaulting to True.
I think this basically does the same thing.
There was a problem hiding this comment.
it might be good to add a comment here about why we have this check here.
There was a problem hiding this comment.
Cool, I'll add that.
There was a problem hiding this comment.
I see we updated options.fetch(:priority_sampling, true), does that mean we should have this be if !priority_sampling.nil? (sorry for my bad ruby)
Since nil is falsey, we probably only want to modify what sampler/writer we are using if we are setting priority sampling.
Also, do we need to handle :priority_smapling => false? if we reconfigure and set to false do we need to update the sampler/writer again to use a RateSampler?
There was a problem hiding this comment.
Since
nilis falsey, we probably only want to modify what sampler/writer we are using if we are setting priority sampling.
Consider the following: {}.fetch(:a, true) #=> true. Users would have to explicitly specify the key with a nil value in order to pass nil.
Given the above, I think your original assertion is already the case here. The if block wouldn't run if given nil, but it should never receive nil unless given nil explicitly.
Also, do we need to handle
:priority_smapling => false? if we reconfigure and set to false do we need to update the sampler/writer again to use aRateSampler?
I think if we support this, then we need to add an elsif:
elsif !priority_sampling
@sampler = sampler || Datadog::AllSampler.new if @sampler.is_a?(PrioritySampler)
@writer = Writer.new
endIf you want nil to be a no-op, then you'd have to change !priority_sampling to priority_sampling == false.
There was a problem hiding this comment.
yeah, sorry I misread the code. In dd-trace-py we default to None (nil), which means the user did not supply the option so we then default to True.
How do we instruct people to use #configure ?
In dd-trace-py we allow people to supply only the arguments they want to modify.
An example:
tracer.configure(priority_sampling=False)
tracer.configure(host='127.0.0.1')Which will configure the tracer disabling priority sampling, and then configure the host to be localhost while keeping priority sampling disabled.
This might just be how we have .configure() setup for dd-trace-py, curious if this is (or should be) the same case here?
There was a problem hiding this comment.
Right, first call would deactivate, then second would reactivate. That's no good.
Changing the logic such that it defaults to nil, activates if != false, and deactivates only if == false.
There was a problem hiding this comment.
Nasty side effect of this is that everytime we reconfigure the tracer, it automatically overrides the previous writer with a new one, which puts test tracers in a bad state.
There was a problem hiding this comment.
It might be good to add a comment here about that
There was a problem hiding this comment.
Unfortunately this comment will apply just about everywhere we use tracer.configure in tests so I don't think it'll help. I'd rather try to find some way to get rid of this, because this kind of practice in tests is not sustainable.
There was a problem hiding this comment.
Something dd-trace-py did for tests in create a DummyTracer to use in all tests that will always overwrite the writer to be a DummyWriter, even after calling .configure()
There was a problem hiding this comment.
Yeah, I was looking at that, too. Problem is configure applies a bunch of mutations to Writer, so if you have to re-initialize with a FauxWriter, then you have to copy over all the settings, otherwise you'll end up with a misconfigured Writer.
I think ideally, the code should either construct immutable Writer objects that have to be replaced, or mutable ones that are never replaced; right now we're in a kind of unhappy middle ground.
Nonetheless I'm going to try to avoid such refactoring right now, maybe there's something else I can do to work around this in the mean time.
There was a problem hiding this comment.
yeah, we have that same issue. since we isolated it into one place in a subclass of Tracer it wasn't too bad... enough to get by for now
There was a problem hiding this comment.
For sure, I'll try one of these tricks to make something work for now, but it would be nice if we refactored things to be more testable. A goal for the future, perhaps.
|
Looks like simply changing the option from |
There was a problem hiding this comment.
In dd-trace-py we removed this part from our docs, since disabling priority sampling has a chance of breaking distributed tracing, better to just leave this out.
There was a problem hiding this comment.
yeah, we have a weird thing in dd-trace-py where we have priority_sampling default to nil so that we only try to update the sampler if the option has been provided, rather than defaulting to True.
I think this basically does the same thing.
There was a problem hiding this comment.
It might be good to add a comment here about that
There was a problem hiding this comment.
it might be good to add a comment here about why we have this check here.
f8c2f89 to
c33dc35
Compare
brettlangdon
left a comment
There was a problem hiding this comment.
looking good, just a note about how we are handling #configure but otherwise, looks good
There was a problem hiding this comment.
I see we updated options.fetch(:priority_sampling, true), does that mean we should have this be if !priority_sampling.nil? (sorry for my bad ruby)
Since nil is falsey, we probably only want to modify what sampler/writer we are using if we are setting priority sampling.
Also, do we need to handle :priority_smapling => false? if we reconfigure and set to false do we need to update the sampler/writer again to use a RateSampler?
| describe 'instance' do | ||
| subject(:subscription) { described_class.new(tracer, span_name, options, &block) } | ||
| let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) } | ||
| let(:tracer) { get_test_tracer } |
There was a problem hiding this comment.
nice, 👍 for encapsulating this somewhere.
| # TODO: Let's try to get rid of this override, which has too much | ||
| # knowledge about the internal workings of the tracer. | ||
| # It is done to prevent the activation of priority sampling | ||
| # from wiping out the configured test writer, by replacing it. |
There was a problem hiding this comment.
👍 agree with this comment, this is great, especially if it helps us get by, but a little hacky/nasty.
c33dc35 to
df01e39
Compare
df01e39 to
956577f
Compare
This pull request enables priority sampling by default.