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

Don't enable sampling by default #482

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

c24t
Copy link
Member

@c24t c24t commented Feb 5, 2019

This is a WIP PR to disable sampling using default trace options. This started as a drive-by fix to replace a string-valued bit field with an int and expanded as I compared TraceOptions and SpanContext to their counterparts in java.

@liyanhui1228 I'd appreciate some comments here since it's not obvious that sampling shouldn't be enabled by default, and there are a few design choices here I don't understand.

Addresses #481.

@c24t c24t added the trace label Feb 5, 2019
@c24t c24t requested a review from liyanhui1228 February 5, 2019 20:58
@@ -64,7 +58,7 @@ def __init__(
trace_id = generate_trace_id()

if trace_options is None:
trace_options = DEFAULT
trace_options = trace_options_module.TraceOptions()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-using the default trace options here meant that tracers would set each others' contexts' sampling bit.

self.span_context.trace_options.set_enabled(True)

I suspect there are other bugs like this lurking in the module.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: add a test for tracer isolation.

)

# TODO: deprecate, replace with is_sampled()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO in #481.

def __init__(self, trace_options_byte=DEFAULT):
if not isinstance(trace_options_byte, int):
logging.warning("trace_options_byte must be an int, this will be "
"an error in future versions")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is technically an API change, so I figure the right approach is to log a warning here and make this an error in the next minor version release. We would benefit from some convention for deprecation, compare to java's @deprecated annotation.

@@ -308,7 +308,7 @@ def test_translate_to_jaeger(self):
operationName='test1',
startTime=1502820146071158,
duration=10000000,
flags=1,
flags=0,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: check that this is the behavior we want.

@@ -73,7 +73,7 @@ def should_sample(self):
:rtype: bool
:returns: Whether to trace the request or not.
"""
return self.span_context.trace_options.enabled \
return self.span_context.trace_options.get_enabled() \
or self.sampler.should_sample(self.span_context.trace_id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to this PR, should_sample needs to take the trace options as well. For example, the way the probability sampler should work is that if trace options is true then return true, else check against the configured probability. This way if a remote parent is sampled the children will be too, but still allowing for a sampler to override that.

@c24t c24t requested review from aabmass, hectorhdzg, lzchen, songy23 and a team as code owners May 13, 2021 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants