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

Implemented random sampling #116

Closed

Conversation

beniwohli
Copy link
Contributor

@beniwohli beniwohli commented Dec 14, 2017

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

Copy link
Contributor

@roncohen roncohen left a 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.

@@ -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,
Copy link
Contributor

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

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!

@@ -102,7 +112,8 @@ def to_dict(self):
'context': self._context,
'spans': [
Copy link
Contributor

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.

@beniwohli beniwohli changed the title First stab at random sampling Implemented random sampling Jan 2, 2018
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
@beniwohli beniwohli closed this in 21fbef4 Jan 2, 2018
beniwohli added a commit that referenced this pull request Jan 2, 2018
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
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

Successfully merging this pull request may close these issues.

None yet

2 participants