Skip to content

Commit 7c4743a

Browse files
committed
Made many optimizations to bring down the file size of the library.
1 parent 8f5bab0 commit 7c4743a

37 files changed

+572
-471
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ We will be adding cdn support in the near future.
2525

2626
#### Node.js
2727
Use this method to install exceptionless into your node app.
28-
1. Install the package by running `npm install exceptionless`.
28+
1. Install the package by running `npm install exceptionless --save-dev`.
2929
2. Add the exceptionless client to your app:
3030
```javascript
3131
var client = require('exceptionless').ExceptionlessClient.default;

example/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,9 @@
3636
<button onclick="throwDivisionByZero()">Division By Zero</button>
3737
<button onclick="throwIndexOutOfRange()">Index Out Of Range</button>
3838
<button onclick="throwStringError()">Throw String Message</button>
39+
<button onclick="sendEvents(10)">Send 10 random events</button>
40+
<button onclick="sendEvents(100)">Send 100 random events</button>
41+
<button onclick="sendEvents(100, 0)">Send 100 log messages</button>
42+
<button onclick="sendEvents(100, 1)">Send 100 exceptions</button>
3943
</body>
4044
</html>

example/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,27 @@ function getNonexistentData() {
22
/* random comment */ nonexistentArray[arguments[0]]; // second random comment;
33
}
44

5+
function sendEvents(numberToSends, eventType) {
6+
eventType = eventType || getRandomInt(0, 1);
7+
8+
for (var index = 0; index < numberToSends; index++) {
9+
switch (eventType) {
10+
case 0: {
11+
Exceptionless.ExceptionlessClient.default.submitLog('sendEvents', 'This is a test message', 'info');
12+
break;
13+
}
14+
case 1: {
15+
throwIndexOutOfRange();
16+
break;
17+
}
18+
}
19+
}
20+
}
21+
22+
function getRandomInt(min, max) {
23+
return Math.floor(Math.random() * (max - min + 1)) + min;
24+
}
25+
526
function throwDivisionByZero() {
627
return divide(10, 0);
728
}

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ gulp.task('exceptionless.es5', ['exceptionless.es5.umd'], function() {
6363
.pipe(concat('exceptionless.min.js'))
6464
.pipe(replace('exceptionless-js/1.0.0.0', 'exceptionless-js/' + package.version))
6565
.pipe(replace('require(\'source-map/lib/source-map/source-map-consumer\')', 'null')) // needed for node until source maps dependency is fixed
66-
.pipe(uglify())
66+
.pipe(uglify({ output: { beautify: false }}))
6767
.pipe(sourcemaps.write('.'))
6868
.pipe(gulp.dest('dist'))
6969
});

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"karma-cli": "0.0.4",
3737
"karma-jasmine": "~0.3.5",
3838
"rimraf": "^2.3.3",
39+
"tracekit": "^0.2.0",
3940
"tsproject": "^0.8.10",
4041
"typescript": "1.5.0-beta"
4142
},

src/EventBuilder.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { EventPluginContext } from './plugins/EventPluginContext';
77
import { Utils } from 'Utils';
88

99
export class EventBuilder {
10-
private _validIdentifierErrorMessage:string = "must contain between 8 and 100 alphanumeric or '-' characters.";
10+
private _validIdentifierErrorMessage:string = "must contain between 8 and 100 alphanumeric or '-' characters."; // optimization for minifier.
1111

1212
public target:IEvent;
1313
public client:ExceptionlessClient;
@@ -20,15 +20,15 @@ export class EventBuilder {
2020
}
2121

2222
public setType(type:string): EventBuilder {
23-
if (!!type && type.length > 0) {
23+
if (!!type) {
2424
this.target.type = type;
2525
}
2626

2727
return this;
2828
}
2929

3030
public setSource(source:string): EventBuilder {
31-
if (!!source && source.length > 0) {
31+
if (!!source) {
3232
this.target.source = source;
3333
}
3434

@@ -54,7 +54,7 @@ export class EventBuilder {
5454
}
5555

5656
public setMessage(message:string): EventBuilder {
57-
if (!!message && message.length > 0) {
57+
if (!!message) {
5858
this.target.message = message;
5959
}
6060

@@ -118,7 +118,6 @@ export class EventBuilder {
118118
return this;
119119
}
120120

121-
//todo: rename this
122121
public addRequestInfo(request:Object): EventBuilder {
123122
if (!!request) {
124123
this.pluginContextData['@request'] = request;
@@ -132,7 +131,7 @@ export class EventBuilder {
132131
}
133132

134133
private isValidIdentifier(value:string): boolean {
135-
if (!value || !value.length) {
134+
if (!value) {
136135
return true;
137136
}
138137

src/ExceptionlessClient.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ export class ExceptionlessClient {
1616
constructor(settings:IConfigurationSettings);
1717
constructor(apiKey:string, serverUrl?:string);
1818
constructor(settingsOrApiKey?:IConfigurationSettings|string, serverUrl?:string) {
19-
// TODO: populate this in a plugin..
20-
//var settings = this.getSettingsFromScriptTag() || {};
21-
2219
if (typeof settingsOrApiKey !== 'object') {
2320
this.config = new Configuration(settingsOrApiKey);
2421
} else {
@@ -197,7 +194,18 @@ export class ExceptionlessClient {
197194
return this.config.lastReferenceIdManager.getLast();
198195
}
199196

197+
/**
198+
* The default ExceptionlessClient instance.
199+
* @type {ExceptionlessClient}
200+
* @private
201+
*/
200202
private static _instance:ExceptionlessClient = null;
203+
204+
205+
/**
206+
* The default ExceptionlessClient instance.
207+
* @type {ExceptionlessClient}
208+
*/
201209
public static get default() {
202210
if(ExceptionlessClient._instance === null) {
203211
ExceptionlessClient._instance = new ExceptionlessClient(null);

src/bootstrap/DefaultBootstrapper.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { IBootstrapper } from 'IBootstrapper';
2+
import { Configuration } from '../configuration/Configuration';
3+
import { IConfigurationSettings } from '../configuration/IConfigurationSettings';
4+
import { IError } from '../models/IError';
5+
import { DefaultErrorParser } from '../services/DefaultErrorParser';
6+
import { DefaultModuleCollector } from '../services/DefaultModuleCollector';
7+
import { DefaultRequestInfoCollector } from '../services/DefaultRequestInfoCollector';
8+
import { DefaultSubmissionClient } from '../submission/DefaultSubmissionClient';
9+
import { ExceptionlessClient } from '../ExceptionlessClient';
10+
import { Utils } from '../Utils';
11+
12+
export class DefaultBootstrapper implements IBootstrapper {
13+
public register(): void {
14+
function getDefaultsSettingsFromScriptTag(): IConfigurationSettings {
15+
if (!document || !document.getElementsByTagName) {
16+
return null;
17+
}
18+
19+
var scripts = document.getElementsByTagName('script');
20+
for (var index = 0; index < scripts.length; index++) {
21+
if (scripts[index].src && scripts[index].src.indexOf('/exceptionless') > -1) {
22+
return Utils.parseQueryString(scripts[index].src.split('?').pop());
23+
}
24+
}
25+
return null;
26+
}
27+
28+
function processUnhandledException(stackTrace:TraceKit.StackTrace, options?:any): void {
29+
var builder = ExceptionlessClient.default.createUnhandledException(new Error(stackTrace.message || (options || {}).status || 'Script error'), 'onerror');
30+
builder.pluginContextData['@@_TraceKit.StackTrace'] = stackTrace;
31+
builder.submit();
32+
}
33+
34+
function processJQueryAjaxError(event, xhr, settings, error:Error): void {
35+
var client = ExceptionlessClient.default;
36+
if (xhr.status === 404) {
37+
client.submitNotFound(settings.url);
38+
} else if (xhr.status !== 401) {
39+
client.createUnhandledException(error, 'JQuery.ajaxError')
40+
.setSource(settings.url)
41+
.setProperty('status', xhr.status)
42+
.setProperty('request', settings.data)
43+
.setProperty('response', xhr.responseText && xhr.responseText.slice && xhr.responseText.slice(0, 1024))
44+
.submit();
45+
}
46+
}
47+
48+
if (typeof window === 'undefined' || typeof document === 'undefined') {
49+
return;
50+
}
51+
52+
var defaults = Configuration.defaults;
53+
var settings = getDefaultsSettingsFromScriptTag();
54+
if (settings && (settings.apiKey || settings.serverUrl)) {
55+
defaults.apiKey = settings.apiKey;
56+
defaults.serverUrl = settings.serverUrl;
57+
}
58+
59+
defaults.errorParser = new DefaultErrorParser();
60+
defaults.moduleCollector = new DefaultModuleCollector();
61+
defaults.requestInfoCollector = new DefaultRequestInfoCollector();
62+
defaults.submissionClient = new DefaultSubmissionClient();
63+
64+
TraceKit.report.subscribe(processUnhandledException);
65+
TraceKit.extendToAsynchronousCallbacks();
66+
67+
if (typeof $ !== 'undefined' && $(document)) {
68+
$(document).ajaxError(processJQueryAjaxError);
69+
}
70+
}
71+
}
72+
73+
declare var $;

src/bootstrap/NodeBootstrapper.ts

Lines changed: 57 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,78 +11,82 @@ import { Utils } from '../Utils';
1111

1212
export class NodeBootstrapper implements IBootstrapper {
1313
public register(): void {
14+
const beforeExit:string = 'beforeExit';
15+
const uncaughtException:string = 'uncaughtException';
16+
1417
if (!(typeof window === 'undefined' && typeof global !== 'undefined' && {}.toString.call(global) === '[object global]')) {
1518
return;
1619
}
1720

18-
var configDefaults = Configuration.defaults;
19-
configDefaults.environmentInfoCollector = new NodeEnvironmentInfoCollector();
20-
configDefaults.errorParser = new NodeErrorParser();
21-
configDefaults.requestInfoCollector = new NodeRequestInfoCollector();
22-
configDefaults.submissionClient = new NodeSubmissionClient();
21+
var defaults = Configuration.defaults;
22+
defaults.environmentInfoCollector = new NodeEnvironmentInfoCollector();
23+
defaults.errorParser = new NodeErrorParser();
24+
defaults.requestInfoCollector = new NodeRequestInfoCollector();
25+
defaults.submissionClient = new NodeSubmissionClient();
2326

24-
process.on('uncaughtException', function(error:Error) {
25-
ExceptionlessClient.default.submitUnhandledException(error, 'uncaughtException');
27+
process.on(uncaughtException, function (error:Error) {
28+
ExceptionlessClient.default.submitUnhandledException(error, uncaughtException);
2629
});
2730

28-
process.on('beforeExit', (code:number) => {
29-
var client = ExceptionlessClient.default;
31+
process.on(beforeExit, function (code:number) {
32+
/**
33+
* exit codes: https://nodejs.org/api/process.html#process_event_exit
34+
*/
35+
function getExitCodeReason(code:number): string {
36+
if (code === 1) {
37+
return 'Uncaught Fatal Exception';
38+
}
3039

31-
var message = this.getExitCodeReason(code);
32-
if (message !== null) {
33-
client.submitLog('beforeExit', message, 'Error')
34-
}
40+
if (code === 3) {
41+
return 'Internal JavaScript Parse Error';
42+
}
3543

36-
client.config.queue.process()
37-
});
38-
}
44+
if (code === 4) {
45+
return 'Internal JavaScript Evaluation Failure';
46+
}
3947

40-
// exit codes: https://nodejs.org/api/process.html#process_event_exit
41-
private getExitCodeReason(code:number): string {
42-
if (code === 1) {
43-
return 'Uncaught Fatal Exception';
44-
}
48+
if (code === 5) {
49+
return 'Fatal Exception';
50+
}
4551

46-
if (code === 3) {
47-
return 'Internal JavaScript Parse Error';
48-
}
52+
if (code === 6) {
53+
return 'Non-function Internal Exception Handler ';
54+
}
4955

50-
if (code === 4) {
51-
return 'Internal JavaScript Evaluation Failure';
52-
}
56+
if (code === 7) {
57+
return 'Internal Exception Handler Run-Time Failure';
58+
}
5359

54-
if (code === 5) {
55-
return 'Fatal Exception';
56-
}
60+
if (code === 8) {
61+
return 'Uncaught Exception';
62+
}
5763

58-
if (code === 6) {
59-
return 'Non-function Internal Exception Handler ';
60-
}
64+
if (code === 9) {
65+
return 'Invalid Argument';
66+
}
6167

62-
if (code === 7) {
63-
return 'Internal Exception Handler Run-Time Failure';
64-
}
68+
if (code === 10) {
69+
return 'Internal JavaScript Run-Time Failure';
70+
}
6571

66-
if (code === 8) {
67-
return 'Uncaught Exception';
68-
}
69-
70-
if (code === 9) {
71-
return 'Invalid Argument';
72-
}
72+
if (code === 12) {
73+
return 'Invalid Debug Argument';
74+
}
7375

74-
if (code === 10) {
75-
return 'Internal JavaScript Run-Time Failure';
76-
}
76+
if (code > 128) {
77+
return 'Signal Exits';
78+
}
7779

78-
if (code === 12) {
79-
return 'Invalid Debug Argument';
80-
}
80+
return null;
81+
}
8182

82-
if (code > 128) {
83-
return 'Signal Exits';
84-
}
83+
var client = ExceptionlessClient.default;
84+
var message = getExitCodeReason(code);
85+
if (message !== null) {
86+
client.submitLog(beforeExit, message, 'Error')
87+
}
8588

86-
return null;
89+
client.config.queue.process()
90+
});
8791
}
8892
}

0 commit comments

Comments
 (0)