Skip to content

Commit c55f13b

Browse files
committed
Added the ability for plugins to specify default configuration settings.
1 parent b3c9d67 commit c55f13b

File tree

6 files changed

+72
-25
lines changed

6 files changed

+72
-25
lines changed

src/ExceptionlessClient.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,18 @@ module Exceptionless {
99
export class ExceptionlessClient {
1010
public config:Configuration;
1111

12-
constructor(apiKey?:string, serverUrl?:string) {
13-
var settings = this.getSettingsFromScriptTag() || {};
14-
this.config = new Configuration(apiKey || settings.apiKey, serverUrl || settings.serverUrl);
12+
constructor();
13+
constructor(settings:IConfigurationSettings);
14+
constructor(apiKey:string, serverUrl?:string);
15+
constructor(settingsOrApiKey?:IConfigurationSettings|string, serverUrl?:string) {
16+
// TODO: populate this in a plugin..
17+
//var settings = this.getSettingsFromScriptTag() || {};
18+
19+
if (typeof settingsOrApiKey !== 'object') {
20+
this.config = new Configuration(settingsOrApiKey);
21+
} else {
22+
this.config = new Configuration({ apiKey: <string>settingsOrApiKey, serverUrl: serverUrl });
23+
}
1524
}
1625

1726
public createException(exception:Error): EventBuilder {
@@ -170,17 +179,17 @@ module Exceptionless {
170179
}
171180
}
172181

173-
private getSettingsFromScriptTag(): any {
174-
var scripts = document.getElementsByTagName('script');
182+
//private getSettingsFromScriptTag(): any {
183+
// var scripts = document.getElementsByTagName('script');
175184

176-
for (var index = 0; index < scripts.length; index++) {
177-
if (scripts[index].src && scripts[index].src.indexOf('/exceptionless') > -1) {
178-
return Utils.parseQueryString(scripts[index].src.split('?').pop());
179-
}
180-
}
185+
// for (var index = 0; index < scripts.length; index++) {
186+
// if (scripts[index].src && scripts[index].src.indexOf('/exceptionless') > -1) {
187+
// return Utils.parseQueryString(scripts[index].src.split('?').pop());
188+
// }
189+
// }
181190

182-
return null;
183-
}
191+
// return null;
192+
//}
184193

185194
private static _instance:ExceptionlessClient = null;
186195
public static get default() {

src/configuration/Configuration-spec.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,36 @@ module Exceptionless {
99
});
1010

1111
it('should set the api key and enabled to true', () => {
12-
var config = new Configuration('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', 'http://localhost:50000');
12+
var config = new Configuration({ apiKey:'LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', serverUrl:'http://localhost:50000'});
1313
expect(config).not.toBe(null);
1414
expect(config.apiKey).toBe('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
1515
expect(config.enabled).toBe(true);
1616
});
1717

18+
it('should override configuration defaults', () => {
19+
var config = new Configuration();
20+
expect(config.apiKey).toBe(null);
21+
expect(config.enabled).toBe(false);
22+
23+
Configuration.defaults.apiKey = 'test';
24+
config = new Configuration();
25+
expect(config.apiKey).toBe('test');
26+
expect(config.enabled).toBe(true);
27+
28+
config = new Configuration({ apiKey:'LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', serverUrl:'http://localhost:50000'});
29+
expect(config.apiKey).toBe('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
30+
expect(config.enabled).toBe(true);
31+
32+
config = new Configuration({ apiKey:null });
33+
expect(config.apiKey).toBe('test');
34+
expect(config.enabled).toBe(true);
35+
36+
delete Configuration.defaults.apiKey;
37+
var config = new Configuration();
38+
expect(config.apiKey).toBe(null);
39+
expect(config.enabled).toBe(false);
40+
});
41+
1842
it('apply client configuration', () => {
1943
var config = new Configuration(null);
2044
expect(config.apiKey).toBe(null);
@@ -26,7 +50,7 @@ module Exceptionless {
2650
});
2751

2852
it('should not add duplicate plugin', () => {
29-
var config = new Configuration('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
53+
var config = new Configuration({ apiKey:'LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', serverUrl:'http://localhost:50000'});
3054
expect(config.plugins).not.toBe(null);
3155
while(config.plugins.length > 0) {
3256
config.removePlugin(config.plugins[0]);
@@ -38,7 +62,7 @@ module Exceptionless {
3862
});
3963

4064
it('should generate plugin name and priority', () => {
41-
var config = new Configuration('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
65+
var config = new Configuration({ apiKey:'LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', serverUrl:'http://localhost:50000'});
4266
expect(config.plugins).not.toBe(null);
4367
while(config.plugins.length > 0) {
4468
config.removePlugin(config.plugins[0]);
@@ -51,7 +75,7 @@ module Exceptionless {
5175
});
5276

5377
it('should sort plugins by priority', () => {
54-
var config = new Configuration('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
78+
var config = new Configuration({ apiKey:'LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', serverUrl:'http://localhost:50000'});
5579
expect(config.plugins).not.toBe(null);
5680
while(config.plugins.length > 0) {
5781
config.removePlugin(config.plugins[0]);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference path="../references.ts" />
2+
3+
module Exceptionless {
4+
export interface IConfigurationSettings {
5+
apiKey?:string;
6+
serverUrl?:string;
7+
lastReferenceIdManager?:ILastReferenceIdManager;
8+
log?:ILog;
9+
submissionBatchSize?:number;
10+
submissionClient?:ISubmissionClient;
11+
storage?:IStorage<any>;
12+
queue?:IEventQueue;
13+
}
14+
}

src/queue/DefaultEventQueue-spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
module Exceptionless {
44
describe('DefaultEventQueue', () => {
55
it('should enqueue event', () => {
6-
var config = new Configuration('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', 'http://localhost:50000');
6+
var config = new Configuration({ apiKey:'LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', serverUrl:'http://localhost:50000'});
77
expect(config.storage.count()).toBe(0);
88
var event:IEvent = { type: 'log', reference_id: '123454321' };
99
config.queue.enqueue(event);
1010
expect(config.storage.count()).toBe(1);
1111
});
1212

1313
it('should process queue', () => {
14-
var config = new Configuration('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', 'http://localhost:50000');
14+
var config = new Configuration({ apiKey:'LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', serverUrl:'http://localhost:50000'});
1515
expect(config.storage.count()).toBe(0);
1616
var event:IEvent = { type: 'log', reference_id: '123454321' };
1717
config.queue.enqueue(event);
@@ -21,7 +21,7 @@ module Exceptionless {
2121
});
2222

2323
it('should discard event submission', () => {
24-
var config = new Configuration('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', 'http://localhost:50000');
24+
var config = new Configuration({ apiKey:'LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', serverUrl:'http://localhost:50000'});
2525
expect(config.storage.count()).toBe(0);
2626
config.queue.suspendProcessing(1, true);
2727

@@ -31,7 +31,7 @@ module Exceptionless {
3131
});
3232

3333
it('should suspend processing', (done) => {
34-
var config = new Configuration('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', 'http://localhost:50000');
34+
var config = new Configuration({ apiKey:'LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', serverUrl:'http://localhost:50000'});
3535
expect(config.storage.count()).toBe(0);
3636
config.queue.suspendProcessing(.0001);
3737

src/references.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// <reference path="../typings/tsd.d.ts" />
22

33
/// <reference path="configuration/Configuration.ts" />
4-
/// <reference path="configuration/IConfigurationOptions.ts" />
4+
/// <reference path="configuration/IConfigurationSettings.ts" />
55
/// <reference path="lastReferenceIdManager/ILastReferenceIdManager.ts" />
66
/// <reference path="lastReferenceIdManager/InMemoryLastReferenceIdManager.ts" />
77
/// <reference path="logging/ConsoleLog.ts" />

src/submission/DefaultSubmissionClient-spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Exceptionless {
1111
}
1212
}
1313

14-
var config = new Configuration('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', 'http://localhost:50000');
14+
var config = new Configuration({ apiKey:'LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', serverUrl:'http://localhost:50000'});
1515
var submissionClient = new DefaultSubmissionClient();
1616
submissionClient.submit([{ type: 'log', message: 'From js client', reference_id: '123454321' }], config)
1717
.then(processResponse, processResponse)
@@ -28,7 +28,7 @@ module Exceptionless {
2828
}
2929
}
3030

31-
var config = new Configuration('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', 'http://localhost:50000');
31+
var config = new Configuration({ apiKey:'LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', serverUrl:'http://localhost:50000'});
3232
var event:IEvent = { type: 'log', message: 'From js client', reference_id: '123454321', data: {
3333
name: 'blake',
3434
age: function() { throw new Error('Test'); }
@@ -49,7 +49,7 @@ module Exceptionless {
4949
}
5050
}
5151

52-
var config = new Configuration('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', 'http://localhost:50000');
52+
var config = new Configuration({ apiKey:'LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', serverUrl:'http://localhost:50000'});
5353
var submissionClient = new DefaultSubmissionClient();
5454
submissionClient.submitDescription('123454321', { email_address: '[email protected]', description: 'unit test' } , config)
5555
.then(processResponse, processResponse)
@@ -67,7 +67,7 @@ module Exceptionless {
6767
}
6868
}
6969

70-
var config = new Configuration('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', 'http://localhost:50000');
70+
var config = new Configuration({ apiKey:'LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', serverUrl:'http://localhost:50000'});
7171
var submissionClient = new DefaultSubmissionClient();
7272
submissionClient.getSettings(config)
7373
.then(processResponse, processResponse)

0 commit comments

Comments
 (0)