Skip to content

Commit 4fec973

Browse files
authored
feat: Introduce hub (#1364)
* feat: Introduce hub * feat: Move function from global to hub * feat: Move everything into hub * feat: Rename shim to hub, Move shim global code into new package minimal * feat: Rewrite to use hub/minimal * feat: Fix browser/core for while using hub * feat: Change node to use hub, Create node specific hub * fix: Linter error and wrong imports * ref: Change scope lister to add processor * ref: Rename scope processor to listener * fix: Tests and carrier hub * feat: Configure scope should pass it to the hub
1 parent 89162db commit 4fec973

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+752
-727
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
"workspaces": [
1212
"packages/browser",
1313
"packages/core",
14+
"packages/hub",
15+
"packages/minimal",
1416
"packages/node",
15-
"packages/shim",
1617
"packages/types",
1718
"packages/typescript",
1819
"packages/utils"

packages/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ For each major JavaScript platform, there is a specific high-level SDK that
3030
provides all the tools you need in a single package. Please refer to the README
3131
and instructions of those SDKs for more detailed information:
3232

33-
* [`@sentry/shim`](https://github.com/getsentry/raven-js/tree/master/packages/shim):
33+
* [`@sentry/hub`](https://github.com/getsentry/raven-js/tree/master/packages/hub):
34+
Gobal state managment of SDKs
35+
* [`@sentry/minimal`](https://github.com/getsentry/raven-js/tree/master/packages/minimal):
3436
Minimal SDK for library authors to add Sentry support
3537
* [`@sentry/browser`](https://github.com/getsentry/raven-js/tree/master/packages/browser):
3638
SDK for Browsers, including integrations for React, Angular, Ember, Vue and

packages/browser/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
[![npm dt](https://img.shields.io/npm/dt/@sentry/browser.svg)](https://www.npmjs.com/package/@sentry/browser)
1313

1414
**WARNING:** This SDK is part of an early access preview for the
15-
[next generation](https://github.com/getsentry/raven-js/tree/next#readme) of
16-
Sentry JavaScript SDKs. Public interfaces might change and break backwards
15+
[next generation](https://github.com/getsentry/raven-js/tree/master/packages#readme)
16+
of Sentry JavaScript SDKs. Public interfaces might change and break backwards
1717
compatibility from time to time. We absolutely recommend
1818
[raven-js](https://github.com/getsentry/raven-js) in production!
1919

packages/browser/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.5.4",
44
"description": "Offical Sentry SDK for browsers",
55
"repository": "git://github.com/getsentry/raven-js.git",
6-
"homepage": "https://github.com/getsentry/raven-js/tree/next/packages/browser",
6+
"homepage": "https://github.com/getsentry/raven-js/tree/master/packages/browser",
77
"author": "Sentry",
88
"license": "BSD-3-Clause",
99
"engines": {
@@ -16,7 +16,8 @@
1616
},
1717
"dependencies": {
1818
"@sentry/core": "0.5.4",
19-
"@sentry/shim": "0.5.4",
19+
"@sentry/hub": "0.5.4",
20+
"@sentry/minimal": "0.5.4",
2021
"@sentry/types": "0.5.4"
2122
},
2223
"devDependencies": {
@@ -38,7 +39,6 @@
3839
"rollup-plugin-commonjs": "^9.1.3",
3940
"rollup-plugin-node-resolve": "^3.3.0",
4041
"rollup-plugin-npm": "^2.0.0",
41-
"rollup-plugin-shim": "^1.0.0",
4242
"rollup-plugin-typescript2": "^0.13.0",
4343
"rollup-plugin-uglify": "^3.0.0",
4444
"sinon": "^5.0.3",

packages/browser/rollup.config.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import commonjs from 'rollup-plugin-commonjs';
22
import uglify from 'rollup-plugin-uglify';
33
import resolve from 'rollup-plugin-node-resolve';
44
import typescript from 'rollup-plugin-typescript2';
5-
import shim from 'rollup-plugin-shim';
65

76
export default [
87
{
@@ -13,7 +12,7 @@ export default [
1312
exports: 'named',
1413
interop: false,
1514
},
16-
external: ['@sentry/core', '@sentry/shim'],
15+
external: ['@sentry/core', '@sentry/hub', '@sentry/minimal'],
1716
plugins: [
1817
typescript({
1918
tsconfig: 'tsconfig.build.json',
@@ -48,9 +47,6 @@ export default [
4847
browser: true,
4948
}),
5049
commonjs(),
51-
shim({
52-
domain: `export var active = false;`,
53-
}),
5450
uglify(),
5551
],
5652
},

packages/browser/src/backend.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Backend, Options, SentryError } from '@sentry/core';
2-
import { addBreadcrumb, captureEvent } from '@sentry/shim';
2+
import { addBreadcrumb, captureEvent } from '@sentry/minimal';
33
import { SentryEvent, SentryException } from '@sentry/types';
44
import { Raven, SendMethod } from './raven';
55

packages/browser/src/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ export {
1717
captureException,
1818
captureEvent,
1919
configureScope,
20-
popScope,
21-
pushScope,
22-
withScope,
23-
Scope,
24-
} from '@sentry/shim';
20+
} from '@sentry/minimal';
21+
22+
export { Hub, Scope } from '@sentry/hub';
2523

2624
export { BrowserBackend, BrowserOptions } from './backend';
2725
export { BrowserClient } from './client';

packages/browser/src/integrations/onunhandledrejection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { captureException } from '@sentry/shim';
1+
import { captureException } from '@sentry/minimal';
22
import { Integration } from '@sentry/types';
33

44
/** onunhandledrejection is not standardized, thus not available on Window type */

packages/browser/src/sdk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { initAndBind } from '@sentry/core';
2-
import { getCurrentClient as shimGetCurrentClient } from '@sentry/shim';
2+
import { getCurrentClient as shimGetCurrentClient } from '@sentry/minimal';
33
import { BrowserOptions } from './backend';
44
import { BrowserClient } from './client';
55
import {

packages/browser/test/index.test.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ import {
99
captureException,
1010
captureMessage,
1111
configureScope,
12+
Hub,
1213
init,
13-
popScope,
14-
pushScope,
1514
Scope,
1615
SentryEvent,
1716
} from '../src';
@@ -26,19 +25,19 @@ describe('SentryBrowser', () => {
2625
});
2726

2827
beforeEach(() => {
29-
pushScope();
28+
Hub.getGlobal().pushScope();
3029
});
3130

3231
afterEach(() => {
33-
popScope();
32+
Hub.getGlobal().popScope();
3433
});
3534

3635
describe('getContext() / setContext()', () => {
3736
it('should store/load extra', () => {
3837
configureScope((scope: Scope) => {
3938
scope.setExtra('abc', { def: [1] });
4039
});
41-
expect(global.__SENTRY__.stack[1].scope.extra).to.deep.equal({
40+
expect(global.__SENTRY__.hub.stack[1].scope.extra).to.deep.equal({
4241
abc: { def: [1] },
4342
});
4443
});
@@ -47,7 +46,7 @@ describe('SentryBrowser', () => {
4746
configureScope((scope: Scope) => {
4847
scope.setTag('abc', 'def');
4948
});
50-
expect(global.__SENTRY__.stack[1].scope.tags).to.deep.equal({
49+
expect(global.__SENTRY__.hub.stack[1].scope.tags).to.deep.equal({
5150
abc: 'def',
5251
});
5352
});
@@ -56,7 +55,7 @@ describe('SentryBrowser', () => {
5655
configureScope((scope: Scope) => {
5756
scope.setUser({ id: 'def' });
5857
});
59-
expect(global.__SENTRY__.stack[1].scope.user).to.deep.equal({
58+
expect(global.__SENTRY__.hub.stack[1].scope.user).to.deep.equal({
6059
id: 'def',
6160
});
6261
});
@@ -76,7 +75,7 @@ describe('SentryBrowser', () => {
7675
});
7776

7877
it('should record auto breadcrumbs', done => {
79-
pushScope(
78+
Hub.getGlobal().pushScope(
8079
new BrowserClient({
8180
afterSend: (event: SentryEvent) => {
8281
expect(event.breadcrumbs!).to.have.lengthOf(3);
@@ -98,7 +97,7 @@ describe('SentryBrowser', () => {
9897
addBreadcrumb({ message: 'test2' });
9998

10099
captureMessage('event');
101-
popScope();
100+
Hub.getGlobal().popScope();
102101
});
103102
});
104103

@@ -116,7 +115,7 @@ describe('SentryBrowser', () => {
116115
});
117116

118117
it('should capture an exception', done => {
119-
pushScope(
118+
Hub.getGlobal().pushScope(
120119
new BrowserClient({
121120
afterSend: (event: SentryEvent) => {
122121
expect(event.exception).to.not.be.undefined;
@@ -134,11 +133,11 @@ describe('SentryBrowser', () => {
134133
} catch (e) {
135134
captureException(e);
136135
}
137-
popScope();
136+
Hub.getGlobal().popScope();
138137
});
139138

140139
it('should capture a message', done => {
141-
pushScope(
140+
Hub.getGlobal().pushScope(
142141
new BrowserClient({
143142
afterSend: (event: SentryEvent) => {
144143
expect(event.message).to.equal('test');
@@ -149,11 +148,11 @@ describe('SentryBrowser', () => {
149148
}),
150149
);
151150
captureMessage('test');
152-
popScope();
151+
Hub.getGlobal().popScope();
153152
});
154153

155154
it('should capture an event', done => {
156-
pushScope(
155+
Hub.getGlobal().pushScope(
157156
new BrowserClient({
158157
afterSend: (event: SentryEvent) => {
159158
expect(event.message).to.equal('test');
@@ -164,7 +163,7 @@ describe('SentryBrowser', () => {
164163
}),
165164
);
166165
captureEvent({ message: 'test' });
167-
popScope();
166+
Hub.getGlobal().popScope();
168167
});
169168
});
170169
});

0 commit comments

Comments
 (0)