Skip to content

Commit

Permalink
refactor: do nothing with aws-lambda instrumentation when code is run…
Browse files Browse the repository at this point in the history
…ning outside a lambda
  • Loading branch information
Ronald-TR committed Jul 29, 2024
1 parent 7a8b084 commit b644506
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -423,12 +423,13 @@ def _instrument(self, **kwargs):
"""
lambda_handler = os.environ.get(ORIG_HANDLER, os.environ.get(_HANDLER))
if not lambda_handler:
raise ValueError(
logger.warning(
(
"Could not find the ORIG_HANDLER or _HANDLER in the environment variables. ",
"This instrumentation is runnning inside an aws lambda?",
)
)
return
# 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,17 +495,15 @@ 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(
def test_lambda_handles_should_do_nothing_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()
AwsLambdaInstrumentor().instrument()

spans = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans), 0)
Expand Down

0 comments on commit b644506

Please sign in to comment.