@usearazzo/runner 1.0.1-alpha.33 → 1.0.1-alpha.35
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/CHANGELOG.md +22 -0
- package/README.md +15 -1
- package/dist/arazzo-runner.browser.js +1516 -265
- package/dist/arazzo-runner.browser.min.js +1 -1
- package/package.json +64 -18
- package/src/ArazzoRunner.cjs +26 -3
- package/src/ArazzoRunner.mjs +26 -3
- package/src/client/OpenAPIOperationResponse.cjs +9 -0
- package/src/client/OpenAPIOperationResponse.mjs +9 -0
- package/src/document/APIDocument.cjs +53 -0
- package/src/document/APIDocument.mjs +53 -0
- package/src/errors/ExecutionError.cjs +2 -0
- package/src/errors/ExecutionError.mjs +2 -0
- package/src/executor/OpenAPIOperationExecutor.cjs +77 -6
- package/src/executor/OpenAPIOperationExecutor.mjs +77 -6
- package/src/executor/StepExecutor.cjs +16 -2
- package/src/executor/StepExecutor.mjs +16 -2
- package/src/executor/StepRetryRunner.cjs +5 -3
- package/src/executor/StepRetryRunner.mjs +5 -3
- package/src/executor/StepTransitionInterpreter.cjs +1 -1
- package/src/executor/StepTransitionInterpreter.mjs +1 -1
- package/src/executor/WorkflowCallStack.cjs +1 -1
- package/src/executor/WorkflowCallStack.mjs +1 -1
- package/src/executor/WorkflowExecutor.cjs +447 -89
- package/src/executor/WorkflowExecutor.mjs +447 -89
- package/src/index.cjs +21 -0
- package/src/index.mjs +4 -0
- package/src/observability/ArazzoRunnerEvent.cjs +5 -0
- package/src/observability/ArazzoRunnerEvent.mjs +1 -0
- package/src/observability/DocumentRegistryEvent.cjs +5 -0
- package/src/observability/DocumentRegistryEvent.mjs +1 -0
- package/src/observability/EventChannel.cjs +106 -0
- package/src/observability/EventChannel.mjs +98 -0
- package/src/observability/OpenAPIOperationEvent.cjs +5 -0
- package/src/observability/OpenAPIOperationEvent.mjs +1 -0
- package/src/observability/Redactor.cjs +215 -0
- package/src/observability/Redactor.mjs +210 -0
- package/src/observability/WorkflowExecutionEvent.cjs +5 -0
- package/src/observability/WorkflowExecutionEvent.mjs +1 -0
- package/src/observability/combineObservers.cjs +18 -0
- package/src/observability/combineObservers.mjs +12 -0
- package/src/observability/instrument.cjs +159 -0
- package/src/observability/instrument.mjs +144 -0
- package/src/observability/logging/LoggingObserver.cjs +177 -0
- package/src/observability/logging/LoggingObserver.mjs +172 -0
- package/src/observability/logging/index.cjs +13 -0
- package/src/observability/logging/index.mjs +1 -0
- package/src/observability/opentelemetry/ArazzoRunnerInstrumentation.cjs +321 -0
- package/src/observability/opentelemetry/ArazzoRunnerInstrumentation.mjs +313 -0
- package/src/observability/opentelemetry/index.cjs +13 -0
- package/src/observability/opentelemetry/index.mjs +1 -0
- package/src/observability/stream/EventStream.cjs +112 -0
- package/src/observability/stream/EventStream.mjs +107 -0
- package/src/observability/stream/index.cjs +13 -0
- package/src/observability/stream/index.mjs +1 -0
- package/src/registry/DocumentRegistry.cjs +27 -3
- package/src/registry/DocumentRegistry.mjs +27 -3
- package/src/registry/providers/ArazzoDocumentRegistryProvider.cjs +20 -0
- package/src/registry/providers/ArazzoDocumentRegistryProvider.mjs +21 -1
- package/src/registry/providers/DocumentRegistryProvider.cjs +14 -0
- package/src/registry/providers/DocumentRegistryProvider.mjs +14 -0
- package/src/registry/providers/OpenAPIDocumentRegistryProvider.cjs +27 -5
- package/src/registry/providers/OpenAPIDocumentRegistryProvider.mjs +27 -5
- package/src/version.cjs +9 -0
- package/src/version.mjs +3 -0
- package/types/observability/logging/LoggingObserver.d.ts +82 -0
- package/types/observability/logging/index.d.ts +2 -0
- package/types/observability/opentelemetry/ArazzoRunnerInstrumentation.d.ts +84 -0
- package/types/observability/opentelemetry/index.d.ts +2 -0
- package/types/observability/stream/EventStream.d.ts +68 -0
- package/types/observability/stream/index.d.ts +2 -0
- package/types/runner.d.ts +802 -5
|
@@ -86,11 +86,13 @@ class ArazzoDocumentRegistryProvider extends _DocumentRegistryProvider.default {
|
|
|
86
86
|
*/
|
|
87
87
|
async provide(uri) {
|
|
88
88
|
const parseResult = await (0, _parser.parseArazzo)(uri, this.#buildParseOptions());
|
|
89
|
+
this.assertParsed(uri, parseResult);
|
|
89
90
|
const {
|
|
90
91
|
workflowIndex,
|
|
91
92
|
stepIndex,
|
|
92
93
|
sourceDescriptionIndex
|
|
93
94
|
} = this.#buildIndexes(uri, parseResult);
|
|
95
|
+
ArazzoDocumentRegistryProvider.#recordPointers(parseResult);
|
|
94
96
|
return new _ArazzoDocument.default(uri, parseResult, workflowIndex, stepIndex, sourceDescriptionIndex);
|
|
95
97
|
}
|
|
96
98
|
|
|
@@ -150,6 +152,24 @@ class ArazzoDocumentRegistryProvider extends _DocumentRegistryProvider.default {
|
|
|
150
152
|
sourceDescriptionIndex
|
|
151
153
|
};
|
|
152
154
|
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Records, in each element's `json-pointer` meta, where it is written: every
|
|
158
|
+
* workflow, step, criterion and action, its `components` included, and
|
|
159
|
+
* every `dependsOn` entry. The record travels with the element through
|
|
160
|
+
* normalization, so an inherited or referenced element keeps the pointer of
|
|
161
|
+
* where it is defined, for the events to locate it by.
|
|
162
|
+
*/
|
|
163
|
+
static #recordPointers(parseResult) {
|
|
164
|
+
(0, _apidomTraverse.traverse)(parseResult.api, {
|
|
165
|
+
enter(path) {
|
|
166
|
+
const element = path.node;
|
|
167
|
+
const located = (0, _apidomNsArazzo.isWorkflowElement)(element) || (0, _apidomNsArazzo.isStepElement)(element) || (0, _apidomNsArazzo.isCriterionElement)(element) || (0, _apidomNsArazzo.isSuccessActionElement)(element) || (0, _apidomNsArazzo.isFailureActionElement)(element) || (0, _apidomNsArazzo.isWorkflowDependsOnElement)(path.parentPath?.node);
|
|
168
|
+
if (!located) return;
|
|
169
|
+
element.meta.set('json-pointer', path.formatPath('jsonpointer'));
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
153
173
|
#buildParseOptions() {
|
|
154
174
|
return (0, _empty.mergeOptions)(_parser.defaultParseArazzoOptions, this.#options);
|
|
155
175
|
}
|
|
@@ -4,7 +4,7 @@ import { UnmatchedResolverError } from '@speclynx/apidom-reference/configuration
|
|
|
4
4
|
import { toValue } from '@speclynx/apidom-core';
|
|
5
5
|
import { isArrayElement, isStringElement } from '@speclynx/apidom-datamodel';
|
|
6
6
|
import { traverse } from '@speclynx/apidom-traverse';
|
|
7
|
-
import { isStepElement } from '@speclynx/apidom-ns-arazzo-1';
|
|
7
|
+
import { isCriterionElement, isFailureActionElement, isStepElement, isSuccessActionElement, isWorkflowDependsOnElement, isWorkflowElement } from '@speclynx/apidom-ns-arazzo-1';
|
|
8
8
|
import * as constants from "../../constants.mjs";
|
|
9
9
|
import ArazzoDocument from "../../document/ArazzoDocument.mjs";
|
|
10
10
|
import DocumentRegistryProvider, { circularReplacer } from "./DocumentRegistryProvider.mjs";
|
|
@@ -78,11 +78,13 @@ class ArazzoDocumentRegistryProvider extends DocumentRegistryProvider {
|
|
|
78
78
|
*/
|
|
79
79
|
async provide(uri) {
|
|
80
80
|
const parseResult = await parseArazzo(uri, this.#buildParseOptions());
|
|
81
|
+
this.assertParsed(uri, parseResult);
|
|
81
82
|
const {
|
|
82
83
|
workflowIndex,
|
|
83
84
|
stepIndex,
|
|
84
85
|
sourceDescriptionIndex
|
|
85
86
|
} = this.#buildIndexes(uri, parseResult);
|
|
87
|
+
ArazzoDocumentRegistryProvider.#recordPointers(parseResult);
|
|
86
88
|
return new ArazzoDocument(uri, parseResult, workflowIndex, stepIndex, sourceDescriptionIndex);
|
|
87
89
|
}
|
|
88
90
|
|
|
@@ -142,6 +144,24 @@ class ArazzoDocumentRegistryProvider extends DocumentRegistryProvider {
|
|
|
142
144
|
sourceDescriptionIndex
|
|
143
145
|
};
|
|
144
146
|
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Records, in each element's `json-pointer` meta, where it is written: every
|
|
150
|
+
* workflow, step, criterion and action, its `components` included, and
|
|
151
|
+
* every `dependsOn` entry. The record travels with the element through
|
|
152
|
+
* normalization, so an inherited or referenced element keeps the pointer of
|
|
153
|
+
* where it is defined, for the events to locate it by.
|
|
154
|
+
*/
|
|
155
|
+
static #recordPointers(parseResult) {
|
|
156
|
+
traverse(parseResult.api, {
|
|
157
|
+
enter(path) {
|
|
158
|
+
const element = path.node;
|
|
159
|
+
const located = isWorkflowElement(element) || isStepElement(element) || isCriterionElement(element) || isSuccessActionElement(element) || isFailureActionElement(element) || isWorkflowDependsOnElement(path.parentPath?.node);
|
|
160
|
+
if (!located) return;
|
|
161
|
+
element.meta.set('json-pointer', path.formatPath('jsonpointer'));
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
145
165
|
#buildParseOptions() {
|
|
146
166
|
return mergeOptions(defaultParseArazzoOptions, this.#options);
|
|
147
167
|
}
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = exports.circularReplacer = void 0;
|
|
7
7
|
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
8
|
+
var _apidomCore = require("@speclynx/apidom-core");
|
|
9
|
+
var _parser = require("@usearazzo/parser");
|
|
8
10
|
/**
|
|
9
11
|
* Replaces circular $ref references with an empty ObjectElement
|
|
10
12
|
* annotated with the original $ref value. This ensures the dereferenced
|
|
@@ -45,5 +47,17 @@ class DocumentRegistryProvider {
|
|
|
45
47
|
/**
|
|
46
48
|
* Loads and produces a document from a URI.
|
|
47
49
|
*/
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Rejects a document the parser could only partly read. The strict parsers
|
|
53
|
+
* throw on a syntax error; the lenient ones that source maps need record it
|
|
54
|
+
* and parse what they can instead, so a document must load with source maps
|
|
55
|
+
* exactly when it loads without.
|
|
56
|
+
*/
|
|
57
|
+
assertParsed(uri, parseResult) {
|
|
58
|
+
const [error] = parseResult.errors;
|
|
59
|
+
if (error === undefined) return;
|
|
60
|
+
throw new _parser.ParseError(`Failed to parse the document at "${uri}": ${(0, _apidomCore.toValue)(error)}`);
|
|
61
|
+
}
|
|
48
62
|
}
|
|
49
63
|
var _default = exports.default = DocumentRegistryProvider;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { ObjectElement } from '@speclynx/apidom-datamodel';
|
|
2
|
+
import { toValue } from '@speclynx/apidom-core';
|
|
3
|
+
import { ParseError } from '@usearazzo/parser';
|
|
2
4
|
/**
|
|
3
5
|
* Replaces circular $ref references with an empty ObjectElement
|
|
4
6
|
* annotated with the original $ref value. This ensures the dereferenced
|
|
@@ -39,5 +41,17 @@ class DocumentRegistryProvider {
|
|
|
39
41
|
/**
|
|
40
42
|
* Loads and produces a document from a URI.
|
|
41
43
|
*/
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Rejects a document the parser could only partly read. The strict parsers
|
|
47
|
+
* throw on a syntax error; the lenient ones that source maps need record it
|
|
48
|
+
* and parse what they can instead, so a document must load with source maps
|
|
49
|
+
* exactly when it loads without.
|
|
50
|
+
*/
|
|
51
|
+
assertParsed(uri, parseResult) {
|
|
52
|
+
const [error] = parseResult.errors;
|
|
53
|
+
if (error === undefined) return;
|
|
54
|
+
throw new ParseError(`Failed to parse the document at "${uri}": ${toValue(error)}`);
|
|
55
|
+
}
|
|
42
56
|
}
|
|
43
57
|
export default DocumentRegistryProvider;
|
|
@@ -78,10 +78,11 @@ class OpenAPIDocumentRegistryProvider extends _DocumentRegistryProvider.default
|
|
|
78
78
|
*/
|
|
79
79
|
async provide(uri) {
|
|
80
80
|
const parseResult = await (0, _parser.parseOpenAPI)(uri, this.#buildParseOptions());
|
|
81
|
-
|
|
81
|
+
this.assertParsed(uri, parseResult);
|
|
82
|
+
const operationIndex = await this.#buildOperationIndex(uri, parseResult);
|
|
82
83
|
return new _OpenAPIDocument.default(uri, parseResult, operationIndex);
|
|
83
84
|
}
|
|
84
|
-
async #buildOperationIndex(parseResult) {
|
|
85
|
+
async #buildOperationIndex(uri, parseResult) {
|
|
85
86
|
const index = new _OpenAPIOperationIndex.default();
|
|
86
87
|
const dereferenceOptions = this.#buildDereferenceOptions(parseResult);
|
|
87
88
|
const apiDereferenced = await (0, _apidomTraverse.traverseAsync)(parseResult.api, {
|
|
@@ -89,16 +90,37 @@ class OpenAPIDocumentRegistryProvider extends _DocumentRegistryProvider.default
|
|
|
89
90
|
const pathItem = path.node;
|
|
90
91
|
if (!pathItem.hasMetaProperty('path')) return path.skip();
|
|
91
92
|
if (!(0, _apidomDatamodel.isStringElement)(pathItem.$ref)) return;
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
|
|
94
|
+
// an operation written next to the `$ref` stays where it is written
|
|
95
|
+
const pointer = path.formatPath('jsonpointer');
|
|
96
|
+
pathItem.forEach((value, key) => {
|
|
97
|
+
if (value.element !== 'operation') return;
|
|
98
|
+
value.meta.set('json-pointer', `${pointer}/${(0, _apidomCore.toValue)(key)}`);
|
|
99
|
+
});
|
|
100
|
+
path.replaceWith(await (0, _resolver.dereferenceOpenAPIElement)(pathItem, dereferenceOptions));
|
|
94
101
|
},
|
|
95
102
|
OperationElement(path) {
|
|
96
103
|
const operation = path.node;
|
|
97
104
|
const operationId = (0, _apidomCore.toValue)(operation.operationId);
|
|
105
|
+
const pointer = path.formatPath('jsonpointer');
|
|
106
|
+
// where the operation is written, for the events to locate it by: an
|
|
107
|
+
// operation of a `$ref` path item is written where that path item is,
|
|
108
|
+
// unless it was written next to the `$ref` and so already located
|
|
109
|
+
if (!operation.hasMetaProperty('json-pointer')) {
|
|
110
|
+
const member = path.parentPath?.node;
|
|
111
|
+
const pathItem = path.parentPath?.parentPath?.node;
|
|
112
|
+
const definition = (0, _apidomCore.toValue)(pathItem.meta.get('ref-origin-pointer'));
|
|
113
|
+
if (typeof definition === 'string') {
|
|
114
|
+
operation.meta.set('ref-origin', (0, _apidomCore.toValue)(pathItem.meta.get('ref-origin')));
|
|
115
|
+
operation.meta.set('json-pointer', `${definition}/${(0, _apidomCore.toValue)(member.key)}`);
|
|
116
|
+
} else {
|
|
117
|
+
operation.meta.set('json-pointer', pointer);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
98
120
|
if (typeof operationId !== 'string') return path.skip();
|
|
99
121
|
if (operationId === '') return path.skip();
|
|
100
122
|
if (index.has(operationId)) return path.skip();
|
|
101
|
-
index.set(operationId,
|
|
123
|
+
index.set(operationId, pointer);
|
|
102
124
|
path.skip();
|
|
103
125
|
}
|
|
104
126
|
});
|
|
@@ -70,10 +70,11 @@ class OpenAPIDocumentRegistryProvider extends DocumentRegistryProvider {
|
|
|
70
70
|
*/
|
|
71
71
|
async provide(uri) {
|
|
72
72
|
const parseResult = await parseOpenAPI(uri, this.#buildParseOptions());
|
|
73
|
-
|
|
73
|
+
this.assertParsed(uri, parseResult);
|
|
74
|
+
const operationIndex = await this.#buildOperationIndex(uri, parseResult);
|
|
74
75
|
return new OpenAPIDocument(uri, parseResult, operationIndex);
|
|
75
76
|
}
|
|
76
|
-
async #buildOperationIndex(parseResult) {
|
|
77
|
+
async #buildOperationIndex(uri, parseResult) {
|
|
77
78
|
const index = new OpenAPIOperationIndex();
|
|
78
79
|
const dereferenceOptions = this.#buildDereferenceOptions(parseResult);
|
|
79
80
|
const apiDereferenced = await traverseAsync(parseResult.api, {
|
|
@@ -81,16 +82,37 @@ class OpenAPIDocumentRegistryProvider extends DocumentRegistryProvider {
|
|
|
81
82
|
const pathItem = path.node;
|
|
82
83
|
if (!pathItem.hasMetaProperty('path')) return path.skip();
|
|
83
84
|
if (!isStringElement(pathItem.$ref)) return;
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
|
|
86
|
+
// an operation written next to the `$ref` stays where it is written
|
|
87
|
+
const pointer = path.formatPath('jsonpointer');
|
|
88
|
+
pathItem.forEach((value, key) => {
|
|
89
|
+
if (value.element !== 'operation') return;
|
|
90
|
+
value.meta.set('json-pointer', `${pointer}/${toValue(key)}`);
|
|
91
|
+
});
|
|
92
|
+
path.replaceWith(await dereferenceOpenAPIElement(pathItem, dereferenceOptions));
|
|
86
93
|
},
|
|
87
94
|
OperationElement(path) {
|
|
88
95
|
const operation = path.node;
|
|
89
96
|
const operationId = toValue(operation.operationId);
|
|
97
|
+
const pointer = path.formatPath('jsonpointer');
|
|
98
|
+
// where the operation is written, for the events to locate it by: an
|
|
99
|
+
// operation of a `$ref` path item is written where that path item is,
|
|
100
|
+
// unless it was written next to the `$ref` and so already located
|
|
101
|
+
if (!operation.hasMetaProperty('json-pointer')) {
|
|
102
|
+
const member = path.parentPath?.node;
|
|
103
|
+
const pathItem = path.parentPath?.parentPath?.node;
|
|
104
|
+
const definition = toValue(pathItem.meta.get('ref-origin-pointer'));
|
|
105
|
+
if (typeof definition === 'string') {
|
|
106
|
+
operation.meta.set('ref-origin', toValue(pathItem.meta.get('ref-origin')));
|
|
107
|
+
operation.meta.set('json-pointer', `${definition}/${toValue(member.key)}`);
|
|
108
|
+
} else {
|
|
109
|
+
operation.meta.set('json-pointer', pointer);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
90
112
|
if (typeof operationId !== 'string') return path.skip();
|
|
91
113
|
if (operationId === '') return path.skip();
|
|
92
114
|
if (index.has(operationId)) return path.skip();
|
|
93
|
-
index.set(operationId,
|
|
115
|
+
index.set(operationId, pointer);
|
|
94
116
|
path.skip();
|
|
95
117
|
}
|
|
96
118
|
});
|
package/src/version.cjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
// generated by scripts/version-update.mjs from package.json; do not edit
|
|
8
|
+
const version = '1.0.1-alpha.34';
|
|
9
|
+
var _default = exports.default = version;
|
package/src/version.mjs
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Redactor, type ArazzoRunnerEvent, type ArazzoRunnerObserver } from '@usearazzo/runner';
|
|
2
|
+
/**
|
|
3
|
+
* The level a log record is written at. Every common logger has these four.
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
7
|
+
/**
|
|
8
|
+
* One log record, made from one event.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export interface LogRecord {
|
|
12
|
+
readonly level: LogLevel;
|
|
13
|
+
/**
|
|
14
|
+
* A one-line, human-readable summary of the event, e.g.
|
|
15
|
+
* `step placeOrder failed after 2 attempts`.
|
|
16
|
+
*/
|
|
17
|
+
readonly message: string;
|
|
18
|
+
/**
|
|
19
|
+
* The event, masked, as structured fields: its `type`, `runId`, `stepId`,
|
|
20
|
+
* `location` and the rest. The selected action of `action:selected` is
|
|
21
|
+
* given by its `name` and `type`, not as the document's element. The
|
|
22
|
+
* `error` of a settled event that threw is the native `Error`, for the
|
|
23
|
+
* logger to serialize as it is configured to: loggers serialize errors only
|
|
24
|
+
* under their own keys (pino's `err`, winston's top level), so give yours
|
|
25
|
+
* one for `error`, e.g. pino's `serializers: { error: pino.stdSerializers.err }`.
|
|
26
|
+
*/
|
|
27
|
+
readonly fields: Readonly<Record<string, unknown>>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Writes one log record to the logger of your choice. Loggers disagree on
|
|
31
|
+
* argument order, so this is where a record is handed over the way yours
|
|
32
|
+
* expects: `logger[level](fields, message)` for pino or bunyan,
|
|
33
|
+
* `logger.log(level, message, fields)` for winston,
|
|
34
|
+
* `console[level](message, fields)` for the console.
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
export type LogFunction = (record: LogRecord) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Options for {@link loggingObserver}.
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export interface LoggingObserverOptions {
|
|
43
|
+
/**
|
|
44
|
+
* Masks each event before it is logged. A `new Redactor()` with the default
|
|
45
|
+
* field patterns when omitted; there is no way to log unmasked events
|
|
46
|
+
* through this adapter. A settled event's `error` is the exception: it is
|
|
47
|
+
* logged as `execute` rejects with it.
|
|
48
|
+
*/
|
|
49
|
+
readonly redactor?: Redactor;
|
|
50
|
+
/**
|
|
51
|
+
* The level for an event type, replacing the default for every event of
|
|
52
|
+
* that type: `{ 'criterion:evaluated': 'info' }`.
|
|
53
|
+
*/
|
|
54
|
+
readonly levels?: Readonly<Partial<Record<ArazzoRunnerEvent['type'], LogLevel>>>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* An observer that writes every event as a log record through `log`, masked
|
|
58
|
+
* by a `Redactor` first.
|
|
59
|
+
*
|
|
60
|
+
* Events carry no level, so this adapter gives them one: `info` for workflows
|
|
61
|
+
* and steps starting and settling, `warn` for a failed step, `error` for a
|
|
62
|
+
* failed workflow or a step or workflow that threw, and `debug` for
|
|
63
|
+
* attempts, criteria, actions, retries,
|
|
64
|
+
* dependencies, document loads, normalization and requests. A workflow that
|
|
65
|
+
* transferred to another is `info`: the workflow it transferred to reports its
|
|
66
|
+
* own outcome. `levels` overrides it per event type.
|
|
67
|
+
*
|
|
68
|
+
* ```js
|
|
69
|
+
* import pino from 'pino';
|
|
70
|
+
* import { ArazzoRunner } from '@usearazzo/runner';
|
|
71
|
+
* import { loggingObserver } from '@usearazzo/runner/observability/logging';
|
|
72
|
+
*
|
|
73
|
+
* // the error of a step or workflow that threw, serialized as pino does `err`
|
|
74
|
+
* const logger = pino({ serializers: { error: pino.stdSerializers.err } });
|
|
75
|
+
* const runner = await ArazzoRunner.load(uri, {
|
|
76
|
+
* observer: loggingObserver(({ level, message, fields }) => logger[level](fields, message)),
|
|
77
|
+
* });
|
|
78
|
+
* ```
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
declare const loggingObserver: (log: LogFunction, options?: LoggingObserverOptions) => ArazzoRunnerObserver;
|
|
82
|
+
export default loggingObserver;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { type TracerProvider } from '@opentelemetry/api';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration of {@link ArazzoRunnerInstrumentation}, OpenTelemetry's
|
|
4
|
+
* `InstrumentationConfig`.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export interface ArazzoRunnerInstrumentationConfig {
|
|
8
|
+
/** Whether it is enabled once constructed. `true` when omitted. */
|
|
9
|
+
readonly enabled?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Traces every runner in the process with OpenTelemetry, as an OpenTelemetry
|
|
13
|
+
* instrumentation: list it with the others, and no runner needs wiring.
|
|
14
|
+
*
|
|
15
|
+
* ```js
|
|
16
|
+
* import { NodeSDK } from '@opentelemetry/sdk-node';
|
|
17
|
+
* import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
|
|
18
|
+
* import { ArazzoRunnerInstrumentation } from '@usearazzo/runner/observability/opentelemetry';
|
|
19
|
+
*
|
|
20
|
+
* new NodeSDK({
|
|
21
|
+
* instrumentations: [getNodeAutoInstrumentations(), new ArazzoRunnerInstrumentation()],
|
|
22
|
+
* }).start();
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* In the browser, with the fetch instrumentation for the request spans:
|
|
26
|
+
*
|
|
27
|
+
* ```js
|
|
28
|
+
* import { BatchSpanProcessor, WebTracerProvider } from '@opentelemetry/sdk-trace-web';
|
|
29
|
+
* import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
|
|
30
|
+
* import { ZoneContextManager } from '@opentelemetry/context-zone';
|
|
31
|
+
* import { registerInstrumentations } from '@opentelemetry/instrumentation';
|
|
32
|
+
* import { FetchInstrumentation } from '@opentelemetry/instrumentation-fetch';
|
|
33
|
+
* import { ArazzoRunnerInstrumentation } from '@usearazzo/runner/observability/opentelemetry';
|
|
34
|
+
*
|
|
35
|
+
* const provider = new WebTracerProvider({
|
|
36
|
+
* spanProcessors: [new BatchSpanProcessor(new OTLPTraceExporter())],
|
|
37
|
+
* });
|
|
38
|
+
* provider.register({ contextManager: new ZoneContextManager() });
|
|
39
|
+
* registerInstrumentations({
|
|
40
|
+
* // propagateTraceHeaderCorsUrls: the cross-origin APIs that get a traceparent
|
|
41
|
+
* instrumentations: [
|
|
42
|
+
* new FetchInstrumentation({ propagateTraceHeaderCorsUrls: [/api\.example\.com/] }),
|
|
43
|
+
* new ArazzoRunnerInstrumentation(),
|
|
44
|
+
* ],
|
|
45
|
+
* });
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* Each workflow invocation and each step is an `INTERNAL` span, the step's
|
|
49
|
+
* under its workflow's, a sub-workflow's and a retry reference's under the
|
|
50
|
+
* step that calls them, and a `dependsOn` workflow's or a transfer target's
|
|
51
|
+
* under the workflow that runs them. Attempts, criteria,
|
|
52
|
+
* selected actions, retry waits, retry references and the operations a step
|
|
53
|
+
* calls are events of the step's span, each named by the runner event it
|
|
54
|
+
* comes from (`step:attempt`, `criterion:evaluated`, `action:selected`, …). A step runs in its span's context, so
|
|
55
|
+
* the HTTP instrumentation of the client it sends with (undici for Node's
|
|
56
|
+
* `fetch`, `@opentelemetry/instrumentation-fetch` in the browser) nests its
|
|
57
|
+
* request spans under the step and propagates the trace into the API.
|
|
58
|
+
*
|
|
59
|
+
* In the browser, the workflow and step spans keep their tree with any
|
|
60
|
+
* context manager, but request spans nest under the step only where the
|
|
61
|
+
* context survives an `await`: zone.js loses it across a native one, so
|
|
62
|
+
* transpile `async`/`await` as OpenTelemetry's web instrumentation asks.
|
|
63
|
+
*
|
|
64
|
+
* Spans carry the identifiers and outcomes of the run, not its data: no
|
|
65
|
+
* inputs, outputs, criterion values or requests. A step or workflow that
|
|
66
|
+
* throws records the error, whose message can quote what the run saw.
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
69
|
+
declare class ArazzoRunnerInstrumentation {
|
|
70
|
+
#private;
|
|
71
|
+
readonly instrumentationName = "@usearazzo/runner";
|
|
72
|
+
readonly instrumentationVersion: string;
|
|
73
|
+
constructor(config?: ArazzoRunnerInstrumentationConfig);
|
|
74
|
+
/** Starts tracing every runner in the process. */
|
|
75
|
+
enable(): void;
|
|
76
|
+
/** Stops tracing; runs in progress stop at their next workflow or step. */
|
|
77
|
+
disable(): void;
|
|
78
|
+
setTracerProvider(tracerProvider: TracerProvider): void;
|
|
79
|
+
/** Records no metrics. */
|
|
80
|
+
setMeterProvider(): void;
|
|
81
|
+
setConfig(config: ArazzoRunnerInstrumentationConfig): void;
|
|
82
|
+
getConfig(): ArazzoRunnerInstrumentationConfig;
|
|
83
|
+
}
|
|
84
|
+
export default ArazzoRunnerInstrumentation;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Redactor, type ArazzoRunnerEvent, type ArazzoRunnerObserver } from '@usearazzo/runner';
|
|
2
|
+
/**
|
|
3
|
+
* Options for {@link eventStream}.
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface EventStreamOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Masks each event before it is queued. A `new Redactor()` with the default
|
|
9
|
+
* field patterns when omitted; there is no way to stream unmasked events
|
|
10
|
+
* through this adapter. A settled event's `error` is the exception: it is
|
|
11
|
+
* queued as `execute` rejects with it.
|
|
12
|
+
*/
|
|
13
|
+
readonly redactor?: Redactor;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A run's events as a stream: wire `observer` into the runner, read the
|
|
17
|
+
* events with `for await`, or pipe `stream`, and end it with `close` or
|
|
18
|
+
* `error` once the run settles.
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export interface EventStream extends AsyncIterable<ArazzoRunnerEvent> {
|
|
22
|
+
/**
|
|
23
|
+
* Queues each event, masked. It never waits for the consumer, so a slow
|
|
24
|
+
* consumer cannot hold the run back: events wait in an unbounded queue.
|
|
25
|
+
*/
|
|
26
|
+
readonly observer: ArazzoRunnerObserver;
|
|
27
|
+
/**
|
|
28
|
+
* The events as a WHATWG `ReadableStream`, for piping. It has one consumer:
|
|
29
|
+
* read it or iterate this object, not both. For two consumers, give each
|
|
30
|
+
* an `eventStream()` of its own behind `combineObservers`: a `tee()`d
|
|
31
|
+
* branch loses its unread events when the stream fails.
|
|
32
|
+
*/
|
|
33
|
+
readonly stream: ReadableStream<ArazzoRunnerEvent>;
|
|
34
|
+
/**
|
|
35
|
+
* Ends the stream once the queued events are read. Call it when `execute`
|
|
36
|
+
* resolves; events after it are dropped.
|
|
37
|
+
*/
|
|
38
|
+
close(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Fails the stream once the queued events are read: reading it then rejects
|
|
41
|
+
* with `reason`. Call it when `execute` rejects; events after it are
|
|
42
|
+
* dropped.
|
|
43
|
+
*/
|
|
44
|
+
error(reason: unknown): void;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Turns a run's events into a stream. The caller ends it: a runner can run
|
|
48
|
+
* many times into one stream, and an `execute` that fails before its
|
|
49
|
+
* workflow starts (an unknown workflow, a document that does not load)
|
|
50
|
+
* emits no workflow event to end it on:
|
|
51
|
+
*
|
|
52
|
+
* ```js
|
|
53
|
+
* import { ArazzoRunner } from '@usearazzo/runner';
|
|
54
|
+
* import { eventStream } from '@usearazzo/runner/observability/stream';
|
|
55
|
+
*
|
|
56
|
+
* const events = eventStream();
|
|
57
|
+
* const runner = await ArazzoRunner.load(uri, { observer: events.observer });
|
|
58
|
+
* runner.execute('authenticateAndOrderPet', options).then(events.close, events.error);
|
|
59
|
+
*
|
|
60
|
+
* for await (const event of events) render(event);
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* A consumer that stops reading early (a `break` out of `for await`, or a
|
|
64
|
+
* cancelled stream) stops the queuing: the run goes on unobserved.
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
67
|
+
declare const eventStream: (options?: EventStreamOptions) => EventStream;
|
|
68
|
+
export default eventStream;
|