@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.mjs CHANGED
@@ -932,6 +932,7 @@ var GraphNode = class _GraphNode extends SignalEmitter {
932
932
  }
933
933
  }
934
934
  emitWithMetadata(signal, ctx) {
935
+ var _a, _b;
935
936
  const data = { ...ctx };
936
937
  if (!this.task.isHidden) {
937
938
  data.__signalEmission = {
@@ -939,13 +940,16 @@ var GraphNode = class _GraphNode extends SignalEmitter {
939
940
  taskVersion: this.task.version,
940
941
  taskExecutionId: this.id
941
942
  };
943
+ const context = this.context.getMetadata();
942
944
  data.__metadata = {
943
- __routineExecId: this.routineExecId
945
+ __routineExecId: this.routineExecId,
946
+ __executionTraceId: (_b = (_a = context.__metadata) == null ? void 0 : _a.__executionTraceId) != null ? _b : context.__executionTraceId
944
947
  };
945
948
  }
946
949
  this.emit(signal, data);
947
950
  }
948
951
  emitMetricsWithMetadata(signal, ctx) {
952
+ var _a, _b;
949
953
  const data = { ...ctx };
950
954
  if (!this.task.isHidden) {
951
955
  data.__signalEmission = {
@@ -954,8 +958,10 @@ var GraphNode = class _GraphNode extends SignalEmitter {
954
958
  taskExecutionId: this.id,
955
959
  isMetric: true
956
960
  };
961
+ const context = this.context.getMetadata();
957
962
  data.__metadata = {
958
- __routineExecId: this.routineExecId
963
+ __routineExecId: this.routineExecId,
964
+ __executionTraceId: (_b = (_a = context.__metadata) == null ? void 0 : _a.__executionTraceId) != null ? _b : context.__executionTraceId
959
965
  };
960
966
  }
961
967
  this.emitMetrics(signal, data);
@@ -2120,7 +2126,7 @@ var GraphRegistry = class _GraphRegistry {
2120
2126
  true,
2121
2127
  false,
2122
2128
  true
2123
- ).doOn("meta.task.created").emits("meta.graph_registry.task_registered");
2129
+ ).doOn("meta.task.created");
2124
2130
  this.tasks.set(this.registerTask.name, this.registerTask);
2125
2131
  this.updateTaskInputSchema = Cadenza.createMetaTask(
2126
2132
  "Update task input schema",
@@ -2293,7 +2299,7 @@ var GraphRunner = class extends SignalEmitter {
2293
2299
  * @edge Empty tasks warns no-op.
2294
2300
  */
2295
2301
  addTasks(tasks, context = {}) {
2296
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
2302
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
2297
2303
  let _tasks = Array.isArray(tasks) ? tasks : [tasks];
2298
2304
  if (_tasks.length === 0) {
2299
2305
  console.warn("No tasks/routines to add.");
@@ -2315,12 +2321,13 @@ var GraphRunner = class extends SignalEmitter {
2315
2321
  });
2316
2322
  const isSubMeta = allTasks.some((t) => t.isSubMeta) || !!context.__isSubMeta;
2317
2323
  context.__isSubMeta = isSubMeta;
2318
- const ctx = new GraphContext(context || {});
2319
- const isNewTrace = !!context.__routineExecId;
2320
- const routineExecId = (_a = context.__routineExecId) != null ? _a : uuid4();
2324
+ const isNewTrace = !context.__routineExecId && !((_a = context.__metadata) == null ? void 0 : _a.__executionTraceId) && !context.__executionTraceId;
2325
+ const executionTraceId = (_d = (_c = (_b = context.__metadata) == null ? void 0 : _b.__executionTraceId) != null ? _c : context.__executionTraceId) != null ? _d : uuid4();
2326
+ context.__executionTraceId = executionTraceId;
2327
+ const routineExecId = (_e = context.__routineExecId) != null ? _e : uuid4();
2321
2328
  context.__routineExecId = routineExecId;
2329
+ const ctx = new GraphContext(context || {});
2322
2330
  if (!isSubMeta) {
2323
- const executionTraceId = (_d = (_c = (_b = context.__metadata) == null ? void 0 : _b.__executionTraceId) != null ? _c : context.__executionTraceId) != null ? _d : uuid4();
2324
2331
  const contextData = ctx.export();
2325
2332
  if (isNewTrace) {
2326
2333
  this.emitMetrics("meta.runner.new_trace", {
@@ -2328,11 +2335,14 @@ var GraphRunner = class extends SignalEmitter {
2328
2335
  uuid: executionTraceId,
2329
2336
  issuer_type: "service",
2330
2337
  // TODO: Add issuer type
2331
- issuer_id: (_g = (_f = (_e = context.__metadata) == null ? void 0 : _e.__issuerId) != null ? _f : context.__issuerId) != null ? _g : null,
2338
+ issuer_id: (_h = (_g = (_f = context.__metadata) == null ? void 0 : _f.__issuerId) != null ? _g : context.__issuerId) != null ? _h : null,
2332
2339
  issued_at: formatTimestamp(Date.now()),
2333
- intent: (_j = (_i = (_h = context.__metadata) == null ? void 0 : _h.__intent) != null ? _i : context.__intent) != null ? _j : null,
2340
+ intent: (_k = (_j = (_i = context.__metadata) == null ? void 0 : _i.__intent) != null ? _j : context.__intent) != null ? _k : null,
2334
2341
  context: contextData,
2335
2342
  is_meta: isMeta
2343
+ },
2344
+ __metadata: {
2345
+ __executionTraceId: executionTraceId
2336
2346
  }
2337
2347
  });
2338
2348
  }
@@ -2344,9 +2354,12 @@ var GraphRunner = class extends SignalEmitter {
2344
2354
  isMeta,
2345
2355
  executionTraceId,
2346
2356
  context: isNewTrace ? contextData.id : contextData,
2347
- previousRoutineExecution: (_l = (_k = context.__metadata) == null ? void 0 : _k.__routineExecId) != null ? _l : null,
2357
+ previousRoutineExecution: (_m = (_l = context.__metadata) == null ? void 0 : _l.__routineExecId) != null ? _m : null,
2348
2358
  // TODO: There is a chance this is not added to the database yet...
2349
2359
  created: formatTimestamp(Date.now())
2360
+ },
2361
+ __metadata: {
2362
+ __executionTraceId: executionTraceId
2350
2363
  }
2351
2364
  });
2352
2365
  }