Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exception handling for events with requestContext #2418

Merged
merged 4 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#2363](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2363))
- `opentelemetry-instrumentation-boto3sqs` Instrument Session and resource
([#2161](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2161))
- `opentelemetry-instrumentation-aws-lambda` Fix exception handling for events with requestContext
([#2418](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2418))
- Use sqlalchemy version in sqlalchemy commenter instead of opentelemetry library version
([#2404](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2404))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ def _instrumented_lambda_handler_call( # noqa pylint: disable=too-many-branches
)

exception = None
result = None
try:
result = call_wrapped(*args, **kwargs)
except Exception as exc: # pylint: disable=W0703
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,31 @@ def test_lambda_handles_handler_exception(self):

exc_env_patch.stop()

def test_lambda_handles_handler_exception_with_api_gateway_proxy_event(
self,
):
exc_env_patch = mock.patch.dict(
"os.environ",
{_HANDLER: "tests.mocks.lambda_function.handler_exc"},
)
exc_env_patch.start()
AwsLambdaInstrumentor().instrument()
# instrumentor re-raises the exception
with self.assertRaises(Exception):
mock_execute_lambda(
{"requestContext": {"http": {"method": "GET"}}}
)

spans = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans), 1)
span = spans[0]
self.assertEqual(span.status.status_code, StatusCode.ERROR)
self.assertEqual(len(span.events), 1)
event = span.events[0]
self.assertEqual(event.name, "exception")

exc_env_patch.stop()

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

Expand Down
Loading