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.
@@ -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 });
@@ -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;