|
4 | 4 | // TODO: Process Errors |
5 | 5 | // TODO: Handle Server Settings |
6 | 6 | // TODO: Lock configuration. |
| 7 | +// TODO: Look into using templated strings `${1 + 1}` |
7 | 8 |
|
8 | 9 | module Exceptionless { |
9 | 10 | export class ExceptionlessClient { |
@@ -117,6 +118,8 @@ module Exceptionless { |
117 | 118 | this.apiKey = apiKey; |
118 | 119 | this.serverUrl = serverUrl; |
119 | 120 | this.queue = new EventQueue(this); |
| 121 | + |
| 122 | + EventPluginManager.addDefaultPlugins(this); |
120 | 123 | } |
121 | 124 |
|
122 | 125 | public get apiKey(): string { |
@@ -178,7 +181,15 @@ module Exceptionless { |
178 | 181 | } |
179 | 182 | } |
180 | 183 |
|
181 | | - public removePlugin(name:string) { |
| 184 | + public removePlugin(plugin:IEventPlugin): void; |
| 185 | + public removePlugin(name:string): void; |
| 186 | + public removePlugin(pluginOrName:IEventPlugin|string): void { |
| 187 | + var name:string = typeof pluginOrName === 'string' ? pluginOrName : pluginOrName.name; |
| 188 | + if (!name) { |
| 189 | + this.log.error('Unable to remove plugin: No plugin name was specified.'); |
| 190 | + return; |
| 191 | + } |
| 192 | + |
182 | 193 | for(var index = 0; index < this._plugins.length; index++) { |
183 | 194 | if (this._plugins[index].name === name) { |
184 | 195 | this._plugins.splice(index, 1); |
@@ -369,7 +380,7 @@ module Exceptionless { |
369 | 380 | private requeueEvents(events:IEvent[]) { |
370 | 381 | this._config.log.info('Requeuing ' + events.length + ' events.'); |
371 | 382 |
|
372 | | - for (var event in events) { |
| 383 | + for (var event of events) { |
373 | 384 | this.enqueue(event); |
374 | 385 | } |
375 | 386 | } |
@@ -709,7 +720,7 @@ module Exceptionless { |
709 | 720 | this.target.tags = []; |
710 | 721 | } |
711 | 722 |
|
712 | | - for(var tag in tags) { |
| 723 | + for(var tag of tags) { |
713 | 724 | if (tag && this.target.tags.indexOf(tag) < 0) { |
714 | 725 | this.target.tags.push(tag); |
715 | 726 | } |
@@ -824,6 +835,47 @@ module Exceptionless { |
824 | 835 | run(context:EventPluginContext): void; |
825 | 836 | } |
826 | 837 |
|
| 838 | + class EventPluginManager { |
| 839 | + public static run(context:EventPluginContext): void { |
| 840 | + for (var plugin of context.client.config.plugins) { |
| 841 | + try { |
| 842 | + plugin.run(context); |
| 843 | + if (context.cancel) { |
| 844 | + context.log.info('Event submission cancelled by plugin "' + plugin.name + '": id=' + context.event.reference_id + ' type=' + context.event.type); |
| 845 | + return; |
| 846 | + } |
| 847 | + } catch (e) { |
| 848 | + context.log.error('An error occurred while running ' + plugin.name + '.run(): ' + e.message); |
| 849 | + } |
| 850 | + } |
| 851 | + } |
| 852 | + |
| 853 | + public static addDefaultPlugins(config:Configuration): void { |
| 854 | + //config.AddPlugin<ConfigurationDefaultsPlugin>(); |
| 855 | + //config.AddPlugin<EnvironmentInfoPlugin>(); |
| 856 | + config.addPlugin(new ErrorPlugin()); |
| 857 | + //config.AddPlugin<DuplicateCheckerPlugin>(); |
| 858 | + //config.AddPlugin<SubmissionMethodPlugin>(); |
| 859 | + } |
| 860 | + } |
| 861 | + |
| 862 | + class ErrorPlugin implements IEventPlugin { |
| 863 | + public priority:number = 50; |
| 864 | + public name:string = 'ErrorPlugin'; |
| 865 | + |
| 866 | + run(context:Exceptionless.EventPluginContext): void { |
| 867 | + var exception = context.contextData.getException(); |
| 868 | + if (exception == null) { |
| 869 | + return; |
| 870 | + } |
| 871 | + |
| 872 | + context.event.type = 'error'; |
| 873 | + |
| 874 | + // TODO Parse the error. |
| 875 | + context.event.data['@error'] = exception; |
| 876 | + } |
| 877 | + } |
| 878 | + |
827 | 879 | export interface IUserDescription { |
828 | 880 | email_address?:string; |
829 | 881 | description?:string; |
|
0 commit comments