Skip to content

Commit a1d322d

Browse files
committed
fix unit test coverage
1 parent a1154df commit a1d322d

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
13
import logging
24
from typing import Optional
35

@@ -13,6 +15,7 @@
1315

1416
class BatchUnsampledSpanProcessor(BaseBatchSpanProcessor):
1517

18+
# pylint: disable=no-self-use
1619
def on_start(self, span: Span, parent_context: Optional[Context] = None) -> None:
1720
if not span.context.trace_flags.sampled:
1821
span.set_attribute(AWS_TRACE_FLAG_UNSAMPLED, "True")
@@ -26,6 +29,7 @@ def on_end(self, span: ReadableSpan) -> None:
2629
return
2730

2831
if len(self.queue) == self.max_queue_size:
32+
# pylint: disable=access-member-before-definition
2933
if not self._spans_dropped:
3034
logger.warning("Queue is full, likely spans will be dropped.")
3135
self._spans_dropped = True

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ def _init_tracing(
154154
span_exporter: SpanExporter = exporter_class(**exporter_args)
155155
span_exporter = _customize_exporter(span_exporter, resource)
156156
trace_provider.add_span_processor(BatchSpanProcessor(span_exporter))
157-
_export_unsampled_span_for_lambda(trace_provider, resource)
158157

158+
_export_unsampled_span_for_lambda(trace_provider, resource)
159159
_customize_span_processors(trace_provider, resource)
160160

161161
set_tracer_provider(trace_provider)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
13
from unittest import TestCase
24
from unittest.mock import MagicMock, patch
35

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from amazon.opentelemetry.distro.always_record_sampler import AlwaysRecordSampler
99
from amazon.opentelemetry.distro.attribute_propagating_span_processor import AttributePropagatingSpanProcessor
10+
from amazon.opentelemetry.distro.aws_batch_unsampled_span_processor import BatchUnsampledSpanProcessor
1011
from amazon.opentelemetry.distro.aws_metric_attributes_span_exporter import AwsMetricAttributesSpanExporter
1112
from amazon.opentelemetry.distro.aws_opentelemetry_configurator import (
1213
ApplicationSignalsExporterProvider,
@@ -15,6 +16,7 @@
1516
_customize_exporter,
1617
_customize_sampler,
1718
_customize_span_processors,
19+
_export_unsampled_span_for_lambda,
1820
_is_application_signals_enabled,
1921
_is_defer_to_workers_enabled,
2022
_is_wsgi_master_process,
@@ -351,6 +353,19 @@ def test_initialize_components_called_when_deferred_disabled(self, mock_initiali
351353
mock_initialize_components.assert_called_once()
352354
os.environ.pop("IS_WSGI_MASTER_PROCESS_ALREADY_SEEN", None)
353355

356+
def test_export_unsampled_span_for_lambda(self):
357+
mock_tracer_provider: TracerProvider = MagicMock()
358+
_export_unsampled_span_for_lambda(mock_tracer_provider, Resource.get_empty())
359+
self.assertEqual(mock_tracer_provider.add_span_processor.call_count, 0)
360+
361+
os.environ.setdefault("OTEL_AWS_APPLICATION_SIGNALS_ENABLED", "True")
362+
os.environ.setdefault("AWS_LAMBDA_FUNCTION_NAME", "myfunction")
363+
_export_unsampled_span_for_lambda(mock_tracer_provider, Resource.get_empty())
364+
self.assertEqual(mock_tracer_provider.add_span_processor.call_count, 1)
365+
first_processor: SpanProcessor = mock_tracer_provider.add_span_processor.call_args_list[0].args[0]
366+
self.assertIsInstance(first_processor, BatchUnsampledSpanProcessor)
367+
os.environ.pop("OTEL_AWS_APPLICATION_SIGNALS_ENABLED", None)
368+
354369

355370
def validate_distro_environ():
356371
tc: TestCase = TestCase()

0 commit comments

Comments
 (0)