@cadenza.io/core 3.0.5 → 3.0.7

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/index.js CHANGED
@@ -969,6 +969,7 @@ var GraphNode = class _GraphNode extends SignalEmitter {
969
969
  }
970
970
  }
971
971
  emitWithMetadata(signal, ctx) {
972
+ var _a, _b;
972
973
  const data = { ...ctx };
973
974
  if (!this.task.isHidden) {
974
975
  data.__signalEmission = {
@@ -976,13 +977,16 @@ var GraphNode = class _GraphNode extends SignalEmitter {
976
977
  taskVersion: this.task.version,
977
978
  taskExecutionId: this.id
978
979
  };
980
+ const context = this.context.getMetadata();
979
981
  data.__metadata = {
980
- __routineExecId: this.routineExecId
982
+ __routineExecId: this.routineExecId,
983
+ __executionTraceId: (_b = (_a = context.__metadata) == null ? void 0 : _a.__executionTraceId) != null ? _b : context.__executionTraceId
981
984
  };
982
985
  }
983
986
  this.emit(signal, data);
984
987
  }
985
988
  emitMetricsWithMetadata(signal, ctx) {
989
+ var _a, _b;
986
990
  const data = { ...ctx };
987
991
  if (!this.task.isHidden) {
988
992
  data.__signalEmission = {
@@ -991,8 +995,10 @@ var GraphNode = class _GraphNode extends SignalEmitter {
991
995
  taskExecutionId: this.id,
992
996
  isMetric: true
993
997
  };
998
+ const context = this.context.getMetadata();
994
999
  data.__metadata = {
995
- __routineExecId: this.routineExecId
1000
+ __routineExecId: this.routineExecId,
1001
+ __executionTraceId: (_b = (_a = context.__metadata) == null ? void 0 : _a.__executionTraceId) != null ? _b : context.__executionTraceId
996
1002
  };
997
1003
  }
998
1004
  this.emitMetrics(signal, data);
@@ -2157,7 +2163,7 @@ var GraphRegistry = class _GraphRegistry {
2157
2163
  true,
2158
2164
  false,
2159
2165
  true
2160
- ).doOn("meta.task.created").emits("meta.graph_registry.task_registered");
2166
+ ).doOn("meta.task.created");
2161
2167
  this.tasks.set(this.registerTask.name, this.registerTask);
2162
2168
  this.updateTaskInputSchema = Cadenza.createMetaTask(
2163
2169
  "Update task input schema",
@@ -2330,7 +2336,7 @@ var GraphRunner = class extends SignalEmitter {
2330
2336
  * @edge Empty tasks warns no-op.
2331
2337
  */
2332
2338
  addTasks(tasks, context = {}) {
2333
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
2339
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
2334
2340
  let _tasks = Array.isArray(tasks) ? tasks : [tasks];
2335
2341
  if (_tasks.length === 0) {
2336
2342
  console.warn("No tasks/routines to add.");
@@ -2352,12 +2358,13 @@ var GraphRunner = class extends SignalEmitter {
2352
2358
  });
2353
2359
  const isSubMeta = allTasks.some((t) => t.isSubMeta) || !!context.__isSubMeta;
2354
2360
  context.__isSubMeta = isSubMeta;
2355
- const ctx = new GraphContext(context || {});
2356
- const isNewTrace = !!context.__routineExecId;
2357
- const routineExecId = (_a = context.__routineExecId) != null ? _a : (0, import_uuid4.v4)();
2361
+ const isNewTrace = !context.__routineExecId && !((_a = context.__metadata) == null ? void 0 : _a.__executionTraceId) && !context.__executionTraceId;
2362
+ const executionTraceId = (_d = (_c = (_b = context.__metadata) == null ? void 0 : _b.__executionTraceId) != null ? _c : context.__executionTraceId) != null ? _d : (0, import_uuid4.v4)();
2363
+ context.__executionTraceId = executionTraceId;
2364
+ const routineExecId = (_e = context.__routineExecId) != null ? _e : (0, import_uuid4.v4)();
2358
2365
  context.__routineExecId = routineExecId;
2366
+ const ctx = new GraphContext(context || {});
2359
2367
  if (!isSubMeta) {
2360
- const executionTraceId = (_d = (_c = (_b = context.__metadata) == null ? void 0 : _b.__executionTraceId) != null ? _c : context.__executionTraceId) != null ? _d : (0, import_uuid4.v4)();
2361
2368
  const contextData = ctx.export();
2362
2369
  if (isNewTrace) {
2363
2370
  this.emitMetrics("meta.runner.new_trace", {
@@ -2365,11 +2372,14 @@ var GraphRunner = class extends SignalEmitter {
2365
2372
  uuid: executionTraceId,
2366
2373
  issuer_type: "service",
2367
2374
  // TODO: Add issuer type
2368
- issuer_id: (_g = (_f = (_e = context.__metadata) == null ? void 0 : _e.__issuerId) != null ? _f : context.__issuerId) != null ? _g : null,
2375
+ issuer_id: (_h = (_g = (_f = context.__metadata) == null ? void 0 : _f.__issuerId) != null ? _g : context.__issuerId) != null ? _h : null,
2369
2376
  issued_at: formatTimestamp(Date.now()),
2370
- intent: (_j = (_i = (_h = context.__metadata) == null ? void 0 : _h.__intent) != null ? _i : context.__intent) != null ? _j : null,
2377
+ intent: (_k = (_j = (_i = context.__metadata) == null ? void 0 : _i.__intent) != null ? _j : context.__intent) != null ? _k : null,
2371
2378
  context: contextData,
2372
2379
  is_meta: isMeta
2380
+ },
2381
+ __metadata: {
2382
+ __executionTraceId: executionTraceId
2373
2383
  }
2374
2384
  });
2375
2385
  }
@@ -2381,9 +2391,12 @@ var GraphRunner = class extends SignalEmitter {
2381
2391
  isMeta,
2382
2392
  executionTraceId,
2383
2393
  context: isNewTrace ? contextData.id : contextData,
2384
- previousRoutineExecution: (_l = (_k = context.__metadata) == null ? void 0 : _k.__routineExecId) != null ? _l : null,
2394
+ previousRoutineExecution: (_m = (_l = context.__metadata) == null ? void 0 : _l.__routineExecId) != null ? _m : null,
2385
2395
  // TODO: There is a chance this is not added to the database yet...
2386
2396
  created: formatTimestamp(Date.now())
2397
+ },
2398
+ __metadata: {
2399
+ __executionTraceId: executionTraceId
2387
2400
  }
2388
2401
  });
2389
2402
  }