Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Fix is_valid_sample_rate to allow check on `Decimal`
  • Loading branch information
Arvind2222 committed Oct 11, 2022
1 parent a48fafd commit 8b6e3a3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions sentry_sdk/tracing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import contextlib
import json
import math
from decimal import Decimal

from numbers import Real

Expand Down Expand Up @@ -132,9 +133,10 @@ def is_valid_sample_rate(rate):
# both booleans and NaN are instances of Real, so a) checking for Real
# checks for the possibility of a boolean also, and b) we have to check
# separately for NaN
if not isinstance(rate, Real) or math.isnan(rate):
if not isinstance(rate, Real) or not isinstance(rate, Decimal) or math.isnan(rate):
logger.warning(
"[Tracing] Given sample rate is invalid. Sample rate must be a boolean or a number between 0 and 1. Got {rate} of type {type}.".format(
"[Tracing] Given sample rate is invalid. Sample rate must be a boolean or a number between 0 and 1. "
"Got {rate} of type {type}.".format(
rate=rate, type=type(rate)
)
)
Expand Down

0 comments on commit 8b6e3a3

Please sign in to comment.