@temelj/workflow 0.0.0-alpha.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.
- package/LICENSE +21 -0
- package/README.md +38 -0
- package/dist/attributes.d.mts +15 -0
- package/dist/attributes.mjs +30 -0
- package/dist/client/create.d.mts +31 -0
- package/dist/client/create.mjs +67 -0
- package/dist/client/facades.d.mts +21 -0
- package/dist/client/facades.mjs +142 -0
- package/dist/client/mod.d.mts +2 -0
- package/dist/client/mod.mjs +2 -0
- package/dist/client/run-handle.d.mts +66 -0
- package/dist/client/run-handle.mjs +156 -0
- package/dist/client/worker-options.d.mts +17 -0
- package/dist/client/worker-options.mjs +25 -0
- package/dist/collection.d.mts +15 -0
- package/dist/collection.mjs +33 -0
- package/dist/compiled-function.d.mts +27 -0
- package/dist/compiled-function.mjs +54 -0
- package/dist/definition.d.mts +37 -0
- package/dist/definition.mjs +83 -0
- package/dist/engine/child-workflow.d.mts +10 -0
- package/dist/engine/child-workflow.mjs +333 -0
- package/dist/engine/command-identity.d.mts +9 -0
- package/dist/engine/command-identity.mjs +14 -0
- package/dist/engine/create.d.mts +106 -0
- package/dist/engine/create.mjs +402 -0
- package/dist/engine/deterministic.d.mts +12 -0
- package/dist/engine/deterministic.mjs +102 -0
- package/dist/engine/durable-command.d.mts +10 -0
- package/dist/engine/durable-command.mjs +17 -0
- package/dist/engine/execution-api.d.mts +29 -0
- package/dist/engine/execution-api.mjs +33 -0
- package/dist/engine/execution-service.d.mts +41 -0
- package/dist/engine/execution-service.mjs +288 -0
- package/dist/engine/hooks.d.mts +56 -0
- package/dist/engine/hooks.mjs +237 -0
- package/dist/engine/inspection-api.d.mts +34 -0
- package/dist/engine/inspection-api.mjs +77 -0
- package/dist/engine/inspection.d.mts +18 -0
- package/dist/engine/inspection.mjs +149 -0
- package/dist/engine/lifecycle.d.mts +18 -0
- package/dist/engine/lifecycle.mjs +38 -0
- package/dist/engine/lock-replay.d.mts +30 -0
- package/dist/engine/lock-replay.mjs +38 -0
- package/dist/engine/lock.d.mts +21 -0
- package/dist/engine/lock.mjs +197 -0
- package/dist/engine/message.d.mts +47 -0
- package/dist/engine/message.mjs +357 -0
- package/dist/engine/mod.d.mts +4 -0
- package/dist/engine/mod.mjs +2 -0
- package/dist/engine/observation.d.mts +35 -0
- package/dist/engine/observation.mjs +201 -0
- package/dist/engine/recovery.d.mts +26 -0
- package/dist/engine/recovery.mjs +92 -0
- package/dist/engine/replay.d.mts +41 -0
- package/dist/engine/replay.mjs +122 -0
- package/dist/engine/retry-policy.d.mts +4 -0
- package/dist/engine/retry-policy.mjs +4 -0
- package/dist/engine/retry.d.mts +23 -0
- package/dist/engine/retry.mjs +75 -0
- package/dist/engine/run-data.d.mts +9 -0
- package/dist/engine/run-data.mjs +74 -0
- package/dist/engine/run-service.d.mts +38 -0
- package/dist/engine/run-service.mjs +133 -0
- package/dist/engine/run-utils.d.mts +16 -0
- package/dist/engine/run-utils.mjs +83 -0
- package/dist/engine/schedule.d.mts +25 -0
- package/dist/engine/schedule.mjs +207 -0
- package/dist/engine/serialization.d.mts +9 -0
- package/dist/engine/serialization.mjs +85 -0
- package/dist/engine/start-api.d.mts +30 -0
- package/dist/engine/start-api.mjs +98 -0
- package/dist/engine/state.d.mts +77 -0
- package/dist/engine/state.mjs +464 -0
- package/dist/engine/step-api.d.mts +9 -0
- package/dist/engine/step-api.mjs +25 -0
- package/dist/engine/stream.d.mts +55 -0
- package/dist/engine/stream.mjs +333 -0
- package/dist/engine/summary/active-events.d.mts +34 -0
- package/dist/engine/summary/active-events.mjs +69 -0
- package/dist/engine/summary/child-workflow-runs.d.mts +24 -0
- package/dist/engine/summary/child-workflow-runs.mjs +138 -0
- package/dist/engine/summary/child-workflow-waits.d.mts +21 -0
- package/dist/engine/summary/child-workflow-waits.mjs +67 -0
- package/dist/engine/summary/recovery-child-workflow-waits.d.mts +11 -0
- package/dist/engine/summary/recovery-child-workflow-waits.mjs +89 -0
- package/dist/engine/summary/recovery-due-runs.d.mts +16 -0
- package/dist/engine/summary/recovery-due-runs.mjs +52 -0
- package/dist/engine/summary/recovery-failed-runs.d.mts +14 -0
- package/dist/engine/summary/recovery-failed-runs.mjs +33 -0
- package/dist/engine/summary/recovery-lease-runs.d.mts +16 -0
- package/dist/engine/summary/recovery-lease-runs.mjs +69 -0
- package/dist/engine/summary/recovery-locks.d.mts +18 -0
- package/dist/engine/summary/recovery-locks.mjs +100 -0
- package/dist/engine/summary/recovery-message-waits.d.mts +11 -0
- package/dist/engine/summary/recovery-message-waits.mjs +74 -0
- package/dist/engine/summary/recovery-retry-runs.d.mts +17 -0
- package/dist/engine/summary/recovery-retry-runs.mjs +65 -0
- package/dist/engine/summary/recovery-run-timestamps.d.mts +13 -0
- package/dist/engine/summary/recovery-run-timestamps.mjs +18 -0
- package/dist/engine/summary/recovery-runs.d.mts +23 -0
- package/dist/engine/summary/recovery-runs.mjs +54 -0
- package/dist/engine/summary/recovery-schedules.d.mts +10 -0
- package/dist/engine/summary/recovery-schedules.mjs +46 -0
- package/dist/engine/summary/recovery-sleep-waits.d.mts +10 -0
- package/dist/engine/summary/recovery-sleep-waits.mjs +53 -0
- package/dist/engine/summary/recovery-waits.d.mts +21 -0
- package/dist/engine/summary/recovery-waits.mjs +29 -0
- package/dist/engine/summary/run-availability.d.mts +13 -0
- package/dist/engine/summary/run-availability.mjs +37 -0
- package/dist/engine/summary/run-cleanup.d.mts +14 -0
- package/dist/engine/summary/run-cleanup.mjs +44 -0
- package/dist/engine/summary/run-failure.d.mts +14 -0
- package/dist/engine/summary/run-failure.mjs +62 -0
- package/dist/engine/summary/run-hooks.d.mts +14 -0
- package/dist/engine/summary/run-hooks.mjs +63 -0
- package/dist/engine/summary/run-lease.d.mts +11 -0
- package/dist/engine/summary/run-lease.mjs +64 -0
- package/dist/engine/summary/run-message-waits.d.mts +15 -0
- package/dist/engine/summary/run-message-waits.mjs +62 -0
- package/dist/engine/summary/run-metrics.d.mts +31 -0
- package/dist/engine/summary/run-metrics.mjs +93 -0
- package/dist/engine/summary/run-retry.d.mts +9 -0
- package/dist/engine/summary/run-retry.mjs +69 -0
- package/dist/engine/summary/run-sleeps.d.mts +15 -0
- package/dist/engine/summary/run-sleeps.mjs +61 -0
- package/dist/engine/summary/run-state.d.mts +26 -0
- package/dist/engine/summary/run-state.mjs +48 -0
- package/dist/engine/summary/run-status.d.mts +16 -0
- package/dist/engine/summary/run-status.mjs +35 -0
- package/dist/engine/summary/run-streams.d.mts +14 -0
- package/dist/engine/summary/run-streams.mjs +46 -0
- package/dist/engine/summary/run-transition.d.mts +9 -0
- package/dist/engine/summary/run-transition.mjs +39 -0
- package/dist/engine/summary/run-workflow.d.mts +9 -0
- package/dist/engine/summary/run-workflow.mjs +47 -0
- package/dist/engine/summary/step-attempt-active-child-workflows.d.mts +13 -0
- package/dist/engine/summary/step-attempt-active-child-workflows.mjs +55 -0
- package/dist/engine/summary/step-attempt-active-fields.d.mts +23 -0
- package/dist/engine/summary/step-attempt-active-fields.mjs +14 -0
- package/dist/engine/summary/step-attempt-active-message-waits.d.mts +12 -0
- package/dist/engine/summary/step-attempt-active-message-waits.mjs +47 -0
- package/dist/engine/summary/step-attempt-active-sleeps.d.mts +19 -0
- package/dist/engine/summary/step-attempt-active-sleeps.mjs +44 -0
- package/dist/engine/summary/step-attempt-buckets.d.mts +22 -0
- package/dist/engine/summary/step-attempt-buckets.mjs +152 -0
- package/dist/engine/summary/step-attempt-failure.d.mts +12 -0
- package/dist/engine/summary/step-attempt-failure.mjs +61 -0
- package/dist/engine/summary/step-attempt-lifecycle.d.mts +13 -0
- package/dist/engine/summary/step-attempt-lifecycle.mjs +19 -0
- package/dist/engine/summary/step-attempts.d.mts +11 -0
- package/dist/engine/summary/step-attempts.mjs +43 -0
- package/dist/engine/summary.d.mts +32 -0
- package/dist/engine/summary.mjs +37 -0
- package/dist/engine/task.d.mts +6 -0
- package/dist/engine/task.mjs +207 -0
- package/dist/errors/base.d.mts +99 -0
- package/dist/errors/base.mjs +426 -0
- package/dist/errors/capability.d.mts +11 -0
- package/dist/errors/capability.mjs +23 -0
- package/dist/errors/definition.d.mts +21 -0
- package/dist/errors/definition.mjs +51 -0
- package/dist/errors/details.d.mts +13 -0
- package/dist/errors/details.mjs +65 -0
- package/dist/errors/failures.d.mts +81 -0
- package/dist/errors/failures.mjs +168 -0
- package/dist/errors/hook.d.mts +14 -0
- package/dist/errors/hook.mjs +30 -0
- package/dist/errors/implementation.d.mts +11 -0
- package/dist/errors/implementation.mjs +25 -0
- package/dist/errors/lock.d.mts +28 -0
- package/dist/errors/lock.mjs +70 -0
- package/dist/errors/message.d.mts +106 -0
- package/dist/errors/message.mjs +122 -0
- package/dist/errors/mod.d.mts +17 -0
- package/dist/errors/mod.mjs +17 -0
- package/dist/errors/record-view.d.mts +11 -0
- package/dist/errors/record-view.mjs +24 -0
- package/dist/errors/records.d.mts +7 -0
- package/dist/errors/records.mjs +280 -0
- package/dist/errors/run.d.mts +116 -0
- package/dist/errors/run.mjs +232 -0
- package/dist/errors/runtime.d.mts +12 -0
- package/dist/errors/runtime.mjs +24 -0
- package/dist/errors/schedule.d.mts +27 -0
- package/dist/errors/schedule.mjs +65 -0
- package/dist/errors/step.d.mts +76 -0
- package/dist/errors/step.mjs +113 -0
- package/dist/errors/stream.d.mts +24 -0
- package/dist/errors/stream.mjs +64 -0
- package/dist/esbuild.d.mts +7 -0
- package/dist/esbuild.mjs +6 -0
- package/dist/events/descriptors.d.mts +245 -0
- package/dist/events/descriptors.mjs +405 -0
- package/dist/events/mod.d.mts +3 -0
- package/dist/events/mod.mjs +2 -0
- package/dist/history/attempt-key.d.mts +6 -0
- package/dist/history/attempt-key.mjs +7 -0
- package/dist/history/mod.d.mts +71 -0
- package/dist/history/mod.mjs +195 -0
- package/dist/history/projection.d.mts +8 -0
- package/dist/history/projection.mjs +259 -0
- package/dist/history/replay-projection.d.mts +88 -0
- package/dist/history/replay-projection.mjs +369 -0
- package/dist/history/sequencer.d.mts +16 -0
- package/dist/history/sequencer.mjs +78 -0
- package/dist/history/step-attempts.d.mts +9 -0
- package/dist/history/step-attempts.mjs +50 -0
- package/dist/history/timeline.d.mts +16 -0
- package/dist/history/timeline.mjs +272 -0
- package/dist/history/validator.d.mts +9 -0
- package/dist/history/validator.mjs +110 -0
- package/dist/inspection/mod.d.mts +5 -0
- package/dist/inspection/mod.mjs +3 -0
- package/dist/message-options.d.mts +8 -0
- package/dist/message-options.mjs +25 -0
- package/dist/mod.d.mts +52 -0
- package/dist/mod.mjs +26 -0
- package/dist/otel/support.d.mts +18 -0
- package/dist/otel/support.mjs +102 -0
- package/dist/otel.d.mts +30 -0
- package/dist/otel.mjs +588 -0
- package/dist/pagination.d.mts +25 -0
- package/dist/pagination.mjs +73 -0
- package/dist/registry.d.mts +20 -0
- package/dist/registry.mjs +48 -0
- package/dist/rolldown.d.mts +7 -0
- package/dist/rolldown.mjs +6 -0
- package/dist/rollup.d.mts +7 -0
- package/dist/rollup.mjs +6 -0
- package/dist/rspack.d.mts +7 -0
- package/dist/rspack.mjs +6 -0
- package/dist/runtime.d.mts +34 -0
- package/dist/runtime.mjs +194 -0
- package/dist/step-definition.d.mts +10 -0
- package/dist/step-definition.mjs +15 -0
- package/dist/store/append-projection.d.mts +15 -0
- package/dist/store/append-projection.mjs +26 -0
- package/dist/store/capabilities.d.mts +14 -0
- package/dist/store/capabilities.mjs +42 -0
- package/dist/store/cleanup.d.mts +18 -0
- package/dist/store/cleanup.mjs +338 -0
- package/dist/store/compaction.d.mts +5 -0
- package/dist/store/compaction.mjs +8 -0
- package/dist/store/create.d.mts +52 -0
- package/dist/store/create.mjs +159 -0
- package/dist/store/event-append-project.d.mts +15 -0
- package/dist/store/event-append-project.mjs +77 -0
- package/dist/store/event-append.d.mts +37 -0
- package/dist/store/event-append.mjs +80 -0
- package/dist/store/event-history.d.mts +22 -0
- package/dist/store/event-history.mjs +75 -0
- package/dist/store/event.d.mts +10 -0
- package/dist/store/event.mjs +28 -0
- package/dist/store/idempotency.d.mts +10 -0
- package/dist/store/idempotency.mjs +167 -0
- package/dist/store/instrumentation.d.mts +7 -0
- package/dist/store/instrumentation.mjs +123 -0
- package/dist/store/lock.d.mts +8 -0
- package/dist/store/lock.mjs +28 -0
- package/dist/store/materialization.d.mts +30 -0
- package/dist/store/materialization.mjs +127 -0
- package/dist/store/message-index.d.mts +21 -0
- package/dist/store/message-index.mjs +121 -0
- package/dist/store/mod.d.mts +5 -0
- package/dist/store/mod.mjs +4 -0
- package/dist/store/query.d.mts +24 -0
- package/dist/store/query.mjs +82 -0
- package/dist/store/revision.d.mts +4 -0
- package/dist/store/revision.mjs +7 -0
- package/dist/store/run.d.mts +49 -0
- package/dist/store/run.mjs +236 -0
- package/dist/store/schedule.d.mts +12 -0
- package/dist/store/schedule.mjs +41 -0
- package/dist/store/schema.d.mts +14 -0
- package/dist/store/schema.mjs +17 -0
- package/dist/store/step-attempt.d.mts +14 -0
- package/dist/store/step-attempt.mjs +23 -0
- package/dist/store/storage-value.d.mts +5 -0
- package/dist/store/storage-value.mjs +6 -0
- package/dist/store/validation.d.mts +35 -0
- package/dist/store/validation.mjs +77 -0
- package/dist/store-keys.d.mts +49 -0
- package/dist/store-keys.mjs +63 -0
- package/dist/telemetry.d.mts +132 -0
- package/dist/telemetry.mjs +172 -0
- package/dist/temporal.d.mts +23 -0
- package/dist/temporal.mjs +59 -0
- package/dist/timer.d.mts +12 -0
- package/dist/timer.mjs +28 -0
- package/dist/types/cleanup.d.mts +112 -0
- package/dist/types/cleanup.mjs +22 -0
- package/dist/types/client.d.mts +270 -0
- package/dist/types/client.mjs +1 -0
- package/dist/types/common.d.mts +19 -0
- package/dist/types/common.mjs +15 -0
- package/dist/types/definition.d.mts +92 -0
- package/dist/types/definition.mjs +1 -0
- package/dist/types/engine-options.d.mts +76 -0
- package/dist/types/engine-options.mjs +1 -0
- package/dist/types/engine.d.mts +309 -0
- package/dist/types/engine.mjs +1 -0
- package/dist/types/error-code.d.mts +256 -0
- package/dist/types/error-code.mjs +131 -0
- package/dist/types/error.d.mts +236 -0
- package/dist/types/error.mjs +48 -0
- package/dist/types/events.d.mts +2869 -0
- package/dist/types/events.mjs +283 -0
- package/dist/types/hook.d.mts +149 -0
- package/dist/types/hook.mjs +66 -0
- package/dist/types/lock.d.mts +63 -0
- package/dist/types/lock.mjs +18 -0
- package/dist/types/message-id.d.mts +7 -0
- package/dist/types/message-id.mjs +5 -0
- package/dist/types/message.d.mts +87 -0
- package/dist/types/message.mjs +1 -0
- package/dist/types/observation.d.mts +146 -0
- package/dist/types/observation.mjs +1 -0
- package/dist/types/pagination.d.mts +32 -0
- package/dist/types/pagination.mjs +13 -0
- package/dist/types/result.d.mts +62 -0
- package/dist/types/result.mjs +1 -0
- package/dist/types/retry.d.mts +48 -0
- package/dist/types/retry.mjs +1 -0
- package/dist/types/run-id.d.mts +7 -0
- package/dist/types/run-id.mjs +5 -0
- package/dist/types/run-list.d.mts +43 -0
- package/dist/types/run-list.mjs +1 -0
- package/dist/types/run-options.d.mts +86 -0
- package/dist/types/run-options.mjs +1 -0
- package/dist/types/run.d.mts +355 -0
- package/dist/types/run.mjs +207 -0
- package/dist/types/runtime.d.mts +143 -0
- package/dist/types/runtime.mjs +21 -0
- package/dist/types/schedule.d.mts +127 -0
- package/dist/types/schedule.mjs +48 -0
- package/dist/types/step-attempts.d.mts +326 -0
- package/dist/types/step-attempts.mjs +43 -0
- package/dist/types/step-id.d.mts +7 -0
- package/dist/types/step-id.mjs +5 -0
- package/dist/types/step.d.mts +183 -0
- package/dist/types/step.mjs +5 -0
- package/dist/types/store.d.mts +254 -0
- package/dist/types/store.mjs +1 -0
- package/dist/types/stream-id.d.mts +7 -0
- package/dist/types/stream-id.mjs +5 -0
- package/dist/types/stream.d.mts +126 -0
- package/dist/types/stream.mjs +1 -0
- package/dist/types/summary.d.mts +318 -0
- package/dist/types/summary.mjs +1 -0
- package/dist/types/telemetry.d.mts +74 -0
- package/dist/types/telemetry.mjs +9 -0
- package/dist/types/timeline.d.mts +237 -0
- package/dist/types/timeline.mjs +1 -0
- package/dist/types/vite.d.mts +65 -0
- package/dist/types/vite.mjs +1 -0
- package/dist/types/worker-id.d.mts +7 -0
- package/dist/types/worker-id.mjs +5 -0
- package/dist/types/worker.d.mts +94 -0
- package/dist/types/worker.mjs +1 -0
- package/dist/utility.d.mts +49 -0
- package/dist/utility.mjs +122 -0
- package/dist/vite/ast.d.mts +23 -0
- package/dist/vite/ast.mjs +73 -0
- package/dist/vite/error.d.mts +19 -0
- package/dist/vite/error.mjs +47 -0
- package/dist/vite/generated-name.d.mts +7 -0
- package/dist/vite/generated-name.mjs +9 -0
- package/dist/vite/manifest.d.mts +7 -0
- package/dist/vite/manifest.mjs +106 -0
- package/dist/vite/plugin.d.mts +7 -0
- package/dist/vite/plugin.mjs +190 -0
- package/dist/vite/safety.d.mts +12 -0
- package/dist/vite/safety.mjs +96 -0
- package/dist/vite/source-edit.d.mts +12 -0
- package/dist/vite/source-edit.mjs +44 -0
- package/dist/vite/source-map.d.mts +11 -0
- package/dist/vite/source-map.mjs +53 -0
- package/dist/vite/source.d.mts +7 -0
- package/dist/vite/source.mjs +14 -0
- package/dist/vite/transform.d.mts +7 -0
- package/dist/vite/transform.mjs +405 -0
- package/dist/vite.d.mts +6 -0
- package/dist/vite.mjs +5 -0
- package/dist/webhook.d.mts +16 -0
- package/dist/webhook.mjs +17 -0
- package/dist/webpack.d.mts +7 -0
- package/dist/webpack.mjs +6 -0
- package/dist/worker/error.d.mts +11 -0
- package/dist/worker/error.mjs +40 -0
- package/dist/worker.d.mts +18 -0
- package/dist/worker.mjs +427 -0
- package/package.json +144 -0
package/dist/otel.mjs
ADDED
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
import { optionalDurationBetweenMilliseconds } from "./temporal.mjs";
|
|
2
|
+
import { WORKFLOW_ATTRIBUTES, WORKFLOW_INSTRUMENTATION_NAME, WORKFLOW_INSTRUMENTATION_VERSION, WORKFLOW_MESSAGING_ATTRIBUTES, WORKFLOW_METRIC_NAMES, WORKFLOW_SPAN_NAMES, WORKFLOW_SYSTEM } from "./telemetry.mjs";
|
|
3
|
+
import { getEventDescriptor } from "./events/descriptors.mjs";
|
|
4
|
+
import { WorkflowHistory } from "./history/mod.mjs";
|
|
5
|
+
import { contextFromTraceContext, errorRecordToException, spanLinkFromTraceContext, streamStatusFromEventKind, toException, withRunSpanStatus, withSpanStatus } from "./otel/support.mjs";
|
|
6
|
+
import { SpanStatusCode, context, metrics, propagation, trace } from "@opentelemetry/api";
|
|
7
|
+
//#region src/otel.ts
|
|
8
|
+
function createOpenTelemetryTelemetry(options = {}) {
|
|
9
|
+
return new OpenTelemetryWorkflowTelemetry(options);
|
|
10
|
+
}
|
|
11
|
+
var OpenTelemetryWorkflowTelemetry = class {
|
|
12
|
+
#tracer = trace.getTracer(WORKFLOW_INSTRUMENTATION_NAME, WORKFLOW_INSTRUMENTATION_VERSION);
|
|
13
|
+
#meter = metrics.getMeter(WORKFLOW_INSTRUMENTATION_NAME, WORKFLOW_INSTRUMENTATION_VERSION);
|
|
14
|
+
#options;
|
|
15
|
+
#runTransitions = this.#meter.createCounter(WORKFLOW_METRIC_NAMES.runTransitions, { description: "Count of workflow run transitions." });
|
|
16
|
+
#runDuration = this.#meter.createHistogram(WORKFLOW_METRIC_NAMES.runDuration, {
|
|
17
|
+
description: "Workflow run duration in milliseconds.",
|
|
18
|
+
unit: "ms"
|
|
19
|
+
});
|
|
20
|
+
#eventsAppended = this.#meter.createCounter(WORKFLOW_METRIC_NAMES.eventsAppended, { description: "Count of durable workflow events appended." });
|
|
21
|
+
#stepAttempts = this.#meter.createCounter(WORKFLOW_METRIC_NAMES.stepAttempts, { description: "Count of workflow step attempt updates." });
|
|
22
|
+
#stepDuration = this.#meter.createHistogram(WORKFLOW_METRIC_NAMES.stepDuration, {
|
|
23
|
+
description: "Workflow step attempt duration in milliseconds.",
|
|
24
|
+
unit: "ms"
|
|
25
|
+
});
|
|
26
|
+
#messagesSent = this.#meter.createCounter(WORKFLOW_METRIC_NAMES.messagesSent, { description: "Count of workflow messages sent." });
|
|
27
|
+
#messageWaitLatency = this.#meter.createHistogram(WORKFLOW_METRIC_NAMES.messageWaitLatency, {
|
|
28
|
+
description: "Latency from workflow message wait creation to message receipt.",
|
|
29
|
+
unit: "ms"
|
|
30
|
+
});
|
|
31
|
+
#hooksResumed = this.#meter.createCounter(WORKFLOW_METRIC_NAMES.hooksResumed, { description: "Count of workflow hooks resumed." });
|
|
32
|
+
#hookResumeLatency = this.#meter.createHistogram(WORKFLOW_METRIC_NAMES.hookResumeLatency, {
|
|
33
|
+
description: "Latency from workflow hook wait creation to hook resume message receipt.",
|
|
34
|
+
unit: "ms"
|
|
35
|
+
});
|
|
36
|
+
#streamUpdates = this.#meter.createCounter(WORKFLOW_METRIC_NAMES.streamUpdates, { description: "Count of workflow stream updates." });
|
|
37
|
+
#cleanupDeletedRuns = this.#meter.createCounter(WORKFLOW_METRIC_NAMES.cleanupDeletedRuns, { description: "Count of workflow runs deleted by cleanup or retention operations." });
|
|
38
|
+
#runGauge;
|
|
39
|
+
#workerActiveExecutionsGauge;
|
|
40
|
+
#workerClaims = this.#meter.createCounter(WORKFLOW_METRIC_NAMES.workerClaims, { description: "Count of workflow run claims by workers." });
|
|
41
|
+
#workerClaimFailures = this.#meter.createCounter(WORKFLOW_METRIC_NAMES.workerClaimFailures, { description: "Count of failed targeted workflow run claims by workers." });
|
|
42
|
+
#workerHeartbeatFailures = this.#meter.createCounter(WORKFLOW_METRIC_NAMES.workerHeartbeatFailures, { description: "Count of failed workflow worker heartbeat lease extensions." });
|
|
43
|
+
#workerLeaseExtensions = this.#meter.createCounter(WORKFLOW_METRIC_NAMES.workerLeaseExtensions, { description: "Count of workflow run lease extension attempts." });
|
|
44
|
+
#workerLeaseReleases = this.#meter.createCounter(WORKFLOW_METRIC_NAMES.workerLeaseReleases, { description: "Count of workflow run lease releases." });
|
|
45
|
+
#pendingToClaimedLatency = this.#meter.createHistogram(WORKFLOW_METRIC_NAMES.pendingToClaimedLatency, {
|
|
46
|
+
description: "Latency from workflow availability to worker claim in milliseconds.",
|
|
47
|
+
unit: "ms"
|
|
48
|
+
});
|
|
49
|
+
#waitingToResumedLatency = this.#meter.createHistogram(WORKFLOW_METRIC_NAMES.runWaitingToResumedLatency, {
|
|
50
|
+
description: "Latency from workflow waiting state to resumed execution in milliseconds.",
|
|
51
|
+
unit: "ms"
|
|
52
|
+
});
|
|
53
|
+
#retryScheduled = this.#meter.createCounter(WORKFLOW_METRIC_NAMES.retryScheduled, { description: "Count of workflow retries scheduled." });
|
|
54
|
+
#retryExhausted = this.#meter.createCounter(WORKFLOW_METRIC_NAMES.retryExhausted, { description: "Count of workflow retries exhausted into permanent failure." });
|
|
55
|
+
#retryDelay = this.#meter.createHistogram(WORKFLOW_METRIC_NAMES.retryDelay, {
|
|
56
|
+
description: "Delay until a scheduled workflow retry in milliseconds.",
|
|
57
|
+
unit: "ms"
|
|
58
|
+
});
|
|
59
|
+
#scheduleDueToRunCreatedLatency = this.#meter.createHistogram(WORKFLOW_METRIC_NAMES.scheduleDueToRunCreatedLatency, {
|
|
60
|
+
description: "Latency from recurring schedule fire time to scheduled run creation.",
|
|
61
|
+
unit: "ms"
|
|
62
|
+
});
|
|
63
|
+
#storageOperationDuration = this.#meter.createHistogram(WORKFLOW_METRIC_NAMES.storageOperationDuration, {
|
|
64
|
+
description: "Workflow storage/backend operation duration in milliseconds.",
|
|
65
|
+
unit: "ms"
|
|
66
|
+
});
|
|
67
|
+
#storageOperationErrors = this.#meter.createCounter(WORKFLOW_METRIC_NAMES.storageOperationErrors, { description: "Count of workflow storage/backend operation failures." });
|
|
68
|
+
#engine;
|
|
69
|
+
constructor(options) {
|
|
70
|
+
this.#options = options;
|
|
71
|
+
this.#runGauge = this.#meter.createObservableGauge(WORKFLOW_METRIC_NAMES.runs, { description: "Current count of workflow runs by status." });
|
|
72
|
+
this.#workerActiveExecutionsGauge = this.#meter.createObservableGauge(WORKFLOW_METRIC_NAMES.workerActiveExecutions, { description: "Current count of workflow runs actively held by workers." });
|
|
73
|
+
this.#runGauge.addCallback(async (result) => {
|
|
74
|
+
if (this.#engine?.getRunSummary === void 0) return;
|
|
75
|
+
try {
|
|
76
|
+
const summary = await this.#engine.getRunSummary();
|
|
77
|
+
for (const [status, count] of Object.entries(summary.status)) result.observe(count, this.#attributes({ [WORKFLOW_ATTRIBUTES.runStatus]: status }));
|
|
78
|
+
} catch {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
this.#workerActiveExecutionsGauge.addCallback(async (result) => {
|
|
83
|
+
if (this.#engine?.getRunSummary === void 0) return;
|
|
84
|
+
try {
|
|
85
|
+
const summary = await this.#engine.getRunSummary();
|
|
86
|
+
result.observe(summary.status.running, this.#attributes({ [WORKFLOW_ATTRIBUTES.runStatus]: "running" }));
|
|
87
|
+
} catch {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
captureContext() {
|
|
93
|
+
const carrier = {};
|
|
94
|
+
propagation.inject(context.active(), carrier);
|
|
95
|
+
return Object.keys(carrier).length === 0 ? void 0 : {
|
|
96
|
+
...carrier.traceparent === void 0 ? {} : { traceparent: carrier.traceparent },
|
|
97
|
+
...carrier.tracestate === void 0 ? {} : { tracestate: carrier.tracestate }
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
async withRunExecution(telemetryContext, callback) {
|
|
101
|
+
const parent = contextFromTraceContext(telemetryContext.traceContext);
|
|
102
|
+
return await this.#tracer.startActiveSpan(this.#runExecutionSpanName(telemetryContext), { attributes: this.#attributes({
|
|
103
|
+
[WORKFLOW_ATTRIBUTES.workflowName]: telemetryContext.run.workflowName,
|
|
104
|
+
...telemetryContext.run.workflowVersion === void 0 ? {} : { [WORKFLOW_ATTRIBUTES.workflowVersion]: telemetryContext.run.workflowVersion },
|
|
105
|
+
[WORKFLOW_ATTRIBUTES.runId]: telemetryContext.run.id,
|
|
106
|
+
[WORKFLOW_ATTRIBUTES.namespace]: telemetryContext.run.namespace,
|
|
107
|
+
...telemetryContext.run.attempts === void 0 ? {} : { [WORKFLOW_ATTRIBUTES.runAttempt]: telemetryContext.run.attempts },
|
|
108
|
+
...telemetryContext.run.workerId === void 0 ? {} : { [WORKFLOW_ATTRIBUTES.workerId]: telemetryContext.run.workerId }
|
|
109
|
+
}) }, parent, async (span) => await withRunSpanStatus(span, callback));
|
|
110
|
+
}
|
|
111
|
+
async withStepExecution(telemetryContext, callback) {
|
|
112
|
+
return await this.#tracer.startActiveSpan(this.#stepExecutionSpanName(telemetryContext), { attributes: this.#attributes({
|
|
113
|
+
[WORKFLOW_ATTRIBUTES.workflowName]: telemetryContext.run.workflowName,
|
|
114
|
+
...telemetryContext.run.workflowVersion === void 0 ? {} : { [WORKFLOW_ATTRIBUTES.workflowVersion]: telemetryContext.run.workflowVersion },
|
|
115
|
+
[WORKFLOW_ATTRIBUTES.runId]: telemetryContext.run.id,
|
|
116
|
+
[WORKFLOW_ATTRIBUTES.stepId]: telemetryContext.step.id,
|
|
117
|
+
[WORKFLOW_ATTRIBUTES.stepName]: telemetryContext.step.name,
|
|
118
|
+
[WORKFLOW_ATTRIBUTES.stepKind]: telemetryContext.step.kind,
|
|
119
|
+
[WORKFLOW_ATTRIBUTES.stepAttempt]: telemetryContext.attempt,
|
|
120
|
+
...telemetryContext.timeoutAt === void 0 ? {} : { [WORKFLOW_ATTRIBUTES.stepTimeoutAt]: telemetryContext.timeoutAt.toString() }
|
|
121
|
+
}) }, async (span) => await withSpanStatus(span, callback));
|
|
122
|
+
}
|
|
123
|
+
async withStorageOperation(telemetryContext, callback) {
|
|
124
|
+
const startedAt = Date.now();
|
|
125
|
+
const attributes = this.#attributes({
|
|
126
|
+
[WORKFLOW_ATTRIBUTES.storageOperation]: telemetryContext.operation,
|
|
127
|
+
[WORKFLOW_ATTRIBUTES.storageBackend]: telemetryContext.backend
|
|
128
|
+
});
|
|
129
|
+
if (this.#options.includeStorageOperationSpans === false) try {
|
|
130
|
+
const result = await callback();
|
|
131
|
+
this.#recordStorageOperationResult(startedAt, attributes, "success");
|
|
132
|
+
return result;
|
|
133
|
+
} catch (error) {
|
|
134
|
+
this.#recordStorageOperationResult(startedAt, attributes, "failure");
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
return await this.#tracer.startActiveSpan(WORKFLOW_SPAN_NAMES.storageOperation, { attributes }, async (span) => {
|
|
138
|
+
try {
|
|
139
|
+
const result = await callback();
|
|
140
|
+
this.#recordStorageOperationResult(startedAt, attributes, "success");
|
|
141
|
+
span.setAttribute(WORKFLOW_ATTRIBUTES.storageOperationStatus, "success");
|
|
142
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
143
|
+
return result;
|
|
144
|
+
} catch (error) {
|
|
145
|
+
this.#recordStorageOperationResult(startedAt, attributes, "failure");
|
|
146
|
+
span.setAttribute(WORKFLOW_ATTRIBUTES.storageOperationStatus, "failure");
|
|
147
|
+
span.recordException(toException(error));
|
|
148
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
149
|
+
throw error;
|
|
150
|
+
} finally {
|
|
151
|
+
span.end();
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
recordRunExecution(telemetryContext) {
|
|
156
|
+
const result = telemetryContext.result;
|
|
157
|
+
if (result?.kind === "completed" || result?.kind === "failed") {
|
|
158
|
+
const duration = optionalDurationBetweenMilliseconds(result.run.startedAt ?? result.run.createdAt, result.run.finishedAt);
|
|
159
|
+
if (duration !== void 0) this.#runDuration.record(duration, this.#attributes({
|
|
160
|
+
[WORKFLOW_ATTRIBUTES.workflowName]: result.run.workflowName,
|
|
161
|
+
...result.run.workflowVersion === void 0 ? {} : { [WORKFLOW_ATTRIBUTES.workflowVersion]: result.run.workflowVersion },
|
|
162
|
+
[WORKFLOW_ATTRIBUTES.runStatus]: result.run.status
|
|
163
|
+
}));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
observe(name, payload) {
|
|
167
|
+
switch (name) {
|
|
168
|
+
case "workflow:run-created":
|
|
169
|
+
case "workflow:run-waiting":
|
|
170
|
+
case "workflow:run-rescheduled":
|
|
171
|
+
case "workflow:run-manual-retry":
|
|
172
|
+
case "workflow:run-completed":
|
|
173
|
+
case "workflow:run-canceled": {
|
|
174
|
+
const event = payload;
|
|
175
|
+
this.#recordRunTransition(event);
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
case "workflow:run-failed": {
|
|
179
|
+
const event = payload;
|
|
180
|
+
this.#recordRunTransition(event);
|
|
181
|
+
this.#recordRetryExhausted(event);
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
case "workflow:run-permanently-failed": {
|
|
185
|
+
const event = payload;
|
|
186
|
+
this.#recordRunTransition(event);
|
|
187
|
+
this.#recordRetryExhausted(event);
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
case "workflow:run-claimed": {
|
|
191
|
+
const event = payload;
|
|
192
|
+
this.#recordRunTransition(event);
|
|
193
|
+
const attributes = this.#runMetricAttributes(event, { [WORKFLOW_ATTRIBUTES.workerOperation]: event.reason });
|
|
194
|
+
this.#workerClaims.add(1, attributes);
|
|
195
|
+
const latency = optionalDurationBetweenMilliseconds(event.previousRun?.availableAt ?? event.run.availableAt ?? event.run.createdAt, event.timestamp);
|
|
196
|
+
if (latency !== void 0) this.#pendingToClaimedLatency.record(latency, attributes);
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
case "workflow:run-started": {
|
|
200
|
+
const event = payload;
|
|
201
|
+
this.#recordRunTransition(event);
|
|
202
|
+
if (event.previousRun?.status !== "waiting") break;
|
|
203
|
+
const latency = optionalDurationBetweenMilliseconds(event.previousRun.availableAt ?? event.previousRun.lastTransitionAt, event.timestamp);
|
|
204
|
+
if (latency !== void 0) this.#waitingToResumedLatency.record(latency, this.#runMetricAttributes(event));
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
case "workflow:run-lease-released": {
|
|
208
|
+
const event = payload;
|
|
209
|
+
this.#recordRunTransition(event);
|
|
210
|
+
this.#workerLeaseReleases.add(1, this.#runMetricAttributes(event));
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
case "workflow:run-retrying": {
|
|
214
|
+
const event = payload;
|
|
215
|
+
this.#recordRunTransition(event);
|
|
216
|
+
const attributes = event.run.retryReason === void 0 ? this.#runMetricAttributes(event) : this.#runMetricAttributes(event, { [WORKFLOW_ATTRIBUTES.retryReason]: event.run.retryReason });
|
|
217
|
+
this.#retryScheduled.add(1, attributes);
|
|
218
|
+
const delay = optionalDurationBetweenMilliseconds(event.timestamp, event.run.retryAt);
|
|
219
|
+
if (delay !== void 0) this.#retryDelay.record(delay, attributes);
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
case "workflow:durable-event-appended": {
|
|
223
|
+
const event = payload;
|
|
224
|
+
const descriptor = getEventDescriptor(event.event.kind);
|
|
225
|
+
this.#eventsAppended.add(1, this.#attributes({
|
|
226
|
+
[WORKFLOW_ATTRIBUTES.eventKind]: descriptor.kind,
|
|
227
|
+
[WORKFLOW_ATTRIBUTES.eventCategory]: descriptor.category
|
|
228
|
+
}));
|
|
229
|
+
const history = new WorkflowHistory(event.events);
|
|
230
|
+
this.#recordDurableEventLatency(event, history);
|
|
231
|
+
this.#recordDurableSleepSpan(event, history);
|
|
232
|
+
this.#recordChildWorkflowOperationSpan(event, history);
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
case "workflow:step-attempt-updated": {
|
|
236
|
+
const event = payload;
|
|
237
|
+
const attributes = this.#attributes({
|
|
238
|
+
[WORKFLOW_ATTRIBUTES.stepKind]: event.attempt.kind,
|
|
239
|
+
[WORKFLOW_ATTRIBUTES.stepStatus]: event.attempt.status,
|
|
240
|
+
...this.#options.includeStepNameMetricAttribute ? { [WORKFLOW_ATTRIBUTES.stepName]: event.attempt.stepName } : {}
|
|
241
|
+
});
|
|
242
|
+
this.#stepAttempts.add(1, attributes);
|
|
243
|
+
if (event.attempt.status === "completed" || event.attempt.status === "failed") {
|
|
244
|
+
const duration = optionalDurationBetweenMilliseconds(event.attempt.startedAt, event.attempt.finishedAt);
|
|
245
|
+
if (duration !== void 0) this.#stepDuration.record(duration, attributes);
|
|
246
|
+
}
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
case "workflow:message-sent": {
|
|
250
|
+
const event = payload;
|
|
251
|
+
this.#messagesSent.add(1, this.#attributes({}));
|
|
252
|
+
this.#recordMessageSentSpan(event);
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
case "workflow:hook-resumed": {
|
|
256
|
+
const event = payload;
|
|
257
|
+
this.#hooksResumed.add(1, this.#attributes({ [WORKFLOW_ATTRIBUTES.hookKind]: "hook" }));
|
|
258
|
+
this.#recordHookResumeSpan("hook", event);
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
case "workflow:webhook-resumed": {
|
|
262
|
+
const event = payload;
|
|
263
|
+
this.#hooksResumed.add(1, this.#attributes({ [WORKFLOW_ATTRIBUTES.hookKind]: "webhook" }));
|
|
264
|
+
this.#recordHookResumeSpan("webhook", event);
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
case "workflow:stream-updated": {
|
|
268
|
+
const event = payload;
|
|
269
|
+
this.#streamUpdates.add(1, this.#attributes({
|
|
270
|
+
[WORKFLOW_ATTRIBUTES.streamEventKind]: event.eventKind,
|
|
271
|
+
[WORKFLOW_ATTRIBUTES.streamStatus]: streamStatusFromEventKind(event.eventKind)
|
|
272
|
+
}));
|
|
273
|
+
this.#recordStreamOperationSpan(event);
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
case "workflow:child-workflow-started": {
|
|
277
|
+
const event = payload;
|
|
278
|
+
this.#recordChildWorkflowStartedSpan(event);
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
case "workflow:cleanup-completed": {
|
|
282
|
+
const event = payload;
|
|
283
|
+
this.#cleanupDeletedRuns.add(event.result.deletedRuns, this.#attributes({ [WORKFLOW_ATTRIBUTES.cleanupSource]: "cleanup" }));
|
|
284
|
+
this.#recordCleanupOperationSpan("cleanup", event);
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
case "workflow:retention-applied": {
|
|
288
|
+
const event = payload;
|
|
289
|
+
this.#cleanupDeletedRuns.add(event.result.deletedRuns, this.#attributes({ [WORKFLOW_ATTRIBUTES.cleanupSource]: "retention" }));
|
|
290
|
+
this.#recordCleanupOperationSpan("retention", event);
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
case "workflow:worker-operation": {
|
|
294
|
+
const event = payload;
|
|
295
|
+
const attributes = this.#attributes({
|
|
296
|
+
[WORKFLOW_ATTRIBUTES.workerOperation]: event.operation,
|
|
297
|
+
[WORKFLOW_ATTRIBUTES.workerOperationStatus]: event.status
|
|
298
|
+
});
|
|
299
|
+
if (event.operation === "claim" && event.status === "failure") this.#workerClaimFailures.add(1, attributes);
|
|
300
|
+
if (event.operation === "heartbeat" && event.status === "failure") this.#workerHeartbeatFailures.add(1, attributes);
|
|
301
|
+
if (event.operation === "lease_extension") this.#workerLeaseExtensions.add(1, attributes);
|
|
302
|
+
if (event.operation === "lease_release") this.#workerLeaseReleases.add(1, attributes);
|
|
303
|
+
this.#recordWorkerOperationSpan(event);
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
306
|
+
case "workflow:schedule-ticked": {
|
|
307
|
+
const event = payload;
|
|
308
|
+
this.#recordScheduleTickSpan(event);
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
case "workflow:schedule-run-created": {
|
|
312
|
+
const event = payload;
|
|
313
|
+
const attributes = this.#attributes({
|
|
314
|
+
[WORKFLOW_ATTRIBUTES.workflowName]: event.workflowName,
|
|
315
|
+
...event.workflowVersion === void 0 ? {} : { [WORKFLOW_ATTRIBUTES.workflowVersion]: event.workflowVersion }
|
|
316
|
+
});
|
|
317
|
+
const latency = optionalDurationBetweenMilliseconds(event.fireAt, event.timestamp);
|
|
318
|
+
if (latency !== void 0) this.#scheduleDueToRunCreatedLatency.record(latency, attributes);
|
|
319
|
+
this.#recordScheduleRunCreatedSpan(event);
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
bindEngine(engine) {
|
|
325
|
+
this.#engine = engine;
|
|
326
|
+
}
|
|
327
|
+
async shutdown() {
|
|
328
|
+
const errors = [];
|
|
329
|
+
try {
|
|
330
|
+
await this.#options.forceFlush?.();
|
|
331
|
+
} catch (error) {
|
|
332
|
+
errors.push(error);
|
|
333
|
+
}
|
|
334
|
+
try {
|
|
335
|
+
await this.#options.shutdown?.();
|
|
336
|
+
} catch (error) {
|
|
337
|
+
errors.push(error);
|
|
338
|
+
}
|
|
339
|
+
if (errors.length > 0) throw errors[0];
|
|
340
|
+
}
|
|
341
|
+
#recordRunTransition(event) {
|
|
342
|
+
this.#runTransitions.add(1, this.#runMetricAttributes(event));
|
|
343
|
+
}
|
|
344
|
+
#recordRetryExhausted(event) {
|
|
345
|
+
const retryReason = event.previousRun?.retryReason ?? ((event.previousRun?.attempts ?? event.run.attempts ?? 1) > 1 ? "workflow" : void 0);
|
|
346
|
+
if (retryReason === void 0) return;
|
|
347
|
+
this.#retryExhausted.add(1, this.#runMetricAttributes(event, {
|
|
348
|
+
[WORKFLOW_ATTRIBUTES.retryReason]: retryReason,
|
|
349
|
+
[WORKFLOW_ATTRIBUTES.retryExhausted]: true
|
|
350
|
+
}));
|
|
351
|
+
}
|
|
352
|
+
#attributes(attributes) {
|
|
353
|
+
return {
|
|
354
|
+
...this.#options.serviceNamespace === void 0 ? {} : { "service.namespace": this.#options.serviceNamespace },
|
|
355
|
+
[WORKFLOW_ATTRIBUTES.system]: WORKFLOW_SYSTEM,
|
|
356
|
+
...attributes
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
#runExecutionSpanName(telemetryContext) {
|
|
360
|
+
return this.#options.includeNamesInSpanNames === true ? `${WORKFLOW_SPAN_NAMES.runExecution} ${telemetryContext.run.workflowName}` : WORKFLOW_SPAN_NAMES.runExecution;
|
|
361
|
+
}
|
|
362
|
+
#stepExecutionSpanName(telemetryContext) {
|
|
363
|
+
return this.#options.includeNamesInSpanNames === true ? `${WORKFLOW_SPAN_NAMES.stepExecution} ${telemetryContext.step.name}` : WORKFLOW_SPAN_NAMES.stepExecution;
|
|
364
|
+
}
|
|
365
|
+
#recordStorageOperationResult(startedAt, attributes, status) {
|
|
366
|
+
const resultAttributes = {
|
|
367
|
+
...attributes,
|
|
368
|
+
[WORKFLOW_ATTRIBUTES.storageOperationStatus]: status
|
|
369
|
+
};
|
|
370
|
+
this.#storageOperationDuration.record(Date.now() - startedAt, resultAttributes);
|
|
371
|
+
if (status === "failure") this.#storageOperationErrors.add(1, resultAttributes);
|
|
372
|
+
}
|
|
373
|
+
#runMetricAttributes(event, attributes = {}) {
|
|
374
|
+
return this.#attributes({
|
|
375
|
+
[WORKFLOW_ATTRIBUTES.workflowName]: event.workflowName,
|
|
376
|
+
...event.workflowVersion === void 0 ? {} : { [WORKFLOW_ATTRIBUTES.workflowVersion]: event.workflowVersion },
|
|
377
|
+
[WORKFLOW_ATTRIBUTES.runStatus]: event.status,
|
|
378
|
+
[WORKFLOW_ATTRIBUTES.runTransition]: event.reason,
|
|
379
|
+
...attributes
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
#recordDurableEventLatency(event, history) {
|
|
383
|
+
if (event.event.kind !== "message_wait_completed") return;
|
|
384
|
+
const completed = event.event;
|
|
385
|
+
const started = history.startedMessageWaitForCompleted(completed);
|
|
386
|
+
if (started === void 0) return;
|
|
387
|
+
const latency = optionalDurationBetweenMilliseconds(started.timestamp, completed.messageTimestamp);
|
|
388
|
+
if (latency === void 0) return;
|
|
389
|
+
const source = started.source ?? "message";
|
|
390
|
+
const attributes = this.#attributes({ [WORKFLOW_ATTRIBUTES.messageSource]: source });
|
|
391
|
+
this.#messageWaitLatency.record(latency, attributes);
|
|
392
|
+
if (source === "hook" || source === "webhook") this.#hookResumeLatency.record(latency, this.#attributes({ [WORKFLOW_ATTRIBUTES.hookKind]: source }));
|
|
393
|
+
this.#recordMessageWaitSpan(completed, started, history);
|
|
394
|
+
}
|
|
395
|
+
#recordDurableSleepSpan(event, history) {
|
|
396
|
+
if (event.event.kind !== "sleep_completed") return;
|
|
397
|
+
const completed = event.event;
|
|
398
|
+
const started = history.startedSleepForCompleted(completed);
|
|
399
|
+
if (started === void 0) return;
|
|
400
|
+
const requestedDuration = started.duration === void 0 ? void 0 : started.duration.total({ unit: "millisecond" });
|
|
401
|
+
const actualDuration = optionalDurationBetweenMilliseconds(started.timestamp, completed.timestamp);
|
|
402
|
+
const span = this.#tracer.startSpan(WORKFLOW_SPAN_NAMES.sleep, { attributes: this.#attributes({
|
|
403
|
+
[WORKFLOW_ATTRIBUTES.runId]: event.runId,
|
|
404
|
+
[WORKFLOW_ATTRIBUTES.stepId]: completed.stepId,
|
|
405
|
+
[WORKFLOW_ATTRIBUTES.stepName]: completed.stepName,
|
|
406
|
+
[WORKFLOW_ATTRIBUTES.stepKind]: "sleep",
|
|
407
|
+
[WORKFLOW_ATTRIBUTES.sleepUntil]: started.until.toString(),
|
|
408
|
+
...requestedDuration === void 0 ? {} : { [WORKFLOW_ATTRIBUTES.sleepDurationMs]: requestedDuration },
|
|
409
|
+
...actualDuration === void 0 ? {} : { [WORKFLOW_ATTRIBUTES.sleepActualMs]: actualDuration }
|
|
410
|
+
}) });
|
|
411
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
412
|
+
span.end();
|
|
413
|
+
}
|
|
414
|
+
#recordChildWorkflowOperationSpan(event, history) {
|
|
415
|
+
if (event.event.kind !== "child_workflow_completed" && event.event.kind !== "child_workflow_failed") return;
|
|
416
|
+
const terminal = event.event;
|
|
417
|
+
const started = history.startedChildWorkflowForTerminal(terminal);
|
|
418
|
+
const duration = started === void 0 ? void 0 : optionalDurationBetweenMilliseconds(started.timestamp, terminal.timestamp);
|
|
419
|
+
const failed = terminal.kind === "child_workflow_failed";
|
|
420
|
+
const span = this.#tracer.startSpan(WORKFLOW_SPAN_NAMES.childWorkflowOperation, { attributes: this.#attributes({
|
|
421
|
+
[WORKFLOW_ATTRIBUTES.runId]: event.runId,
|
|
422
|
+
[WORKFLOW_ATTRIBUTES.stepId]: terminal.stepId,
|
|
423
|
+
[WORKFLOW_ATTRIBUTES.stepName]: terminal.stepName,
|
|
424
|
+
[WORKFLOW_ATTRIBUTES.stepKind]: "workflow",
|
|
425
|
+
[WORKFLOW_ATTRIBUTES.stepAttempt]: terminal.attempt,
|
|
426
|
+
[WORKFLOW_ATTRIBUTES.childWorkflowOperation]: failed ? "fail" : "complete",
|
|
427
|
+
[WORKFLOW_ATTRIBUTES.childWorkflowRunId]: terminal.childRunId,
|
|
428
|
+
...started === void 0 ? {} : {
|
|
429
|
+
[WORKFLOW_ATTRIBUTES.childWorkflowName]: started.workflowName,
|
|
430
|
+
...started.workflowVersion === void 0 ? {} : { [WORKFLOW_ATTRIBUTES.childWorkflowVersion]: started.workflowVersion }
|
|
431
|
+
},
|
|
432
|
+
[WORKFLOW_ATTRIBUTES.childWorkflowStatus]: failed ? "failed" : "completed",
|
|
433
|
+
...duration === void 0 ? {} : { [WORKFLOW_ATTRIBUTES.childWorkflowDurationMs]: duration },
|
|
434
|
+
...failed ? { [WORKFLOW_ATTRIBUTES.errorKind]: terminal.error.name } : {}
|
|
435
|
+
}) });
|
|
436
|
+
if (failed) {
|
|
437
|
+
span.recordException(errorRecordToException(terminal.error));
|
|
438
|
+
span.setStatus({
|
|
439
|
+
code: SpanStatusCode.ERROR,
|
|
440
|
+
message: terminal.error.message
|
|
441
|
+
});
|
|
442
|
+
} else span.setStatus({ code: SpanStatusCode.OK });
|
|
443
|
+
span.end();
|
|
444
|
+
}
|
|
445
|
+
#recordChildWorkflowStartedSpan(event) {
|
|
446
|
+
const started = event.event;
|
|
447
|
+
const span = this.#tracer.startSpan(WORKFLOW_SPAN_NAMES.childWorkflowOperation, { attributes: this.#attributes({
|
|
448
|
+
[WORKFLOW_ATTRIBUTES.runId]: event.runId,
|
|
449
|
+
[WORKFLOW_ATTRIBUTES.stepId]: started.stepId,
|
|
450
|
+
[WORKFLOW_ATTRIBUTES.stepName]: started.stepName,
|
|
451
|
+
[WORKFLOW_ATTRIBUTES.stepKind]: "workflow",
|
|
452
|
+
[WORKFLOW_ATTRIBUTES.stepAttempt]: started.attempt,
|
|
453
|
+
[WORKFLOW_ATTRIBUTES.childWorkflowOperation]: "start",
|
|
454
|
+
[WORKFLOW_ATTRIBUTES.childWorkflowRunId]: started.childRunId,
|
|
455
|
+
[WORKFLOW_ATTRIBUTES.childWorkflowName]: started.workflowName,
|
|
456
|
+
...started.workflowVersion === void 0 ? {} : { [WORKFLOW_ATTRIBUTES.childWorkflowVersion]: started.workflowVersion },
|
|
457
|
+
[WORKFLOW_ATTRIBUTES.childWorkflowStatus]: "started"
|
|
458
|
+
}) });
|
|
459
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
460
|
+
span.end();
|
|
461
|
+
}
|
|
462
|
+
#recordMessageSentSpan(event) {
|
|
463
|
+
const parent = contextFromTraceContext(event.traceContext);
|
|
464
|
+
const span = this.#tracer.startSpan(WORKFLOW_SPAN_NAMES.messageSend, { attributes: this.#attributes({
|
|
465
|
+
[WORKFLOW_ATTRIBUTES.runId]: event.runId,
|
|
466
|
+
[WORKFLOW_ATTRIBUTES.messageId]: event.messageId,
|
|
467
|
+
[WORKFLOW_MESSAGING_ATTRIBUTES.system]: "temelj.workflow",
|
|
468
|
+
[WORKFLOW_MESSAGING_ATTRIBUTES.destinationName]: event.runId,
|
|
469
|
+
[WORKFLOW_MESSAGING_ATTRIBUTES.messageId]: event.messageId,
|
|
470
|
+
[WORKFLOW_MESSAGING_ATTRIBUTES.operationName]: "send",
|
|
471
|
+
[WORKFLOW_MESSAGING_ATTRIBUTES.operationType]: "publish"
|
|
472
|
+
}) }, parent);
|
|
473
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
474
|
+
span.end();
|
|
475
|
+
}
|
|
476
|
+
#recordHookResumeSpan(kind, event) {
|
|
477
|
+
const parent = contextFromTraceContext(event.traceContext);
|
|
478
|
+
const span = this.#tracer.startSpan(WORKFLOW_SPAN_NAMES.hookResume, { attributes: this.#attributes({
|
|
479
|
+
[WORKFLOW_ATTRIBUTES.hookKind]: kind,
|
|
480
|
+
[WORKFLOW_ATTRIBUTES.runId]: event.runId,
|
|
481
|
+
[WORKFLOW_ATTRIBUTES.messageId]: event.messageId,
|
|
482
|
+
[WORKFLOW_MESSAGING_ATTRIBUTES.system]: "temelj.workflow",
|
|
483
|
+
[WORKFLOW_MESSAGING_ATTRIBUTES.destinationName]: event.runId,
|
|
484
|
+
[WORKFLOW_MESSAGING_ATTRIBUTES.messageId]: event.messageId,
|
|
485
|
+
[WORKFLOW_MESSAGING_ATTRIBUTES.operationName]: "resume",
|
|
486
|
+
[WORKFLOW_MESSAGING_ATTRIBUTES.operationType]: "publish"
|
|
487
|
+
}) }, parent);
|
|
488
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
489
|
+
span.end();
|
|
490
|
+
}
|
|
491
|
+
#recordScheduleRunCreatedSpan(event) {
|
|
492
|
+
const span = this.#tracer.startSpan(WORKFLOW_SPAN_NAMES.scheduleRunCreate, { attributes: this.#attributes({
|
|
493
|
+
[WORKFLOW_ATTRIBUTES.workflowName]: event.workflowName,
|
|
494
|
+
...event.workflowVersion === void 0 ? {} : { [WORKFLOW_ATTRIBUTES.workflowVersion]: event.workflowVersion },
|
|
495
|
+
[WORKFLOW_ATTRIBUTES.scheduleId]: event.scheduleId,
|
|
496
|
+
[WORKFLOW_ATTRIBUTES.scheduleFireAt]: event.fireAt.toString(),
|
|
497
|
+
[WORKFLOW_ATTRIBUTES.runId]: event.runId
|
|
498
|
+
}) });
|
|
499
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
500
|
+
span.end();
|
|
501
|
+
}
|
|
502
|
+
#recordScheduleTickSpan(event) {
|
|
503
|
+
const span = this.#tracer.startSpan(WORKFLOW_SPAN_NAMES.scheduleTick, { attributes: this.#attributes({
|
|
504
|
+
[WORKFLOW_ATTRIBUTES.scheduleTickedRuns]: event.result.ticked,
|
|
505
|
+
[WORKFLOW_ATTRIBUTES.scheduleTickedSchedules]: event.result.scheduleIds.length,
|
|
506
|
+
...event.result.nextScheduleAt === void 0 ? {} : { [WORKFLOW_ATTRIBUTES.scheduleNextAt]: event.result.nextScheduleAt.toString() }
|
|
507
|
+
}) });
|
|
508
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
509
|
+
span.end();
|
|
510
|
+
}
|
|
511
|
+
#recordWorkerOperationSpan(event) {
|
|
512
|
+
const span = this.#tracer.startSpan(WORKFLOW_SPAN_NAMES.workerOperation, { attributes: this.#attributes({
|
|
513
|
+
[WORKFLOW_ATTRIBUTES.workerId]: event.workerId,
|
|
514
|
+
...event.runId === void 0 ? {} : { [WORKFLOW_ATTRIBUTES.runId]: event.runId },
|
|
515
|
+
...event.run === void 0 ? {} : {
|
|
516
|
+
[WORKFLOW_ATTRIBUTES.workflowName]: event.run.workflowName,
|
|
517
|
+
...event.run.workflowVersion === void 0 ? {} : { [WORKFLOW_ATTRIBUTES.workflowVersion]: event.run.workflowVersion },
|
|
518
|
+
[WORKFLOW_ATTRIBUTES.runStatus]: event.run.status
|
|
519
|
+
},
|
|
520
|
+
[WORKFLOW_ATTRIBUTES.workerOperation]: event.operation,
|
|
521
|
+
[WORKFLOW_ATTRIBUTES.workerOperationStatus]: event.status
|
|
522
|
+
}) });
|
|
523
|
+
if (event.status === "failure") {
|
|
524
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
525
|
+
if (event.error !== void 0) span.recordException(toException(event.error));
|
|
526
|
+
} else span.setStatus({ code: SpanStatusCode.OK });
|
|
527
|
+
span.end();
|
|
528
|
+
}
|
|
529
|
+
#recordCleanupOperationSpan(source, event) {
|
|
530
|
+
const span = this.#tracer.startSpan(WORKFLOW_SPAN_NAMES.cleanupOperation, { attributes: this.#attributes({
|
|
531
|
+
[WORKFLOW_ATTRIBUTES.cleanupSource]: source,
|
|
532
|
+
[WORKFLOW_ATTRIBUTES.cleanupDeletedRuns]: event.result.deletedRuns,
|
|
533
|
+
[WORKFLOW_ATTRIBUTES.cleanupCreatedMarkers]: event.result.createdCleanupMarkers,
|
|
534
|
+
[WORKFLOW_ATTRIBUTES.cleanupDeletedMarkers]: event.result.deletedCleanupMarkers,
|
|
535
|
+
[WORKFLOW_ATTRIBUTES.cleanupDeletedEvents]: event.result.deletedEvents,
|
|
536
|
+
[WORKFLOW_ATTRIBUTES.cleanupDeletedStepAttempts]: event.result.deletedStepAttempts,
|
|
537
|
+
[WORKFLOW_ATTRIBUTES.cleanupDeletedIdempotencyKeys]: event.result.deletedIdempotencyKeys,
|
|
538
|
+
[WORKFLOW_ATTRIBUTES.cleanupDeletedMessageIdempotencyKeys]: event.result.deletedMessageIdempotencyKeys,
|
|
539
|
+
...event.result.dryRun === void 0 ? {} : { [WORKFLOW_ATTRIBUTES.cleanupDryRun]: event.result.dryRun },
|
|
540
|
+
[WORKFLOW_ATTRIBUTES.cleanupMatchedRuns]: event.result.matchedRuns ?? event.result.runIds.length
|
|
541
|
+
}) });
|
|
542
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
543
|
+
span.end();
|
|
544
|
+
}
|
|
545
|
+
#recordStreamOperationSpan(event) {
|
|
546
|
+
const span = this.#tracer.startSpan(WORKFLOW_SPAN_NAMES.streamOperation, { attributes: this.#attributes({
|
|
547
|
+
[WORKFLOW_ATTRIBUTES.runId]: event.runId,
|
|
548
|
+
[WORKFLOW_ATTRIBUTES.streamId]: event.streamId,
|
|
549
|
+
[WORKFLOW_ATTRIBUTES.streamEventKind]: event.eventKind,
|
|
550
|
+
[WORKFLOW_ATTRIBUTES.streamStatus]: streamStatusFromEventKind(event.eventKind),
|
|
551
|
+
[WORKFLOW_ATTRIBUTES.stepId]: event.stepId,
|
|
552
|
+
[WORKFLOW_ATTRIBUTES.stepName]: event.stepName,
|
|
553
|
+
...event.index === void 0 ? {} : { [WORKFLOW_ATTRIBUTES.streamIndex]: event.index },
|
|
554
|
+
...event.error === void 0 ? {} : { [WORKFLOW_ATTRIBUTES.errorKind]: event.error.name }
|
|
555
|
+
}) });
|
|
556
|
+
if (event.error === void 0) span.setStatus({ code: SpanStatusCode.OK });
|
|
557
|
+
else {
|
|
558
|
+
span.recordException(errorRecordToException(event.error));
|
|
559
|
+
span.setStatus({
|
|
560
|
+
code: SpanStatusCode.ERROR,
|
|
561
|
+
message: event.error.message
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
span.end();
|
|
565
|
+
}
|
|
566
|
+
#recordMessageWaitSpan(completed, started, history) {
|
|
567
|
+
const message = history.messageSentByTimestamp(completed.messageId, completed.messageTimestamp);
|
|
568
|
+
const link = spanLinkFromTraceContext(completed.telemetryContext ?? message?.telemetryContext);
|
|
569
|
+
return this.#tracer.startActiveSpan(WORKFLOW_SPAN_NAMES.messageWait, {
|
|
570
|
+
attributes: this.#attributes({
|
|
571
|
+
[WORKFLOW_ATTRIBUTES.messageId]: completed.messageId,
|
|
572
|
+
[WORKFLOW_ATTRIBUTES.messageSource]: started.source ?? "message",
|
|
573
|
+
[WORKFLOW_ATTRIBUTES.stepId]: completed.stepId,
|
|
574
|
+
[WORKFLOW_ATTRIBUTES.stepName]: completed.stepName,
|
|
575
|
+
[WORKFLOW_MESSAGING_ATTRIBUTES.system]: "temelj.workflow",
|
|
576
|
+
[WORKFLOW_MESSAGING_ATTRIBUTES.messageId]: completed.messageId,
|
|
577
|
+
[WORKFLOW_MESSAGING_ATTRIBUTES.operationName]: "receive",
|
|
578
|
+
[WORKFLOW_MESSAGING_ATTRIBUTES.operationType]: "receive"
|
|
579
|
+
}),
|
|
580
|
+
...link === void 0 ? {} : { links: [link] }
|
|
581
|
+
}, (span) => {
|
|
582
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
583
|
+
span.end();
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
//#endregion
|
|
588
|
+
export { createOpenTelemetryTelemetry };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { StepId } from "./types/step-id.mjs";
|
|
2
|
+
import { CursorKeyPart, PageOptions, WorkflowPage } from "./types/pagination.mjs";
|
|
3
|
+
import "./types/step.mjs";
|
|
4
|
+
//#region src/pagination.d.ts
|
|
5
|
+
declare function pageItems<TItem>(items: readonly TItem[], options: PageOptions | undefined, label: string, cursorKey: (item: TItem, index: number) => readonly CursorKeyPart[]): WorkflowPage<TItem>;
|
|
6
|
+
declare function makeWorkflowRunCursorKey(run: {
|
|
7
|
+
readonly createdAt: Temporal.Instant;
|
|
8
|
+
readonly id: string;
|
|
9
|
+
}): readonly [number, string];
|
|
10
|
+
declare function makeWorkflowEventCursorKey(_event: unknown, index: number): readonly [number];
|
|
11
|
+
declare function makeWorkflowStepAttemptCursorKey(attempt: {
|
|
12
|
+
readonly startedAt: Temporal.Instant;
|
|
13
|
+
readonly stepId: StepId;
|
|
14
|
+
readonly attempt: number;
|
|
15
|
+
}): readonly [number, StepId, number];
|
|
16
|
+
declare function makeScheduleCursorKey(schedule: {
|
|
17
|
+
readonly nextFireAt: Temporal.Instant;
|
|
18
|
+
readonly createdAt: Temporal.Instant;
|
|
19
|
+
readonly id: string;
|
|
20
|
+
}): readonly [number, number, string];
|
|
21
|
+
declare function makeStreamChunkCursorKey(chunk: {
|
|
22
|
+
readonly index: number;
|
|
23
|
+
}): readonly [number];
|
|
24
|
+
//#endregion
|
|
25
|
+
export { makeScheduleCursorKey, makeStreamChunkCursorKey, makeWorkflowEventCursorKey, makeWorkflowRunCursorKey, makeWorkflowStepAttemptCursorKey, pageItems };
|