app-tracker 2.2.2 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,78 +1,84 @@
1
-
2
-
3
- # App Tracker for Web & Node.js
4
-
5
- App Tracker is a TypeScript/JavaScript library for logging and tracking events in web and Node.js applications. It supports batching, flexible configuration, and sending logs to a central endpoint.
6
-
7
- ## Installation
8
-
9
- ```bash
10
- npm i app-tracker
11
- ```
12
-
13
- ## Registration & API Key
14
-
15
- - Register at [App Tracker](https://www.app-tracker.cloud/) and create an application to get your API key.
16
-
17
- ## Quick Start
18
-
19
- ```typescript
20
- import { AppTracker, AppTrackerService } from "app-tracker";
21
-
22
- const config = {
23
- userAgentOrOs: typeof window !== 'undefined' ? navigator.userAgent : require('os'),
24
- logInConsole: true,
25
- sendLogsInDevelopment: true,
26
- // more options below
27
- };
28
- const tracker: AppTrackerService = AppTracker.init("API_KEY", config);
29
-
30
- tracker.debug("Debug message", { foo: "bar" });
31
- tracker.error("An error occurred", errorObj);
32
- ```
33
-
34
- ## Configuration
35
-
36
- | Property | Type | Default | Description |
37
- |-----------------------------|--------------|--------------------------------|-------------|
38
- | sendLogsInDevelopment | boolean | false | Send logs during development |
39
- | logInConsole | boolean | false | Also log to the console |
40
- | endpointUrl | string | https://app-tracker-api.azurewebsites.net/ | Target endpoint for logs |
41
- | maxSendTries | number | 5 | Max. send attempts on error |
42
- | maxLogsCount | number | 10 | Batch size for sending logs |
43
- | logLevel | LogType[] | [LogType.error] | Which log types are sent |
44
- | sendLogsByTypesImmediately | LogType[] | [LogType.error, LogType.critical] | Types sent immediately |
45
- | userAgentOrOs | any | | Browser: navigator.userAgent, Node: require('os') |
46
-
47
- **LogType:** `debug`, `info`, `log`, `warn`, `error`, `critical`
48
-
49
- ## Architecture & Features
50
-
51
- - **Singleton Service:** Always access via `AppTracker.init()` or `AppTracker.getService()`
52
- - **Batching:** Logs are collected and sent after `maxLogsCount` or immediately for critical errors
53
- - **Environment Awareness:** Automatically adapts for browser/Node.js
54
- - **Secure Sending:** API key required, retry mechanism on errors
55
- - **External Dependency:** Uses `cross-fetch` for HTTP requests
56
-
57
- ## Build & Development
58
-
59
- - **Build:** `npm run build` (TypeScript compile & copy to `lib/`)
60
- - **Minify:** `npm run terser` (Terser minification of JS files)
61
- - **Lint:** `npm run lint` (TSLint)
62
- - **Format:** `npm run format` (Prettier)
63
-
64
- ## FAQ
65
-
66
- **Where do I get my API key?**
67
- > Register at https://www.app-tracker.cloud/ and create an application.
68
-
69
- **How can I suppress logs in development?**
70
- > Set `sendLogsInDevelopment: false` in the configuration.
71
-
72
- **How do I send custom log types?**
73
- > Use the `debug`, `info`, `warn`, `error`, `critical` methods of the service object.
74
-
75
- ## Further Information
76
- - See `src/app-tracker.service.ts` for service logic
77
- - See `src/log.ts` for configuration and log types
78
- - See `.github/copilot-instructions.md` for developer guidelines
1
+
2
+
3
+ # App Tracker for Web & Node.js
4
+
5
+ App Tracker is a TypeScript/JavaScript library for logging and tracking events in web and Node.js applications. It supports batching, flexible configuration, and sending logs to a central endpoint.
6
+
7
+ Runtime support: Node.js 16 or newer and modern browsers with `fetch`/XHR, `Promise`, and `WeakSet`. Missing browser storage or `sendBeacon` support is handled with fallbacks.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm i app-tracker
13
+ ```
14
+
15
+ ## Registration & API Key
16
+
17
+ - Register at [App Tracker](https://www.app-tracker.cloud/) and create an application to get your API key.
18
+
19
+ ## Quick Start
20
+
21
+ ```typescript
22
+ import { AppTracker, AppTrackerService } from "app-tracker";
23
+
24
+ const config = {
25
+ userAgentOrOs: typeof window !== 'undefined' ? navigator.userAgent : require('os'),
26
+ logInConsole: true,
27
+ sendLogsInDevelopment: true,
28
+ // more options below
29
+ };
30
+ const tracker: AppTrackerService = AppTracker.init("API_KEY", config);
31
+
32
+ tracker.debug("Debug message", { foo: "bar" });
33
+ tracker.error("An error occurred", errorObj);
34
+ ```
35
+
36
+ ## Configuration
37
+
38
+ | Property | Type | Default | Description |
39
+ |-----------------------------|--------------|--------------------------------|-------------|
40
+ | sendLogsInDevelopment | boolean | false | Send logs during development |
41
+ | logInConsole | boolean | false | Also log to the console |
42
+ | endpointUrl | string | https://app-tracker-api.azurewebsites.net/ | Target endpoint for logs |
43
+ | maxSendTries | number | 5 | Max. send attempts on error |
44
+ | retryDelayMs | number | 10000 | Delay between send attempts in milliseconds |
45
+ | requestTimeoutMs | number | 10000 | Timeout for each HTTP attempt in milliseconds |
46
+ | maxLogsCount | number | 10 | Batch size for sending logs |
47
+ | logLevel | LogType[] | [LogType.error] | Which log types are sent |
48
+ | sendLogsByTypesImmediately | LogType[] | [LogType.error, LogType.critical] | Types sent immediately |
49
+ | userAgentOrOs | any | | Browser: navigator.userAgent, Node: require('os') |
50
+
51
+ **LogType:** `debug`, `info`, `log`, `warn`, `error`, `critical`
52
+
53
+ ## Architecture & Features
54
+
55
+ - **Singleton Service:** Always access via `AppTracker.init()` or `AppTracker.getService()`
56
+ - **Batching:** Logs are collected and sent after `maxLogsCount` or immediately for critical errors
57
+ - **Explicit flush:** Call and await `tracker.flush()` before a controlled Node.js shutdown
58
+ - **Environment Awareness:** Automatically adapts for browser/Node.js
59
+ - **Browser correlation:** Generates one in-memory correlation ID per page lifetime and includes it in every browser log batch. Node.js payloads do not include it. Use `tracker.getCorrelationId()` to display the current ID when needed.
60
+ - **Secure Sending:** API key required, retry mechanism on errors
61
+ - **External Dependency:** Uses `cross-fetch` for HTTP requests
62
+
63
+ ## Build & Development
64
+
65
+ - **Build:** `npm run build` (TypeScript compile & copy to `lib/`)
66
+ - **Minify:** `npm run terser` (Terser minification of JS files)
67
+ - **Lint:** `npm run lint` (TSLint)
68
+ - **Format:** `npm run format` (Prettier)
69
+
70
+ ## FAQ
71
+
72
+ **Where do I get my API key?**
73
+ > Register at https://www.app-tracker.cloud/ and create an application.
74
+
75
+ **How can I suppress logs in development?**
76
+ > Set `sendLogsInDevelopment: false` in the configuration.
77
+
78
+ **How do I send custom log types?**
79
+ > Use the `debug`, `info`, `warn`, `error`, `critical` methods of the service object.
80
+
81
+ ## Further Information
82
+ - See `src/app-tracker.service.ts` for service logic
83
+ - See `src/log.ts` for configuration and log types
84
+ - See `.github/copilot-instructions.md` for developer guidelines
@@ -1,40 +1,50 @@
1
- import { AppTrackerConfig } from './log';
2
- export declare class AppTrackerService {
3
- private sendLogsInDevelopment;
4
- private logInConsole;
5
- private endpointUrl;
6
- private apiKey;
7
- private logs;
8
- private sendTries;
9
- private maxSendTries;
10
- private isSending;
11
- private maxLogsCount;
12
- private userAgent;
13
- private logLevel;
14
- private sendLogsByTypesImmediately;
15
- private isNode;
16
- private os;
17
- private isRunningLocal;
18
- private ident;
19
- private eventListenerAdded;
20
- private _boundBeforeUnloadHandler?;
21
- init(apiKey: string, config?: AppTrackerConfig): void;
22
- private addEventListener;
23
- private removeEventListener;
24
- private beforeunloadHandler;
25
- private setRunningSystem;
26
- getIdent(): string;
27
- debug(message?: string, ...optionalParams: any[]): void;
28
- info(message?: string, ...optionalParams: any[]): void;
29
- log(message?: string, ...optionalParams: any[]): void;
30
- warn(message?: string, ...optionalParams: any[]): void;
31
- error(message?: string, ...optionalParams: any[]): void;
32
- critical(message?: string, ...optionalParams: any[]): void;
33
- private addLog;
34
- private logToConsole;
35
- private sendLogsToServer;
36
- private checkLogType;
37
- private sendLogsToServerCore;
38
- private setUserAgentFromOs;
39
- private createUUID;
40
- }
1
+ import { AppTrackerConfig } from './log';
2
+ export declare class AppTrackerService {
3
+ private sendLogsInDevelopment;
4
+ private logInConsole;
5
+ private endpointUrl;
6
+ private apiKey;
7
+ private logs;
8
+ private maxSendTries;
9
+ private retryDelayMs;
10
+ private requestTimeoutMs;
11
+ private isSending;
12
+ private activeSend?;
13
+ private maxLogsCount;
14
+ private clientInfo;
15
+ private correlationId?;
16
+ private logLevel;
17
+ private sendLogsByTypesImmediately;
18
+ private isNode;
19
+ private nodeProcess;
20
+ private isRunningLocal;
21
+ private eventListenerAdded;
22
+ private _boundBeforeUnloadHandler?;
23
+ init(apiKey: string, config?: AppTrackerConfig): void;
24
+ private addEventListener;
25
+ private removeEventListener;
26
+ private beforeunloadHandler;
27
+ private setRunningSystem;
28
+ getIdent(): string;
29
+ getCorrelationId(): string;
30
+ debug(message?: string, ...optionalParams: any[]): void;
31
+ info(message?: string, ...optionalParams: any[]): void;
32
+ log(message?: string, ...optionalParams: any[]): void;
33
+ warn(message?: string, ...optionalParams: any[]): void;
34
+ error(message?: string, ...optionalParams: any[]): void;
35
+ critical(message?: string, ...optionalParams: any[]): void;
36
+ private addLog;
37
+ private logToConsole;
38
+ private sendLogsToServer;
39
+ private checkLogType;
40
+ /** Sends all currently queued logs and any logs added while sending. */
41
+ flush(): Promise<void>;
42
+ private runSendLoop;
43
+ private sendLogsToServerCore;
44
+ private getLogsEndpoint;
45
+ private serializePayload;
46
+ private getBrowserClientInfo;
47
+ private getNodeClientInfo;
48
+ private majorVersion;
49
+ private createCorrelationId;
50
+ }