Skip to content

Commit c58f98f

Browse files
authored
fix: On fatal error callback (#1426)
* fix: On fatal error callback * feat: Export default integrations * fix: Use defaultIntegrations
1 parent a0ebb3c commit c58f98f

File tree

5 files changed

+29
-15
lines changed

5 files changed

+29
-15
lines changed

packages/browser/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export { getHubFromCarrier, getDefaultHub, Hub, Scope } from '@sentry/hub';
2525

2626
export { BrowserBackend, BrowserOptions } from './backend';
2727
export { BrowserClient } from './client';
28-
export { init } from './sdk';
28+
export { defaultIntegrations, init } from './sdk';
2929

3030
import * as Integrations from './integrations';
3131
import * as Transports from './transports';

packages/browser/src/sdk.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ import {
99
TryCatch,
1010
} from './integrations';
1111

12+
export const defaultIntegrations = [
13+
new Breadcrumbs(),
14+
new FunctionToString(),
15+
new OnError(),
16+
new OnUnhandledRejection(),
17+
new TryCatch(),
18+
];
19+
1220
/**
1321
* The Sentry Browser SDK Client.
1422
*
@@ -53,11 +61,5 @@ import {
5361
* @see BrowserOptions for documentation on configuration options.
5462
*/
5563
export function init(options: BrowserOptions): void {
56-
initAndBind(BrowserClient, options, [
57-
new OnError(),
58-
new OnUnhandledRejection(),
59-
new FunctionToString(),
60-
new TryCatch(),
61-
new Breadcrumbs(),
62-
]);
64+
initAndBind(BrowserClient, options, defaultIntegrations);
6365
}

packages/node/src/backend.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ export class NodeBackend implements Backend {
8080
if (callback && (callback as FunctionExt).__SENTRY_CAPTURE__) {
8181
callback(normalizeEvent(event));
8282
} else {
83+
// This "if" needs to be here in order for raven-node to propergate
84+
// internal callbacks like in makeErrorHandler -> captureException
85+
// correctly. Also the setTimeout is a dirty hack because in case of a
86+
// fatal error, raven-node exits the process and our consturct of
87+
// hub -> client doesn't have enough time to send the event.
88+
if (callback) {
89+
setTimeout(() => {
90+
callback(event);
91+
}, 1000);
92+
}
8393
captureEvent(normalizeEvent(event));
8494
}
8595
};

packages/node/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export { getHubFromCarrier, Hub, Scope } from '@sentry/hub';
2626
export { getDefaultHub } from './hub';
2727
export { NodeBackend, NodeOptions } from './backend';
2828
export { NodeClient } from './client';
29-
export { init } from './sdk';
29+
export { defaultIntegrations, init } from './sdk';
3030

3131
import * as Integrations from './integrations';
3232
import * as Transports from './transports';

packages/node/src/sdk.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ import {
88
OnUnhandledRejection,
99
} from './integrations';
1010

11+
export const defaultIntegrations = [
12+
new Console(),
13+
new Http(),
14+
new OnUncaughtException(),
15+
new OnUnhandledRejection(),
16+
];
17+
1118
/**
1219
* The Sentry Node SDK Client.
1320
*
@@ -53,10 +60,5 @@ import {
5360
* @see NodeOptions for documentation on configuration options.
5461
*/
5562
export function init(options: NodeOptions): void {
56-
initAndBind(NodeClient, options, [
57-
new OnUncaughtException(),
58-
new OnUnhandledRejection(),
59-
new Console(),
60-
new Http(),
61-
]);
63+
initAndBind(NodeClient, options, defaultIntegrations);
6264
}

0 commit comments

Comments
 (0)