arvo-event-handler 2.0.3 → 2.1.0

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.
@@ -1,113 +1,48 @@
1
- import { SpanKind } from '@opentelemetry/api';
2
- import { ArvoEvent, ArvoExecutionSpanKind, OpenInferenceSpanKind } from 'arvo-core';
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 { OpenTelemetryConfig } from '../OpenTelemetry/types';
5
+ import { ArvoEventHandlerOpenTelemetryOptions } from '../types';
6
6
  /**
7
- * Represents a Multi ArvoEvent handler that can process multiple event types.
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
- * @remarks
10
- * Unlike ArvoEventHandler, which is bound to a specific ArvoContract and handles
11
- * events of a single type, MultiArvoEventHandler can handle multiple event types
12
- * without being tied to a specific contract. This makes it more flexible for
13
- * scenarios where you need to process various event types with a single handler.
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
- /** The default execution cost associated with this handler */
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
- readonly openInferenceSpanKind: OpenInferenceSpanKind;
31
- readonly arvoExecutionSpanKind: ArvoExecutionSpanKind;
32
- readonly openTelemetrySpanKind: SpanKind;
33
- private readonly _handler;
24
+ /** OpenTelemetry configuration */
25
+ readonly spanOptions: SpanOptions;
26
+ /** Event processing function */
27
+ readonly handler: MultiArvoEventHandlerFunction;
34
28
  /**
35
- * Creates an instance of MultiArvoEventHandler.
36
- *
37
- * @param param - The configuration parameters for the event handler.
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
- * Executes the event handler for a given event.
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
- * ```
68
- *
69
- * @throws {Error} Throws an error if the event's 'to' field doesn't match the handler's 'source'.
70
- * All other errors thrown during the execution are returned as a system error event.
71
- *
72
- * **Routing**
35
+ * Processes an event through configured handler function. Creates telemetry span,
36
+ * validates event destination, executes handler, and manages errors.
73
37
  *
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?: OpenTelemetryConfig): Promise<ArvoEvent[]>;
42
+ execute(event: ArvoEvent, opentelemetry?: ArvoEventHandlerOpenTelemetryOptions): Promise<ArvoEvent[]>;
97
43
  /**
98
- * Provides the schema for system error events.
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;
@@ -116,12 +51,12 @@ export default class MultiArvoEventHandler extends AbstractArvoEventHandler {
116
51
  errorMessage: import("zod").ZodString;
117
52
  errorStack: import("zod").ZodNullable<import("zod").ZodString>;
118
53
  }, "strip", import("zod").ZodTypeAny, {
119
- errorMessage: string;
120
54
  errorName: string;
55
+ errorMessage: string;
121
56
  errorStack: string | null;
122
57
  }, {
123
- errorMessage: string;
124
58
  errorName: string;
59
+ errorMessage: string;
125
60
  errorStack: string | null;
126
61
  }>;
127
62
  };
@@ -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,119 +69,73 @@ 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 OpenTelemetry_1 = require("../OpenTelemetry");
62
- var utils_2 = require("../OpenTelemetry/utils");
63
72
  /**
64
- * Represents a Multi ArvoEvent handler that can process multiple event types.
73
+ * MultiArvoEventHandler processes multiple event types without being bound to specific contracts.
74
+ * Manages event execution, telemetry tracking, and error handling for diverse event streams.
65
75
  *
66
- * @remarks
67
- * Unlike ArvoEventHandler, which is bound to a specific ArvoContract and handles
68
- * events of a single type, MultiArvoEventHandler can handle multiple event types
69
- * without being tied to a specific contract. This makes it more flexible for
70
- * scenarios where you need to process various event types with a single handler.
76
+ * @example
77
+ * const handler = createMultiArvoEventHandler({
78
+ * source: "order.handler",
79
+ * executionunits: 1,
80
+ * handler: async ({ event }) => {
81
+ * // Handle multiple event types
82
+ * }
83
+ * });
71
84
  */
72
85
  var MultiArvoEventHandler = /** @class */ (function (_super) {
73
86
  __extends(MultiArvoEventHandler, _super);
74
87
  /**
75
- * Creates an instance of MultiArvoEventHandler.
76
- *
77
- * @param param - The configuration parameters for the event handler.
78
- * @throws {Error} Throws an error if the provided source is invalid.
88
+ * Creates handler instance with specified configuration.
89
+ * @param param Handler configuration including source and execution parameters
90
+ * @throws When source contains invalid characters
79
91
  */
80
92
  function MultiArvoEventHandler(param) {
81
- var _a, _b, _c;
93
+ var _a;
94
+ var _b, _c;
82
95
  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
96
  _this.executionunits = param.executionunits;
87
- _this._handler = param.handler;
97
+ _this.handler = param.handler;
88
98
  if (!(0, utils_1.isLowerAlphanumeric)(param.source)) {
89
- throw new Error("Invalid 'source' = '".concat(param.source, "'. The 'source' must only contain alphanumeric characters e.g. test.handler"));
99
+ throw new Error("Invalid source identifier '".concat(param.source, "': Must contain only alphanumeric characters (example: order.handler)"));
90
100
  }
91
101
  _this.source = param.source;
92
- _this.arvoExecutionSpanKind =
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;
102
+ _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
103
  return _this;
99
104
  }
100
105
  /**
101
- * Executes the event handler for a given event.
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.
106
+ * Processes an event through configured handler function. Creates telemetry span,
107
+ * validates event destination, executes handler, and manages errors.
130
108
  *
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**
150
- *
151
- * - Checks if the event's 'to' field matches the handler's 'source'.
152
- * - If they don't match, an error is thrown with a descriptive message.
153
- * - This ensures that the handler only processes events intended for it.
109
+ * @param event Event to process
110
+ * @param opentelemetry Telemetry context configuration
111
+ * @returns Resulting events or error events
154
112
  */
155
- MultiArvoEventHandler.prototype.execute = function (event, opentelemetry) {
156
- return __awaiter(this, void 0, void 0, function () {
157
- var span;
113
+ MultiArvoEventHandler.prototype.execute = function (event_1) {
114
+ return __awaiter(this, arguments, void 0, function (event, opentelemetry) {
158
115
  var _this = this;
116
+ if (opentelemetry === void 0) { opentelemetry = {
117
+ inheritFrom: 'EVENT',
118
+ }; }
159
119
  return __generator(this, function (_a) {
160
120
  switch (_a.label) {
161
- case 0:
162
- span = (0, utils_2.createOtelSpan)({
163
- spanName: "MutliArvoEventHandler.source<".concat(this.source, ">.execute<").concat(event.type, ">"),
164
- spanKinds: {
165
- kind: this.openTelemetrySpanKind,
166
- openInference: this.openInferenceSpanKind,
167
- arvoExecution: this.arvoExecutionSpanKind,
168
- },
169
- event: event,
170
- opentelemetryConfig: opentelemetry,
171
- });
172
- return [4 /*yield*/, api_1.context.with(api_1.trace.setSpan(api_1.context.active(), span), function () { return __awaiter(_this, void 0, void 0, function () {
173
- var otelSpanHeaders, _handlerOutput, outputs, error_1;
121
+ case 0: return [4 /*yield*/, arvo_core_1.ArvoOpenTelemetry.getInstance().startActiveSpan({
122
+ name: 'MutliArvoEventHandler',
123
+ spanOptions: this.spanOptions,
124
+ disableSpanManagement: true,
125
+ context: opentelemetry.inheritFrom === 'EVENT'
126
+ ? {
127
+ inheritFrom: 'TRACE_HEADERS',
128
+ traceHeaders: {
129
+ traceparent: event.traceparent,
130
+ tracestate: event.tracestate,
131
+ },
132
+ }
133
+ : {
134
+ inheritFrom: 'CONTEXT',
135
+ context: api_1.context.active(),
136
+ },
137
+ fn: function (span) { return __awaiter(_this, void 0, void 0, function () {
138
+ var otelSpanHeaders, _handlerOutput, outputs, resultingEvents, error_1;
174
139
  return __generator(this, function (_a) {
175
140
  switch (_a.label) {
176
141
  case 0:
@@ -183,12 +148,17 @@ var MultiArvoEventHandler = /** @class */ (function (_super) {
183
148
  var key = _a[0], value = _a[1];
184
149
  return span.setAttribute("to_process.0.".concat(key), value);
185
150
  });
151
+ (0, arvo_core_1.logToSpan)({
152
+ level: 'INFO',
153
+ message: "Initiating event resolution - Type: ".concat(event.type, ", Source: ").concat(event.source, ", Destination: ").concat(event.to),
154
+ });
186
155
  if (event.to !== this.source) {
187
- throw new Error((0, arvo_core_1.cleanString)("\n Invalid event. The 'event.to' is ".concat(event.to, " while this handler \n listens to only 'event.to' equal to ").concat(this.source, ". If this is a mistake,\n please update the 'source' field of the handler\n ")));
156
+ throw new Error("Event destination mismatch: Expected '".concat(this.source, "', received '").concat(event.to, "'"));
188
157
  }
189
- return [4 /*yield*/, this._handler({
158
+ return [4 /*yield*/, this.handler({
190
159
  event: event,
191
160
  source: this.source,
161
+ span: span
192
162
  })];
193
163
  case 2:
194
164
  _handlerOutput = _a.sent();
@@ -201,27 +171,23 @@ var MultiArvoEventHandler = /** @class */ (function (_super) {
201
171
  else {
202
172
  outputs = [_handlerOutput];
203
173
  }
204
- return [2 /*return*/, (0, utils_1.eventHandlerOutputEventCreator)(outputs, otelSpanHeaders, this.source, event, this.executionunits, function (param, extension) {
205
- var _a;
206
- return (0, arvo_core_1.createArvoEvent)(param, extension, {
207
- tracer: (_a = opentelemetry === null || opentelemetry === void 0 ? void 0 : opentelemetry.tracer) !== null && _a !== void 0 ? _a : (0, OpenTelemetry_1.fetchOpenTelemetryTracer)(),
208
- });
209
- })];
174
+ resultingEvents = (0, utils_1.eventHandlerOutputEventCreator)(outputs, otelSpanHeaders, this.source, event, this.executionunits, function (param, extensions) { return (0, arvo_core_1.createArvoEvent)(param, extensions); });
175
+ (0, arvo_core_1.logToSpan)({
176
+ level: 'INFO',
177
+ message: "Event processing completed successfully - Generated ".concat(resultingEvents.length, " new event(s)"),
178
+ });
179
+ return [2 /*return*/, resultingEvents];
210
180
  case 3:
211
181
  error_1 = _a.sent();
212
- return [2 /*return*/, (0, utils_1.createHandlerErrorOutputEvent)(error_1, otelSpanHeaders, "sys.".concat(this.source, ".error"), this.source, event, this.executionunits, function (param, extension) {
213
- var _a;
214
- return (0, arvo_core_1.createArvoEvent)(param, extension, {
215
- tracer: (_a = opentelemetry === null || opentelemetry === void 0 ? void 0 : opentelemetry.tracer) !== null && _a !== void 0 ? _a : (0, OpenTelemetry_1.fetchOpenTelemetryTracer)(),
216
- });
217
- })];
182
+ 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); })];
218
183
  case 4:
219
184
  span.end();
220
185
  return [7 /*endfinally*/];
221
186
  case 5: return [2 /*return*/];
222
187
  }
223
188
  });
224
- }); })];
189
+ }); },
190
+ })];
225
191
  case 1: return [2 /*return*/, _a.sent()];
226
192
  }
227
193
  });
@@ -229,19 +195,8 @@ var MultiArvoEventHandler = /** @class */ (function (_super) {
229
195
  };
230
196
  Object.defineProperty(MultiArvoEventHandler.prototype, "systemErrorSchema", {
231
197
  /**
232
- * Provides the schema for system error events.
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'
198
+ * System error schema configuration.
199
+ * Error events follow format: sys.<handler-source>.error
245
200
  */
246
201
  get: function () {
247
202
  return {
@@ -1,5 +1,5 @@
1
- import { SpanKind } from '@opentelemetry/api';
2
- import { ArvoEvent, ArvoExecutionSpanKind, CreateArvoEvent, OpenInferenceSpanKind } from 'arvo-core';
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
- * The OpenTelemetry span kind attributes for the handler
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, OpenTelemetryConfig, createOtelSpan, deleteOtelHeaders, };
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.createOtelSpan = exports.AbstractArvoEventHandler = exports.createArvoEventRouter = exports.ArvoEventRouter = exports.coalesceOrDefault = exports.coalesce = exports.getValueOrDefault = exports.isNullOrUndefined = exports.createMultiArvoEventHandler = exports.MultiArvoEventHandler = exports.createArvoEventHandler = exports.ArvoEventHandler = void 0;
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("./OpenTelemetry/utils");
27
- Object.defineProperty(exports, "createOtelSpan", { enumerable: true, get: function () { return utils_2.createOtelSpan; } });
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
@@ -15,3 +15,6 @@
15
15
  * // Equivalent to: { id: number; name?: string; email?: string; }
16
16
  */
17
17
  export type PartialExcept<T, K extends keyof T> = Partial<Omit<T, K>> & Pick<T, K>;
18
+ export type ArvoEventHandlerOpenTelemetryOptions = {
19
+ inheritFrom: 'EVENT' | 'CONTEXT';
20
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arvo-event-handler",
3
- "version": "2.0.3",
3
+ "version": "2.1.0",
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.0.10",
53
+ "arvo-core": "^2.1.10",
54
54
  "uuid": "^10.0.0",
55
55
  "zod": "^3.23.8"
56
56
  }
@@ -1,4 +0,0 @@
1
- /**
2
- * Returns a tracer instance for the ArvoEventHandler package.
3
- */
4
- export declare const fetchOpenTelemetryTracer: () => import("@opentelemetry/api").Tracer;
@@ -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;
@@ -1,48 +0,0 @@
1
- import { SpanKind, Tracer } from '@opentelemetry/api';
2
- import { ArvoEvent, ArvoExecutionSpanKind, OpenInferenceSpanKind } from 'arvo-core';
3
- export type PackageJson = {
4
- name: string;
5
- version: string;
6
- [key: string]: any;
7
- };
8
- /**
9
- * Configuration options for OpenTelemetry integration in execution context.
10
- *
11
- * This type defines how tracing should be configured and inherited within
12
- * the execution pipeline.
13
- */
14
- export type OpenTelemetryConfig = {
15
- /**
16
- * Specifies the context from which to inherit OpenTelemetry context.
17
- * - 'event': Inherits context from the event that triggered the execution
18
- * - 'execution': Inherits context from the parent execution context
19
- */
20
- inheritFrom: 'event' | 'execution';
21
- /**
22
- * Optional OpenTelemetry tracer instance to use for creating spans.
23
- * If not provided, a default tracer may be used depending on the implementation.
24
- */
25
- tracer: Tracer | null;
26
- };
27
- /**
28
- * Interface defining the required parameters for creating a handler execution span.
29
- *
30
- * @interface ICreateHandlerExecutionSpan
31
- * @property {string} spanName - The name to be assigned to the created span
32
- * @property {Object} spanKinds - Object containing different span kind classifications
33
- * @property {SpanKind} spanKinds.kind - OpenTelemetry span kind
34
- * @property {OpenInferenceSpanKind} spanKinds.openInference - OpenInference-specific span classification
35
- * @property {ArvoExecutionSpanKind} spanKinds.arvoExecution - Arvo execution-specific span classification
36
- * @property {ArvoEvent} event - The Arvo event associated with this span
37
- * @property {EventHandlerExecutionOtelConfiguration} opentelemetryConfig - Configuration for OpenTelemetry behavior
38
- */
39
- export interface ICreateOtelSpan {
40
- spanName: string;
41
- spanKinds: {
42
- kind: SpanKind;
43
- openInference: OpenInferenceSpanKind;
44
- arvoExecution: ArvoExecutionSpanKind;
45
- };
46
- event: ArvoEvent;
47
- opentelemetryConfig?: OpenTelemetryConfig;
48
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });