Skip to content

Commit 08555ed

Browse files
authored
Merge pull request bugsnag#799 from bugsnag/v7-revert-top-level-metadata
V7: revert top level metadata
2 parents d938f37 + 08022ba commit 08555ed

File tree

5 files changed

+14
-31
lines changed

5 files changed

+14
-31
lines changed

UPGRADING.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,13 @@ It remains possible to supply initial metadata in configuration:
237237
})
238238
```
239239

240-
All metadata is now required to have a section. If you were previously supplying metadata without a section name (this would display on your dashboard under the "Custom" tab), we have enabled passing `null` as the section name for continuity:
240+
Previously, it was possible to add "top-level" metadata, i.e. data that you did not provide a specific `section` name for. In the dashboard, this would display under a tab with the heading "Custom". Since a section name is now required, for continuity both visually and for any custom filters you may have set up based on such data, you should set the section name to `'custom'`:
241241

242-
```js
243-
- bugsnagClient.metaData.assetUrl = config.assetUrl
244-
+ Bugsnag.addMetadata(null, 'assetUrl', config.assetUrl)
242+
```diff
243+
- bugsnagClient.metaData = { processId: 'aa874cbd', role: 'image-resizer' }
244+
+ Bugsnag.addMetadata('custom', { processId: 'aa874cbd', role: 'image-resizer' })
245245
```
246246

247-
You should only use this method if you have a custom filter based on some top-level metadata, otherwise you should supply a section name for your metadata.
248-
249247
#### Context
250248

251249
On the client, context is now managed via `get/setContext()`:

packages/core/lib/metadata-delegate.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const assign = require('./es-utils/assign')
22

33
const add = (state, section, keyOrObj, maybeVal) => {
4-
if (!section && section !== null) return
4+
if (!section) return
55
let updates
66

77
// addMetadata("section", null) -> clears section
@@ -14,14 +14,11 @@ const add = (state, section, keyOrObj, maybeVal) => {
1414
// exit if we don't have an updates object at this point
1515
if (!updates) return
1616

17-
if (section !== null) {
18-
// ensure a section with this name exists
19-
if (!state[section] || typeof state[section] !== 'object') state[section] = {}
20-
// merge the updates with the existing section
21-
state[section] = assign({}, state[section], updates)
22-
} else {
23-
assign(state, updates)
24-
}
17+
// ensure a section with this name exists
18+
if (!state[section]) state[section] = {}
19+
20+
// merge the updates with the existing section
21+
state[section] = assign({}, state[section], updates)
2522
}
2623

2724
const get = (state, section, key) => {

packages/core/test/client.test.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -654,18 +654,6 @@ describe('@bugsnag/core/client', () => {
654654
expect(client.getMetadata('a', 'b')).toBe(undefined)
655655
client.clearMetadata('a')
656656
expect(client.getMetadata('a')).toBe(undefined)
657-
658-
// check that top-level metadata can be added with section=null
659-
client.addMetadata(null, 'top', 'val')
660-
expect(client._metadata).toEqual({ top: 'val' })
661-
client.addMetadata('top', 'key', 'val')
662-
expect(client._metadata).toEqual({ top: { key: 'val' } })
663-
664-
client._metadata = {}
665-
666-
client.addMetadata('replace', 'key', 'origval')
667-
client.addMetadata(null, 'replace', { diffkey: 'replaceval' })
668-
expect(client._metadata).toEqual({ replace: { diffkey: 'replaceval' } })
669657
})
670658

671659
it('can be set in config', () => {

packages/core/types/client.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ declare class Client {
3434
): void;
3535

3636
// metadata
37-
public addMetadata(section: string | null, values: { [key: string]: any }): void;
38-
public addMetadata(section: string | null, key: string, value: any): void;
37+
public addMetadata(section: string, values: { [key: string]: any }): void;
38+
public addMetadata(section: string, key: string, value: any): void;
3939
public getMetadata(section: string, key?: string): any;
4040
public clearMetadata(section: string, key?: string): void;
4141

packages/core/types/event.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ declare class Event {
3838
public setUser(id?: string, email?: string, name?: string): void;
3939

4040
// metadata
41-
public addMetadata(section: string | null, values: { [key: string]: any }): void;
42-
public addMetadata(section: string | null, key: string, value: any): void;
41+
public addMetadata(section: string, values: { [key: string]: any }): void;
42+
public addMetadata(section: string, key: string, value: any): void;
4343
public getMetadata(section: string, key?: string): any;
4444
public clearMetadata(section: string, key?: string): void;
4545
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy