Add the ability to store metadata globally #699
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Goal
This PR adds the ability to store metadata globally, which will then be attached to any future events. The API matches the new event metadata API added in #694, for example:
Metadata can also be added/cleared outside of a
configure
block withBugsnag.add_metadata
andBugsnag.clear_metadata
Global metadata is deeply cloned when attached to an event, which means mutating the event's metadata won't affect the global metadata:
Design
The deep cloning is handled by a new
Bugsnag::Utility::Duplicator
class. The existing Gems I found were either unmaintained, monkey patched core objects or didn't support all of our supported Ruby versionsWhile this should be pretty thorough, it's possible for some values not to be duplicated. I think this is unlikely to be a problem given that types of values that will realistically be used in metadata, since it has to serialise to JSON in the end
The alternative to adding this class is using the
Marshal.load(Marshal.dump(object))
trick, but this has a few drawbacks: