forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodeExceptionlessClient.ts
More file actions
50 lines (42 loc) · 1.83 KB
/
NodeExceptionlessClient.ts
File metadata and controls
50 lines (42 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import {
Configuration,
DefaultSubmissionClient,
ExceptionlessClient,
LocalStorage,
SimpleErrorPlugin
} from "@exceptionless/core";
import { LocalStorage as LocalStoragePolyfill } from "node-localstorage";
import fetch from "node-fetch";
import { NodeErrorPlugin } from "./plugins/NodeErrorPlugin.js";
import { NodeEnvironmentInfoPlugin } from "./plugins/NodeEnvironmentInfoPlugin.js";
import { NodeGlobalHandlerPlugin } from "./plugins/NodeGlobalHandlerPlugin.js";
import { NodeLifeCyclePlugin } from "./plugins/NodeLifeCyclePlugin.js";
import { NodeRequestInfoPlugin } from "./plugins/NodeRequestInfoPlugin.js";
import { NodeWrapFunctions } from "./plugins/NodeWrapFunctions.js";
export class NodeExceptionlessClient extends ExceptionlessClient {
public async startup(configurationOrApiKey?: (config: Configuration) => void | string): Promise<void> {
const config = this.config;
if (configurationOrApiKey) {
if (!globalThis?.localStorage) {
const storage = new LocalStorage(undefined, new LocalStoragePolyfill(process.cwd() + '/.exceptionless'));
config.useLocalStorage = () => storage;
config.services.storage = storage;
}
if (!globalThis?.fetch) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
config.services.submissionClient = new DefaultSubmissionClient(config, fetch);
}
config.addPlugin(new NodeEnvironmentInfoPlugin());
config.addPlugin(new NodeGlobalHandlerPlugin());
config.addPlugin(new NodeLifeCyclePlugin());
config.addPlugin(new NodeRequestInfoPlugin());
config.addPlugin(new NodeWrapFunctions());
config.addPlugin(new NodeErrorPlugin());
}
await super.startup(configurationOrApiKey);
if (configurationOrApiKey) {
config.removePlugin(new SimpleErrorPlugin());
}
}
}