Skip to content

Commit 4b36553

Browse files
authored
Fix no attributes returned with un-sampled case. (#253)
*Issue #, if available:* *Description of changes:* Fix the bug: When trace is not sampled, the span attributes is None, `RemoteOperation` and `RemoteService` becomes Unknown. Testing: **Before the change**: `OTEL_TRACES_SAMPLER=traceidratio OTEL_TRACES_SAMPLER_ARG="0.0":` ![Screenshot 2024-09-10 at 11 40 22 AM](https://github.com/user-attachments/assets/a0108dc2-ff82-4c5d-9ce6-d21f32678ead) `OTEL_TRACES_SAMPLER=xray OTEL_TRACES_SAMPLER_ARG="endpoint=http://localhost:2000" ` with more than 1 segments per second: ![Screenshot 2024-09-10 at 12 41 34 PM](https://github.com/user-attachments/assets/41260bb0-2e0d-4c05-8866-9aad25e3db6d) **After the change**: `OTEL_TRACES_SAMPLER=traceidratio OTEL_TRACES_SAMPLER_ARG="0.0":` ![Screenshot 2024-09-10 at 12 02 07 PM](https://github.com/user-attachments/assets/fe86ea7a-e147-4a8c-8e0a-f0494e0a0f0e) `OTEL_TRACES_SAMPLER=xray OTEL_TRACES_SAMPLER_ARG="endpoint=http://localhost:2000" ` with more than 1 segments per second: ![Screenshot 2024-09-10 at 12 22 58 PM](https://github.com/user-attachments/assets/c85f9fda-4c54-4f01-9738-ed1aa5667e61) By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent ae5e113 commit 4b36553

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/always_record_sampler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@ def should_sample(
5252
parent_context, trace_id, name, kind, attributes, links, trace_state
5353
)
5454
if result.decision is Decision.DROP:
55-
result = _wrap_result_with_record_only_result(result)
55+
result = _wrap_result_with_record_only_result(result, attributes)
5656
return result
5757

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

6262

63-
def _wrap_result_with_record_only_result(result: SamplingResult) -> SamplingResult:
63+
def _wrap_result_with_record_only_result(result: SamplingResult, attributes: Attributes) -> SamplingResult:
6464
return SamplingResult(
6565
Decision.RECORD_ONLY,
66-
result.attributes,
66+
attributes,
6767
result.trace_state,
6868
)

aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test_always_record_sampler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def validate_should_sample(self, root_decision: Decision, expected_decision: Dec
3838
trace_id=0,
3939
name="name",
4040
kind=SpanKind.CLIENT,
41-
attributes={},
41+
attributes={"key": root_decision.name},
4242
trace_state=TraceState(),
4343
)
4444

0 commit comments

Comments
 (0)