Skip to content

Commit 6e0b02b

Browse files
authored
Check for Decimal is in_valid_sample_rate (getsentry#1672)
1 parent a48fafd commit 6e0b02b

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

sentry_sdk/tracing_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import math
55

66
from numbers import Real
7+
from decimal import Decimal
78

89
import sentry_sdk
910
from sentry_sdk.consts import OP
@@ -131,8 +132,8 @@ def is_valid_sample_rate(rate):
131132

132133
# both booleans and NaN are instances of Real, so a) checking for Real
133134
# checks for the possibility of a boolean also, and b) we have to check
134-
# separately for NaN
135-
if not isinstance(rate, Real) or math.isnan(rate):
135+
# separately for NaN and Decimal does not derive from Real so need to check that too
136+
if not isinstance(rate, (Real, Decimal)) or math.isnan(rate):
136137
logger.warning(
137138
"[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(
138139
rate=rate, type=type(rate)

0 commit comments

Comments
 (0)