@temporalio/core-bridge 1.14.2-canary-release-testing.0 → 1.16.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 (233) hide show
  1. package/Cargo.lock +794 -650
  2. package/bridge-macros/src/derive_tryintojs.rs +40 -0
  3. package/lib/native.d.ts +24 -3
  4. package/package.json +4 -4
  5. package/releases/aarch64-apple-darwin/index.node +0 -0
  6. package/releases/aarch64-unknown-linux-gnu/index.node +0 -0
  7. package/releases/x86_64-apple-darwin/index.node +0 -0
  8. package/releases/x86_64-pc-windows-msvc/index.node +0 -0
  9. package/releases/x86_64-unknown-linux-gnu/index.node +0 -0
  10. package/sdk-core/.github/workflows/per-pr.yml +6 -6
  11. package/sdk-core/AGENTS.md +42 -31
  12. package/sdk-core/Cargo.toml +4 -1
  13. package/sdk-core/README.md +19 -13
  14. package/sdk-core/crates/client/Cargo.toml +4 -0
  15. package/sdk-core/crates/client/README.md +139 -0
  16. package/sdk-core/crates/client/src/async_activity_handle.rs +297 -0
  17. package/sdk-core/crates/client/src/callback_based.rs +7 -0
  18. package/sdk-core/crates/client/src/errors.rs +294 -0
  19. package/sdk-core/crates/client/src/{raw.rs → grpc.rs} +370 -159
  20. package/sdk-core/crates/client/src/lib.rs +920 -1326
  21. package/sdk-core/crates/client/src/metrics.rs +24 -33
  22. package/sdk-core/crates/client/src/options_structs.rs +457 -0
  23. package/sdk-core/crates/client/src/replaceable.rs +5 -4
  24. package/sdk-core/crates/client/src/request_extensions.rs +8 -9
  25. package/sdk-core/crates/client/src/retry.rs +99 -54
  26. package/sdk-core/crates/client/src/{worker/mod.rs → worker.rs} +104 -29
  27. package/sdk-core/crates/client/src/workflow_handle.rs +826 -0
  28. package/sdk-core/crates/common/Cargo.toml +62 -3
  29. package/sdk-core/crates/common/build.rs +742 -12
  30. package/sdk-core/crates/common/protos/api_upstream/.github/workflows/ci.yml +2 -0
  31. package/sdk-core/crates/common/protos/api_upstream/.github/workflows/create-release.yml +0 -5
  32. package/sdk-core/crates/common/protos/api_upstream/Makefile +2 -1
  33. package/sdk-core/crates/common/protos/api_upstream/README.md +8 -0
  34. package/sdk-core/crates/common/protos/api_upstream/cmd/check-path-conflicts/main.go +137 -0
  35. package/sdk-core/crates/common/protos/api_upstream/openapi/openapiv2.json +3329 -2647
  36. package/sdk-core/crates/common/protos/api_upstream/openapi/openapiv3.yaml +2734 -708
  37. package/sdk-core/crates/common/protos/api_upstream/temporal/api/activity/v1/message.proto +155 -3
  38. package/sdk-core/crates/common/protos/api_upstream/temporal/api/command/v1/message.proto +26 -0
  39. package/sdk-core/crates/common/protos/api_upstream/temporal/api/common/v1/message.proto +8 -1
  40. package/sdk-core/crates/common/protos/api_upstream/temporal/api/deployment/v1/message.proto +27 -1
  41. package/sdk-core/crates/common/protos/api_upstream/temporal/api/enums/v1/activity.proto +81 -0
  42. package/sdk-core/crates/common/protos/api_upstream/temporal/api/enums/v1/event_type.proto +4 -0
  43. package/sdk-core/crates/common/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +4 -0
  44. package/sdk-core/crates/common/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +15 -0
  45. package/sdk-core/crates/common/protos/api_upstream/temporal/api/enums/v1/workflow.proto +63 -15
  46. package/sdk-core/crates/common/protos/api_upstream/temporal/api/errordetails/v1/message.proto +8 -0
  47. package/sdk-core/crates/common/protos/api_upstream/temporal/api/failure/v1/message.proto +1 -0
  48. package/sdk-core/crates/common/protos/api_upstream/temporal/api/history/v1/message.proto +111 -17
  49. package/sdk-core/crates/common/protos/api_upstream/temporal/api/namespace/v1/message.proto +21 -0
  50. package/sdk-core/crates/common/protos/api_upstream/temporal/api/nexus/v1/message.proto +20 -1
  51. package/sdk-core/crates/common/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +4 -0
  52. package/sdk-core/crates/common/protos/api_upstream/temporal/api/schedule/v1/message.proto +2 -2
  53. package/sdk-core/crates/common/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +2 -0
  54. package/sdk-core/crates/common/protos/api_upstream/temporal/api/worker/v1/message.proto +4 -7
  55. package/sdk-core/crates/common/protos/api_upstream/temporal/api/workflow/v1/message.proto +80 -22
  56. package/sdk-core/crates/common/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +347 -23
  57. package/sdk-core/crates/common/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +242 -43
  58. package/sdk-core/crates/common/protos/local/temporal/sdk/core/core_interface.proto +15 -0
  59. package/sdk-core/crates/common/protos/local/temporal/sdk/core/nexus/nexus.proto +9 -2
  60. package/sdk-core/crates/common/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +8 -0
  61. package/sdk-core/crates/common/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +22 -5
  62. package/sdk-core/crates/common/src/activity_definition.rs +20 -0
  63. package/sdk-core/crates/common/src/data_converters.rs +770 -0
  64. package/sdk-core/crates/common/src/envconfig.rs +5 -0
  65. package/sdk-core/crates/common/src/lib.rs +15 -211
  66. package/sdk-core/crates/common/src/payload_visitor.rs +648 -0
  67. package/sdk-core/crates/common/src/priority.rs +110 -0
  68. package/sdk-core/crates/common/src/protos/canned_histories.rs +19 -0
  69. package/sdk-core/crates/common/src/protos/history_builder.rs +45 -0
  70. package/sdk-core/crates/common/src/protos/history_info.rs +2 -0
  71. package/sdk-core/crates/common/src/protos/mod.rs +134 -27
  72. package/sdk-core/crates/common/src/protos/task_token.rs +3 -3
  73. package/sdk-core/crates/common/src/protos/utilities.rs +11 -0
  74. package/sdk-core/crates/{sdk-core → common}/src/telemetry/log_export.rs +11 -16
  75. package/sdk-core/crates/common/src/telemetry/metrics/core.rs +125 -0
  76. package/sdk-core/crates/common/src/telemetry/metrics.rs +272 -225
  77. package/sdk-core/crates/{sdk-core → common}/src/telemetry/otel.rs +8 -13
  78. package/sdk-core/crates/{sdk-core → common}/src/telemetry/prometheus_meter.rs +49 -50
  79. package/sdk-core/crates/{sdk-core → common}/src/telemetry/prometheus_server.rs +2 -3
  80. package/sdk-core/crates/common/src/telemetry.rs +278 -19
  81. package/sdk-core/crates/common/src/worker.rs +68 -636
  82. package/sdk-core/crates/common/src/workflow_definition.rs +60 -0
  83. package/sdk-core/crates/macros/Cargo.toml +5 -1
  84. package/sdk-core/crates/macros/src/activities_definitions.rs +585 -0
  85. package/sdk-core/crates/macros/src/fsm_impl.rs +507 -0
  86. package/sdk-core/crates/macros/src/lib.rs +138 -512
  87. package/sdk-core/crates/macros/src/macro_utils.rs +106 -0
  88. package/sdk-core/crates/macros/src/workflow_definitions.rs +1224 -0
  89. package/sdk-core/crates/sdk/Cargo.toml +19 -6
  90. package/sdk-core/crates/sdk/README.md +415 -0
  91. package/sdk-core/crates/sdk/src/activities.rs +417 -0
  92. package/sdk-core/crates/sdk/src/interceptors.rs +1 -1
  93. package/sdk-core/crates/sdk/src/lib.rs +759 -442
  94. package/sdk-core/crates/sdk/src/workflow_context/options.rs +64 -35
  95. package/sdk-core/crates/sdk/src/workflow_context.rs +1033 -289
  96. package/sdk-core/crates/sdk/src/workflow_future.rs +277 -213
  97. package/sdk-core/crates/sdk/src/workflows.rs +711 -0
  98. package/sdk-core/crates/sdk-core/Cargo.toml +59 -65
  99. package/sdk-core/crates/sdk-core/benches/workflow_replay_bench.rs +45 -54
  100. package/sdk-core/crates/sdk-core/machine_coverage/ActivityMachine_Coverage.puml +1 -1
  101. package/sdk-core/crates/sdk-core/src/abstractions.rs +6 -10
  102. package/sdk-core/crates/sdk-core/src/core_tests/activity_tasks.rs +6 -5
  103. package/sdk-core/crates/sdk-core/src/core_tests/mod.rs +22 -21
  104. package/sdk-core/crates/sdk-core/src/core_tests/queries.rs +21 -25
  105. package/sdk-core/crates/sdk-core/src/core_tests/replay_flag.rs +7 -10
  106. package/sdk-core/crates/sdk-core/src/core_tests/updates.rs +14 -17
  107. package/sdk-core/crates/sdk-core/src/core_tests/workers.rs +647 -27
  108. package/sdk-core/crates/sdk-core/src/core_tests/workflow_tasks.rs +46 -41
  109. package/sdk-core/crates/sdk-core/src/ephemeral_server/mod.rs +13 -16
  110. package/sdk-core/crates/sdk-core/src/histfetch.rs +20 -10
  111. package/sdk-core/crates/sdk-core/src/lib.rs +60 -123
  112. package/sdk-core/crates/sdk-core/src/pollers/mod.rs +4 -9
  113. package/sdk-core/crates/sdk-core/src/pollers/poll_buffer.rs +411 -32
  114. package/sdk-core/crates/sdk-core/src/protosext/mod.rs +2 -2
  115. package/sdk-core/crates/sdk-core/src/replay/mod.rs +14 -5
  116. package/sdk-core/crates/sdk-core/src/telemetry/metrics.rs +183 -198
  117. package/sdk-core/crates/sdk-core/src/telemetry/mod.rs +3 -281
  118. package/sdk-core/crates/sdk-core/src/test_help/integ_helpers.rs +35 -16
  119. package/sdk-core/crates/sdk-core/src/test_help/unit_helpers.rs +3 -6
  120. package/sdk-core/crates/sdk-core/src/worker/activities/activity_heartbeat_manager.rs +1 -0
  121. package/sdk-core/crates/sdk-core/src/worker/activities/local_activities.rs +11 -14
  122. package/sdk-core/crates/sdk-core/src/worker/activities.rs +16 -19
  123. package/sdk-core/crates/sdk-core/src/worker/client/mocks.rs +11 -5
  124. package/sdk-core/crates/sdk-core/src/worker/client.rs +104 -86
  125. package/sdk-core/crates/sdk-core/src/worker/heartbeat.rs +10 -14
  126. package/sdk-core/crates/sdk-core/src/worker/mod.rs +1175 -241
  127. package/sdk-core/crates/sdk-core/src/worker/nexus.rs +150 -23
  128. package/sdk-core/crates/sdk-core/src/worker/slot_provider.rs +2 -2
  129. package/sdk-core/crates/sdk-core/src/worker/tuner/fixed_size.rs +2 -2
  130. package/sdk-core/crates/sdk-core/src/worker/tuner/resource_based.rs +25 -27
  131. package/sdk-core/crates/sdk-core/src/worker/tuner.rs +64 -44
  132. package/sdk-core/crates/sdk-core/src/worker/workflow/driven_workflow.rs +9 -3
  133. package/sdk-core/crates/sdk-core/src/worker/workflow/machines/patch_state_machine.rs +5 -8
  134. package/sdk-core/crates/sdk-core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +21 -22
  135. package/sdk-core/crates/sdk-core/src/worker/workflow/machines/workflow_machines.rs +28 -4
  136. package/sdk-core/crates/sdk-core/src/worker/workflow/managed_run.rs +20 -41
  137. package/sdk-core/crates/sdk-core/src/worker/workflow/mod.rs +50 -9
  138. package/sdk-core/crates/sdk-core/src/worker/workflow/run_cache.rs +4 -7
  139. package/sdk-core/crates/sdk-core/src/worker/workflow/wft_extraction.rs +2 -4
  140. package/sdk-core/crates/sdk-core/src/worker/workflow/wft_poller.rs +8 -9
  141. package/sdk-core/crates/sdk-core/src/worker/workflow/workflow_stream.rs +1 -3
  142. package/sdk-core/crates/sdk-core/tests/activities_procmacro.rs +6 -0
  143. package/sdk-core/crates/sdk-core/tests/activities_trybuild/basic_pass.rs +54 -0
  144. package/sdk-core/crates/sdk-core/tests/activities_trybuild/invalid_self_type_fail.rs +18 -0
  145. package/sdk-core/crates/sdk-core/tests/activities_trybuild/invalid_self_type_fail.stderr +5 -0
  146. package/sdk-core/crates/sdk-core/tests/activities_trybuild/missing_context_fail.rs +14 -0
  147. package/sdk-core/crates/sdk-core/tests/activities_trybuild/missing_context_fail.stderr +5 -0
  148. package/sdk-core/crates/sdk-core/tests/activities_trybuild/multi_arg_pass.rs +48 -0
  149. package/sdk-core/crates/sdk-core/tests/activities_trybuild/no_input_pass.rs +14 -0
  150. package/sdk-core/crates/sdk-core/tests/activities_trybuild/no_return_type_pass.rs +19 -0
  151. package/sdk-core/crates/sdk-core/tests/cloud_tests.rs +14 -5
  152. package/sdk-core/crates/sdk-core/tests/common/activity_functions.rs +55 -0
  153. package/sdk-core/crates/sdk-core/tests/common/mod.rs +281 -236
  154. package/sdk-core/crates/sdk-core/tests/common/workflows.rs +41 -28
  155. package/sdk-core/crates/sdk-core/tests/global_metric_tests.rs +9 -14
  156. package/sdk-core/crates/sdk-core/tests/heavy_tests/fuzzy_workflow.rs +73 -66
  157. package/sdk-core/crates/sdk-core/tests/heavy_tests.rs +306 -268
  158. package/sdk-core/crates/sdk-core/tests/integ_tests/async_activity_client_tests.rs +230 -0
  159. package/sdk-core/crates/sdk-core/tests/integ_tests/client_tests.rs +94 -57
  160. package/sdk-core/crates/sdk-core/tests/integ_tests/data_converter_tests.rs +381 -0
  161. package/sdk-core/crates/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +37 -38
  162. package/sdk-core/crates/sdk-core/tests/integ_tests/heartbeat_tests.rs +49 -40
  163. package/sdk-core/crates/sdk-core/tests/integ_tests/metrics_tests.rs +447 -300
  164. package/sdk-core/crates/sdk-core/tests/integ_tests/pagination_tests.rs +50 -45
  165. package/sdk-core/crates/sdk-core/tests/integ_tests/polling_tests.rs +157 -157
  166. package/sdk-core/crates/sdk-core/tests/integ_tests/queries_tests.rs +103 -89
  167. package/sdk-core/crates/sdk-core/tests/integ_tests/update_tests.rs +609 -463
  168. package/sdk-core/crates/sdk-core/tests/integ_tests/visibility_tests.rs +80 -62
  169. package/sdk-core/crates/sdk-core/tests/integ_tests/worker_heartbeat_tests.rs +389 -265
  170. package/sdk-core/crates/sdk-core/tests/integ_tests/worker_tests.rs +250 -185
  171. package/sdk-core/crates/sdk-core/tests/integ_tests/worker_versioning_tests.rs +52 -49
  172. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_client_tests.rs +180 -0
  173. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/activities.rs +437 -327
  174. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +82 -58
  175. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +56 -30
  176. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +364 -251
  177. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/client_interactions.rs +552 -0
  178. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +110 -46
  179. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +243 -149
  180. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/eager.rs +98 -32
  181. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +1475 -1040
  182. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +73 -43
  183. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/nexus.rs +402 -245
  184. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/patches.rs +343 -207
  185. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/queries.rs +415 -0
  186. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/replay.rs +96 -36
  187. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/resets.rs +155 -140
  188. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/signals.rs +183 -113
  189. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +85 -44
  190. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/timers.rs +142 -48
  191. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +73 -56
  192. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests.rs +365 -242
  193. package/sdk-core/crates/sdk-core/tests/main.rs +22 -16
  194. package/sdk-core/crates/sdk-core/tests/manual_tests.rs +233 -187
  195. package/sdk-core/crates/sdk-core/tests/runner.rs +4 -6
  196. package/sdk-core/crates/sdk-core/tests/shared_tests/mod.rs +73 -27
  197. package/sdk-core/crates/sdk-core/tests/shared_tests/priority.rs +107 -84
  198. package/sdk-core/crates/sdk-core/tests/workflows_procmacro.rs +6 -0
  199. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/async_query_fail.rs +26 -0
  200. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/async_query_fail.stderr +5 -0
  201. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/basic_pass.rs +49 -0
  202. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/minimal_pass.rs +21 -0
  203. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/mut_query_fail.rs +26 -0
  204. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/mut_query_fail.stderr +5 -0
  205. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/sync_run_fail.rs +21 -0
  206. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/sync_run_fail.stderr +5 -0
  207. package/sdk-core/crates/sdk-core-c-bridge/Cargo.toml +8 -1
  208. package/sdk-core/crates/sdk-core-c-bridge/include/temporal-sdk-core-c-bridge.h +37 -26
  209. package/sdk-core/crates/sdk-core-c-bridge/src/client.rs +180 -87
  210. package/sdk-core/crates/sdk-core-c-bridge/src/lib.rs +89 -5
  211. package/sdk-core/crates/sdk-core-c-bridge/src/metric.rs +10 -16
  212. package/sdk-core/crates/sdk-core-c-bridge/src/runtime.rs +59 -67
  213. package/sdk-core/crates/sdk-core-c-bridge/src/testing.rs +10 -10
  214. package/sdk-core/crates/sdk-core-c-bridge/src/tests/context.rs +57 -22
  215. package/sdk-core/crates/sdk-core-c-bridge/src/tests/mod.rs +108 -12
  216. package/sdk-core/crates/sdk-core-c-bridge/src/tests/utils.rs +9 -52
  217. package/sdk-core/crates/sdk-core-c-bridge/src/worker.rs +74 -91
  218. package/sdk-core/rustfmt.toml +2 -1
  219. package/src/client.rs +206 -289
  220. package/src/helpers/try_into_js.rs +88 -2
  221. package/src/metrics.rs +277 -35
  222. package/src/runtime.rs +94 -45
  223. package/src/testing.rs +9 -16
  224. package/src/worker.rs +86 -68
  225. package/ts/native.ts +39 -3
  226. package/sdk-core/crates/client/src/workflow_handle/mod.rs +0 -212
  227. package/sdk-core/crates/common/src/errors.rs +0 -85
  228. package/sdk-core/crates/common/tests/worker_task_types_test.rs +0 -129
  229. package/sdk-core/crates/macros/LICENSE.txt +0 -21
  230. package/sdk-core/crates/sdk/src/activity_context.rs +0 -238
  231. package/sdk-core/crates/sdk/src/app_data.rs +0 -37
  232. package/sdk-core/crates/sdk-core/tests/integ_tests/activity_functions.rs +0 -5
  233. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/appdata_propagation.rs +0 -61
@@ -3,27 +3,26 @@ use crate::TelemetryInstance;
3
3
  use crate::abstractions::dbg_panic;
4
4
 
5
5
  use std::{
6
+ collections::HashMap,
6
7
  fmt::{Debug, Display},
7
8
  iter::Iterator,
8
- sync::Arc,
9
+ sync::{Arc, atomic::AtomicU64},
9
10
  time::Duration,
10
11
  };
11
12
  use temporalio_common::{
12
13
  protos::temporal::api::{enums::v1::WorkflowTaskFailedCause, failure::v1::Failure},
13
- telemetry::metrics::{
14
- BufferAttributes, BufferInstrumentRef, CoreMeter, Counter, CounterBase, Gauge, GaugeBase,
15
- GaugeF64, GaugeF64Base, Histogram, HistogramBase, HistogramDuration, HistogramDurationBase,
16
- HistogramF64, HistogramF64Base, LazyBufferInstrument, MetricAttributable, MetricAttributes,
17
- MetricCallBufferer, MetricEvent, MetricKeyValue, MetricKind, MetricParameters,
18
- MetricUpdateVal, NewAttributes, NoOpCoreMeter, TemporalMeter, WorkerHeartbeatMetrics,
19
- },
14
+ telemetry::metrics::{core::*, *},
20
15
  };
21
16
 
17
+ pub(super) const NUM_POLLERS_NAME: &str = "num_pollers";
18
+ pub(super) const TASK_SLOTS_AVAILABLE_NAME: &str = "worker_task_slots_available";
19
+ pub(super) const TASK_SLOTS_USED_NAME: &str = "worker_task_slots_used";
20
+ pub(super) const STICKY_CACHE_SIZE_NAME: &str = "sticky_cache_size";
21
+
22
22
  /// Used to track context associated with metrics, and record/update them
23
23
  #[derive(Clone)]
24
24
  pub(crate) struct MetricsContext {
25
- meter: Arc<dyn CoreMeter>,
26
- kvs: MetricAttributes,
25
+ meter: TemporalMeter,
27
26
  instruments: Arc<Instruments>,
28
27
  in_memory_metrics: Option<Arc<WorkerHeartbeatMetrics>>,
29
28
  }
@@ -69,12 +68,10 @@ struct Instruments {
69
68
 
70
69
  impl MetricsContext {
71
70
  pub(crate) fn no_op() -> Self {
72
- let meter = Arc::new(NoOpCoreMeter);
73
- let kvs = meter.new_attributes(Default::default());
71
+ let meter = TemporalMeter::no_op();
74
72
  let in_memory_metrics = Some(Arc::new(WorkerHeartbeatMetrics::default()));
75
- let instruments = Arc::new(Instruments::new(meter.as_ref(), in_memory_metrics.clone()));
73
+ let instruments = Arc::new(Instruments::new(&meter, in_memory_metrics.clone()));
76
74
  Self {
77
- kvs,
78
75
  instruments,
79
76
  meter,
80
77
  in_memory_metrics,
@@ -92,19 +89,17 @@ impl MetricsContext {
92
89
  temporal_meter: Option<TemporalMeter>,
93
90
  ) -> Self {
94
91
  if let Some(mut meter) = temporal_meter {
95
- meter
96
- .default_attribs
97
- .attributes
98
- .push(MetricKeyValue::new(KEY_NAMESPACE, namespace));
99
- meter.default_attribs.attributes.push(task_queue(tq));
100
- let kvs = meter.inner.new_attributes(meter.default_attribs);
92
+ let addtl_attributes = [
93
+ MetricKeyValue::new(KEY_NAMESPACE, namespace),
94
+ task_queue(tq),
95
+ ];
96
+ meter.merge_attributes(addtl_attributes.into());
101
97
  let in_memory_metrics = Some(Arc::new(WorkerHeartbeatMetrics::default()));
102
- let mut instruments = Instruments::new(meter.inner.as_ref(), in_memory_metrics.clone());
103
- instruments.update_attributes(&kvs);
98
+ let mut instruments = Instruments::new(&meter, in_memory_metrics.clone());
99
+ instruments.update_attributes(meter.get_default_attributes());
104
100
  Self {
105
- kvs,
106
101
  instruments: Arc::new(instruments),
107
- meter: meter.inner,
102
+ meter,
108
103
  in_memory_metrics,
109
104
  }
110
105
  } else {
@@ -117,14 +112,12 @@ impl MetricsContext {
117
112
  &self,
118
113
  new_attrs: impl IntoIterator<Item = MetricKeyValue>,
119
114
  ) -> Self {
120
- let kvs = self
121
- .meter
122
- .extend_attributes(self.kvs.clone(), new_attrs.into());
115
+ let mut tm = self.meter.clone();
116
+ tm.merge_attributes(new_attrs.into());
123
117
  let mut instruments = (*self.instruments).clone();
124
- instruments.update_attributes(&kvs);
118
+ instruments.update_attributes(tm.get_default_attributes());
125
119
  Self {
126
120
  instruments: Arc::new(instruments),
127
- kvs,
128
121
  meter: self.meter.clone(),
129
122
  in_memory_metrics: self.in_memory_metrics.clone(),
130
123
  }
@@ -309,7 +302,7 @@ impl MetricsContext {
309
302
  }
310
303
 
311
304
  impl Instruments {
312
- fn new(meter: &dyn CoreMeter, in_memory: Option<Arc<WorkerHeartbeatMetrics>>) -> Self {
305
+ fn new(meter: &TemporalMeter, in_memory: Option<Arc<WorkerHeartbeatMetrics>>) -> Self {
313
306
  let counter_with_in_mem = |params: MetricParameters| -> Counter {
314
307
  in_memory
315
308
  .clone()
@@ -591,6 +584,129 @@ impl Instruments {
591
584
  }
592
585
  }
593
586
 
587
+ #[derive(Default, Debug)]
588
+ pub(crate) struct NumPollersMetric {
589
+ pub wft_current_pollers: Arc<AtomicU64>,
590
+ pub sticky_wft_current_pollers: Arc<AtomicU64>,
591
+ pub activity_current_pollers: Arc<AtomicU64>,
592
+ pub nexus_current_pollers: Arc<AtomicU64>,
593
+ }
594
+
595
+ impl NumPollersMetric {
596
+ pub(crate) fn as_map(&self) -> HashMap<String, Arc<AtomicU64>> {
597
+ HashMap::from([
598
+ (
599
+ "workflow_task".to_string(),
600
+ self.wft_current_pollers.clone(),
601
+ ),
602
+ (
603
+ "sticky_workflow_task".to_string(),
604
+ self.sticky_wft_current_pollers.clone(),
605
+ ),
606
+ (
607
+ "activity_task".to_string(),
608
+ self.activity_current_pollers.clone(),
609
+ ),
610
+ ("nexus_task".to_string(), self.nexus_current_pollers.clone()),
611
+ ])
612
+ }
613
+ }
614
+
615
+ #[derive(Default, Debug)]
616
+ pub(crate) struct SlotMetrics {
617
+ pub workflow_worker: Arc<AtomicU64>,
618
+ pub activity_worker: Arc<AtomicU64>,
619
+ pub nexus_worker: Arc<AtomicU64>,
620
+ pub local_activity_worker: Arc<AtomicU64>,
621
+ }
622
+
623
+ impl SlotMetrics {
624
+ pub(crate) fn as_map(&self) -> HashMap<String, Arc<AtomicU64>> {
625
+ HashMap::from([
626
+ ("WorkflowWorker".to_string(), self.workflow_worker.clone()),
627
+ ("ActivityWorker".to_string(), self.activity_worker.clone()),
628
+ ("NexusWorker".to_string(), self.nexus_worker.clone()),
629
+ (
630
+ "LocalActivityWorker".to_string(),
631
+ self.local_activity_worker.clone(),
632
+ ),
633
+ ])
634
+ }
635
+ }
636
+
637
+ #[derive(Default, Debug)]
638
+ pub(crate) struct WorkerHeartbeatMetrics {
639
+ pub sticky_cache_size: Arc<AtomicU64>,
640
+ pub total_sticky_cache_hit: Arc<AtomicU64>,
641
+ pub total_sticky_cache_miss: Arc<AtomicU64>,
642
+ pub num_pollers: NumPollersMetric,
643
+ pub worker_task_slots_used: SlotMetrics,
644
+ pub worker_task_slots_available: SlotMetrics,
645
+ pub workflow_task_execution_failed: Arc<AtomicU64>,
646
+ pub activity_execution_failed: Arc<AtomicU64>,
647
+ pub nexus_task_execution_failed: Arc<AtomicU64>,
648
+ pub local_activity_execution_failed: Arc<AtomicU64>,
649
+ // Although latency metrics here are histograms, we are using the number of times they're called
650
+ // to represent the `total_processed_tasks` heartbeat field
651
+ pub activity_execution_latency: Arc<AtomicU64>,
652
+ pub local_activity_execution_latency: Arc<AtomicU64>,
653
+ pub workflow_task_execution_latency: Arc<AtomicU64>,
654
+ pub nexus_task_execution_latency: Arc<AtomicU64>,
655
+ }
656
+
657
+ impl WorkerHeartbeatMetrics {
658
+ pub(crate) fn get_metric(&self, name: &str) -> Option<HeartbeatMetricType> {
659
+ match name {
660
+ "sticky_cache_size" => Some(HeartbeatMetricType::Individual(
661
+ self.sticky_cache_size.clone(),
662
+ )),
663
+ "sticky_cache_hit" => Some(HeartbeatMetricType::Individual(
664
+ self.total_sticky_cache_hit.clone(),
665
+ )),
666
+ "sticky_cache_miss" => Some(HeartbeatMetricType::Individual(
667
+ self.total_sticky_cache_miss.clone(),
668
+ )),
669
+ "num_pollers" => Some(HeartbeatMetricType::WithLabel {
670
+ label_key: "poller_type".to_string(),
671
+ metrics: self.num_pollers.as_map(),
672
+ }),
673
+ "worker_task_slots_used" => Some(HeartbeatMetricType::WithLabel {
674
+ label_key: "worker_type".to_string(),
675
+ metrics: self.worker_task_slots_used.as_map(),
676
+ }),
677
+ "worker_task_slots_available" => Some(HeartbeatMetricType::WithLabel {
678
+ label_key: "worker_type".to_string(),
679
+ metrics: self.worker_task_slots_available.as_map(),
680
+ }),
681
+ "workflow_task_execution_failed" => Some(HeartbeatMetricType::Individual(
682
+ self.workflow_task_execution_failed.clone(),
683
+ )),
684
+ "activity_execution_failed" => Some(HeartbeatMetricType::Individual(
685
+ self.activity_execution_failed.clone(),
686
+ )),
687
+ "nexus_task_execution_failed" => Some(HeartbeatMetricType::Individual(
688
+ self.nexus_task_execution_failed.clone(),
689
+ )),
690
+ "local_activity_execution_failed" => Some(HeartbeatMetricType::Individual(
691
+ self.local_activity_execution_failed.clone(),
692
+ )),
693
+ "activity_execution_latency" => Some(HeartbeatMetricType::Individual(
694
+ self.activity_execution_latency.clone(),
695
+ )),
696
+ "local_activity_execution_latency" => Some(HeartbeatMetricType::Individual(
697
+ self.local_activity_execution_latency.clone(),
698
+ )),
699
+ "workflow_task_execution_latency" => Some(HeartbeatMetricType::Individual(
700
+ self.workflow_task_execution_latency.clone(),
701
+ )),
702
+ "nexus_task_execution_latency" => Some(HeartbeatMetricType::Individual(
703
+ self.nexus_task_execution_latency.clone(),
704
+ )),
705
+ _ => None,
706
+ }
707
+ }
708
+ }
709
+
594
710
  const KEY_NAMESPACE: &str = "namespace";
595
711
  const KEY_WF_TYPE: &str = "workflow_type";
596
712
  const KEY_TASK_QUEUE: &str = "task_queue";
@@ -669,25 +785,6 @@ pub(crate) fn failure_reason(reason: FailureReason) -> MetricKeyValue {
669
785
  MetricKeyValue::new(KEY_TASK_FAILURE_TYPE, reason.to_string())
670
786
  }
671
787
 
672
- /// The string name (which may be prefixed) for this metric
673
- pub const WORKFLOW_E2E_LATENCY_HISTOGRAM_NAME: &str = "workflow_endtoend_latency";
674
- /// The string name (which may be prefixed) for this metric
675
- pub const WORKFLOW_TASK_SCHED_TO_START_LATENCY_HISTOGRAM_NAME: &str =
676
- "workflow_task_schedule_to_start_latency";
677
- /// The string name (which may be prefixed) for this metric
678
- pub const WORKFLOW_TASK_REPLAY_LATENCY_HISTOGRAM_NAME: &str = "workflow_task_replay_latency";
679
- /// The string name (which may be prefixed) for this metric
680
- pub const WORKFLOW_TASK_EXECUTION_LATENCY_HISTOGRAM_NAME: &str = "workflow_task_execution_latency";
681
- /// The string name (which may be prefixed) for this metric
682
- pub const ACTIVITY_SCHED_TO_START_LATENCY_HISTOGRAM_NAME: &str =
683
- "activity_schedule_to_start_latency";
684
- /// The string name (which may be prefixed) for this metric
685
- pub const ACTIVITY_EXEC_LATENCY_HISTOGRAM_NAME: &str = "activity_execution_latency";
686
- pub(super) const NUM_POLLERS_NAME: &str = "num_pollers";
687
- pub(super) const TASK_SLOTS_AVAILABLE_NAME: &str = "worker_task_slots_available";
688
- pub(super) const TASK_SLOTS_USED_NAME: &str = "worker_task_slots_used";
689
- pub(super) const STICKY_CACHE_SIZE_NAME: &str = "sticky_cache_size";
690
-
691
788
  /// Track a failure metric if the failure is not a benign application failure.
692
789
  pub(crate) fn should_record_failure_metric(failure: &Option<Failure>) -> bool {
693
790
  !failure
@@ -695,81 +792,6 @@ pub(crate) fn should_record_failure_metric(failure: &Option<Failure>) -> bool {
695
792
  .is_some_and(|f| f.is_benign_application_failure())
696
793
  }
697
794
 
698
- /// Helps define buckets once in terms of millis, but also generates a seconds version
699
- macro_rules! define_latency_buckets {
700
- ($(($metric_name:pat, $name:ident, $sec_name:ident, [$($bucket:expr),*])),*) => {
701
- $(
702
- pub(super) static $name: &[f64] = &[$($bucket,)*];
703
- pub(super) static $sec_name: &[f64] = &[$( $bucket / 1000.0, )*];
704
- )*
705
-
706
- /// Returns the default histogram buckets that lang should use for a given metric name if
707
- /// they have not been overridden by the user. If `use_seconds` is true, returns buckets
708
- /// in terms of seconds rather than milliseconds.
709
- ///
710
- /// The name must *not* be prefixed with `temporal_`
711
- pub fn default_buckets_for(histo_name: &str, use_seconds: bool) -> &'static [f64] {
712
- match histo_name {
713
- $(
714
- $metric_name => { if use_seconds { &$sec_name } else { &$name } },
715
- )*
716
- }
717
- }
718
- };
719
- }
720
-
721
- define_latency_buckets!(
722
- (
723
- WORKFLOW_E2E_LATENCY_HISTOGRAM_NAME,
724
- WF_LATENCY_MS_BUCKETS,
725
- WF_LATENCY_S_BUCKETS,
726
- [
727
- 100.,
728
- 500.,
729
- 1000.,
730
- 1500.,
731
- 2000.,
732
- 5000.,
733
- 10_000.,
734
- 30_000.,
735
- 60_000.,
736
- 120_000.,
737
- 300_000.,
738
- 600_000.,
739
- 1_800_000., // 30 min
740
- 3_600_000., // 1 hr
741
- 30_600_000., // 10 hrs
742
- 8.64e7 // 24 hrs
743
- ]
744
- ),
745
- (
746
- WORKFLOW_TASK_EXECUTION_LATENCY_HISTOGRAM_NAME
747
- | WORKFLOW_TASK_REPLAY_LATENCY_HISTOGRAM_NAME,
748
- WF_TASK_MS_BUCKETS,
749
- WF_TASK_S_BUCKETS,
750
- [1., 10., 20., 50., 100., 200., 500., 1000.]
751
- ),
752
- (
753
- ACTIVITY_EXEC_LATENCY_HISTOGRAM_NAME,
754
- ACT_EXE_MS_BUCKETS,
755
- ACT_EXE_S_BUCKETS,
756
- [50., 100., 500., 1000., 5000., 10_000., 60_000.]
757
- ),
758
- (
759
- WORKFLOW_TASK_SCHED_TO_START_LATENCY_HISTOGRAM_NAME
760
- | ACTIVITY_SCHED_TO_START_LATENCY_HISTOGRAM_NAME,
761
- TASK_SCHED_TO_START_MS_BUCKETS,
762
- TASK_SCHED_TO_START_S_BUCKETS,
763
- [100., 500., 1000., 5000., 10_000., 100_000., 1_000_000.]
764
- ),
765
- (
766
- _,
767
- DEFAULT_MS_BUCKETS,
768
- DEFAULT_S_BUCKETS,
769
- [50., 100., 500., 1000., 2500., 10_000.]
770
- )
771
- );
772
-
773
795
  /// Buffers [MetricEvent]s for periodic consumption by lang
774
796
  #[derive(Debug)]
775
797
  pub struct MetricsCallBuffer<I>
@@ -860,7 +882,9 @@ where
860
882
  }
861
883
 
862
884
  fn histogram_f64(&self, params: MetricParameters) -> HistogramF64 {
863
- HistogramF64::new(Arc::new(self.new_instrument(params, MetricKind::Histogram)))
885
+ HistogramF64::new(Arc::new(
886
+ self.new_instrument(params, MetricKind::HistogramF64),
887
+ ))
864
888
  }
865
889
 
866
890
  fn histogram_duration(&self, params: MetricParameters) -> HistogramDuration {
@@ -874,7 +898,7 @@ where
874
898
  }
875
899
 
876
900
  fn gauge_f64(&self, params: MetricParameters) -> GaugeF64 {
877
- GaugeF64::new(Arc::new(self.new_instrument(params, MetricKind::Gauge)))
901
+ GaugeF64::new(Arc::new(self.new_instrument(params, MetricKind::GaugeF64)))
878
902
  }
879
903
  }
880
904
  impl<I> MetricCallBufferer<I> for MetricsCallBuffer<I>
@@ -898,7 +922,10 @@ where
898
922
  fn send(&self, value: MetricUpdateVal, attributes: &MetricAttributes) {
899
923
  let attributes = match attributes {
900
924
  MetricAttributes::Buffer(l) => l.clone(),
901
- _ => panic!("MetricsCallBuffer only works with MetricAttributes::Buffer"),
925
+ e => panic!(
926
+ "MetricsCallBuffer only works with MetricAttributes::Buffer, but used: {:?}",
927
+ e
928
+ ),
902
929
  };
903
930
  self.tx.send(MetricEvent::Update {
904
931
  instrument: self.instrument_ref.clone(),
@@ -1058,64 +1085,15 @@ where
1058
1085
  }
1059
1086
  }
1060
1087
 
1061
- #[derive(Debug, derive_more::Constructor)]
1062
- pub(crate) struct PrefixedMetricsMeter<CM> {
1063
- prefix: String,
1064
- meter: CM,
1065
- }
1066
- impl<CM: CoreMeter> CoreMeter for PrefixedMetricsMeter<CM> {
1067
- fn new_attributes(&self, attribs: NewAttributes) -> MetricAttributes {
1068
- self.meter.new_attributes(attribs)
1069
- }
1070
-
1071
- fn extend_attributes(
1072
- &self,
1073
- existing: MetricAttributes,
1074
- attribs: NewAttributes,
1075
- ) -> MetricAttributes {
1076
- self.meter.extend_attributes(existing, attribs)
1077
- }
1078
-
1079
- fn counter(&self, mut params: MetricParameters) -> Counter {
1080
- params.name = (self.prefix.clone() + &*params.name).into();
1081
- self.meter.counter(params)
1082
- }
1083
-
1084
- fn histogram(&self, mut params: MetricParameters) -> Histogram {
1085
- params.name = (self.prefix.clone() + &*params.name).into();
1086
- self.meter.histogram(params)
1087
- }
1088
-
1089
- fn histogram_f64(&self, mut params: MetricParameters) -> HistogramF64 {
1090
- params.name = (self.prefix.clone() + &*params.name).into();
1091
- self.meter.histogram_f64(params)
1092
- }
1093
-
1094
- fn histogram_duration(&self, mut params: MetricParameters) -> HistogramDuration {
1095
- params.name = (self.prefix.clone() + &*params.name).into();
1096
- self.meter.histogram_duration(params)
1097
- }
1098
-
1099
- fn gauge(&self, mut params: MetricParameters) -> Gauge {
1100
- params.name = (self.prefix.clone() + &*params.name).into();
1101
- self.meter.gauge(params)
1102
- }
1103
-
1104
- fn gauge_f64(&self, mut params: MetricParameters) -> GaugeF64 {
1105
- params.name = (self.prefix.clone() + &*params.name).into();
1106
- self.meter.gauge_f64(params)
1107
- }
1108
- }
1109
-
1110
1088
  #[cfg(test)]
1111
1089
  mod tests {
1112
1090
  use super::*;
1113
1091
  use std::any::Any;
1114
1092
  use temporalio_common::telemetry::{
1115
- METRIC_PREFIX,
1116
- metrics::{BufferInstrumentRef, CustomMetricAttributes},
1093
+ TelemetryOptions,
1094
+ metrics::core::{BufferInstrumentRef, CustomMetricAttributes},
1095
+ telemetry_init,
1117
1096
  };
1118
- use tracing::subscriber::NoSubscriber;
1119
1097
 
1120
1098
  #[derive(Debug)]
1121
1099
  struct DummyCustomAttrs(usize);
@@ -1142,16 +1120,13 @@ mod tests {
1142
1120
 
1143
1121
  #[test]
1144
1122
  fn test_buffered_core_context() {
1145
- let no_op_subscriber = Arc::new(NoSubscriber::new());
1146
1123
  let call_buffer = Arc::new(MetricsCallBuffer::new(100));
1147
- let telem_instance = TelemetryInstance::new(
1148
- Some(no_op_subscriber),
1149
- None,
1150
- METRIC_PREFIX.to_string(),
1151
- Some(call_buffer.clone()),
1152
- true,
1153
- temporalio_common::telemetry::TaskQueueLabelStrategy::UseNormal,
1154
- );
1124
+ let telem_instance = telemetry_init(
1125
+ TelemetryOptions::builder()
1126
+ .metrics(call_buffer.clone() as Arc<dyn CoreMeter>)
1127
+ .build(),
1128
+ )
1129
+ .unwrap();
1155
1130
  let mc = MetricsContext::top_level("foo".to_string(), "q".to_string(), &telem_instance);
1156
1131
  mc.forced_cache_eviction();
1157
1132
  let events = call_buffer.retrieve();
@@ -1162,17 +1137,27 @@ mod tests {
1162
1137
  append_from: None,
1163
1138
  attributes,
1164
1139
  }
1165
- if attributes[0].key == "service_name" &&
1166
- attributes[1].key == "namespace" &&
1167
- attributes[2].key == "task_queue"
1140
+ if attributes[0].key == "service_name"
1141
+ => populate_into
1142
+ );
1143
+ let a2 = assert_matches!(
1144
+ &events[1],
1145
+ MetricEvent::CreateAttributes {
1146
+ populate_into,
1147
+ append_from: Some(_),
1148
+ attributes,
1149
+ }
1150
+ if attributes[0].key == "namespace" &&
1151
+ attributes[1].key == "task_queue"
1168
1152
  => populate_into
1169
1153
  );
1170
1154
  a1.set(Arc::new(DummyCustomAttrs(1))).unwrap();
1155
+ a2.set(Arc::new(DummyCustomAttrs(2))).unwrap();
1171
1156
  // Verify all metrics are created. This number will need to get updated any time a metric
1172
1157
  // is added.
1173
1158
  let num_metrics = 35;
1174
1159
  #[allow(clippy::needless_range_loop)] // Sorry clippy, this reads easier.
1175
- for metric_num in 1..=num_metrics {
1160
+ for metric_num in 2..=num_metrics + 1 {
1176
1161
  let hole = assert_matches!(&events[metric_num],
1177
1162
  MetricEvent::Create { populate_into, .. }
1178
1163
  => populate_into
@@ -1180,18 +1165,19 @@ mod tests {
1180
1165
  hole.set(Arc::new(DummyInstrumentRef(metric_num))).unwrap();
1181
1166
  }
1182
1167
  assert_matches!(
1183
- &events[num_metrics + 1], // +1 for attrib creation (at start), then this update
1168
+ &events[num_metrics + 2], // +2 for attrib creation (at start), then this update
1184
1169
  MetricEvent::Update {
1185
1170
  instrument,
1186
1171
  attributes,
1187
1172
  update: MetricUpdateVal::Delta(1)
1188
1173
  }
1189
- if DummyCustomAttrs::as_id(attributes) == 1 && instrument.get().0 == num_metrics
1174
+ if DummyCustomAttrs::as_id(attributes) == 2 && instrument.get().0 == num_metrics + 1
1190
1175
  );
1191
1176
  // Verify creating a new context with new attributes merges them properly
1192
1177
  let mc2 = mc.with_new_attrs([MetricKeyValue::new("gotta", "go fast")]);
1193
1178
  mc2.wf_task_latency(Duration::from_secs(1));
1194
1179
  let events = call_buffer.retrieve();
1180
+ dbg!(&events);
1195
1181
  let a2 = assert_matches!(
1196
1182
  &events[0],
1197
1183
  MetricEvent::CreateAttributes {
@@ -1199,11 +1185,10 @@ mod tests {
1199
1185
  append_from: Some(eh),
1200
1186
  attributes
1201
1187
  }
1202
- if attributes[0].key == "gotta" && DummyCustomAttrs::as_id(eh) == 1
1188
+ if attributes[0].key == "gotta" && DummyCustomAttrs::as_id(eh) == 2
1203
1189
  => populate_into
1204
1190
  );
1205
- a2.set(Arc::new(DummyCustomAttrs(2))).unwrap();
1206
- dbg!(&events);
1191
+ a2.set(Arc::new(DummyCustomAttrs(3))).unwrap();
1207
1192
  assert_matches!(
1208
1193
  &events[1],
1209
1194
  MetricEvent::Update {
@@ -1211,7 +1196,7 @@ mod tests {
1211
1196
  attributes,
1212
1197
  update: MetricUpdateVal::Duration(d)
1213
1198
  }
1214
- if DummyCustomAttrs::as_id(attributes) == 2 && instrument.get().0 == 11
1199
+ if DummyCustomAttrs::as_id(attributes) == 3 && instrument.get().0 == 12
1215
1200
  && d == &Duration::from_secs(1)
1216
1201
  );
1217
1202
  }