Skip to content

Commit

Permalink
populate aws.trace.flag.sampled attribute only if unsampled
Browse files Browse the repository at this point in the history
  • Loading branch information
srprash committed Nov 12, 2024
1 parent 3557f6a commit 43af1e5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ public static AwsUnsampledOnlySpanProcessorBuilder builder() {

@Override
public void onStart(Context parentContext, ReadWriteSpan span) {
if (span.getSpanContext().isSampled()) {
span.setAttribute(AwsAttributeKeys.AWS_TRACE_FLAG_SAMPLED, true);
} else {
if (!span.getSpanContext().isSampled()) {
span.setAttribute(AwsAttributeKeys.AWS_TRACE_FLAG_SAMPLED, false);
}
delegate.onStart(parentContext, span);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public void testStartAddsAttributeToSampledSpan() {
AwsUnsampledOnlySpanProcessor processor = AwsUnsampledOnlySpanProcessor.builder().build();
processor.onStart(parentContextMock, spanMock);

// verify setAttribute was called with the correct arguments
verify(spanMock, times(1)).setAttribute(AwsAttributeKeys.AWS_TRACE_FLAG_SAMPLED, true);
// verify setAttribute was never called
verify(spanMock, never()).setAttribute(any(), anyBoolean());
}

@Test
Expand Down

0 comments on commit 43af1e5

Please sign in to comment.