From b94768f800db9c6e9a23212c3c28548ca6fd0e47 Mon Sep 17 00:00:00 2001 From: ibrahimmaq14 Date: Sat, 21 Nov 2026 21:19:29 +0530 Subject: [PATCH 1/2] test(otel): reproduce malformed stack cleanup --- .../tests/test_status_mapping.py | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/packages/aws-durable-execution-sdk-python-otel/tests/test_status_mapping.py b/packages/aws-durable-execution-sdk-python-otel/tests/test_status_mapping.py index f5eff92c5..98e07ea7c 100644 --- a/packages/aws-durable-execution-sdk-python-otel/tests/test_status_mapping.py +++ b/packages/aws-durable-execution-sdk-python-otel/tests/test_status_mapping.py @@ -511,6 +511,53 @@ def test_exception_stacktrace_requires_nonempty_joined_stack( assert span.start_time <= span.events[0].timestamp <= span.end_time +@pytest.mark.parametrize("event_kind", ["operation", "attempt"]) +@pytest.mark.parametrize( + ("stack_trace", "expected_stack"), + [ + ( + ["first frame", None, "last frame"], + {"exception.stacktrace": "first frame\nlast frame"}, + ), + ([None, 42], {}), + ], +) +def test_malformed_stack_does_not_interrupt_span_cleanup( + instrumented_view: InstrumentedView, + event_kind: str, + stack_trace: list[object], + expected_stack: dict[str, str], +) -> None: + plugin, exporter = instrumented_view + error = ErrorObject.from_dict( + { + "ErrorType": "RuntimeError", + "ErrorMessage": "boom", + "StackTrace": stack_trace, + } + ) + _start_invocation(plugin) + enclosing_context = context.get_current() + try: + if event_kind == "operation": + plugin.on_operation_end(_operation_end_info(error)) + span_name = "wait" + else: + _run_failed_step_attempt(plugin, error) + span_name = "step-1 attempt 1" + + assert context.get_current() == enclosing_context + span = next(s for s in exporter.get_finished_spans() if s.name == span_name) + assert span.status.status_code is StatusCode.ERROR + assert dict(_exception_attributes(span)) == { + "exception.type": "RuntimeError", + "exception.message": "boom", + **expected_stack, + } + finally: + _end_invocation(plugin) + + @pytest.mark.parametrize(("message", "error_type", "expected"), PARTIAL_CASES) def test_failed_operation_omits_absent_error_fields( instrumented_view: InstrumentedView, From 71a09b0f8ad8b0a265c79b11008956a47ad17265 Mon Sep 17 00:00:00 2001 From: ibrahimmaq14 Date: Sat, 21 Nov 2026 21:21:12 +0530 Subject: [PATCH 2/2] fix(otel): ignore non-string stack frames --- .../exception_events.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/aws-durable-execution-sdk-python-otel/src/aws_durable_execution_sdk_python_otel/exception_events.py b/packages/aws-durable-execution-sdk-python-otel/src/aws_durable_execution_sdk_python_otel/exception_events.py index f2693cfc2..910a51d99 100644 --- a/packages/aws-durable-execution-sdk-python-otel/src/aws_durable_execution_sdk_python_otel/exception_events.py +++ b/packages/aws-durable-execution-sdk-python-otel/src/aws_durable_execution_sdk_python_otel/exception_events.py @@ -27,7 +27,10 @@ def error_object_exception_attributes(error: ErrorObject) -> dict[str, Any]: attributes["exception.type"] = error.type if error.message is not None: attributes["exception.message"] = error.message - stack_trace = "\n".join(error.stack_trace or []) + # Stored stack entries may include values other than strings. + stack_trace = "\n".join( + frame for frame in (error.stack_trace or []) if isinstance(frame, str) + ) if stack_trace: attributes["exception.stacktrace"] = stack_trace return attributes