-
Notifications
You must be signed in to change notification settings - Fork 459
Client sampling #8
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
39ac2d1
Introduce client-side sampling with sample_rate
LotharSee 69b5673
Skip ES instrumentation when sampled
LotharSee d4f900b
Skip Flask instrumentation when sampled
LotharSee b597b68
Skip Psycopg instrumentation when sampled
LotharSee 113097e
Skip Sqlite instrumentation when sampled
LotharSee 585d9fe
Skip Pylons instrumentation when sampled
LotharSee 4ec676c
Define 'set_sample_rate' in Trace
LotharSee 83715d0
Simplify 'reporter.py' file
LotharSee 2c865f1
Add weight attribute to all spans
LotharSee 8af16fd
Add a test on span.weight value
LotharSee ea55443
Rename Sampler to RateSampler, improve its interface
LotharSee fc0983d
Redefine `span.sampled` as `span` being kept
LotharSee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import logging | ||
|
||
from .span import MAX_TRACE_ID | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class RateSampler(object): | ||
"""RateSampler manages the client-side trace sampling based on a rate | ||
|
||
Keep (100 * sample_rate)% of the traces. | ||
Any `sampled = False` trace won't be written, and can be ignored by the instrumentation. | ||
It samples randomly, its main purpose is to reduce the instrumentation footprint. | ||
""" | ||
|
||
def __init__(self, sample_rate): | ||
if sample_rate <= 0: | ||
log.error("sample_rate is negative or null, disable the Sampler") | ||
sample_rate = 1 | ||
elif sample_rate > 1: | ||
sample_rate = 1 | ||
|
||
self.sample_rate = sample_rate | ||
self.sampling_id_threshold = sample_rate * MAX_TRACE_ID | ||
|
||
def sample(self, span): | ||
span.sampled = span.trace_id <= self.sampling_id_threshold | ||
# `weight` is an attribute applied to all spans to help scaling related statistics | ||
span.weight = 1 / (self.sample_rate or 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
shouldn't this be in the if block as well ?
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.
The span already got created. Even if it is not sampled (and we didn't put the various attributes), we still have to finish it (to keep a valid tree).