Skip to content

Commit

Permalink
AwsInstrumentor catches handler exception
Browse files Browse the repository at this point in the history
  • Loading branch information
tammy-baylis-swi committed Feb 15, 2024
1 parent 2518a4a commit ea87363
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def custom_event_context_extractor(lambda_event):
get_tracer_provider,
)
from opentelemetry.trace.propagation import get_current_span
from opentelemetry.trace.status import Status, StatusCode

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -350,7 +351,12 @@ def _instrumented_lambda_handler_call( # noqa pylint: disable=too-many-branches
lambda_context.aws_request_id,
)

result = call_wrapped(*args, **kwargs)
exception = None
try:
result = call_wrapped(*args, **kwargs)
except Exception as exc: # pylint: disable=W0703
exception = exc
span.set_status(Status(StatusCode.ERROR))

# If the request came from an API Gateway, extract http attributes from the event
# https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/instrumentation/aws-lambda.md#api-gateway
Expand Down Expand Up @@ -398,6 +404,9 @@ def _instrumented_lambda_handler_call( # noqa pylint: disable=too-many-branches
"MeterProvider was missing `force_flush` method. This is necessary in case of a Lambda freeze and would exist in the OTel SDK implementation."
)

if exception is not None:
raise exception.with_traceback(exception.__traceback__)

return result

wrap_function_wrapper(
Expand Down

0 comments on commit ea87363

Please sign in to comment.