arvo-event-handler 3.0.8 → 3.0.11

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.
@@ -50,6 +50,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
50
50
  exports.executeWithOrchestrationWrapper = exports.returnEventsWithLogging = void 0;
51
51
  var api_1 = require("@opentelemetry/api");
52
52
  var arvo_core_1 = require("arvo-core");
53
+ var utils_1 = require("../../utils");
53
54
  var handlerErrors_1 = require("../handlerErrors");
54
55
  var acquireLockWithValidation_1 = require("./acquireLockWithValidation");
55
56
  var validateAndParseSubject_1 = require("./validateAndParseSubject");
@@ -70,158 +71,150 @@ exports.returnEventsWithLogging = returnEventsWithLogging;
70
71
  * - Error handling and system error generation
71
72
  */
72
73
  var executeWithOrchestrationWrapper = function (_a, coreExecutionFn_1) { return __awaiter(void 0, [_a, coreExecutionFn_1], void 0, function (_b, coreExecutionFn) {
73
- var _c;
74
- var event = _b.event, opentelemetry = _b.opentelemetry, spanName = _b.spanName, source = _b.source, syncEventResource = _b.syncEventResource, executionunits = _b.executionunits, systemErrorDomain = _b.systemErrorDomain, selfContract = _b.selfContract, domain = _b.domain, _handlerType = _b._handlerType;
75
- return __generator(this, function (_d) {
76
- switch (_d.label) {
77
- case 0: return [4 /*yield*/, arvo_core_1.ArvoOpenTelemetry.getInstance().startActiveSpan({
78
- name: spanName,
79
- spanOptions: {
80
- kind: api_1.SpanKind.PRODUCER,
81
- attributes: __assign((_c = {}, _c[arvo_core_1.ArvoExecution.ATTR_SPAN_KIND] = arvo_core_1.ArvoExecutionSpanKind.ORCHESTRATOR, _c[arvo_core_1.OpenInference.ATTR_SPAN_KIND] = arvo_core_1.OpenInferenceSpanKind.CHAIN, _c), Object.fromEntries(Object.entries(event.otelAttributes).map(function (_a) {
82
- var key = _a[0], value = _a[1];
83
- return ["to_process.0.".concat(key), value];
84
- }))),
85
- },
86
- context: opentelemetry.inheritFrom === 'EVENT'
87
- ? {
88
- inheritFrom: 'TRACE_HEADERS',
89
- traceHeaders: {
90
- traceparent: event.traceparent,
91
- tracestate: event.tracestate,
92
- },
93
- }
94
- : {
95
- inheritFrom: 'CONTEXT',
96
- context: api_1.context.active(),
97
- },
98
- disableSpanManagement: true,
99
- fn: function (span) { return __awaiter(void 0, void 0, void 0, function () {
100
- var otelHeaders, orchestrationParentSubject, initEventId, acquiredLock, parsedEventSubject, state, _a, emittables, newState, i, _i, _b, _c, key, value, error_1, _d, errorToThrow, errorEvents;
101
- var _e, _f, _g, _h;
102
- return __generator(this, function (_j) {
103
- switch (_j.label) {
104
- case 0:
105
- (0, arvo_core_1.logToSpan)({
106
- level: 'INFO',
107
- message: "Starting execution for ".concat(event.type, " on subject ").concat(event.subject),
108
- }, span);
109
- otelHeaders = (0, arvo_core_1.currentOpenTelemetryHeaders)();
110
- orchestrationParentSubject = null;
111
- initEventId = null;
112
- acquiredLock = null;
113
- _j.label = 1;
114
- case 1:
115
- _j.trys.push([1, 6, 8, 10]);
116
- parsedEventSubject = (0, validateAndParseSubject_1.validateAndParseSubject)(event, source, syncEventResource, span, 'orchestrator');
117
- if (!parsedEventSubject) {
118
- return [2 /*return*/, (0, exports.returnEventsWithLogging)({ events: [] }, span)];
119
- }
120
- return [4 /*yield*/, (0, acquireLockWithValidation_1.acquireLockWithValidation)(syncEventResource, event, span)];
121
- case 2:
122
- // Lock acquisition
123
- acquiredLock = _j.sent();
124
- return [4 /*yield*/, syncEventResource.acquireState(event, span)];
125
- case 3:
126
- state = _j.sent();
127
- if ((state === null || state === void 0 ? void 0 : state.executionStatus) === 'failure') {
128
- (0, arvo_core_1.logToSpan)({
129
- level: 'WARNING',
130
- message: "The orchestration has failed in a previous event. Ignoring event id: ".concat(event.id, " with event subject: ").concat(event.subject),
131
- }, span);
132
- return [2 /*return*/, (0, exports.returnEventsWithLogging)({ events: [] }, span)];
133
- }
134
- orchestrationParentSubject = (_e = state === null || state === void 0 ? void 0 : state.parentSubject) !== null && _e !== void 0 ? _e : null;
135
- initEventId = (_f = state === null || state === void 0 ? void 0 : state.initEventId) !== null && _f !== void 0 ? _f : null;
136
- if (!state) {
74
+ var otelConfig;
75
+ var event = _b.event, opentelemetry = _b.opentelemetry, spanOptions = _b.spanOptions, source = _b.source, syncEventResource = _b.syncEventResource, executionunits = _b.executionunits, systemErrorDomain = _b.systemErrorDomain, selfContract = _b.selfContract, domain = _b.domain, _handlerType = _b._handlerType;
76
+ return __generator(this, function (_c) {
77
+ switch (_c.label) {
78
+ case 0:
79
+ otelConfig = (0, utils_1.createEventHandlerTelemetryConfig)(spanOptions.spanName({ selfContractUri: selfContract.uri, consumedEvent: event }), spanOptions, opentelemetry, event);
80
+ return [4 /*yield*/, arvo_core_1.ArvoOpenTelemetry.getInstance().startActiveSpan(__assign(__assign({}, otelConfig), { fn: function (span) { return __awaiter(void 0, void 0, void 0, function () {
81
+ var _i, _a, _b, key, value, otelHeaders, orchestrationParentSubject, initEventId, acquiredLock, parsedEventSubject, state, _c, emittables, newState, i, _d, _e, _f, key, value, error_1, _g, errorToThrow, errorEvents;
82
+ var _h, _j, _k, _l;
83
+ return __generator(this, function (_m) {
84
+ switch (_m.label) {
85
+ case 0:
86
+ span.setStatus({ code: api_1.SpanStatusCode.OK });
87
+ span.setAttribute('arvo.handler.execution.type', _handlerType);
88
+ span.setAttribute('arvo.handler.execution.status', 'normal');
89
+ for (_i = 0, _a = Object.entries(event.otelAttributes); _i < _a.length; _i++) {
90
+ _b = _a[_i], key = _b[0], value = _b[1];
91
+ span.setAttribute("consumable.0.".concat(key), value);
92
+ }
137
93
  (0, arvo_core_1.logToSpan)({
138
94
  level: 'INFO',
139
- message: "Initializing new execution state for subject: ".concat(event.subject),
140
- });
141
- if (event.type !== source) {
95
+ message: "Starting execution for ".concat(event.type, " on subject ").concat(event.subject),
96
+ }, span);
97
+ otelHeaders = (0, arvo_core_1.currentOpenTelemetryHeaders)();
98
+ orchestrationParentSubject = null;
99
+ initEventId = null;
100
+ acquiredLock = null;
101
+ _m.label = 1;
102
+ case 1:
103
+ _m.trys.push([1, 6, 8, 10]);
104
+ parsedEventSubject = (0, validateAndParseSubject_1.validateAndParseSubject)(event, source, syncEventResource, span, 'orchestrator');
105
+ if (!parsedEventSubject) {
106
+ return [2 /*return*/, (0, exports.returnEventsWithLogging)({ events: [] }, span)];
107
+ }
108
+ return [4 /*yield*/, (0, acquireLockWithValidation_1.acquireLockWithValidation)(syncEventResource, event, span)];
109
+ case 2:
110
+ // Lock acquisition
111
+ acquiredLock = _m.sent();
112
+ return [4 /*yield*/, syncEventResource.acquireState(event, span)];
113
+ case 3:
114
+ state = _m.sent();
115
+ if ((state === null || state === void 0 ? void 0 : state.executionStatus) === 'failure') {
116
+ span.setAttribute('arvo.handler.execution.status', state.executionStatus);
142
117
  (0, arvo_core_1.logToSpan)({
143
118
  level: 'WARNING',
144
- message: "Invalid initialization event detected. Expected type '".concat(source, "' but received '").concat(event.type, "'."),
119
+ message: "The orchestration has failed in a previous event. Ignoring event id: ".concat(event.id, " with event subject: ").concat(event.subject),
120
+ }, span);
121
+ span.setStatus({
122
+ code: api_1.SpanStatusCode.ERROR,
123
+ message: "The orchestration has failed in a previous event. Ignoring event id: ".concat(event.id, " with event subject: ").concat(event.subject),
145
124
  });
146
125
  return [2 /*return*/, (0, exports.returnEventsWithLogging)({ events: [] }, span)];
147
126
  }
148
- }
149
- else {
127
+ orchestrationParentSubject = (_h = state === null || state === void 0 ? void 0 : state.parentSubject) !== null && _h !== void 0 ? _h : null;
128
+ initEventId = (_j = state === null || state === void 0 ? void 0 : state.initEventId) !== null && _j !== void 0 ? _j : null;
129
+ if (!state) {
130
+ (0, arvo_core_1.logToSpan)({
131
+ level: 'INFO',
132
+ message: "Initializing new execution state for subject: ".concat(event.subject),
133
+ });
134
+ if (event.type !== source) {
135
+ (0, arvo_core_1.logToSpan)({
136
+ level: 'WARNING',
137
+ message: "Invalid initialization event detected. Expected type '".concat(source, "' but received '").concat(event.type, "'."),
138
+ });
139
+ return [2 /*return*/, (0, exports.returnEventsWithLogging)({ events: [] }, span)];
140
+ }
141
+ }
142
+ else {
143
+ (0, arvo_core_1.logToSpan)({
144
+ level: 'INFO',
145
+ message: "Resuming execution with existing state for subject: ".concat(event.subject),
146
+ });
147
+ }
148
+ // Extract parent subject from init event if applicable
149
+ if (event.type === source) {
150
+ orchestrationParentSubject = (_l = (_k = event === null || event === void 0 ? void 0 : event.data) === null || _k === void 0 ? void 0 : _k.parentSubject$$) !== null && _l !== void 0 ? _l : null;
151
+ }
152
+ return [4 /*yield*/, coreExecutionFn({
153
+ span: span,
154
+ otelHeaders: otelHeaders,
155
+ orchestrationParentSubject: orchestrationParentSubject,
156
+ initEventId: initEventId !== null && initEventId !== void 0 ? initEventId : event.id,
157
+ parsedEventSubject: parsedEventSubject,
158
+ state: state,
159
+ _handlerType: _handlerType,
160
+ })];
161
+ case 4:
162
+ _c = _m.sent(), emittables = _c.emittables, newState = _c.newState;
163
+ // Add OpenTelemetry attributes for emitted events
164
+ for (i = 0; i < emittables.length; i++) {
165
+ for (_d = 0, _e = Object.entries(emittables[i].otelAttributes); _d < _e.length; _d++) {
166
+ _f = _e[_d], key = _f[0], value = _f[1];
167
+ span.setAttribute("emittables.".concat(i, ".").concat(key), value);
168
+ }
169
+ }
170
+ // Persist state
171
+ return [4 /*yield*/, syncEventResource.persistState(event, newState, state, span)];
172
+ case 5:
173
+ // Persist state
174
+ _m.sent();
150
175
  (0, arvo_core_1.logToSpan)({
151
176
  level: 'INFO',
152
- message: "Resuming execution with existing state for subject: ".concat(event.subject),
177
+ message: "State update persisted in memory for subject ".concat(event.subject),
153
178
  });
154
- }
155
- // Extract parent subject from init event if applicable
156
- if (event.type === source) {
157
- orchestrationParentSubject = (_h = (_g = event === null || event === void 0 ? void 0 : event.data) === null || _g === void 0 ? void 0 : _g.parentSubject$$) !== null && _h !== void 0 ? _h : null;
158
- }
159
- return [4 /*yield*/, coreExecutionFn({
160
- span: span,
161
- otelHeaders: otelHeaders,
162
- orchestrationParentSubject: orchestrationParentSubject,
163
- initEventId: initEventId !== null && initEventId !== void 0 ? initEventId : event.id,
164
- parsedEventSubject: parsedEventSubject,
165
- state: state,
166
- _handlerType: _handlerType,
167
- })];
168
- case 4:
169
- _a = _j.sent(), emittables = _a.emittables, newState = _a.newState;
170
- span.setAttribute("arvo.".concat(_handlerType, ".execution.status"), newState.executionStatus);
171
- // Add OpenTelemetry attributes for emitted events
172
- for (i = 0; i < emittables.length; i++) {
173
- for (_i = 0, _b = Object.entries(emittables[i].otelAttributes); _i < _b.length; _i++) {
174
- _c = _b[_i], key = _c[0], value = _c[1];
175
- span.setAttribute("to_emit.".concat(i, ".").concat(key), value);
176
- }
177
- }
178
- // Persist state
179
- return [4 /*yield*/, syncEventResource.persistState(event, newState, state, span)];
180
- case 5:
181
- // Persist state
182
- _j.sent();
183
- (0, arvo_core_1.logToSpan)({
184
- level: 'INFO',
185
- message: "State update persisted in memory for subject ".concat(event.subject),
186
- });
187
- (0, arvo_core_1.logToSpan)({
188
- level: 'INFO',
189
- message: "Execution successfully completed and emitted ".concat(emittables.length, " events"),
190
- });
191
- return [2 /*return*/, (0, exports.returnEventsWithLogging)({ events: emittables }, span)];
192
- case 6:
193
- error_1 = _j.sent();
194
- return [4 /*yield*/, (0, handlerErrors_1.handleOrchestrationErrors)(_handlerType, {
195
- error: error_1,
196
- event: event,
197
- otelHeaders: otelHeaders,
198
- orchestrationParentSubject: orchestrationParentSubject,
199
- initEventId: initEventId,
200
- selfContract: selfContract,
201
- systemErrorDomain: systemErrorDomain,
202
- executionunits: executionunits,
203
- source: source,
204
- domain: domain,
205
- syncEventResource: syncEventResource,
206
- }, span)];
207
- case 7:
208
- _d = _j.sent(), errorToThrow = _d.errorToThrow, errorEvents = _d.events;
209
- if (errorToThrow)
210
- throw errorToThrow;
211
- return [2 /*return*/, {
212
- events: errorEvents,
213
- }];
214
- case 8: return [4 /*yield*/, syncEventResource.releaseLock(event, acquiredLock, span)];
215
- case 9:
216
- _j.sent();
217
- span.end();
218
- return [7 /*endfinally*/];
219
- case 10: return [2 /*return*/];
220
- }
221
- });
222
- }); },
223
- })];
224
- case 1: return [2 /*return*/, _d.sent()];
179
+ (0, arvo_core_1.logToSpan)({
180
+ level: 'INFO',
181
+ message: "Execution successfully completed and emitted ".concat(emittables.length, " events"),
182
+ });
183
+ return [2 /*return*/, (0, exports.returnEventsWithLogging)({ events: emittables }, span)];
184
+ case 6:
185
+ error_1 = _m.sent();
186
+ span.setAttribute('arvo.handler.execution.status', 'failure');
187
+ return [4 /*yield*/, (0, handlerErrors_1.handleOrchestrationErrors)(_handlerType, {
188
+ error: error_1,
189
+ event: event,
190
+ otelHeaders: otelHeaders,
191
+ orchestrationParentSubject: orchestrationParentSubject,
192
+ initEventId: initEventId,
193
+ selfContract: selfContract,
194
+ systemErrorDomain: systemErrorDomain,
195
+ executionunits: executionunits,
196
+ source: source,
197
+ domain: domain,
198
+ syncEventResource: syncEventResource,
199
+ handlerType: _handlerType,
200
+ }, span)];
201
+ case 7:
202
+ _g = _m.sent(), errorToThrow = _g.errorToThrow, errorEvents = _g.events;
203
+ if (errorToThrow)
204
+ throw errorToThrow;
205
+ return [2 /*return*/, {
206
+ events: errorEvents,
207
+ }];
208
+ case 8: return [4 /*yield*/, syncEventResource.releaseLock(event, acquiredLock, span)];
209
+ case 9:
210
+ _m.sent();
211
+ span.end();
212
+ return [7 /*endfinally*/];
213
+ case 10: return [2 /*return*/];
214
+ }
215
+ });
216
+ }); } }))];
217
+ case 1: return [2 /*return*/, _c.sent()];
225
218
  }
226
219
  });
227
220
  }); };
@@ -0,0 +1,22 @@
1
+ import type { ArvoContract, VersionedArvoContract } from 'arvo-core';
2
+ import { type ArvoOrchestrationHandlerType } from './types';
3
+ /**
4
+ * Validates that all service contracts in a collection have unique URIs.
5
+ *
6
+ * Iterates through the provided contracts and checks if any URI appears more than once.
7
+ * Multiple versions of the same contract (with the same URI) are not allowed.
8
+ *
9
+ * @param contracts - A record mapping contract keys to their respective ArvoContract objects
10
+ * @returns An object with a boolean result indicating if all contracts are unique, and the error keys if not
11
+ */
12
+ export declare const areServiceContractsUnique: (contracts: Record<string, ArvoContract | VersionedArvoContract<any, any>>) => {
13
+ result: false;
14
+ keys: [string, string];
15
+ contractUri: string;
16
+ } | {
17
+ result: true;
18
+ };
19
+ export declare const servicesValidation: (contracts: {
20
+ self: ArvoContract | VersionedArvoContract<any, any>;
21
+ services: Record<string, VersionedArvoContract<any, any>>;
22
+ }, _handlerType: ArvoOrchestrationHandlerType) => void;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.servicesValidation = exports.areServiceContractsUnique = void 0;
15
+ var uuid_1 = require("uuid");
16
+ var errors_1 = require("../errors");
17
+ var types_1 = require("./types");
18
+ /**
19
+ * Validates that all service contracts in a collection have unique URIs.
20
+ *
21
+ * Iterates through the provided contracts and checks if any URI appears more than once.
22
+ * Multiple versions of the same contract (with the same URI) are not allowed.
23
+ *
24
+ * @param contracts - A record mapping contract keys to their respective ArvoContract objects
25
+ * @returns An object with a boolean result indicating if all contracts are unique, and the error keys if not
26
+ */
27
+ var areServiceContractsUnique = function (contracts) {
28
+ var uriToKeyMap = {};
29
+ for (var _i = 0, _a = Object.entries(contracts); _i < _a.length; _i++) {
30
+ var _b = _a[_i], key = _b[0], contract = _b[1];
31
+ if (uriToKeyMap[contract.uri]) {
32
+ return {
33
+ result: false,
34
+ keys: [key, uriToKeyMap[contract.uri]],
35
+ contractUri: contract.uri,
36
+ };
37
+ }
38
+ uriToKeyMap[contract.uri] = key;
39
+ }
40
+ return {
41
+ result: true,
42
+ };
43
+ };
44
+ exports.areServiceContractsUnique = areServiceContractsUnique;
45
+ var servicesValidation = function (contracts, _handlerType) {
46
+ var _a;
47
+ var __areServiceContractsUnique = (0, exports.areServiceContractsUnique)(contracts.services);
48
+ if (!__areServiceContractsUnique.result) {
49
+ throw new errors_1.ConfigViolation("In ".concat(types_1.ArvoOrchestrationHandlerMap[_handlerType], ", the service contracts must have unique URIs. Multiple versions of the same contract are not allow. The contracts '").concat(__areServiceContractsUnique.keys[0], "' and '").concat(__areServiceContractsUnique.keys[1], "' have the same URI '").concat(__areServiceContractsUnique.contractUri, "'"));
50
+ }
51
+ var __checkIfSelfIsAService = (0, exports.areServiceContractsUnique)(__assign(__assign({}, contracts.services), (_a = {}, _a[(0, uuid_1.v4)()] = contracts.self, _a)));
52
+ if (!__checkIfSelfIsAService.result) {
53
+ throw new errors_1.ConfigViolation("In ".concat(types_1.ArvoOrchestrationHandlerMap[_handlerType], ", Circular dependency detected: Machine with URI '").concat(contracts.self.uri, "' is registered as service '").concat(__checkIfSelfIsAService.keys[1], "'. Self-referential services create execution loops and are prohibited."));
54
+ }
55
+ };
56
+ exports.servicesValidation = servicesValidation;
@@ -1 +1,7 @@
1
- export type ArvoOrchestrationHandlerType = 'orchestrator' | 'resumable';
1
+ export declare const ArvoOrchestrationHandlerMap: {
2
+ readonly orchestrator: "ArvoOrchestrator";
3
+ readonly resumable: "ArvoResumable";
4
+ readonly machine: "ArvoMachine";
5
+ readonly handler: "ArvoEventHandler";
6
+ };
7
+ export type ArvoOrchestrationHandlerType = keyof typeof ArvoOrchestrationHandlerMap;
@@ -1,2 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ArvoOrchestrationHandlerMap = void 0;
4
+ exports.ArvoOrchestrationHandlerMap = {
5
+ orchestrator: 'ArvoOrchestrator',
6
+ resumable: 'ArvoResumable',
7
+ machine: 'ArvoMachine',
8
+ handler: 'ArvoEventHandler',
9
+ };
@@ -1,5 +1,5 @@
1
1
  import { ArvoOrchestrator } from '.';
2
- import type { ICreateArvoOrchestrator } from './types';
2
+ import type { CreateArvoOrchestratorParam } from './types';
3
3
  /**
4
4
  * Creates a new Arvo orchestrator instance with default components.
5
5
  * For custom components, use ArvoOrchestrator constructor directly.
@@ -26,4 +26,4 @@ import type { ICreateArvoOrchestrator } from './types';
26
26
  * });
27
27
  * ```
28
28
  */
29
- export declare const createArvoOrchestrator: ({ executionunits, memory, machines, systemErrorDomain, }: ICreateArvoOrchestrator) => ArvoOrchestrator;
29
+ export declare const createArvoOrchestrator: ({ executionunits, memory, machines, systemErrorDomain, spanOptions, }: CreateArvoOrchestratorParam) => ArvoOrchestrator;
@@ -41,7 +41,7 @@ var errors_1 = require("../errors");
41
41
  * ```
42
42
  */
43
43
  var createArvoOrchestrator = function (_a) {
44
- var executionunits = _a.executionunits, memory = _a.memory, machines = _a.machines, systemErrorDomain = _a.systemErrorDomain;
44
+ var executionunits = _a.executionunits, memory = _a.memory, machines = _a.machines, systemErrorDomain = _a.systemErrorDomain, spanOptions = _a.spanOptions;
45
45
  if (!(machines === null || machines === void 0 ? void 0 : machines.length)) {
46
46
  throw new Error('At least one machine must be provided');
47
47
  }
@@ -66,6 +66,7 @@ var createArvoOrchestrator = function (_a) {
66
66
  executionEngine: new MachineExecutionEngine_1.MachineExecutionEngine(),
67
67
  requiresResourceLocking: requiresResourceLocking,
68
68
  systemErrorDomain: systemErrorDomain,
69
+ spanOptions: spanOptions,
69
70
  });
70
71
  };
71
72
  exports.createArvoOrchestrator = createArvoOrchestrator;
@@ -16,6 +16,7 @@ export declare class ArvoOrchestrator implements IArvoEventHandler {
16
16
  readonly executionEngine: IMachineExectionEngine;
17
17
  readonly syncEventResource: SyncEventResource<MachineMemoryRecord>;
18
18
  readonly systemErrorDomain?: (string | null)[];
19
+ private readonly spanOptions;
19
20
  get source(): any;
20
21
  get requiresResourceLocking(): boolean;
21
22
  get memory(): IMachineMemory<MachineMemoryRecord>;
@@ -25,7 +26,7 @@ export declare class ArvoOrchestrator implements IArvoEventHandler {
25
26
  * @param params - Configuration parameters
26
27
  * @throws Error if machines in registry have different sources
27
28
  */
28
- constructor({ executionunits, memory, registry, executionEngine, requiresResourceLocking, systemErrorDomain, }: ArvoOrchestratorParam);
29
+ constructor({ executionunits, memory, registry, executionEngine, requiresResourceLocking, systemErrorDomain, spanOptions, }: ArvoOrchestratorParam);
29
30
  /**
30
31
  * Core orchestration method that executes state machines in response to events.
31
32
  *
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -37,6 +48,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
48
  };
38
49
  Object.defineProperty(exports, "__esModule", { value: true });
39
50
  exports.ArvoOrchestrator = void 0;
51
+ var api_1 = require("@opentelemetry/api");
40
52
  var arvo_core_1 = require("arvo-core");
41
53
  var createEmitableEvent_1 = require("../ArvoOrchestrationUtils/createEmitableEvent");
42
54
  var orchestrationExecutionWrapper_1 = require("../ArvoOrchestrationUtils/orchestrationExecutionWrapper");
@@ -53,13 +65,16 @@ var ArvoOrchestrator = /** @class */ (function () {
53
65
  * @throws Error if machines in registry have different sources
54
66
  */
55
67
  function ArvoOrchestrator(_a) {
56
- var executionunits = _a.executionunits, memory = _a.memory, registry = _a.registry, executionEngine = _a.executionEngine, requiresResourceLocking = _a.requiresResourceLocking, systemErrorDomain = _a.systemErrorDomain;
68
+ var _b;
69
+ var executionunits = _a.executionunits, memory = _a.memory, registry = _a.registry, executionEngine = _a.executionEngine, requiresResourceLocking = _a.requiresResourceLocking, systemErrorDomain = _a.systemErrorDomain, spanOptions = _a.spanOptions;
70
+ var _c, _d, _e, _f, _g, _h, _j;
57
71
  this.systemErrorDomain = [];
58
72
  this.executionunits = executionunits;
59
73
  this.registry = registry;
60
74
  this.executionEngine = executionEngine;
61
75
  this.syncEventResource = new SyncEventResource_1.SyncEventResource(memory, requiresResourceLocking);
62
76
  this.systemErrorDomain = systemErrorDomain;
77
+ this.spanOptions = __assign(__assign({ kind: api_1.SpanKind.PRODUCER }, spanOptions), { attributes: __assign(__assign((_b = {}, _b[arvo_core_1.ArvoExecution.ATTR_SPAN_KIND] = arvo_core_1.ArvoExecutionSpanKind.ORCHESTRATOR, _b[arvo_core_1.OpenInference.ATTR_SPAN_KIND] = arvo_core_1.OpenInferenceSpanKind.CHAIN, _b), ((_c = spanOptions === null || spanOptions === void 0 ? void 0 : spanOptions.attributes) !== null && _c !== void 0 ? _c : {})), { 'arvo.handler.source': this.source, 'arvo.contract.uri': (_j = (_h = (_g = (_f = (_e = (_d = this === null || this === void 0 ? void 0 : this.registry) === null || _d === void 0 ? void 0 : _d.machines) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.contracts) === null || _g === void 0 ? void 0 : _g.self) === null || _h === void 0 ? void 0 : _h.uri) !== null && _j !== void 0 ? _j : 'N/A' }) });
63
78
  }
64
79
  Object.defineProperty(ArvoOrchestrator.prototype, "source", {
65
80
  get: function () {
@@ -101,19 +116,19 @@ var ArvoOrchestrator = /** @class */ (function () {
101
116
  * @throws {ContractViolation} Schema/contract mismatch
102
117
  * @throws {ConfigViolation} Missing/invalid machine version
103
118
  */
104
- ArvoOrchestrator.prototype.execute = function (event_1) {
105
- return __awaiter(this, arguments, void 0, function (event, opentelemetry) {
119
+ ArvoOrchestrator.prototype.execute = function (event, opentelemetry) {
120
+ return __awaiter(this, void 0, void 0, function () {
106
121
  var _this = this;
107
- if (opentelemetry === void 0) { opentelemetry = {
108
- inheritFrom: 'EVENT',
109
- }; }
110
122
  return __generator(this, function (_a) {
111
123
  switch (_a.label) {
112
124
  case 0: return [4 /*yield*/, (0, orchestrationExecutionWrapper_1.executeWithOrchestrationWrapper)({
113
125
  _handlerType: 'orchestrator',
114
126
  event: event,
115
- opentelemetry: opentelemetry,
116
- spanName: "Orchestrator<".concat(this.registry.machines[0].contracts.self.uri, ">@<").concat(event.type, ">"),
127
+ opentelemetry: opentelemetry !== null && opentelemetry !== void 0 ? opentelemetry : { inheritFrom: 'EVENT' },
128
+ spanOptions: __assign({ spanName: function (_a) {
129
+ var selfContractUri = _a.selfContractUri, consumedEvent = _a.consumedEvent;
130
+ return "Orchestrator<".concat(selfContractUri, ">@<").concat(consumedEvent.type, ">");
131
+ } }, this.spanOptions),
117
132
  source: this.source,
118
133
  syncEventResource: this.syncEventResource,
119
134
  executionunits: this.executionunits,
@@ -5,6 +5,7 @@ import type { OrchestrationExecutionMemoryRecord } from '../ArvoOrchestrationUti
5
5
  import type { IMachineExectionEngine } from '../MachineExecutionEngine/interface';
6
6
  import type { IMachineMemory } from '../MachineMemory/interface';
7
7
  import type { IMachineRegistry } from '../MachineRegistry/interface';
8
+ import type { ArvoEventHandlerOtelSpanOptions } from '../types';
8
9
  export type TryFunctionOutput<TData, TError extends Error> = {
9
10
  type: 'success';
10
11
  data: TData;
@@ -82,24 +83,6 @@ export type ArvoOrchestratorParam = {
82
83
  /** Engine responsible for machine execution */
83
84
  executionEngine: IMachineExectionEngine;
84
85
  requiresResourceLocking: boolean;
85
- /**
86
- * Optional configuration to customize where system error events are emitted.
87
- */
88
- systemErrorDomain?: (string | null)[];
89
- };
90
- /**
91
- * Configuration interface for creating an Arvo orchestrator instance.
92
- */
93
- export interface ICreateArvoOrchestrator {
94
- /** Memory interface for storing and retrieving machine state */
95
- memory: IMachineMemory<MachineMemoryRecord>;
96
- /** The cost of the execution of the orchestrator */
97
- executionunits: number;
98
- /**
99
- * Collection of state machines to be managed by the orchestrator.
100
- * All machines must have the same source identifier.
101
- */
102
- machines: ArvoMachine<any, any, any, any, any>[];
103
86
  /**
104
87
  * Optional configuration to customize where system error events are emitted.
105
88
  *
@@ -114,4 +97,18 @@ export interface ICreateArvoOrchestrator {
114
97
  * @default undefined — uses standard fallback broadcast domains
115
98
  */
116
99
  systemErrorDomain?: (string | null)[];
117
- }
100
+ /**
101
+ * The OpenTelemetry span options
102
+ */
103
+ spanOptions?: ArvoEventHandlerOtelSpanOptions;
104
+ };
105
+ /**
106
+ * Configuration interface for creating an Arvo orchestrator instance.
107
+ */
108
+ export type CreateArvoOrchestratorParam = Pick<ArvoOrchestratorParam, 'memory' | 'executionunits' | 'spanOptions' | 'systemErrorDomain'> & {
109
+ /**
110
+ * Collection of state machines to be managed by the orchestrator.
111
+ * All machines must have the same source identifier.
112
+ */
113
+ machines: ArvoMachine<any, any, any, any, any>[];
114
+ };
@@ -1,6 +1,7 @@
1
1
  import type { ArvoOrchestratorContract, VersionedArvoContract } from 'arvo-core';
2
2
  import { ArvoResumable } from '.';
3
3
  import type { IMachineMemory } from '../MachineMemory/interface';
4
+ import type { ArvoEventHandlerOtelSpanOptions } from '../types';
4
5
  import type { ArvoResumableHandler, ArvoResumableState } from './types';
5
6
  /**
6
7
  * Factory function for creating ArvoResumable orchestrator instances
@@ -39,4 +40,5 @@ export declare const createArvoResumable: <TMemory extends Record<string, any>,
39
40
  executionunits?: number;
40
41
  requiresResourceLocking?: boolean;
41
42
  systemErrorDomain?: (string | null)[];
43
+ spanOptions?: ArvoEventHandlerOtelSpanOptions;
42
44
  }) => ArvoResumable<TMemory, TSelfContract, TServiceContract>;