Mocking or stubbing Sentry for testing #5207
Unanswered
jenstroeger
asked this question in
Q&A
Replies: 1 comment 1 reply
-
|
I tried your custom transport with explicitly calling >>> import sentry_sdk
>>> class PrintTransport(sentry_sdk.Transport):
... def capture_envelope(self, envelope):
... print("SENTRY", envelope)
...
>>> sentry_sdk.init(dsn=None, transport=PrintTransport(), transport_queue_size=0)
<sentry_sdk._init_implementation._InitGuard object at 0x7f4046857b60>
>>> try:
... a=1/0
... except:
... sentry_sdk.capture_exception()
...
SENTRY <Envelope headers={'event_id': '669b18c429e54f32b0abbd64da600635', 'sent_at': '2025-12-11T15:28:44.422663Z', 'trace': {'trace_id': '1a507934c3fb496f9fce0847c37c2d79', 'environment': 'production', 'release': '2e9a36cdc11139eff27e126331f1a8c7cf2d148f'}} items=[<Item headers={'type': 'event', 'content_type': 'application/json'} payload=<Payload 'application/json'> data_category='error'>]>
'669b18c429e54f32b0abbd64da600635' |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
If I wanted to test code that’s been instrumented by Sentry, or if I wanted to test that my own filters work as expected, then I would want to run tests without Sentry actually sending off anything. (Related discussion #4499.)
There’s some documentation here on passing a custom Transport object when initializing Sentry, but there’s not much information on subclassing Transports. Reading the code it seems the capture_envelope() methods needs to be overridden:
However, when I initialize Sentry
and then trigger an error
I had expected the
print()output but that didn’t happen.What am I missing here? Thanks!
Beta Was this translation helpful? Give feedback.
All reactions