Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove current breadcrumbs in sentry

Tags:

python

sentry

I have simple synchronous code like this:

import sentry_sdk
from time import sleep


sentry_sdk.init(MY_DSN)
while True:
    # remove sentry breadcrumbs here, so they would not accumulate
    try:
        do_my_stuff()
    except:
        handle_my_exception()

    sleep(some_non_linear_algorithm())  # I would like not to use crontab

When exception occurs sentry captures it and all breadcrumbs from previous iterations, so I need to delete all current breadcrumbs in the beginning of each iteration. But I cannot find any API to do that in sentry documentation.

like image 967
Helvdan Avatar asked Sep 11 '26 15:09

Helvdan


1 Answers

Wrap your code in this:

with sentry_sdk.push_scope():
    try:
        ...
    except:
        ...

This will make sure that you don't leak breadcrumbs, tags, etc between iterations.

Alternatively you can use:

with sentry_sdk.configure_scope() as scope:
    scope.clear()
like image 123
Markus Unterwaditzer Avatar answered Sep 14 '26 04:09

Markus Unterwaditzer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!