Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -12,6 +12,8 @@ If your change does not need a CHANGELOG entry, add the "skip changelog" label t

## Unreleased

- fix: Ensure AlwaysRecordSampler respects root sampling result attributes
([#594](https://github.com/aws-observability/aws-otel-python-instrumentation/pull/594))
- Adaptive Sampling support
([#576](https://github.com/aws-observability/aws-otel-python-instrumentation/pull/576))
- Fix: Support new fields in X-Ray API responses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ def should_sample(
parent_context, trace_id, name, kind, attributes, links, trace_state
)
if result.decision is Decision.DROP:
result = _wrap_result_with_record_only_result(result, attributes)
result = _wrap_result_with_record_only_result(result)
return result

@override
def get_description(self) -> str:
return "AlwaysRecordSampler{" + self._root_sampler.get_description() + "}"


def _wrap_result_with_record_only_result(result: SamplingResult, attributes: Attributes) -> SamplingResult:
def _wrap_result_with_record_only_result(result: SamplingResult) -> SamplingResult:
return SamplingResult(
Decision.RECORD_ONLY,
attributes,
result.attributes,
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 this was intentionally NOT done: 4b36553

result.trace_state,
)
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ def test_record_only_sampling_decision(self):
def test_drop_sampling_decision(self):
self.validate_should_sample(Decision.DROP, Decision.RECORD_ONLY)

def test_drop_decision_preserves_root_sampler_attributes(self):
root_result = _build_root_sampling_result(Decision.DROP, {"attr_key": "attr_val"})
self.mock_sampler.should_sample.return_value = root_result

actual_result = self.sampler.should_sample(
parent_context=Context(),
trace_id=0,
name="name",
kind=SpanKind.CLIENT,
attributes={},
trace_state=TraceState(),
)

self.assertEqual(actual_result.decision, Decision.RECORD_ONLY)
self.assertEqual(actual_result.attributes.get("attr_key"), "attr_val")

def validate_should_sample(self, root_decision: Decision, expected_decision: Decision):
root_result: SamplingResult = _build_root_sampling_result(root_decision)
self.mock_sampler.should_sample.return_value = root_result
Expand All @@ -53,8 +69,8 @@ def validate_should_sample(self, root_decision: Decision, expected_decision: Dec
self.assertEqual(actual_result.trace_state, root_result.trace_state)


def _build_root_sampling_result(sampling_decision: Decision):
sampling_attr: Attributes = {"key": sampling_decision.name}
def _build_root_sampling_result(sampling_decision: Decision, attributes: Attributes = None):
sampling_attr: Attributes = attributes if attributes is not None else {"key": sampling_decision.name}
sampling_trace_state: TraceState = TraceState()
sampling_trace_state.add("key", sampling_decision.name)
sampling_result: SamplingResult = SamplingResult(
Expand Down