-
Notifications
You must be signed in to change notification settings - Fork 27
fix(provider)!: RaygunMessage
object in on_grouping_key
method
#118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fa74eba
e252372
816c2f0
c6efac5
1a936d4
778bdd4
788ca44
7acc55f
ff6317b
3040cc6
b41bfd2
85193c4
0e95048
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
USE_MULTIPROCESSING = False | ||
|
||
import platform | ||
from datetime import datetime | ||
from datetime import datetime, timezone | ||
|
||
from raygun4py import http_utilities | ||
|
||
|
@@ -129,15 +129,30 @@ def set_user(self, user): | |
class RaygunMessage(object): | ||
|
||
def __init__(self): | ||
self.occurredOn = datetime.utcnow() | ||
self.occurredOn = datetime.now(timezone.utc) | ||
self.details = {} | ||
|
||
def __copy__(self): | ||
new_instance = RaygunMessage() | ||
new_instance.details = self.details.copy() | ||
new_instance.occurredOn = self.occurredOn | ||
return new_instance | ||
|
||
def copy(self): | ||
return self.__copy__() | ||
|
||
Comment on lines
+135
to
+143
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Necessary to avoid modifying the original object in pure functions |
||
def get_error(self): | ||
return self.details.get("error") | ||
|
||
def get_details(self): | ||
return self.details | ||
|
||
def set_details(self, details): | ||
self.details = details | ||
|
||
def set_error(self, error): | ||
self.details["error"] = error | ||
|
||
|
||
class RaygunErrorMessage(object): | ||
log = logging.getLogger(__name__) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -295,42 +295,44 @@ def _create_message( | |
) | ||
|
||
def _transform_message(self, message): | ||
message = message.copy() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
message = utilities.ignore_exceptions(self.ignored_exceptions, message) | ||
|
||
if message is not None: | ||
message = utilities.filter_keys(self.filtered_keys, message) | ||
message["details"]["groupingKey"] = utilities.execute_grouping_key( | ||
details = message.get_details() | ||
details = utilities.filter_keys(self.filtered_keys, details) | ||
Comment on lines
+302
to
+303
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pass the |
||
details["groupingKey"] = utilities.execute_grouping_key( | ||
self.grouping_key_callback, message | ||
) | ||
message.set_details(details) | ||
|
||
if self.before_send_callback is not None: | ||
mutated_payload = self.before_send_callback(message["details"]) | ||
mutated_payload = self.before_send_callback(message.get_details()) | ||
|
||
if mutated_payload is not None: | ||
message["details"] = mutated_payload | ||
message.set_details(mutated_payload) | ||
else: | ||
return None | ||
|
||
return message | ||
|
||
def _post(self, raygunMessage): | ||
raygunMessage = raygunMessage.copy() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
options = { | ||
"enforce_payload_size_limit": self.enforce_payload_size_limit, | ||
"log_payload_size_limit_breaches": self.log_payload_size_limit_breaches, | ||
} | ||
|
||
if ( | ||
isinstance(raygunMessage["details"]["error"], raygunmsgs.RaygunErrorMessage) | ||
isinstance(raygunMessage.get_error(), raygunmsgs.RaygunErrorMessage) | ||
and "enforce_payload_size_limit" in options | ||
and options["enforce_payload_size_limit"] is True | ||
): | ||
error = jsonpickle.loads( | ||
jsonpickle.dumps(raygunMessage["details"]["error"]) | ||
) | ||
error = jsonpickle.loads(jsonpickle.dumps(raygunMessage.get_error())) | ||
|
||
error.check_and_modify_payload_size(options) | ||
|
||
raygunMessage["details"]["error"] = error | ||
raygunMessage.set_error(error) | ||
|
||
json = jsonpickle.encode(raygunMessage, unpicklable=False) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
import re | ||
|
||
from raygun4py import raygunmsgs | ||
|
||
|
||
def ignore_exceptions(ignored_exceptions, message): | ||
classname = message.get_error().get_classname() | ||
|
@@ -11,11 +9,18 @@ def ignore_exceptions(ignored_exceptions, message): | |
return message | ||
|
||
|
||
def filter_keys(filtered_keys, object): | ||
iteration_target = object | ||
def filter_keys(filtered_keys, obj): | ||
miquelbeltran marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Filter keys from a dictionary. | ||
|
||
Parameters: | ||
filtered_keys (list): A list of keys to filter. | ||
obj (dict): The dictionary to filter. | ||
|
||
if isinstance(object, raygunmsgs.RaygunMessage): | ||
iteration_target = object.__dict__ | ||
Comment on lines
-17
to
-18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
Returns: | ||
dict: The filtered dictionary. | ||
""" | ||
iteration_target = dict(obj) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make a copy to avoid modifying the original object |
||
|
||
for key in iter(iteration_target.keys()): | ||
if isinstance(iteration_target[key], dict): | ||
|
Uh oh!
There was an error while loading. Please reload this page.