-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'tim/sentry' into 'master'
feat: Add Sentry tags with Tanker info on outbound exceptions See merge request TankerHQ/sdk-js!1002
- Loading branch information
Showing
17 changed files
with
282 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type { Breadcrumb, Hub } from '@sentry/types'; | ||
|
||
export const BREADCRUMB_LIMIT = 20; | ||
|
||
export class SentryLimiter { | ||
breadcrumbs: Array<Breadcrumb>; | ||
sentryHub: Hub; | ||
|
||
constructor(sentryHub: Hub) { | ||
this.breadcrumbs = []; | ||
this.sentryHub = sentryHub; | ||
} | ||
|
||
addBreadcrumb = (breadcrumb: Breadcrumb) => { | ||
if (this.breadcrumbs.length == BREADCRUMB_LIMIT) | ||
this.breadcrumbs.shift(); | ||
|
||
this.breadcrumbs.push({ | ||
timestamp: Math.floor(Date.now() / 1000), | ||
...breadcrumb, | ||
}); | ||
}; | ||
|
||
flush = () => { | ||
for (const breadcrumb of this.breadcrumbs) | ||
this.sentryHub.addBreadcrumb(breadcrumb, undefined); | ||
this.breadcrumbs = []; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { expect } from '@tanker/test-utils'; | ||
import { BREADCRUMB_LIMIT, SentryLimiter } from '../SentryLimiter'; | ||
import type { Breadcrumb } from '@sentry/types'; | ||
|
||
describe('SentryLimiter', () => { | ||
it('adds timestamp on breadcrumbs', async () => { | ||
// @ts-expect-error Not using a real Hub object | ||
const limiter = new SentryLimiter({ | ||
addBreadcrumb: (breadcrumb: Breadcrumb) => { | ||
expect(breadcrumb.timestamp).to.be.a('number'); | ||
expect(breadcrumb.message).to.equal('plop'); | ||
}, | ||
}); | ||
|
||
limiter.addBreadcrumb({ | ||
message: 'plop', | ||
// no timestamp | ||
}); | ||
}); | ||
|
||
it('only keeps the last BREADCRUMB_LIMIT breadcrumbs', async () => { | ||
let result: Array<Breadcrumb> = []; | ||
// @ts-expect-error Not using a real Hub object | ||
const limiter = new SentryLimiter({ | ||
addBreadcrumb: (b: Breadcrumb) => result.push(b), | ||
}); | ||
|
||
const NUM_TO_DROP = 10; | ||
for (let i = 0; i < BREADCRUMB_LIMIT + NUM_TO_DROP; i += 1) { | ||
limiter.addBreadcrumb({ | ||
level: 'info', | ||
message: `${i}`, | ||
}); | ||
} | ||
expect(result.length).to.equal(0); | ||
|
||
limiter.flush(); | ||
expect(result.length).to.equal(BREADCRUMB_LIMIT); | ||
result.forEach((b, idx) => { | ||
expect(b.level).to.equal('info'); | ||
expect(b.message).to.equal(`${NUM_TO_DROP + idx}`); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.