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

is_sampled logic is flawed #20

Open
Anonymous-Coward opened this issue Feb 15, 2018 · 0 comments
Open

is_sampled logic is flawed #20

Anonymous-Coward opened this issue Feb 15, 2018 · 0 comments

Comments

@Anonymous-Coward
Copy link

Anonymous-Coward commented Feb 15, 2018

If the X-B3-Sampled header is missing from the incoming request - for example when you just call the app from a browser - no span whatsoever will be sampled. This effectively means the sampling rate will be ignored.

I'm not enough of a Python programmer to submit a merge request, but here's what I think would work:

  • create a new field unmarkedRequests in init
  • in each _before_request
    • if the header X-B3-TraceId is missing, increment unmarkedRequests
    • is_sampled = (unmarkedRequests >= 100 / sample_rate) or X-B3-Sampled is present and "1"
    • if unmarkedRequests >= 100 / sample_rate then set unmarkedRequests to 0

I tested with this code added in _before_request(self), and it seems to work right:

        if (not headers.get('X-B3-Sampled')):
            self._unmarked = self._unmarked + 1;
            
        is_sampled = (self._unmarked >= 100 / self._sample_rate) or is_sampled;
        if (self._unmarked >= 1 / self._sample_rate):
            self._unmarked = 0;

Why this way: if requests come from a source which has already set sampling info, we don't need to deal with them. Otherwise, we need to record a proportion of sample_rate of them - which translates roughly to one request every 100 / sample_rate requests.

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

No branches or pull requests

1 participant