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 +84 -78
- package/app-tracker.service.d.ts +50 -40
- package/app-tracker.service.js +363 -247
- package/index.d.ts +4 -3
- package/index.js +9 -8
- package/log-privacy.d.ts +2 -0
- package/log-privacy.js +63 -0
- package/log.d.ts +31 -32
- package/log.js +30 -27
- package/main.d.ts +8 -8
- package/main.js +19 -19
- package/package.json +54 -46
- package/version.d.ts +2 -0
- package/version.js +4 -0
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
tracker.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
|
39
|
-
|
|
40
|
-
|
|
|
41
|
-
|
|
|
42
|
-
|
|
|
43
|
-
|
|
|
44
|
-
|
|
|
45
|
-
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
- **
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
- **
|
|
60
|
-
- **
|
|
61
|
-
- **
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
**
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
**
|
|
73
|
-
>
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
package/app-tracker.service.d.ts
CHANGED
|
@@ -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
|
|
9
|
-
private
|
|
10
|
-
private
|
|
11
|
-
private
|
|
12
|
-
private
|
|
13
|
-
private
|
|
14
|
-
private
|
|
15
|
-
private
|
|
16
|
-
private
|
|
17
|
-
private
|
|
18
|
-
private
|
|
19
|
-
private
|
|
20
|
-
private
|
|
21
|
-
|
|
22
|
-
private
|
|
23
|
-
|
|
24
|
-
private
|
|
25
|
-
private
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
private
|
|
37
|
-
private
|
|
38
|
-
private
|
|
39
|
-
private
|
|
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
|
+
}
|