mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-07-29 21:23:55 +08:00
Fix exception handling for events with requestContext (#2418)
* Fix exception handling for events with requestContext * added entry to changelog * reformatted with black --------- Co-authored-by: Diego Hurtado <ocelotl@users.noreply.github.com>
This commit is contained in:

committed by
GitHub

parent
5375acf534
commit
d5b5925cf8
@ -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))
|
||||
|
||||
|
@ -365,6 +365,7 @@ def _instrument(
|
||||
)
|
||||
|
||||
exception = None
|
||||
result = None
|
||||
try:
|
||||
result = call_wrapped(*args, **kwargs)
|
||||
except Exception as exc: # pylint: disable=W0703
|
||||
|
@ -436,6 +436,31 @@ class TestAwsLambdaInstrumentor(TestBase):
|
||||
|
||||
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()
|
||||
|
||||
|
Reference in New Issue
Block a user