fix(sentry): stop reporting optional-integration import errors as SDK bugs#175
fix(sentry): stop reporting optional-integration import errors as SDK bugs#175cursor[bot] wants to merge 1 commit into
Conversation
…YTHON-YY) The SDK's lightweight Sentry trace function reported ModuleNotFoundError exceptions raised while importing optional framework integrations (blaxel.openai, blaxel.livekit, ...) as if they were SDK bugs. These failures are environment issues: the user imported an integration without installing its extra, the extra has a missing transitive dependency, or a stripped/partial install is missing the integration's modules (e.g. 'No module named blaxel.openai.model'). Expand _is_optional_dependency_error to recognize: - import errors for any optional blaxel integration subpackage - import failures of third-party deps raised while loading an optional integration package Genuine SDK import bugs (failures on blaxel.* core modules) are still captured. Adds tests/core/test_sentry.py. Co-authored-by: psinai <psinai@blaxel.ai>
🧪 Testing GuideWhat this PR addressesThe SDK's global Steps to reproduce the original issue
What to verify (expected behavior)
Note Posted by PR Testing Guide · Tag @mendral-app with feedback. |
There was a problem hiding this comment.
LGTM
The logic is sound: the three checks correctly classify integration import errors as expected while preserving reporting for core module failures. The traceback walk is bounded (no infinite loop risk), the if missing guard prevents the empty-string edge case, and the not missing.startswith("blaxel") condition ensures genuine SDK import bugs on blaxel.* core modules still reach Sentry. The hardcoded _OPTIONAL_INTEGRATION_PACKAGES list will require manual updates when new integrations are added, but that's an acceptable maintenance trade-off for explicit control over the filter scope. Tests are well-structured and cover the key cases.
Tag @mendral-app with feedback or questions. View session
🔀 Interaction FlowThis PR enhances the Sentry error filtering in the SDK to suppress optional-integration sequenceDiagram
participant App as User Application
participant Hook as sys.settrace Hook
participant Filter as _is_optional_dependency_error()
participant Pkgs as _OPTIONAL_INTEGRATION_PACKAGES
participant Paths as _OPTIONAL_INTEGRATION_PATHS
participant Sentry as Sentry (Remote)
App->>Hook: ImportError raised in blaxel frame
Hook->>Filter: exc_type, exc_value
alt Not an ImportError
Filter-->>Hook: False (report it)
Hook->>Sentry: Forward exception
else Tier 1: Missing module matches optional package
Filter->>Pkgs: Check exc_value.name against package list
Pkgs-->>Filter: Match found (e.g. blaxel.openai.model)
Filter-->>Hook: True (suppress)
else Tier 2: Known optional third-party dep (e.g. opentelemetry)
Filter-->>Hook: True (suppress)
else Tier 3: Non-blaxel import failing inside integration path
Filter->>Paths: Walk traceback, check frame paths
Paths-->>Filter: Frame in optional integration directory
Filter-->>Hook: True (suppress)
else No match in any tier
Filter-->>Hook: False (report it)
Hook->>Sentry: Forward exception
end
SummaryThe refactored
Only errors that fail all three tiers are forwarded to Sentry, ensuring real SDK bugs still get reported. Note Posted by PR Sequence Diagram · Tag @mendral-app with feedback. |
Problem
Sentry issue SDK-PYTHON-YY —
ModuleNotFoundError: No module named 'blaxel.livekit.model'(clustered withNo module named 'blaxel.openai.model'), 7 occurrences, 0 users impacted, releasesdk-python@0.2.58.Root cause
The SDK installs a global
sys.settracehook (src/blaxel/core/common/sentry.py) that forwards any exception whose frame lives insite-packages/blaxelto Blaxel's Sentry. Its_is_optional_dependency_errorallow-list only knew aboutopentelemetry.When a user imports an optional framework integration (
blaxel.openai,blaxel.livekit, …) in an environment that is missing the matching extra — or runs a stripped/partial install where the integration'smodel.pyis absent (common in.pyenv-based agent images, which is the exact production case: culpritblaxel/<pkg>/__init__.pyline 3 =from .model import *) — the resultingModuleNotFoundErrorwas captured and reported as if it were an SDK defect. These are environment issues, not SDK bugs.I verified this empirically:
0.2.58wheel and sdist both containmodel.pyfor every integration (so it is not a packaging bug).blaxel/openai/model.pyfrom a clean install reproduces the exact Sentry signature, includingexc.name == 'blaxel.openai.model'and the single__init__.pyline-3 frame.Fix
Expand
_is_optional_dependency_errorto also treat as expected (and therefore not report):blaxel.langgraph,blaxel.llamaindex,blaxel.openai,blaxel.crewai,blaxel.googleadk,blaxel.livekit,blaxel.pydantic,blaxel.telemetry), andagents,livekit).Genuine SDK import bugs (failures on
blaxel.*core modules) are still captured.Validation
tests/core/test_sentry.py(8 cases) — all pass.blaxel.core.broken) is still captured.BL_API_KEYcredentials not present in CI sandbox).ruff check+ruff formatclean.Remaining risk
Low. The change only narrows what is sent to Sentry, scoped to
ImportErrorfrom optional integration packages; it does not alter integration behavior or what users see at import time.Fixes SDK-PYTHON-YY
Note
Expands the Sentry error filter to suppress
ImportError/ModuleNotFoundErrorexceptions from optional integration packages (e.g.blaxel.openai,blaxel.livekit) so they are not reported as SDK bugs. Adds a traceback-walking heuristic for third-party deps failing inside integration code, and covers the logic with unit tests.Written by Mendral for commit cb2dc73.