arvo-core 1.1.16 → 1.1.17
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/ArvoEvent/helpers.d.ts +2 -1
- package/dist/ArvoEvent/helpers.js +5 -2
- package/dist/ArvoEventFactory/index.d.ts +4 -3
- package/dist/ArvoEventFactory/index.js +18 -9
- package/dist/ArvoOrchestratorContract/schema.js +1 -2
- package/dist/index.d.ts +2 -1
- package/dist/types.d.ts +14 -0
- package/package.json +1 -1
@@ -1,5 +1,6 @@
|
|
1
1
|
import ArvoEvent from '.';
|
2
2
|
import { ArvoEventData, CloudEventExtension, CreateArvoEvent } from './types';
|
3
|
+
import { ExecutionOpenTelemetryConfiguration } from '../types';
|
3
4
|
/**
|
4
5
|
* Creates an ArvoEvent with the provided data and extensions.
|
5
6
|
*
|
@@ -35,4 +36,4 @@ import { ArvoEventData, CloudEventExtension, CreateArvoEvent } from './types';
|
|
35
36
|
* { customextension: 'value' },
|
36
37
|
* );
|
37
38
|
*/
|
38
|
-
export declare const createArvoEvent: <TData extends ArvoEventData, TExtension extends CloudEventExtension, TType extends string>(event: CreateArvoEvent<TData, TType>, extensions?: TExtension) => ArvoEvent<TData, TExtension, TType>;
|
39
|
+
export declare const createArvoEvent: <TData extends ArvoEventData, TExtension extends CloudEventExtension, TType extends string>(event: CreateArvoEvent<TData, TType>, extensions?: TExtension, opentelemetry?: ExecutionOpenTelemetryConfiguration) => ArvoEvent<TData, TExtension, TType>;
|
@@ -45,8 +45,11 @@ var uuid_1 = require("uuid");
|
|
45
45
|
* { customextension: 'value' },
|
46
46
|
* );
|
47
47
|
*/
|
48
|
-
var createArvoEvent = function (event, extensions) {
|
49
|
-
|
48
|
+
var createArvoEvent = function (event, extensions, opentelemetry) {
|
49
|
+
if (opentelemetry === void 0) { opentelemetry = {
|
50
|
+
tracer: OpenTelemetry_1.ArvoCoreTracer,
|
51
|
+
}; }
|
52
|
+
var span = opentelemetry.tracer.startSpan("createArvoEvent<".concat(event.type, ">"), {});
|
50
53
|
return api_1.context.with(api_1.trace.setSpan(api_1.context.active(), span), function () {
|
51
54
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
52
55
|
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import ArvoContract from '../ArvoContract';
|
2
2
|
import { z } from 'zod';
|
3
3
|
import { CreateArvoEvent } from '../ArvoEvent/types';
|
4
|
+
import { ExecutionOpenTelemetryConfiguration } from '../types';
|
4
5
|
/**
|
5
6
|
* A factory class for creating contractual ArvoEvents based on a given ArvoContract.
|
6
7
|
*
|
@@ -26,7 +27,7 @@ export default class ArvoEventFactory<TUri extends string = string, TType extend
|
|
26
27
|
* @returns The created ArvoEvent as per the accept record of the contract.
|
27
28
|
* @throws If the event data fails validation against the contract.
|
28
29
|
*/
|
29
|
-
accepts<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.input<TAcceptSchema>, TType>, 'type' | 'datacontenttype' | 'dataschema'>, extensions?: TExtension): import("..").ArvoEvent<z.TypeOf<TAcceptSchema>, TExtension, TType>;
|
30
|
+
accepts<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.input<TAcceptSchema>, TType>, 'type' | 'datacontenttype' | 'dataschema'>, extensions?: TExtension, opentelemetry?: ExecutionOpenTelemetryConfiguration): import("..").ArvoEvent<z.TypeOf<TAcceptSchema>, TExtension, TType>;
|
30
31
|
/**
|
31
32
|
* Creates an ArvoEvent as per one of the emits record in the contract.
|
32
33
|
*
|
@@ -37,7 +38,7 @@ export default class ArvoEventFactory<TUri extends string = string, TType extend
|
|
37
38
|
* @returns The created ArvoEvent as per one of the emits records of the contract.
|
38
39
|
* @throws If the event data fails validation against the contract.
|
39
40
|
*/
|
40
|
-
emits<U extends keyof TEmits & string, TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.input<TEmits[U]>, U>, 'datacontenttype' | 'dataschema'>, extensions?: TExtension): import("..").ArvoEvent<z.TypeOf<TEmits[U]>, TExtension, U>;
|
41
|
+
emits<U extends keyof TEmits & string, TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.input<TEmits[U]>, U>, 'datacontenttype' | 'dataschema'>, extensions?: TExtension, opentelemetry?: ExecutionOpenTelemetryConfiguration): import("..").ArvoEvent<z.TypeOf<TEmits[U]>, TExtension, U>;
|
41
42
|
/**
|
42
43
|
* Creates a system error ArvoEvent.
|
43
44
|
*
|
@@ -48,7 +49,7 @@ export default class ArvoEventFactory<TUri extends string = string, TType extend
|
|
48
49
|
*/
|
49
50
|
systemError<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<any, any>, 'data' | 'type' | 'datacontenttype' | 'dataschema'> & {
|
50
51
|
error: Error;
|
51
|
-
}, extensions?: TExtension): import("..").ArvoEvent<{
|
52
|
+
}, extensions?: TExtension, opentelemetry?: ExecutionOpenTelemetryConfiguration): import("..").ArvoEvent<{
|
52
53
|
errorMessage: string;
|
53
54
|
errorName: string;
|
54
55
|
errorStack: string | null;
|
@@ -52,9 +52,12 @@ var ArvoEventFactory = /** @class */ (function () {
|
|
52
52
|
* @returns The created ArvoEvent as per the accept record of the contract.
|
53
53
|
* @throws If the event data fails validation against the contract.
|
54
54
|
*/
|
55
|
-
ArvoEventFactory.prototype.accepts = function (event, extensions) {
|
55
|
+
ArvoEventFactory.prototype.accepts = function (event, extensions, opentelemetry) {
|
56
56
|
var _this = this;
|
57
|
-
|
57
|
+
if (opentelemetry === void 0) { opentelemetry = {
|
58
|
+
tracer: OpenTelemetry_1.ArvoCoreTracer,
|
59
|
+
}; }
|
60
|
+
var span = opentelemetry.tracer.startSpan("ArvoEventFactory<".concat(this.contract.uri, ">.accepts<").concat(this.contract.accepts.type, ">.create"));
|
58
61
|
return api_1.context.with(api_1.trace.setSpan(api_1.context.active(), span), function () {
|
59
62
|
var _a, _b, _c, _d;
|
60
63
|
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
@@ -64,7 +67,7 @@ var ArvoEventFactory = /** @class */ (function () {
|
|
64
67
|
if (!validationResult.success) {
|
65
68
|
throw new Error("Accept Event data validation failed: ".concat(validationResult.error.message));
|
66
69
|
}
|
67
|
-
return (0, helpers_1.createArvoEvent)(__assign(__assign({}, event), { traceparent: (_b = (_a = event.traceparent) !== null && _a !== void 0 ? _a : otelHeaders.traceparent) !== null && _b !== void 0 ? _b : undefined, tracestate: (_d = (_c = event.tracestate) !== null && _c !== void 0 ? _c : otelHeaders.tracestate) !== null && _d !== void 0 ? _d : undefined, type: _this.contract.accepts.type, datacontenttype: schema_1.ArvoDataContentType, dataschema: _this.contract.uri, data: validationResult.data }), extensions);
|
70
|
+
return (0, helpers_1.createArvoEvent)(__assign(__assign({}, event), { traceparent: (_b = (_a = event.traceparent) !== null && _a !== void 0 ? _a : otelHeaders.traceparent) !== null && _b !== void 0 ? _b : undefined, tracestate: (_d = (_c = event.tracestate) !== null && _c !== void 0 ? _c : otelHeaders.tracestate) !== null && _d !== void 0 ? _d : undefined, type: _this.contract.accepts.type, datacontenttype: schema_1.ArvoDataContentType, dataschema: _this.contract.uri, data: validationResult.data }), extensions, opentelemetry);
|
68
71
|
}
|
69
72
|
catch (error) {
|
70
73
|
(0, OpenTelemetry_1.exceptionToSpan)(error);
|
@@ -89,9 +92,12 @@ var ArvoEventFactory = /** @class */ (function () {
|
|
89
92
|
* @returns The created ArvoEvent as per one of the emits records of the contract.
|
90
93
|
* @throws If the event data fails validation against the contract.
|
91
94
|
*/
|
92
|
-
ArvoEventFactory.prototype.emits = function (event, extensions) {
|
95
|
+
ArvoEventFactory.prototype.emits = function (event, extensions, opentelemetry) {
|
93
96
|
var _this = this;
|
94
|
-
|
97
|
+
if (opentelemetry === void 0) { opentelemetry = {
|
98
|
+
tracer: OpenTelemetry_1.ArvoCoreTracer,
|
99
|
+
}; }
|
100
|
+
var span = opentelemetry.tracer.startSpan("ArvoEventFactory<".concat(this.contract.uri, ">.emits<").concat(event.type, ">.create"));
|
95
101
|
return api_1.context.with(api_1.trace.setSpan(api_1.context.active(), span), function () {
|
96
102
|
var _a, _b, _c, _d;
|
97
103
|
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
@@ -101,7 +107,7 @@ var ArvoEventFactory = /** @class */ (function () {
|
|
101
107
|
if (!validationResult.success) {
|
102
108
|
throw new Error("Emit Event data validation failed: ".concat(validationResult.error.message));
|
103
109
|
}
|
104
|
-
return (0, helpers_1.createArvoEvent)(__assign(__assign({}, event), { traceparent: (_b = (_a = event.traceparent) !== null && _a !== void 0 ? _a : otelHeaders.traceparent) !== null && _b !== void 0 ? _b : undefined, tracestate: (_d = (_c = event.tracestate) !== null && _c !== void 0 ? _c : otelHeaders.tracestate) !== null && _d !== void 0 ? _d : undefined, datacontenttype: schema_1.ArvoDataContentType, dataschema: _this.contract.uri, data: validationResult.data }), extensions);
|
110
|
+
return (0, helpers_1.createArvoEvent)(__assign(__assign({}, event), { traceparent: (_b = (_a = event.traceparent) !== null && _a !== void 0 ? _a : otelHeaders.traceparent) !== null && _b !== void 0 ? _b : undefined, tracestate: (_d = (_c = event.tracestate) !== null && _c !== void 0 ? _c : otelHeaders.tracestate) !== null && _d !== void 0 ? _d : undefined, datacontenttype: schema_1.ArvoDataContentType, dataschema: _this.contract.uri, data: validationResult.data }), extensions, opentelemetry);
|
105
111
|
}
|
106
112
|
catch (error) {
|
107
113
|
(0, OpenTelemetry_1.exceptionToSpan)(error);
|
@@ -124,9 +130,12 @@ var ArvoEventFactory = /** @class */ (function () {
|
|
124
130
|
* @param [extensions] - Optional extensions to add to the event.
|
125
131
|
* @returns The created system error ArvoEvent.
|
126
132
|
*/
|
127
|
-
ArvoEventFactory.prototype.systemError = function (event, extensions) {
|
133
|
+
ArvoEventFactory.prototype.systemError = function (event, extensions, opentelemetry) {
|
128
134
|
var _this = this;
|
129
|
-
|
135
|
+
if (opentelemetry === void 0) { opentelemetry = {
|
136
|
+
tracer: OpenTelemetry_1.ArvoCoreTracer,
|
137
|
+
}; }
|
138
|
+
var span = opentelemetry.tracer.startSpan("ArvoEventFactory<".concat(this.contract.uri, ">.systemError<sys.").concat(this.contract.accepts.type, ".error>.create"));
|
130
139
|
return api_1.context.with(api_1.trace.setSpan(api_1.context.active(), span), function () {
|
131
140
|
var _a, _b, _c, _d, _e;
|
132
141
|
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
@@ -137,7 +146,7 @@ var ArvoEventFactory = /** @class */ (function () {
|
|
137
146
|
errorName: error.name,
|
138
147
|
errorMessage: error.message,
|
139
148
|
errorStack: (_e = error.stack) !== null && _e !== void 0 ? _e : null,
|
140
|
-
}, datacontenttype: schema_1.ArvoDataContentType, dataschema: _this.contract.uri }), extensions);
|
149
|
+
}, datacontenttype: schema_1.ArvoDataContentType, dataschema: _this.contract.uri }), extensions, opentelemetry);
|
141
150
|
}
|
142
151
|
catch (error) {
|
143
152
|
(0, OpenTelemetry_1.exceptionToSpan)(error);
|
@@ -8,8 +8,7 @@ var utils_1 = require("../utils");
|
|
8
8
|
* This schema is used to validate and type-check the minimal required fields
|
9
9
|
* for an orchestrator to accept a task or event.
|
10
10
|
*/
|
11
|
-
exports.OrchestrationInitEventBaseSchema = zod_1.z
|
12
|
-
.object({
|
11
|
+
exports.OrchestrationInitEventBaseSchema = zod_1.z.object({
|
13
12
|
parentSubject$$: zod_1.z
|
14
13
|
.string()
|
15
14
|
.min(1, 'The parent subject must not be an empty string')
|
package/dist/index.d.ts
CHANGED
@@ -28,6 +28,7 @@ import { createArvoOrchestratorContract } from './ArvoOrchestratorContract/helpe
|
|
28
28
|
import ArvoOrchestratorContract from './ArvoOrchestratorContract';
|
29
29
|
import { ICreateArvoOrchestratorContract, IArvoOrchestratorContract } from './ArvoOrchestratorContract/types';
|
30
30
|
import { ArvoOrchestratorEventTypeGen } from './ArvoOrchestratorContract/typegen';
|
31
|
+
import { ExecutionOpenTelemetryConfiguration } from './types';
|
31
32
|
/**
|
32
33
|
* Collection of Zod schemas for validating various aspects of Arvo events.
|
33
34
|
* @property {z.ZodObject} CloudEventContextSchema - Schema for core CloudEvent properties.
|
@@ -102,4 +103,4 @@ declare const ArvoEventSchemas: {
|
|
102
103
|
parentSubject$$: string | null;
|
103
104
|
}>;
|
104
105
|
};
|
105
|
-
export { ArvoEventHttpConfig, ArvoEventHttp, ArvoEvent, createArvoEvent, ArvoDataContentType, ArvoEventData, CloudEventExtension, ArvoEventSchemas, CloudEventContext, ArvoExtension, OpenTelemetryExtension, CreateArvoEvent, exceptionToSpan, logToSpan, OpenTelemetryHeaders, TelemetryLogLevel, OTelNull, validateURI, cleanString, ArvoContract, createArvoContract, ArvoContractValidators, ArvoContractRecord, IArvoContract, ResolveArvoContractRecord, ArvoContractLibrary, createArvoContractLibrary, ArvoEventFactory, createArvoEventFactory, ArvoErrorSchema, currentOpenTelemetryHeaders, OpenInference, OpenInferenceSpanKind, ArvoExecution, ArvoExecutionSpanKind, ArvoContractJSONSchema, ArvoOrchestrationSubject, ArvoOrchestrationSubjectContentSchema, ArvoOrchestratorVersionSchema, ArvoOrchestrationSubjectContent, ArvoOrchestratorVersion, InferArvoEvent, InferArvoContract, InferArvoContractType, createArvoOrchestratorContract, ArvoOrchestratorContract, ICreateArvoOrchestratorContract, IArvoOrchestratorContract, InferArvoOrchestratorContract, ArvoOrchestratorEventTypeGen, };
|
106
|
+
export { ArvoEventHttpConfig, ArvoEventHttp, ArvoEvent, createArvoEvent, ArvoDataContentType, ArvoEventData, CloudEventExtension, ArvoEventSchemas, CloudEventContext, ArvoExtension, OpenTelemetryExtension, CreateArvoEvent, exceptionToSpan, logToSpan, OpenTelemetryHeaders, TelemetryLogLevel, OTelNull, validateURI, cleanString, ArvoContract, createArvoContract, ArvoContractValidators, ArvoContractRecord, IArvoContract, ResolveArvoContractRecord, ArvoContractLibrary, createArvoContractLibrary, ArvoEventFactory, createArvoEventFactory, ArvoErrorSchema, currentOpenTelemetryHeaders, OpenInference, OpenInferenceSpanKind, ArvoExecution, ArvoExecutionSpanKind, ArvoContractJSONSchema, ArvoOrchestrationSubject, ArvoOrchestrationSubjectContentSchema, ArvoOrchestratorVersionSchema, ArvoOrchestrationSubjectContent, ArvoOrchestratorVersion, InferArvoEvent, InferArvoContract, InferArvoContractType, createArvoOrchestratorContract, ArvoOrchestratorContract, ICreateArvoOrchestratorContract, IArvoOrchestratorContract, InferArvoOrchestratorContract, ArvoOrchestratorEventTypeGen, ExecutionOpenTelemetryConfiguration, };
|
package/dist/types.d.ts
CHANGED
@@ -3,6 +3,20 @@ import ArvoContract from './ArvoContract';
|
|
3
3
|
import ArvoEvent from './ArvoEvent';
|
4
4
|
import { ArvoExtension, OpenTelemetryExtension } from './ArvoEvent/types';
|
5
5
|
import ArvoOrchestratorContract from './ArvoOrchestratorContract';
|
6
|
+
import { Tracer } from '@opentelemetry/api';
|
7
|
+
/**
|
8
|
+
* Configuration options for OpenTelemetry integration in execution context.
|
9
|
+
*
|
10
|
+
* This type defines how tracing should be configured and inherited within
|
11
|
+
* the execution pipeline.
|
12
|
+
*/
|
13
|
+
export type ExecutionOpenTelemetryConfiguration = {
|
14
|
+
/**
|
15
|
+
* Optional OpenTelemetry tracer instance to use for creating spans.
|
16
|
+
* If not provided, a default tracer may be used depending on the implementation.
|
17
|
+
*/
|
18
|
+
tracer: Tracer;
|
19
|
+
};
|
6
20
|
/**
|
7
21
|
* A type utility that infers the structure of an ArvoEvent.
|
8
22
|
*
|