From 000ab1262b54ff622d2b43dae34940ec21bf47ce Mon Sep 17 00:00:00 2001 From: Jeremy Date: Mon, 28 Feb 2022 13:44:17 +1300 Subject: [PATCH] Add set_customdata to RaygunSender, apply process level custom data when building messages --- python2/raygun4py/raygunmsgs.py | 4 +++- python2/raygun4py/raygunprovider.py | 8 +++++++- python3/raygun4py/raygunmsgs.py | 4 +++- python3/raygun4py/raygunprovider.py | 6 ++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/python2/raygun4py/raygunmsgs.py b/python2/raygun4py/raygunmsgs.py index a36dca4..779fa9c 100644 --- a/python2/raygun4py/raygunmsgs.py +++ b/python2/raygun4py/raygunmsgs.py @@ -86,7 +86,9 @@ def set_client_details(self): def set_customdata(self, user_custom_data): if type(user_custom_data) is dict: - self.raygunMessage.details['userCustomData'] = user_custom_data + if not self.raygunMessage.details.get('userCustomData'): + self.raygunMessage.details['userCustomData'] = dict() + self.raygunMessage.details['userCustomData'].update(user_custom_data) return self def set_tags(self, tags): diff --git a/python2/raygun4py/raygunprovider.py b/python2/raygun4py/raygunprovider.py index 9d60d1b..d70ce48 100644 --- a/python2/raygun4py/raygunprovider.py +++ b/python2/raygun4py/raygunprovider.py @@ -34,7 +34,8 @@ class RaygunSender: endpointhost = 'api.raygun.io' endpointpath = '/entries' process_tags = [] - + process_custom_data = dict() + def __init__(self, api_key, config=None): if (api_key): self.api_key = api_key @@ -64,6 +65,10 @@ def set_tags(self, tags): if type(tags) is list: self.process_tags = tags + def set_customdata(self, custom_data): + if type(custom_data) is dict: + self.process_custom_data = custom_data + def ignore_exceptions(self, exceptions): if isinstance(exceptions, list): self.ignored_exceptions = exceptions @@ -141,6 +146,7 @@ def _create_message(self, raygunExceptionMessage, tags, user_custom_data, http_r .set_environment_details(extra_environment_data) \ .set_tags(self.process_tags) \ .set_tags(tags) \ + .set_customdata(self.process_custom_data) \ .set_customdata(user_custom_data) \ .set_request_details(http_request) \ .set_user(user_override if user_override else self.user) \ diff --git a/python3/raygun4py/raygunmsgs.py b/python3/raygun4py/raygunmsgs.py index 2cbe610..86db5ee 100644 --- a/python3/raygun4py/raygunmsgs.py +++ b/python3/raygun4py/raygunmsgs.py @@ -86,7 +86,9 @@ def set_client_details(self): def set_customdata(self, user_custom_data): if type(user_custom_data) is dict: - self.raygunMessage.details['userCustomData'] = user_custom_data + if not self.raygunMessage.details.get('userCustomData'): + self.raygunMessage.details['userCustomData'] = dict() + self.raygunMessage.details['userCustomData'].update(user_custom_data) return self def set_tags(self, tags): diff --git a/python3/raygun4py/raygunprovider.py b/python3/raygun4py/raygunprovider.py index b01acdc..510473e 100644 --- a/python3/raygun4py/raygunprovider.py +++ b/python3/raygun4py/raygunprovider.py @@ -30,6 +30,7 @@ class RaygunSender: endpointhost = 'api.raygun.io' endpointpath = '/entries' process_tags = [] + process_custom_data = dict() def __init__(self, api_key, config={}): if (api_key): @@ -60,6 +61,10 @@ def set_tags(self, tags): if type(tags) is list: self.process_tags = tags + def set_customdata(self, custom_data): + if type(custom_data) is dict: + self.process_custom_data = custom_data + def ignore_exceptions(self, exceptions): if isinstance(exceptions, list): self.ignored_exceptions = exceptions @@ -131,6 +136,7 @@ def _create_message(self, raygunExceptionMessage, tags, user_custom_data, http_r .set_environment_details(extra_environment_data) \ .set_tags(self.process_tags) \ .set_tags(tags) \ + .set_customdata(self.process_custom_data) \ .set_customdata(user_custom_data) \ .set_request_details(http_request) \ .set_user(user_override if user_override else self.user) \