Skip to content

Fix ImportError with slash-delimited Lambda handler paths#3894

Merged
xrmx merged 4 commits into
open-telemetry:mainfrom
DivMode:fix/aws-lambda-slash-delimited-handler
Oct 30, 2025
Merged

Fix ImportError with slash-delimited Lambda handler paths#3894
xrmx merged 4 commits into
open-telemetry:mainfrom
DivMode:fix/aws-lambda-slash-delimited-handler

Conversation

@DivMode

@DivMode DivMode commented Oct 24, 2025

Copy link
Copy Markdown
Contributor

Description

AWS Lambda accepts handler paths in both formats:

  • Slash-delimited: python/functions/api.handler
  • Dot-delimited: python.functions.api.handler

The instrumentation was failing when slash-delimited paths were used because it attempted to import invalid Python module paths containing forward slashes. This fix normalizes the handler path by converting slashes to dots before splitting the module and function names.

Fixes #1465

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Added unit test test_slash_delimited_handler_path() that verifies both slash-delimited and dot-delimited handler paths work correctly
  • Tested with AWS Lambda function using slash-delimited handler (python/functions/api.handler) in production environment
  • Verified OpenTelemetry instrumentation layer successfully imports and instruments the handler
  • Previously failed with ImportError: No module named 'python/functions/api', now works correctly
  • Tested in production with SST framework which uses slash-delimited paths by default
  • All existing tests pass with the change

Does This PR Require a Core Repo Change?

  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated (not applicable - internal bug fix, no API changes)

AWS Lambda accepts handler paths in both formats:
- Slash-delimited: python/functions/api.handler
- Dot-delimited: python.functions.api.handler

The instrumentation was failing when slash-delimited paths were used
because it attempted to import invalid Python module paths containing
forward slashes. This fix normalizes the handler path by converting
slashes to dots before splitting the module and function names.

Fixes open-telemetry#1465
- Add changelog entry in Unreleased section
- Add unit test verifying both slash and dot-delimited handler paths work
- Test confirms instrumentation handles both formats correctly

Related to open-telemetry#1465
@DivMode DivMode requested a review from a team as a code owner October 24, 2025 00:51
@linux-foundation-easycla

linux-foundation-easycla Bot commented Oct 24, 2025

Copy link
Copy Markdown

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: xrmx / name: Riccardo Magliocchetti (400f554)

Comment thread CHANGELOG.md Outdated

@tammy-baylis-swi tammy-baylis-swi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this! It lgtm, the Maintainers will also have a look.

Co-authored-by: Tammy Baylis <96076570+tammy-baylis-swi@users.noreply.github.com>
@xrmx xrmx enabled auto-merge (squash) October 30, 2025 13:27
@xrmx xrmx merged commit b16709e into open-telemetry:main Oct 30, 2025
647 checks passed
@github-project-automation github-project-automation Bot moved this from Ready for review to Done in Python PR digest Oct 30, 2025
bisgaard-itis pushed a commit to bisgaard-itis/opentelemetry-python-contrib that referenced this pull request Nov 3, 2025
…etry#3894)

* Fix ImportError with slash-delimited Lambda handler paths

AWS Lambda accepts handler paths in both formats:
- Slash-delimited: python/functions/api.handler
- Dot-delimited: python.functions.api.handler

The instrumentation was failing when slash-delimited paths were used
because it attempted to import invalid Python module paths containing
forward slashes. This fix normalizes the handler path by converting
slashes to dots before splitting the module and function names.

Fixes open-telemetry#1465

* Add changelog and unit test for slash-delimited handler fix

- Add changelog entry in Unreleased section
- Add unit test verifying both slash and dot-delimited handler paths work
- Test confirms instrumentation handles both formats correctly

Related to open-telemetry#1465

* Update CHANGELOG.md

Co-authored-by: Tammy Baylis <96076570+tammy-baylis-swi@users.noreply.github.com>

---------

Co-authored-by: Emídio Neto <9735060+emdneto@users.noreply.github.com>
Co-authored-by: Tammy Baylis <96076570+tammy-baylis-swi@users.noreply.github.com>
Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
sightseeker added a commit to sightseeker/opentelemetry-python-contrib that referenced this pull request Mar 11, 2026
…etry#3894)

* Fix ImportError with slash-delimited Lambda handler paths

AWS Lambda accepts handler paths in both formats:
- Slash-delimited: python/functions/api.handler
- Dot-delimited: python.functions.api.handler

The instrumentation was failing when slash-delimited paths were used
because it attempted to import invalid Python module paths containing
forward slashes. This fix normalizes the handler path by converting
slashes to dots before splitting the module and function names.

Fixes open-telemetry#1465

* Add changelog and unit test for slash-delimited handler fix

- Add changelog entry in Unreleased section
- Add unit test verifying both slash and dot-delimited handler paths work
- Test confirms instrumentation handles both formats correctly

Related to open-telemetry#1465

* Update CHANGELOG.md

Co-authored-by: Tammy Baylis <96076570+tammy-baylis-swi@users.noreply.github.com>

---------

Co-authored-by: Emídio Neto <9735060+emdneto@users.noreply.github.com>
Co-authored-by: Tammy Baylis <96076570+tammy-baylis-swi@users.noreply.github.com>
Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Slash-delimited handler paths result in ImportError within AwsLambdaInstrumentor.instrument

4 participants