Skip to content

fix(otel): ignore non-string stack frames - #980

Draft
ibrahimmaq14 wants to merge 2 commits into
aws:mainfrom
ibrahimmaq14:fix/966-otel-malformed-stack
Draft

ibrahimmaq14 wants to merge 2 commits into
aws:mainfrom
ibrahimmaq14:fix/966-otel-malformed-stack

Conversation

@ibrahimmaq14

@ibrahimmaq14 ibrahimmaq14 commented Nov 21, 2026 •

Copy link
Copy Markdown

Issue

Fixes #966.

Description of changes

Filter non-string entries when the shared OTel exception recorder joins checkpointed stack frames. Both the Execution and Invocation views retain valid frames, record the stored error type and message, and finish failed operation and attempt spans.

Design

  • Rule 3 applicability. Internal bug fix.
  • Root cause. ErrorObject.from_dict preserves the stored stack entries. Joining the raw list raises TypeError before either plugin can finish the span or detach the attempt context.
  • Filtering during the existing join handles the problem at the shared call site. Dropping the whole stack would discard valid frames. Stringifying invalid entries would introduce frames that the checkpoint did not store.
  • Net change is three production lines and zero public API members.

Assumptions

The regression uses the SDK's real ErrorObject.from_dict and the real OTel SDK's in-memory exporter. It covers both plugin implementations and checks span completion, context restoration, error status, and exact event attributes. It makes no assumption about whether Lambda produces malformed stacks.

Decisions not covered by the issue or the design note

  • Keep valid string frames in their original order so mixed stacks retain useful telemetry.
  • Omit the stack attribute when filtering produces an empty joined stack, consistent with the recorder's existing empty-stack behavior.

Validation

Python 3.13.17, Hatch 1.16.5, Windows.

  • hatch run dev-otel:test -q -k malformed_stack --tb=short — 8 failed with TypeError at b94768f; 8 passed with the fix.
  • hatch run dev-otel:test -q --tb=short — 1,021 passed, 84 warnings.
  • hatch run dev-otel:typecheck — passed, 46 source files checked.
  • hatch fmt --check from the OTel package — Ruff lint and format passed.
  • Core and OTel distributions built, the OTel wheel dependency check passed, and the commit-message and diff checks passed.
  • hatch run test-wheel-otel:test -q --tb=short — 1,021 OTel tests passed and all 12 lifecycle compatibility tests passed.
  • hatch run test-wheel-otel-legacy:test -q --tb=short — 4 passed.
  • Repository-wide Windows coverage run — 7,001 passed, 10 failed, and 7 skipped. The main worktree at 764e950b ran the full suite with 6,998 passed, 5 failed, and 7 skipped. Negative timestamps and port binding failed on both revisions. Callback suites showed intermittent Windows checkpoint-file access errors and replay-count differences on the baseline and patch across the full and focused runs. All six empty-callback persistence cases passed when rerun in isolation on both revisions.
  • The upstream Python package workflow awaits maintainer approval.

Checklist

  • Both outcomes of the new frame filter are exercised.
  • The first commit adds the failing regression. The following commit fixes it.
  • Regression coverage adds eight cases without editing existing expectations.

Prepared with OpenAI Codex assistance. The results above are from local runs.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@zhongkechen

Copy link
Copy Markdown
Contributor

Looks good to me. @ibrahimmaq14 please mark the PR ready and I'll approve it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OTel end hooks can skip span cleanup when a stored stack contains a non-string entry

2 participants