Skip to content
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

Tracer and OkHttp: what happen when apply sampler for both of them? #1892

Closed
alecarnevale opened this issue Feb 27, 2024 · 2 comments
Closed
Labels
question Further information is requested

Comments

@alecarnevale
Copy link

Question

Hi there, I have some questions about sampling.
I'm sorry if my doubts are documented somewhere, but I didn't find anything here or in the official doc.

Looking into the code, I found two different Sampler interfaces:

As far as I understood the former is applied at OkHttp level, the latter when you register an AndroidTracer through AndroidTracer.Builder().setSampleRate(double).


My first doubt is how do the two work together? What If I apply both of them?
Correct me if I'm wrong, but looking into the code:

  • given that you set AndroidTracer.Builder().setSampleRate(globalRate);
  • given that you added a DataDogInterceptor (application) or a TracingInterceptor (network) with a RateBasedSampler;
  • the RateBasedSampler is triggered at the network level and some span is sampled;
  • then the sampled span is injected into the AndroidTracer;
  • then the sampler set with the globalRate is applied.

Is this flow correct?


My second doubt is about the DeterministicSampler implementation of the andorid-core sampler.
Is it a head-based sampling like the TraceIdRatioBased OpenTelemetry sampler?

This is specifically to understand if apply the DeterministicSampler into the Android client and a TraceIdRatioBased on some backend services as well, means that when a span is sampled from the Android client then also the related spans for the same trace_id are sampled on the backend as well.

@alecarnevale alecarnevale added the question Further information is requested label Feb 27, 2024
@xgouchet
Copy link
Collaborator

Hi @alecarnevale and thanks for contacting us.

Regarding the sampling rates from the AndroidTracer and the TracingInterceptor, they are as you thought cumulative.
The former one simply asks how many spans (out of all the one the tracer receives) should be kept, and the latter asks how many network requests should have a span created for it.

And indeed the sampling works as Head Based sampling, as describe in the documentation you're mentionning. In theory the DeterministicSampler should give you the same sampling on both Android and the Backend, assuming we use the same Deterministic sampling algorithm (our Android implementation uses the same implementation as our Backend Java Agent).

@alecarnevale
Copy link
Author

Hi @xgouchet thanks for your reply, that's all clear now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants