@illuma-ai/observability-core 0.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/dist/core-client.d.ts +101 -0
- package/dist/core-client.d.ts.map +1 -0
- package/dist/core-client.js +253 -0
- package/dist/core-client.js.map +1 -0
- package/dist/generation-client.d.ts +38 -0
- package/dist/generation-client.d.ts.map +1 -0
- package/dist/generation-client.js +72 -0
- package/dist/generation-client.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/span-client.d.ts +60 -0
- package/dist/span-client.d.ts.map +1 -0
- package/dist/span-client.js +141 -0
- package/dist/span-client.js.map +1 -0
- package/dist/trace-client.d.ts +51 -0
- package/dist/trace-client.d.ts.map +1 -0
- package/dist/trace-client.js +121 -0
- package/dist/trace-client.js.map +1 -0
- package/dist/types.d.ts +300 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +39 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +57 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +114 -0
- package/dist/utils.js.map +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,8EAA8E;AAC9E,oBAAoB;AACpB,8EAA8E;AAE9E,wCAAwC;AACxC,MAAM,CAAN,IAAY,gBAKX;AALD,WAAY,gBAAgB;IAC1B,mCAAe,CAAA;IACf,uCAAmB,CAAA;IACnB,uCAAmB,CAAA;IACnB,mCAAe,CAAA;AACjB,CAAC,EALW,gBAAgB,KAAhB,gBAAgB,QAK3B;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,SAAS;IACT,YAAY,EAAE,cAAc;IAE5B,QAAQ;IACR,WAAW,EAAE,aAAa;IAC1B,WAAW,EAAE,aAAa;IAE1B,cAAc;IACd,iBAAiB,EAAE,mBAAmB;IACtC,iBAAiB,EAAE,mBAAmB;IAEtC,sCAAsC;IACtC,YAAY,EAAE,cAAc;IAE5B,SAAS;IACT,YAAY,EAAE,cAAc;IAE5B,eAAe;IACf,OAAO,EAAE,SAAS;CACV,CAAC"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utility functions for the observability SDK.
|
|
3
|
+
*
|
|
4
|
+
* These helpers are intentionally dependency-free so they work in both
|
|
5
|
+
* Node.js and browser environments without polyfills.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Generate a unique ID suitable for trace / observation / event identifiers.
|
|
9
|
+
*
|
|
10
|
+
* Prefers `crypto.randomUUID()` (available in Node 19+, modern browsers,
|
|
11
|
+
* and Cloudflare Workers). Falls back to a manual v4-style UUID built from
|
|
12
|
+
* `Math.random()` for older runtimes.
|
|
13
|
+
*/
|
|
14
|
+
export declare function generateId(): string;
|
|
15
|
+
/**
|
|
16
|
+
* Returns the current time as an ISO-8601 string with millisecond precision.
|
|
17
|
+
*/
|
|
18
|
+
export declare function currentISOTimestamp(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Safely serialise any value to a JSON string.
|
|
21
|
+
*
|
|
22
|
+
* - Handles circular references by replacing them with `"[Circular]"`.
|
|
23
|
+
* - Catches any other `JSON.stringify` errors and returns a fallback string.
|
|
24
|
+
*
|
|
25
|
+
* @param value - The value to serialise.
|
|
26
|
+
* @param indent - Optional indentation for pretty-printing.
|
|
27
|
+
*/
|
|
28
|
+
export declare function safeStringify(value: unknown, indent?: number): string;
|
|
29
|
+
/**
|
|
30
|
+
* Encode a public-key / secret-key pair into a Basic Authorization header value.
|
|
31
|
+
*
|
|
32
|
+
* Uses `btoa` in browsers and `Buffer` in Node.js.
|
|
33
|
+
*
|
|
34
|
+
* @param publicKey - The public API key (username).
|
|
35
|
+
* @param secretKey - The secret API key (password).
|
|
36
|
+
* @returns The full header value, e.g. `"Basic cHVibGljOnNlY3JldA=="`.
|
|
37
|
+
*/
|
|
38
|
+
export declare function encodeBasicAuth(publicKey: string, secretKey: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Compute exponential backoff delay with jitter.
|
|
41
|
+
*
|
|
42
|
+
* @param attempt - Zero-based attempt index (0 = first retry).
|
|
43
|
+
* @param baseMs - Base delay in milliseconds.
|
|
44
|
+
* @returns Delay in milliseconds.
|
|
45
|
+
*/
|
|
46
|
+
export declare function backoffDelay(attempt: number, baseMs?: number): number;
|
|
47
|
+
/**
|
|
48
|
+
* Simple no-op logger that can be replaced by platform-specific implementations.
|
|
49
|
+
* Avoids direct console usage so the SDK stays silent by default.
|
|
50
|
+
*/
|
|
51
|
+
export declare const defaultLogger: {
|
|
52
|
+
debug: (..._args: unknown[]) => void;
|
|
53
|
+
info: (..._args: unknown[]) => void;
|
|
54
|
+
warn: (...args: unknown[]) => void;
|
|
55
|
+
error: (...args: unknown[]) => void;
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;GAMG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAenC;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAwBrE;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAgB5E;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAO,GAAG,MAAM,CAKnE;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa;sBACN,OAAO,EAAE,KAAG,IAAI;qBACjB,OAAO,EAAE,KAAG,IAAI;oBACjB,OAAO,EAAE,KAAG,IAAI;qBAKf,OAAO,EAAE,KAAG,IAAI;CAIlC,CAAC"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utility functions for the observability SDK.
|
|
3
|
+
*
|
|
4
|
+
* These helpers are intentionally dependency-free so they work in both
|
|
5
|
+
* Node.js and browser environments without polyfills.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Generate a unique ID suitable for trace / observation / event identifiers.
|
|
9
|
+
*
|
|
10
|
+
* Prefers `crypto.randomUUID()` (available in Node 19+, modern browsers,
|
|
11
|
+
* and Cloudflare Workers). Falls back to a manual v4-style UUID built from
|
|
12
|
+
* `Math.random()` for older runtimes.
|
|
13
|
+
*/
|
|
14
|
+
export function generateId() {
|
|
15
|
+
// crypto.randomUUID is available in Node >= 19, modern browsers, workers
|
|
16
|
+
if (typeof globalThis !== 'undefined' &&
|
|
17
|
+
typeof globalThis.crypto?.randomUUID === 'function') {
|
|
18
|
+
return globalThis.crypto.randomUUID();
|
|
19
|
+
}
|
|
20
|
+
// Fallback: RFC-4122 v4 UUID from Math.random
|
|
21
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
22
|
+
const r = (Math.random() * 16) | 0;
|
|
23
|
+
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
24
|
+
return v.toString(16);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Returns the current time as an ISO-8601 string with millisecond precision.
|
|
29
|
+
*/
|
|
30
|
+
export function currentISOTimestamp() {
|
|
31
|
+
return new Date().toISOString();
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Safely serialise any value to a JSON string.
|
|
35
|
+
*
|
|
36
|
+
* - Handles circular references by replacing them with `"[Circular]"`.
|
|
37
|
+
* - Catches any other `JSON.stringify` errors and returns a fallback string.
|
|
38
|
+
*
|
|
39
|
+
* @param value - The value to serialise.
|
|
40
|
+
* @param indent - Optional indentation for pretty-printing.
|
|
41
|
+
*/
|
|
42
|
+
export function safeStringify(value, indent) {
|
|
43
|
+
const seen = new WeakSet();
|
|
44
|
+
try {
|
|
45
|
+
return JSON.stringify(value, (_key, val) => {
|
|
46
|
+
if (typeof val === 'object' && val !== null) {
|
|
47
|
+
if (seen.has(val)) {
|
|
48
|
+
return '[Circular]';
|
|
49
|
+
}
|
|
50
|
+
seen.add(val);
|
|
51
|
+
}
|
|
52
|
+
// Convert BigInt to string since JSON.stringify can't handle it
|
|
53
|
+
if (typeof val === 'bigint') {
|
|
54
|
+
return val.toString();
|
|
55
|
+
}
|
|
56
|
+
return val;
|
|
57
|
+
}, indent);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return String(value);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Encode a public-key / secret-key pair into a Basic Authorization header value.
|
|
65
|
+
*
|
|
66
|
+
* Uses `btoa` in browsers and `Buffer` in Node.js.
|
|
67
|
+
*
|
|
68
|
+
* @param publicKey - The public API key (username).
|
|
69
|
+
* @param secretKey - The secret API key (password).
|
|
70
|
+
* @returns The full header value, e.g. `"Basic cHVibGljOnNlY3JldA=="`.
|
|
71
|
+
*/
|
|
72
|
+
export function encodeBasicAuth(publicKey, secretKey) {
|
|
73
|
+
const credentials = `${publicKey}:${secretKey}`;
|
|
74
|
+
// Node.js
|
|
75
|
+
if (typeof Buffer !== 'undefined') {
|
|
76
|
+
return `Basic ${Buffer.from(credentials).toString('base64')}`;
|
|
77
|
+
}
|
|
78
|
+
// Browser / Workers
|
|
79
|
+
if (typeof btoa === 'function') {
|
|
80
|
+
return `Basic ${btoa(credentials)}`;
|
|
81
|
+
}
|
|
82
|
+
throw new Error('No base64 encoder available. Ensure you are running in Node.js or a modern browser.');
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Compute exponential backoff delay with jitter.
|
|
86
|
+
*
|
|
87
|
+
* @param attempt - Zero-based attempt index (0 = first retry).
|
|
88
|
+
* @param baseMs - Base delay in milliseconds.
|
|
89
|
+
* @returns Delay in milliseconds.
|
|
90
|
+
*/
|
|
91
|
+
export function backoffDelay(attempt, baseMs = 1000) {
|
|
92
|
+
const exponential = baseMs * Math.pow(2, attempt);
|
|
93
|
+
// Add up to 25 % random jitter to avoid thundering herd
|
|
94
|
+
const jitter = exponential * 0.25 * Math.random();
|
|
95
|
+
return Math.min(exponential + jitter, 30_000); // cap at 30 s
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Simple no-op logger that can be replaced by platform-specific implementations.
|
|
99
|
+
* Avoids direct console usage so the SDK stays silent by default.
|
|
100
|
+
*/
|
|
101
|
+
export const defaultLogger = {
|
|
102
|
+
debug: (..._args) => { },
|
|
103
|
+
info: (..._args) => { },
|
|
104
|
+
warn: (...args) => {
|
|
105
|
+
// Warnings are surfaced by default so users know about misconfiguration
|
|
106
|
+
// eslint-disable-next-line no-console
|
|
107
|
+
console.warn('[illuma-observability]', ...args);
|
|
108
|
+
},
|
|
109
|
+
error: (...args) => {
|
|
110
|
+
// eslint-disable-next-line no-console
|
|
111
|
+
console.error('[illuma-observability]', ...args);
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;GAMG;AACH,MAAM,UAAU,UAAU;IACxB,yEAAyE;IACzE,IACE,OAAO,UAAU,KAAK,WAAW;QACjC,OAAO,UAAU,CAAC,MAAM,EAAE,UAAU,KAAK,UAAU,EACnD,CA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AC;IAClD,CAAC;IACD,KAAK,EAAE,CAAC,GAAG,IAAe,EAAQ,EAAE;QAClC,sCAAsC;QACtC,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,GAAG,IAAI,CAAC,CAAC;IACnD,CAAC;CACF,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@illuma-ai/observability-core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Core observability SDK - shared foundation for Node.js and browser clients",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"prepublishOnly": "npm run build"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"typescript": "^5.4.5",
|
|
24
|
+
"@types/node": "^20.14.2"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/illuma-ai/observability.git",
|
|
32
|
+
"directory": "packages/observability-core"
|
|
33
|
+
},
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"keywords": [
|
|
36
|
+
"llm",
|
|
37
|
+
"observability",
|
|
38
|
+
"tracing",
|
|
39
|
+
"langfuse",
|
|
40
|
+
"illuma",
|
|
41
|
+
"langchain",
|
|
42
|
+
"openai"
|
|
43
|
+
]
|
|
44
|
+
}
|