@temporalio/core-bridge 1.8.5 → 1.9.0-rc.0

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.
Files changed (196) hide show
  1. package/Cargo.lock +189 -152
  2. package/Cargo.toml +1 -0
  3. package/lib/index.d.ts +17 -44
  4. package/lib/index.js.map +1 -1
  5. package/package.json +3 -4
  6. package/releases/aarch64-apple-darwin/index.node +0 -0
  7. package/releases/aarch64-unknown-linux-gnu/index.node +0 -0
  8. package/releases/x86_64-apple-darwin/index.node +0 -0
  9. package/releases/x86_64-pc-windows-msvc/index.node +0 -0
  10. package/releases/x86_64-unknown-linux-gnu/index.node +0 -0
  11. package/sdk-core/.github/workflows/heavy.yml +4 -0
  12. package/sdk-core/.github/workflows/per-pr.yml +96 -0
  13. package/sdk-core/ARCHITECTURE.md +1 -1
  14. package/sdk-core/Cargo.toml +6 -0
  15. package/sdk-core/README.md +37 -21
  16. package/sdk-core/client/Cargo.toml +6 -3
  17. package/sdk-core/client/src/lib.rs +272 -138
  18. package/sdk-core/client/src/metrics.rs +68 -57
  19. package/sdk-core/client/src/raw.rs +191 -45
  20. package/sdk-core/client/src/retry.rs +20 -0
  21. package/sdk-core/client/src/worker_registry/mod.rs +264 -0
  22. package/sdk-core/client/src/workflow_handle/mod.rs +2 -1
  23. package/sdk-core/core/Cargo.toml +16 -18
  24. package/sdk-core/core/src/core_tests/child_workflows.rs +7 -7
  25. package/sdk-core/core/src/core_tests/mod.rs +1 -0
  26. package/sdk-core/core/src/core_tests/replay_flag.rs +29 -39
  27. package/sdk-core/core/src/core_tests/updates.rs +73 -0
  28. package/sdk-core/core/src/core_tests/workflow_tasks.rs +52 -1
  29. package/sdk-core/core/src/ephemeral_server/mod.rs +34 -11
  30. package/sdk-core/core/src/internal_flags.rs +7 -1
  31. package/sdk-core/core/src/lib.rs +19 -36
  32. package/sdk-core/core/src/protosext/mod.rs +11 -3
  33. package/sdk-core/core/src/protosext/protocol_messages.rs +102 -0
  34. package/sdk-core/core/src/replay/mod.rs +100 -48
  35. package/sdk-core/core/src/telemetry/log_export.rs +161 -28
  36. package/sdk-core/core/src/telemetry/metrics.rs +869 -248
  37. package/sdk-core/core/src/telemetry/mod.rs +135 -239
  38. package/sdk-core/core/src/telemetry/prometheus_server.rs +36 -31
  39. package/sdk-core/core/src/test_help/mod.rs +63 -4
  40. package/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +12 -2
  41. package/sdk-core/core/src/worker/activities.rs +276 -10
  42. package/sdk-core/core/src/worker/client/mocks.rs +18 -0
  43. package/sdk-core/core/src/worker/client.rs +16 -3
  44. package/sdk-core/core/src/worker/mod.rs +50 -19
  45. package/sdk-core/core/src/worker/slot_provider.rs +175 -0
  46. package/sdk-core/core/src/worker/workflow/driven_workflow.rs +27 -34
  47. package/sdk-core/core/src/worker/workflow/history_update.rs +4 -1
  48. package/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +36 -94
  49. package/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +34 -22
  50. package/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +50 -34
  51. package/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +106 -92
  52. package/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +22 -21
  53. package/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +386 -499
  54. package/sdk-core/core/src/worker/workflow/machines/mod.rs +12 -2
  55. package/sdk-core/core/src/worker/workflow/machines/modify_workflow_properties_state_machine.rs +33 -26
  56. package/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +198 -215
  57. package/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +66 -62
  58. package/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +88 -119
  59. package/sdk-core/core/src/worker/workflow/machines/transition_coverage.rs +3 -1
  60. package/sdk-core/core/src/worker/workflow/machines/update_state_machine.rs +411 -0
  61. package/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +26 -25
  62. package/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +302 -85
  63. package/sdk-core/core/src/worker/workflow/managed_run.rs +179 -132
  64. package/sdk-core/core/src/worker/workflow/mod.rs +121 -46
  65. package/sdk-core/core/src/worker/workflow/run_cache.rs +8 -12
  66. package/sdk-core/core/src/worker/workflow/workflow_stream.rs +45 -38
  67. package/sdk-core/core-api/Cargo.toml +7 -6
  68. package/sdk-core/core-api/src/lib.rs +4 -12
  69. package/sdk-core/core-api/src/telemetry/metrics.rs +334 -0
  70. package/sdk-core/core-api/src/telemetry.rs +53 -42
  71. package/sdk-core/core-api/src/worker.rs +7 -0
  72. package/sdk-core/{.buildkite/docker → docker}/docker-compose.yaml +1 -1
  73. package/sdk-core/etc/dynamic-config.yaml +11 -1
  74. package/sdk-core/fsm/rustfsm_procmacro/Cargo.toml +1 -1
  75. package/sdk-core/fsm/rustfsm_procmacro/src/lib.rs +1 -3
  76. package/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.stderr +2 -2
  77. package/sdk-core/sdk/Cargo.toml +1 -1
  78. package/sdk-core/sdk/src/lib.rs +85 -7
  79. package/sdk-core/sdk/src/workflow_context/options.rs +4 -0
  80. package/sdk-core/sdk/src/workflow_context.rs +43 -15
  81. package/sdk-core/sdk/src/workflow_future.rs +334 -204
  82. package/sdk-core/sdk-core-protos/Cargo.toml +2 -2
  83. package/sdk-core/sdk-core-protos/build.rs +14 -14
  84. package/sdk-core/sdk-core-protos/protos/api_upstream/.buildkite/Dockerfile +2 -0
  85. package/sdk-core/sdk-core-protos/protos/api_upstream/Makefile +99 -0
  86. package/sdk-core/sdk-core-protos/protos/api_upstream/api-linter.yaml +56 -0
  87. package/sdk-core/sdk-core-protos/protos/api_upstream/buf.gen.yaml +20 -0
  88. package/sdk-core/sdk-core-protos/protos/api_upstream/buf.lock +11 -0
  89. package/sdk-core/sdk-core-protos/protos/api_upstream/buf.yaml +18 -0
  90. package/sdk-core/sdk-core-protos/protos/api_upstream/google/api/annotations.proto +31 -0
  91. package/sdk-core/sdk-core-protos/protos/api_upstream/google/api/http.proto +379 -0
  92. package/sdk-core/sdk-core-protos/protos/api_upstream/google/protobuf/any.proto +162 -0
  93. package/sdk-core/sdk-core-protos/protos/api_upstream/google/protobuf/descriptor.proto +1212 -0
  94. package/sdk-core/sdk-core-protos/protos/api_upstream/google/protobuf/duration.proto +115 -0
  95. package/sdk-core/sdk-core-protos/protos/api_upstream/google/protobuf/empty.proto +51 -0
  96. package/sdk-core/sdk-core-protos/protos/api_upstream/google/protobuf/timestamp.proto +144 -0
  97. package/sdk-core/sdk-core-protos/protos/api_upstream/google/protobuf/wrappers.proto +123 -0
  98. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/batch/v1/message.proto +3 -5
  99. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/command/v1/message.proto +11 -13
  100. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/common/v1/message.proto +2 -4
  101. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/enums/v1/failed_cause.proto +2 -0
  102. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/enums/v1/reset.proto +1 -1
  103. package/sdk-core/{protos/api_upstream/build/tools.go → sdk-core-protos/protos/api_upstream/temporal/api/export/v1/message.proto} +22 -6
  104. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/filter/v1/message.proto +2 -4
  105. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/history/v1/message.proto +21 -23
  106. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/namespace/v1/message.proto +2 -4
  107. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/operatorservice/v1/request_response.proto +2 -0
  108. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/operatorservice/v1/service.proto +4 -0
  109. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/replication/v1/message.proto +1 -3
  110. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/schedule/v1/message.proto +36 -20
  111. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/sdk/v1/task_complete_metadata.proto +13 -0
  112. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/taskqueue/v1/message.proto +2 -4
  113. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/update/v1/message.proto +1 -1
  114. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/version/v1/message.proto +2 -3
  115. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/workflow/v1/message.proto +18 -20
  116. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/workflowservice/v1/request_response.proto +84 -32
  117. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/workflowservice/v1/service.proto +205 -47
  118. package/sdk-core/{protos → sdk-core-protos/protos}/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +57 -0
  119. package/sdk-core/{protos → sdk-core-protos/protos}/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +27 -0
  120. package/sdk-core/sdk-core-protos/src/history_builder.rs +67 -2
  121. package/sdk-core/sdk-core-protos/src/lib.rs +75 -2
  122. package/sdk-core/sdk-core-protos/src/utilities.rs +14 -0
  123. package/sdk-core/test-utils/Cargo.toml +5 -1
  124. package/sdk-core/test-utils/src/canned_histories.rs +3 -57
  125. package/sdk-core/test-utils/src/interceptors.rs +46 -0
  126. package/sdk-core/test-utils/src/lib.rs +106 -38
  127. package/sdk-core/tests/integ_tests/metrics_tests.rs +110 -15
  128. package/sdk-core/tests/integ_tests/queries_tests.rs +174 -3
  129. package/sdk-core/tests/integ_tests/update_tests.rs +908 -0
  130. package/sdk-core/tests/integ_tests/workflow_tests/activities.rs +44 -1
  131. package/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +1 -1
  132. package/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +1 -1
  133. package/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +4 -4
  134. package/sdk-core/tests/integ_tests/workflow_tests/eager.rs +61 -0
  135. package/sdk-core/tests/integ_tests/workflow_tests/replay.rs +27 -2
  136. package/sdk-core/tests/integ_tests/workflow_tests.rs +1 -0
  137. package/sdk-core/tests/main.rs +2 -1
  138. package/sdk-core/tests/runner.rs +15 -2
  139. package/src/conversions.rs +75 -89
  140. package/src/helpers.rs +74 -0
  141. package/src/runtime.rs +17 -6
  142. package/src/worker.rs +14 -61
  143. package/ts/index.ts +21 -52
  144. package/sdk-core/.buildkite/docker/Dockerfile +0 -9
  145. package/sdk-core/.buildkite/docker/build.sh +0 -5
  146. package/sdk-core/.buildkite/docker/docker-compose-ci.yaml +0 -27
  147. package/sdk-core/.buildkite/pipeline.yml +0 -57
  148. package/sdk-core/.github/workflows/semgrep.yml +0 -25
  149. package/sdk-core/core/src/worker/workflow/bridge.rs +0 -35
  150. package/sdk-core/core/src/worker/workflow/managed_run/managed_wf_test.rs +0 -215
  151. package/sdk-core/protos/api_upstream/.buildkite/Dockerfile +0 -2
  152. package/sdk-core/protos/api_upstream/Makefile +0 -80
  153. package/sdk-core/protos/api_upstream/api-linter.yaml +0 -40
  154. package/sdk-core/protos/api_upstream/buf.yaml +0 -9
  155. package/sdk-core/protos/api_upstream/build/go.mod +0 -7
  156. package/sdk-core/protos/api_upstream/build/go.sum +0 -5
  157. package/sdk-core/protos/api_upstream/go.mod +0 -6
  158. package/sdk-core/protos/testsrv_upstream/dependencies/gogoproto/gogo.proto +0 -141
  159. /package/sdk-core/{.buildkite/docker → docker}/docker-compose-telem.yaml +0 -0
  160. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/.buildkite/docker-compose.yml +0 -0
  161. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/.buildkite/pipeline.yml +0 -0
  162. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/.github/CODEOWNERS +0 -0
  163. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/.github/PULL_REQUEST_TEMPLATE.md +0 -0
  164. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/.github/workflows/publish-docs.yml +0 -0
  165. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/.github/workflows/trigger-api-go-update.yml +0 -0
  166. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/LICENSE +0 -0
  167. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/README.md +0 -0
  168. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/enums/v1/batch_operation.proto +0 -0
  169. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/enums/v1/command_type.proto +0 -0
  170. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/enums/v1/common.proto +0 -0
  171. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/enums/v1/event_type.proto +0 -0
  172. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/enums/v1/namespace.proto +0 -0
  173. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/enums/v1/query.proto +0 -0
  174. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/enums/v1/schedule.proto +0 -0
  175. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/enums/v1/task_queue.proto +0 -0
  176. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/enums/v1/update.proto +0 -0
  177. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/enums/v1/workflow.proto +0 -0
  178. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/errordetails/v1/message.proto +0 -0
  179. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/failure/v1/message.proto +0 -0
  180. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/protocol/v1/message.proto +0 -0
  181. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/query/v1/message.proto +0 -0
  182. /package/sdk-core/{protos → sdk-core-protos/protos}/google/rpc/status.proto +0 -0
  183. /package/sdk-core/{protos → sdk-core-protos/protos}/grpc/health/v1/health.proto +0 -0
  184. /package/sdk-core/{protos → sdk-core-protos/protos}/local/temporal/sdk/core/activity_result/activity_result.proto +0 -0
  185. /package/sdk-core/{protos → sdk-core-protos/protos}/local/temporal/sdk/core/activity_task/activity_task.proto +0 -0
  186. /package/sdk-core/{protos → sdk-core-protos/protos}/local/temporal/sdk/core/child_workflow/child_workflow.proto +0 -0
  187. /package/sdk-core/{protos → sdk-core-protos/protos}/local/temporal/sdk/core/common/common.proto +0 -0
  188. /package/sdk-core/{protos → sdk-core-protos/protos}/local/temporal/sdk/core/core_interface.proto +0 -0
  189. /package/sdk-core/{protos → sdk-core-protos/protos}/local/temporal/sdk/core/external_data/external_data.proto +0 -0
  190. /package/sdk-core/{protos → sdk-core-protos/protos}/local/temporal/sdk/core/workflow_completion/workflow_completion.proto +0 -0
  191. /package/sdk-core/{protos → sdk-core-protos/protos}/testsrv_upstream/Makefile +0 -0
  192. /package/sdk-core/{protos → sdk-core-protos/protos}/testsrv_upstream/api-linter.yaml +0 -0
  193. /package/sdk-core/{protos → sdk-core-protos/protos}/testsrv_upstream/buf.yaml +0 -0
  194. /package/sdk-core/{protos/api_upstream → sdk-core-protos/protos/testsrv_upstream}/dependencies/gogoproto/gogo.proto +0 -0
  195. /package/sdk-core/{protos → sdk-core-protos/protos}/testsrv_upstream/temporal/api/testservice/v1/request_response.proto +0 -0
  196. /package/sdk-core/{protos → sdk-core-protos/protos}/testsrv_upstream/temporal/api/testservice/v1/service.proto +0 -0
@@ -0,0 +1,334 @@
1
+ use std::{
2
+ any::Any,
3
+ borrow::Cow,
4
+ fmt::Debug,
5
+ sync::{Arc, OnceLock},
6
+ };
7
+
8
+ /// Implementors of this trait are expected to be defined in each language's bridge.
9
+ /// The implementor is responsible for the allocation/instantiation of new metric meters which
10
+ /// Core has requested.
11
+ pub trait CoreMeter: Send + Sync + Debug {
12
+ /// Given some k/v pairs, create a return a new instantiated instance of metric attributes.
13
+ /// Only [MetricAttributes] created by this meter can be used when calling record on instruments
14
+ /// created by this meter.
15
+ fn new_attributes(&self, attribs: NewAttributes) -> MetricAttributes;
16
+ /// Extend some existing attributes with new values. Implementations should create new instances
17
+ /// when doing so, rather than mutating whatever is backing the passed in `existing` attributes.
18
+ /// Ideally that new instance retains a ref to the extended old attribute, promoting re-use.
19
+ fn extend_attributes(
20
+ &self,
21
+ existing: MetricAttributes,
22
+ attribs: NewAttributes,
23
+ ) -> MetricAttributes;
24
+ fn counter(&self, params: MetricParameters) -> Arc<dyn Counter>;
25
+ fn histogram(&self, params: MetricParameters) -> Arc<dyn Histogram>;
26
+ fn gauge(&self, params: MetricParameters) -> Arc<dyn Gauge>;
27
+ }
28
+
29
+ #[derive(Debug, Clone, derive_builder::Builder)]
30
+ pub struct MetricParameters {
31
+ /// The name for the new metric/instrument
32
+ #[builder(setter(into))]
33
+ pub name: Cow<'static, str>,
34
+ /// A description that will appear in metadata if the backend supports it
35
+ #[builder(setter(into), default = "\"\".into()")]
36
+ pub description: Cow<'static, str>,
37
+ /// Unit information that will appear in metadata if the backend supports it
38
+ #[builder(setter(into), default = "\"\".into()")]
39
+ pub unit: Cow<'static, str>,
40
+ }
41
+ impl From<&'static str> for MetricParameters {
42
+ fn from(value: &'static str) -> Self {
43
+ Self {
44
+ name: value.into(),
45
+ description: Default::default(),
46
+ unit: Default::default(),
47
+ }
48
+ }
49
+ }
50
+
51
+ /// Wraps a [CoreMeter] to enable the attaching of default labels to metrics. Cloning is cheap.
52
+ #[derive(derive_more::Constructor, Clone, Debug)]
53
+ pub struct TemporalMeter {
54
+ pub inner: Arc<dyn CoreMeter>,
55
+ pub default_attribs: NewAttributes,
56
+ }
57
+
58
+ impl CoreMeter for Arc<dyn CoreMeter> {
59
+ fn new_attributes(&self, attribs: NewAttributes) -> MetricAttributes {
60
+ self.as_ref().new_attributes(attribs)
61
+ }
62
+
63
+ fn extend_attributes(
64
+ &self,
65
+ existing: MetricAttributes,
66
+ attribs: NewAttributes,
67
+ ) -> MetricAttributes {
68
+ self.as_ref().extend_attributes(existing, attribs)
69
+ }
70
+
71
+ fn counter(&self, params: MetricParameters) -> Arc<dyn Counter> {
72
+ self.as_ref().counter(params)
73
+ }
74
+ fn histogram(&self, params: MetricParameters) -> Arc<dyn Histogram> {
75
+ self.as_ref().histogram(params)
76
+ }
77
+ fn gauge(&self, params: MetricParameters) -> Arc<dyn Gauge> {
78
+ self.as_ref().gauge(params)
79
+ }
80
+ }
81
+
82
+ /// Attributes which are provided every time a call to record a specific metric is made.
83
+ /// Implementors must be very cheap to clone, as these attributes will be re-used frequently.
84
+ #[derive(Clone, Debug)]
85
+ #[non_exhaustive]
86
+ pub enum MetricAttributes {
87
+ #[cfg(feature = "otel_impls")]
88
+ OTel {
89
+ kvs: Arc<Vec<opentelemetry::KeyValue>>,
90
+ },
91
+ Buffer(BufferAttributes),
92
+ Dynamic(Arc<dyn CustomMetricAttributes>),
93
+ }
94
+
95
+ /// A reference to some attributes created lang side.
96
+ pub trait CustomMetricAttributes: Debug + Send + Sync {
97
+ /// Must be implemented to work around existing type system restrictions, see
98
+ /// [here](https://internals.rust-lang.org/t/downcast-not-from-any-but-from-any-trait/16736/12)
99
+ fn as_any(self: Arc<Self>) -> Arc<dyn Any + Send + Sync>;
100
+ }
101
+
102
+ /// Options that are attached to metrics on a per-call basis
103
+ #[derive(Clone, Debug, Default, derive_more::Constructor)]
104
+ pub struct NewAttributes {
105
+ pub attributes: Vec<MetricKeyValue>,
106
+ }
107
+ impl NewAttributes {
108
+ pub fn extend(&mut self, new_kvs: impl IntoIterator<Item = MetricKeyValue>) {
109
+ self.attributes.extend(new_kvs)
110
+ }
111
+ }
112
+ impl<I> From<I> for NewAttributes
113
+ where
114
+ I: IntoIterator<Item = MetricKeyValue>,
115
+ {
116
+ fn from(value: I) -> Self {
117
+ Self {
118
+ attributes: value.into_iter().collect(),
119
+ }
120
+ }
121
+ }
122
+
123
+ /// A K/V pair that can be used to label a specific recording of a metric
124
+ #[derive(Clone, Debug)]
125
+ pub struct MetricKeyValue {
126
+ pub key: String,
127
+ pub value: MetricValue,
128
+ }
129
+ impl MetricKeyValue {
130
+ pub fn new(key: impl Into<String>, value: impl Into<MetricValue>) -> Self {
131
+ Self {
132
+ key: key.into(),
133
+ value: value.into(),
134
+ }
135
+ }
136
+ }
137
+
138
+ /// Values metric labels may assume
139
+ #[derive(Clone, Debug, derive_more::From)]
140
+ pub enum MetricValue {
141
+ String(String),
142
+ Int(i64),
143
+ Float(f64),
144
+ Bool(bool),
145
+ // can add array if needed
146
+ }
147
+ impl From<&'static str> for MetricValue {
148
+ fn from(value: &'static str) -> Self {
149
+ MetricValue::String(value.to_string())
150
+ }
151
+ }
152
+
153
+ pub trait Counter: Send + Sync {
154
+ fn add(&self, value: u64, attributes: &MetricAttributes);
155
+ }
156
+
157
+ pub trait Histogram: Send + Sync {
158
+ // When referring to durations, this value is in millis
159
+ fn record(&self, value: u64, attributes: &MetricAttributes);
160
+ }
161
+
162
+ pub trait Gauge: Send + Sync {
163
+ // When referring to durations, this value is in millis
164
+ fn record(&self, value: u64, attributes: &MetricAttributes);
165
+ }
166
+
167
+ #[derive(Debug, Clone)]
168
+ pub enum MetricEvent<I: BufferInstrumentRef> {
169
+ Create {
170
+ params: MetricParameters,
171
+ /// One you receive this event, call `set` on this with the initialized instrument reference
172
+ populate_into: LazyBufferInstrument<I>,
173
+ kind: MetricKind,
174
+ },
175
+ CreateAttributes {
176
+ /// One you receive this event, call `set` on this with the initialized attributes
177
+ populate_into: BufferAttributes,
178
+ /// If not `None`, use these already-initialized attributes as the base (extended with
179
+ /// `attributes`) for the ones you are about to initialize.
180
+ append_from: Option<BufferAttributes>,
181
+ attributes: Vec<MetricKeyValue>,
182
+ },
183
+ Update {
184
+ instrument: LazyBufferInstrument<I>,
185
+ attributes: BufferAttributes,
186
+ update: MetricUpdateVal,
187
+ },
188
+ }
189
+ #[derive(Debug, Clone, Copy)]
190
+ pub enum MetricKind {
191
+ Counter,
192
+ Gauge,
193
+ Histogram,
194
+ }
195
+ #[derive(Debug, Clone, Copy)]
196
+ pub enum MetricUpdateVal {
197
+ // Currently all deltas are natural numbers
198
+ Delta(u64),
199
+ // Currently all values are natural numbers
200
+ Value(u64),
201
+ }
202
+
203
+ pub trait MetricCallBufferer<I: BufferInstrumentRef>: Send + Sync {
204
+ fn retrieve(&self) -> Vec<MetricEvent<I>>;
205
+ }
206
+
207
+ /// A lazy reference to some metrics buffer attributes
208
+ pub type BufferAttributes = LazyRef<Arc<dyn CustomMetricAttributes + 'static>>;
209
+
210
+ /// Types lang uses to contain references to its lang-side defined instrument references must
211
+ /// implement this marker trait
212
+ pub trait BufferInstrumentRef {}
213
+ /// A lazy reference to a metrics buffer instrument
214
+ pub type LazyBufferInstrument<T> = LazyRef<Arc<T>>;
215
+
216
+ #[derive(Debug, Clone)]
217
+ pub struct LazyRef<T> {
218
+ to_be_initted: Arc<OnceLock<T>>,
219
+ }
220
+ impl<T> LazyRef<T> {
221
+ pub fn hole() -> Self {
222
+ Self {
223
+ to_be_initted: Arc::new(OnceLock::new()),
224
+ }
225
+ }
226
+
227
+ /// Get the reference you previously initialized
228
+ ///
229
+ /// # Panics
230
+ /// If `set` has not already been called. You must set the reference before using it.
231
+ pub fn get(&self) -> &T {
232
+ self.to_be_initted
233
+ .get()
234
+ .expect("You must initialize the reference before using it")
235
+ }
236
+
237
+ /// Assigns a value to fill this reference.
238
+ /// Returns according to semantics of [OnceLock].
239
+ pub fn set(&self, val: T) -> Result<(), T> {
240
+ self.to_be_initted.set(val)
241
+ }
242
+ }
243
+
244
+ #[derive(Debug)]
245
+ pub struct NoOpCoreMeter;
246
+ impl CoreMeter for NoOpCoreMeter {
247
+ fn new_attributes(&self, _: NewAttributes) -> MetricAttributes {
248
+ MetricAttributes::Dynamic(Arc::new(NoOpAttributes))
249
+ }
250
+
251
+ fn extend_attributes(&self, existing: MetricAttributes, _: NewAttributes) -> MetricAttributes {
252
+ existing
253
+ }
254
+
255
+ fn counter(&self, _: MetricParameters) -> Arc<dyn Counter> {
256
+ Arc::new(NoOpInstrument)
257
+ }
258
+
259
+ fn histogram(&self, _: MetricParameters) -> Arc<dyn Histogram> {
260
+ Arc::new(NoOpInstrument)
261
+ }
262
+
263
+ fn gauge(&self, _: MetricParameters) -> Arc<dyn Gauge> {
264
+ Arc::new(NoOpInstrument)
265
+ }
266
+ }
267
+
268
+ pub struct NoOpInstrument;
269
+ impl Counter for NoOpInstrument {
270
+ fn add(&self, _: u64, _: &MetricAttributes) {}
271
+ }
272
+ impl Histogram for NoOpInstrument {
273
+ fn record(&self, _: u64, _: &MetricAttributes) {}
274
+ }
275
+ impl Gauge for NoOpInstrument {
276
+ fn record(&self, _: u64, _: &MetricAttributes) {}
277
+ }
278
+
279
+ #[derive(Debug, Clone)]
280
+ pub struct NoOpAttributes;
281
+ impl CustomMetricAttributes for NoOpAttributes {
282
+ fn as_any(self: Arc<Self>) -> Arc<dyn Any + Send + Sync> {
283
+ self as Arc<dyn Any + Send + Sync>
284
+ }
285
+ }
286
+
287
+ #[cfg(feature = "otel_impls")]
288
+ mod otel_impls {
289
+ use super::*;
290
+ use opentelemetry::{metrics, KeyValue};
291
+
292
+ impl From<MetricKeyValue> for KeyValue {
293
+ fn from(kv: MetricKeyValue) -> Self {
294
+ KeyValue::new(kv.key, kv.value)
295
+ }
296
+ }
297
+
298
+ impl From<MetricValue> for opentelemetry::Value {
299
+ fn from(mv: MetricValue) -> Self {
300
+ match mv {
301
+ MetricValue::String(s) => opentelemetry::Value::String(s.into()),
302
+ MetricValue::Int(i) => opentelemetry::Value::I64(i),
303
+ MetricValue::Float(f) => opentelemetry::Value::F64(f),
304
+ MetricValue::Bool(b) => opentelemetry::Value::Bool(b),
305
+ }
306
+ }
307
+ }
308
+
309
+ impl Counter for metrics::Counter<u64> {
310
+ fn add(&self, value: u64, attributes: &MetricAttributes) {
311
+ if let MetricAttributes::OTel { kvs } = attributes {
312
+ self.add(value, kvs);
313
+ } else {
314
+ debug_assert!(
315
+ false,
316
+ "Must use OTel attributes with an OTel metric implementation"
317
+ );
318
+ }
319
+ }
320
+ }
321
+
322
+ impl Histogram for metrics::Histogram<u64> {
323
+ fn record(&self, value: u64, attributes: &MetricAttributes) {
324
+ if let MetricAttributes::OTel { kvs } = attributes {
325
+ self.record(value, kvs);
326
+ } else {
327
+ debug_assert!(
328
+ false,
329
+ "Must use OTel attributes with an OTel metric implementation"
330
+ );
331
+ }
332
+ }
333
+ }
334
+ }
@@ -1,11 +1,18 @@
1
+ pub mod metrics;
2
+
3
+ use crate::telemetry::metrics::CoreMeter;
1
4
  use std::{
2
5
  collections::HashMap,
6
+ fmt::Debug,
3
7
  net::SocketAddr,
8
+ sync::Arc,
4
9
  time::{Duration, SystemTime, UNIX_EPOCH},
5
10
  };
6
11
  use tracing_core::Level;
7
12
  use url::Url;
8
13
 
14
+ pub static METRIC_PREFIX: &str = "temporal_";
15
+
9
16
  /// Each core runtime instance has a telemetry subsystem associated with it, this trait defines the
10
17
  /// operations that lang might want to perform on that telemetry after it's initialized.
11
18
  pub trait CoreTelemetry {
@@ -23,32 +30,25 @@ pub trait CoreTelemetry {
23
30
  #[derive(Debug, Clone, derive_builder::Builder)]
24
31
  #[non_exhaustive]
25
32
  pub struct TelemetryOptions {
26
- /// Optional trace exporter - set as None to disable.
27
- #[builder(setter(into, strip_option), default)]
28
- pub tracing: Option<TraceExportConfig>,
29
33
  /// Optional logger - set as None to disable.
30
34
  #[builder(setter(into, strip_option), default)]
31
35
  pub logging: Option<Logger>,
32
36
  /// Optional metrics exporter - set as None to disable.
33
37
  #[builder(setter(into, strip_option), default)]
34
- pub metrics: Option<MetricsExporter>,
35
-
36
- /// If set true, do not prefix metrics with `temporal_`. Will be removed eventually as
37
- /// the prefix is consistent with other SDKs.
38
- #[builder(default)]
39
- pub no_temporal_prefix_for_metrics: bool,
40
-
41
- /// Specifies the aggregation temporality for metric export. Defaults to cumulative.
42
- #[builder(default = "MetricTemporality::Cumulative")]
43
- pub metric_temporality: MetricTemporality,
44
-
45
- // A map of tags to be applied to all metrics
46
- #[builder(default)]
47
- pub global_tags: HashMap<String, String>,
38
+ pub metrics: Option<Arc<dyn CoreMeter>>,
39
+ /// If set true (the default) explicitly attach a `service_name` label to all metrics. Turn this
40
+ /// off if your collection system supports the `target_info` metric from the OpenMetrics spec.
41
+ /// For more, see
42
+ /// [here](https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#supporting-target-metadata-in-both-push-based-and-pull-based-systems)
43
+ #[builder(default = "true")]
44
+ pub attach_service_name: bool,
45
+ /// A prefix to be applied to all core-created metrics. Defaults to "temporal_".
46
+ #[builder(default = "METRIC_PREFIX.to_string()")]
47
+ pub metric_prefix: String,
48
48
  }
49
49
 
50
50
  /// Options for exporting to an OpenTelemetry Collector
51
- #[derive(Debug, Clone)]
51
+ #[derive(Debug, Clone, derive_builder::Builder)]
52
52
  pub struct OtelCollectorOptions {
53
53
  /// The url of the OTel collector to export telemetry and metrics to. Lang SDK should also
54
54
  /// export to this same collector.
@@ -56,32 +56,30 @@ pub struct OtelCollectorOptions {
56
56
  /// Optional set of HTTP headers to send to the Collector, e.g for authentication.
57
57
  pub headers: HashMap<String, String>,
58
58
  /// Optionally specify how frequently metrics should be exported. Defaults to 1 second.
59
- pub metric_periodicity: Option<Duration>,
60
- }
61
-
62
- /// Configuration for the external export of traces
63
- #[derive(Debug, Clone)]
64
- pub struct TraceExportConfig {
65
- /// An [EnvFilter](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/struct.EnvFilter.html) filter string.
66
- pub filter: String,
67
- /// Where they should go
68
- pub exporter: TraceExporter,
69
- }
70
-
71
- /// Control where traces are exported.
72
- #[derive(Debug, Clone)]
73
- pub enum TraceExporter {
74
- /// Export traces to an OpenTelemetry Collector <https://opentelemetry.io/docs/collector/>.
75
- Otel(OtelCollectorOptions),
59
+ #[builder(default = "Duration::from_secs(1)")]
60
+ pub metric_periodicity: Duration,
61
+ /// Specifies the aggregation temporality for metric export. Defaults to cumulative.
62
+ #[builder(default = "MetricTemporality::Cumulative")]
63
+ pub metric_temporality: MetricTemporality,
64
+ // A map of tags to be applied to all metrics
65
+ #[builder(default)]
66
+ pub global_tags: HashMap<String, String>,
76
67
  }
77
68
 
78
- /// Control where metrics are exported
79
- #[derive(Debug, Clone)]
80
- pub enum MetricsExporter {
81
- /// Export metrics to an OpenTelemetry Collector <https://opentelemetry.io/docs/collector/>.
82
- Otel(OtelCollectorOptions),
83
- /// Expose metrics directly via an embedded http server bound to the provided address.
84
- Prometheus(SocketAddr),
69
+ /// Options for exporting metrics to Prometheus
70
+ #[derive(Debug, Clone, derive_builder::Builder)]
71
+ pub struct PrometheusExporterOptions {
72
+ pub socket_addr: SocketAddr,
73
+ // A map of tags to be applied to all metrics
74
+ #[builder(default)]
75
+ pub global_tags: HashMap<String, String>,
76
+ /// If set true, all counters will include a "_total" suffix
77
+ #[builder(default = "false")]
78
+ pub counters_total_suffix: bool,
79
+ /// If set true, all histograms will include the unit in their name as a suffix.
80
+ /// Ex: "_milliseconds".
81
+ #[builder(default = "false")]
82
+ pub unit_suffix: bool,
85
83
  }
86
84
 
87
85
  /// Control where logs go
@@ -97,6 +95,13 @@ pub enum Logger {
97
95
  /// An [EnvFilter](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/struct.EnvFilter.html) filter string.
98
96
  filter: String,
99
97
  },
98
+ // Push logs to Lang. Can used with temporal_sdk_core::telemetry::CoreLogBufferedConsumer to buffer.
99
+ Push {
100
+ /// An [EnvFilter](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/struct.EnvFilter.html) filter string.
101
+ filter: String,
102
+ /// Trait invoked on each log.
103
+ consumer: Arc<dyn CoreLogConsumer>,
104
+ },
100
105
  }
101
106
 
102
107
  /// Types of aggregation temporality for metric export.
@@ -143,3 +148,9 @@ impl CoreLog {
143
148
  .as_millis()
144
149
  }
145
150
  }
151
+
152
+ /// Consumer trait for use with push logger.
153
+ pub trait CoreLogConsumer: Send + Sync + Debug {
154
+ /// Invoked synchronously for every single log.
155
+ fn on_log(&self, log: CoreLog);
156
+ }
@@ -115,6 +115,7 @@ pub struct WorkerConfig {
115
115
  #[builder(default = "5")]
116
116
  pub fetching_concurrency: usize,
117
117
 
118
+ // TODO: Move this out - dependency on tokio should not exist just for this
118
119
  /// If set, and the `save_wf_inputs` feature is enabled in core, will be sent a serialized
119
120
  /// instance of every input to workflow state in order. This is for testing purposes, SDK
120
121
  /// implementations never need to care about it.
@@ -126,6 +127,12 @@ pub struct WorkerConfig {
126
127
  /// initiated and this amount of time has elapsed.
127
128
  #[builder(default)]
128
129
  pub graceful_shutdown_period: Option<Duration>,
130
+
131
+ /// The amount of time core will wait before timing out activities using its own local timers
132
+ /// after one of them elapses. This is to avoid racing with server's own tracking of the
133
+ /// timeout.
134
+ #[builder(default = "Duration::from_secs(5)")]
135
+ pub local_timeout_buffer_for_activities: Duration,
129
136
  }
130
137
 
131
138
  impl WorkerConfig {
@@ -9,7 +9,7 @@ services:
9
9
  # - '9042:9042'
10
10
 
11
11
  temporal:
12
- image: temporalio/auto-setup:1.20.0
12
+ image: temporalio/auto-setup:1.22.0
13
13
  ports:
14
14
  - "7233:7233"
15
15
  - "7234:7234"
@@ -1,2 +1,12 @@
1
1
  system.enableActivityLocalDispatch:
2
- - value: true
2
+ - value: true
3
+ system.enableEagerWorkflowStart:
4
+ - value: true
5
+ frontend.workerVersioningWorkflowAPIs:
6
+ - value: true
7
+ frontend.workerVersioningDataAPIs:
8
+ - value: true
9
+ frontend.enableUpdateWorkflowExecution:
10
+ - value: true
11
+ frontend.enableUpdateWorkflowExecutionAsyncAccepted:
12
+ - value: true
@@ -16,7 +16,7 @@ path = "tests/progress.rs"
16
16
  [dependencies]
17
17
  derive_more = "0.99"
18
18
  proc-macro2 = "1.0"
19
- syn = { version = "1.0", features = ["default", "extra-traits"] }
19
+ syn = { version = "2.0", features = ["default", "extra-traits"] }
20
20
  quote = "1.0"
21
21
  rustfsm_trait = { version = "0.1", path = "../rustfsm_trait" }
22
22
 
@@ -5,7 +5,6 @@ use syn::{
5
5
  parenthesized,
6
6
  parse::{Parse, ParseStream, Result},
7
7
  parse_macro_input,
8
- punctuated::Punctuated,
9
8
  spanned::Spanned,
10
9
  Error, Fields, Ident, Token, Type, Variant, Visibility,
11
10
  };
@@ -212,8 +211,7 @@ impl Parse for StateMachineDefinition {
212
211
  })?;
213
212
  // Then the state machine definition is simply a sequence of transitions separated by
214
213
  // semicolons
215
- let transitions: Punctuated<Transition, Token![;]> =
216
- input.parse_terminated(Transition::parse)?;
214
+ let transitions = input.parse_terminated(Transition::parse, Token![;])?;
217
215
  let transitions: Vec<_> = transitions.into_iter().collect();
218
216
  // Check for and whine about any identical transitions. We do this here because preserving
219
217
  // the order transitions were defined in is important, so simply collecting to a set is
@@ -1,8 +1,8 @@
1
1
  error[E0277]: the trait bound `One: From<Two>` is not satisfied
2
- --> tests/trybuild/no_handle_conversions_require_into_fail.rs:11:18
2
+ --> tests/trybuild/no_handle_conversions_require_into_fail.rs:11:5
3
3
  |
4
4
  11 | Two --(B)--> One;
5
- | ^^^ the trait `From<Two>` is not implemented for `One`
5
+ | ^^^ the trait `From<Two>` is not implemented for `One`
6
6
  |
7
7
  = note: required for `Two` to implement `Into<One>`
8
8
  note: required by a bound in `TransitionResult::<Sm, Ds>::from`
@@ -28,7 +28,7 @@ serde = "1.0"
28
28
  tokio = { version = "1.26", features = ["rt", "rt-multi-thread", "parking_lot", "time", "fs"] }
29
29
  tokio-util = { version = "0.7" }
30
30
  tokio-stream = "0.1"
31
- tonic = "0.8"
31
+ tonic = { workspace = true }
32
32
  tracing = "0.1"
33
33
 
34
34
  [dependencies.temporal-sdk-core]