@statsig/web-analytics 3.21.0 → 3.21.1
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statsig/web-analytics",
|
|
3
|
-
"version": "3.21.
|
|
3
|
+
"version": "3.21.1",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"homepage": "https://github.com/statsig-io/js-client-monorepo",
|
|
6
6
|
"repository": {
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"directory": "packages/web-analytics"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@statsig/client-core": "3.21.
|
|
13
|
-
"@statsig/js-client": "3.21.
|
|
12
|
+
"@statsig/client-core": "3.21.1",
|
|
13
|
+
"@statsig/js-client": "3.21.1",
|
|
14
14
|
"web-vitals": "5.0.3"
|
|
15
15
|
},
|
|
16
16
|
"jsdelivr": "./build/statsig-web-analytics.min.js",
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { LogLevel } from '@statsig/client-core';
|
|
2
1
|
import { AutoCaptureEvent } from './AutoCaptureEvent';
|
|
2
|
+
import { ConsoleLogLevel } from './ConsoleLogManager';
|
|
3
3
|
export type AutoCaptureOptions = {
|
|
4
4
|
eventFilterFunc?: (event: AutoCaptureEvent) => boolean;
|
|
5
5
|
consoleLogAutoCaptureSettings?: ConsoleLogAutoCaptureSettings;
|
|
6
6
|
};
|
|
7
7
|
export type ConsoleLogAutoCaptureSettings = {
|
|
8
8
|
enabled: boolean;
|
|
9
|
-
logLevel?:
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
logLevel?: ConsoleLogLevel;
|
|
10
|
+
service?: string;
|
|
11
|
+
version?: string;
|
|
12
12
|
sampleRate?: number;
|
|
13
13
|
resourceMetadata?: Record<string, string | number | boolean>;
|
|
14
14
|
};
|
|
@@ -1,21 +1,13 @@
|
|
|
1
1
|
import { AutoCaptureEventName } from './AutoCaptureEvent';
|
|
2
2
|
import { ConsoleLogAutoCaptureSettings } from './AutoCaptureOptions';
|
|
3
|
-
export type
|
|
4
|
-
export type ConsoleLogEvent = {
|
|
5
|
-
eventName: 'statsig::console_log';
|
|
6
|
-
value: string;
|
|
7
|
-
metadata: {
|
|
8
|
-
timestamp: string;
|
|
9
|
-
log_level: LogLevel;
|
|
10
|
-
payload: string[];
|
|
11
|
-
trace: string[];
|
|
12
|
-
};
|
|
13
|
-
};
|
|
3
|
+
export type ConsoleLogLevel = 'log' | 'info' | 'warn' | 'error' | 'debug' | 'trace';
|
|
14
4
|
export declare class ConsoleLogManager {
|
|
15
5
|
private _enqueueFn;
|
|
16
6
|
private _options;
|
|
17
7
|
private _restoreFns;
|
|
18
8
|
private _isTracking;
|
|
9
|
+
private _logLevel;
|
|
10
|
+
private readonly __source;
|
|
19
11
|
constructor(_enqueueFn: (eventName: AutoCaptureEventName, value: string, metadata: Record<string, unknown>) => void, _options: ConsoleLogAutoCaptureSettings);
|
|
20
12
|
startTracking(): void;
|
|
21
13
|
stopTracking(): void;
|
package/src/ConsoleLogManager.js
CHANGED
|
@@ -6,12 +6,24 @@ const client_core_1 = require("@statsig/client-core");
|
|
|
6
6
|
const AutoCaptureEvent_1 = require("./AutoCaptureEvent");
|
|
7
7
|
const commonUtils_1 = require("./utils/commonUtils");
|
|
8
8
|
const metadataUtils_1 = require("./utils/metadataUtils");
|
|
9
|
+
const ConsoleLogPriority = {
|
|
10
|
+
trace: 10,
|
|
11
|
+
debug: 20,
|
|
12
|
+
log: 30, // log & info are the same priority
|
|
13
|
+
info: 30,
|
|
14
|
+
warn: 40,
|
|
15
|
+
error: 50,
|
|
16
|
+
};
|
|
9
17
|
class ConsoleLogManager {
|
|
10
18
|
constructor(_enqueueFn, _options) {
|
|
19
|
+
var _a;
|
|
11
20
|
this._enqueueFn = _enqueueFn;
|
|
12
21
|
this._options = _options;
|
|
13
22
|
this._restoreFns = [];
|
|
14
23
|
this._isTracking = false;
|
|
24
|
+
this._logLevel = 'info';
|
|
25
|
+
this.__source = 'js-auto-capture';
|
|
26
|
+
this._logLevel = (_a = this._options.logLevel) !== null && _a !== void 0 ? _a : 'info';
|
|
15
27
|
}
|
|
16
28
|
startTracking() {
|
|
17
29
|
if (this._isTracking || !this._options.enabled)
|
|
@@ -30,7 +42,9 @@ class ConsoleLogManager {
|
|
|
30
42
|
this._isTracking = false;
|
|
31
43
|
}
|
|
32
44
|
_patchConsole() {
|
|
33
|
-
|
|
45
|
+
Object.entries(ConsoleLogPriority).forEach(([level, priority]) => {
|
|
46
|
+
if (priority < ConsoleLogPriority[this._logLevel])
|
|
47
|
+
return;
|
|
34
48
|
if (!console[level])
|
|
35
49
|
return;
|
|
36
50
|
const original = console[level].bind(console);
|
|
@@ -61,9 +75,9 @@ class ConsoleLogManager {
|
|
|
61
75
|
var _a, _b, _c;
|
|
62
76
|
if (!this._shouldLog())
|
|
63
77
|
return;
|
|
64
|
-
const metadata = Object.assign(Object.assign({ log_level: level, payload,
|
|
65
|
-
trace, timestamp: Date.now(),
|
|
66
|
-
this._enqueueFn(AutoCaptureEvent_1.AutoCaptureEventName.CONSOLE_LOG, (
|
|
78
|
+
const metadata = Object.assign(Object.assign({ status: level === 'log' ? 'info' : level, log_level: level, payload,
|
|
79
|
+
trace, timestamp: Date.now(), service: (_a = this._options.service) !== null && _a !== void 0 ? _a : '', version: (_b = this._options.version) !== null && _b !== void 0 ? _b : '', source: this.__source }, ((_c = this._options.resourceMetadata) !== null && _c !== void 0 ? _c : {})), (0, metadataUtils_1._gatherAllMetadata)((0, commonUtils_1._getSafeUrl)()));
|
|
80
|
+
this._enqueueFn(AutoCaptureEvent_1.AutoCaptureEventName.CONSOLE_LOG, payload.join(' '), metadata);
|
|
67
81
|
}
|
|
68
82
|
_shouldLog() {
|
|
69
83
|
if (!this._options.sampleRate ||
|