feat(transport): Add EnvelopePrinterTransport for debug logging #6181
3 issues
code-review: Found 3 issues (1 high, 2 low)
High
Overriding __class__ as a property breaks isinstance and type identity - `sentry_sdk/transport.py:1095-1099`
The __class__ property dynamically returns self._inner.__class__, which causes isinstance(printer, _EnvelopePrinterTransport) to return False and type(printer) to report the inner transport's class. This is a significant side effect that can confuse Sentry's internal type checks (e.g., isinstance(transport, HttpTransport) checks elsewhere in the SDK), break debugging/logging, and cause subtle bugs in any code that relies on type identity of the transport. It also conflicts with backwards compatibility expectations of the Transport interface.
Low
__getattr__ implementation could cause infinite recursion in edge cases - `sentry_sdk/transport.py:1165-1168`
__getattr__ accesses self._inner without guarding against the case where _inner doesn't exist, which could cause infinite recursion if __getattr__ is somehow invoked before self._inner is assigned in __init__. While normal code paths don't trigger this (since __init__ either completes successfully or raises before the object is created), this violates Python best practices for __getattr__ implementation and could be triggered in edge cases like object deserialization, introspection tools, or metaclass manipulation. The standard pattern is to use object.__getattribute__(self, '_inner') or guard with if name == '_inner': raise AttributeError(name).
Bare except swallows all exceptions during envelope printing - `sentry_sdk/transport.py:1124-1125`
The except Exception: pass block silently discards any error during debug printing, including programming errors. While the intent (don't break envelope sending due to debug logging) is reasonable, swallowing without even a debug log makes diagnosing issues with the printer itself impossible. Consider logger.debug("Failed to print envelope", exc_info=True) so failures are visible when debug logging is enabled.
Duration: 42.2s · Tokens: 50.5k in / 1.7k out · Cost: $2.08 (+verification: $1.95, +merge: $0.00)
Annotations
Check failure on line 1099 in sentry_sdk/transport.py
sentry-warden / warden: code-review
Overriding __class__ as a property breaks isinstance and type identity
The `__class__` property dynamically returns `self._inner.__class__`, which causes `isinstance(printer, _EnvelopePrinterTransport)` to return False and `type(printer)` to report the inner transport's class. This is a significant side effect that can confuse Sentry's internal type checks (e.g., `isinstance(transport, HttpTransport)` checks elsewhere in the SDK), break debugging/logging, and cause subtle bugs in any code that relies on type identity of the transport. It also conflicts with backwards compatibility expectations of the Transport interface.