arvo-event-handler 1.1.8 → 1.1.9
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/AbstractArvoEventHandler/index.d.ts +32 -9
- package/dist/AbstractArvoEventHandler/types.d.ts +33 -0
- package/dist/AbstractArvoEventHandler/types.js +2 -0
- package/dist/ArvoEventHandler/index.d.ts +5 -5
- package/dist/ArvoEventHandler/index.js +2 -0
- package/dist/ArvoEventRouter/index.d.ts +5 -5
- package/dist/ArvoEventRouter/index.js +2 -0
- package/dist/MultiArvoEventHandler/index.d.ts +5 -5
- package/dist/MultiArvoEventHandler/index.js +2 -0
- package/dist/index.d.ts +2 -1
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ArvoContractRecord, ArvoEvent } from 'arvo-core';
|
|
2
|
+
import { ExecutionOpenTelemetryConfiguration } from './types';
|
|
2
3
|
/**
|
|
3
4
|
* Abstract base class for Arvo event handlers.
|
|
4
5
|
*
|
|
@@ -14,22 +15,44 @@ export default abstract class AbstractArvoEventHandler {
|
|
|
14
15
|
* Executes the event handling logic for a given Arvo event.
|
|
15
16
|
*
|
|
16
17
|
* @abstract
|
|
17
|
-
* @param {ArvoEvent} event - The Arvo event to be processed.
|
|
18
|
+
* @param {ArvoEvent} event - The Arvo event to be processed. This event should conform
|
|
19
|
+
* to the expected schema for the specific handler implementation.
|
|
20
|
+
* @param {ExecutionOpenTelemetryConfiguration} opentelemetry - Configuration for OpenTelemetry
|
|
21
|
+
* integration, including tracing options
|
|
22
|
+
* and context inheritance settings.
|
|
18
23
|
* @returns {Promise<ArvoEvent[]>} A promise that resolves to an array of resulting Arvo events.
|
|
24
|
+
* These events represent the outcome of processing the input event.
|
|
19
25
|
*
|
|
20
26
|
* @description
|
|
21
|
-
* This method
|
|
22
|
-
*
|
|
23
|
-
*
|
|
27
|
+
* This method defines the core event processing logic that each concrete handler must implement.
|
|
28
|
+
* It should handle the complete lifecycle of an event, including:
|
|
29
|
+
* - Validation of the input event
|
|
30
|
+
* - Processing of the event according to business rules
|
|
31
|
+
* - Generation of any resulting events
|
|
32
|
+
* - Error handling and reporting
|
|
33
|
+
* - OpenTelemetry integration for observability
|
|
24
34
|
*
|
|
25
|
-
* @throws {Error}
|
|
35
|
+
* @throws {Error}
|
|
36
|
+
* - When the input event fails validation
|
|
37
|
+
* - When processing encounters an unrecoverable error
|
|
38
|
+
* - When the handler is unable to properly execute the event
|
|
26
39
|
*
|
|
27
40
|
* @remarks
|
|
28
|
-
*
|
|
29
|
-
* -
|
|
30
|
-
* -
|
|
41
|
+
* Implementation considerations:
|
|
42
|
+
* - Ensure proper error handling and event validation
|
|
43
|
+
* - Implement appropriate retry logic for transient failures
|
|
44
|
+
* - Use the provided OpenTelemetry configuration for tracing
|
|
45
|
+
* - Consider performance implications for long-running operations
|
|
46
|
+
* - Maintain idempotency where appropriate
|
|
47
|
+
* - Document any specific requirements for event schemas
|
|
48
|
+
*
|
|
49
|
+
* The method should handle observability concerns by:
|
|
50
|
+
* - Creating appropriate spans for tracing
|
|
51
|
+
* - Recording relevant attributes and events
|
|
52
|
+
* - Properly handling span lifecycle (creation and completion)
|
|
53
|
+
* - Propagating context appropriately
|
|
31
54
|
*/
|
|
32
|
-
abstract execute(event: ArvoEvent): Promise<ArvoEvent[]>;
|
|
55
|
+
abstract execute(event: ArvoEvent, opentelemetry: ExecutionOpenTelemetryConfiguration): Promise<ArvoEvent[]>;
|
|
33
56
|
/**
|
|
34
57
|
* Provides the schema for system error events.
|
|
35
58
|
*
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Tracer } from '@opentelemetry/api';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration options for OpenTelemetry integration in execution context.
|
|
4
|
+
*
|
|
5
|
+
* This type defines how tracing should be configured and inherited within
|
|
6
|
+
* the execution pipeline.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const config: ExecutionOpenTelemetryConfiguration = {
|
|
11
|
+
* inheritFrom: 'event',
|
|
12
|
+
* tracer: new OpenTelemetry.Tracer('service-name')
|
|
13
|
+
* };
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export type ExecutionOpenTelemetryConfiguration = {
|
|
17
|
+
/**
|
|
18
|
+
* Specifies the context from which to inherit OpenTelemetry context.
|
|
19
|
+
*
|
|
20
|
+
* @property {('event' | 'execution')} inheritFrom
|
|
21
|
+
* - 'event': Inherits context from the event that triggered the execution
|
|
22
|
+
* - 'execution': Inherits context from the parent execution context
|
|
23
|
+
*/
|
|
24
|
+
inheritFrom: 'event' | 'execution';
|
|
25
|
+
/**
|
|
26
|
+
* Optional OpenTelemetry tracer instance to use for creating spans.
|
|
27
|
+
* If not provided, a default tracer may be used depending on the implementation.
|
|
28
|
+
*
|
|
29
|
+
* @property {Tracer} [tracer]
|
|
30
|
+
* @see {@link https://open-telemetry.github.io/opentelemetry-js/classes/_opentelemetry_api.Tracer.html OpenTelemetry Tracer}
|
|
31
|
+
*/
|
|
32
|
+
tracer?: Tracer;
|
|
33
|
+
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ArvoContract, ArvoEvent, ArvoExecutionSpanKind, OpenInferenceSpanKind, ResolveArvoContractRecord } from 'arvo-core';
|
|
2
2
|
import { IArvoEventHandler } from './types';
|
|
3
|
-
import { SpanKind
|
|
3
|
+
import { SpanKind } from '@opentelemetry/api';
|
|
4
4
|
import AbstractArvoEventHandler from '../AbstractArvoEventHandler';
|
|
5
|
+
import { ExecutionOpenTelemetryConfiguration } from '../AbstractArvoEventHandler/types';
|
|
5
6
|
/**
|
|
6
7
|
* Represents an event handler for Arvo contracts.
|
|
7
8
|
*
|
|
@@ -45,6 +46,8 @@ export default class ArvoEventHandler<TContract extends ArvoContract> extends Ab
|
|
|
45
46
|
* Executes the event handler for a given event.
|
|
46
47
|
*
|
|
47
48
|
* @param event - The event to handle.
|
|
49
|
+
* @param opentelemetry - Configuration for OpenTelemetry integration, including tracing options
|
|
50
|
+
* and context inheritance settings.
|
|
48
51
|
* @returns A promise that resolves to an array of resulting ArvoEvents.
|
|
49
52
|
*
|
|
50
53
|
* @remarks
|
|
@@ -88,10 +91,7 @@ export default class ArvoEventHandler<TContract extends ArvoContract> extends Ab
|
|
|
88
91
|
* - Propagates trace context to output events
|
|
89
92
|
* - Handles error cases and sets appropriate span status
|
|
90
93
|
*/
|
|
91
|
-
execute(event: ArvoEvent<ResolveArvoContractRecord<TContract['accepts']>, Record<string, any>, TContract['accepts']['type']>, opentelemetry?:
|
|
92
|
-
inheritFrom: 'event' | 'execution';
|
|
93
|
-
tracer?: Tracer;
|
|
94
|
-
}): Promise<ArvoEvent[]>;
|
|
94
|
+
execute(event: ArvoEvent<ResolveArvoContractRecord<TContract['accepts']>, Record<string, any>, TContract['accepts']['type']>, opentelemetry?: ExecutionOpenTelemetryConfiguration): Promise<ArvoEvent[]>;
|
|
95
95
|
/**
|
|
96
96
|
* Provides the schema for system error events.
|
|
97
97
|
*
|
|
@@ -114,6 +114,8 @@ var ArvoEventHandler = /** @class */ (function (_super) {
|
|
|
114
114
|
* Executes the event handler for a given event.
|
|
115
115
|
*
|
|
116
116
|
* @param event - The event to handle.
|
|
117
|
+
* @param opentelemetry - Configuration for OpenTelemetry integration, including tracing options
|
|
118
|
+
* and context inheritance settings.
|
|
117
119
|
* @returns A promise that resolves to an array of resulting ArvoEvents.
|
|
118
120
|
*
|
|
119
121
|
* @remarks
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ArvoContract, ArvoEvent, ArvoExecutionSpanKind, OpenInferenceSpanKind } from 'arvo-core';
|
|
2
2
|
import ArvoEventHandler from '../ArvoEventHandler';
|
|
3
3
|
import { IArvoEventRouter } from './types';
|
|
4
|
-
import { SpanKind
|
|
4
|
+
import { SpanKind } from '@opentelemetry/api';
|
|
5
5
|
import AbstractArvoEventHandler from '../AbstractArvoEventHandler';
|
|
6
|
+
import { ExecutionOpenTelemetryConfiguration } from '../AbstractArvoEventHandler/types';
|
|
6
7
|
/**
|
|
7
8
|
* ArvoEventRouter class handles routing of ArvoEvents to appropriate event handlers.
|
|
8
9
|
*/
|
|
@@ -48,6 +49,8 @@ export declare class ArvoEventRouter extends AbstractArvoEventHandler {
|
|
|
48
49
|
* Executes the routing process for a given ArvoEvent.
|
|
49
50
|
*
|
|
50
51
|
* @param event - The ArvoEvent to be processed and routed.
|
|
52
|
+
* @param opentelemetry - Configuration for OpenTelemetry integration, including tracing options
|
|
53
|
+
* and context inheritance settings.
|
|
51
54
|
* @returns A Promise that resolves to an array of ArvoEvents.
|
|
52
55
|
*
|
|
53
56
|
* @remarks
|
|
@@ -89,10 +92,7 @@ export declare class ArvoEventRouter extends AbstractArvoEventHandler {
|
|
|
89
92
|
* - Execution units are tracked for both successful executions and errors.
|
|
90
93
|
* - The router's default execution units are used for error events.
|
|
91
94
|
*/
|
|
92
|
-
execute(event: ArvoEvent, opentelemetry?:
|
|
93
|
-
inheritFrom: 'event' | 'execution';
|
|
94
|
-
tracer?: Tracer;
|
|
95
|
-
}): Promise<ArvoEvent[]>;
|
|
95
|
+
execute(event: ArvoEvent, opentelemetry?: ExecutionOpenTelemetryConfiguration): Promise<ArvoEvent[]>;
|
|
96
96
|
/**
|
|
97
97
|
* Provides the schema for system error events.
|
|
98
98
|
*
|
|
@@ -123,6 +123,8 @@ var ArvoEventRouter = /** @class */ (function (_super) {
|
|
|
123
123
|
* Executes the routing process for a given ArvoEvent.
|
|
124
124
|
*
|
|
125
125
|
* @param event - The ArvoEvent to be processed and routed.
|
|
126
|
+
* @param opentelemetry - Configuration for OpenTelemetry integration, including tracing options
|
|
127
|
+
* and context inheritance settings.
|
|
126
128
|
* @returns A Promise that resolves to an array of ArvoEvents.
|
|
127
129
|
*
|
|
128
130
|
* @remarks
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { SpanKind
|
|
1
|
+
import { SpanKind } from '@opentelemetry/api';
|
|
2
2
|
import { ArvoEvent, ArvoExecutionSpanKind, OpenInferenceSpanKind } from 'arvo-core';
|
|
3
3
|
import { IMultiArvoEventHandler } from './types';
|
|
4
4
|
import AbstractArvoEventHandler from '../AbstractArvoEventHandler';
|
|
5
|
+
import { ExecutionOpenTelemetryConfiguration } from '../AbstractArvoEventHandler/types';
|
|
5
6
|
/**
|
|
6
7
|
* Represents a Multi ArvoEvent handler that can process multiple event types.
|
|
7
8
|
*
|
|
@@ -41,6 +42,8 @@ export default class MultiArvoEventHandler extends AbstractArvoEventHandler {
|
|
|
41
42
|
* Executes the event handler for a given event.
|
|
42
43
|
*
|
|
43
44
|
* @param event - The event to handle.
|
|
45
|
+
* @param opentelemetry - Configuration for OpenTelemetry integration, including tracing options
|
|
46
|
+
* and context inheritance settings.
|
|
44
47
|
* @returns A promise that resolves to an array of resulting ArvoEvents.
|
|
45
48
|
*
|
|
46
49
|
* @remarks
|
|
@@ -90,10 +93,7 @@ export default class MultiArvoEventHandler extends AbstractArvoEventHandler {
|
|
|
90
93
|
* - If they don't match, an error is thrown with a descriptive message.
|
|
91
94
|
* - This ensures that the handler only processes events intended for it.
|
|
92
95
|
*/
|
|
93
|
-
execute(event: ArvoEvent, opentelemetry?:
|
|
94
|
-
inheritFrom: 'event' | 'execution';
|
|
95
|
-
tracer?: Tracer;
|
|
96
|
-
}): Promise<ArvoEvent[]>;
|
|
96
|
+
execute(event: ArvoEvent, opentelemetry?: ExecutionOpenTelemetryConfiguration): Promise<ArvoEvent[]>;
|
|
97
97
|
/**
|
|
98
98
|
* Provides the schema for system error events.
|
|
99
99
|
*
|
|
@@ -101,6 +101,8 @@ var MultiArvoEventHandler = /** @class */ (function (_super) {
|
|
|
101
101
|
* Executes the event handler for a given event.
|
|
102
102
|
*
|
|
103
103
|
* @param event - The event to handle.
|
|
104
|
+
* @param opentelemetry - Configuration for OpenTelemetry integration, including tracing options
|
|
105
|
+
* and context inheritance settings.
|
|
104
106
|
* @returns A promise that resolves to an array of resulting ArvoEvents.
|
|
105
107
|
*
|
|
106
108
|
* @remarks
|
package/dist/index.d.ts
CHANGED
|
@@ -11,4 +11,5 @@ import { ArvoEventRouter } from './ArvoEventRouter';
|
|
|
11
11
|
import { createArvoEventRouter } from './ArvoEventRouter/helpers';
|
|
12
12
|
import AbstractArvoEventHandler from './AbstractArvoEventHandler';
|
|
13
13
|
import { createSpanFromEvent } from './OpenTelemetry/utils';
|
|
14
|
-
|
|
14
|
+
import { ExecutionOpenTelemetryConfiguration } from './AbstractArvoEventHandler/types';
|
|
15
|
+
export { ArvoEventHandler, createArvoEventHandler, IArvoEventHandler, ArvoEventHandlerFunctionOutput, ArvoEventHandlerFunctionInput, ArvoEventHandlerFunction, PartialExcept, MultiArvoEventHandler, MultiArvoEventHandlerFunctionInput, MultiArvoEventHandlerFunctionOutput, MultiArvoEventHandlerFunction, IMultiArvoEventHandler, createMultiArvoEventHandler, isNullOrUndefined, getValueOrDefault, coalesce, coalesceOrDefault, IArvoEventRouter, ArvoEventRouter, createArvoEventRouter, AbstractArvoEventHandler, createSpanFromEvent as createOtelSpanFromEvent, ExecutionOpenTelemetryConfiguration, };
|