Skip to content

Commit

Permalink
ref: Dedupe is now optional, Fix integration build
Browse files Browse the repository at this point in the history
  • Loading branch information
HazAT committed Mar 20, 2019
1 parent a4734da commit 93902d6
Show file tree
Hide file tree
Showing 40 changed files with 317 additions and 168 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ since we removed some methods from the public API and removed some classes from
- [all] feat: Prefix all private methods with `_`
- [all] build: Use terser instead of uglify
- [opentracing] feat: Introduce `@sentry/opentracing` providing functions to attach opentracing data to Sentry Events
- **breaking** [core] ref: `Dedupe` Integration is now optional, it is no longer enabled by default.

## 4.6.4

Expand Down
2 changes: 1 addition & 1 deletion dangerfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ export default async () => {

schedule(async () => {
const result = (await promisify(exec)('cd packages/browser; yarn size:check')).stdout;
message(`@sentry/browser gzip'ed minified size: ${result.split('\n')[1]}`);
message(`@sentry/browser bundle gzip'ed minified size: \n${result.split('\n')[2]}\n${result.split('\n')[3]}`);
});
};
1 change: 0 additions & 1 deletion packages/browser/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { BrowserClient, ReportDialogOptions } from './client';
import { Breadcrumbs, GlobalHandlers, LinkedErrors, TryCatch, UserAgent } from './integrations';

export const defaultIntegrations = [
new CoreIntegrations.Dedupe(),
new CoreIntegrations.InboundFilters(),
new CoreIntegrations.FunctionToString(),
new TryCatch(),
Expand Down
9 changes: 0 additions & 9 deletions packages/browser/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,6 @@ describe('SentryBrowser', () => {
captureEvent({ message: 'event' });
});

it('should dedupe an event', async () => {
captureMessage('event222');
captureMessage('event222');

await flush(2000);

expect(beforeSend.calledOnce).to.be.true;
});

it('should not dedupe an event on bound client', async () => {
const localBeforeSend = spy();
getCurrentHub().bindClient(
Expand Down
1 change: 1 addition & 0 deletions packages/browser/test/integration/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ function initSDK() {
Sentry.init({
dsn: 'https://[email protected]/1',
// debug: true,
integrations: [new SentryIntegration.Dedupe()],
attachStacktrace: true,
transport: DummyTransport,
ignoreErrors: ['ignoreErrorTest'],
Expand Down
1 change: 1 addition & 0 deletions packages/browser/test/integration/dedupe.js
1 change: 1 addition & 0 deletions packages/browser/test/integration/dedupe.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/browser/test/integration/frame.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<title></title>
<script src="polyfills/es6-promise-4.2.5.auto.js"></script>
<script src="polyfills/whatwg-fetch-3.0.0.js"></script>
<script src="dedupe.js"></script>
<script src="common.js"></script>
<script src="../../build/bundle.js"></script>
<script src="init.js"></script>
Expand Down
1 change: 1 addition & 0 deletions packages/browser/test/integration/loader-lazy-no.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<title></title>
<script src="polyfills/es6-promise-4.2.5.auto.js"></script>
<script src="polyfills/whatwg-fetch-3.0.0.js"></script>
<script src="dedupe.js"></script>
<script src="common.js"></script>
<script src="../../src/loader.js" data-lazy="no"></script>
</head>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<title></title>
<script src="polyfills/es6-promise-4.2.5.auto.js"></script>
<script src="polyfills/whatwg-fetch-3.0.0.js"></script>
<script src="dedupe.js"></script>
<script src="common.js"></script>
<script src="../../src/loader.js" data-lazy="no"></script>
</head>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<title></title>
<script src="polyfills/es6-promise-4.2.5.auto.js"></script>
<script src="polyfills/whatwg-fetch-3.0.0.js"></script>
<script src="dedupe.js"></script>
<script src="common.js"></script>
<script src="../../src/loader.js"></script>
</head>
Expand Down
1 change: 1 addition & 0 deletions packages/browser/test/integration/loader.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<title></title>
<script src="polyfills/es6-promise-4.2.5.auto.js"></script>
<script src="polyfills/whatwg-fetch-3.0.0.js"></script>
<script src="dedupe.js"></script>
<script src="common.js"></script>
<script src="../../src/loader.js"></script>
</head>
Expand Down
2 changes: 2 additions & 0 deletions packages/browser/test/karma/integration-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ module.exports = [
{ pattern: 'test/integration/init.js', included: false },
{ pattern: 'build/bundle.js', included: false },
{ pattern: 'build/bundle.js.map', included: false },
{ pattern: 'test/integration/dedupe.js', included: false },
{ pattern: 'test/integration/dedupe.js.map', included: false },
'test/integration/test.js',
];
3 changes: 2 additions & 1 deletion packages/core/src/integration.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { addGlobalEventProcessor, getCurrentHub } from '@sentry/hub';
import { Integration, Options } from '@sentry/types';
import { logger } from '@sentry/utils/logger';

Expand Down Expand Up @@ -50,7 +51,7 @@ export function setupIntegration(integration: Integration): void {
if (installedIntegrations.indexOf(getIntegrationName(integration)) !== -1) {
return;
}
integration.setupOnce();
integration.setupOnce(addGlobalEventProcessor, getCurrentHub);
installedIntegrations.push(getIntegrationName(integration));
logger.log(`Integration installed: ${getIntegrationName(integration)}`);
}
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/integrations/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { Dedupe } from './dedupe';
export { FunctionToString } from './functiontostring';
export { InboundFilters } from './inboundfilters';
2 changes: 1 addition & 1 deletion packages/core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "./tsconfig.build.json",
"include": ["src/**/*.ts", "test/**/*.ts"],
"include": ["src/**/*.ts", "test/**/*.ts", "../integrations/test/dedupe.test.ts"],
"exclude": ["dist"],
"compilerOptions": {
"rootDir": ".",
Expand Down
86 changes: 20 additions & 66 deletions packages/hub/src/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Client,
Event,
EventHint,
Hub as HubInterface,
Integration,
IntegrationClass,
Severity,
Expand Down Expand Up @@ -49,7 +50,7 @@ const MAX_BREADCRUMBS = 100;
* Internal class used to make sure we always have the latest internal functions
* working in case we have a version conflict.
*/
export class Hub {
export class Hub implements HubInterface {
/** Is a {@link Layer}[] containing the client and scope */
private readonly _stack: Layer[] = [];

Expand Down Expand Up @@ -82,35 +83,22 @@ export class Hub {
}

/**
* Checks if this hub's version is older than the given version.
*
* @param version A version number to compare to.
* @return True if the given version is newer; otherwise false.
*
* @hidden
* @inheritdoc
*/
public isOlderThan(version: number): boolean {
return this._version < version;
}

/**
* This binds the given client to the current scope.
* @param client An SDK client (client) instance.
* @inheritdoc
*/
public bindClient(client?: Client): void {
const top = this.getStackTop();
top.client = client;
}

/**
* Create a new scope to store context information.
*
* The scope will be layered on top of the current one. It is isolated, i.e. all
* breadcrumbs and context information added to this scope will be removed once
* the scope ends. Be sure to always remove this scope with {@link this.popScope}
* when the operation finishes or throws.
*
* @returns Scope, the new cloned scope
* @inheritdoc
*/
public pushScope(): Scope {
// We want to clone the content of prev scope
Expand All @@ -125,28 +113,14 @@ export class Hub {
}

/**
* Removes a previously pushed scope from the stack.
*
* This restores the state before the scope was pushed. All breadcrumbs and
* context information added since the last call to {@link this.pushScope} are
* discarded.
* @inheritdoc
*/
public popScope(): boolean {
return this.getStack().pop() !== undefined;
}

/**
* Creates a new scope with and executes the given operation within.
* The scope is automatically removed once the operation
* finishes or throws.
*
* This is essentially a convenience function for:
*
* pushScope();
* callback();
* popScope();
*
* @param callback that will be enclosed into push/popScope.
* @inheritdoc
*/
public withScope(callback: (scope: Scope) => void): void {
const scope = this.pushScope();
Expand All @@ -157,7 +131,9 @@ export class Hub {
}
}

/** Returns the client of the top stack. */
/**
* @inheritdoc
*/
public getClient(): Client | undefined {
return this.getStackTop().client;
}
Expand All @@ -178,11 +154,7 @@ export class Hub {
}

/**
* Captures an exception event and sends it to Sentry.
*
* @param exception An exception-like object.
* @param hint May contain additional information about the original exception.
* @returns The generated eventId.
* @inheritdoc
*/
public captureException(exception: any, hint?: EventHint): string {
const eventId = (this._lastEventId = uuid4());
Expand All @@ -194,12 +166,7 @@ export class Hub {
}

/**
* Captures a message event and sends it to Sentry.
*
* @param message The message to send to Sentry.
* @param level Define the level of the message.
* @param hint May contain additional information about the original exception.
* @returns The generated eventId.
* @inheritdoc
*/
public captureMessage(message: string, level?: Severity, hint?: EventHint): string {
const eventId = (this._lastEventId = uuid4());
Expand All @@ -211,10 +178,7 @@ export class Hub {
}

/**
* Captures a manually created event and sends it to Sentry.
*
* @param event The event to send to Sentry.
* @param hint May contain additional information about the original exception.
* @inheritdoc
*/
public captureEvent(event: Event, hint?: EventHint): string {
const eventId = (this._lastEventId = uuid4());
Expand All @@ -226,22 +190,14 @@ export class Hub {
}

/**
* This is the getter for lastEventId.
*
* @returns The last event id of a captured event.
* @inheritdoc
*/
public lastEventId(): string | undefined {
return this._lastEventId;
}

/**
* Records a new breadcrumb which will be attached to future events.
*
* Breadcrumbs will be added to subsequent events to provide more context on
* user's actions prior to an error or crash.
*
* @param breadcrumb The breadcrumb to record.
* @param hint May contain additional information about the original breadcrumb.
* @inheritdoc
*/
public addBreadcrumb(breadcrumb: Breadcrumb, hint?: BreadcrumbHint): void {
const top = this.getStackTop();
Expand Down Expand Up @@ -270,9 +226,7 @@ export class Hub {
}

/**
* Callback to set context information onto the scope.
*
* @param callback Callback function that receives Scope.
* @inheritdoc
*/
public configureScope(callback: (scope: Scope) => void): void {
const top = this.getStackTop();
Expand All @@ -283,9 +237,7 @@ export class Hub {
}

/**
* For the duraction of the callback, this hub will be set as the global current Hub.
* This function is useful if you want to run your own client and hook into an already initialized one
* e.g.: Reporting issues to your own sentry when running in your component while still using the users configuration.
* @inheritdoc
*/
public run(callback: (hub: Hub) => void): void {
const oldHub = makeMain(this);
Expand All @@ -296,7 +248,9 @@ export class Hub {
}
}

/** Returns the integration if installed on the current client. */
/**
* @inheritdoc
*/
public getIntegration<T extends Integration>(integration: IntegrationClass<T>): T | null {
const client = this.getClient();
if (!client) {
Expand Down
2 changes: 1 addition & 1 deletion packages/hub/src/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class Scope implements ScopeInterface {
/**
* @inheritdoc
*/
public setLevel(level?: Severity): this {
public setLevel(level: Severity): this {
this._level = normalize(level);
this._notifyScopeListeners();
return this;
Expand Down
3 changes: 0 additions & 3 deletions packages/integrations/.gitignore

This file was deleted.

6 changes: 2 additions & 4 deletions packages/integrations/.npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
*
!*.js.map
!*.d.ts
!*.js
!/dist/**/*
!/build/**/*
!/esm/**/*
jest.config.js
23 changes: 16 additions & 7 deletions packages/integrations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@
"access": "public"
},
"dependencies": {
"@sentry/core": "5.0.0-beta0",
"@sentry/hub": "5.0.0-beta0",
"@sentry/types": "5.0.0-beta0",
"@sentry/utils": "5.0.0-beta0",
"tslib": "^1.9.3"
"@sentry/utils": "5.0.0-beta0"
},
"devDependencies": {
"@types/angular": "^1.6.54",
Expand All @@ -27,12 +24,19 @@
"prettier": "^1.16.4",
"prettier-check": "^2.0.0",
"rimraf": "^2.6.3",
"rollup": "^1.4.0",
"rollup-plugin-commonjs": "^9.2.1",
"rollup-plugin-node-resolve": "^4.0.1",
"rollup-plugin-terser": "^4.0.4",
"rollup-plugin-typescript2": "^0.19.2",
"tslint": "^5.12.1",
"typescript": "^3.3.3"
},
"scripts": {
"build": "tsc -p tsconfig.build.json",
"build": "run-p build:es5 build:bundle",
"build:es5": "tsc -p tsconfig.build.json",
"build:watch": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
"build:bundle": "rollup --config",
"clean": "rimraf dist coverage *.js *.js.map *.d.ts",
"lint": "run-s lint:prettier lint:tslint",
"lint:prettier": "prettier-check \"{src,test}/**/*.ts\"",
Expand All @@ -49,9 +53,14 @@
"transform": {
"^.+\\.ts$": "ts-jest"
},
"moduleFileExtensions": ["js", "ts"],
"moduleFileExtensions": [
"js",
"ts"
],
"testEnvironment": "node",
"testMatch": ["**/*.test.ts"],
"testMatch": [
"**/*.test.ts"
],
"globals": {
"ts-jest": {
"tsConfig": "./tsconfig.json",
Expand Down
Loading

0 comments on commit 93902d6

Please sign in to comment.