Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions lambda-layer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading