-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Python] Improved code snippet for
error_sampler
(#11314)
--------- Co-authored-by: vivianyentran <[email protected]>
- Loading branch information
1 parent
014af4f
commit b916cd0
Showing
2 changed files
with
16 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
```python | ||
import sentry_sdk | ||
from sentry_sdk.types import Event, Hint | ||
|
||
def my_sampler(_, hint): | ||
exception_sampler_values = { | ||
MyException: 0.5, | ||
MyIgnoredException: 0.0, # or equivalently, False | ||
} | ||
|
||
try: | ||
return exception_sampler_values[hint["exc_info"][0]] | ||
except (IndexError, KeyError, TypeError): | ||
return 1.0 # or equivalently, True | ||
def my_error_sampler(event: Event, hint: Hint) -> float: | ||
error_class = hint["exc_info"][0] | ||
|
||
if error_class == MyException: | ||
return 0.5 | ||
elif error_class == MyIgnoredException: | ||
return 0 | ||
|
||
# All the other errors | ||
return 1.0 | ||
|
||
|
||
sentry_sdk.init( | ||
# ... | ||
|
||
error_sampler=my_sampler, | ||
error_sampler=my_error_sampler, | ||
) | ||
``` |