Commit a77cef6
fix(observability): wrap lazy OTel import in try/except ImportError
_emit_event gated the OTel path on `if import_checker.is_otel_installed` but
ran `from opentelemetry import trace` unguarded. If is_otel_installed was
True yet the import failed (PEP 420 namespace false-positive in 0.8.3 and
earlier; or any future partial install / broken api package), the
ImportError escaped _emit_event and crashed the middleware calling it
(AsyncRetry, Retry, AsyncBulkhead, Bulkhead) mid-request.
Wrap the lazy import in `try/except ImportError`. On failure, return — the
structured log record on the line above has already fired, so emission
degrades to log-only.
Catch ImportError specifically, not bare Exception: misconfigured-tracer
crashes (RuntimeError, AttributeError) should still surface; only the
install-gate-is-wrong case is in scope.
_emit_event's docstring grows one sentence describing the soft-fallback.
Closes audit Low finding (observability.py:40) from
planning/audit/2026-06-07-deep-audit.md.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 06dfb75 commit a77cef6
2 files changed
Lines changed: 54 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
40 | | - | |
41 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
42 | 48 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
0 commit comments