From 43af1e542cdb92614465386dc896c24d59e0a009 Mon Sep 17 00:00:00 2001 From: Prashant Srivastava Date: Mon, 11 Nov 2024 22:58:28 -0800 Subject: [PATCH] populate aws.trace.flag.sampled attribute only if unsampled --- .../javaagent/providers/AwsUnsampledOnlySpanProcessor.java | 4 +--- .../providers/AwsUnsampledOnlySpanProcessorTest.java | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/awsagentprovider/src/main/java/software/amazon/opentelemetry/javaagent/providers/AwsUnsampledOnlySpanProcessor.java b/awsagentprovider/src/main/java/software/amazon/opentelemetry/javaagent/providers/AwsUnsampledOnlySpanProcessor.java index e15bda66a..3848016f3 100644 --- a/awsagentprovider/src/main/java/software/amazon/opentelemetry/javaagent/providers/AwsUnsampledOnlySpanProcessor.java +++ b/awsagentprovider/src/main/java/software/amazon/opentelemetry/javaagent/providers/AwsUnsampledOnlySpanProcessor.java @@ -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); diff --git a/awsagentprovider/src/test/java/software/amazon/opentelemetry/javaagent/providers/AwsUnsampledOnlySpanProcessorTest.java b/awsagentprovider/src/test/java/software/amazon/opentelemetry/javaagent/providers/AwsUnsampledOnlySpanProcessorTest.java index bdcc4873f..ba41740bd 100644 --- a/awsagentprovider/src/test/java/software/amazon/opentelemetry/javaagent/providers/AwsUnsampledOnlySpanProcessorTest.java +++ b/awsagentprovider/src/test/java/software/amazon/opentelemetry/javaagent/providers/AwsUnsampledOnlySpanProcessorTest.java @@ -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