Skip to content

Commit

Permalink
feat: clone event processors (#1433)
Browse files Browse the repository at this point in the history
* release: 4.0.0-beta.7

* fix: Set scope listerns to []

* release: 4.0.0-beta.8

* feat: Clone event processors
  • Loading branch information
HazAT authored Jul 12, 2018
1 parent e0c91f1 commit 7f8f946
Show file tree
Hide file tree
Showing 15 changed files with 391 additions and 249 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"lerna": "2.11.0",
"version": "4.0.0-beta.6",
"version": "4.0.0-beta.8",
"packages": "packages/*",
"ignore": "raven-*",
"npmClient": "yarn",
Expand Down
12 changes: 6 additions & 6 deletions packages/browser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sentry/browser",
"version": "4.0.0-beta.6",
"version": "4.0.0-beta.8",
"description": "Offical Sentry SDK for browsers",
"repository": "git://github.com/getsentry/raven-js.git",
"homepage": "https://github.com/getsentry/raven-js/tree/master/packages/browser",
Expand All @@ -15,11 +15,11 @@
"access": "public"
},
"dependencies": {
"@sentry/core": "4.0.0-beta.6",
"@sentry/hub": "4.0.0-beta.6",
"@sentry/minimal": "4.0.0-beta.6",
"@sentry/types": "4.0.0-beta.6",
"@sentry/utils": "4.0.0-beta.6"
"@sentry/core": "4.0.0-beta.8",
"@sentry/hub": "4.0.0-beta.8",
"@sentry/minimal": "4.0.0-beta.8",
"@sentry/types": "4.0.0-beta.8",
"@sentry/utils": "4.0.0-beta.8"
},
"devDependencies": {
"chai": "^4.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
public getSdkInfo(): SdkInfo {
return {
name: 'sentry-browser',
version: '4.0.0-beta.6',
version: '4.0.0-beta.8',
};
}

Expand Down
10 changes: 5 additions & 5 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sentry/core",
"version": "4.0.0-beta.6",
"version": "4.0.0-beta.8",
"description": "Base implementation for all Sentry JavaScript SDKs",
"repository": "git://github.com/getsentry/raven-js.git",
"homepage": "https://github.com/getsentry/raven-js/tree/master/packages/core",
Expand All @@ -15,10 +15,10 @@
"access": "public"
},
"dependencies": {
"@sentry/hub": "4.0.0-beta.6",
"@sentry/minimal": "4.0.0-beta.6",
"@sentry/types": "4.0.0-beta.6",
"@sentry/utils": "4.0.0-beta.6"
"@sentry/hub": "4.0.0-beta.8",
"@sentry/minimal": "4.0.0-beta.8",
"@sentry/types": "4.0.0-beta.8",
"@sentry/utils": "4.0.0-beta.8"
},
"devDependencies": {
"jest": "^22.4.3",
Expand Down
6 changes: 3 additions & 3 deletions packages/hub/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sentry/hub",
"version": "4.0.0-beta.6",
"version": "4.0.0-beta.8",
"description": "Sentry hub which handles global state managment.",
"repository": "git://github.com/getsentry/raven-js.git",
"homepage": "https://github.com/getsentry/raven-js/tree/master/packages/hub",
Expand All @@ -15,8 +15,8 @@
"access": "public"
},
"dependencies": {
"@sentry/types": "4.0.0-beta.6",
"@sentry/utils": "4.0.0-beta.6"
"@sentry/types": "4.0.0-beta.8",
"@sentry/utils": "4.0.0-beta.8"
},
"devDependencies": {
"jest": "^22.4.3",
Expand Down
7 changes: 6 additions & 1 deletion packages/hub/src/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,16 @@ export class Hub {
}
}

/** Returns the client of the currently active scope. */
/** Returns the client of the top stack. */
public getClient(): any | undefined {
return this.getStackTop().client;
}

/** Returns the scope of the top stack. */
public getScope(): Scope | undefined {
return this.getStackTop().scope;
}

/** Returns the scope stack for domains or the process. */
public getStack(): Layer[] {
return this.stack;
Expand Down
7 changes: 6 additions & 1 deletion packages/hub/src/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ export class Scope {
*/
public static clone(scope?: Scope): Scope {
const newScope = new Scope();
Object.assign(newScope, scope);
Object.assign(newScope, scope, {
scopeListeners: [],
});
if (scope) {
newScope.eventProcessors = [...scope.eventProcessors];
}
return newScope;
}

Expand Down
46 changes: 39 additions & 7 deletions packages/hub/test/lib/hub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const scope = new Scope();
describe('Hub', () => {
afterEach(() => {
jest.resetAllMocks();
jest.useRealTimers();
});

test('push process into stack', () => {
Expand Down Expand Up @@ -49,6 +50,7 @@ describe('Hub', () => {
});

test('invoke client async catch error in case', done => {
const orig = global.console;
// @ts-ignore
global.console = { error: jest.fn() };
const hub = new Hub({
Expand All @@ -59,6 +61,7 @@ describe('Hub', () => {
setTimeout(() => {
// tslint:disable-next-line
expect(console.error).toHaveBeenCalled();
global.console = orig;
done();
});
});
Expand Down Expand Up @@ -248,32 +251,61 @@ describe('Hub', () => {
await localScope.applyToEvent(event);
});

test.only('addEventProcessor async', async done => {
expect.assertions(2);
test('addEventProcessor async', async () => {
expect.assertions(6);
const event: SentryEvent = {
extra: { b: 3 },
};
const localScope = new Scope();
localScope.setExtra('a', 'b');
const hub = new Hub({ a: 'b' }, localScope);
const callCounter = jest.fn();
hub.addEventProcessor(async (processedEvent: SentryEvent) => {
callCounter(1);
expect(processedEvent.extra).toEqual({ a: 'b', b: 3 });
return processedEvent;
});
hub.addEventProcessor(
async (processedEvent: SentryEvent) =>
new Promise<SentryEvent>(resolve => {
setImmediate(() => {
callCounter(2);
setTimeout(() => {
callCounter(3);
processedEvent.dist = '1';
resolve(processedEvent);
});
}, 1);
}),
);
hub.addEventProcessor(async (processedEvent: SentryEvent) => {
expect(processedEvent.dist).toEqual('1');
done();
callCounter(4);
return processedEvent;
});
await localScope.applyToEvent(event);
const final = await localScope.applyToEvent(event);
expect(callCounter.mock.calls[0][0]).toBe(1);
expect(callCounter.mock.calls[1][0]).toBe(2);
expect(callCounter.mock.calls[2][0]).toBe(3);
expect(callCounter.mock.calls[3][0]).toBe(4);
expect(final.dist).toEqual('1');
});

test('pushScope inherit processors', async () => {
const event: SentryEvent = {
extra: { b: 3 },
};
const localScope = new Scope();
localScope.setExtra('a', 'b');
const hub = new Hub({ a: 'b' }, localScope);
const callCounter = jest.fn();
hub.addEventProcessor(async (processedEvent: SentryEvent) => {
callCounter(1);
processedEvent.dist = '1';
return processedEvent;
});
hub.pushScope();
const pushedScope = hub.getStackTop().scope;
if (pushedScope) {
const final = await pushedScope.applyToEvent(event);
expect(final.dist).toEqual('1');
}
});
});
6 changes: 3 additions & 3 deletions packages/minimal/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sentry/minimal",
"version": "4.0.0-beta.6",
"version": "4.0.0-beta.8",
"description": "Sentry minimal library that can be used in other packages",
"repository": "git://github.com/getsentry/raven-js.git",
"homepage": "https://github.com/getsentry/raven-js/tree/master/packages/types",
Expand All @@ -15,8 +15,8 @@
"access": "public"
},
"dependencies": {
"@sentry/hub": "4.0.0-beta.6",
"@sentry/types": "4.0.0-beta.6"
"@sentry/hub": "4.0.0-beta.8",
"@sentry/types": "4.0.0-beta.8"
},
"devDependencies": {
"jest": "^22.4.3",
Expand Down
12 changes: 6 additions & 6 deletions packages/node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sentry/node",
"version": "4.0.0-beta.6",
"version": "4.0.0-beta.8",
"description": "Offical Sentry SDK for Node.js",
"repository": "git://github.com/getsentry/raven-js.git",
"homepage": "https://github.com/getsentry/raven-js/tree/master/packages/node",
Expand All @@ -15,11 +15,11 @@
"access": "public"
},
"dependencies": {
"@sentry/core": "4.0.0-beta.6",
"@sentry/hub": "4.0.0-beta.6",
"@sentry/minimal": "4.0.0-beta.6",
"@sentry/types": "4.0.0-beta.6",
"@sentry/utils": "4.0.0-beta.6",
"@sentry/core": "4.0.0-beta.8",
"@sentry/hub": "4.0.0-beta.8",
"@sentry/minimal": "4.0.0-beta.8",
"@sentry/types": "4.0.0-beta.8",
"@sentry/utils": "4.0.0-beta.8",
"@types/cookie": "0.3.1",
"@types/md5": "2.1.32",
"@types/stack-trace": "0.0.29",
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class NodeClient extends BaseClient<NodeBackend, NodeOptions> {
public getSdkInfo(): SdkInfo {
return {
name: 'sentry-node',
version: '4.0.0-beta.6',
version: '4.0.0-beta.8',
};
}
}
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sentry/types",
"version": "4.0.0-beta.6",
"version": "4.0.0-beta.8",
"description": "Types for all Sentry JavaScript SDKs",
"repository": "git://github.com/getsentry/raven-js.git",
"homepage": "https://github.com/getsentry/raven-js/tree/master/packages/types",
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sentry/typescript",
"version": "4.0.0-beta.6",
"version": "4.0.0-beta.8",
"description": "Typescript configuration used at Sentry",
"repository": "git://github.com/getsentry/raven-js.git",
"homepage": "https://github.com/getsentry/raven-js/tree/master/packages/typescript",
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sentry/utils",
"version": "4.0.0-beta.6",
"version": "4.0.0-beta.8",
"description": "Utilities for all Sentry JavaScript SDKs",
"repository": "git://github.com/getsentry/raven-js.git",
"homepage": "https://github.com/getsentry/raven-js/tree/master/packages/utils",
Expand All @@ -13,7 +13,7 @@
"access": "public"
},
"dependencies": {
"@sentry/types": "4.0.0-beta.6"
"@sentry/types": "4.0.0-beta.8"
},
"devDependencies": {
"chai": "^4.1.2",
Expand Down
Loading

0 comments on commit 7f8f946

Please sign in to comment.