Skip to content

Commit

Permalink
Update sampling result names (#1128)
Browse files Browse the repository at this point in the history
  • Loading branch information
ffe4 authored Sep 18, 2020
1 parent e8f5eb5 commit a59e268
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
3 changes: 3 additions & 0 deletions opentelemetry-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- Update sampling result names
([#1128](https://github.com/open-telemetry/opentelemetry-python/pull/1128))

## Version 0.13b0

Released 2020-09-17
Expand Down
14 changes: 7 additions & 7 deletions opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

class Decision(enum.Enum):
# IsRecording() == false, span will not be recorded and all events and attributes will be dropped.
IGNORE = 0
DROP = 0
# IsRecording() == true, but Sampled flag MUST NOT be set.
RECORD_ONLY = 1
# IsRecording() == true AND Sampled flag` MUST be set.
Expand Down Expand Up @@ -140,12 +140,12 @@ def should_sample(
attributes: Attributes = None,
links: Sequence["Link"] = (),
) -> "SamplingResult":
if self._decision is Decision.IGNORE:
if self._decision is Decision.DROP:
return SamplingResult(self._decision)
return SamplingResult(self._decision, attributes)

def get_description(self) -> str:
if self._decision is Decision.IGNORE:
if self._decision is Decision.DROP:
return "AlwaysOffSampler"
return "AlwaysOnSampler"

Expand Down Expand Up @@ -194,10 +194,10 @@ def should_sample(
attributes: Attributes = None, # TODO
links: Sequence["Link"] = (),
) -> "SamplingResult":
decision = Decision.IGNORE
decision = Decision.DROP
if trace_id & self.TRACE_ID_LIMIT < self.bound:
decision = Decision.RECORD_AND_SAMPLE
if decision is Decision.IGNORE:
if decision is Decision.DROP:
return SamplingResult(decision)
return SamplingResult(decision, attributes)

Expand Down Expand Up @@ -231,7 +231,7 @@ def should_sample(
not parent_context.is_valid
or not parent_context.trace_flags.sampled
):
return SamplingResult(Decision.IGNORE)
return SamplingResult(Decision.DROP)
return SamplingResult(Decision.RECORD_AND_SAMPLE, attributes)

return self._delegate.should_sample(
Expand All @@ -246,7 +246,7 @@ def get_description(self):
return "ParentBased{{{}}}".format(self._delegate.get_description())


ALWAYS_OFF = StaticSampler(Decision.IGNORE)
ALWAYS_OFF = StaticSampler(Decision.DROP)
"""Sampler that never samples spans, regardless of the parent span's sampling decision."""

ALWAYS_ON = StaticSampler(Decision.RECORD_AND_SAMPLE)
Expand Down
6 changes: 2 additions & 4 deletions opentelemetry-sdk/tests/trace/test_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_is_recording(self):
sampling.Decision.is_recording(sampling.Decision.RECORD_AND_SAMPLE)
)
self.assertFalse(
sampling.Decision.is_recording(sampling.Decision.IGNORE)
sampling.Decision.is_recording(sampling.Decision.DROP)
)

def test_is_sampled(self):
Expand All @@ -41,9 +41,7 @@ def test_is_sampled(self):
self.assertTrue(
sampling.Decision.is_sampled(sampling.Decision.RECORD_AND_SAMPLE)
)
self.assertFalse(
sampling.Decision.is_sampled(sampling.Decision.IGNORE)
)
self.assertFalse(sampling.Decision.is_sampled(sampling.Decision.DROP))


class TestSamplingResult(unittest.TestCase):
Expand Down

0 comments on commit a59e268

Please sign in to comment.