From a59e268fab1afead2f8d3bf1c6d9490959562019 Mon Sep 17 00:00:00 2001 From: Daniel <61800298+ffe4@users.noreply.github.com> Date: Fri, 18 Sep 2020 05:20:50 +0200 Subject: [PATCH] Update sampling result names (#1128) --- opentelemetry-sdk/CHANGELOG.md | 3 +++ .../src/opentelemetry/sdk/trace/sampling.py | 14 +++++++------- opentelemetry-sdk/tests/trace/test_sampling.py | 6 ++---- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/opentelemetry-sdk/CHANGELOG.md b/opentelemetry-sdk/CHANGELOG.md index 5faa74b3cf2..efa139f347b 100644 --- a/opentelemetry-sdk/CHANGELOG.md +++ b/opentelemetry-sdk/CHANGELOG.md @@ -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 diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py index 2fd14a528e5..c40d3e691ee 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py @@ -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. @@ -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" @@ -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) @@ -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( @@ -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) diff --git a/opentelemetry-sdk/tests/trace/test_sampling.py b/opentelemetry-sdk/tests/trace/test_sampling.py index 179b31aef5b..9160ec4a351 100644 --- a/opentelemetry-sdk/tests/trace/test_sampling.py +++ b/opentelemetry-sdk/tests/trace/test_sampling.py @@ -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): @@ -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):