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

Change should_sample parameters to be spec compliant #1764

Merged
merged 9 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `py.typed` file to every package. This should resolve a bunch of mypy
errors for users.
([#1720](https://github.com/open-telemetry/opentelemetry-python/pull/1720))
- Added `SpanKind` to `should_sample` parameters
([#1764](https://github.com/open-telemetry/opentelemetry-python/pull/1764))

### Changed
- Adjust `B3Format` propagator to be spec compliant by not modifying context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ def start_span( # pylint: disable=too-many-locals
# The sampler may also add attributes to the newly-created span, e.g.
# to include information about the sampling result.
sampling_result = self.sampler.should_sample(
context, trace_id, name, attributes, links, trace_state
context, trace_id, name, kind, attributes, links, trace_state
)

trace_flags = (
Expand Down
7 changes: 6 additions & 1 deletion opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
OTEL_TRACES_SAMPLER,
OTEL_TRACES_SAMPLER_ARG,
)
from opentelemetry.trace import Link, get_current_span
from opentelemetry.trace import Link, SpanKind, get_current_span
from opentelemetry.trace.span import TraceState
from opentelemetry.util.types import Attributes

Expand Down Expand Up @@ -167,6 +167,7 @@ def should_sample(
parent_context: Optional["Context"],
trace_id: int,
name: str,
kind: SpanKind = None,
attributes: Attributes = None,
links: Sequence["Link"] = None,
trace_state: "TraceState" = None,
Expand All @@ -189,6 +190,7 @@ def should_sample(
parent_context: Optional["Context"],
trace_id: int,
name: str,
kind: SpanKind = None,
attributes: Attributes = None,
links: Sequence["Link"] = None,
trace_state: "TraceState" = None,
Expand Down Expand Up @@ -246,6 +248,7 @@ def should_sample(
parent_context: Optional["Context"],
trace_id: int,
name: str,
kind: SpanKind = None,
attributes: Attributes = None,
links: Sequence["Link"] = None,
trace_state: "TraceState" = None,
Expand Down Expand Up @@ -296,6 +299,7 @@ def should_sample(
parent_context: Optional["Context"],
trace_id: int,
name: str,
kind: SpanKind = None,
attributes: Attributes = None,
links: Sequence["Link"] = None,
trace_state: "TraceState" = None,
Expand All @@ -322,6 +326,7 @@ def should_sample(
parent_context=parent_context,
trace_id=trace_id,
name=name,
kind=kind,
attributes=attributes,
links=links,
trace_state=trace_state,
Expand Down
20 changes: 20 additions & 0 deletions opentelemetry-sdk/tests/trace/test_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def test_always_on(self):
context,
0xDEADBEF1,
"sampling on",
trace.SpanKind.INTERNAL,
attributes={"sampled.expect": "true"},
trace_state=trace_state,
)
Expand All @@ -118,6 +119,7 @@ def test_always_off(self):
context,
0xDEADBEF1,
"sampling off",
trace.SpanKind.INTERNAL,
attributes={"sampled.expect": "false"},
trace_state=trace_state,
)
Expand All @@ -132,6 +134,7 @@ def test_default_on(self):
context,
0xDEADBEF1,
"unsampled parent, sampling on",
trace.SpanKind.INTERNAL,
attributes={"sampled.expect": "false"},
trace_state=trace_state,
)
Expand All @@ -144,6 +147,7 @@ def test_default_on(self):
context,
0xDEADBEF1,
"sampled parent, sampling on",
trace.SpanKind.INTERNAL,
attributes={"sampled.expect": "true"},
trace_state=trace_state,
)
Expand All @@ -155,6 +159,7 @@ def test_default_on(self):
None,
0xDEADBEF1,
"no parent, sampling on",
trace.SpanKind.INTERNAL,
attributes={"sampled.expect": "true"},
trace_state=trace_state,
)
Expand All @@ -169,6 +174,7 @@ def test_default_off(self):
context,
0xDEADBEF1,
"unsampled parent, sampling off",
trace.SpanKind.INTERNAL,
attributes={"sampled.expect", "false"},
trace_state=trace_state,
)
Expand All @@ -181,6 +187,7 @@ def test_default_off(self):
context,
0xDEADBEF1,
"sampled parent, sampling on",
trace.SpanKind.INTERNAL,
attributes={"sampled.expect": "true"},
trace_state=trace_state,
)
Expand All @@ -192,6 +199,7 @@ def test_default_off(self):
None,
0xDEADBEF1,
"unsampled parent, sampling off",
trace.SpanKind.INTERNAL,
attributes={"sampled.expect": "false"},
trace_state=trace_state,
)
Expand All @@ -209,6 +217,7 @@ def test_probability_sampler(self):
None,
0x7FFFFFFFFFFFFFFF,
"sampled true",
trace.SpanKind.INTERNAL,
attributes={"sampled.expect": "true"},
trace_state=trace_state,
)
Expand All @@ -220,6 +229,7 @@ def test_probability_sampler(self):
None,
0x8000000000000000,
"sampled false",
trace.SpanKind.INTERNAL,
attributes={"sampled.expect": "false"},
trace_state=trace_state,
)
Expand Down Expand Up @@ -324,6 +334,7 @@ def exec_parent_based(self, parent_sampling_context):
context,
0x7FFFFFFFFFFFFFFF,
"unsampled parent, sampling on",
trace.SpanKind.INTERNAL,
attributes={"sampled": "false"},
trace_state=trace_state,
)
Expand All @@ -343,6 +354,7 @@ def exec_parent_based(self, parent_sampling_context):
context,
0x7FFFFFFFFFFFFFFF,
"unsampled parent, sampling on",
trace.SpanKind.INTERNAL,
attributes={"sampled": "false"},
trace_state=trace_state,
)
Expand All @@ -359,6 +371,7 @@ def exec_parent_based(self, parent_sampling_context):
context,
0x8000000000000000,
"sampled parent, sampling off",
trace.SpanKind.INTERNAL,
attributes={"sampled": "true"},
trace_state=trace_state,
)
Expand All @@ -378,6 +391,7 @@ def exec_parent_based(self, parent_sampling_context):
context,
0x7FFFFFFFFFFFFFFF,
"unsampled parent, sampling on",
trace.SpanKind.INTERNAL,
attributes={"sampled": "false"},
trace_state=trace_state,
)
Expand All @@ -394,6 +408,7 @@ def exec_parent_based(self, parent_sampling_context):
context,
0x7FFFFFFFFFFFFFFF,
"unsampled parent, sampling on",
trace.SpanKind.INTERNAL,
attributes={"sampled": "false"},
trace_state=trace_state,
)
Expand All @@ -413,6 +428,7 @@ def exec_parent_based(self, parent_sampling_context):
context,
0x7FFFFFFFFFFFFFFF,
"unsampled parent, sampling on",
trace.SpanKind.INTERNAL,
attributes={"sampled": "false"},
trace_state=trace_state,
)
Expand All @@ -429,6 +445,7 @@ def exec_parent_based(self, parent_sampling_context):
context,
0x8000000000000000,
"sampled parent, sampling off",
trace.SpanKind.INTERNAL,
attributes={"sampled": "true"},
trace_state=trace_state,
)
Expand All @@ -448,6 +465,7 @@ def exec_parent_based(self, parent_sampling_context):
context,
0x7FFFFFFFFFFFFFFF,
"unsampled parent, sampling on",
trace.SpanKind.INTERNAL,
attributes={"sampled": "false"},
trace_state=trace_state,
)
Expand All @@ -462,6 +480,7 @@ def exec_parent_based(self, parent_sampling_context):
context,
0x8000000000000000,
"parent, sampling off",
trace.SpanKind.INTERNAL,
attributes={"sampled": "false"},
trace_state=trace_state,
)
Expand All @@ -475,6 +494,7 @@ def exec_parent_based(self, parent_sampling_context):
context,
0x8000000000000000,
"no parent, sampling on",
trace.SpanKind.INTERNAL,
attributes={"sampled": "true"},
trace_state=trace_state,
)
Expand Down