Skip to content

feat: Expose withScope #1536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ lerna-debug.log
.Trashes

.rpt2_cache

docs
59 changes: 22 additions & 37 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,60 +15,45 @@ cache:

matrix:
include:
- name: "@sentry/packages - lint"
node_js: "8"
- name: '@sentry/packages - lint'
node_js: '8'
script: .travis/lint.sh
- name: "@sentry/packages - build and test [node v6]"
node_js: "6"
- name: '@sentry/packages - build and test [node v6]'
node_js: '6'
script: .travis/test.sh
- name: "@sentry/packages - build and test [node v7]"
node_js: "7"
- name: '@sentry/packages - build and test [node v8]'
node_js: '8'
script: .travis/test.sh
- name: "@sentry/packages - build and test [node v8]"
node_js: "8"
- name: '@sentry/packages - build and test [node v10]'
node_js: '10'
script: .travis/test.sh
- name: "@sentry/packages - build and test [node v9]"
node_js: "9"
script: .travis/test.sh
- name: "@sentry/packages - build and test [node v10]"
node_js: "10"
script: .travis/test.sh
- name: "@sentry/browser - integration tests"
node_js: "8"
- name: '@sentry/browser - integration tests'
node_js: '8'
addons:
chrome: stable
firefox: latest
sauce_connect: true
script: .travis/integration.sh
- name: "raven-js - unit and integration tests"
node_js: "8"
- name: 'raven-js - unit and integration tests'
node_js: '8'
addons:
chrome: stable
firefox: latest
script: .travis/raven-js.sh
- name: "raven-js - saucelabs tests"
node_js: "8"
- name: 'raven-js - saucelabs tests'
node_js: '8'
addons:
sauce_connect: true
script: .travis/raven-js-saucelabs.sh
- name: "raven-node [node v4]"
node_js: "4"
script: .travis/raven-node.sh
- name: "raven-node [node v5]"
node_js: "5"
script: .travis/raven-node.sh
- name: "raven-node [node v6]"
node_js: "6"
script: .travis/raven-node.sh
- name: "raven-node [node v7]"
node_js: "7"
- name: 'raven-node [node v4]'
node_js: '4'
script: .travis/raven-node.sh
- name: "raven-node [node v8]"
node_js: "8"
- name: 'raven-node [node v6]'
node_js: '6'
script: .travis/raven-node.sh
- name: "raven-node [node v9]"
node_js: "9"
- name: 'raven-node [node v8]'
node_js: '8'
script: .travis/raven-node.sh
- name: "raven-node [node v10]"
node_js: "10"
- name: 'raven-node [node v10]'
node_js: '10'
script: .travis/raven-node.sh
2 changes: 0 additions & 2 deletions packages/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
},
"dependencies": {
"@sentry/core": "4.0.0-rc.2",
"@sentry/hub": "4.0.0-rc.2",
"@sentry/minimal": "4.0.0-rc.2",
"@sentry/types": "4.0.0-rc.2",
"@sentry/utils": "4.0.0-rc.2",
"md5": "2.2.1"
Expand Down
15 changes: 12 additions & 3 deletions packages/browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,18 @@ export {
User,
} from '@sentry/types';

export { addBreadcrumb, captureMessage, captureException, captureEvent, configureScope } from '@sentry/minimal';

export { getHubFromCarrier, getCurrentHub, Hub, Scope } from '@sentry/hub';
export {
addBreadcrumb,
captureException,
captureEvent,
captureMessage,
configureScope,
withScope,
getHubFromCarrier,
getCurrentHub,
Hub,
Scope,
} from '@sentry/core';

export { BrowserBackend, BrowserOptions } from './backend';
export { BrowserClient } from './client';
Expand Down
3 changes: 1 addition & 2 deletions packages/browser/src/integrations/breadcrumbs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { API, logger } from '@sentry/core';
import { getCurrentHub } from '@sentry/hub';
import { API, getCurrentHub, logger } from '@sentry/core';
import { Integration, Severity } from '@sentry/types';
import { isFunction, isString } from '@sentry/utils/is';
import { getGlobalObject, parseUrl } from '@sentry/utils/misc';
Expand Down
5 changes: 2 additions & 3 deletions packages/browser/src/integrations/dedupe.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { logger } from '@sentry/core';
import { getCurrentHub, Scope } from '@sentry/hub';
import { configureScope, logger } from '@sentry/core';
import { Integration, SentryEvent, SentryException, StackFrame } from '@sentry/types';

/** Deduplication filter */
Expand All @@ -18,7 +17,7 @@ export class Dedupe implements Integration {
* @inheritDoc
*/
public install(): void {
getCurrentHub().configureScope((scope: Scope) => {
configureScope(scope => {
scope.addEventProcessor(async (currentEvent: SentryEvent) => {
// Juuust in case something goes wrong
try {
Expand Down
3 changes: 1 addition & 2 deletions packages/browser/src/integrations/globalhandlers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { logger } from '@sentry/core';
import { getCurrentHub } from '@sentry/hub';
import { getCurrentHub, logger } from '@sentry/core';
import { Integration, SentryEvent } from '@sentry/types';
import { eventFromStacktrace } from '../parsers';
import {
Expand Down
20 changes: 9 additions & 11 deletions packages/browser/src/integrations/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCurrentHub, Scope } from '@sentry/hub';
import { getCurrentHub, withScope } from '@sentry/core';
import { Mechanism, SentryEvent, SentryWrappedFunction } from '@sentry/types';
import { isFunction } from '@sentry/utils/is';
import { htmlTreeAsString } from '@sentry/utils/misc';
Expand Down Expand Up @@ -65,18 +65,16 @@ export function wrap(
} catch (ex) {
ignoreNextOnError();

getCurrentHub().withScope(async () => {
getCurrentHub().configureScope((scope: Scope) => {
scope.addEventProcessor(async (event: SentryEvent) => {
const processedEvent = { ...event };
withScope(async scope => {
scope.addEventProcessor(async (event: SentryEvent) => {
const processedEvent = { ...event };

if (options.mechanism) {
processedEvent.exception = processedEvent.exception || {};
processedEvent.exception.mechanism = options.mechanism;
}
if (options.mechanism) {
processedEvent.exception = processedEvent.exception || {};
processedEvent.exception.mechanism = options.mechanism;
}

return processedEvent;
});
return processedEvent;
});

getCurrentHub().captureException(ex, { originalException: ex });
Expand Down
5 changes: 2 additions & 3 deletions packages/browser/src/integrations/inboundfilters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { logger } from '@sentry/core';
import { getCurrentHub, Scope } from '@sentry/hub';
import { configureScope, logger } from '@sentry/core';
import { Integration, SentryEvent } from '@sentry/types';
import { isRegExp } from '@sentry/utils/is';
import { BrowserOptions } from '../backend';
Expand Down Expand Up @@ -27,7 +26,7 @@ export class InboundFilters implements Integration {
public install(options: BrowserOptions = {}): void {
this.configureOptions(options);

getCurrentHub().configureScope((scope: Scope) => {
configureScope(scope => {
scope.addEventProcessor(async (event: SentryEvent) => {
if (this.shouldDropEvent(event)) {
return null;
Expand Down
6 changes: 2 additions & 4 deletions packages/browser/src/integrations/linkederrors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCurrentHub } from '@sentry/hub';
import { configureScope } from '@sentry/core';
import { Integration, SentryEvent, SentryEventHint, SentryException } from '@sentry/types';
import { exceptionFromStacktrace } from '../parsers';
import { computeStackTrace } from '../tracekit';
Expand Down Expand Up @@ -42,9 +42,7 @@ export class LinkedErrors implements Integration {
* @inheritDoc
*/
public install(): void {
getCurrentHub().configureScope(scope => {
scope.addEventProcessor(this.handler.bind(this));
});
configureScope(scope => scope.addEventProcessor(this.handler.bind(this)));
}

/**
Expand Down
28 changes: 9 additions & 19 deletions packages/browser/src/integrations/pluggable/ember.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCurrentHub, Scope } from '@sentry/hub';
import { captureMessage, getCurrentHub, Scope, withScope } from '@sentry/core';
import { Integration, SentryEvent } from '@sentry/types';
import { getGlobalObject } from '@sentry/utils/misc';

Expand Down Expand Up @@ -36,10 +36,8 @@ export class Ember implements Integration {
const oldOnError = this.Ember.onerror;

this.Ember.onerror = (error: Error): void => {
getCurrentHub().withScope(() => {
getCurrentHub().configureScope((scope: Scope) => {
this.addIntegrationToSdkInfo(scope);
});
withScope(scope => {
this.addIntegrationToSdkInfo(scope);
getCurrentHub().captureException(error, { originalException: error });
});

Expand All @@ -51,24 +49,16 @@ export class Ember implements Integration {
this.Ember.RSVP.on(
'error',
(reason: any): void => {
getCurrentHub().pushScope();

const scope = getCurrentHub().pushScope();
if (reason instanceof Error) {
getCurrentHub().configureScope((scope: Scope) => {
scope.setExtra('context', 'Unhandled Promise error detected');
this.addIntegrationToSdkInfo(scope);
});

scope.setExtra('context', 'Unhandled Promise error detected');
this.addIntegrationToSdkInfo(scope);
getCurrentHub().captureException(reason, { originalException: reason });
} else {
getCurrentHub().configureScope((scope: Scope) => {
scope.setExtra('reason', reason);
this.addIntegrationToSdkInfo(scope);
});

getCurrentHub().captureMessage('Unhandled Promise error detected');
scope.setExtra('reason', reason);
this.addIntegrationToSdkInfo(scope);
captureMessage('Unhandled Promise error detected');
}

getCurrentHub().popScope();
},
);
Expand Down
30 changes: 14 additions & 16 deletions packages/browser/src/integrations/pluggable/vue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCurrentHub, Scope } from '@sentry/hub';
import { getCurrentHub, withScope } from '@sentry/core';
import { Integration, SentryEvent } from '@sentry/types';
import { isPlainObject, isUndefined } from '@sentry/utils/is';
import { getGlobalObject } from '@sentry/utils/misc';
Expand Down Expand Up @@ -70,22 +70,20 @@ export class Vue implements Integration {
metadata.lifecycleHook = info;
}

getCurrentHub().withScope(() => {
getCurrentHub().configureScope((scope: Scope) => {
Object.keys(metadata).forEach(key => {
scope.setExtra(key, metadata[key]);
});
withScope(scope => {
Object.keys(metadata).forEach(key => {
scope.setExtra(key, metadata[key]);
});

scope.addEventProcessor(async (event: SentryEvent) => {
if (event.sdk) {
const integrations = event.sdk.integrations || [];
event.sdk = {
...event.sdk,
integrations: [...integrations, 'vue'],
};
}
return event;
});
scope.addEventProcessor(async (event: SentryEvent) => {
if (event.sdk) {
const integrations = event.sdk.integrations || [];
event.sdk = {
...event.sdk,
integrations: [...integrations, 'vue'],
};
}
return event;
});

getCurrentHub().captureException(error, { originalException: error });
Expand Down
14 changes: 5 additions & 9 deletions packages/browser/src/integrations/reportingobserver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCurrentHub, Scope } from '@sentry/hub';
import { captureMessage, withScope } from '@sentry/core';
import { Integration } from '@sentry/types';
import { getGlobalObject } from '@sentry/utils/misc';
import { supportsReportingObserver } from '@sentry/utils/supports';
Expand Down Expand Up @@ -93,10 +93,8 @@ export class ReportingObserver implements Integration {
*/
public handler(reports: Report[]): void {
for (const report of reports) {
getCurrentHub().withScope(() => {
getCurrentHub().configureScope((scope: Scope) => {
scope.setExtra('url', report.url);
});
withScope(scope => {
scope.setExtra('url', report.url);

const label = `ReportingObserver [${report.type}]`;
let details = 'No details available';
Expand All @@ -112,9 +110,7 @@ export class ReportingObserver implements Integration {
plainBody[prop] = report.body[prop];
}

getCurrentHub().configureScope((scope: Scope) => {
scope.setExtra('body', plainBody);
});
scope.setExtra('body', plainBody);

if (report.type === ReportTypes.Crash) {
const body = report.body as CrashReportBody;
Expand All @@ -125,7 +121,7 @@ export class ReportingObserver implements Integration {
}
}

getCurrentHub().captureMessage(`${label}: ${details}`);
captureMessage(`${label}: ${details}`);
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/integrations/sdkinformation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCurrentHub, Scope } from '@sentry/hub';
import { configureScope } from '@sentry/core';
import { Integration, SentryEvent } from '@sentry/types';
import { SDK_NAME, SDK_VERSION } from '../version';

Expand All @@ -13,7 +13,7 @@ export class SDKInformation implements Integration {
* @inheritDoc
*/
public install(): void {
getCurrentHub().configureScope((scope: Scope) => {
configureScope(scope => {
scope.addEventProcessor(async (event: SentryEvent) => ({
...event,
sdk: {
Expand Down
3 changes: 1 addition & 2 deletions packages/browser/src/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { initAndBind } from '@sentry/core';
import { getCurrentHub } from '@sentry/hub';
import { getCurrentHub, initAndBind } from '@sentry/core';
import { DsnLike } from '@sentry/types';
import { BrowserOptions } from './backend';
import { BrowserClient } from './client';
Expand Down
11 changes: 9 additions & 2 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
export { logger } from './logger';
export { captureException, captureMessage, configureScope } from '@sentry/minimal';
export { Hub, Scope } from '@sentry/hub';
export {
addBreadcrumb,
captureException,
captureEvent,
captureMessage,
configureScope,
withScope,
} from '@sentry/minimal';
export { getCurrentHub, Hub, getHubFromCarrier, Scope } from '@sentry/hub';
export { API } from './api';
export { BaseClient } from './baseclient';
export { BackendClass, BaseBackend } from './basebackend';
Expand Down
Loading