Skip to content

Commit

Permalink
refactor: raise exception when lambda_handler envs not present in aws…
Browse files Browse the repository at this point in the history
…-lambda instrumentation
  • Loading branch information
Ronald-TR committed Jul 29, 2024
1 parent c45a620 commit 7a8b084
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,13 @@ def _instrument(self, **kwargs):
request.
"""
lambda_handler = os.environ.get(ORIG_HANDLER, os.environ.get(_HANDLER))
if not lambda_handler:
raise ValueError(
(
"Could not find the ORIG_HANDLER or _HANDLER in the environment variables. ",
"This instrumentation is runnning inside an aws lambda?",
)
)
# pylint: disable=attribute-defined-outside-init
(
self._wrapped_module_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,22 @@ def test_lambda_handles_handler_exception_with_api_gateway_proxy_event(

exc_env_patch.stop()

def test_lambda_handles_raises_exception_when_environment_variables_not_present(
self,
):
exc_env_patch = mock.patch.dict(
"os.environ",
{_HANDLER: ""},
)
exc_env_patch.start()

with self.assertRaises(Exception):
AwsLambdaInstrumentor().instrument()

spans = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans), 0)
exc_env_patch.stop()

def test_uninstrument(self):
AwsLambdaInstrumentor().instrument()

Expand Down

0 comments on commit 7a8b084

Please sign in to comment.