From 8b6e3a375342bb81e72d71922712399f21e5558f Mon Sep 17 00:00:00 2001 From: Arvind Mishra Date: Tue, 11 Oct 2022 11:37:34 +0530 Subject: [PATCH] Fixes #1386 * Fix is_valid_sample_rate to allow check on `Decimal` --- sentry_sdk/tracing_utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sentry_sdk/tracing_utils.py b/sentry_sdk/tracing_utils.py index 61d630321a..3b0965fc88 100644 --- a/sentry_sdk/tracing_utils.py +++ b/sentry_sdk/tracing_utils.py @@ -2,6 +2,7 @@ import contextlib import json import math +from decimal import Decimal from numbers import Real @@ -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) ) )