Skip to content
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

Improve metadata API in Report/Event #694

Merged
merged 5 commits into from
Sep 9, 2021
Merged

Conversation

imjoehaines
Copy link
Contributor

Goal

This PR adds two new methods to replace the existing add_tab/remove_tabadd_metadata and clear_metadata

The new methods support almost all the use-cases of the old methods, with some additional functionality that matches other notifiers (e.g. @bugsnag/js):

event.add_metadata(:abc, :xyz, 123) # => { abc: { xyz: 123 } }
event.add_metadata(:abc, { x: 1, y: 2, z: 3 }) # => { abc: { xyz: 123, x: 1, y: 2, z: 3 } }

# a value of 'nil' removes the key entirely
event.add_metadata(:abc, :xyz, nil) # => { abc: { x: 1, y: 2, z: 3 } }

# new values will overwrite old ones, 'nil' still removes the key entirely
event.add_metadata(:abc, { x: nil, z: 9 }) # => { abc: { y: 2, z: 9 } }

event.clear_metadata(:abc, :y) # => { abc: { z: 9 } }
event.clear_metadata(:abc) # => {}

The only use-case that add_tab supported that add_metadata doesn't is the automatic "custom" tab. This was created if add_tab was called with a non-Hash value, but is quite a surprising API (e.g. see #587):

event.add_tab(:abc, 123) # => { "custom" => { abc: 123 } }
# is equivalent to:
event.add_metadata("custom", :abc, 123) # => { "custom" => { abc: 123 } }

Design

The implementation uses a MetadataDelegate class internally. This is to allow the new metadata operations to be supported in multiple classes as Configuration will gain support for global metadata in the future

This class handles the various ways metadata can be updated so this
logic can be reused in multiple classes
This will let us re-use them in other tests, to ensure all classes
support every use-case of the metadata delegate
These can be replaced with add/clear metadata
@imjoehaines imjoehaines merged commit d5ae38c into next Sep 9, 2021
@imjoehaines imjoehaines deleted the improve-metadata-api branch September 9, 2021 16:38
@imjoehaines imjoehaines mentioned this pull request Sep 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants