wobs-js 0.1.0 → 0.1.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/examples/demo.js
CHANGED
package/package.json
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wobs-js",
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Wuying Observer SDK for JavaScript",
|
|
5
|
+
"main": "src/observer.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "node examples/demo.js",
|
|
8
|
+
"demo": "node examples/demo.js"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"opentelemetry",
|
|
12
|
+
"trace",
|
|
13
|
+
"trackpoint",
|
|
14
|
+
"monitoring"
|
|
15
|
+
],
|
|
16
|
+
"author": "Wuying",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"directories": {
|
|
19
|
+
"example": "examples",
|
|
20
|
+
"src": "src"
|
|
21
|
+
},
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=12.0.0"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"ini": "^6.0.0"
|
|
27
|
+
}
|
|
25
28
|
}
|
package/src/userInfo.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
const os = require('os');
|
|
6
6
|
const fs = require('fs');
|
|
7
|
+
const ini = require('ini');
|
|
7
8
|
const path = require('path');
|
|
8
9
|
|
|
9
10
|
class ObserverConfig {
|
|
@@ -252,6 +253,16 @@ function getUserInfoFromRegistry(userInfo) {
|
|
|
252
253
|
}
|
|
253
254
|
}
|
|
254
255
|
|
|
256
|
+
function readRuntimeIni(file) {
|
|
257
|
+
if (!fs.existsSync(file)) return {};
|
|
258
|
+
|
|
259
|
+
const content = fs.readFileSync(file, 'utf-8');
|
|
260
|
+
const config = ini.parse(content); // 自动处理 "AliUid = 123" 这种格式
|
|
261
|
+
|
|
262
|
+
return config;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
|
|
255
266
|
function getUserInfoFromIni(userInfo) {
|
|
256
267
|
/** Get user info from INI-style config file (Linux/macOS). */
|
|
257
268
|
const os = require('os');
|
|
@@ -269,25 +280,18 @@ function getUserInfoFromIni(userInfo) {
|
|
|
269
280
|
// Read from runtime.ini
|
|
270
281
|
if (fs.existsSync(runtimeIniPath)) {
|
|
271
282
|
try {
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
} else if (key === 'OfficeSiteId') {
|
|
285
|
-
userInfo.officeSiteID = value;
|
|
286
|
-
} else if (key === 'regionId') {
|
|
287
|
-
userInfo.regionID = value;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
}
|
|
283
|
+
const cfg = readRuntimeIni(runtimeIniPath);
|
|
284
|
+
if (cfg.AliUID) {
|
|
285
|
+
userInfo.AliUID = cfg.AliUID;
|
|
286
|
+
}
|
|
287
|
+
if (cfg.DesktopId) {
|
|
288
|
+
userInfo.desktopID = cfg.DesktopId;
|
|
289
|
+
}
|
|
290
|
+
if (cfg.OfficeSiteId) {
|
|
291
|
+
userInfo.officeSiteID = cfg.OfficeSiteId;
|
|
292
|
+
}
|
|
293
|
+
if (cfg.regionId) {
|
|
294
|
+
userInfo.regionID = cfg.regionId;
|
|
291
295
|
}
|
|
292
296
|
} catch (error) {
|
|
293
297
|
console.warn(`Failed to read ${runtimeIniPath}: ${error.message}`);
|
|
@@ -358,8 +362,20 @@ function getUserInfoFromEnv(userInfo) {
|
|
|
358
362
|
if (appInstanceId !== undefined) {
|
|
359
363
|
userInfo.appInstanceID = appInstanceId;
|
|
360
364
|
}
|
|
365
|
+
getAliUidFromEnv(userInfo);
|
|
366
|
+
} catch (error) {
|
|
367
|
+
console.warn(`Get user info from env failed, error: ${error.message}`);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function getAliUidFromEnv(userInfo) {
|
|
372
|
+
/** Get AliUid from environment variable. */
|
|
373
|
+
try {
|
|
374
|
+
if (process.env.ALI_UID) {
|
|
375
|
+
userInfo.AliUID = process.env.ALI_UID;
|
|
376
|
+
}
|
|
361
377
|
} catch (error) {
|
|
362
|
-
console.warn(`Get
|
|
378
|
+
console.warn(`Get ALI_UID failed, error: ${error.message}`);
|
|
363
379
|
}
|
|
364
380
|
}
|
|
365
381
|
|
|
@@ -381,6 +397,7 @@ function getUserInfo() {
|
|
|
381
397
|
getUserInfoFromEnv(userInfo);
|
|
382
398
|
} else {
|
|
383
399
|
// Linux/Unix systems
|
|
400
|
+
getAliUidFromEnv(userInfo);
|
|
384
401
|
getUserInfoFromIni(userInfo);
|
|
385
402
|
}
|
|
386
403
|
|
|
File without changes
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
{"time":"2026-01-21T20:49:13.687+0800","eventName":"test","module":"builder","InstanceID":"i-123","osVersion":"macOS 25.1.0","userName":"panxiangpeng","properties":{"args":["/usr/local/bin/node","/Users/panxiangpeng/Work/code/wuying-guestos-observer-js/examples/demo.js"]}}
|
|
2
|
+
{"time":"2026-01-21T20:49:37.619+0800","eventName":"test","module":"builder","InstanceID":"i-123","aliUid":"12345","osVersion":"macOS 25.1.0","userName":"panxiangpeng","properties":{"args":["/usr/local/bin/node","/Users/panxiangpeng/Work/code/wuying-guestos-observer-js/examples/demo.js"]}}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
{"host":"","service":"unknown","resource":{"service.name":"test","env.osVersion":"macOS 25.0.0","env.userName":"panxiangpeng"},"name":"test_span","kind":"","traceID":"000000000000000000093e58102c3734","spanID":"0005dc64bdb79db1","parentSpanID":"ffffffffffffffff","links":[],"logs":[{"Name":"event1","Time":88834253599625,"attribute":{"event_attr":"event_value"}}],"traceState":"","start":88834253579.5,"end":88834258160.666,"duration":4581.166,"attribute":{"key":"value","key2":"value2"},"statusCode":"ERROR"}
|
|
2
|
-
{"host":"","service":"unknown","resource":{"service.name":"test","env.osVersion":"macOS 25.0.0","env.userName":"panxiangpeng"},"name":"test_exception","kind":"","traceID":"00000000000000000006add8749fc552","spanID":"0000f7df6181896d","parentSpanID":"","links":[],"logs":[{"Name":"event1","Time":88834258513833,"attribute":{"event_attr":"event_value"}}],"traceState":"","start":88834258511.041,"end":88834258532.125,"duration":21.084,"attribute":{"key":"value"},"statusCode":"UNSET"}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
{"time":"2025-11-04T10:30:28.130+0800","eventName":"test_trace","module":"test","osVersion":"macOS 25.0.0","userName":"panxiangpeng"}
|
|
2
|
-
{"time":"2025-11-04T10:30:28.135+0800","eventName":"test","module":"test","osVersion":"macOS 25.0.0","userName":"panxiangpeng","properties":{"args":["/usr/local/bin/node","/Users/panxiangpeng/Work/code/wuying-guestos-observer-python/js/examples/demo.js"]}}
|
|
3
|
-
{"time":"2025-11-04T10:30:28.135+0800","eventName":"test_exception","module":"test","osVersion":"macOS 25.0.0","userName":"panxiangpeng"}
|