-
Notifications
You must be signed in to change notification settings - Fork 212
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
Implemented random sampling #116
Conversation
77729ce
to
31701b0
Compare
31701b0
to
511f36b
Compare
511f36b
to
30b05f2
Compare
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.
Added a couple of questions.
elasticapm/traces.py
Outdated
@@ -230,14 +244,14 @@ def decorated(*args, **kwds): | |||
def __enter__(self): | |||
transaction = get_transaction() | |||
|
|||
if transaction: | |||
if transaction and transaction.is_sampled: | |||
transaction.begin_span(self.name, self.type, self.extra, |
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.
Do you need the check for in_sampled
it both here and inside begin_span
?
@@ -219,7 +219,8 @@ def uninstrument(self): | |||
self.originals = {} | |||
|
|||
def call_if_sampling(self, module, method, wrapped, instance, args, kwargs): | |||
if not get_transaction(): | |||
transaction = get_transaction() | |||
if not transaction or not transaction.is_sampled: | |||
return wrapped(*args, **kwargs) |
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.
you have the check in begin_span
. Do you need it here too?
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.
not 100% sure tbh. I'll step through it with the debugger
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.
After taking a closer read of the code, I think it's worth doing the check in both places.
call_if_sampling
is called for stuff we instrument automatically. Checking here avoids even calling the capture_span
decorator and doing other stuff we do in the wrappers (e.g. parsing the SQL query for an sql
span).
the check in capture_span.__enter__
is useful for cases where code is instrumented manually using the capture_span
decorator.
The third check, in Transaction.begin_span
seems to be superfluous, however, as it is only called from capture_span.__enter__
. Good catch!
elasticapm/traces.py
Outdated
@@ -102,7 +112,8 @@ def to_dict(self): | |||
'context': self._context, | |||
'spans': [ |
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 think it's worth considering removing the spans
key entirely to clearly indicate this is an unsampled transaction.
30b05f2
to
5e49a5d
Compare
Given a sample rate, this will randomly choose transactions to be sampled. If a transaction isn't sampled, no spans will be collected, as well as no context information
5e49a5d
to
4dee914
Compare
Given a sample rate, this will randomly choose transactions to be sampled. If a transaction isn't sampled, no spans will be collected, as well as no context information closes #116
Given a sample rate, this will randomly choose transactions
to be sampled. If a transaction isn't sampled, no spans will
be collected, as well as no context information