arvo-event-handler 2.0.4 → 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.
- 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 +118 -135
- 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 +75 -120
- 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/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,87 +0,0 @@
|
|
|
1
|
-
import { Span, SpanKind, Tracer, Context } from '@opentelemetry/api';
|
|
2
|
-
import { ArvoEvent, ArvoExecutionSpanKind, OpenInferenceSpanKind } from 'arvo-core';
|
|
3
|
-
import { ICreateOtelSpan } from './types';
|
|
4
|
-
export declare const extractContext: (traceparent: string, tracestate: string | null) => Context;
|
|
5
|
-
/**
|
|
6
|
-
* Creates an OpenTelemetry span from an ArvoEvent, facilitating distributed tracing in the Arvo system.
|
|
7
|
-
*
|
|
8
|
-
* This function is a cornerstone of Arvo's observability infrastructure, creating spans that represent
|
|
9
|
-
* discrete units of work or operations within the system. It supports both creating new root spans
|
|
10
|
-
* and continuing existing traces, enabling comprehensive end-to-end tracing across distributed components.
|
|
11
|
-
*
|
|
12
|
-
* @param spanName - A descriptive name for the span, indicating the operation being traced.
|
|
13
|
-
* Choose a name that clearly identifies the work being performed.
|
|
14
|
-
*
|
|
15
|
-
* @param event - The ArvoEvent that triggers the span creation. This event may contain
|
|
16
|
-
* tracing context (traceparent and tracestate) to link this span to an existing trace.
|
|
17
|
-
*
|
|
18
|
-
* @param spanKinds - An object specifying the span's categorization across different tracing contexts:
|
|
19
|
-
* @param spanKinds.kind - OpenTelemetry SpanKind, indicating the span's role in the trace hierarchy
|
|
20
|
-
* (e.g., SERVER, CLIENT, INTERNAL).
|
|
21
|
-
* @param spanKinds.openInference - OpenInference span kind, used for AI/ML operation categorization.
|
|
22
|
-
* @param spanKinds.arvoExecution - ArvoExecution span kind, for Arvo-specific execution context labeling.
|
|
23
|
-
*
|
|
24
|
-
* @param tracer - The OpenTelemetry Tracer instance to use for creating the span.
|
|
25
|
-
* Defaults to ArvoXStateTracer if not provided.
|
|
26
|
-
*
|
|
27
|
-
* @returns A new OpenTelemetry Span object that can be used to record operation details,
|
|
28
|
-
* set attributes, and create child spans.
|
|
29
|
-
*
|
|
30
|
-
* @remarks
|
|
31
|
-
* - If the input event contains a 'traceparent', the function will continue the existing trace,
|
|
32
|
-
* maintaining the distributed tracing context across system boundaries.
|
|
33
|
-
* - Without a 'traceparent', a new root span is created, potentially starting a new trace.
|
|
34
|
-
* - The function automatically sets OpenInference and ArvoExecution-specific attributes,
|
|
35
|
-
* enhancing the span's context for specialized analysis.
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```typescript
|
|
39
|
-
* const event: ArvoEvent = createArvoEvent({
|
|
40
|
-
* type: 'orderProcess',
|
|
41
|
-
* data: { orderId: '12345' },
|
|
42
|
-
* traceparent: "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01",
|
|
43
|
-
* tracestate: "rojo=00f067aa0ba902b7",
|
|
44
|
-
* ...
|
|
45
|
-
* });
|
|
46
|
-
*
|
|
47
|
-
* const span = createSpanFromEvent("processOrder", event, {
|
|
48
|
-
* kind: SpanKind.INTERNAL,
|
|
49
|
-
* openInference: OpenInferenceSpanKind.LLM,
|
|
50
|
-
* arvoExecution: ArvoExecutionSpanKind.EVENT_HANDLER
|
|
51
|
-
* });
|
|
52
|
-
*
|
|
53
|
-
* context.with(trace.setSpan(context.active(), span), () => {
|
|
54
|
-
* try {
|
|
55
|
-
* // Perform order processing logic
|
|
56
|
-
* span.setAttributes({ orderId: '12345', status: 'processing' });
|
|
57
|
-
* // ... more processing ...
|
|
58
|
-
* span.setStatus({ code: SpanStatusCode.OK });
|
|
59
|
-
* } catch (error) {
|
|
60
|
-
* span.setStatus({ code: SpanStatusCode.ERROR, message: error.message });
|
|
61
|
-
* } finally {
|
|
62
|
-
* span.end(); // Always remember to end the span
|
|
63
|
-
* }
|
|
64
|
-
* })
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
export declare const createSpanFromEvent: (spanName: string, event: ArvoEvent, spanKinds: {
|
|
68
|
-
kind: SpanKind;
|
|
69
|
-
openInference: OpenInferenceSpanKind;
|
|
70
|
-
arvoExecution: ArvoExecutionSpanKind;
|
|
71
|
-
}, tracer: Tracer) => Span;
|
|
72
|
-
/**
|
|
73
|
-
* Creates an OpenTelemetry span for tracking handler execution.
|
|
74
|
-
*
|
|
75
|
-
* This function creates a span either from an existing event or as a new span,
|
|
76
|
-
* depending on the configuration. It includes attributes for both OpenInference
|
|
77
|
-
* and Arvo execution span kinds.
|
|
78
|
-
*
|
|
79
|
-
* @param params - Parameters for creating the handler execution span
|
|
80
|
-
* @param params.spanName - Name of the span to be created
|
|
81
|
-
* @param params.spanKinds - Object containing different span kind classifications
|
|
82
|
-
* @param params.event - The Arvo event associated with this span
|
|
83
|
-
* @param params.opentelemetryConfig - OpenTelemetry configuration
|
|
84
|
-
*
|
|
85
|
-
* @returns A new OpenTelemetry span configured according to the parameters
|
|
86
|
-
*/
|
|
87
|
-
export declare const createOtelSpan: ({ spanName, spanKinds, event, opentelemetryConfig, }: ICreateOtelSpan) => Span;
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createOtelSpan = exports.createSpanFromEvent = exports.extractContext = void 0;
|
|
4
|
-
var api_1 = require("@opentelemetry/api");
|
|
5
|
-
var arvo_core_1 = require("arvo-core");
|
|
6
|
-
var _1 = require(".");
|
|
7
|
-
// Helper function to extract context from traceparent and tracestate
|
|
8
|
-
var extractContext = function (traceparent, tracestate) {
|
|
9
|
-
var extractedContext = api_1.propagation.extract(api_1.context.active(), {
|
|
10
|
-
traceparent: traceparent,
|
|
11
|
-
tracestate: tracestate !== null && tracestate !== void 0 ? tracestate : undefined,
|
|
12
|
-
});
|
|
13
|
-
return extractedContext;
|
|
14
|
-
};
|
|
15
|
-
exports.extractContext = extractContext;
|
|
16
|
-
/**
|
|
17
|
-
* Creates an OpenTelemetry span from an ArvoEvent, facilitating distributed tracing in the Arvo system.
|
|
18
|
-
*
|
|
19
|
-
* This function is a cornerstone of Arvo's observability infrastructure, creating spans that represent
|
|
20
|
-
* discrete units of work or operations within the system. It supports both creating new root spans
|
|
21
|
-
* and continuing existing traces, enabling comprehensive end-to-end tracing across distributed components.
|
|
22
|
-
*
|
|
23
|
-
* @param spanName - A descriptive name for the span, indicating the operation being traced.
|
|
24
|
-
* Choose a name that clearly identifies the work being performed.
|
|
25
|
-
*
|
|
26
|
-
* @param event - The ArvoEvent that triggers the span creation. This event may contain
|
|
27
|
-
* tracing context (traceparent and tracestate) to link this span to an existing trace.
|
|
28
|
-
*
|
|
29
|
-
* @param spanKinds - An object specifying the span's categorization across different tracing contexts:
|
|
30
|
-
* @param spanKinds.kind - OpenTelemetry SpanKind, indicating the span's role in the trace hierarchy
|
|
31
|
-
* (e.g., SERVER, CLIENT, INTERNAL).
|
|
32
|
-
* @param spanKinds.openInference - OpenInference span kind, used for AI/ML operation categorization.
|
|
33
|
-
* @param spanKinds.arvoExecution - ArvoExecution span kind, for Arvo-specific execution context labeling.
|
|
34
|
-
*
|
|
35
|
-
* @param tracer - The OpenTelemetry Tracer instance to use for creating the span.
|
|
36
|
-
* Defaults to ArvoXStateTracer if not provided.
|
|
37
|
-
*
|
|
38
|
-
* @returns A new OpenTelemetry Span object that can be used to record operation details,
|
|
39
|
-
* set attributes, and create child spans.
|
|
40
|
-
*
|
|
41
|
-
* @remarks
|
|
42
|
-
* - If the input event contains a 'traceparent', the function will continue the existing trace,
|
|
43
|
-
* maintaining the distributed tracing context across system boundaries.
|
|
44
|
-
* - Without a 'traceparent', a new root span is created, potentially starting a new trace.
|
|
45
|
-
* - The function automatically sets OpenInference and ArvoExecution-specific attributes,
|
|
46
|
-
* enhancing the span's context for specialized analysis.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```typescript
|
|
50
|
-
* const event: ArvoEvent = createArvoEvent({
|
|
51
|
-
* type: 'orderProcess',
|
|
52
|
-
* data: { orderId: '12345' },
|
|
53
|
-
* traceparent: "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01",
|
|
54
|
-
* tracestate: "rojo=00f067aa0ba902b7",
|
|
55
|
-
* ...
|
|
56
|
-
* });
|
|
57
|
-
*
|
|
58
|
-
* const span = createSpanFromEvent("processOrder", event, {
|
|
59
|
-
* kind: SpanKind.INTERNAL,
|
|
60
|
-
* openInference: OpenInferenceSpanKind.LLM,
|
|
61
|
-
* arvoExecution: ArvoExecutionSpanKind.EVENT_HANDLER
|
|
62
|
-
* });
|
|
63
|
-
*
|
|
64
|
-
* context.with(trace.setSpan(context.active(), span), () => {
|
|
65
|
-
* try {
|
|
66
|
-
* // Perform order processing logic
|
|
67
|
-
* span.setAttributes({ orderId: '12345', status: 'processing' });
|
|
68
|
-
* // ... more processing ...
|
|
69
|
-
* span.setStatus({ code: SpanStatusCode.OK });
|
|
70
|
-
* } catch (error) {
|
|
71
|
-
* span.setStatus({ code: SpanStatusCode.ERROR, message: error.message });
|
|
72
|
-
* } finally {
|
|
73
|
-
* span.end(); // Always remember to end the span
|
|
74
|
-
* }
|
|
75
|
-
* })
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
var createSpanFromEvent = function (spanName, event, spanKinds, tracer) {
|
|
79
|
-
var _a;
|
|
80
|
-
var spanOptions = {
|
|
81
|
-
kind: spanKinds.kind,
|
|
82
|
-
attributes: (_a = {},
|
|
83
|
-
_a[arvo_core_1.OpenInference.ATTR_SPAN_KIND] = spanKinds.openInference,
|
|
84
|
-
_a[arvo_core_1.ArvoExecution.ATTR_SPAN_KIND] = spanKinds.arvoExecution,
|
|
85
|
-
_a),
|
|
86
|
-
};
|
|
87
|
-
var span;
|
|
88
|
-
if (event.traceparent) {
|
|
89
|
-
var inheritedContext = (0, exports.extractContext)(event.traceparent, event.tracestate);
|
|
90
|
-
span = tracer.startSpan(spanName, spanOptions, inheritedContext);
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
span = tracer.startSpan(spanName, spanOptions);
|
|
94
|
-
}
|
|
95
|
-
return span;
|
|
96
|
-
};
|
|
97
|
-
exports.createSpanFromEvent = createSpanFromEvent;
|
|
98
|
-
/**
|
|
99
|
-
* Creates an OpenTelemetry span for tracking handler execution.
|
|
100
|
-
*
|
|
101
|
-
* This function creates a span either from an existing event or as a new span,
|
|
102
|
-
* depending on the configuration. It includes attributes for both OpenInference
|
|
103
|
-
* and Arvo execution span kinds.
|
|
104
|
-
*
|
|
105
|
-
* @param params - Parameters for creating the handler execution span
|
|
106
|
-
* @param params.spanName - Name of the span to be created
|
|
107
|
-
* @param params.spanKinds - Object containing different span kind classifications
|
|
108
|
-
* @param params.event - The Arvo event associated with this span
|
|
109
|
-
* @param params.opentelemetryConfig - OpenTelemetry configuration
|
|
110
|
-
*
|
|
111
|
-
* @returns A new OpenTelemetry span configured according to the parameters
|
|
112
|
-
*/
|
|
113
|
-
var createOtelSpan = function (_a) {
|
|
114
|
-
var _b;
|
|
115
|
-
var _c;
|
|
116
|
-
var spanName = _a.spanName, spanKinds = _a.spanKinds, event = _a.event, opentelemetryConfig = _a.opentelemetryConfig;
|
|
117
|
-
opentelemetryConfig = opentelemetryConfig !== null && opentelemetryConfig !== void 0 ? opentelemetryConfig : {
|
|
118
|
-
inheritFrom: 'event',
|
|
119
|
-
tracer: null,
|
|
120
|
-
};
|
|
121
|
-
var spanOptions = {
|
|
122
|
-
kind: spanKinds.kind,
|
|
123
|
-
attributes: (_b = {},
|
|
124
|
-
_b[arvo_core_1.OpenInference.ATTR_SPAN_KIND] = spanKinds.openInference,
|
|
125
|
-
_b[arvo_core_1.ArvoExecution.ATTR_SPAN_KIND] = spanKinds.arvoExecution,
|
|
126
|
-
_b),
|
|
127
|
-
};
|
|
128
|
-
var tracer = (_c = opentelemetryConfig.tracer) !== null && _c !== void 0 ? _c : (0, _1.fetchOpenTelemetryTracer)();
|
|
129
|
-
return opentelemetryConfig.inheritFrom === 'event'
|
|
130
|
-
? (0, exports.createSpanFromEvent)(spanName, event, spanKinds, tracer)
|
|
131
|
-
: tracer.startSpan(spanName, spanOptions);
|
|
132
|
-
};
|
|
133
|
-
exports.createOtelSpan = createOtelSpan;
|