Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fc91338

Browse files
Merge pull request bugsnag#787 from bugsnag/v7-top-level-metadata
V7: allow top level metadata
2 parents 77ab4de + 23e3a02 commit fc91338

File tree

5 files changed

+34
-10
lines changed

5 files changed

+34
-10
lines changed

‎UPGRADING.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,15 @@ 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:
241+
242+
```js
243+
- bugsnagClient.metaData.assetUrl = config.assetUrl
244+
+ Bugsnag.addMetadata(null, 'assetUrl', config.assetUrl)
245+
```
246+
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+
240249
#### Context
241250

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

‎packages/core/lib/metadata-delegate.js‎

Lines changed: 9 additions & 6 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) return
4+
if (!section&&section!==null) return
55
let updates
66

77
// addMetadata("section", null) -> clears section
@@ -14,11 +14,14 @@ 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-
// 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)
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+
}
2225
}
2326

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

‎packages/core/test/client.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,18 @@ describe('@bugsnag/core/client', () => {
639639
expect(client.getMetadata('a', 'b')).toBe(undefined)
640640
client.clearMetadata('a')
641641
expect(client.getMetadata('a')).toBe(undefined)
642+
643+
// check that top-level metadata can be added with section=null
644+
client.addMetadata(null, 'top', 'val')
645+
expect(client._metadata).toEqual({ top: 'val' })
646+
client.addMetadata('top', 'key', 'val')
647+
expect(client._metadata).toEqual({ top: { key: 'val' } })
648+
649+
client._metadata = {}
650+
651+
client.addMetadata('replace', 'key', 'origval')
652+
client.addMetadata(null, 'replace', { diffkey: 'replaceval' })
653+
expect(client._metadata).toEqual({ replace: { diffkey: 'replaceval' } })
642654
})
643655

644656
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, values: { [key: string]: any }): void;
38-
public addMetadata(section: string, key: string, value: any): void;
37+
public addMetadata(section: string|null, values: { [key: string]: any }): void;
38+
public addMetadata(section: string|null, 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, values: { [key: string]: any }): void;
42-
public addMetadata(section: string, key: string, value: any): void;
41+
public addMetadata(section: string|null, values: { [key: string]: any }): void;
42+
public addMetadata(section: string|null, 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)

AltStyle によって変換されたページ (->オリジナル) /