Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Fixed

- `opentelemetry-instrumentation-aws-lambda`: Fix ImportError with slash-delimited handler paths
([#3894](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3894))

## Version 1.38.0/0.59b0 (2025-10-16)

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ def _instrument(self, **kwargs):
)
return
# pylint: disable=attribute-defined-outside-init
# Convert slash-delimited paths to dot-delimited for valid Python imports
lambda_handler = lambda_handler.replace("/", ".")
(
self._wrapped_module_name,
self._wrapped_function_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,53 @@ def test_sqs_event_sets_attributes(self):
MOCK_LAMBDA_CONTEXT_ATTRIBUTES,
)

def test_slash_delimited_handler_path(self):
"""Test that slash-delimited handler paths work correctly.

AWS Lambda accepts both slash-delimited (python/functions/api.handler)
and dot-delimited (python.functions.api.handler) handler paths.
This test ensures the instrumentation handles both formats.
"""
# Test slash-delimited format
slash_env_patch = mock.patch.dict(
"os.environ",
{_HANDLER: "tests/mocks/lambda_function.handler"},
)
slash_env_patch.start()
AwsLambdaInstrumentor().instrument()

mock_execute_lambda()

spans = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans), 1)
self.assertSpanHasAttributes(
spans[0],
MOCK_LAMBDA_CONTEXT_ATTRIBUTES,
)

slash_env_patch.stop()
AwsLambdaInstrumentor().uninstrument()
self.memory_exporter.clear()

# Test dot-delimited format (should still work)
dot_env_patch = mock.patch.dict(
"os.environ",
{_HANDLER: "tests.mocks.lambda_function.handler"},
)
dot_env_patch.start()
AwsLambdaInstrumentor().instrument()

mock_execute_lambda()

spans = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans), 1)
self.assertSpanHasAttributes(
spans[0],
MOCK_LAMBDA_CONTEXT_ATTRIBUTES,
)

dot_env_patch.stop()

def test_lambda_handles_handler_exception_with_api_gateway_proxy_event(
self,
):
Expand Down