-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RUM-6866 Allow typed Sampler #2385
Conversation
1e9cf52
to
4c2c9cf
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #2385 +/- ##
===========================================
+ Coverage 70.28% 70.31% +0.02%
===========================================
Files 744 744
Lines 27733 27694 -39
Branches 4631 4621 -10
===========================================
- Hits 19492 19471 -21
+ Misses 6953 6947 -6
+ Partials 1288 1276 -12
|
|
||
/** | ||
* Creates a new instance of [RateBasedSampler] with the given sample rate. | ||
* Creates a new instance lof [RateBasedSampler] with the given sample rate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be reverted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
interface com.datadog.android.core.sampling.Sampler<T: Any> | ||
fun sample(T): Boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is potentially a binary-incompatible change, because public constructors of DatadogInterceptor
and TracingInterceptor
(and builder methods since recently) take Sampler
instance which can be some customer-defined Sampler
rather than default RateBasedSampler
.
Is there a way to avoid breaking it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hesitated to do it, as indeed it's technically a breaking change on a public interface. That being said, looking at our code base, the interface is used in:
- the
internal class TelemetryEventHandler
constructor, but the sampler is built internally based on a sample rate provided in the configuration - the
internal class SessionReplayFeature
constructor, but the sampler is built internally based on a sample rate provided in the configuration - the
internal class DatadogLogHandler
constructor, but the sampler is built internally based on a sample rate provided in the configuration - an internal property of the
internal class WebViewLogEventConsumer
, built internally based on a sample rate provided in the configuration - in the
DatadogInterceptor
andTracingInterceptor
deprecated constructors; they were replaced by a Builder. The builder only accepts a Sampler, which is the only place we could have ab issue for customer, which I guess is acceptable. I'll also add a builder method to set the sampling rate as I feel it's missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 suggestion: What about a keeping the builder method that accepts the Sampler
and wrapping this old Sampler
that the customer is passing to your own Sampler<Unit>
? In this case it will not be a breaking change anymore. And we could deprecate that method for later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will it make sense to make the API be like fun sample(T? = null): Boolean
instead of fun sample(T): Boolean
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we probably don't want to allow nullable types in the interface definition. But probably even if we do so, it would be still binary incompatible change, because then customer implementing custom Sampler
still need to update the method signature.
My main concern is indeed in the interceptors usage (other places are pretty much internal), but if we ultimately cannot avoid this and we need to progress on this topic, I'm fine with this minor breaking change.
4c2c9cf
to
52ca276
Compare
*/ | ||
fun setTraceSampler(traceSampler: Sampler): R { | ||
fun setTraceSampler(traceSampler: Sampler<Span>): R { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 suggestion: Like I suggested in my previous comment maybe we can keep also the previous method and wrap the customer old Sampler
implementation in our own Sampler<Span>
which delegates to the customer. Not sure but I think is doable. We can also Deprecate
the old method.
52ca276
to
808f3d7
Compare
interface com.datadog.android.core.sampling.Sampler<T: Any> | ||
fun sample(T): Boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we probably don't want to allow nullable types in the interface definition. But probably even if we do so, it would be still binary incompatible change, because then customer implementing custom Sampler
still need to update the method signature.
My main concern is indeed in the interceptors usage (other places are pretty much internal), but if we ultimately cannot avoid this and we need to progress on this topic, I'm fine with this minor breaking change.
What does this PR do?
Preparing for a new implementation of a sampler for the TracingInterceptor, add a type to the sampler to allow adapting the sampling decision to the event being sampled.