@temelj/workflow 0.0.0-alpha.3 → 0.0.0-alpha.4
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/README.md +394 -2
- package/dist/attributes.d.mts +11 -9
- package/dist/attributes.mjs +23 -5
- package/dist/bundle.d.mts +5 -23
- package/dist/bundle.mjs +2 -18
- package/dist/client/create.d.mts +26 -23
- package/dist/client/create.mjs +26 -32
- package/dist/client/facades.d.mts +12 -18
- package/dist/client/facades.mjs +102 -93
- package/dist/client/mod.mjs +1 -2
- package/dist/client/run-handle.d.mts +17 -54
- package/dist/client/run-handle.mjs +35 -105
- package/dist/client/worker-options.d.mts +8 -8
- package/dist/client/worker-options.mjs +11 -11
- package/dist/cloudflare/cloudflare.d.mts +4 -5
- package/dist/cloudflare/codec.d.mts +28 -13
- package/dist/cloudflare/codec.mjs +40 -17
- package/dist/cloudflare/entrypoint.d.mts +3 -4
- package/dist/cloudflare/entrypoint.mjs +4 -3
- package/dist/cloudflare/execution.d.mts +3 -4
- package/dist/cloudflare/execution.mjs +20 -13
- package/dist/cloudflare/host.d.mts +6 -7
- package/dist/cloudflare/host.mjs +7 -6
- package/dist/cloudflare/mod.d.mts +4 -4
- package/dist/cloudflare/mod.mjs +2 -2
- package/dist/cloudflare/name.d.mts +3 -4
- package/dist/cloudflare/name.mjs +3 -3
- package/dist/cloudflare/registry.d.mts +3 -23
- package/dist/cloudflare/registry.mjs +2 -20
- package/dist/cloudflare/runtime.d.mts +11 -18
- package/dist/cloudflare/runtime.mjs +52 -73
- package/dist/cloudflare/step.d.mts +6 -6
- package/dist/cloudflare/step.mjs +69 -57
- package/dist/cloudflare/types.d.mts +17 -36
- package/dist/collection.d.mts +8 -11
- package/dist/collection.mjs +10 -14
- package/dist/compiled-function.d.mts +14 -19
- package/dist/compiled-function.mjs +12 -24
- package/dist/compiled.d.mts +4 -0
- package/dist/compiled.mjs +4 -0
- package/dist/compiler/ast.d.mts +26 -0
- package/dist/{vite → compiler}/ast.mjs +24 -16
- package/dist/{vite → compiler}/error.d.mts +4 -6
- package/dist/{vite → compiler}/error.mjs +14 -16
- package/dist/compiler/manifest.d.mts +6 -0
- package/dist/{vite → compiler}/manifest.mjs +9 -7
- package/dist/compiler/plugin.d.mts +7 -0
- package/dist/{vite → compiler}/plugin.mjs +45 -46
- package/dist/compiler/safety.d.mts +12 -0
- package/dist/{vite → compiler}/safety.mjs +5 -11
- package/dist/{vite → compiler}/source-edit.d.mts +3 -4
- package/dist/{vite → compiler}/source-edit.mjs +1 -1
- package/dist/{vite → compiler}/source-map.d.mts +4 -3
- package/dist/{vite → compiler}/source-map.mjs +3 -3
- package/dist/compiler/source.d.mts +7 -0
- package/dist/{vite → compiler}/source.mjs +1 -1
- package/dist/compiler/transform.d.mts +12 -0
- package/dist/{vite → compiler}/transform.mjs +37 -38
- package/dist/definition.d.mts +17 -25
- package/dist/definition.mjs +19 -35
- package/dist/engine/child-workflow.d.mts +5 -9
- package/dist/engine/child-workflow.mjs +46 -67
- package/dist/engine/command-identity.d.mts +5 -6
- package/dist/engine/command-identity.mjs +9 -5
- package/dist/engine/context.d.mts +17 -0
- package/dist/engine/create.d.mts +36 -94
- package/dist/engine/create.mjs +55 -260
- package/dist/engine/deterministic.d.mts +6 -11
- package/dist/engine/deterministic.mjs +47 -68
- package/dist/engine/durable-command.d.mts +5 -5
- package/dist/engine/durable-command.mjs +2 -2
- package/dist/engine/execution-service.d.mts +20 -24
- package/dist/engine/execution-service.mjs +54 -52
- package/dist/engine/hooks.d.mts +17 -39
- package/dist/engine/hooks.mjs +73 -94
- package/dist/engine/inspection.d.mts +23 -15
- package/dist/engine/inspection.mjs +55 -29
- package/dist/engine/lifecycle.d.mts +6 -12
- package/dist/engine/lifecycle.mjs +5 -5
- package/dist/engine/lock-replay.d.mts +8 -15
- package/dist/engine/lock-replay.mjs +12 -25
- package/dist/engine/lock.d.mts +10 -15
- package/dist/engine/lock.mjs +65 -51
- package/dist/engine/message.d.mts +14 -34
- package/dist/engine/message.mjs +94 -127
- package/dist/engine/observation.d.mts +9 -11
- package/dist/engine/observation.mjs +18 -27
- package/dist/engine/replay.d.mts +18 -19
- package/dist/engine/replay.mjs +32 -56
- package/dist/engine/resume.d.mts +16 -0
- package/dist/engine/resume.mjs +24 -0
- package/dist/engine/retry.d.mts +15 -19
- package/dist/engine/retry.mjs +17 -17
- package/dist/engine/run-data.d.mts +4 -8
- package/dist/engine/run-data.mjs +24 -22
- package/dist/engine/run-service.d.mts +24 -33
- package/dist/engine/run-service.mjs +125 -93
- package/dist/engine/run-utils.d.mts +11 -13
- package/dist/engine/run-utils.mjs +23 -46
- package/dist/engine/schedule.d.mts +8 -22
- package/dist/engine/schedule.mjs +37 -34
- package/dist/engine/serialization.d.mts +9 -6
- package/dist/engine/serialization.mjs +30 -21
- package/dist/engine/signals.d.mts +23 -0
- package/dist/engine/signals.mjs +41 -0
- package/dist/engine/start.d.mts +18 -0
- package/dist/engine/start.mjs +88 -0
- package/dist/engine/state.d.mts +37 -67
- package/dist/engine/state.mjs +119 -280
- package/dist/engine/step-api.d.mts +5 -8
- package/dist/engine/step-api.mjs +16 -16
- package/dist/engine/stream-reader.d.mts +12 -0
- package/dist/engine/stream-reader.mjs +154 -0
- package/dist/engine/stream.d.mts +9 -54
- package/dist/engine/stream.mjs +54 -196
- package/dist/engine/summary/recovery.d.mts +35 -0
- package/dist/engine/summary/recovery.mjs +363 -0
- package/dist/engine/summary/runs.d.mts +43 -0
- package/dist/engine/summary/runs.mjs +294 -0
- package/dist/engine/summary/step-attempts.d.mts +5 -10
- package/dist/engine/summary/step-attempts.mjs +157 -36
- package/dist/engine/summary/tally.d.mts +44 -0
- package/dist/engine/summary/tally.mjs +142 -0
- package/dist/engine/task.d.mts +4 -5
- package/dist/engine/task.mjs +40 -48
- package/dist/errors/base.d.mts +17 -77
- package/dist/errors/base.mjs +26 -327
- package/dist/errors/capability.d.mts +3 -6
- package/dist/errors/capability.mjs +4 -8
- package/dist/errors/codes.d.mts +116 -0
- package/dist/{types/error-code.mjs → errors/codes.mjs} +2 -17
- package/dist/errors/definition.d.mts +3 -17
- package/dist/errors/definition.mjs +5 -42
- package/dist/errors/failures.d.mts +17 -51
- package/dist/errors/failures.mjs +35 -102
- package/dist/errors/hook.d.mts +5 -9
- package/dist/errors/hook.mjs +4 -16
- package/dist/errors/implementation.d.mts +3 -6
- package/dist/errors/implementation.mjs +7 -12
- package/dist/errors/lock.d.mts +7 -20
- package/dist/errors/lock.mjs +8 -44
- package/dist/errors/message.d.mts +14 -59
- package/dist/errors/message.mjs +13 -39
- package/dist/errors/mod.d.mts +4 -5
- package/dist/errors/mod.mjs +5 -7
- package/dist/errors/records.d.mts +10 -4
- package/dist/errors/records.mjs +256 -256
- package/dist/errors/run.d.mts +27 -68
- package/dist/errors/run.mjs +31 -85
- package/dist/errors/schedule.d.mts +7 -18
- package/dist/errors/schedule.mjs +7 -39
- package/dist/errors/step.d.mts +12 -45
- package/dist/errors/step.mjs +13 -34
- package/dist/errors/stream.d.mts +8 -16
- package/dist/errors/stream.mjs +7 -41
- package/dist/esbuild.d.mts +6 -4
- package/dist/esbuild.mjs +2 -1
- package/dist/events/descriptors.d.mts +12 -241
- package/dist/events/descriptors.mjs +12 -5
- package/dist/history/projection.d.mts +4 -6
- package/dist/history/projection.mjs +22 -26
- package/dist/history/replay-projection.d.mts +44 -48
- package/dist/history/replay-projection.mjs +41 -50
- package/dist/history/{mod.d.mts → replay.d.mts} +16 -21
- package/dist/history/{mod.mjs → replay.mjs} +21 -25
- package/dist/history/sequencer.d.mts +10 -11
- package/dist/history/sequencer.mjs +11 -7
- package/dist/history/step-attempts.d.mts +4 -7
- package/dist/history/step-attempts.mjs +8 -9
- package/dist/history/timeline.d.mts +4 -13
- package/dist/history/timeline.mjs +46 -265
- package/dist/history/validator.d.mts +5 -7
- package/dist/history/validator.mjs +9 -24
- package/dist/hook-token.d.mts +7 -0
- package/dist/hook-token.mjs +32 -0
- package/dist/ids.d.mts +8 -0
- package/dist/ids.mjs +21 -0
- package/dist/message-options.d.mts +11 -5
- package/dist/message-options.mjs +9 -7
- package/dist/mod.d.mts +32 -36
- package/dist/mod.mjs +9 -13
- package/dist/otel/metrics.d.mts +31 -0
- package/dist/otel/metrics.mjs +60 -0
- package/dist/otel/mod.d.mts +3 -0
- package/dist/otel/mod.mjs +3 -0
- package/dist/otel/spans.d.mts +24 -0
- package/dist/otel/spans.mjs +218 -0
- package/dist/otel/support.d.mts +15 -8
- package/dist/otel/support.mjs +18 -40
- package/dist/{otel.d.mts → otel/telemetry.d.mts} +5 -6
- package/dist/otel/telemetry.mjs +305 -0
- package/dist/pagination.d.mts +6 -12
- package/dist/pagination.mjs +10 -14
- package/dist/registry.d.mts +8 -5
- package/dist/registry.mjs +19 -10
- package/dist/rolldown.d.mts +6 -4
- package/dist/rolldown.mjs +2 -1
- package/dist/rollup.d.mts +6 -4
- package/dist/rollup.mjs +2 -1
- package/dist/rspack.d.mts +6 -4
- package/dist/rspack.mjs +2 -1
- package/dist/run-status.d.mts +29 -0
- package/dist/run-status.mjs +42 -0
- package/dist/schema/common.d.mts +22 -0
- package/dist/schema/common.mjs +54 -0
- package/dist/schema/error.d.mts +17 -0
- package/dist/schema/error.mjs +39 -0
- package/dist/schema/events.d.mts +446 -0
- package/dist/schema/events.mjs +235 -0
- package/dist/schema/pagination.d.mts +5 -0
- package/dist/schema/pagination.mjs +11 -0
- package/dist/schema/persisted-value.d.mts +8 -0
- package/dist/schema/persisted-value.mjs +94 -0
- package/dist/schema/run.d.mts +51 -0
- package/dist/schema/run.mjs +88 -0
- package/dist/schema/store.d.mts +94 -0
- package/dist/schema/store.mjs +116 -0
- package/dist/step-definition.d.mts +4 -9
- package/dist/step-definition.mjs +2 -2
- package/dist/store/capabilities.d.mts +8 -9
- package/dist/store/capabilities.mjs +7 -7
- package/dist/store/cleanup.d.mts +9 -14
- package/dist/store/cleanup.mjs +86 -85
- package/dist/store/create.d.mts +28 -29
- package/dist/store/create.mjs +10 -11
- package/dist/store/events.d.mts +48 -0
- package/dist/store/events.mjs +263 -0
- package/dist/store/indexes.d.mts +25 -0
- package/dist/store/indexes.mjs +282 -0
- package/dist/store/instrumentation.d.mts +2 -3
- package/dist/store/instrumentation.mjs +30 -30
- package/dist/store/lock.d.mts +4 -5
- package/dist/store/lock.mjs +5 -7
- package/dist/store/materialization.d.mts +10 -17
- package/dist/store/materialization.mjs +39 -33
- package/dist/store/mod.d.mts +3 -3
- package/dist/store/mod.mjs +2 -2
- package/dist/store/query.d.mts +13 -17
- package/dist/store/query.mjs +13 -13
- package/dist/store/run.d.mts +25 -34
- package/dist/store/run.mjs +67 -108
- package/dist/store/schedule.d.mts +6 -8
- package/dist/store/schedule.mjs +11 -11
- package/dist/store/step-attempt.d.mts +9 -12
- package/dist/store/step-attempt.mjs +9 -9
- package/dist/store/storage-value.d.mts +3 -3
- package/dist/store/storage-value.mjs +17 -1
- package/dist/store/validation.d.mts +17 -20
- package/dist/store/validation.mjs +30 -33
- package/dist/store-keys.d.mts +35 -47
- package/dist/store-keys.mjs +9 -17
- package/dist/telemetry.d.mts +16 -16
- package/dist/telemetry.mjs +3 -3
- package/dist/temporal.d.mts +11 -16
- package/dist/temporal.mjs +8 -9
- package/dist/timer.d.mts +12 -10
- package/dist/timer.mjs +11 -3
- package/dist/types/cleanup.d.mts +13 -50
- package/dist/types/cleanup.mjs +1 -22
- package/dist/types/client.d.mts +101 -162
- package/dist/types/{vite.d.mts → compiler.d.mts} +17 -24
- package/dist/types/compiler.mjs +1 -0
- package/dist/types/definition.d.mts +22 -34
- package/dist/types/engine-options.d.mts +10 -17
- package/dist/types/engine.d.mts +15 -274
- package/dist/types/error.d.mts +15 -217
- package/dist/types/error.mjs +1 -48
- package/dist/types/events.d.mts +59 -2730
- package/dist/types/events.mjs +1 -283
- package/dist/types/hook.d.mts +27 -85
- package/dist/types/hook.mjs +1 -66
- package/dist/types/ids.d.mts +9 -0
- package/dist/types/ids.mjs +1 -0
- package/dist/types/lock.d.mts +8 -26
- package/dist/types/lock.mjs +1 -18
- package/dist/types/message.d.mts +29 -43
- package/dist/types/observation.d.mts +43 -58
- package/dist/types/pagination.d.mts +6 -22
- package/dist/types/pagination.mjs +1 -13
- package/dist/types/result.d.mts +11 -43
- package/dist/types/retry.d.mts +7 -14
- package/dist/types/run-list.d.mts +9 -11
- package/dist/types/run-options.d.mts +25 -32
- package/dist/types/run.d.mts +35 -315
- package/dist/types/run.mjs +1 -207
- package/dist/types/runtime.d.mts +33 -145
- package/dist/types/runtime.mjs +1 -21
- package/dist/types/schedule.d.mts +13 -72
- package/dist/types/schedule.mjs +1 -48
- package/dist/types/step-attempts.d.mts +65 -261
- package/dist/types/step-attempts.mjs +1 -43
- package/dist/types/step.d.mts +66 -77
- package/dist/types/step.mjs +1 -5
- package/dist/types/store.d.mts +50 -182
- package/dist/types/stream.d.mts +19 -40
- package/dist/types/summary.d.mts +174 -278
- package/dist/types/telemetry.d.mts +23 -28
- package/dist/types/telemetry.mjs +1 -9
- package/dist/types/timeline.d.mts +46 -233
- package/dist/types/worker.d.mts +22 -29
- package/dist/values.d.mts +15 -0
- package/dist/values.mjs +57 -0
- package/dist/vite.d.mts +5 -6
- package/dist/vite.mjs +3 -4
- package/dist/webpack.d.mts +6 -4
- package/dist/webpack.mjs +2 -1
- package/dist/worker/error.d.mts +2 -9
- package/dist/worker/error.mjs +20 -32
- package/dist/worker/missing-implementation.d.mts +19 -0
- package/dist/worker/missing-implementation.mjs +62 -0
- package/dist/worker/worker.d.mts +18 -0
- package/dist/{worker.mjs → worker/worker.mjs} +64 -118
- package/package.json +28 -47
- package/dist/engine/execution-api.d.mts +0 -29
- package/dist/engine/execution-api.mjs +0 -33
- package/dist/engine/inspection-api.d.mts +0 -34
- package/dist/engine/inspection-api.mjs +0 -78
- package/dist/engine/mod.d.mts +0 -4
- package/dist/engine/mod.mjs +0 -2
- package/dist/engine/recovery.d.mts +0 -26
- package/dist/engine/recovery.mjs +0 -92
- package/dist/engine/retry-policy.d.mts +0 -4
- package/dist/engine/retry-policy.mjs +0 -4
- package/dist/engine/start-api.d.mts +0 -30
- package/dist/engine/start-api.mjs +0 -99
- package/dist/engine/summary/active-events.d.mts +0 -34
- package/dist/engine/summary/active-events.mjs +0 -69
- package/dist/engine/summary/child-workflow-runs.d.mts +0 -24
- package/dist/engine/summary/child-workflow-runs.mjs +0 -138
- package/dist/engine/summary/child-workflow-waits.d.mts +0 -21
- package/dist/engine/summary/child-workflow-waits.mjs +0 -67
- package/dist/engine/summary/recovery-child-workflow-waits.d.mts +0 -11
- package/dist/engine/summary/recovery-child-workflow-waits.mjs +0 -89
- package/dist/engine/summary/recovery-due-runs.d.mts +0 -16
- package/dist/engine/summary/recovery-due-runs.mjs +0 -52
- package/dist/engine/summary/recovery-failed-runs.d.mts +0 -14
- package/dist/engine/summary/recovery-failed-runs.mjs +0 -33
- package/dist/engine/summary/recovery-lease-runs.d.mts +0 -16
- package/dist/engine/summary/recovery-lease-runs.mjs +0 -69
- package/dist/engine/summary/recovery-locks.d.mts +0 -18
- package/dist/engine/summary/recovery-locks.mjs +0 -100
- package/dist/engine/summary/recovery-message-waits.d.mts +0 -11
- package/dist/engine/summary/recovery-message-waits.mjs +0 -74
- package/dist/engine/summary/recovery-retry-runs.d.mts +0 -17
- package/dist/engine/summary/recovery-retry-runs.mjs +0 -65
- package/dist/engine/summary/recovery-run-timestamps.d.mts +0 -13
- package/dist/engine/summary/recovery-run-timestamps.mjs +0 -18
- package/dist/engine/summary/recovery-runs.d.mts +0 -23
- package/dist/engine/summary/recovery-runs.mjs +0 -54
- package/dist/engine/summary/recovery-schedules.d.mts +0 -10
- package/dist/engine/summary/recovery-schedules.mjs +0 -46
- package/dist/engine/summary/recovery-sleep-waits.d.mts +0 -10
- package/dist/engine/summary/recovery-sleep-waits.mjs +0 -53
- package/dist/engine/summary/recovery-waits.d.mts +0 -21
- package/dist/engine/summary/recovery-waits.mjs +0 -29
- package/dist/engine/summary/run-availability.d.mts +0 -13
- package/dist/engine/summary/run-availability.mjs +0 -37
- package/dist/engine/summary/run-cleanup.d.mts +0 -14
- package/dist/engine/summary/run-cleanup.mjs +0 -44
- package/dist/engine/summary/run-failure.d.mts +0 -14
- package/dist/engine/summary/run-failure.mjs +0 -62
- package/dist/engine/summary/run-hooks.d.mts +0 -14
- package/dist/engine/summary/run-hooks.mjs +0 -63
- package/dist/engine/summary/run-lease.d.mts +0 -11
- package/dist/engine/summary/run-lease.mjs +0 -64
- package/dist/engine/summary/run-message-waits.d.mts +0 -15
- package/dist/engine/summary/run-message-waits.mjs +0 -62
- package/dist/engine/summary/run-metrics.d.mts +0 -31
- package/dist/engine/summary/run-metrics.mjs +0 -93
- package/dist/engine/summary/run-retry.d.mts +0 -9
- package/dist/engine/summary/run-retry.mjs +0 -69
- package/dist/engine/summary/run-sleeps.d.mts +0 -15
- package/dist/engine/summary/run-sleeps.mjs +0 -61
- package/dist/engine/summary/run-state.d.mts +0 -26
- package/dist/engine/summary/run-state.mjs +0 -48
- package/dist/engine/summary/run-status.d.mts +0 -16
- package/dist/engine/summary/run-status.mjs +0 -35
- package/dist/engine/summary/run-streams.d.mts +0 -14
- package/dist/engine/summary/run-streams.mjs +0 -46
- package/dist/engine/summary/run-transition.d.mts +0 -9
- package/dist/engine/summary/run-transition.mjs +0 -39
- package/dist/engine/summary/run-workflow.d.mts +0 -9
- package/dist/engine/summary/run-workflow.mjs +0 -47
- package/dist/engine/summary/step-attempt-active-child-workflows.d.mts +0 -13
- package/dist/engine/summary/step-attempt-active-child-workflows.mjs +0 -55
- package/dist/engine/summary/step-attempt-active-fields.d.mts +0 -23
- package/dist/engine/summary/step-attempt-active-fields.mjs +0 -14
- package/dist/engine/summary/step-attempt-active-message-waits.d.mts +0 -12
- package/dist/engine/summary/step-attempt-active-message-waits.mjs +0 -47
- package/dist/engine/summary/step-attempt-active-sleeps.d.mts +0 -19
- package/dist/engine/summary/step-attempt-active-sleeps.mjs +0 -44
- package/dist/engine/summary/step-attempt-buckets.d.mts +0 -22
- package/dist/engine/summary/step-attempt-buckets.mjs +0 -152
- package/dist/engine/summary/step-attempt-failure.d.mts +0 -12
- package/dist/engine/summary/step-attempt-failure.mjs +0 -61
- package/dist/engine/summary/step-attempt-lifecycle.d.mts +0 -13
- package/dist/engine/summary/step-attempt-lifecycle.mjs +0 -19
- package/dist/engine/summary.d.mts +0 -32
- package/dist/engine/summary.mjs +0 -37
- package/dist/errors/details.d.mts +0 -13
- package/dist/errors/details.mjs +0 -66
- package/dist/errors/record-view.d.mts +0 -11
- package/dist/errors/record-view.mjs +0 -24
- package/dist/errors/runtime.d.mts +0 -12
- package/dist/errors/runtime.mjs +0 -24
- package/dist/events/mod.d.mts +0 -3
- package/dist/events/mod.mjs +0 -2
- package/dist/history/attempt-key.d.mts +0 -6
- package/dist/history/attempt-key.mjs +0 -7
- package/dist/inspection/mod.d.mts +0 -5
- package/dist/inspection/mod.mjs +0 -3
- package/dist/otel.mjs +0 -590
- package/dist/runtime.d.mts +0 -35
- package/dist/runtime.mjs +0 -198
- package/dist/store/append-projection.d.mts +0 -15
- package/dist/store/append-projection.mjs +0 -26
- package/dist/store/compaction.d.mts +0 -5
- package/dist/store/compaction.mjs +0 -8
- package/dist/store/event-append-project.d.mts +0 -15
- package/dist/store/event-append-project.mjs +0 -77
- package/dist/store/event-append.d.mts +0 -37
- package/dist/store/event-append.mjs +0 -80
- package/dist/store/event-history.d.mts +0 -22
- package/dist/store/event-history.mjs +0 -75
- package/dist/store/event.d.mts +0 -10
- package/dist/store/event.mjs +0 -28
- package/dist/store/idempotency.d.mts +0 -10
- package/dist/store/idempotency.mjs +0 -167
- package/dist/store/message-index.d.mts +0 -21
- package/dist/store/message-index.mjs +0 -122
- package/dist/store/revision.d.mts +0 -4
- package/dist/store/revision.mjs +0 -7
- package/dist/store/schema.d.mts +0 -14
- package/dist/store/schema.mjs +0 -17
- package/dist/types/common.d.mts +0 -20
- package/dist/types/common.mjs +0 -16
- package/dist/types/error-code.d.mts +0 -256
- package/dist/types/message-id.d.mts +0 -7
- package/dist/types/message-id.mjs +0 -5
- package/dist/types/run-id.d.mts +0 -7
- package/dist/types/run-id.mjs +0 -5
- package/dist/types/step-id.d.mts +0 -7
- package/dist/types/step-id.mjs +0 -5
- package/dist/types/stream-id.d.mts +0 -7
- package/dist/types/stream-id.mjs +0 -5
- package/dist/types/worker-id.d.mts +0 -7
- package/dist/types/worker-id.mjs +0 -5
- package/dist/utility.d.mts +0 -49
- package/dist/utility.mjs +0 -122
- package/dist/vite/ast.d.mts +0 -23
- package/dist/vite/generated-name.d.mts +0 -7
- package/dist/vite/generated-name.mjs +0 -9
- package/dist/vite/manifest.d.mts +0 -7
- package/dist/vite/plugin.d.mts +0 -7
- package/dist/vite/safety.d.mts +0 -12
- package/dist/vite/source.d.mts +0 -7
- package/dist/vite/transform.d.mts +0 -7
- package/dist/webhook.d.mts +0 -16
- package/dist/webhook.mjs +0 -17
- package/dist/worker.d.mts +0 -19
- /package/dist/{types/vite.mjs → engine/context.mjs} +0 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { optionalDurationBetweenMilliseconds } from "../temporal.mjs";
|
|
2
|
+
import { WORKFLOW_ATTRIBUTES, WORKFLOW_MESSAGING_ATTRIBUTES, WORKFLOW_SPAN_NAMES } from "../telemetry.mjs";
|
|
3
|
+
import { contextFromTraceContext, errorRecordToException, spanLinkFromTraceContext, streamStatusFromEventKind, toException } from "./support.mjs";
|
|
4
|
+
import { SpanStatusCode } from "@opentelemetry/api";
|
|
5
|
+
//#region src/otel/spans.ts
|
|
6
|
+
/** Records the spans for durable events, messages, hooks, schedules, workers, and streams. */
|
|
7
|
+
var SpanRecorder = class {
|
|
8
|
+
#tracer;
|
|
9
|
+
#metrics;
|
|
10
|
+
#attributes;
|
|
11
|
+
constructor(tracer, metrics, attributes) {
|
|
12
|
+
this.#tracer = tracer;
|
|
13
|
+
this.#metrics = metrics;
|
|
14
|
+
this.#attributes = attributes;
|
|
15
|
+
}
|
|
16
|
+
recordDurableEventLatency(event, history) {
|
|
17
|
+
if (event.event.kind !== "message_wait_completed") return;
|
|
18
|
+
const completed = event.event;
|
|
19
|
+
const started = history.startedMessageWaitForCompleted(completed);
|
|
20
|
+
if (started === void 0) return;
|
|
21
|
+
const latency = optionalDurationBetweenMilliseconds(started.timestamp, completed.messageTimestamp);
|
|
22
|
+
if (latency === void 0) return;
|
|
23
|
+
const source = started.source ?? "message";
|
|
24
|
+
const attributes = this.#attributes({ [WORKFLOW_ATTRIBUTES.messageSource]: source });
|
|
25
|
+
this.#metrics.messageWaitLatency.record(latency, attributes);
|
|
26
|
+
if (source === "hook" || source === "webhook") this.#metrics.hookResumeLatency.record(latency, this.#attributes({ [WORKFLOW_ATTRIBUTES.hookKind]: source }));
|
|
27
|
+
this.recordMessageWaitSpan(completed, started, history);
|
|
28
|
+
}
|
|
29
|
+
recordDurableSleepSpan(event, history) {
|
|
30
|
+
if (event.event.kind !== "sleep_completed") return;
|
|
31
|
+
const completed = event.event;
|
|
32
|
+
const started = history.startedSleepForCompleted(completed);
|
|
33
|
+
if (started === void 0) return;
|
|
34
|
+
const requestedDuration = started.duration?.total({ unit: "millisecond" });
|
|
35
|
+
const actualDuration = optionalDurationBetweenMilliseconds(started.timestamp, completed.timestamp);
|
|
36
|
+
const span = this.#tracer.startSpan(WORKFLOW_SPAN_NAMES.sleep, { attributes: this.#attributes({
|
|
37
|
+
[WORKFLOW_ATTRIBUTES.runId]: event.runId,
|
|
38
|
+
[WORKFLOW_ATTRIBUTES.stepId]: completed.stepId,
|
|
39
|
+
[WORKFLOW_ATTRIBUTES.stepName]: completed.stepName,
|
|
40
|
+
[WORKFLOW_ATTRIBUTES.stepKind]: "sleep",
|
|
41
|
+
[WORKFLOW_ATTRIBUTES.sleepUntil]: started.until.toString(),
|
|
42
|
+
[WORKFLOW_ATTRIBUTES.sleepDurationMs]: requestedDuration,
|
|
43
|
+
[WORKFLOW_ATTRIBUTES.sleepActualMs]: actualDuration
|
|
44
|
+
}) });
|
|
45
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
46
|
+
span.end();
|
|
47
|
+
}
|
|
48
|
+
recordChildWorkflowOperationSpan(event, history) {
|
|
49
|
+
if (event.event.kind !== "child_workflow_completed" && event.event.kind !== "child_workflow_failed") return;
|
|
50
|
+
const terminal = event.event;
|
|
51
|
+
const started = history.startedChildWorkflowForTerminal(terminal);
|
|
52
|
+
const duration = started === void 0 ? void 0 : optionalDurationBetweenMilliseconds(started.timestamp, terminal.timestamp);
|
|
53
|
+
const failed = terminal.kind === "child_workflow_failed";
|
|
54
|
+
const span = this.#tracer.startSpan(WORKFLOW_SPAN_NAMES.childWorkflowOperation, { attributes: this.#attributes({
|
|
55
|
+
[WORKFLOW_ATTRIBUTES.runId]: event.runId,
|
|
56
|
+
[WORKFLOW_ATTRIBUTES.stepId]: terminal.stepId,
|
|
57
|
+
[WORKFLOW_ATTRIBUTES.stepName]: terminal.stepName,
|
|
58
|
+
[WORKFLOW_ATTRIBUTES.stepKind]: "workflow",
|
|
59
|
+
[WORKFLOW_ATTRIBUTES.stepAttempt]: terminal.attempt,
|
|
60
|
+
[WORKFLOW_ATTRIBUTES.childWorkflowOperation]: failed ? "fail" : "complete",
|
|
61
|
+
[WORKFLOW_ATTRIBUTES.childWorkflowRunId]: terminal.childRunId,
|
|
62
|
+
[WORKFLOW_ATTRIBUTES.childWorkflowName]: started?.workflowName,
|
|
63
|
+
[WORKFLOW_ATTRIBUTES.childWorkflowVersion]: started?.workflowVersion,
|
|
64
|
+
[WORKFLOW_ATTRIBUTES.childWorkflowStatus]: failed ? "failed" : "completed",
|
|
65
|
+
[WORKFLOW_ATTRIBUTES.childWorkflowDurationMs]: duration,
|
|
66
|
+
[WORKFLOW_ATTRIBUTES.errorKind]: failed ? terminal.error.name : void 0
|
|
67
|
+
}) });
|
|
68
|
+
if (failed) {
|
|
69
|
+
span.recordException(errorRecordToException(terminal.error));
|
|
70
|
+
span.setStatus({
|
|
71
|
+
code: SpanStatusCode.ERROR,
|
|
72
|
+
message: terminal.error.message
|
|
73
|
+
});
|
|
74
|
+
} else span.setStatus({ code: SpanStatusCode.OK });
|
|
75
|
+
span.end();
|
|
76
|
+
}
|
|
77
|
+
recordChildWorkflowStartedSpan(event) {
|
|
78
|
+
const started = event.event;
|
|
79
|
+
const span = this.#tracer.startSpan(WORKFLOW_SPAN_NAMES.childWorkflowOperation, { attributes: this.#attributes({
|
|
80
|
+
[WORKFLOW_ATTRIBUTES.runId]: event.runId,
|
|
81
|
+
[WORKFLOW_ATTRIBUTES.stepId]: started.stepId,
|
|
82
|
+
[WORKFLOW_ATTRIBUTES.stepName]: started.stepName,
|
|
83
|
+
[WORKFLOW_ATTRIBUTES.stepKind]: "workflow",
|
|
84
|
+
[WORKFLOW_ATTRIBUTES.stepAttempt]: started.attempt,
|
|
85
|
+
[WORKFLOW_ATTRIBUTES.childWorkflowOperation]: "start",
|
|
86
|
+
[WORKFLOW_ATTRIBUTES.childWorkflowRunId]: started.childRunId,
|
|
87
|
+
[WORKFLOW_ATTRIBUTES.childWorkflowName]: started.workflowName,
|
|
88
|
+
[WORKFLOW_ATTRIBUTES.childWorkflowVersion]: started.workflowVersion,
|
|
89
|
+
[WORKFLOW_ATTRIBUTES.childWorkflowStatus]: "started"
|
|
90
|
+
}) });
|
|
91
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
92
|
+
span.end();
|
|
93
|
+
}
|
|
94
|
+
recordMessageSentSpan(event) {
|
|
95
|
+
const parent = contextFromTraceContext(event.traceContext);
|
|
96
|
+
const span = this.#tracer.startSpan(WORKFLOW_SPAN_NAMES.messageSend, { attributes: this.#attributes({
|
|
97
|
+
[WORKFLOW_ATTRIBUTES.runId]: event.runId,
|
|
98
|
+
[WORKFLOW_ATTRIBUTES.messageId]: event.messageId,
|
|
99
|
+
[WORKFLOW_MESSAGING_ATTRIBUTES.system]: "temelj.workflow",
|
|
100
|
+
[WORKFLOW_MESSAGING_ATTRIBUTES.destinationName]: event.runId,
|
|
101
|
+
[WORKFLOW_MESSAGING_ATTRIBUTES.messageId]: event.messageId,
|
|
102
|
+
[WORKFLOW_MESSAGING_ATTRIBUTES.operationName]: "send",
|
|
103
|
+
[WORKFLOW_MESSAGING_ATTRIBUTES.operationType]: "publish"
|
|
104
|
+
}) }, parent);
|
|
105
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
106
|
+
span.end();
|
|
107
|
+
}
|
|
108
|
+
recordHookResumeSpan(kind, event) {
|
|
109
|
+
const parent = contextFromTraceContext(event.traceContext);
|
|
110
|
+
const span = this.#tracer.startSpan(WORKFLOW_SPAN_NAMES.hookResume, { attributes: this.#attributes({
|
|
111
|
+
[WORKFLOW_ATTRIBUTES.hookKind]: kind,
|
|
112
|
+
[WORKFLOW_ATTRIBUTES.runId]: event.runId,
|
|
113
|
+
[WORKFLOW_ATTRIBUTES.messageId]: event.messageId,
|
|
114
|
+
[WORKFLOW_MESSAGING_ATTRIBUTES.system]: "temelj.workflow",
|
|
115
|
+
[WORKFLOW_MESSAGING_ATTRIBUTES.destinationName]: event.runId,
|
|
116
|
+
[WORKFLOW_MESSAGING_ATTRIBUTES.messageId]: event.messageId,
|
|
117
|
+
[WORKFLOW_MESSAGING_ATTRIBUTES.operationName]: "resume",
|
|
118
|
+
[WORKFLOW_MESSAGING_ATTRIBUTES.operationType]: "publish"
|
|
119
|
+
}) }, parent);
|
|
120
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
121
|
+
span.end();
|
|
122
|
+
}
|
|
123
|
+
recordScheduleRunCreatedSpan(event) {
|
|
124
|
+
const span = this.#tracer.startSpan(WORKFLOW_SPAN_NAMES.scheduleRunCreate, { attributes: this.#attributes({
|
|
125
|
+
[WORKFLOW_ATTRIBUTES.workflowName]: event.workflowName,
|
|
126
|
+
[WORKFLOW_ATTRIBUTES.workflowVersion]: event.workflowVersion,
|
|
127
|
+
[WORKFLOW_ATTRIBUTES.scheduleId]: event.scheduleId,
|
|
128
|
+
[WORKFLOW_ATTRIBUTES.scheduleFireAt]: event.fireAt.toString(),
|
|
129
|
+
[WORKFLOW_ATTRIBUTES.runId]: event.runId
|
|
130
|
+
}) });
|
|
131
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
132
|
+
span.end();
|
|
133
|
+
}
|
|
134
|
+
recordScheduleTickSpan(event) {
|
|
135
|
+
const span = this.#tracer.startSpan(WORKFLOW_SPAN_NAMES.scheduleTick, { attributes: this.#attributes({
|
|
136
|
+
[WORKFLOW_ATTRIBUTES.scheduleTickedRuns]: event.result.ticked,
|
|
137
|
+
[WORKFLOW_ATTRIBUTES.scheduleTickedSchedules]: event.result.scheduleIds.length,
|
|
138
|
+
[WORKFLOW_ATTRIBUTES.scheduleNextAt]: event.result.nextScheduleAt === void 0 ? void 0 : event.result.nextScheduleAt.toString()
|
|
139
|
+
}) });
|
|
140
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
141
|
+
span.end();
|
|
142
|
+
}
|
|
143
|
+
recordWorkerOperationSpan(event) {
|
|
144
|
+
const span = this.#tracer.startSpan(WORKFLOW_SPAN_NAMES.workerOperation, { attributes: this.#attributes({
|
|
145
|
+
[WORKFLOW_ATTRIBUTES.workerId]: event.workerId,
|
|
146
|
+
[WORKFLOW_ATTRIBUTES.runId]: event.runId,
|
|
147
|
+
[WORKFLOW_ATTRIBUTES.workflowName]: event.run?.workflowName,
|
|
148
|
+
[WORKFLOW_ATTRIBUTES.workflowVersion]: event.run?.workflowVersion,
|
|
149
|
+
[WORKFLOW_ATTRIBUTES.runStatus]: event.run?.status,
|
|
150
|
+
[WORKFLOW_ATTRIBUTES.workerOperation]: event.operation,
|
|
151
|
+
[WORKFLOW_ATTRIBUTES.workerOperationStatus]: event.status
|
|
152
|
+
}) });
|
|
153
|
+
if (event.status === "failure") {
|
|
154
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
155
|
+
if (event.error !== void 0) span.recordException(toException(event.error));
|
|
156
|
+
} else span.setStatus({ code: SpanStatusCode.OK });
|
|
157
|
+
span.end();
|
|
158
|
+
}
|
|
159
|
+
recordCleanupOperationSpan(source, event) {
|
|
160
|
+
const span = this.#tracer.startSpan(WORKFLOW_SPAN_NAMES.cleanupOperation, { attributes: this.#attributes({
|
|
161
|
+
[WORKFLOW_ATTRIBUTES.cleanupSource]: source,
|
|
162
|
+
[WORKFLOW_ATTRIBUTES.cleanupDeletedRuns]: event.result.deletedRuns,
|
|
163
|
+
[WORKFLOW_ATTRIBUTES.cleanupCreatedMarkers]: event.result.createdCleanupMarkers,
|
|
164
|
+
[WORKFLOW_ATTRIBUTES.cleanupDeletedMarkers]: event.result.deletedCleanupMarkers,
|
|
165
|
+
[WORKFLOW_ATTRIBUTES.cleanupDeletedEvents]: event.result.deletedEvents,
|
|
166
|
+
[WORKFLOW_ATTRIBUTES.cleanupDeletedStepAttempts]: event.result.deletedStepAttempts,
|
|
167
|
+
[WORKFLOW_ATTRIBUTES.cleanupDeletedIdempotencyKeys]: event.result.deletedIdempotencyKeys,
|
|
168
|
+
[WORKFLOW_ATTRIBUTES.cleanupDeletedMessageIdempotencyKeys]: event.result.deletedMessageIdempotencyKeys,
|
|
169
|
+
[WORKFLOW_ATTRIBUTES.cleanupDryRun]: event.result.dryRun,
|
|
170
|
+
[WORKFLOW_ATTRIBUTES.cleanupMatchedRuns]: event.result.matchedRuns ?? event.result.runIds.length
|
|
171
|
+
}) });
|
|
172
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
173
|
+
span.end();
|
|
174
|
+
}
|
|
175
|
+
recordStreamOperationSpan(event) {
|
|
176
|
+
const span = this.#tracer.startSpan(WORKFLOW_SPAN_NAMES.streamOperation, { attributes: this.#attributes({
|
|
177
|
+
[WORKFLOW_ATTRIBUTES.runId]: event.runId,
|
|
178
|
+
[WORKFLOW_ATTRIBUTES.streamId]: event.streamId,
|
|
179
|
+
[WORKFLOW_ATTRIBUTES.streamEventKind]: event.eventKind,
|
|
180
|
+
[WORKFLOW_ATTRIBUTES.streamStatus]: streamStatusFromEventKind(event.eventKind),
|
|
181
|
+
[WORKFLOW_ATTRIBUTES.stepId]: event.stepId,
|
|
182
|
+
[WORKFLOW_ATTRIBUTES.stepName]: event.stepName,
|
|
183
|
+
[WORKFLOW_ATTRIBUTES.streamIndex]: event.index,
|
|
184
|
+
[WORKFLOW_ATTRIBUTES.errorKind]: event.error?.name
|
|
185
|
+
}) });
|
|
186
|
+
if (event.error === void 0) span.setStatus({ code: SpanStatusCode.OK });
|
|
187
|
+
else {
|
|
188
|
+
span.recordException(errorRecordToException(event.error));
|
|
189
|
+
span.setStatus({
|
|
190
|
+
code: SpanStatusCode.ERROR,
|
|
191
|
+
message: event.error.message
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
span.end();
|
|
195
|
+
}
|
|
196
|
+
recordMessageWaitSpan(completed, started, history) {
|
|
197
|
+
const message = history.messageSentByTimestamp(completed.messageId, completed.messageTimestamp);
|
|
198
|
+
const link = spanLinkFromTraceContext(completed.telemetryContext ?? message?.telemetryContext);
|
|
199
|
+
return this.#tracer.startActiveSpan(WORKFLOW_SPAN_NAMES.messageWait, {
|
|
200
|
+
attributes: this.#attributes({
|
|
201
|
+
[WORKFLOW_ATTRIBUTES.messageId]: completed.messageId,
|
|
202
|
+
[WORKFLOW_ATTRIBUTES.messageSource]: started.source ?? "message",
|
|
203
|
+
[WORKFLOW_ATTRIBUTES.stepId]: completed.stepId,
|
|
204
|
+
[WORKFLOW_ATTRIBUTES.stepName]: completed.stepName,
|
|
205
|
+
[WORKFLOW_MESSAGING_ATTRIBUTES.system]: "temelj.workflow",
|
|
206
|
+
[WORKFLOW_MESSAGING_ATTRIBUTES.messageId]: completed.messageId,
|
|
207
|
+
[WORKFLOW_MESSAGING_ATTRIBUTES.operationName]: "receive",
|
|
208
|
+
[WORKFLOW_MESSAGING_ATTRIBUTES.operationType]: "receive"
|
|
209
|
+
}),
|
|
210
|
+
links: link === void 0 ? [] : [link]
|
|
211
|
+
}, (span) => {
|
|
212
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
213
|
+
span.end();
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
//#endregion
|
|
218
|
+
export { SpanRecorder };
|
package/dist/otel/support.d.mts
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
|
+
import { ExecutionResult } from "../types/result.mjs";
|
|
1
2
|
import { TelemetryContext } from "../types/telemetry.mjs";
|
|
2
3
|
import { StreamEventKind } from "../types/events.mjs";
|
|
3
4
|
import { Context, Span, SpanContext } from "@opentelemetry/api";
|
|
4
5
|
//#region src/otel/support.d.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
interface SpanStatusHooks<T> {
|
|
7
|
+
/** Records a successful result; the span status defaults to OK when this is absent. */
|
|
8
|
+
readonly onSuccess?: (result: T) => void;
|
|
9
|
+
readonly onFailure?: () => void;
|
|
10
|
+
}
|
|
11
|
+
/** Runs `callback` in `span`, records its outcome, and ends the span. */
|
|
12
|
+
export declare function withSpanStatus<T>(span: Span, callback: () => Promise<T>, hooks?: SpanStatusHooks<T>): Promise<T>;
|
|
13
|
+
export declare function recordResultOnSpan(span: Span, result: ExecutionResult): void;
|
|
14
|
+
export declare function contextFromTraceContext(traceContext: TelemetryContext | undefined): Context;
|
|
15
|
+
export declare function spanLinkFromTraceContext(traceContext: TelemetryContext | undefined): {
|
|
9
16
|
readonly context: SpanContext;
|
|
10
17
|
} | undefined;
|
|
11
|
-
declare function streamStatusFromEventKind(eventKind: StreamEventKind): "open" | "closed" | "failed";
|
|
12
|
-
declare function errorRecordToException(error: {
|
|
18
|
+
export declare function streamStatusFromEventKind(eventKind: StreamEventKind): "open" | "closed" | "failed";
|
|
19
|
+
export declare function errorRecordToException(error: {
|
|
13
20
|
readonly message: string;
|
|
14
21
|
readonly name: string;
|
|
15
22
|
}): Error;
|
|
16
|
-
declare function toException(
|
|
23
|
+
export declare function toException(cause: unknown): Error;
|
|
17
24
|
//#endregion
|
|
18
|
-
export {
|
|
25
|
+
export {};
|
package/dist/otel/support.mjs
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
|
+
import { omitUndefined } from "../collection.mjs";
|
|
1
2
|
import { WORKFLOW_ATTRIBUTES } from "../telemetry.mjs";
|
|
2
3
|
import { SpanStatusCode, context, propagation } from "@opentelemetry/api";
|
|
3
4
|
//#region src/otel/support.ts
|
|
4
|
-
var
|
|
5
|
-
constructor(message, name
|
|
5
|
+
var TelemetryException = class TelemetryException extends Error {
|
|
6
|
+
constructor(message, name) {
|
|
6
7
|
super(message);
|
|
7
8
|
this.name = name;
|
|
8
|
-
if (Error.captureStackTrace !== void 0) Error.captureStackTrace(this, context ?? this.constructor);
|
|
9
9
|
}
|
|
10
10
|
static fromRecord(error) {
|
|
11
|
-
return new
|
|
11
|
+
return new TelemetryException(error.message, error.name);
|
|
12
12
|
}
|
|
13
|
-
static fromUnknown(
|
|
14
|
-
return new
|
|
13
|
+
static fromUnknown(cause) {
|
|
14
|
+
return new TelemetryException(String(cause), "Error");
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
|
-
|
|
17
|
+
/** Runs `callback` in `span`, records its outcome, and ends the span. */
|
|
18
|
+
async function withSpanStatus(span, callback, hooks = {}) {
|
|
18
19
|
try {
|
|
19
20
|
const result = await callback();
|
|
20
|
-
|
|
21
|
+
if (hooks.onSuccess === void 0) span.setStatus({ code: SpanStatusCode.OK });
|
|
22
|
+
else hooks.onSuccess(result);
|
|
21
23
|
return result;
|
|
22
24
|
} catch (error) {
|
|
25
|
+
hooks.onFailure?.();
|
|
23
26
|
span.recordException(toException(error));
|
|
24
27
|
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
25
28
|
throw error;
|
|
@@ -27,24 +30,7 @@ async function withRunSpanStatus(span, callback) {
|
|
|
27
30
|
span.end();
|
|
28
31
|
}
|
|
29
32
|
}
|
|
30
|
-
|
|
31
|
-
try {
|
|
32
|
-
const result = await callback();
|
|
33
|
-
span.setStatus({ code: SpanStatusCode.OK });
|
|
34
|
-
return result;
|
|
35
|
-
} catch (error) {
|
|
36
|
-
span.recordException(toException(error));
|
|
37
|
-
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
38
|
-
throw error;
|
|
39
|
-
} finally {
|
|
40
|
-
span.end();
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
function recordWorkflowResultOnSpan(span, result) {
|
|
44
|
-
if (!isExecutionResult(result)) {
|
|
45
|
-
span.setStatus({ code: SpanStatusCode.OK });
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
33
|
+
function recordResultOnSpan(span, result) {
|
|
48
34
|
span.setAttributes({
|
|
49
35
|
[WORKFLOW_ATTRIBUTES.runStatus]: result.run.status,
|
|
50
36
|
[WORKFLOW_ATTRIBUTES.runTransition]: result.run.lastTransitionReason
|
|
@@ -59,17 +45,9 @@ function recordWorkflowResultOnSpan(span, result) {
|
|
|
59
45
|
}
|
|
60
46
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
61
47
|
}
|
|
62
|
-
function isExecutionResult(result) {
|
|
63
|
-
if (typeof result !== "object" || result === null || !("kind" in result) || !("run" in result)) return false;
|
|
64
|
-
const kind = result.kind;
|
|
65
|
-
return kind === "completed" || kind === "failed" || kind === "waiting";
|
|
66
|
-
}
|
|
67
48
|
function contextFromTraceContext(traceContext) {
|
|
68
49
|
if (traceContext === void 0) return context.active();
|
|
69
|
-
return propagation.extract(context.active(),
|
|
70
|
-
...traceContext.traceparent === void 0 ? {} : { traceparent: traceContext.traceparent },
|
|
71
|
-
...traceContext.tracestate === void 0 ? {} : { tracestate: traceContext.tracestate }
|
|
72
|
-
});
|
|
50
|
+
return propagation.extract(context.active(), omitUndefined(traceContext));
|
|
73
51
|
}
|
|
74
52
|
function spanLinkFromTraceContext(traceContext) {
|
|
75
53
|
if (traceContext?.traceparent === void 0) return;
|
|
@@ -92,11 +70,11 @@ function streamStatusFromEventKind(eventKind) {
|
|
|
92
70
|
}
|
|
93
71
|
}
|
|
94
72
|
function errorRecordToException(error) {
|
|
95
|
-
return
|
|
73
|
+
return TelemetryException.fromRecord(error);
|
|
96
74
|
}
|
|
97
|
-
function toException(
|
|
98
|
-
if (
|
|
99
|
-
return
|
|
75
|
+
function toException(cause) {
|
|
76
|
+
if (cause instanceof Error) return cause;
|
|
77
|
+
return TelemetryException.fromUnknown(cause);
|
|
100
78
|
}
|
|
101
79
|
//#endregion
|
|
102
|
-
export { contextFromTraceContext, errorRecordToException, spanLinkFromTraceContext, streamStatusFromEventKind, toException,
|
|
80
|
+
export { contextFromTraceContext, errorRecordToException, recordResultOnSpan, spanLinkFromTraceContext, streamStatusFromEventKind, toException, withSpanStatus };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Telemetry } from "
|
|
2
|
-
//#region src/otel.d.ts
|
|
3
|
-
interface OpenTelemetryWorkflowTelemetryOptions {
|
|
1
|
+
import { Telemetry } from "../types/telemetry.mjs";
|
|
2
|
+
//#region src/otel/telemetry.d.ts
|
|
3
|
+
export interface OpenTelemetryWorkflowTelemetryOptions {
|
|
4
4
|
readonly serviceNamespace?: string;
|
|
5
5
|
readonly includeStepNameMetricAttribute?: boolean;
|
|
6
6
|
/**
|
|
@@ -25,6 +25,5 @@ interface OpenTelemetryWorkflowTelemetryOptions {
|
|
|
25
25
|
*/
|
|
26
26
|
readonly shutdown?: () => Promise<void> | void;
|
|
27
27
|
}
|
|
28
|
-
declare function createOpenTelemetryTelemetry(options?: OpenTelemetryWorkflowTelemetryOptions): Telemetry;
|
|
29
|
-
//#endregion
|
|
30
|
-
export { OpenTelemetryWorkflowTelemetryOptions, createOpenTelemetryTelemetry };
|
|
28
|
+
export declare function createOpenTelemetryTelemetry(options?: OpenTelemetryWorkflowTelemetryOptions): Telemetry;
|
|
29
|
+
//#endregion
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { optionalDurationBetweenMilliseconds } from "../temporal.mjs";
|
|
2
|
+
import { omitUndefined } from "../collection.mjs";
|
|
3
|
+
import { getEventDescriptor } from "../events/descriptors.mjs";
|
|
4
|
+
import { History } from "../history/replay.mjs";
|
|
5
|
+
import { WORKFLOW_ATTRIBUTES, WORKFLOW_INSTRUMENTATION_NAME, WORKFLOW_INSTRUMENTATION_VERSION, WORKFLOW_METRIC_NAMES, WORKFLOW_SPAN_NAMES, WORKFLOW_SYSTEM } from "../telemetry.mjs";
|
|
6
|
+
import { createInstruments } from "./metrics.mjs";
|
|
7
|
+
import { contextFromTraceContext, recordResultOnSpan, streamStatusFromEventKind, withSpanStatus } from "./support.mjs";
|
|
8
|
+
import { SpanRecorder } from "./spans.mjs";
|
|
9
|
+
import { SpanStatusCode, context, metrics, propagation, trace } from "@opentelemetry/api";
|
|
10
|
+
//#region src/otel/telemetry.ts
|
|
11
|
+
function createOpenTelemetryTelemetry(options = {}) {
|
|
12
|
+
return new OpenTelemetryTelemetry(options);
|
|
13
|
+
}
|
|
14
|
+
var OpenTelemetryTelemetry = class {
|
|
15
|
+
#tracer = trace.getTracer(WORKFLOW_INSTRUMENTATION_NAME, WORKFLOW_INSTRUMENTATION_VERSION);
|
|
16
|
+
#meter = metrics.getMeter(WORKFLOW_INSTRUMENTATION_NAME, WORKFLOW_INSTRUMENTATION_VERSION);
|
|
17
|
+
#options;
|
|
18
|
+
#metrics = createInstruments(this.#meter);
|
|
19
|
+
#spans = new SpanRecorder(this.#tracer, this.#metrics, (attributes) => this.#attributes(attributes));
|
|
20
|
+
#runGauge;
|
|
21
|
+
#workerActiveExecutionsGauge;
|
|
22
|
+
#engine;
|
|
23
|
+
constructor(options) {
|
|
24
|
+
this.#options = options;
|
|
25
|
+
this.#runGauge = this.#meter.createObservableGauge(WORKFLOW_METRIC_NAMES.runs, { description: "Current count of workflow runs by status." });
|
|
26
|
+
this.#workerActiveExecutionsGauge = this.#meter.createObservableGauge(WORKFLOW_METRIC_NAMES.workerActiveExecutions, { description: "Current count of workflow runs actively held by workers." });
|
|
27
|
+
this.#runGauge.addCallback(async (result) => {
|
|
28
|
+
if (this.#engine?.getRunSummary === void 0) return;
|
|
29
|
+
try {
|
|
30
|
+
const summary = await this.#engine.getRunSummary();
|
|
31
|
+
for (const [status, count] of Object.entries(summary.status)) result.observe(count, this.#attributes({ [WORKFLOW_ATTRIBUTES.runStatus]: status }));
|
|
32
|
+
} catch {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
this.#workerActiveExecutionsGauge.addCallback(async (result) => {
|
|
37
|
+
if (this.#engine?.getRunSummary === void 0) return;
|
|
38
|
+
try {
|
|
39
|
+
const summary = await this.#engine.getRunSummary();
|
|
40
|
+
result.observe(summary.status.running, this.#attributes({ [WORKFLOW_ATTRIBUTES.runStatus]: "running" }));
|
|
41
|
+
} catch {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
captureContext() {
|
|
47
|
+
const carrier = {};
|
|
48
|
+
propagation.inject(context.active(), carrier);
|
|
49
|
+
return Object.keys(carrier).length === 0 ? void 0 : omitUndefined({
|
|
50
|
+
traceparent: carrier.traceparent,
|
|
51
|
+
tracestate: carrier.tracestate
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async withRunExecution(telemetryContext, callback) {
|
|
55
|
+
const parent = contextFromTraceContext(telemetryContext.traceContext);
|
|
56
|
+
return await this.#tracer.startActiveSpan(this.#runExecutionSpanName(telemetryContext), { attributes: this.#attributes({
|
|
57
|
+
[WORKFLOW_ATTRIBUTES.workflowName]: telemetryContext.run.workflowName,
|
|
58
|
+
[WORKFLOW_ATTRIBUTES.workflowVersion]: telemetryContext.run.workflowVersion,
|
|
59
|
+
[WORKFLOW_ATTRIBUTES.runId]: telemetryContext.run.id,
|
|
60
|
+
[WORKFLOW_ATTRIBUTES.namespace]: telemetryContext.run.namespace,
|
|
61
|
+
[WORKFLOW_ATTRIBUTES.runAttempt]: telemetryContext.run.attempts,
|
|
62
|
+
[WORKFLOW_ATTRIBUTES.workerId]: telemetryContext.run.workerId
|
|
63
|
+
}) }, parent, (span) => withSpanStatus(span, callback, { onSuccess: (result) => recordResultOnSpan(span, result) }));
|
|
64
|
+
}
|
|
65
|
+
async withStepExecution(telemetryContext, callback) {
|
|
66
|
+
return await this.#tracer.startActiveSpan(this.#stepExecutionSpanName(telemetryContext), { attributes: this.#attributes({
|
|
67
|
+
[WORKFLOW_ATTRIBUTES.workflowName]: telemetryContext.run.workflowName,
|
|
68
|
+
[WORKFLOW_ATTRIBUTES.workflowVersion]: telemetryContext.run.workflowVersion,
|
|
69
|
+
[WORKFLOW_ATTRIBUTES.runId]: telemetryContext.run.id,
|
|
70
|
+
[WORKFLOW_ATTRIBUTES.stepId]: telemetryContext.step.id,
|
|
71
|
+
[WORKFLOW_ATTRIBUTES.stepName]: telemetryContext.step.name,
|
|
72
|
+
[WORKFLOW_ATTRIBUTES.stepKind]: telemetryContext.step.kind,
|
|
73
|
+
[WORKFLOW_ATTRIBUTES.stepAttempt]: telemetryContext.attempt,
|
|
74
|
+
[WORKFLOW_ATTRIBUTES.stepTimeoutAt]: telemetryContext.timeoutAt === void 0 ? void 0 : telemetryContext.timeoutAt.toString()
|
|
75
|
+
}) }, (span) => withSpanStatus(span, callback));
|
|
76
|
+
}
|
|
77
|
+
async withStorageOperation(telemetryContext, callback) {
|
|
78
|
+
const startedAt = Date.now();
|
|
79
|
+
const attributes = this.#attributes({
|
|
80
|
+
[WORKFLOW_ATTRIBUTES.storageOperation]: telemetryContext.operation,
|
|
81
|
+
[WORKFLOW_ATTRIBUTES.storageBackend]: telemetryContext.backend
|
|
82
|
+
});
|
|
83
|
+
if (this.#options.includeStorageOperationSpans === false) try {
|
|
84
|
+
const result = await callback();
|
|
85
|
+
this.#recordStorageOperationResult(startedAt, attributes, "success");
|
|
86
|
+
return result;
|
|
87
|
+
} catch (error) {
|
|
88
|
+
this.#recordStorageOperationResult(startedAt, attributes, "failure");
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
return await this.#tracer.startActiveSpan(WORKFLOW_SPAN_NAMES.storageOperation, { attributes }, async (span) => {
|
|
92
|
+
const record = (status) => {
|
|
93
|
+
this.#recordStorageOperationResult(startedAt, attributes, status);
|
|
94
|
+
span.setAttribute(WORKFLOW_ATTRIBUTES.storageOperationStatus, status);
|
|
95
|
+
};
|
|
96
|
+
return await withSpanStatus(span, callback, {
|
|
97
|
+
onSuccess: () => {
|
|
98
|
+
record("success");
|
|
99
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
100
|
+
},
|
|
101
|
+
onFailure: () => record("failure")
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
recordRunExecution(telemetryContext) {
|
|
106
|
+
const result = telemetryContext.result;
|
|
107
|
+
if (result?.kind === "completed" || result?.kind === "failed") {
|
|
108
|
+
const duration = optionalDurationBetweenMilliseconds(result.run.startedAt ?? result.run.createdAt, result.run.finishedAt);
|
|
109
|
+
if (duration !== void 0) this.#metrics.runDuration.record(duration, this.#attributes({
|
|
110
|
+
[WORKFLOW_ATTRIBUTES.workflowName]: result.run.workflowName,
|
|
111
|
+
[WORKFLOW_ATTRIBUTES.workflowVersion]: result.run.workflowVersion,
|
|
112
|
+
[WORKFLOW_ATTRIBUTES.runStatus]: result.run.status
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
observe(...[name, event]) {
|
|
117
|
+
switch (name) {
|
|
118
|
+
case "workflow:run-created":
|
|
119
|
+
case "workflow:run-waiting":
|
|
120
|
+
case "workflow:run-rescheduled":
|
|
121
|
+
case "workflow:run-manual-retry":
|
|
122
|
+
case "workflow:run-completed":
|
|
123
|
+
case "workflow:run-canceled":
|
|
124
|
+
this.#recordRunTransition(event);
|
|
125
|
+
break;
|
|
126
|
+
case "workflow:run-failed":
|
|
127
|
+
this.#recordRunTransition(event);
|
|
128
|
+
this.#recordRetryExhausted(event);
|
|
129
|
+
break;
|
|
130
|
+
case "workflow:run-permanently-failed":
|
|
131
|
+
this.#recordRunTransition(event);
|
|
132
|
+
this.#recordRetryExhausted(event);
|
|
133
|
+
break;
|
|
134
|
+
case "workflow:run-claimed": {
|
|
135
|
+
this.#recordRunTransition(event);
|
|
136
|
+
const attributes = this.#runMetricAttributes(event, { [WORKFLOW_ATTRIBUTES.workerOperation]: event.reason });
|
|
137
|
+
this.#metrics.workerClaims.add(1, attributes);
|
|
138
|
+
const startedAt = event.previousRun?.availableAt ?? event.run.availableAt ?? event.run.createdAt;
|
|
139
|
+
const latency = optionalDurationBetweenMilliseconds(startedAt, event.timestamp);
|
|
140
|
+
if (latency !== void 0) this.#metrics.pendingToClaimedLatency.record(latency, attributes);
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
case "workflow:run-started": {
|
|
144
|
+
this.#recordRunTransition(event);
|
|
145
|
+
if (event.previousRun?.status !== "waiting") break;
|
|
146
|
+
const startedAt = event.previousRun.availableAt ?? event.previousRun.lastTransitionAt;
|
|
147
|
+
const latency = optionalDurationBetweenMilliseconds(startedAt, event.timestamp);
|
|
148
|
+
if (latency !== void 0) this.#metrics.waitingToResumedLatency.record(latency, this.#runMetricAttributes(event));
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
case "workflow:run-lease-released":
|
|
152
|
+
this.#recordRunTransition(event);
|
|
153
|
+
this.#metrics.workerLeaseReleases.add(1, this.#runMetricAttributes(event));
|
|
154
|
+
break;
|
|
155
|
+
case "workflow:run-retrying": {
|
|
156
|
+
this.#recordRunTransition(event);
|
|
157
|
+
const attributes = event.run.retryReason === void 0 ? this.#runMetricAttributes(event) : this.#runMetricAttributes(event, { [WORKFLOW_ATTRIBUTES.retryReason]: event.run.retryReason });
|
|
158
|
+
this.#metrics.retryScheduled.add(1, attributes);
|
|
159
|
+
const delay = optionalDurationBetweenMilliseconds(event.timestamp, event.run.retryAt);
|
|
160
|
+
if (delay !== void 0) this.#metrics.retryDelay.record(delay, attributes);
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
case "workflow:durable-event-appended": {
|
|
164
|
+
const descriptor = getEventDescriptor(event.event.kind);
|
|
165
|
+
this.#metrics.eventsAppended.add(1, this.#attributes({
|
|
166
|
+
[WORKFLOW_ATTRIBUTES.eventKind]: descriptor.kind,
|
|
167
|
+
[WORKFLOW_ATTRIBUTES.eventCategory]: descriptor.category
|
|
168
|
+
}));
|
|
169
|
+
const history = new History(event.events);
|
|
170
|
+
this.#spans.recordDurableEventLatency(event, history);
|
|
171
|
+
this.#spans.recordDurableSleepSpan(event, history);
|
|
172
|
+
this.#spans.recordChildWorkflowOperationSpan(event, history);
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
case "workflow:step-attempt-updated": {
|
|
176
|
+
const attributes = this.#attributes({
|
|
177
|
+
[WORKFLOW_ATTRIBUTES.stepKind]: event.attempt.kind,
|
|
178
|
+
[WORKFLOW_ATTRIBUTES.stepStatus]: event.attempt.status,
|
|
179
|
+
[WORKFLOW_ATTRIBUTES.stepName]: this.#options.includeStepNameMetricAttribute ? event.attempt.stepName : void 0
|
|
180
|
+
});
|
|
181
|
+
this.#metrics.stepAttempts.add(1, attributes);
|
|
182
|
+
if (event.attempt.status === "completed" || event.attempt.status === "failed") {
|
|
183
|
+
const duration = optionalDurationBetweenMilliseconds(event.attempt.startedAt, event.attempt.finishedAt);
|
|
184
|
+
if (duration !== void 0) this.#metrics.stepDuration.record(duration, attributes);
|
|
185
|
+
}
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
case "workflow:message-sent":
|
|
189
|
+
this.#metrics.messagesSent.add(1, this.#attributes({}));
|
|
190
|
+
this.#spans.recordMessageSentSpan(event);
|
|
191
|
+
break;
|
|
192
|
+
case "workflow:hook-resumed":
|
|
193
|
+
this.#metrics.hooksResumed.add(1, this.#attributes({ [WORKFLOW_ATTRIBUTES.hookKind]: "hook" }));
|
|
194
|
+
this.#spans.recordHookResumeSpan("hook", event);
|
|
195
|
+
break;
|
|
196
|
+
case "workflow:webhook-resumed":
|
|
197
|
+
this.#metrics.hooksResumed.add(1, this.#attributes({ [WORKFLOW_ATTRIBUTES.hookKind]: "webhook" }));
|
|
198
|
+
this.#spans.recordHookResumeSpan("webhook", event);
|
|
199
|
+
break;
|
|
200
|
+
case "workflow:stream-updated":
|
|
201
|
+
this.#metrics.streamUpdates.add(1, this.#attributes({
|
|
202
|
+
[WORKFLOW_ATTRIBUTES.streamEventKind]: event.eventKind,
|
|
203
|
+
[WORKFLOW_ATTRIBUTES.streamStatus]: streamStatusFromEventKind(event.eventKind)
|
|
204
|
+
}));
|
|
205
|
+
this.#spans.recordStreamOperationSpan(event);
|
|
206
|
+
break;
|
|
207
|
+
case "workflow:child-workflow-started":
|
|
208
|
+
this.#spans.recordChildWorkflowStartedSpan(event);
|
|
209
|
+
break;
|
|
210
|
+
case "workflow:cleanup-completed":
|
|
211
|
+
this.#metrics.cleanupDeletedRuns.add(event.result.deletedRuns, this.#attributes({ [WORKFLOW_ATTRIBUTES.cleanupSource]: "cleanup" }));
|
|
212
|
+
this.#spans.recordCleanupOperationSpan("cleanup", event);
|
|
213
|
+
break;
|
|
214
|
+
case "workflow:retention-applied":
|
|
215
|
+
this.#metrics.cleanupDeletedRuns.add(event.result.deletedRuns, this.#attributes({ [WORKFLOW_ATTRIBUTES.cleanupSource]: "retention" }));
|
|
216
|
+
this.#spans.recordCleanupOperationSpan("retention", event);
|
|
217
|
+
break;
|
|
218
|
+
case "workflow:worker-operation": {
|
|
219
|
+
const attributes = this.#attributes({
|
|
220
|
+
[WORKFLOW_ATTRIBUTES.workerOperation]: event.operation,
|
|
221
|
+
[WORKFLOW_ATTRIBUTES.workerOperationStatus]: event.status
|
|
222
|
+
});
|
|
223
|
+
if (event.operation === "claim" && event.status === "failure") this.#metrics.workerClaimFailures.add(1, attributes);
|
|
224
|
+
if (event.operation === "heartbeat" && event.status === "failure") this.#metrics.workerHeartbeatFailures.add(1, attributes);
|
|
225
|
+
if (event.operation === "lease_extension") this.#metrics.workerLeaseExtensions.add(1, attributes);
|
|
226
|
+
if (event.operation === "lease_release") this.#metrics.workerLeaseReleases.add(1, attributes);
|
|
227
|
+
this.#spans.recordWorkerOperationSpan(event);
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
case "workflow:schedule-ticked":
|
|
231
|
+
this.#spans.recordScheduleTickSpan(event);
|
|
232
|
+
break;
|
|
233
|
+
case "workflow:schedule-run-created": {
|
|
234
|
+
const attributes = this.#attributes({
|
|
235
|
+
[WORKFLOW_ATTRIBUTES.workflowName]: event.workflowName,
|
|
236
|
+
[WORKFLOW_ATTRIBUTES.workflowVersion]: event.workflowVersion
|
|
237
|
+
});
|
|
238
|
+
const latency = optionalDurationBetweenMilliseconds(event.fireAt, event.timestamp);
|
|
239
|
+
if (latency !== void 0) this.#metrics.scheduleDueToRunCreatedLatency.record(latency, attributes);
|
|
240
|
+
this.#spans.recordScheduleRunCreatedSpan(event);
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
bindEngine(engine) {
|
|
246
|
+
this.#engine = engine;
|
|
247
|
+
}
|
|
248
|
+
async shutdown() {
|
|
249
|
+
const errors = [];
|
|
250
|
+
try {
|
|
251
|
+
await this.#options.forceFlush?.();
|
|
252
|
+
} catch (error) {
|
|
253
|
+
errors.push(error);
|
|
254
|
+
}
|
|
255
|
+
try {
|
|
256
|
+
await this.#options.shutdown?.();
|
|
257
|
+
} catch (error) {
|
|
258
|
+
errors.push(error);
|
|
259
|
+
}
|
|
260
|
+
if (errors.length > 0) throw errors[0];
|
|
261
|
+
}
|
|
262
|
+
#recordRunTransition(event) {
|
|
263
|
+
this.#metrics.runTransitions.add(1, this.#runMetricAttributes(event));
|
|
264
|
+
}
|
|
265
|
+
#recordRetryExhausted(event) {
|
|
266
|
+
const retryReason = event.previousRun?.retryReason ?? ((event.previousRun?.attempts ?? event.run.attempts ?? 1) > 1 ? "workflow" : void 0);
|
|
267
|
+
if (retryReason === void 0) return;
|
|
268
|
+
this.#metrics.retryExhausted.add(1, this.#runMetricAttributes(event, {
|
|
269
|
+
[WORKFLOW_ATTRIBUTES.retryReason]: retryReason,
|
|
270
|
+
[WORKFLOW_ATTRIBUTES.retryExhausted]: true
|
|
271
|
+
}));
|
|
272
|
+
}
|
|
273
|
+
#attributes(attributes) {
|
|
274
|
+
return omitUndefined({
|
|
275
|
+
"service.namespace": this.#options.serviceNamespace,
|
|
276
|
+
[WORKFLOW_ATTRIBUTES.system]: WORKFLOW_SYSTEM,
|
|
277
|
+
...attributes
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
#runExecutionSpanName(telemetryContext) {
|
|
281
|
+
return this.#options.includeNamesInSpanNames === true ? `${WORKFLOW_SPAN_NAMES.runExecution} ${telemetryContext.run.workflowName}` : WORKFLOW_SPAN_NAMES.runExecution;
|
|
282
|
+
}
|
|
283
|
+
#stepExecutionSpanName(telemetryContext) {
|
|
284
|
+
return this.#options.includeNamesInSpanNames === true ? `${WORKFLOW_SPAN_NAMES.stepExecution} ${telemetryContext.step.name}` : WORKFLOW_SPAN_NAMES.stepExecution;
|
|
285
|
+
}
|
|
286
|
+
#recordStorageOperationResult(startedAt, attributes, status) {
|
|
287
|
+
const resultAttributes = {
|
|
288
|
+
...attributes,
|
|
289
|
+
[WORKFLOW_ATTRIBUTES.storageOperationStatus]: status
|
|
290
|
+
};
|
|
291
|
+
this.#metrics.storageOperationDuration.record(Date.now() - startedAt, resultAttributes);
|
|
292
|
+
if (status === "failure") this.#metrics.storageOperationErrors.add(1, resultAttributes);
|
|
293
|
+
}
|
|
294
|
+
#runMetricAttributes(event, attributes = {}) {
|
|
295
|
+
return this.#attributes({
|
|
296
|
+
[WORKFLOW_ATTRIBUTES.workflowName]: event.workflowName,
|
|
297
|
+
[WORKFLOW_ATTRIBUTES.workflowVersion]: event.workflowVersion,
|
|
298
|
+
[WORKFLOW_ATTRIBUTES.runStatus]: event.status,
|
|
299
|
+
[WORKFLOW_ATTRIBUTES.runTransition]: event.reason,
|
|
300
|
+
...attributes
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
//#endregion
|
|
305
|
+
export { createOpenTelemetryTelemetry };
|