From b1fcdb3977bbc295b20b3879fb1beee84e83005c Mon Sep 17 00:00:00 2001 From: Lei Wang <66336933+wangzlei@users.noreply.github.com> Date: Wed, 18 Sep 2024 19:41:13 -0700 Subject: [PATCH] Changing span unsampled flag to be sampled flag (#260) *Issue #, if available:* Previously we use `aws.trace.flag.unsampled` mark the span is unsampled. The change updates this attribute to be `aws.trace.flag.sampled`. *Description of changes:* #### span is unsampled: If span has no span attribute aws.trace.flag.sampled , value type is boolean and value is false. #### span is sampled: If span has no span attribute aws.trace.flag.sampled or span has span attribute aws.trace.flag.sampled , value type is boolean and value is true, or span has span attribute aws.trace.flag.sampled , value type is NOT boolean By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. --- .../src/amazon/opentelemetry/distro/_aws_attribute_keys.py | 2 +- .../distro/aws_batch_unsampled_span_processor.py | 6 ++---- .../distro/test_aws_batch_unsampled_span_processor.py | 4 ++-- lambda-layer/README.md | 7 +++++++ 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/_aws_attribute_keys.py b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/_aws_attribute_keys.py index 923025894..a2b7cd00b 100644 --- a/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/_aws_attribute_keys.py +++ b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/_aws_attribute_keys.py @@ -11,7 +11,7 @@ AWS_REMOTE_RESOURCE_IDENTIFIER: str = "aws.remote.resource.identifier" AWS_SDK_DESCENDANT: str = "aws.sdk.descendant" AWS_CONSUMER_PARENT_SPAN_KIND: str = "aws.consumer.parent.span.kind" -AWS_TRACE_FLAG_UNSAMPLED: str = "aws.trace.flag.unsampled" +AWS_TRACE_FLAG_SAMPLED: str = "aws.trace.flag.sampled" # AWS_#_NAME attributes are not supported in python as they are not part of the Semantic Conventions. # TODOļ¼šMove to Semantic Conventions when these attributes are added. diff --git a/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_batch_unsampled_span_processor.py b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_batch_unsampled_span_processor.py index 36e239188..367ff38ee 100644 --- a/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_batch_unsampled_span_processor.py +++ b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_batch_unsampled_span_processor.py @@ -3,22 +3,20 @@ import logging from typing import Optional -from amazon.opentelemetry.distro._aws_attribute_keys import AWS_TRACE_FLAG_UNSAMPLED +from amazon.opentelemetry.distro._aws_attribute_keys import AWS_TRACE_FLAG_SAMPLED from opentelemetry.context import Context from opentelemetry.sdk.trace import ReadableSpan, Span from opentelemetry.sdk.trace.export import BatchSpanProcessor as BaseBatchSpanProcessor logger = logging.getLogger(__name__) -SPANUNSAMPLED_FLAG = "OTEL_AWS_APP_SIGNALS_ENABLED" - class BatchUnsampledSpanProcessor(BaseBatchSpanProcessor): # pylint: disable=no-self-use def on_start(self, span: Span, parent_context: Optional[Context] = None) -> None: if not span.context.trace_flags.sampled: - span.set_attribute(AWS_TRACE_FLAG_UNSAMPLED, True) + span.set_attribute(AWS_TRACE_FLAG_SAMPLED, False) def on_end(self, span: ReadableSpan) -> None: if span.context.trace_flags.sampled: diff --git a/aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_batch_unsampled_span_processor.py b/aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_batch_unsampled_span_processor.py index 004d2f1d1..5b6fed42e 100644 --- a/aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_batch_unsampled_span_processor.py +++ b/aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_batch_unsampled_span_processor.py @@ -3,7 +3,7 @@ from unittest import TestCase from unittest.mock import MagicMock, patch -from amazon.opentelemetry.distro._aws_attribute_keys import AWS_TRACE_FLAG_UNSAMPLED +from amazon.opentelemetry.distro._aws_attribute_keys import AWS_TRACE_FLAG_SAMPLED from amazon.opentelemetry.distro.aws_batch_unsampled_span_processor import BatchUnsampledSpanProcessor from opentelemetry.trace import TraceFlags @@ -43,7 +43,7 @@ def test_on_end_not_sampled(self, mock_span_class): self.processor.on_end(mock_span2) self.assertEqual(len(self.processor.queue), 1) - self.assertIn(AWS_TRACE_FLAG_UNSAMPLED, mock_span1.set_attribute.call_args_list[0][0][0]) + self.assertIn(AWS_TRACE_FLAG_SAMPLED, mock_span1.set_attribute.call_args_list[0][0][0]) self.processor.shutdown() mock_span2 = mock_span_class.return_value diff --git a/lambda-layer/README.md b/lambda-layer/README.md index dbdba611c..5eb0fab46 100644 --- a/lambda-layer/README.md +++ b/lambda-layer/README.md @@ -47,3 +47,10 @@ cd lambda-layer Once the script has successfully run, you will see the deployed Lambda sample app in your AWS account. You can trigger the Lambda function and view the traces and metrics through the AWS CloudWatch Console. + +## Configuration + +By default the layer enable botocore and aws-lambda instrumentation libraries only for better Lambda cold start performance. To +enable all opentelemetry python +supported libraries you can set environment variable `OTEL_PYTHON_DISABLED_INSTRUMENTATIONS=none`. Refer to details in +[OpenTelemetry Python Disabling Specific Instrumentations](Disabling Specific Instrumentations) \ No newline at end of file