Skip to content

Commit

Permalink
Check for Decimal is in_valid_sample_rate (#1672)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arvind2222 committed Oct 11, 2022
1 parent a48fafd commit 6e0b02b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions sentry_sdk/tracing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import math

from numbers import Real
from decimal import Decimal

import sentry_sdk
from sentry_sdk.consts import OP
Expand Down Expand Up @@ -131,8 +132,8 @@ 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):
# separately for NaN and Decimal does not derive from Real so need to check that too
if not isinstance(rate, (Real, 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(
rate=rate, type=type(rate)
Expand Down

0 comments on commit 6e0b02b

Please sign in to comment.