@redthreadlabs/tracelog-client 1.3.1 → 1.5.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/dist/EventBuilder.js +16 -6
- package/dist/LogClient.js +3 -0
- package/dist/types.d.ts +2 -79
- package/dist/types.js +0 -1
- package/dist/util.d.ts +8 -0
- package/dist/util.js +13 -0
- package/package.json +7 -2
package/dist/EventBuilder.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EventBuilder = void 0;
|
|
4
|
+
const util_1 = require("./util");
|
|
4
5
|
class EventBuilder {
|
|
5
6
|
constructor(enqueue, type) {
|
|
6
7
|
this._level = 'info';
|
|
@@ -42,9 +43,12 @@ class EventBuilder {
|
|
|
42
43
|
}
|
|
43
44
|
withError(err) {
|
|
44
45
|
if (err instanceof Error) {
|
|
45
|
-
this._error = { message:
|
|
46
|
+
this._error = { message: err.message };
|
|
46
47
|
if (err.name)
|
|
47
48
|
this._error.type = err.name;
|
|
49
|
+
const code = extractCode(err.code);
|
|
50
|
+
if (code !== undefined)
|
|
51
|
+
this._error.code = code;
|
|
48
52
|
if (err.stack)
|
|
49
53
|
this._error.stack = err.stack;
|
|
50
54
|
}
|
|
@@ -57,10 +61,13 @@ class EventBuilder {
|
|
|
57
61
|
const message = typeof err.message === 'string' && err.message.length > 0
|
|
58
62
|
? err.message
|
|
59
63
|
: safeJson(err);
|
|
60
|
-
this._error = { message
|
|
64
|
+
this._error = { message };
|
|
61
65
|
if (typeof err.name === 'string' && err.name.length > 0) {
|
|
62
66
|
this._error.type = err.name;
|
|
63
67
|
}
|
|
68
|
+
const code = extractCode(err.code);
|
|
69
|
+
if (code !== undefined)
|
|
70
|
+
this._error.code = code;
|
|
64
71
|
if (typeof err.stack === 'string')
|
|
65
72
|
this._error.stack = err.stack;
|
|
66
73
|
}
|
|
@@ -76,6 +83,7 @@ class EventBuilder {
|
|
|
76
83
|
timestamp: Date.now(),
|
|
77
84
|
level: this._level,
|
|
78
85
|
message: this._message,
|
|
86
|
+
tz_offset: (0, util_1.tzOffsetMinutes)(),
|
|
79
87
|
};
|
|
80
88
|
if (this._duration !== undefined)
|
|
81
89
|
event.duration = this._duration;
|
|
@@ -87,12 +95,14 @@ class EventBuilder {
|
|
|
87
95
|
}
|
|
88
96
|
}
|
|
89
97
|
exports.EventBuilder = EventBuilder;
|
|
90
|
-
//
|
|
91
|
-
|
|
98
|
+
// Stringify an error code (ShareDB and Node errors carry one) for the
|
|
99
|
+
// structured `error.code` field. Until 1.4.0 the code was appended to the
|
|
100
|
+
// message text; a dedicated field is facetable downstream.
|
|
101
|
+
function extractCode(code) {
|
|
92
102
|
if (typeof code === 'string' || typeof code === 'number') {
|
|
93
|
-
return
|
|
103
|
+
return String(code);
|
|
94
104
|
}
|
|
95
|
-
return
|
|
105
|
+
return undefined;
|
|
96
106
|
}
|
|
97
107
|
// Bounded JSON fallback for objects with no usable message property.
|
|
98
108
|
function safeJson(obj) {
|
package/dist/LogClient.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LogClient = void 0;
|
|
4
4
|
const EventBuilder_1 = require("./EventBuilder");
|
|
5
|
+
const util_1 = require("./util");
|
|
5
6
|
// Default constants (matching the original AppLogRecorder)
|
|
6
7
|
const DEFAULT_FLUSH_INTERVAL_MS = 5000;
|
|
7
8
|
const DEFAULT_MAX_BUFFER_SIZE = 100;
|
|
@@ -37,6 +38,7 @@ class LogClient {
|
|
|
37
38
|
const active = {
|
|
38
39
|
token,
|
|
39
40
|
startTime: now(),
|
|
41
|
+
tzOffset: (0, util_1.tzOffsetMinutes)(),
|
|
40
42
|
parentToken: parent,
|
|
41
43
|
children: [],
|
|
42
44
|
};
|
|
@@ -71,6 +73,7 @@ class LogClient {
|
|
|
71
73
|
timestamp: Math.round(active.startTime),
|
|
72
74
|
duration: Math.round(duration),
|
|
73
75
|
outcome: 'success',
|
|
76
|
+
tz_offset: active.tzOffset,
|
|
74
77
|
};
|
|
75
78
|
if (active.parentToken) {
|
|
76
79
|
timer.parent_id = active.parentToken.id;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,82 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
};
|
|
4
|
-
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
5
|
-
export interface LogBatch {
|
|
6
|
-
client: ClientInfo;
|
|
7
|
-
user_id?: string;
|
|
8
|
-
session_ref?: string;
|
|
9
|
-
device_id?: string;
|
|
10
|
-
events: LogEventItem[];
|
|
11
|
-
timers: TimerItem[];
|
|
12
|
-
}
|
|
13
|
-
export interface LogEventItem {
|
|
14
|
-
/** Event category, e.g. 'auth', 'billing', 'startup'. Default: 'client-log' */
|
|
15
|
-
type: string;
|
|
16
|
-
/** Epoch milliseconds */
|
|
17
|
-
timestamp: number;
|
|
18
|
-
level: LogLevel;
|
|
19
|
-
message: string;
|
|
20
|
-
/** Duration in milliseconds (for timed events that aren't span-shaped) */
|
|
21
|
-
duration?: number;
|
|
22
|
-
/** Serialized error info (message, type, stack) */
|
|
23
|
-
error?: {
|
|
24
|
-
message: string;
|
|
25
|
-
type?: string;
|
|
26
|
-
stack?: string;
|
|
27
|
-
};
|
|
28
|
-
/** Arbitrary key-value event data */
|
|
29
|
-
params?: Record<string, JsonValue>;
|
|
30
|
-
}
|
|
31
|
-
export interface TimerItem {
|
|
32
|
-
/** 16-char hex ID, generated client-side */
|
|
33
|
-
id: string;
|
|
34
|
-
/** 32-char hex trace ID, shared by parent + children */
|
|
35
|
-
trace_id: string;
|
|
36
|
-
/** ID of the root timer in this trace (for transaction_id on spans) */
|
|
37
|
-
root_id: string;
|
|
38
|
-
/** 16-char hex ID of parent timer (absent for root timers) */
|
|
39
|
-
parent_id?: string;
|
|
40
|
-
/** Operation name, e.g. 'content-store-startup' */
|
|
41
|
-
name: string;
|
|
42
|
-
/** Timer category. Default: 'client-perf' */
|
|
43
|
-
type: string;
|
|
44
|
-
/** Start time, epoch milliseconds */
|
|
45
|
-
timestamp: number;
|
|
46
|
-
/** Duration in milliseconds */
|
|
47
|
-
duration: number;
|
|
48
|
-
outcome: 'success' | 'failure' | 'unknown';
|
|
49
|
-
context?: {
|
|
50
|
-
tags?: Record<string, JsonValue>;
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
export interface ClientInfo {
|
|
54
|
-
/** Application name, e.g. 'duiduidui-app' */
|
|
55
|
-
name: string;
|
|
56
|
-
/** Application version */
|
|
57
|
-
version: string;
|
|
58
|
-
os: {
|
|
59
|
-
name: string;
|
|
60
|
-
version: string;
|
|
61
|
-
};
|
|
62
|
-
device: {
|
|
63
|
-
model?: string;
|
|
64
|
-
brand?: string;
|
|
65
|
-
type: string;
|
|
66
|
-
};
|
|
67
|
-
runtime: {
|
|
68
|
-
name: string;
|
|
69
|
-
version: string;
|
|
70
|
-
};
|
|
71
|
-
screen?: {
|
|
72
|
-
width: number;
|
|
73
|
-
height: number;
|
|
74
|
-
pixel_ratio: number;
|
|
75
|
-
};
|
|
76
|
-
locale?: string;
|
|
77
|
-
timezone?: string;
|
|
78
|
-
device_year_class?: number;
|
|
79
|
-
}
|
|
1
|
+
import type { ClientInfo } from '@redthreadlabs/tracelog-schema';
|
|
2
|
+
export type { JsonValue, LogLevel, LogBatch, LogEventItem, TimerItem, ClientInfo, } from '@redthreadlabs/tracelog-schema';
|
|
80
3
|
export interface TimerToken {
|
|
81
4
|
/** 16-char hex ID for this timer */
|
|
82
5
|
id: string;
|
package/dist/types.js
CHANGED
package/dist/util.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minutes east of UTC right now (ISO-8601 sign: localWallClock = UTC + offset).
|
|
3
|
+
* `Date.prototype.getTimezoneOffset()` returns minutes to ADD to local to get
|
|
4
|
+
* UTC (so it's inverted, e.g. +300 for EST); negating gives the conventional
|
|
5
|
+
* eastward offset (EST = -300, IST = +330). Captured at record time so a
|
|
6
|
+
* buffered event reflects where/when it actually happened.
|
|
7
|
+
*/
|
|
8
|
+
export declare function tzOffsetMinutes(): number;
|
package/dist/util.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tzOffsetMinutes = tzOffsetMinutes;
|
|
4
|
+
/**
|
|
5
|
+
* Minutes east of UTC right now (ISO-8601 sign: localWallClock = UTC + offset).
|
|
6
|
+
* `Date.prototype.getTimezoneOffset()` returns minutes to ADD to local to get
|
|
7
|
+
* UTC (so it's inverted, e.g. +300 for EST); negating gives the conventional
|
|
8
|
+
* eastward offset (EST = -300, IST = +330). Captured at record time so a
|
|
9
|
+
* buffered event reflects where/when it actually happened.
|
|
10
|
+
*/
|
|
11
|
+
function tzOffsetMinutes() {
|
|
12
|
+
return -new Date().getTimezoneOffset();
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@redthreadlabs/tracelog-client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Lightweight logging client for tracelog — works in React Native and browsers",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -13,9 +13,14 @@
|
|
|
13
13
|
],
|
|
14
14
|
"scripts": {
|
|
15
15
|
"build": "tsc",
|
|
16
|
-
"prepublishOnly": "npm run build"
|
|
16
|
+
"prepublishOnly": "npm run build",
|
|
17
|
+
"pretest": "npm run build",
|
|
18
|
+
"test": "node --test"
|
|
17
19
|
},
|
|
18
20
|
"devDependencies": {
|
|
19
21
|
"typescript": "latest"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@redthreadlabs/tracelog-schema": "^0.1.0"
|
|
20
25
|
}
|
|
21
26
|
}
|