arvo-event-handler 2.0.4 → 2.1.1
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/CHANGELOG.md +4 -0
- package/dist/AbstractArvoEventHandler/index.d.ts +5 -18
- package/dist/ArvoEventHandler/helpers.d.ts +10 -21
- package/dist/ArvoEventHandler/helpers.js +10 -21
- package/dist/ArvoEventHandler/index.d.ts +56 -91
- package/dist/ArvoEventHandler/index.js +173 -204
- package/dist/ArvoEventHandler/types.d.ts +7 -30
- package/dist/ArvoEventRouter/helpers.d.ts +8 -25
- package/dist/ArvoEventRouter/helpers.js +8 -25
- package/dist/ArvoEventRouter/index.d.ts +47 -89
- package/dist/ArvoEventRouter/index.js +138 -155
- package/dist/ArvoEventRouter/types.d.ts +4 -22
- package/dist/MultiArvoEventHandler/index.d.ts +31 -96
- package/dist/MultiArvoEventHandler/index.js +97 -155
- package/dist/MultiArvoEventHandler/types.d.ts +6 -14
- package/dist/index.d.ts +2 -4
- package/dist/index.js +3 -5
- package/dist/types.d.ts +3 -0
- package/dist/utils.d.ts +18 -0
- package/dist/utils.js +18 -1
- package/package.json +2 -2
- package/dist/OpenTelemetry/index.d.ts +0 -4
- package/dist/OpenTelemetry/index.js +0 -11
- package/dist/OpenTelemetry/types.d.ts +0 -48
- package/dist/OpenTelemetry/types.js +0 -2
- package/dist/OpenTelemetry/utils.d.ts +0 -87
- package/dist/OpenTelemetry/utils.js +0 -133
|
@@ -1,113 +1,48 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ArvoEvent
|
|
3
|
-
import { IMultiArvoEventHandler } from './types';
|
|
1
|
+
import { SpanOptions } from '@opentelemetry/api';
|
|
2
|
+
import { ArvoEvent } from 'arvo-core';
|
|
3
|
+
import { IMultiArvoEventHandler, MultiArvoEventHandlerFunction } from './types';
|
|
4
4
|
import AbstractArvoEventHandler from '../AbstractArvoEventHandler';
|
|
5
|
-
import {
|
|
5
|
+
import { ArvoEventHandlerOpenTelemetryOptions } from '../types';
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* MultiArvoEventHandler processes multiple event types without being bound to specific contracts.
|
|
8
|
+
* Manages event execution, telemetry tracking, and error handling for diverse event streams.
|
|
8
9
|
*
|
|
9
|
-
* @
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
* @example
|
|
11
|
+
* const handler = createMultiArvoEventHandler({
|
|
12
|
+
* source: "order.handler",
|
|
13
|
+
* executionunits: 1,
|
|
14
|
+
* handler: async ({ event }) => {
|
|
15
|
+
* // Handle multiple event types
|
|
16
|
+
* }
|
|
17
|
+
* });
|
|
14
18
|
*/
|
|
15
19
|
export default class MultiArvoEventHandler extends AbstractArvoEventHandler {
|
|
16
|
-
/**
|
|
20
|
+
/** Computational cost metric for handler operations */
|
|
17
21
|
readonly executionunits: number;
|
|
18
|
-
/**
|
|
19
|
-
* The source identifier for events produced by this handler
|
|
20
|
-
*
|
|
21
|
-
* @remarks
|
|
22
|
-
* The handler listens to the events with field `event.to` equal
|
|
23
|
-
* to the this `source` value. If the event does not confirm to
|
|
24
|
-
* this, a system error event is returned
|
|
25
|
-
*
|
|
26
|
-
* For all the events which are emitted by the handler, this is
|
|
27
|
-
* the source field value of them all.
|
|
28
|
-
*/
|
|
22
|
+
/** Source identifier for event routing */
|
|
29
23
|
readonly source: string;
|
|
30
|
-
|
|
31
|
-
readonly
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
/** OpenTelemetry configuration */
|
|
25
|
+
readonly spanOptions: SpanOptions;
|
|
26
|
+
/** Event processing function */
|
|
27
|
+
readonly handler: MultiArvoEventHandlerFunction;
|
|
34
28
|
/**
|
|
35
|
-
* Creates
|
|
36
|
-
*
|
|
37
|
-
* @
|
|
38
|
-
* @throws {Error} Throws an error if the provided source is invalid.
|
|
29
|
+
* Creates handler instance with specified configuration.
|
|
30
|
+
* @param param Handler configuration including source and execution parameters
|
|
31
|
+
* @throws When source contains invalid characters
|
|
39
32
|
*/
|
|
40
33
|
constructor(param: IMultiArvoEventHandler);
|
|
41
34
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* @param event - The event to handle.
|
|
45
|
-
* @param opentelemetry - Configuration for OpenTelemetry integration, including tracing options
|
|
46
|
-
* and context inheritance settings.
|
|
47
|
-
* @returns A promise that resolves to an array of resulting ArvoEvents.
|
|
48
|
-
*
|
|
49
|
-
* @remarks
|
|
50
|
-
* This method performs the following steps:
|
|
51
|
-
* 1. Creates an OpenTelemetry span for the execution.
|
|
52
|
-
* 2. Validates that the event's 'to' field matches the handler's 'source'.
|
|
53
|
-
* 3. Executes the handler function.
|
|
54
|
-
* 4. Creates and returns the result event(s).
|
|
55
|
-
* 5. Handles any errors and creates an error event if necessary.
|
|
56
|
-
*
|
|
57
|
-
* All telemetry data is properly set and propagated throughout the execution.
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```typescript
|
|
61
|
-
* const handler = new MultiArvoEventHandler({
|
|
62
|
-
* source: 'com.multi.handler',
|
|
63
|
-
* ...
|
|
64
|
-
* });
|
|
65
|
-
* const inputEvent: ArvoEvent = createArvoEvent({ ... });
|
|
66
|
-
* const resultEvents = await handler.execute(inputEvent);
|
|
67
|
-
* ```
|
|
35
|
+
* Processes an event through configured handler function. Creates telemetry span,
|
|
36
|
+
* validates event destination, executes handler, and manages errors.
|
|
68
37
|
*
|
|
69
|
-
* @
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* **Routing**
|
|
73
|
-
*
|
|
74
|
-
* The routing of the resulting events is determined as follows:
|
|
75
|
-
* - The `to` field of the output event is set in this priority:
|
|
76
|
-
* 1. The `to` field provided by the handler result
|
|
77
|
-
* 2. The `redirectto` field from the input event
|
|
78
|
-
* 3. The `source` field from the input event (as a form of reply)
|
|
79
|
-
* - For system error events, the `to` field is always set to the `source` of the input event.
|
|
80
|
-
*
|
|
81
|
-
* **Telemetry**
|
|
82
|
-
*
|
|
83
|
-
* - Creates a new span for each execution as per the traceparent and tracestate field
|
|
84
|
-
* of the event. If those are not present, then a brand new span is created and distributed
|
|
85
|
-
* tracing is disabled
|
|
86
|
-
* - Sets span attributes for input and output events
|
|
87
|
-
* - Propagates trace context to output events
|
|
88
|
-
* - Handles error cases and sets appropriate span status
|
|
89
|
-
*
|
|
90
|
-
* **Event Validation**
|
|
91
|
-
*
|
|
92
|
-
* - Checks if the event's 'to' field matches the handler's 'source'.
|
|
93
|
-
* - If they don't match, an error is thrown with a descriptive message.
|
|
94
|
-
* - This ensures that the handler only processes events intended for it.
|
|
38
|
+
* @param event Event to process
|
|
39
|
+
* @param opentelemetry Telemetry context configuration
|
|
40
|
+
* @returns Resulting events or error events
|
|
95
41
|
*/
|
|
96
|
-
execute(event: ArvoEvent, opentelemetry?:
|
|
42
|
+
execute(event: ArvoEvent, opentelemetry?: ArvoEventHandlerOpenTelemetryOptions): Promise<ArvoEvent[]>;
|
|
97
43
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* @returns An object containing the error event type and schema.
|
|
101
|
-
*
|
|
102
|
-
* @remarks
|
|
103
|
-
* This getter defines the structure for system error events that may be emitted
|
|
104
|
-
* when an unexpected error occurs during event handling. The error event type
|
|
105
|
-
* is prefixed with 'sys.' followed by the handler's source and '.error'.
|
|
106
|
-
* The schema used for these error events is the standard ArvoErrorSchema.
|
|
107
|
-
*
|
|
108
|
-
* @example
|
|
109
|
-
* // If the handler's source is 'user.service'
|
|
110
|
-
* // The system error event type would be 'sys.user.service.error'
|
|
44
|
+
* System error schema configuration.
|
|
45
|
+
* Error events follow format: sys.<handler-source>.error
|
|
111
46
|
*/
|
|
112
47
|
get systemErrorSchema(): {
|
|
113
48
|
type: string;
|
|
@@ -14,6 +14,17 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
14
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
15
|
};
|
|
16
16
|
})();
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
17
28
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
29
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
30
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -58,170 +69,112 @@ var api_1 = require("@opentelemetry/api");
|
|
|
58
69
|
var arvo_core_1 = require("arvo-core");
|
|
59
70
|
var utils_1 = require("../utils");
|
|
60
71
|
var AbstractArvoEventHandler_1 = __importDefault(require("../AbstractArvoEventHandler"));
|
|
61
|
-
var
|
|
62
|
-
var utils_2 = require("../OpenTelemetry/utils");
|
|
72
|
+
var utils_2 = require("../utils");
|
|
63
73
|
/**
|
|
64
|
-
*
|
|
74
|
+
* MultiArvoEventHandler processes multiple event types without being bound to specific contracts.
|
|
75
|
+
* Manages event execution, telemetry tracking, and error handling for diverse event streams.
|
|
65
76
|
*
|
|
66
|
-
* @
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
77
|
+
* @example
|
|
78
|
+
* const handler = createMultiArvoEventHandler({
|
|
79
|
+
* source: "order.handler",
|
|
80
|
+
* executionunits: 1,
|
|
81
|
+
* handler: async ({ event }) => {
|
|
82
|
+
* // Handle multiple event types
|
|
83
|
+
* }
|
|
84
|
+
* });
|
|
71
85
|
*/
|
|
72
86
|
var MultiArvoEventHandler = /** @class */ (function (_super) {
|
|
73
87
|
__extends(MultiArvoEventHandler, _super);
|
|
74
88
|
/**
|
|
75
|
-
* Creates
|
|
76
|
-
*
|
|
77
|
-
* @
|
|
78
|
-
* @throws {Error} Throws an error if the provided source is invalid.
|
|
89
|
+
* Creates handler instance with specified configuration.
|
|
90
|
+
* @param param Handler configuration including source and execution parameters
|
|
91
|
+
* @throws When source contains invalid characters
|
|
79
92
|
*/
|
|
80
93
|
function MultiArvoEventHandler(param) {
|
|
81
|
-
var _a
|
|
94
|
+
var _a;
|
|
95
|
+
var _b, _c;
|
|
82
96
|
var _this = _super.call(this) || this;
|
|
83
|
-
_this.openInferenceSpanKind = arvo_core_1.OpenInferenceSpanKind.CHAIN;
|
|
84
|
-
_this.arvoExecutionSpanKind = arvo_core_1.ArvoExecutionSpanKind.EVENT_HANDLER;
|
|
85
|
-
_this.openTelemetrySpanKind = api_1.SpanKind.INTERNAL;
|
|
86
97
|
_this.executionunits = param.executionunits;
|
|
87
|
-
_this.
|
|
98
|
+
_this.handler = param.handler;
|
|
88
99
|
if (!(0, utils_1.isLowerAlphanumeric)(param.source)) {
|
|
89
|
-
throw new Error("Invalid
|
|
100
|
+
throw new Error("Invalid source identifier '".concat(param.source, "': Must contain only alphanumeric characters (example: order.handler)"));
|
|
90
101
|
}
|
|
91
102
|
_this.source = param.source;
|
|
92
|
-
_this.
|
|
93
|
-
((_a = param.spanKind) === null || _a === void 0 ? void 0 : _a.arvoExecution) || _this.arvoExecutionSpanKind;
|
|
94
|
-
_this.openInferenceSpanKind =
|
|
95
|
-
((_b = param.spanKind) === null || _b === void 0 ? void 0 : _b.openInference) || _this.openInferenceSpanKind;
|
|
96
|
-
_this.openTelemetrySpanKind =
|
|
97
|
-
((_c = param.spanKind) === null || _c === void 0 ? void 0 : _c.openTelemetry) || _this.openTelemetrySpanKind;
|
|
103
|
+
_this.spanOptions = __assign(__assign({ kind: api_1.SpanKind.CONSUMER }, param.spanOptions), { attributes: __assign(__assign((_a = {}, _a[arvo_core_1.ArvoExecution.ATTR_SPAN_KIND] = arvo_core_1.ArvoExecutionSpanKind.EVENT_HANDLER, _a[arvo_core_1.OpenInference.ATTR_SPAN_KIND] = arvo_core_1.OpenInferenceSpanKind.CHAIN, _a), ((_c = (_b = param.spanOptions) === null || _b === void 0 ? void 0 : _b.attributes) !== null && _c !== void 0 ? _c : {})), { 'arvo.handler.source': _this.source }) });
|
|
98
104
|
return _this;
|
|
99
105
|
}
|
|
100
106
|
/**
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* @param event - The event to handle.
|
|
104
|
-
* @param opentelemetry - Configuration for OpenTelemetry integration, including tracing options
|
|
105
|
-
* and context inheritance settings.
|
|
106
|
-
* @returns A promise that resolves to an array of resulting ArvoEvents.
|
|
107
|
-
*
|
|
108
|
-
* @remarks
|
|
109
|
-
* This method performs the following steps:
|
|
110
|
-
* 1. Creates an OpenTelemetry span for the execution.
|
|
111
|
-
* 2. Validates that the event's 'to' field matches the handler's 'source'.
|
|
112
|
-
* 3. Executes the handler function.
|
|
113
|
-
* 4. Creates and returns the result event(s).
|
|
114
|
-
* 5. Handles any errors and creates an error event if necessary.
|
|
115
|
-
*
|
|
116
|
-
* All telemetry data is properly set and propagated throughout the execution.
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* ```typescript
|
|
120
|
-
* const handler = new MultiArvoEventHandler({
|
|
121
|
-
* source: 'com.multi.handler',
|
|
122
|
-
* ...
|
|
123
|
-
* });
|
|
124
|
-
* const inputEvent: ArvoEvent = createArvoEvent({ ... });
|
|
125
|
-
* const resultEvents = await handler.execute(inputEvent);
|
|
126
|
-
* ```
|
|
127
|
-
*
|
|
128
|
-
* @throws {Error} Throws an error if the event's 'to' field doesn't match the handler's 'source'.
|
|
129
|
-
* All other errors thrown during the execution are returned as a system error event.
|
|
130
|
-
*
|
|
131
|
-
* **Routing**
|
|
132
|
-
*
|
|
133
|
-
* The routing of the resulting events is determined as follows:
|
|
134
|
-
* - The `to` field of the output event is set in this priority:
|
|
135
|
-
* 1. The `to` field provided by the handler result
|
|
136
|
-
* 2. The `redirectto` field from the input event
|
|
137
|
-
* 3. The `source` field from the input event (as a form of reply)
|
|
138
|
-
* - For system error events, the `to` field is always set to the `source` of the input event.
|
|
139
|
-
*
|
|
140
|
-
* **Telemetry**
|
|
141
|
-
*
|
|
142
|
-
* - Creates a new span for each execution as per the traceparent and tracestate field
|
|
143
|
-
* of the event. If those are not present, then a brand new span is created and distributed
|
|
144
|
-
* tracing is disabled
|
|
145
|
-
* - Sets span attributes for input and output events
|
|
146
|
-
* - Propagates trace context to output events
|
|
147
|
-
* - Handles error cases and sets appropriate span status
|
|
148
|
-
*
|
|
149
|
-
* **Event Validation**
|
|
107
|
+
* Processes an event through configured handler function. Creates telemetry span,
|
|
108
|
+
* validates event destination, executes handler, and manages errors.
|
|
150
109
|
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
110
|
+
* @param event Event to process
|
|
111
|
+
* @param opentelemetry Telemetry context configuration
|
|
112
|
+
* @returns Resulting events or error events
|
|
154
113
|
*/
|
|
155
|
-
MultiArvoEventHandler.prototype.execute = function (
|
|
156
|
-
return __awaiter(this,
|
|
157
|
-
var
|
|
114
|
+
MultiArvoEventHandler.prototype.execute = function (event_1) {
|
|
115
|
+
return __awaiter(this, arguments, void 0, function (event, opentelemetry) {
|
|
116
|
+
var otelConfig;
|
|
158
117
|
var _this = this;
|
|
118
|
+
if (opentelemetry === void 0) { opentelemetry = {
|
|
119
|
+
inheritFrom: 'EVENT',
|
|
120
|
+
}; }
|
|
159
121
|
return __generator(this, function (_a) {
|
|
160
122
|
switch (_a.label) {
|
|
161
123
|
case 0:
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
return
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
return [2 /*return
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
});
|
|
217
|
-
})];
|
|
218
|
-
case 4:
|
|
219
|
-
span.end();
|
|
220
|
-
return [7 /*endfinally*/];
|
|
221
|
-
case 5: return [2 /*return*/];
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
}); })];
|
|
124
|
+
otelConfig = (0, utils_2.createEventHandlerTelemetryConfig)('MutliArvoEventHandler', this.spanOptions, opentelemetry, event);
|
|
125
|
+
return [4 /*yield*/, arvo_core_1.ArvoOpenTelemetry.getInstance().startActiveSpan(__assign(__assign({}, otelConfig), { fn: function (span) { return __awaiter(_this, void 0, void 0, function () {
|
|
126
|
+
var otelSpanHeaders, _handlerOutput, outputs, resultingEvents, error_1;
|
|
127
|
+
return __generator(this, function (_a) {
|
|
128
|
+
switch (_a.label) {
|
|
129
|
+
case 0:
|
|
130
|
+
otelSpanHeaders = (0, arvo_core_1.currentOpenTelemetryHeaders)();
|
|
131
|
+
_a.label = 1;
|
|
132
|
+
case 1:
|
|
133
|
+
_a.trys.push([1, 3, 4, 5]);
|
|
134
|
+
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
135
|
+
Object.entries(event.otelAttributes).forEach(function (_a) {
|
|
136
|
+
var key = _a[0], value = _a[1];
|
|
137
|
+
return span.setAttribute("to_process.0.".concat(key), value);
|
|
138
|
+
});
|
|
139
|
+
(0, arvo_core_1.logToSpan)({
|
|
140
|
+
level: 'INFO',
|
|
141
|
+
message: "Initiating event resolution - Type: ".concat(event.type, ", Source: ").concat(event.source, ", Destination: ").concat(event.to),
|
|
142
|
+
});
|
|
143
|
+
if (event.to !== this.source) {
|
|
144
|
+
throw new Error("Event destination mismatch: Expected '".concat(this.source, "', received '").concat(event.to, "'"));
|
|
145
|
+
}
|
|
146
|
+
return [4 /*yield*/, this.handler({
|
|
147
|
+
event: event,
|
|
148
|
+
source: this.source,
|
|
149
|
+
span: span
|
|
150
|
+
})];
|
|
151
|
+
case 2:
|
|
152
|
+
_handlerOutput = _a.sent();
|
|
153
|
+
if (!_handlerOutput)
|
|
154
|
+
return [2 /*return*/, []];
|
|
155
|
+
outputs = [];
|
|
156
|
+
if (Array.isArray(_handlerOutput)) {
|
|
157
|
+
outputs = _handlerOutput;
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
outputs = [_handlerOutput];
|
|
161
|
+
}
|
|
162
|
+
resultingEvents = (0, utils_1.eventHandlerOutputEventCreator)(outputs, otelSpanHeaders, this.source, event, this.executionunits, function (param, extensions) { return (0, arvo_core_1.createArvoEvent)(param, extensions); });
|
|
163
|
+
(0, arvo_core_1.logToSpan)({
|
|
164
|
+
level: 'INFO',
|
|
165
|
+
message: "Event processing completed successfully - Generated ".concat(resultingEvents.length, " new event(s)"),
|
|
166
|
+
});
|
|
167
|
+
return [2 /*return*/, resultingEvents];
|
|
168
|
+
case 3:
|
|
169
|
+
error_1 = _a.sent();
|
|
170
|
+
return [2 /*return*/, (0, utils_1.createHandlerErrorOutputEvent)(error_1, otelSpanHeaders, "sys.".concat(this.source, ".error"), this.source, event, this.executionunits, function (param, extensions) { return (0, arvo_core_1.createArvoEvent)(param, extensions); })];
|
|
171
|
+
case 4:
|
|
172
|
+
span.end();
|
|
173
|
+
return [7 /*endfinally*/];
|
|
174
|
+
case 5: return [2 /*return*/];
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}); } }))];
|
|
225
178
|
case 1: return [2 /*return*/, _a.sent()];
|
|
226
179
|
}
|
|
227
180
|
});
|
|
@@ -229,19 +182,8 @@ var MultiArvoEventHandler = /** @class */ (function (_super) {
|
|
|
229
182
|
};
|
|
230
183
|
Object.defineProperty(MultiArvoEventHandler.prototype, "systemErrorSchema", {
|
|
231
184
|
/**
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
* @returns An object containing the error event type and schema.
|
|
235
|
-
*
|
|
236
|
-
* @remarks
|
|
237
|
-
* This getter defines the structure for system error events that may be emitted
|
|
238
|
-
* when an unexpected error occurs during event handling. The error event type
|
|
239
|
-
* is prefixed with 'sys.' followed by the handler's source and '.error'.
|
|
240
|
-
* The schema used for these error events is the standard ArvoErrorSchema.
|
|
241
|
-
*
|
|
242
|
-
* @example
|
|
243
|
-
* // If the handler's source is 'user.service'
|
|
244
|
-
* // The system error event type would be 'sys.user.service.error'
|
|
185
|
+
* System error schema configuration.
|
|
186
|
+
* Error events follow format: sys.<handler-source>.error
|
|
245
187
|
*/
|
|
246
188
|
get: function () {
|
|
247
189
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ArvoEvent,
|
|
1
|
+
import { Span, SpanOptions } from '@opentelemetry/api';
|
|
2
|
+
import { ArvoEvent, CreateArvoEvent } from 'arvo-core';
|
|
3
3
|
/**
|
|
4
4
|
* Represents the input for a Multi ArvoEvent handler function.
|
|
5
5
|
*/
|
|
@@ -8,6 +8,8 @@ export type MultiArvoEventHandlerFunctionInput = {
|
|
|
8
8
|
event: ArvoEvent;
|
|
9
9
|
/** The source field data of the handler */
|
|
10
10
|
source: string;
|
|
11
|
+
/** The OpenTelemetry span */
|
|
12
|
+
span: Span;
|
|
11
13
|
};
|
|
12
14
|
/**
|
|
13
15
|
* Represents the output of a Multi ArvoEvent handler function.
|
|
@@ -57,16 +59,6 @@ export interface IMultiArvoEventHandler {
|
|
|
57
59
|
* @returns A promise of object containing the created ArvoEvent and optional extensions.
|
|
58
60
|
*/
|
|
59
61
|
handler: MultiArvoEventHandlerFunction;
|
|
60
|
-
/**
|
|
61
|
-
|
|
62
|
-
* executor.
|
|
63
|
-
* @param [openInference] - The OpenInference span kind. Default is "CHAIN"
|
|
64
|
-
* @param [arvoExecution] - The ArvoExecution span kind. Default is "EVENT_HANDLER"
|
|
65
|
-
* @param [openTelemetry] - The OpenTelemetry span kind. Default is "INTERNAL"
|
|
66
|
-
*/
|
|
67
|
-
spanKind?: {
|
|
68
|
-
openInference?: OpenInferenceSpanKind;
|
|
69
|
-
arvoExecution?: ArvoExecutionSpanKind;
|
|
70
|
-
openTelemetry?: SpanKind;
|
|
71
|
-
};
|
|
62
|
+
/** The OpenTelemetry span options */
|
|
63
|
+
spanOptions?: SpanOptions;
|
|
72
64
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import ArvoEventHandler from './ArvoEventHandler';
|
|
2
2
|
import { ArvoEventHandlerFunctionInput, ArvoEventHandlerFunctionOutput, ArvoEventHandlerFunction, IArvoEventHandler } from './ArvoEventHandler/types';
|
|
3
3
|
import { createArvoEventHandler } from './ArvoEventHandler/helpers';
|
|
4
|
-
import { PartialExcept } from './types';
|
|
4
|
+
import { PartialExcept, ArvoEventHandlerOpenTelemetryOptions } from './types';
|
|
5
5
|
import MultiArvoEventHandler from './MultiArvoEventHandler';
|
|
6
6
|
import { MultiArvoEventHandlerFunctionInput, MultiArvoEventHandlerFunctionOutput, MultiArvoEventHandlerFunction, IMultiArvoEventHandler } from './MultiArvoEventHandler/types';
|
|
7
7
|
import { createMultiArvoEventHandler } from './MultiArvoEventHandler/helpers';
|
|
@@ -10,7 +10,5 @@ import { IArvoEventRouter } from './ArvoEventRouter/types';
|
|
|
10
10
|
import { ArvoEventRouter } from './ArvoEventRouter';
|
|
11
11
|
import { createArvoEventRouter } from './ArvoEventRouter/helpers';
|
|
12
12
|
import AbstractArvoEventHandler from './AbstractArvoEventHandler';
|
|
13
|
-
import { createOtelSpan } from './OpenTelemetry/utils';
|
|
14
|
-
import { OpenTelemetryConfig } from './OpenTelemetry/types';
|
|
15
13
|
import { deleteOtelHeaders } from './ArvoEventRouter/utils';
|
|
16
|
-
export { ArvoEventHandler, createArvoEventHandler, IArvoEventHandler, ArvoEventHandlerFunctionOutput, ArvoEventHandlerFunctionInput, ArvoEventHandlerFunction, PartialExcept, MultiArvoEventHandler, MultiArvoEventHandlerFunctionInput, MultiArvoEventHandlerFunctionOutput, MultiArvoEventHandlerFunction, IMultiArvoEventHandler, createMultiArvoEventHandler, isNullOrUndefined, getValueOrDefault, coalesce, coalesceOrDefault, IArvoEventRouter, ArvoEventRouter, createArvoEventRouter, AbstractArvoEventHandler,
|
|
14
|
+
export { ArvoEventHandler, createArvoEventHandler, IArvoEventHandler, ArvoEventHandlerFunctionOutput, ArvoEventHandlerFunctionInput, ArvoEventHandlerFunction, PartialExcept, MultiArvoEventHandler, MultiArvoEventHandlerFunctionInput, MultiArvoEventHandlerFunctionOutput, MultiArvoEventHandlerFunction, IMultiArvoEventHandler, createMultiArvoEventHandler, isNullOrUndefined, getValueOrDefault, coalesce, coalesceOrDefault, IArvoEventRouter, ArvoEventRouter, createArvoEventRouter, AbstractArvoEventHandler, deleteOtelHeaders, ArvoEventHandlerOpenTelemetryOptions, };
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.deleteOtelHeaders = exports.
|
|
6
|
+
exports.deleteOtelHeaders = exports.AbstractArvoEventHandler = exports.createArvoEventRouter = exports.ArvoEventRouter = exports.coalesceOrDefault = exports.coalesce = exports.getValueOrDefault = exports.isNullOrUndefined = exports.createMultiArvoEventHandler = exports.MultiArvoEventHandler = exports.createArvoEventHandler = exports.ArvoEventHandler = void 0;
|
|
7
7
|
var ArvoEventHandler_1 = __importDefault(require("./ArvoEventHandler"));
|
|
8
8
|
exports.ArvoEventHandler = ArvoEventHandler_1.default;
|
|
9
9
|
var helpers_1 = require("./ArvoEventHandler/helpers");
|
|
@@ -23,7 +23,5 @@ var helpers_3 = require("./ArvoEventRouter/helpers");
|
|
|
23
23
|
Object.defineProperty(exports, "createArvoEventRouter", { enumerable: true, get: function () { return helpers_3.createArvoEventRouter; } });
|
|
24
24
|
var AbstractArvoEventHandler_1 = __importDefault(require("./AbstractArvoEventHandler"));
|
|
25
25
|
exports.AbstractArvoEventHandler = AbstractArvoEventHandler_1.default;
|
|
26
|
-
var utils_2 = require("./
|
|
27
|
-
Object.defineProperty(exports, "
|
|
28
|
-
var utils_3 = require("./ArvoEventRouter/utils");
|
|
29
|
-
Object.defineProperty(exports, "deleteOtelHeaders", { enumerable: true, get: function () { return utils_3.deleteOtelHeaders; } });
|
|
26
|
+
var utils_2 = require("./ArvoEventRouter/utils");
|
|
27
|
+
Object.defineProperty(exports, "deleteOtelHeaders", { enumerable: true, get: function () { return utils_2.deleteOtelHeaders; } });
|
package/dist/types.d.ts
CHANGED
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ArvoEvent, CreateArvoEvent, OpenTelemetryHeaders } from 'arvo-core';
|
|
2
2
|
import { ArvoEventHandlerFunctionOutput } from './ArvoEventHandler/types';
|
|
3
3
|
import { MultiArvoEventHandlerFunctionOutput } from './MultiArvoEventHandler/types';
|
|
4
|
+
import { SpanOptions } from '@opentelemetry/api';
|
|
5
|
+
import { ArvoEventHandlerOpenTelemetryOptions } from './types';
|
|
4
6
|
/**
|
|
5
7
|
* Checks if the item is null or undefined.
|
|
6
8
|
*
|
|
@@ -76,3 +78,19 @@ export declare const createHandlerErrorOutputEvent: (error: Error, otelSpanHeade
|
|
|
76
78
|
* @returns True if the string contains only alphanumeric characters, false otherwise.
|
|
77
79
|
*/
|
|
78
80
|
export declare function isLowerAlphanumeric(input: string): boolean;
|
|
81
|
+
export declare const createEventHandlerTelemetryConfig: (name: string, options: SpanOptions, contextConfig: ArvoEventHandlerOpenTelemetryOptions, event: ArvoEvent) => {
|
|
82
|
+
name: string;
|
|
83
|
+
disableSpanManagement: boolean;
|
|
84
|
+
context: {
|
|
85
|
+
inheritFrom: "TRACE_HEADERS";
|
|
86
|
+
traceHeaders: {
|
|
87
|
+
traceparent: string | null;
|
|
88
|
+
tracestate: string | null;
|
|
89
|
+
};
|
|
90
|
+
context?: undefined;
|
|
91
|
+
} | {
|
|
92
|
+
inheritFrom: "CONTEXT";
|
|
93
|
+
context: import("@opentelemetry/api").Context;
|
|
94
|
+
traceHeaders?: undefined;
|
|
95
|
+
};
|
|
96
|
+
};
|
package/dist/utils.js
CHANGED
|
@@ -22,7 +22,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
22
22
|
return t;
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.createHandlerErrorOutputEvent = exports.eventHandlerOutputEventCreator = void 0;
|
|
25
|
+
exports.createEventHandlerTelemetryConfig = exports.createHandlerErrorOutputEvent = exports.eventHandlerOutputEventCreator = void 0;
|
|
26
26
|
exports.isNullOrUndefined = isNullOrUndefined;
|
|
27
27
|
exports.getValueOrDefault = getValueOrDefault;
|
|
28
28
|
exports.coalesce = coalesce;
|
|
@@ -167,3 +167,20 @@ function isLowerAlphanumeric(input) {
|
|
|
167
167
|
var alphanumericRegex = /^[a-z0-9.]+$/;
|
|
168
168
|
return alphanumericRegex.test(input);
|
|
169
169
|
}
|
|
170
|
+
var createEventHandlerTelemetryConfig = function (name, options, contextConfig, event) { return ({
|
|
171
|
+
name: name,
|
|
172
|
+
disableSpanManagement: true,
|
|
173
|
+
context: contextConfig.inheritFrom === 'EVENT'
|
|
174
|
+
? {
|
|
175
|
+
inheritFrom: 'TRACE_HEADERS',
|
|
176
|
+
traceHeaders: {
|
|
177
|
+
traceparent: event.traceparent,
|
|
178
|
+
tracestate: event.tracestate,
|
|
179
|
+
},
|
|
180
|
+
}
|
|
181
|
+
: {
|
|
182
|
+
inheritFrom: 'CONTEXT',
|
|
183
|
+
context: api_1.context.active(),
|
|
184
|
+
},
|
|
185
|
+
}); };
|
|
186
|
+
exports.createEventHandlerTelemetryConfig = createEventHandlerTelemetryConfig;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arvo-event-handler",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Type-safe event handler system with versioning, telemetry, and contract validation for distributed Arvo event-driven architectures, featuring routing and multi-handler support.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@opentelemetry/api": "^1.9.0",
|
|
52
52
|
"@opentelemetry/core": "^1.27.0",
|
|
53
|
-
"arvo-core": "^2.1.
|
|
53
|
+
"arvo-core": "^2.1.10",
|
|
54
54
|
"uuid": "^10.0.0",
|
|
55
55
|
"zod": "^3.23.8"
|
|
56
56
|
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchOpenTelemetryTracer = void 0;
|
|
4
|
-
var api_1 = require("@opentelemetry/api");
|
|
5
|
-
/**
|
|
6
|
-
* Returns a tracer instance for the ArvoEventHandler package.
|
|
7
|
-
*/
|
|
8
|
-
var fetchOpenTelemetryTracer = function () {
|
|
9
|
-
return api_1.trace.getTracer('arvo-instrumentation');
|
|
10
|
-
};
|
|
11
|
-
exports.fetchOpenTelemetryTracer = fetchOpenTelemetryTracer;
|