Skip to content

Commit 1b3f738

Browse files
authored
Updated LambdaSpanProcessor to run outside of Application Signals (#341)
*Description of changes:* Updated LambdaSpanProcessor to run outside of Application Signals. This allows customers to still have the same behavior in lambda even if they opt to disable application signals. Testing: Updated unit tests and made sure they are passing. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent 8632951 commit 1b3f738

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,10 @@ def _customize_exporter(span_exporter: SpanExporter, resource: Resource) -> Span
331331

332332

333333
def _customize_span_processors(provider: TracerProvider, resource: Resource) -> None:
334+
# Add LambdaSpanProcessor to list of processors regardless of application signals.
335+
if _is_lambda_environment():
336+
provider.add_span_processor(AwsLambdaSpanProcessor())
337+
334338
if not _is_application_signals_enabled():
335339
return
336340

@@ -344,7 +348,6 @@ def _customize_span_processors(provider: TracerProvider, resource: Resource) ->
344348
# Export 100% spans and not export Application-Signals metrics if on Lambda.
345349
if _is_lambda_environment():
346350
_export_unsampled_span_for_lambda(provider, resource)
347-
provider.add_span_processor(AwsLambdaSpanProcessor())
348351
return
349352

350353
# Construct meterProvider

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from amazon.opentelemetry.distro.always_record_sampler import AlwaysRecordSampler
99
from amazon.opentelemetry.distro.attribute_propagating_span_processor import AttributePropagatingSpanProcessor
1010
from amazon.opentelemetry.distro.aws_batch_unsampled_span_processor import BatchUnsampledSpanProcessor
11+
from amazon.opentelemetry.distro.aws_lambda_span_processor import AwsLambdaSpanProcessor
1112
from amazon.opentelemetry.distro.aws_metric_attributes_span_exporter import AwsMetricAttributesSpanExporter
1213
from amazon.opentelemetry.distro.aws_opentelemetry_configurator import (
1314
LAMBDA_SPAN_EXPORT_BATCH_SIZE,
@@ -320,10 +321,12 @@ def test_customize_span_processors_lambda(self):
320321
_customize_span_processors(mock_tracer_provider, Resource.get_empty())
321322
self.assertEqual(mock_tracer_provider.add_span_processor.call_count, 3)
322323
first_processor: SpanProcessor = mock_tracer_provider.add_span_processor.call_args_list[0].args[0]
323-
self.assertIsInstance(first_processor, AttributePropagatingSpanProcessor)
324+
self.assertIsInstance(first_processor, AwsLambdaSpanProcessor)
324325
second_processor: SpanProcessor = mock_tracer_provider.add_span_processor.call_args_list[1].args[0]
325-
self.assertIsInstance(second_processor, BatchUnsampledSpanProcessor)
326-
self.assertEqual(second_processor.max_export_batch_size, LAMBDA_SPAN_EXPORT_BATCH_SIZE)
326+
self.assertIsInstance(second_processor, AttributePropagatingSpanProcessor)
327+
third_processor: SpanProcessor = mock_tracer_provider.add_span_processor.call_args_list[2].args[0]
328+
self.assertIsInstance(third_processor, BatchUnsampledSpanProcessor)
329+
self.assertEqual(third_processor.max_export_batch_size, LAMBDA_SPAN_EXPORT_BATCH_SIZE)
327330
os.environ.pop("OTEL_AWS_APPLICATION_SIGNALS_ENABLED", None)
328331
os.environ.pop("AWS_LAMBDA_FUNCTION_NAME", None)
329332

0 commit comments

Comments
 (0)