@principal-ai/principal-view-core 0.20.1 → 0.20.3
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/LibraryLoader.d.ts +3 -3
- package/dist/LibraryLoader.d.ts.map +1 -1
- package/dist/LibraryLoader.js +43 -8
- package/dist/LibraryLoader.js.map +1 -1
- package/dist/types/library.d.ts +68 -16
- package/dist/types/library.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/LibraryLoader.ts +50 -10
- package/src/types/library.ts +91 -16
package/dist/LibraryLoader.d.ts
CHANGED
|
@@ -20,21 +20,21 @@ export declare class LibraryLoader {
|
|
|
20
20
|
* @param baseDir - Base directory containing .principal-views/ folder
|
|
21
21
|
* @returns Library load result
|
|
22
22
|
*/
|
|
23
|
-
load(baseDir: string): LibraryLoadResult
|
|
23
|
+
load(baseDir: string): Promise<LibraryLoadResult>;
|
|
24
24
|
/**
|
|
25
25
|
* Load a library from a specific file path
|
|
26
26
|
*
|
|
27
27
|
* @param filePath - Full path to the library file
|
|
28
28
|
* @returns Library load result
|
|
29
29
|
*/
|
|
30
|
-
loadFromPath(filePath: string): LibraryLoadResult
|
|
30
|
+
loadFromPath(filePath: string): Promise<LibraryLoadResult>;
|
|
31
31
|
/**
|
|
32
32
|
* Check if a library file exists in the .principal-views/ folder
|
|
33
33
|
*
|
|
34
34
|
* @param baseDir - Base directory containing .principal-views/ folder
|
|
35
35
|
* @returns True if a library file exists
|
|
36
36
|
*/
|
|
37
|
-
hasLibrary(baseDir: string): boolean
|
|
37
|
+
hasLibrary(baseDir: string): Promise<boolean>;
|
|
38
38
|
/**
|
|
39
39
|
* Get the path where the library file would be located
|
|
40
40
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LibraryLoader.d.ts","sourceRoot":"","sources":["../src/LibraryLoader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,KAAK,EAAoB,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAa3E;;GAEG;AACH,qBAAa,aAAa;IACZ,OAAO,CAAC,SAAS;gBAAT,SAAS,EAAE,iBAAiB;IAEhD;;;;;;;OAOG;
|
|
1
|
+
{"version":3,"file":"LibraryLoader.d.ts","sourceRoot":"","sources":["../src/LibraryLoader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,KAAK,EAAoB,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAa3E;;GAEG;AACH,qBAAa,aAAa;IACZ,OAAO,CAAC,SAAS;gBAAT,SAAS,EAAE,iBAAiB;IAEhD;;;;;;;OAOG;IACG,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IA+BvD;;;;;OAKG;IACG,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAiChE;;;;;OAKG;IACG,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAuBnD;;;;;;OAMG;IACH,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,GAAG,MAAe,GAAG,MAAM;IAKzE;;OAEG;IACH,OAAO,CAAC,SAAS;IAUjB;;OAEG;IACH,OAAO,CAAC,SAAS;IAUjB;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ;CA4GjB"}
|
package/dist/LibraryLoader.js
CHANGED
|
@@ -28,10 +28,12 @@ export class LibraryLoader {
|
|
|
28
28
|
* @param baseDir - Base directory containing .principal-views/ folder
|
|
29
29
|
* @returns Library load result
|
|
30
30
|
*/
|
|
31
|
-
load(baseDir) {
|
|
31
|
+
async load(baseDir) {
|
|
32
32
|
const configPath = this.fsAdapter.join(baseDir, CONFIG_DIR);
|
|
33
33
|
// Check if .principal-views directory exists
|
|
34
|
-
|
|
34
|
+
const configExists = await this.fsAdapter.exists(configPath);
|
|
35
|
+
const isDir = configExists ? await this.fsAdapter.isDirectory(configPath) : false;
|
|
36
|
+
if (!configExists || !isDir) {
|
|
35
37
|
return {
|
|
36
38
|
success: false,
|
|
37
39
|
error: 'Configuration directory .principal-views/ not found',
|
|
@@ -41,7 +43,7 @@ export class LibraryLoader {
|
|
|
41
43
|
// Try each default library file name
|
|
42
44
|
for (const fileName of DEFAULT_LIBRARY_FILES) {
|
|
43
45
|
const fullPath = this.fsAdapter.join(configPath, fileName);
|
|
44
|
-
if (this.fsAdapter.exists(fullPath)) {
|
|
46
|
+
if (await this.fsAdapter.exists(fullPath)) {
|
|
45
47
|
return this.loadFromPath(fullPath);
|
|
46
48
|
}
|
|
47
49
|
}
|
|
@@ -57,9 +59,9 @@ export class LibraryLoader {
|
|
|
57
59
|
* @param filePath - Full path to the library file
|
|
58
60
|
* @returns Library load result
|
|
59
61
|
*/
|
|
60
|
-
loadFromPath(filePath) {
|
|
62
|
+
async loadFromPath(filePath) {
|
|
61
63
|
try {
|
|
62
|
-
const content = this.fsAdapter.readFile(filePath);
|
|
64
|
+
const content = await this.fsAdapter.readFile(filePath);
|
|
63
65
|
const isJson = filePath.endsWith('.json');
|
|
64
66
|
const library = isJson
|
|
65
67
|
? this.parseJson(content, filePath)
|
|
@@ -93,12 +95,23 @@ export class LibraryLoader {
|
|
|
93
95
|
* @param baseDir - Base directory containing .principal-views/ folder
|
|
94
96
|
* @returns True if a library file exists
|
|
95
97
|
*/
|
|
96
|
-
hasLibrary(baseDir) {
|
|
98
|
+
async hasLibrary(baseDir) {
|
|
97
99
|
const configPath = this.fsAdapter.join(baseDir, CONFIG_DIR);
|
|
98
|
-
|
|
100
|
+
const configExists = await this.fsAdapter.exists(configPath);
|
|
101
|
+
if (!configExists) {
|
|
99
102
|
return false;
|
|
100
103
|
}
|
|
101
|
-
|
|
104
|
+
const isDir = await this.fsAdapter.isDirectory(configPath);
|
|
105
|
+
if (!isDir) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
for (const fileName of DEFAULT_LIBRARY_FILES) {
|
|
109
|
+
const fullPath = this.fsAdapter.join(configPath, fileName);
|
|
110
|
+
if (await this.fsAdapter.exists(fullPath)) {
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
102
115
|
}
|
|
103
116
|
/**
|
|
104
117
|
* Get the path where the library file would be located
|
|
@@ -208,6 +221,28 @@ export class LibraryLoader {
|
|
|
208
221
|
}
|
|
209
222
|
}
|
|
210
223
|
}
|
|
224
|
+
// Validate resources if present
|
|
225
|
+
if (library.resources) {
|
|
226
|
+
if (typeof library.resources !== 'object' || Array.isArray(library.resources)) {
|
|
227
|
+
return `Field 'resources' must be an object in ${filePath}`;
|
|
228
|
+
}
|
|
229
|
+
for (const [serviceId, resourceAttrs] of Object.entries(library.resources)) {
|
|
230
|
+
// Check that each service has a resource attributes object
|
|
231
|
+
if (typeof resourceAttrs !== 'object' || Array.isArray(resourceAttrs) || resourceAttrs === null) {
|
|
232
|
+
return `Resource entry '${serviceId}' must be an object in ${filePath}`;
|
|
233
|
+
}
|
|
234
|
+
// Check that service.name is present (required)
|
|
235
|
+
if (!resourceAttrs['service.name']) {
|
|
236
|
+
return `Resource entry '${serviceId}' is missing required attribute 'service.name' in ${filePath}`;
|
|
237
|
+
}
|
|
238
|
+
// Validate all attribute values are strings
|
|
239
|
+
for (const [attrName, attrValue] of Object.entries(resourceAttrs)) {
|
|
240
|
+
if (typeof attrValue !== 'string') {
|
|
241
|
+
return `Resource '${serviceId}' attribute '${attrName}' must have a string value in ${filePath}`;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
211
246
|
return undefined;
|
|
212
247
|
}
|
|
213
248
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LibraryLoader.js","sourceRoot":"","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,EAAE,CAAC;aAC7D;YAED,KAAK,MAAM,CAAC,SAAS,EAAE,aAAa,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;gBAC1E,2DAA2D;gBAC3D,IAAI,OAAO,aAAa,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,aAAa,KAAK,IAAI,EAAE;oBAC/F,OAAO,mBAAmB,SAAS,0BAA0B,QAAQ,EAAE,CAAC;iBACzE;gBAED,gDAAgD;gBAChD,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC,EAAE;oBAClC,OAAO,mBAAmB,SAAS,qDAAqD,QAAQ,EAAE,CAAC;iBACpG;gBAED,4CAA4C;gBAC5C,KAAK,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE;oBACjE,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;wBACjC,OAAO,aAAa,SAAS,gBAAgB,QAAQ,iCAAiC,QAAQ,EAAE,CAAC;qBAClG;iBACF;aACF;SACF;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF"}
|
package/dist/types/library.d.ts
CHANGED
|
@@ -12,6 +12,54 @@
|
|
|
12
12
|
* the type definition gets embedded into the node's `pv` field.
|
|
13
13
|
*/
|
|
14
14
|
import type { PVNodeShape, PVEdgeStyle, PVAnimationType, PVNodeState, PVEventSchema } from './canvas';
|
|
15
|
+
/**
|
|
16
|
+
* OTEL resource attributes for a service/component
|
|
17
|
+
*
|
|
18
|
+
* Represents the actual resource attribute values (not match patterns).
|
|
19
|
+
* These are the attributes that would be set when instrumenting the service.
|
|
20
|
+
*
|
|
21
|
+
* @see https://opentelemetry.io/docs/specs/semconv/resource/
|
|
22
|
+
*/
|
|
23
|
+
export interface ResourceAttributes {
|
|
24
|
+
/** Service identification (required) */
|
|
25
|
+
'service.name': string;
|
|
26
|
+
/** Service version (recommended) */
|
|
27
|
+
'service.version'?: string;
|
|
28
|
+
/** Service namespace (optional) */
|
|
29
|
+
'service.namespace'?: string;
|
|
30
|
+
/** Service instance ID (optional) */
|
|
31
|
+
'service.instance.id'?: string;
|
|
32
|
+
/** Deployment environment (recommended) */
|
|
33
|
+
'deployment.environment'?: string;
|
|
34
|
+
/** Kubernetes namespace */
|
|
35
|
+
'k8s.namespace.name'?: string;
|
|
36
|
+
/** Kubernetes deployment name */
|
|
37
|
+
'k8s.deployment.name'?: string;
|
|
38
|
+
/** Kubernetes pod name */
|
|
39
|
+
'k8s.pod.name'?: string;
|
|
40
|
+
/** Kubernetes container name */
|
|
41
|
+
'k8s.container.name'?: string;
|
|
42
|
+
/** Kubernetes node name */
|
|
43
|
+
'k8s.node.name'?: string;
|
|
44
|
+
/** Database system */
|
|
45
|
+
'db.system'?: string;
|
|
46
|
+
/** Database name */
|
|
47
|
+
'db.name'?: string;
|
|
48
|
+
/** Host name */
|
|
49
|
+
'host.name'?: string;
|
|
50
|
+
/** Host ID */
|
|
51
|
+
'host.id'?: string;
|
|
52
|
+
/** Cloud provider */
|
|
53
|
+
'cloud.provider'?: string;
|
|
54
|
+
/** Cloud region */
|
|
55
|
+
'cloud.region'?: string;
|
|
56
|
+
/** Messaging system */
|
|
57
|
+
'messaging.system'?: string;
|
|
58
|
+
/** Messaging destination name */
|
|
59
|
+
'messaging.destination.name'?: string;
|
|
60
|
+
/** Allow arbitrary OTEL resource attributes */
|
|
61
|
+
[key: string]: string | undefined;
|
|
62
|
+
}
|
|
15
63
|
/**
|
|
16
64
|
* A reusable node component definition in the library.
|
|
17
65
|
* Contains all the information needed to create a canvas node.
|
|
@@ -152,30 +200,34 @@ export interface ComponentLibrary {
|
|
|
152
200
|
/** Library description */
|
|
153
201
|
description?: string;
|
|
154
202
|
/**
|
|
155
|
-
*
|
|
203
|
+
* Service resource registry
|
|
156
204
|
*
|
|
157
|
-
* Defines
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
* - Service
|
|
161
|
-
* -
|
|
205
|
+
* Defines the services in this package and their expected OTEL resource attributes.
|
|
206
|
+
* Each service configures its own resources at runtime (via env vars or SDK),
|
|
207
|
+
* but declaring them here provides:
|
|
208
|
+
* - Service documentation/registry
|
|
209
|
+
* - Expected resource schema for validation
|
|
210
|
+
* - Dev instrumentation defaults
|
|
211
|
+
* - Canvas node generation
|
|
162
212
|
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
* - service.version: Service version
|
|
166
|
-
* - dev.server.url: Development server path (for routing to correct dev workspace)
|
|
167
|
-
* - deployment.environment: Environment (dev/staging/prod)
|
|
213
|
+
* The key is a service identifier (used for reference), and the value contains
|
|
214
|
+
* the OTEL resource attributes for that service.
|
|
168
215
|
*
|
|
169
216
|
* @example
|
|
170
217
|
* ```yaml
|
|
171
218
|
* resources:
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
219
|
+
* payment-api:
|
|
220
|
+
* service.name: "payment-api"
|
|
221
|
+
* service.version: "1.0.0"
|
|
222
|
+
* deployment.environment: "development"
|
|
223
|
+
*
|
|
224
|
+
* payment-worker:
|
|
225
|
+
* service.name: "payment-worker"
|
|
226
|
+
* service.version: "1.0.0"
|
|
227
|
+
* deployment.environment: "development"
|
|
176
228
|
* ```
|
|
177
229
|
*/
|
|
178
|
-
resources?: Record<string,
|
|
230
|
+
resources?: Record<string, ResourceAttributes>;
|
|
179
231
|
/** Reusable node component definitions */
|
|
180
232
|
nodeComponents: Record<string, LibraryNodeComponent>;
|
|
181
233
|
/** Reusable edge type definitions */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"library.d.ts","sourceRoot":"","sources":["../../src/types/library.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,eAAe,EAEf,WAAW,EACX,aAAa,EACd,MAAM,UAAU,CAAC;AAMlB;;;GAGG;AACH,MAA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AO,CAAC;IAEjB,yCAAyC;IACzC,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAE3B,gCAAgC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
|
package/package.json
CHANGED
package/src/LibraryLoader.ts
CHANGED
|
@@ -33,11 +33,14 @@ export class LibraryLoader {
|
|
|
33
33
|
* @param baseDir - Base directory containing .principal-views/ folder
|
|
34
34
|
* @returns Library load result
|
|
35
35
|
*/
|
|
36
|
-
load(baseDir: string): LibraryLoadResult {
|
|
36
|
+
async load(baseDir: string): Promise<LibraryLoadResult> {
|
|
37
37
|
const configPath = this.fsAdapter.join(baseDir, CONFIG_DIR);
|
|
38
38
|
|
|
39
39
|
// Check if .principal-views directory exists
|
|
40
|
-
|
|
40
|
+
const configExists = await this.fsAdapter.exists(configPath);
|
|
41
|
+
const isDir = configExists ? await this.fsAdapter.isDirectory(configPath) : false;
|
|
42
|
+
|
|
43
|
+
if (!configExists || !isDir) {
|
|
41
44
|
return {
|
|
42
45
|
success: false,
|
|
43
46
|
error: 'Configuration directory .principal-views/ not found',
|
|
@@ -49,7 +52,7 @@ export class LibraryLoader {
|
|
|
49
52
|
for (const fileName of DEFAULT_LIBRARY_FILES) {
|
|
50
53
|
const fullPath = this.fsAdapter.join(configPath, fileName);
|
|
51
54
|
|
|
52
|
-
if (this.fsAdapter.exists(fullPath)) {
|
|
55
|
+
if (await this.fsAdapter.exists(fullPath)) {
|
|
53
56
|
return this.loadFromPath(fullPath);
|
|
54
57
|
}
|
|
55
58
|
}
|
|
@@ -67,9 +70,9 @@ export class LibraryLoader {
|
|
|
67
70
|
* @param filePath - Full path to the library file
|
|
68
71
|
* @returns Library load result
|
|
69
72
|
*/
|
|
70
|
-
loadFromPath(filePath: string): LibraryLoadResult {
|
|
73
|
+
async loadFromPath(filePath: string): Promise<LibraryLoadResult> {
|
|
71
74
|
try {
|
|
72
|
-
const content = this.fsAdapter.readFile(filePath);
|
|
75
|
+
const content = await this.fsAdapter.readFile(filePath);
|
|
73
76
|
const isJson = filePath.endsWith('.json');
|
|
74
77
|
|
|
75
78
|
const library = isJson
|
|
@@ -106,16 +109,27 @@ export class LibraryLoader {
|
|
|
106
109
|
* @param baseDir - Base directory containing .principal-views/ folder
|
|
107
110
|
* @returns True if a library file exists
|
|
108
111
|
*/
|
|
109
|
-
hasLibrary(baseDir: string): boolean {
|
|
112
|
+
async hasLibrary(baseDir: string): Promise<boolean> {
|
|
110
113
|
const configPath = this.fsAdapter.join(baseDir, CONFIG_DIR);
|
|
111
114
|
|
|
112
|
-
|
|
115
|
+
const configExists = await this.fsAdapter.exists(configPath);
|
|
116
|
+
if (!configExists) {
|
|
113
117
|
return false;
|
|
114
118
|
}
|
|
115
119
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
120
|
+
const isDir = await this.fsAdapter.isDirectory(configPath);
|
|
121
|
+
if (!isDir) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
for (const fileName of DEFAULT_LIBRARY_FILES) {
|
|
126
|
+
const fullPath = this.fsAdapter.join(configPath, fileName);
|
|
127
|
+
if (await this.fsAdapter.exists(fullPath)) {
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return false;
|
|
119
133
|
}
|
|
120
134
|
|
|
121
135
|
/**
|
|
@@ -243,6 +257,32 @@ export class LibraryLoader {
|
|
|
243
257
|
}
|
|
244
258
|
}
|
|
245
259
|
|
|
260
|
+
// Validate resources if present
|
|
261
|
+
if (library.resources) {
|
|
262
|
+
if (typeof library.resources !== 'object' || Array.isArray(library.resources)) {
|
|
263
|
+
return `Field 'resources' must be an object in ${filePath}`;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
for (const [serviceId, resourceAttrs] of Object.entries(library.resources)) {
|
|
267
|
+
// Check that each service has a resource attributes object
|
|
268
|
+
if (typeof resourceAttrs !== 'object' || Array.isArray(resourceAttrs) || resourceAttrs === null) {
|
|
269
|
+
return `Resource entry '${serviceId}' must be an object in ${filePath}`;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// Check that service.name is present (required)
|
|
273
|
+
if (!resourceAttrs['service.name']) {
|
|
274
|
+
return `Resource entry '${serviceId}' is missing required attribute 'service.name' in ${filePath}`;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// Validate all attribute values are strings
|
|
278
|
+
for (const [attrName, attrValue] of Object.entries(resourceAttrs)) {
|
|
279
|
+
if (typeof attrValue !== 'string') {
|
|
280
|
+
return `Resource '${serviceId}' attribute '${attrName}' must have a string value in ${filePath}`;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
246
286
|
return undefined;
|
|
247
287
|
}
|
|
248
288
|
}
|
package/src/types/library.ts
CHANGED
|
@@ -21,6 +21,77 @@ import type {
|
|
|
21
21
|
PVEventSchema,
|
|
22
22
|
} from './canvas';
|
|
23
23
|
|
|
24
|
+
// ============================================================================
|
|
25
|
+
// Resource Types
|
|
26
|
+
// ============================================================================
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* OTEL resource attributes for a service/component
|
|
30
|
+
*
|
|
31
|
+
* Represents the actual resource attribute values (not match patterns).
|
|
32
|
+
* These are the attributes that would be set when instrumenting the service.
|
|
33
|
+
*
|
|
34
|
+
* @see https://opentelemetry.io/docs/specs/semconv/resource/
|
|
35
|
+
*/
|
|
36
|
+
export interface ResourceAttributes {
|
|
37
|
+
/** Service identification (required) */
|
|
38
|
+
'service.name': string;
|
|
39
|
+
|
|
40
|
+
/** Service version (recommended) */
|
|
41
|
+
'service.version'?: string;
|
|
42
|
+
|
|
43
|
+
/** Service namespace (optional) */
|
|
44
|
+
'service.namespace'?: string;
|
|
45
|
+
|
|
46
|
+
/** Service instance ID (optional) */
|
|
47
|
+
'service.instance.id'?: string;
|
|
48
|
+
|
|
49
|
+
/** Deployment environment (recommended) */
|
|
50
|
+
'deployment.environment'?: string;
|
|
51
|
+
|
|
52
|
+
/** Kubernetes namespace */
|
|
53
|
+
'k8s.namespace.name'?: string;
|
|
54
|
+
|
|
55
|
+
/** Kubernetes deployment name */
|
|
56
|
+
'k8s.deployment.name'?: string;
|
|
57
|
+
|
|
58
|
+
/** Kubernetes pod name */
|
|
59
|
+
'k8s.pod.name'?: string;
|
|
60
|
+
|
|
61
|
+
/** Kubernetes container name */
|
|
62
|
+
'k8s.container.name'?: string;
|
|
63
|
+
|
|
64
|
+
/** Kubernetes node name */
|
|
65
|
+
'k8s.node.name'?: string;
|
|
66
|
+
|
|
67
|
+
/** Database system */
|
|
68
|
+
'db.system'?: string;
|
|
69
|
+
|
|
70
|
+
/** Database name */
|
|
71
|
+
'db.name'?: string;
|
|
72
|
+
|
|
73
|
+
/** Host name */
|
|
74
|
+
'host.name'?: string;
|
|
75
|
+
|
|
76
|
+
/** Host ID */
|
|
77
|
+
'host.id'?: string;
|
|
78
|
+
|
|
79
|
+
/** Cloud provider */
|
|
80
|
+
'cloud.provider'?: string;
|
|
81
|
+
|
|
82
|
+
/** Cloud region */
|
|
83
|
+
'cloud.region'?: string;
|
|
84
|
+
|
|
85
|
+
/** Messaging system */
|
|
86
|
+
'messaging.system'?: string;
|
|
87
|
+
|
|
88
|
+
/** Messaging destination name */
|
|
89
|
+
'messaging.destination.name'?: string;
|
|
90
|
+
|
|
91
|
+
/** Allow arbitrary OTEL resource attributes */
|
|
92
|
+
[key: string]: string | undefined;
|
|
93
|
+
}
|
|
94
|
+
|
|
24
95
|
// ============================================================================
|
|
25
96
|
// Library Component Types
|
|
26
97
|
// ============================================================================
|
|
@@ -195,30 +266,34 @@ export interface ComponentLibrary {
|
|
|
195
266
|
description?: string;
|
|
196
267
|
|
|
197
268
|
/**
|
|
198
|
-
*
|
|
269
|
+
* Service resource registry
|
|
199
270
|
*
|
|
200
|
-
* Defines
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
* - Service
|
|
204
|
-
* -
|
|
271
|
+
* Defines the services in this package and their expected OTEL resource attributes.
|
|
272
|
+
* Each service configures its own resources at runtime (via env vars or SDK),
|
|
273
|
+
* but declaring them here provides:
|
|
274
|
+
* - Service documentation/registry
|
|
275
|
+
* - Expected resource schema for validation
|
|
276
|
+
* - Dev instrumentation defaults
|
|
277
|
+
* - Canvas node generation
|
|
205
278
|
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
* - service.version: Service version
|
|
209
|
-
* - dev.server.url: Development server path (for routing to correct dev workspace)
|
|
210
|
-
* - deployment.environment: Environment (dev/staging/prod)
|
|
279
|
+
* The key is a service identifier (used for reference), and the value contains
|
|
280
|
+
* the OTEL resource attributes for that service.
|
|
211
281
|
*
|
|
212
282
|
* @example
|
|
213
283
|
* ```yaml
|
|
214
284
|
* resources:
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
285
|
+
* payment-api:
|
|
286
|
+
* service.name: "payment-api"
|
|
287
|
+
* service.version: "1.0.0"
|
|
288
|
+
* deployment.environment: "development"
|
|
289
|
+
*
|
|
290
|
+
* payment-worker:
|
|
291
|
+
* service.name: "payment-worker"
|
|
292
|
+
* service.version: "1.0.0"
|
|
293
|
+
* deployment.environment: "development"
|
|
219
294
|
* ```
|
|
220
295
|
*/
|
|
221
|
-
resources?: Record<string,
|
|
296
|
+
resources?: Record<string, ResourceAttributes>;
|
|
222
297
|
|
|
223
298
|
/** Reusable node component definitions */
|
|
224
299
|
nodeComponents: Record<string, LibraryNodeComponent>;
|