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.
- package/dist/ArvoEventHandler/index.d.ts +2 -3
- package/dist/ArvoEventHandler/index.js +52 -70
- package/dist/ArvoEventHandler/types.d.ts +3 -2
- package/dist/ArvoOrchestrationUtils/createEmitableEvent.js +1 -1
- package/dist/ArvoOrchestrationUtils/handlerErrors.d.ts +3 -2
- package/dist/ArvoOrchestrationUtils/handlerErrors.js +25 -22
- package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/index.d.ts +5 -3
- package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/index.js +135 -142
- package/dist/ArvoOrchestrationUtils/servicesValidation.d.ts +22 -0
- package/dist/ArvoOrchestrationUtils/servicesValidation.js +56 -0
- package/dist/ArvoOrchestrationUtils/types.d.ts +7 -1
- package/dist/ArvoOrchestrationUtils/types.js +7 -0
- package/dist/ArvoOrchestrator/factory.d.ts +2 -2
- package/dist/ArvoOrchestrator/factory.js +2 -1
- package/dist/ArvoOrchestrator/index.d.ts +2 -1
- package/dist/ArvoOrchestrator/index.js +23 -8
- package/dist/ArvoOrchestrator/types.d.ts +16 -19
- package/dist/ArvoResumable/factory.d.ts +2 -0
- package/dist/ArvoResumable/factory.js +6 -25
- package/dist/ArvoResumable/index.d.ts +5 -3
- package/dist/ArvoResumable/index.js +20 -3
- package/dist/IArvoEventHandler/index.d.ts +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +3 -3
- package/dist/types.d.ts +8 -0
- package/package.json +2 -2
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { type SpanOptions } from '@opentelemetry/api';
|
|
2
1
|
import { type ArvoContract, type ArvoEvent } from 'arvo-core';
|
|
3
2
|
import type IArvoEventHandler from '../IArvoEventHandler';
|
|
4
|
-
import type { ArvoEventHandlerOpenTelemetryOptions } from '../types';
|
|
3
|
+
import type { ArvoEventHandlerOpenTelemetryOptions, ArvoEventHandlerOtelSpanOptions } from '../types';
|
|
5
4
|
import type { ArvoEventHandlerFunction, ArvoEventHandlerParam } from './types';
|
|
6
5
|
/**
|
|
7
6
|
* `ArvoEventHandler` is the foundational component for building stateless,
|
|
@@ -89,7 +88,7 @@ export default class ArvoEventHandler<TContract extends ArvoContract> implements
|
|
|
89
88
|
/** Computational cost metric associated with event handling operations */
|
|
90
89
|
readonly executionunits: number;
|
|
91
90
|
/** OpenTelemetry configuration for event handling spans */
|
|
92
|
-
readonly spanOptions:
|
|
91
|
+
readonly spanOptions: ArvoEventHandlerOtelSpanOptions;
|
|
93
92
|
/** Version-specific event handler implementation map */
|
|
94
93
|
readonly handler: ArvoEventHandlerFunction<TContract>;
|
|
95
94
|
/** The source identifier for events produced by this handler */
|
|
@@ -61,6 +61,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
61
61
|
var api_1 = require("@opentelemetry/api");
|
|
62
62
|
var arvo_core_1 = require("arvo-core");
|
|
63
63
|
var ArvoDomain_1 = require("../ArvoDomain");
|
|
64
|
+
var handlerErrors_1 = require("../ArvoOrchestrationUtils/handlerErrors");
|
|
65
|
+
var orchestrationExecutionWrapper_1 = require("../ArvoOrchestrationUtils/orchestrationExecutionWrapper");
|
|
64
66
|
var errors_1 = require("../errors");
|
|
65
67
|
var utils_1 = require("../utils");
|
|
66
68
|
/**
|
|
@@ -208,32 +210,32 @@ var ArvoEventHandler = /** @class */ (function () {
|
|
|
208
210
|
* in handler configuration, or when contract URI mismatch occurs
|
|
209
211
|
* @throws {ExecutionViolation} for explicitly handled runtime errors that should bubble up
|
|
210
212
|
*/
|
|
211
|
-
ArvoEventHandler.prototype.execute = function (
|
|
212
|
-
return __awaiter(this,
|
|
213
|
+
ArvoEventHandler.prototype.execute = function (event, opentelemetry) {
|
|
214
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
213
215
|
var otelConfig;
|
|
214
216
|
var _this = this;
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
return __generator(this, function (_a) {
|
|
219
|
-
switch (_a.label) {
|
|
217
|
+
var _a, _b;
|
|
218
|
+
return __generator(this, function (_c) {
|
|
219
|
+
switch (_c.label) {
|
|
220
220
|
case 0:
|
|
221
|
-
otelConfig = (0, utils_1.createEventHandlerTelemetryConfig)(
|
|
221
|
+
otelConfig = (0, utils_1.createEventHandlerTelemetryConfig)(((_b = (_a = this.spanOptions).spanName) === null || _b === void 0 ? void 0 : _b.call(_a, { selfContractUri: this.contract.uri, consumedEvent: event })) ||
|
|
222
|
+
"Handler<".concat(this.contract.uri, ">"), this.spanOptions, opentelemetry !== null && opentelemetry !== void 0 ? opentelemetry : { inheritFrom: 'EVENT' }, event);
|
|
222
223
|
return [4 /*yield*/, arvo_core_1.ArvoOpenTelemetry.getInstance().startActiveSpan(__assign(__assign({}, otelConfig), { fn: function (span) { return __awaiter(_this, void 0, void 0, function () {
|
|
223
|
-
var otelSpanHeaders, _i, _a, _b, key, value, parsedDataSchema, handlerContract_1, inputEventValidation, _handleOutput, outputs, result, _c, outputs_1, item, __extensions, handlerResult, domains, _d, _e, _dom, _f, _g, _h, key, value, error_1,
|
|
224
|
-
var
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
switch (_z.label) {
|
|
224
|
+
var otelSpanHeaders, _i, _a, _b, key, value, parsedDataSchema, handlerContract_1, inputEventValidation, _handleOutput, outputs, result, _c, outputs_1, item, __extensions, handlerResult, domains, _d, _e, _dom, _f, _g, _h, key, value, error_1, errorEvents, _j, _k, _l, errEvtIdx, errEvt, _m, _o, _p, key, value;
|
|
225
|
+
var _q, _r, _s, _t, _u, _v;
|
|
226
|
+
return __generator(this, function (_w) {
|
|
227
|
+
switch (_w.label) {
|
|
228
228
|
case 0:
|
|
229
229
|
otelSpanHeaders = (0, arvo_core_1.currentOpenTelemetryHeaders)();
|
|
230
|
-
|
|
230
|
+
_w.label = 1;
|
|
231
231
|
case 1:
|
|
232
|
-
|
|
232
|
+
_w.trys.push([1, 3, 4, 5]);
|
|
233
|
+
span.setAttribute('arvo.handler.execution.status', 'normal');
|
|
234
|
+
span.setAttribute('arvo.handler.execution.type', 'handler');
|
|
233
235
|
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
234
236
|
for (_i = 0, _a = Object.entries(event.otelAttributes); _i < _a.length; _i++) {
|
|
235
237
|
_b = _a[_i], key = _b[0], value = _b[1];
|
|
236
|
-
span.setAttribute("
|
|
238
|
+
span.setAttribute("consumable.0.".concat(key), value);
|
|
237
239
|
}
|
|
238
240
|
if (this.contract.type !== event.type) {
|
|
239
241
|
throw new errors_1.ConfigViolation("Event type mismatch: Received '".concat(event.type, "', expected '").concat(this.contract.type, "'"));
|
|
@@ -256,9 +258,9 @@ var ArvoEventHandler = /** @class */ (function () {
|
|
|
256
258
|
});
|
|
257
259
|
}
|
|
258
260
|
try {
|
|
259
|
-
handlerContract_1 = this.contract.version((
|
|
261
|
+
handlerContract_1 = this.contract.version((_q = parsedDataSchema === null || parsedDataSchema === void 0 ? void 0 : parsedDataSchema.version) !== null && _q !== void 0 ? _q : 'latest');
|
|
260
262
|
}
|
|
261
|
-
catch (
|
|
263
|
+
catch (_x) {
|
|
262
264
|
throw new errors_1.ConfigViolation("Invalid contract version: ".concat(parsedDataSchema === null || parsedDataSchema === void 0 ? void 0 : parsedDataSchema.version, ". Available versions: ").concat(Object.keys(this.contract.versions).join(', ')));
|
|
263
265
|
}
|
|
264
266
|
(0, arvo_core_1.logToSpan)({
|
|
@@ -289,7 +291,7 @@ var ArvoEventHandler = /** @class */ (function () {
|
|
|
289
291
|
spanHeaders: otelSpanHeaders,
|
|
290
292
|
})];
|
|
291
293
|
case 2:
|
|
292
|
-
_handleOutput =
|
|
294
|
+
_handleOutput = _w.sent();
|
|
293
295
|
if (!_handleOutput)
|
|
294
296
|
return [2 /*return*/, {
|
|
295
297
|
events: [],
|
|
@@ -306,85 +308,65 @@ var ArvoEventHandler = /** @class */ (function () {
|
|
|
306
308
|
item = outputs_1[_c];
|
|
307
309
|
try {
|
|
308
310
|
__extensions = item.__extensions, handlerResult = __rest(item, ["__extensions"]);
|
|
309
|
-
domains = (
|
|
311
|
+
domains = (_s = (_r = handlerResult.domain) === null || _r === void 0 ? void 0 : _r.map(function (item) {
|
|
310
312
|
return (0, ArvoDomain_1.resolveEventDomain)({
|
|
311
313
|
domainToResolve: item,
|
|
312
314
|
handlerSelfContract: handlerContract_1,
|
|
313
315
|
eventContract: handlerContract_1,
|
|
314
316
|
triggeringEvent: event,
|
|
315
317
|
});
|
|
316
|
-
})) !== null &&
|
|
318
|
+
})) !== null && _s !== void 0 ? _s : [null];
|
|
317
319
|
for (_d = 0, _e = Array.from(new Set(domains)); _d < _e.length; _d++) {
|
|
318
320
|
_dom = _e[_d];
|
|
319
321
|
result.push((0, arvo_core_1.createArvoEventFactory)(handlerContract_1).emits(__assign(__assign({}, handlerResult), { traceparent: otelSpanHeaders.traceparent || undefined, tracestate: otelSpanHeaders.tracestate || undefined, source: this.source, subject: event.subject,
|
|
320
322
|
// 'source'
|
|
321
323
|
// prioritise returned 'to', 'redirectto' and then
|
|
322
|
-
to: (0, utils_1.coalesceOrDefault)([handlerResult.to, event.redirectto], event.source), executionunits: (0, utils_1.coalesce)(handlerResult.executionunits, this.executionunits), accesscontrol: (
|
|
324
|
+
to: (0, utils_1.coalesceOrDefault)([handlerResult.to, event.redirectto], event.source), executionunits: (0, utils_1.coalesce)(handlerResult.executionunits, this.executionunits), accesscontrol: (_u = (_t = handlerResult.accesscontrol) !== null && _t !== void 0 ? _t : event.accesscontrol) !== null && _u !== void 0 ? _u : undefined, parentid: event.id, domain: _dom }), __extensions));
|
|
323
325
|
for (_f = 0, _g = Object.entries(result[result.length - 1].otelAttributes); _f < _g.length; _f++) {
|
|
324
326
|
_h = _g[_f], key = _h[0], value = _h[1];
|
|
325
|
-
span.setAttribute("
|
|
327
|
+
span.setAttribute("emittables.".concat(result.length - 1, ".").concat(key), value);
|
|
326
328
|
}
|
|
327
329
|
}
|
|
328
330
|
}
|
|
329
331
|
catch (e) {
|
|
330
|
-
throw new errors_1.ContractViolation((
|
|
332
|
+
throw new errors_1.ContractViolation((_v = e === null || e === void 0 ? void 0 : e.message) !== null && _v !== void 0 ? _v : 'Invalid data');
|
|
331
333
|
}
|
|
332
334
|
}
|
|
333
|
-
(0,
|
|
334
|
-
level: 'INFO',
|
|
335
|
-
message: "Event processing completed successfully. Generated ".concat(result.length, " event(s)"),
|
|
336
|
-
});
|
|
337
|
-
(0, arvo_core_1.logToSpan)({
|
|
338
|
-
level: 'INFO',
|
|
339
|
-
message: 'Event handled successfully',
|
|
340
|
-
});
|
|
341
|
-
return [2 /*return*/, {
|
|
342
|
-
events: result,
|
|
343
|
-
}];
|
|
335
|
+
return [2 /*return*/, (0, orchestrationExecutionWrapper_1.returnEventsWithLogging)({ events: result }, span)];
|
|
344
336
|
case 3:
|
|
345
|
-
error_1 =
|
|
337
|
+
error_1 = _w.sent();
|
|
338
|
+
span.setAttribute('arvo.handler.execution.status', 'failure');
|
|
346
339
|
(0, arvo_core_1.exceptionToSpan)(error_1);
|
|
347
340
|
span.setStatus({
|
|
348
341
|
code: api_1.SpanStatusCode.ERROR,
|
|
349
342
|
message: "Event processing failed: ".concat(error_1.message),
|
|
350
343
|
});
|
|
351
|
-
if (
|
|
344
|
+
if ((0, arvo_core_1.isViolationError)(error_1)) {
|
|
352
345
|
throw error_1;
|
|
353
346
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
:
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
error: error_1,
|
|
373
|
-
executionunits: this.executionunits,
|
|
374
|
-
traceparent: (_v = otelSpanHeaders.traceparent) !== null && _v !== void 0 ? _v : undefined,
|
|
375
|
-
tracestate: (_w = otelSpanHeaders.tracestate) !== null && _w !== void 0 ? _w : undefined,
|
|
376
|
-
accesscontrol: (_x = event.accesscontrol) !== null && _x !== void 0 ? _x : undefined,
|
|
377
|
-
parentid: (_y = event.id) !== null && _y !== void 0 ? _y : undefined,
|
|
378
|
-
domain: _dom,
|
|
379
|
-
}));
|
|
380
|
-
for (_l = 0, _m = Object.entries(result[result.length - 1].otelAttributes); _l < _m.length; _l++) {
|
|
381
|
-
_o = _m[_l], key = _o[0], value = _o[1];
|
|
382
|
-
span.setAttribute("to_emit.".concat(result.length - 1, ".").concat(key), value);
|
|
347
|
+
errorEvents = (0, handlerErrors_1.createSystemErrorEvents)({
|
|
348
|
+
error: error_1,
|
|
349
|
+
event: event,
|
|
350
|
+
otelHeaders: otelSpanHeaders,
|
|
351
|
+
orchestrationParentSubject: null,
|
|
352
|
+
initEventId: event.id,
|
|
353
|
+
selfContract: this.contract.version('any'),
|
|
354
|
+
systemErrorDomain: undefined,
|
|
355
|
+
executionunits: this.executionunits,
|
|
356
|
+
source: this.source,
|
|
357
|
+
domain: this.domain,
|
|
358
|
+
handlerType: 'handler',
|
|
359
|
+
});
|
|
360
|
+
for (_j = 0, _k = Object.entries(errorEvents); _j < _k.length; _j++) {
|
|
361
|
+
_l = _k[_j], errEvtIdx = _l[0], errEvt = _l[1];
|
|
362
|
+
for (_m = 0, _o = Object.entries(errEvt.otelAttributes); _m < _o.length; _m++) {
|
|
363
|
+
_p = _o[_m], key = _p[0], value = _p[1];
|
|
364
|
+
span.setAttribute("emittables.".concat(errEvtIdx, ".").concat(key), value);
|
|
383
365
|
}
|
|
384
366
|
}
|
|
385
|
-
return [2 /*return*/, {
|
|
386
|
-
events:
|
|
387
|
-
}];
|
|
367
|
+
return [2 /*return*/, (0, orchestrationExecutionWrapper_1.returnEventsWithLogging)({
|
|
368
|
+
events: errorEvents,
|
|
369
|
+
}, span)];
|
|
388
370
|
case 4:
|
|
389
371
|
span.end();
|
|
390
372
|
return [7 /*endfinally*/];
|
|
@@ -392,7 +374,7 @@ var ArvoEventHandler = /** @class */ (function () {
|
|
|
392
374
|
}
|
|
393
375
|
});
|
|
394
376
|
}); } }))];
|
|
395
|
-
case 1: return [2 /*return*/,
|
|
377
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
396
378
|
}
|
|
397
379
|
});
|
|
398
380
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { Span
|
|
1
|
+
import type { Span } from '@opentelemetry/api';
|
|
2
2
|
import type { ArvoContract, ArvoEvent, ArvoSemanticVersion, CreateArvoEvent, InferArvoEvent, OpenTelemetryHeaders, VersionedArvoContract } from 'arvo-core';
|
|
3
3
|
import type { z } from 'zod';
|
|
4
|
+
import type { ArvoEventHandlerOtelSpanOptions } from '../types';
|
|
4
5
|
/**
|
|
5
6
|
* Represents the input for an ArvoEvent handler function.
|
|
6
7
|
*/
|
|
@@ -90,7 +91,7 @@ export type ArvoEventHandlerParam<TContract extends ArvoContract> = {
|
|
|
90
91
|
/**
|
|
91
92
|
* The OpenTelemetry span options
|
|
92
93
|
*/
|
|
93
|
-
spanOptions?:
|
|
94
|
+
spanOptions?: ArvoEventHandlerOtelSpanOptions;
|
|
94
95
|
/**
|
|
95
96
|
* Optional configuration to customize where system error events are emitted.
|
|
96
97
|
*
|
|
@@ -151,7 +151,7 @@ var processRawEventsIntoEmittables = function (params, span) {
|
|
|
151
151
|
emittables.push(evt);
|
|
152
152
|
for (var _e = 0, _f = Object.entries(emittables[emittables.length - 1].otelAttributes); _e < _f.length; _e++) {
|
|
153
153
|
var _g = _f[_e], key = _g[0], value = _g[1];
|
|
154
|
-
span.setAttribute("
|
|
154
|
+
span.setAttribute("emittables.".concat(emittables.length - 1, ".").concat(key), value);
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
}
|
|
@@ -2,7 +2,7 @@ import { type Span } from '@opentelemetry/api';
|
|
|
2
2
|
import { type ArvoEvent, type ArvoOrchestratorContract, type ArvoSemanticVersion, type OpenTelemetryHeaders, type VersionedArvoContract, type ViolationError } from 'arvo-core';
|
|
3
3
|
import type { SyncEventResource } from '../SyncEventResource';
|
|
4
4
|
import type { OrchestrationExecutionMemoryRecord } from './orchestrationExecutionState';
|
|
5
|
-
import type
|
|
5
|
+
import { type ArvoOrchestrationHandlerType } from './types';
|
|
6
6
|
/**
|
|
7
7
|
* Parameters for system error event creation
|
|
8
8
|
*/
|
|
@@ -17,11 +17,12 @@ export type CreateSystemErrorEventsParams = {
|
|
|
17
17
|
executionunits: number;
|
|
18
18
|
source: string;
|
|
19
19
|
domain: string | null;
|
|
20
|
+
handlerType: ArvoOrchestrationHandlerType;
|
|
20
21
|
};
|
|
21
22
|
/**
|
|
22
23
|
* Creates system error events
|
|
23
24
|
*/
|
|
24
|
-
export declare const createSystemErrorEvents: ({ error, event, otelHeaders, orchestrationParentSubject, initEventId, selfContract, systemErrorDomain, executionunits, source, domain, }: CreateSystemErrorEventsParams & {
|
|
25
|
+
export declare const createSystemErrorEvents: ({ error, event, otelHeaders, orchestrationParentSubject: _orchestrationParentSubject, initEventId, selfContract, systemErrorDomain, executionunits, source, domain, handlerType, }: CreateSystemErrorEventsParams & {
|
|
25
26
|
error: Error;
|
|
26
27
|
}) => ArvoEvent[];
|
|
27
28
|
export declare const handleOrchestrationErrors: (_handlerType: ArvoOrchestrationHandlerType, param: CreateSystemErrorEventsParams & {
|
|
@@ -53,26 +53,31 @@ var arvo_core_1 = require("arvo-core");
|
|
|
53
53
|
var ArvoDomain_1 = require("../ArvoDomain");
|
|
54
54
|
var errors_1 = require("../errors");
|
|
55
55
|
var utils_1 = require("../utils");
|
|
56
|
+
var types_1 = require("./types");
|
|
56
57
|
/**
|
|
57
58
|
* Creates system error events
|
|
58
59
|
*/
|
|
59
60
|
var createSystemErrorEvents = function (_a) {
|
|
60
|
-
var _b, _c, _d, _e;
|
|
61
|
-
var error = _a.error, event = _a.event, otelHeaders = _a.otelHeaders,
|
|
61
|
+
var _b, _c, _d, _e, _f;
|
|
62
|
+
var error = _a.error, event = _a.event, otelHeaders = _a.otelHeaders, _orchestrationParentSubject = _a.orchestrationParentSubject, initEventId = _a.initEventId, selfContract = _a.selfContract, systemErrorDomain = _a.systemErrorDomain, executionunits = _a.executionunits, source = _a.source, domain = _a.domain, handlerType = _a.handlerType;
|
|
62
63
|
// In case of none transaction errors like errors from
|
|
63
64
|
// the machine or the event creation etc, the are workflow
|
|
64
65
|
// error and shuold be handled by the workflow. Then are
|
|
65
66
|
// called system error and must be sent
|
|
66
67
|
// to the initiator. In as good of a format as possible
|
|
67
68
|
var parsedEventSubject = null;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
69
|
+
var orchestrationParentSubject = null;
|
|
70
|
+
if (handlerType === 'orchestrator' || handlerType === 'resumable') {
|
|
71
|
+
orchestrationParentSubject = _orchestrationParentSubject;
|
|
72
|
+
try {
|
|
73
|
+
parsedEventSubject = arvo_core_1.ArvoOrchestrationSubject.parse(event.subject);
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
(0, arvo_core_1.logToSpan)({
|
|
77
|
+
level: 'WARNING',
|
|
78
|
+
message: "Unable to parse event subject: ".concat(e.message),
|
|
79
|
+
});
|
|
80
|
+
}
|
|
76
81
|
}
|
|
77
82
|
var domainSets = new Set(systemErrorDomain
|
|
78
83
|
? systemErrorDomain.map(function (item) {
|
|
@@ -85,9 +90,10 @@ var createSystemErrorEvents = function (_a) {
|
|
|
85
90
|
})
|
|
86
91
|
: [event.domain, domain, null]);
|
|
87
92
|
var result = [];
|
|
88
|
-
for (var _i = 0,
|
|
89
|
-
var _dom =
|
|
90
|
-
|
|
93
|
+
for (var _i = 0, _g = Array.from(domainSets); _i < _g.length; _i++) {
|
|
94
|
+
var _dom = _g[_i];
|
|
95
|
+
var factoryBuilder = handlerType === 'handler' ? arvo_core_1.createArvoEventFactory : arvo_core_1.createArvoOrchestratorEventFactory;
|
|
96
|
+
result.push(factoryBuilder(selfContract).systemError({
|
|
91
97
|
source: source,
|
|
92
98
|
// If the initiator of the workflow exist then match the
|
|
93
99
|
// subject so that it can incorporate it in its state. If
|
|
@@ -96,11 +102,11 @@ var createSystemErrorEvents = function (_a) {
|
|
|
96
102
|
subject: orchestrationParentSubject !== null && orchestrationParentSubject !== void 0 ? orchestrationParentSubject : event.subject,
|
|
97
103
|
// The system error must always go back to
|
|
98
104
|
// the source which initiated it
|
|
99
|
-
to: (_b = parsedEventSubject === null || parsedEventSubject === void 0 ? void 0 : parsedEventSubject.execution.initiator) !== null &&
|
|
105
|
+
to: (_c = (_b = parsedEventSubject === null || parsedEventSubject === void 0 ? void 0 : parsedEventSubject.execution) === null || _b === void 0 ? void 0 : _b.initiator) !== null && _c !== void 0 ? _c : event.source,
|
|
100
106
|
error: error,
|
|
101
|
-
traceparent: (
|
|
102
|
-
tracestate: (
|
|
103
|
-
accesscontrol: (
|
|
107
|
+
traceparent: (_d = otelHeaders.traceparent) !== null && _d !== void 0 ? _d : undefined,
|
|
108
|
+
tracestate: (_e = otelHeaders.tracestate) !== null && _e !== void 0 ? _e : undefined,
|
|
109
|
+
accesscontrol: (_f = event.accesscontrol) !== null && _f !== void 0 ? _f : undefined,
|
|
104
110
|
executionunits: executionunits,
|
|
105
111
|
// If there is initEventID then use that.
|
|
106
112
|
// Otherwise, use event id. If the error is in init event
|
|
@@ -118,10 +124,7 @@ var handleOrchestrationErrors = function (_handlerType, param, span) { return __
|
|
|
118
124
|
return __generator(this, function (_f) {
|
|
119
125
|
switch (_f.label) {
|
|
120
126
|
case 0:
|
|
121
|
-
handlerType =
|
|
122
|
-
orchestrator: 'ArvoOrchestrator',
|
|
123
|
-
resumable: 'ArvoResumable',
|
|
124
|
-
}[_handlerType];
|
|
127
|
+
handlerType = types_1.ArvoOrchestrationHandlerMap[_handlerType];
|
|
125
128
|
error = (0, utils_1.isError)(param.error)
|
|
126
129
|
? param.error
|
|
127
130
|
: new errors_1.ExecutionViolation("Non-Error object thrown during machine execution: ".concat(typeof param.error, ". This indicates a serious implementation flaw."));
|
|
@@ -171,7 +174,7 @@ var handleOrchestrationErrors = function (_handlerType, param, span) { return __
|
|
|
171
174
|
_b = _a[_i], errEvtIdx = _b[0], errEvt = _b[1];
|
|
172
175
|
for (_c = 0, _d = Object.entries(errEvt.otelAttributes); _c < _d.length; _c++) {
|
|
173
176
|
_e = _d[_c], key = _e[0], value = _e[1];
|
|
174
|
-
span.setAttribute("
|
|
177
|
+
span.setAttribute("emittables.".concat(errEvtIdx, ".").concat(key), value);
|
|
175
178
|
}
|
|
176
179
|
}
|
|
177
180
|
return [2 /*return*/, {
|
|
@@ -2,13 +2,12 @@ import { type Span } from '@opentelemetry/api';
|
|
|
2
2
|
import { type ArvoEvent, type ArvoOrchestrationSubjectContent, type ArvoOrchestratorContract, type ArvoSemanticVersion, type OpenTelemetryHeaders, type VersionedArvoContract } from 'arvo-core';
|
|
3
3
|
import type IArvoEventHandler from '../../IArvoEventHandler';
|
|
4
4
|
import type { SyncEventResource } from '../../SyncEventResource';
|
|
5
|
-
import type { ArvoEventHandlerOpenTelemetryOptions } from '../../types';
|
|
5
|
+
import type { ArvoEventHandlerOpenTelemetryOptions, ArvoEventHandlerOtelSpanOptions } from '../../types';
|
|
6
6
|
import type { OrchestrationExecutionMemoryRecord } from '../orchestrationExecutionState';
|
|
7
7
|
import type { ArvoOrchestrationHandlerType } from '../types';
|
|
8
8
|
export type OrchestrationExecutionContext<TState extends OrchestrationExecutionMemoryRecord<Record<string, any>>> = {
|
|
9
9
|
event: ArvoEvent;
|
|
10
10
|
opentelemetry: ArvoEventHandlerOpenTelemetryOptions;
|
|
11
|
-
spanName: string;
|
|
12
11
|
source: string;
|
|
13
12
|
syncEventResource: SyncEventResource<TState>;
|
|
14
13
|
executionunits: number;
|
|
@@ -16,6 +15,9 @@ export type OrchestrationExecutionContext<TState extends OrchestrationExecutionM
|
|
|
16
15
|
selfContract: VersionedArvoContract<ArvoOrchestratorContract, ArvoSemanticVersion>;
|
|
17
16
|
domain: string | null;
|
|
18
17
|
_handlerType: ArvoOrchestrationHandlerType;
|
|
18
|
+
spanOptions: ArvoEventHandlerOtelSpanOptions & {
|
|
19
|
+
spanName: NonNullable<ArvoEventHandlerOtelSpanOptions['spanName']>;
|
|
20
|
+
};
|
|
19
21
|
};
|
|
20
22
|
export type CoreExecutionFn<TState extends OrchestrationExecutionMemoryRecord<Record<string, any>>> = (params: {
|
|
21
23
|
span: any;
|
|
@@ -37,4 +39,4 @@ export declare const returnEventsWithLogging: (param: Awaited<ReturnType<IArvoEv
|
|
|
37
39
|
* - State management
|
|
38
40
|
* - Error handling and system error generation
|
|
39
41
|
*/
|
|
40
|
-
export declare const executeWithOrchestrationWrapper: <TState extends OrchestrationExecutionMemoryRecord<Record<string, any>>>({ event, opentelemetry,
|
|
42
|
+
export declare const executeWithOrchestrationWrapper: <TState extends OrchestrationExecutionMemoryRecord<Record<string, any>>>({ event, opentelemetry, spanOptions, source, syncEventResource, executionunits, systemErrorDomain, selfContract, domain, _handlerType, }: OrchestrationExecutionContext<TState>, coreExecutionFn: CoreExecutionFn<TState>) => Promise<Awaited<ReturnType<IArvoEventHandler["execute"]>>>;
|