Skip to content

Commit 986733b

Browse files
committed
Moved config services, removed node storage prefix and more
1 parent 49f9ecb commit 986733b

31 files changed

+137
-174
lines changed

packages/browser/src/BrowserExceptionlessClient.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
Configuration,
32
ExceptionlessClient,
43
parseQueryString
54
} from "@exceptionless/core";
@@ -15,7 +14,7 @@ export class BrowserExceptionlessClient extends ExceptionlessClient {
1514
super(new BrowserConfiguration());
1615
}
1716

18-
public async startup(configurationOrApiKey?: (config: Configuration) => void | string): Promise<void> {
17+
public async startup(configurationOrApiKey?: (config: BrowserConfiguration) => void | string): Promise<void> {
1918
if (configurationOrApiKey) {
2019
const settings = this.getDefaultsSettingsFromScriptTag();
2120
if (settings?.apiKey) {
@@ -34,10 +33,10 @@ export class BrowserExceptionlessClient extends ExceptionlessClient {
3433
this.config.includePrivateInformation = settings.includePrivateInformation === "true";
3534
}
3635

37-
this.config.errorParser = new BrowserErrorParser();
38-
this.config.moduleCollector = new BrowserModuleCollector();
39-
this.config.requestInfoCollector = new BrowserRequestInfoCollector();
40-
this.config.submissionClient = new BrowserFetchSubmissionClient(this.config);
36+
this.config.services.errorParser = new BrowserErrorParser();
37+
this.config.services.moduleCollector = new BrowserModuleCollector();
38+
this.config.services.requestInfoCollector = new BrowserRequestInfoCollector();
39+
this.config.services.submissionClient = new BrowserFetchSubmissionClient(this.config);
4140

4241
// TODO: Register platform specific plugins.
4342
}

packages/browser/src/configuration/BrowserConfiguration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { BrowserLocalStorageProvider } from "../storage/BrowserLocalStorageProvi
55
export class BrowserConfiguration extends Configuration {
66
public useLocalStorage(): void {
77
if (BrowserLocalStorage.isAvailable()) {
8-
this.storage = new BrowserLocalStorageProvider();
8+
this.services.storage = new BrowserLocalStorageProvider();
99
SettingsManager.applySavedServerSettings(this);
1010
super.changed();
1111
}

packages/core/src/ExceptionlessClient.ts

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class ExceptionlessClient {
2727

2828
SettingsManager.applySavedServerSettings(this.config);
2929
this.config.onChanged(() => this.updateSettingsTimer(this._timeoutId > 0 ? 5000 : 0));
30-
this.config.queue.onEventsPosted(() => this.updateSettingsTimer());
30+
this.config.services.queue.onEventsPosted(() => this.updateSettingsTimer());
3131
}
3232

3333
this.updateSettingsTimer(configurationOrApiKey ? 5000 : 0);
@@ -39,12 +39,12 @@ export class ExceptionlessClient {
3939
public async suspend(): Promise<void> {
4040
await EventPluginManager.suspend(new PluginContext(this));
4141
await this.processQueue();
42-
await this.config.queue.suspend();
42+
await this.config.services.queue.suspend();
4343
this.updateSettingsTimer(0, -1);
4444
}
4545

4646
public async processQueue(): Promise<void> {
47-
await this.config.queue.process();
47+
await this.config.services.queue.process();
4848
}
4949

5050
// TODO: Look into better async scheduling..
@@ -54,7 +54,7 @@ export class ExceptionlessClient {
5454

5555
const interval = updateWhenIdleInterval || this.config.updateSettingsWhenIdleInterval;
5656
if (interval > 0) {
57-
this.config.log.info(`Update settings every ${interval}ms (${initialDelay || 0}ms delay)`);
57+
this.config.services.log.info(`Update settings every ${interval}ms (${initialDelay || 0}ms delay)`);
5858
// TODO: Fix awaiting promise.
5959
const updateSettings = () => void SettingsManager.updateSettings(this.config);
6060
if (initialDelay > 0) {
@@ -63,7 +63,7 @@ export class ExceptionlessClient {
6363

6464
this._intervalId = setInterval(updateSettings, interval);
6565
} else {
66-
this.config.log.info("Turning off update settings");
66+
this.config.services.log.info("Turning off update settings");
6767
}
6868
}
6969

@@ -77,21 +77,15 @@ export class ExceptionlessClient {
7777
return this.createException(exception).submit();
7878
}
7979

80-
public createUnhandledException(
81-
exception: Error,
82-
submissionMethod?: string,
83-
): EventBuilder {
80+
public createUnhandledException(exception: Error, submissionMethod?: string): EventBuilder {
8481
const builder = this.createException(exception);
8582
builder.pluginContextData.markAsUnhandledError();
8683
builder.pluginContextData.setSubmissionMethod(submissionMethod);
8784

8885
return builder;
8986
}
9087

91-
public submitUnhandledException(
92-
exception: Error,
93-
submissionMethod?: string,
94-
): Promise<EventPluginContext> {
88+
public submitUnhandledException(exception: Error, submissionMethod?: string): Promise<EventPluginContext> {
9589
return this.createUnhandledException(exception, submissionMethod).submit();
9690
}
9791

@@ -105,16 +99,8 @@ export class ExceptionlessClient {
10599

106100
public createLog(message: string): EventBuilder;
107101
public createLog(source: string, message: string): EventBuilder;
108-
public createLog(
109-
source: string,
110-
message: string,
111-
level: string,
112-
): EventBuilder;
113-
public createLog(
114-
sourceOrMessage: string,
115-
message?: string,
116-
level?: string,
117-
): EventBuilder {
102+
public createLog(source: string, message: string, level: string): EventBuilder;
103+
public createLog(sourceOrMessage: string, message?: string, level?: string): EventBuilder {
118104
let builder = this.createEvent().setType("log");
119105

120106
if (level) {
@@ -132,7 +118,7 @@ export class ExceptionlessClient {
132118
caller && caller.caller && caller.caller.name,
133119
);
134120
} catch (e) {
135-
this.config.log.trace("Unable to resolve log source: " + e.message);
121+
this.config.services.log.trace("Unable to resolve log source: " + e.message);
136122
}
137123
}
138124

@@ -141,16 +127,8 @@ export class ExceptionlessClient {
141127

142128
public submitLog(message: string): Promise<EventPluginContext>;
143129
public submitLog(source: string, message: string): Promise<EventPluginContext>;
144-
public submitLog(
145-
source: string,
146-
message: string,
147-
level: string,
148-
): Promise<EventPluginContext>;
149-
public submitLog(
150-
sourceOrMessage: string,
151-
message?: string,
152-
level?: string,
153-
): Promise<EventPluginContext> {
130+
public submitLog(source: string, message: string, level: string): Promise<EventPluginContext>;
131+
public submitLog(sourceOrMessage: string, message?: string, level?: string): Promise<EventPluginContext> {
154132
return this.createLog(sourceOrMessage, message, level).submit();
155133
}
156134

@@ -172,15 +150,15 @@ export class ExceptionlessClient {
172150

173151
public async submitSessionEnd(sessionIdOrUserId: string): Promise<void> {
174152
if (sessionIdOrUserId && this.config.enabled && this.config.isValid) {
175-
this.config.log.info(`Submitting session end: ${sessionIdOrUserId}`);
176-
await this.config.submissionClient.submitHeartbeat(sessionIdOrUserId, true);
153+
this.config.services.log.info(`Submitting session end: ${sessionIdOrUserId}`);
154+
await this.config.services.submissionClient.submitHeartbeat(sessionIdOrUserId, true);
177155
}
178156
}
179157

180158
public async submitSessionHeartbeat(sessionIdOrUserId: string): Promise<void> {
181159
if (sessionIdOrUserId && this.config.enabled && this.config.isValid) {
182-
this.config.log.info(`Submitting session heartbeat: ${sessionIdOrUserId}`);
183-
await this.config.submissionClient.submitHeartbeat(sessionIdOrUserId, false);
160+
this.config.services.log.info(`Submitting session heartbeat: ${sessionIdOrUserId}`);
161+
await this.config.services.submissionClient.submitHeartbeat(sessionIdOrUserId, false);
184162
}
185163
}
186164

@@ -203,7 +181,7 @@ export class ExceptionlessClient {
203181
}
204182

205183
if (!this.config.enabled || !this.config.isValid) {
206-
this.config.log.info("Event submission is currently disabled.");
184+
this.config.services.log.info("Event submission is currently disabled.");
207185
context.cancelled = true;
208186
return context;
209187
}
@@ -233,11 +211,11 @@ export class ExceptionlessClient {
233211
ev.date = new Date();
234212
}
235213

236-
config.queue.enqueue(ev);
214+
config.services.queue.enqueue(ev);
237215

238216
if (ev.reference_id && ev.reference_id.length > 0) {
239217
context.log.info(`Setting last reference id "${ev.reference_id}"`);
240-
config.lastReferenceIdManager.setLast(ev.reference_id);
218+
config.services.lastReferenceIdManager.setLast(ev.reference_id);
241219
}
242220
}
243221

@@ -257,9 +235,9 @@ export class ExceptionlessClient {
257235
email_address: email,
258236
description
259237
};
260-
const response = await this.config.submissionClient.submitUserDescription(referenceId, userDescription);
238+
const response = await this.config.services.submissionClient.submitUserDescription(referenceId, userDescription);
261239
if (!response.success) {
262-
this.config.log.error(
240+
this.config.services.log.error(
263241
`Failed to submit user email and description for event "${referenceId}": ${response.status} ${response.message}`,
264242
);
265243
}
@@ -270,6 +248,6 @@ export class ExceptionlessClient {
270248
* @returns {string} The event client id.
271249
*/
272250
public getLastReferenceId(): string {
273-
return this.config.lastReferenceIdManager.getLast();
251+
return this.config.services.lastReferenceIdManager.getLast();
274252
}
275253
}

packages/core/src/Utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export function isMatch(input: string, patterns: string[], ignoreCase: boolean =
155155
});
156156
}
157157

158-
export function isEmpty(input: Record<string, unknown>) {
158+
export function isEmpty(input: Record<string, unknown> | unknown) {
159159
return input === null || (typeof (input) === "object" && Object.keys(input).length === 0);
160160
}
161161

packages/core/src/configuration/Configuration.ts

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import { guid } from "../Utils.js";
2121
import { KnownEventDataKeys } from "../models/Event.js";
2222

2323
export class Configuration {
24+
// TODO: add flag if your suspended.
25+
// change version to be a string.
2426
/**
2527
* A default list of tags that will automatically be added to every
2628
* report submitted to the server.
@@ -45,30 +47,34 @@ export class Configuration {
4547
*/
4648
public enabled: boolean = true;
4749

48-
// TODO: Move this into services sub object
49-
public environmentInfoCollector: IEnvironmentInfoCollector;
50-
public errorParser: IErrorParser;
51-
public lastReferenceIdManager: ILastReferenceIdManager = new DefaultLastReferenceIdManager();
52-
public log: ILog = new NullLog();
53-
public moduleCollector: IModuleCollector;
54-
public requestInfoCollector: IRequestInfoCollector;
50+
public services: {
51+
environmentInfoCollector?: IEnvironmentInfoCollector,
52+
errorParser?: IErrorParser,
53+
lastReferenceIdManager: ILastReferenceIdManager,
54+
log: ILog,
55+
moduleCollector?: IModuleCollector,
56+
requestInfoCollector?: IRequestInfoCollector,
57+
submissionClient?: ISubmissionClient,
58+
storage: IStorageProvider,
59+
queue: IEventQueue
60+
} = {
61+
lastReferenceIdManager: new DefaultLastReferenceIdManager(),
62+
log: new NullLog(),
63+
storage: new InMemoryStorageProvider(),
64+
queue: new DefaultEventQueue(this)
65+
}
5566

5667
/**
5768
* Maximum number of events that should be sent to the server together in a batch. (Defaults to 50)
5869
*/
5970
public submissionBatchSize: number = 50;
60-
public submissionClient: ISubmissionClient;
6171

6272
/**
6373
* Contains a dictionary of custom settings that can be used to control
6474
* the client and will be automatically updated from the server.
6575
*/
6676
public settings: Record<string, string> = {};
6777

68-
public storage: IStorageProvider = new InMemoryStorageProvider();
69-
70-
public queue: IEventQueue = new DefaultEventQueue(this);
71-
7278
/**
7379
* The API key that will be used when sending events to the server.
7480
* @type {string}
@@ -154,7 +160,7 @@ export class Configuration {
154160
*/
155161
public set apiKey(value: string) {
156162
this._apiKey = value || null;
157-
this.log.info(`apiKey: ${this._apiKey}`);
163+
this.services.log.info(`apiKey: ${this._apiKey}`);
158164
this.changed();
159165
}
160166

@@ -183,7 +189,7 @@ export class Configuration {
183189
this._serverUrl = value;
184190
this._configServerUrl = value;
185191
this._heartbeatServerUrl = value;
186-
this.log.info(`serverUrl: ${value}`);
192+
this.services.log.info(`serverUrl: ${value}`);
187193
this.changed();
188194
}
189195
}
@@ -203,7 +209,7 @@ export class Configuration {
203209
public set configServerUrl(value: string) {
204210
if (value) {
205211
this._configServerUrl = value;
206-
this.log.info(`configServerUrl: ${value}`);
212+
this.services.log.info(`configServerUrl: ${value}`);
207213
this.changed();
208214
}
209215
}
@@ -223,7 +229,7 @@ export class Configuration {
223229
public set heartbeatServerUrl(value: string) {
224230
if (value) {
225231
this._heartbeatServerUrl = value;
226-
this.log.info(`heartbeatServerUrl: ${value}`);
232+
this.services.log.info(`heartbeatServerUrl: ${value}`);
227233
this.changed();
228234
}
229235
}
@@ -252,7 +258,7 @@ export class Configuration {
252258
}
253259

254260
this._updateSettingsWhenIdleInterval = value;
255-
this.log.info(`updateSettingsWhenIdleInterval: ${value}`);
261+
this.services.log.info(`updateSettingsWhenIdleInterval: ${value}`);
256262
this.changed();
257263
}
258264

@@ -307,7 +313,7 @@ export class Configuration {
307313
this._includeCookies = val;
308314
this._includePostData = val;
309315
this._includeQueryString = val;
310-
this.log.info(`includePrivateInformation: ${val}`);
316+
this.services.log.info(`includePrivateInformation: ${val}`);
311317
this.changed();
312318
}
313319

@@ -485,7 +491,7 @@ export class Configuration {
485491
? { name: pluginOrName as string, priority, run: pluginAction }
486492
: pluginOrName as IEventPlugin;
487493
if (!plugin || !plugin.run) {
488-
this.log.error("Add plugin failed: Run method not defined");
494+
this.services.log.error("Add plugin failed: Run method not defined");
489495
return;
490496
}
491497

@@ -526,7 +532,7 @@ export class Configuration {
526532
? pluginOrName
527533
: pluginOrName.name;
528534
if (!name) {
529-
this.log.error("Remove plugin failed: Plugin name not defined");
535+
this.services.log.error("Remove plugin failed: Plugin name not defined");
530536
return;
531537
}
532538

@@ -568,7 +574,7 @@ export class Configuration {
568574
this.defaultData[KnownEventDataKeys.UserInfo] = userInfo;
569575
}
570576

571-
this.log.info(
577+
this.services.log.info(
572578
`user identity: ${shouldRemove ? "null" : userInfo.identity}`,
573579
);
574580
}
@@ -602,7 +608,7 @@ export class Configuration {
602608

603609
// TODO: Support a min log level.
604610
public useDebugLogger(): void {
605-
this.log = new ConsoleLog();
611+
this.services.log = new ConsoleLog();
606612
}
607613

608614
public onChanged(handler: (config: Configuration) => void): void {
@@ -615,7 +621,7 @@ export class Configuration {
615621
try {
616622
handler(this);
617623
} catch (ex) {
618-
this.log.error(`Error calling onChanged handler: ${ex}`);
624+
this.services.log.error(`Error calling onChanged handler: ${ex}`);
619625
}
620626
}
621627
}

0 commit comments

Comments
 (0)