Skip to content

Commit ee57888

Browse files
authored
feat: Browser integrations (#1355)
1 parent 0c2973a commit ee57888

File tree

13 files changed

+822
-3
lines changed

13 files changed

+822
-3
lines changed

packages/browser/karma.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module.exports = function(config) {
1818
tsconfig: 'tsconfig.json',
1919
bundlerOptions: {
2020
sourceMap: true,
21+
transforms: [require('karma-typescript-es6-transform')()],
2122
},
2223
include: ['test/**/*.ts'],
2324
reports: {

packages/browser/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"karma-mocha-reporter": "^2.2.5",
2929
"karma-rollup-preprocessor": "^6.0.0",
3030
"karma-typescript": "^3.0.12",
31+
"karma-typescript-es6-transform": "^1.0.4",
3132
"npm-run-all": "^4.1.2",
3233
"prettier": "^1.12.1",
3334
"prettier-check": "^2.0.0",

packages/browser/src/backend.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export interface BrowserOptions extends Options {
6363
/** The Sentry Browser SDK Backend. */
6464
export class BrowserBackend implements Backend {
6565
/** Creates a new browser backend instance. */
66-
public constructor(private readonly options: BrowserOptions) {}
66+
public constructor(private readonly options: BrowserOptions = {}) {}
6767

6868
/**
6969
* @inheritDoc
@@ -79,7 +79,13 @@ export class BrowserBackend implements Backend {
7979
);
8080
}
8181

82-
Raven.config(dsn, this.options).install();
82+
Raven.config(dsn, this.options);
83+
84+
// We need to leave it here for now, as we are skipping `install` call,
85+
// due to integrations migration
86+
// TODO: Remove it once we fully migrate our code
87+
Raven._isRavenInstalled = true;
88+
Error.stackTraceLimit = Raven._globalOptions.stackTraceLimit;
8389

8490
// Hook into Raven's breadcrumb mechanism. This allows us to intercept both
8591
// breadcrumbs created internally by Raven and pass them to the Client
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Integration } from '@sentry/types';
2+
import { Raven } from '../raven';
3+
4+
/** Default Breadcrumbs instrumentations */
5+
export class Breadcrumbs implements Integration {
6+
/**
7+
* @inheritDoc
8+
*/
9+
public name: string = 'Breadcrumbs';
10+
/**
11+
* @inheritDoc
12+
*/
13+
public install(): void {
14+
Raven._instrumentBreadcrumbs();
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Integration } from '@sentry/types';
2+
import { Raven } from '../raven';
3+
4+
/** Patch toString calls to return proper name for wrapped functions */
5+
export class FunctionToString implements Integration {
6+
/**
7+
* @inheritDoc
8+
*/
9+
public name: string = 'FunctionToString';
10+
/**
11+
* @inheritDoc
12+
*/
13+
public install(): void {
14+
Raven._patchFunctionToString();
15+
}
16+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export { OnUnhandledRejection } from './onunhandledrejection';
2+
export { OnError } from './onerror';
3+
export { FunctionToString } from './functiontostring';
4+
export { TryCatch } from './trycatch';
5+
export { Breadcrumbs } from './breadcrumbs';
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Integration } from '@sentry/types';
2+
import { Raven } from '../raven';
3+
// @ts-ignore
4+
import { TraceKit } from './tracekit';
5+
6+
/** Global OnError handler */
7+
export class OnError implements Integration {
8+
/**
9+
* @inheritDoc
10+
*/
11+
public name: string = 'OnError';
12+
/**
13+
* @inheritDoc
14+
*/
15+
public handler(...args: any[]): void {
16+
Raven._handleOnErrorStackInfo.call(Raven, ...args);
17+
}
18+
/**
19+
* @inheritDoc
20+
*/
21+
public install(): void {
22+
TraceKit.report.subscribe(this.handler.bind(this));
23+
}
24+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { captureException } from '@sentry/shim';
2+
import { Integration } from '@sentry/types';
3+
4+
/** onunhandledrejection is not standardized, thus not available on Window type */
5+
interface PromisifiedWindow extends Window {
6+
onunhandledrejection?(event: PromiseRejectionEvent): void;
7+
}
8+
9+
/** TODO: Change to safe window access, window||global||self||{} */
10+
const _window: PromisifiedWindow = window;
11+
12+
/** Global Promise Rejection handler */
13+
export class OnUnhandledRejection implements Integration {
14+
/**
15+
* @inheritDoc
16+
*/
17+
public name: string = 'OnUnhandledRejection';
18+
/**
19+
* @inheritDoc
20+
*/
21+
public handler(event: PromiseRejectionEvent): void {
22+
captureException(event.reason);
23+
}
24+
/**
25+
* @inheritDoc
26+
*/
27+
public install(): void {
28+
_window.addEventListener('unhandledrejection', this.handler.bind(
29+
this,
30+
) as EventListener);
31+
}
32+
}

0 commit comments

Comments
 (0)