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
@@ -50,7 +50,7 @@ function testRotation() {
50
50
  // 主程序
51
51
  if (require.main === module) {
52
52
  // 初始化observer,指定trackpoint和trace文件存放目录,这里设置为当前路径,默认可不填,和C++、Golang版本保持一致
53
- init('builder');
53
+ init('builder', './', './');
54
54
 
55
55
 
56
56
  newTrackPoint('test', { args: process.argv });
package/package.json CHANGED
@@ -1,25 +1,28 @@
1
1
  {
2
2
  "name": "wobs-js",
3
- "version": "0.1.0",
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
- }
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 data = fs.readFileSync(runtimeIniPath, 'utf8');
273
- const lines = data.split('\n');
274
-
275
- for (const line of lines) {
276
- if (line.trim() && !line.startsWith('#')) {
277
- const parts = line.trim().split('=', 2);
278
- if (parts.length === 2) {
279
- const [key, value] = parts;
280
- if (key === 'DesktopId') {
281
- userInfo.desktopID = value;
282
- } else if (key === 'AliUid') {
283
- userInfo.AliUID = value;
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 instanceid failed, error: ${error.message}`);
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"}