Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b644506

Browse files
committedJul 29, 2024·
refactor: do nothing with aws-lambda instrumentation when code is running outside a lambda
1 parent 7a8b084 commit b644506

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed
 

‎instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -423,12 +423,13 @@ def _instrument(self, **kwargs):
423423
"""
424424
lambda_handler = os.environ.get(ORIG_HANDLER, os.environ.get(_HANDLER))
425425
if not lambda_handler:
426-
raise ValueError(
426+
logger.warning(
427427
(
428428
"Could not find the ORIG_HANDLER or _HANDLER in the environment variables. ",
429429
"This instrumentation is runnning inside an aws lambda?",
430430
)
431431
)
432+
return
432433
# pylint: disable=attribute-defined-outside-init
433434
(
434435
self._wrapped_module_name,

‎instrumentation/opentelemetry-instrumentation-aws-lambda/tests/test_aws_lambda_instrumentation_manual.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -495,17 +495,15 @@ def test_lambda_handles_handler_exception_with_api_gateway_proxy_event(
495495

496496
exc_env_patch.stop()
497497

498-
def test_lambda_handles_raises_exception_when_environment_variables_not_present(
498+
def test_lambda_handles_should_do_nothing_when_environment_variables_not_present(
499499
self,
500500
):
501501
exc_env_patch = mock.patch.dict(
502502
"os.environ",
503503
{_HANDLER: ""},
504504
)
505505
exc_env_patch.start()
506-
507-
with self.assertRaises(Exception):
508-
AwsLambdaInstrumentor().instrument()
506+
AwsLambdaInstrumentor().instrument()
509507

510508
spans = self.memory_exporter.get_finished_spans()
511509
self.assertEqual(len(spans), 0)

0 commit comments

Comments
 (0)
Please sign in to comment.