diff --git a/moesifdjango/app_config.py b/moesifdjango/app_config.py index 6c15935..d9a5aaf 100644 --- a/moesifdjango/app_config.py +++ b/moesifdjango/app_config.py @@ -51,18 +51,23 @@ def get_sampling_percentage(cls, config, user_id, company_id): """Get sampling percentage""" if config is not None: - config_body = json.loads(config.raw_body) + try: + config_body = json.loads(config.raw_body) - user_sample_rate = config_body.get('user_sample_rate', None) + user_sample_rate = config_body.get('user_sample_rate', None) - company_sample_rate = config_body.get('company_sample_rate', None) + company_sample_rate = config_body.get('company_sample_rate', None) - if user_id and user_sample_rate and user_id in user_sample_rate: - return user_sample_rate[user_id] + if user_id and user_sample_rate and user_id in user_sample_rate: + return user_sample_rate[user_id] - if company_id and company_sample_rate and company_id in company_sample_rate: - return company_sample_rate[company_id] + if company_id and company_sample_rate and company_id in company_sample_rate: + return company_sample_rate[company_id] - return config_body.get('sample_rate', 100) - else: - return 100 + return config_body.get('sample_rate', 100) + except Exception as e: + print("Error while parsing user or company sample rate") + print(e) + + # Use default + return 100 diff --git a/setup.py b/setup.py index bd5c915..e39846f 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ # Versions should comply with PEP440. For a discussion on single-sourcing # the version across setup.py and the project code, see # https://packaging.python.org/en/latest/single_source_version.html - version='2.1.5', + version='2.1.6', description='Moesif Middleware for Python Django', long_description=long_description,