@temporalio/core-bridge 0.22.0 → 1.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/Cargo.lock +120 -15
  2. package/Cargo.toml +3 -1
  3. package/README.md +1 -1
  4. package/index.d.ts +137 -33
  5. package/package.json +6 -6
  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/.buildkite/docker/docker-compose.yaml +4 -2
  12. package/sdk-core/ARCHITECTURE.md +9 -7
  13. package/sdk-core/README.md +5 -1
  14. package/sdk-core/arch_docs/diagrams/workflow_internals.svg +1 -0
  15. package/sdk-core/bridge-ffi/src/lib.rs +1 -1
  16. package/sdk-core/bridge-ffi/src/wrappers.rs +60 -37
  17. package/sdk-core/client/Cargo.toml +1 -0
  18. package/sdk-core/client/src/lib.rs +50 -15
  19. package/sdk-core/client/src/raw.rs +167 -55
  20. package/sdk-core/client/src/retry.rs +9 -4
  21. package/sdk-core/client/src/workflow_handle/mod.rs +4 -2
  22. package/sdk-core/core/Cargo.toml +2 -0
  23. package/sdk-core/core/benches/workflow_replay.rs +1 -7
  24. package/sdk-core/core/src/abstractions.rs +137 -16
  25. package/sdk-core/core/src/core_tests/activity_tasks.rs +258 -63
  26. package/sdk-core/core/src/core_tests/child_workflows.rs +1 -2
  27. package/sdk-core/core/src/core_tests/determinism.rs +2 -2
  28. package/sdk-core/core/src/core_tests/local_activities.rs +8 -7
  29. package/sdk-core/core/src/core_tests/queries.rs +146 -60
  30. package/sdk-core/core/src/core_tests/replay_flag.rs +1 -1
  31. package/sdk-core/core/src/core_tests/workers.rs +39 -23
  32. package/sdk-core/core/src/core_tests/workflow_cancels.rs +1 -1
  33. package/sdk-core/core/src/core_tests/workflow_tasks.rs +387 -280
  34. package/sdk-core/core/src/lib.rs +8 -5
  35. package/sdk-core/core/src/pollers/poll_buffer.rs +16 -10
  36. package/sdk-core/core/src/protosext/mod.rs +7 -9
  37. package/sdk-core/core/src/retry_logic.rs +73 -16
  38. package/sdk-core/core/src/telemetry/metrics.rs +21 -7
  39. package/sdk-core/core/src/telemetry/mod.rs +182 -110
  40. package/sdk-core/core/src/test_help/mod.rs +341 -109
  41. package/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +18 -9
  42. package/sdk-core/core/src/worker/activities/local_activities.rs +22 -25
  43. package/sdk-core/core/src/worker/activities.rs +156 -29
  44. package/sdk-core/core/src/worker/client.rs +1 -0
  45. package/sdk-core/core/src/worker/mod.rs +132 -659
  46. package/sdk-core/core/src/{workflow → worker/workflow}/bridge.rs +1 -1
  47. package/sdk-core/core/src/{workflow → worker/workflow}/driven_workflow.rs +1 -1
  48. package/sdk-core/core/src/{workflow → worker/workflow}/history_update.rs +16 -2
  49. package/sdk-core/core/src/{workflow → worker/workflow}/machines/activity_state_machine.rs +39 -4
  50. package/sdk-core/core/src/{workflow → worker/workflow}/machines/cancel_external_state_machine.rs +5 -2
  51. package/sdk-core/core/src/{workflow → worker/workflow}/machines/cancel_workflow_state_machine.rs +1 -1
  52. package/sdk-core/core/src/{workflow → worker/workflow}/machines/child_workflow_state_machine.rs +2 -4
  53. package/sdk-core/core/src/{workflow → worker/workflow}/machines/complete_workflow_state_machine.rs +0 -0
  54. package/sdk-core/core/src/{workflow → worker/workflow}/machines/continue_as_new_workflow_state_machine.rs +1 -1
  55. package/sdk-core/core/src/{workflow → worker/workflow}/machines/fail_workflow_state_machine.rs +0 -0
  56. package/sdk-core/core/src/{workflow → worker/workflow}/machines/local_activity_state_machine.rs +2 -5
  57. package/sdk-core/core/src/{workflow → worker/workflow}/machines/mod.rs +1 -1
  58. package/sdk-core/core/src/{workflow → worker/workflow}/machines/mutable_side_effect_state_machine.rs +0 -0
  59. package/sdk-core/core/src/{workflow → worker/workflow}/machines/patch_state_machine.rs +1 -1
  60. package/sdk-core/core/src/{workflow → worker/workflow}/machines/side_effect_state_machine.rs +0 -0
  61. package/sdk-core/core/src/{workflow → worker/workflow}/machines/signal_external_state_machine.rs +4 -2
  62. package/sdk-core/core/src/{workflow → worker/workflow}/machines/timer_state_machine.rs +1 -2
  63. package/sdk-core/core/src/{workflow → worker/workflow}/machines/transition_coverage.rs +1 -1
  64. package/sdk-core/core/src/{workflow → worker/workflow}/machines/upsert_search_attributes_state_machine.rs +5 -7
  65. package/sdk-core/core/src/{workflow → worker/workflow}/machines/workflow_machines/local_acts.rs +2 -2
  66. package/sdk-core/core/src/{workflow → worker/workflow}/machines/workflow_machines.rs +40 -16
  67. package/sdk-core/core/src/{workflow → worker/workflow}/machines/workflow_task_state_machine.rs +0 -0
  68. package/sdk-core/core/src/worker/workflow/managed_run/managed_wf_test.rs +198 -0
  69. package/sdk-core/core/src/worker/workflow/managed_run.rs +627 -0
  70. package/sdk-core/core/src/worker/workflow/mod.rs +1115 -0
  71. package/sdk-core/core/src/worker/workflow/run_cache.rs +143 -0
  72. package/sdk-core/core/src/worker/workflow/wft_poller.rs +88 -0
  73. package/sdk-core/core/src/worker/workflow/workflow_stream.rs +936 -0
  74. package/sdk-core/core-api/src/errors.rs +3 -10
  75. package/sdk-core/core-api/src/lib.rs +2 -1
  76. package/sdk-core/core-api/src/worker.rs +26 -2
  77. package/sdk-core/etc/dynamic-config.yaml +2 -0
  78. package/sdk-core/integ-with-otel.sh +1 -1
  79. package/sdk-core/protos/api_upstream/Makefile +4 -4
  80. package/sdk-core/protos/api_upstream/api-linter.yaml +2 -0
  81. package/sdk-core/protos/api_upstream/buf.yaml +8 -9
  82. package/sdk-core/protos/api_upstream/temporal/api/cluster/v1/message.proto +83 -0
  83. package/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +7 -1
  84. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/cluster.proto +40 -0
  85. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +3 -0
  86. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/reset.proto +3 -1
  87. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/schedule.proto +60 -0
  88. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/workflow.proto +3 -0
  89. package/sdk-core/protos/api_upstream/temporal/api/errordetails/v1/message.proto +32 -4
  90. package/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +69 -19
  91. package/sdk-core/protos/api_upstream/temporal/api/namespace/v1/message.proto +13 -0
  92. package/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +163 -0
  93. package/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/service.proto +97 -0
  94. package/sdk-core/protos/api_upstream/temporal/api/schedule/v1/message.proto +300 -0
  95. package/sdk-core/protos/api_upstream/temporal/api/workflow/v1/message.proto +25 -0
  96. package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +180 -3
  97. package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +53 -3
  98. package/sdk-core/protos/local/temporal/sdk/core/activity_result/activity_result.proto +2 -2
  99. package/sdk-core/protos/local/temporal/sdk/core/activity_task/activity_task.proto +6 -5
  100. package/sdk-core/protos/local/temporal/sdk/core/bridge/bridge.proto +27 -6
  101. package/sdk-core/protos/local/temporal/sdk/core/child_workflow/child_workflow.proto +2 -1
  102. package/sdk-core/protos/local/temporal/sdk/core/common/common.proto +0 -64
  103. package/sdk-core/protos/local/temporal/sdk/core/core_interface.proto +2 -1
  104. package/sdk-core/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +11 -8
  105. package/sdk-core/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +30 -25
  106. package/sdk-core/sdk/src/activity_context.rs +12 -5
  107. package/sdk-core/sdk/src/app_data.rs +37 -0
  108. package/sdk-core/sdk/src/lib.rs +76 -43
  109. package/sdk-core/sdk/src/workflow_context/options.rs +8 -6
  110. package/sdk-core/sdk/src/workflow_context.rs +14 -19
  111. package/sdk-core/sdk/src/workflow_future.rs +11 -6
  112. package/sdk-core/sdk-core-protos/src/history_builder.rs +19 -5
  113. package/sdk-core/sdk-core-protos/src/history_info.rs +11 -6
  114. package/sdk-core/sdk-core-protos/src/lib.rs +87 -176
  115. package/sdk-core/test-utils/src/histfetch.rs +1 -1
  116. package/sdk-core/test-utils/src/lib.rs +93 -77
  117. package/sdk-core/tests/integ_tests/client_tests.rs +2 -2
  118. package/sdk-core/tests/integ_tests/heartbeat_tests.rs +11 -9
  119. package/sdk-core/tests/integ_tests/polling_tests.rs +12 -0
  120. package/sdk-core/tests/integ_tests/queries_tests.rs +39 -22
  121. package/sdk-core/tests/integ_tests/workflow_tests/activities.rs +49 -4
  122. package/sdk-core/tests/integ_tests/workflow_tests/appdata_propagation.rs +61 -0
  123. package/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +1 -1
  124. package/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +74 -13
  125. package/sdk-core/tests/integ_tests/workflow_tests/replay.rs +19 -0
  126. package/sdk-core/tests/integ_tests/workflow_tests/resets.rs +1 -1
  127. package/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +6 -3
  128. package/sdk-core/tests/integ_tests/workflow_tests.rs +10 -23
  129. package/sdk-core/tests/load_tests.rs +8 -3
  130. package/sdk-core/tests/main.rs +7 -3
  131. package/src/conversions.rs +149 -70
  132. package/src/errors.rs +10 -21
  133. package/src/lib.rs +400 -319
  134. package/sdk-core/core/src/pending_activations.rs +0 -173
  135. package/sdk-core/core/src/worker/wft_delivery.rs +0 -81
  136. package/sdk-core/core/src/workflow/mod.rs +0 -478
  137. package/sdk-core/core/src/workflow/workflow_tasks/cache_manager.rs +0 -194
  138. package/sdk-core/core/src/workflow/workflow_tasks/concurrency_manager.rs +0 -418
  139. package/sdk-core/core/src/workflow/workflow_tasks/mod.rs +0 -989
@@ -9,17 +9,16 @@
9
9
  pub extern crate assert_matches;
10
10
  #[macro_use]
11
11
  extern crate tracing;
12
+ extern crate core;
12
13
 
13
14
  mod abstractions;
14
15
  mod log_export;
15
- mod pending_activations;
16
16
  mod pollers;
17
17
  mod protosext;
18
18
  pub mod replay;
19
19
  pub(crate) mod retry_logic;
20
20
  pub(crate) mod telemetry;
21
21
  mod worker;
22
- mod workflow;
23
22
 
24
23
  #[cfg(test)]
25
24
  mod core_tests;
@@ -34,7 +33,8 @@ pub use pollers::{
34
33
  TlsConfig, WorkflowClientTrait,
35
34
  };
36
35
  pub use telemetry::{
37
- fetch_global_buffered_logs, telemetry_init, TelemetryOptions, TelemetryOptionsBuilder,
36
+ fetch_global_buffered_logs, telemetry_init, Logger, MetricsExporter, OtelCollectorOptions,
37
+ TelemetryOptions, TelemetryOptionsBuilder, TraceExporter,
38
38
  };
39
39
  pub use temporal_sdk_core_api as api;
40
40
  pub use temporal_sdk_core_protos as protos;
@@ -68,11 +68,14 @@ where
68
68
  CT: Into<AnyClient>,
69
69
  {
70
70
  let as_enum = client.into();
71
- // TODO: Assert namespaces match
72
71
  let client = match as_enum {
73
72
  AnyClient::HighLevel(ac) => ac,
74
73
  AnyClient::LowLevel(ll) => {
75
- let client = Client::new(*ll, worker_config.namespace.clone());
74
+ let mut client = Client::new(*ll, worker_config.namespace.clone());
75
+ client.set_worker_build_id(worker_config.worker_build_id.clone());
76
+ if let Some(ref id_override) = worker_config.client_identity_override {
77
+ client.options_mut().identity = id_override.clone();
78
+ }
76
79
  let retry_client = RetryClient::new(client, RetryConfig::default());
77
80
  Arc::new(retry_client)
78
81
  }
@@ -17,14 +17,15 @@ use temporal_sdk_core_protos::temporal::api::workflowservice::v1::{
17
17
  use tokio::{
18
18
  sync::{
19
19
  mpsc::{channel, Receiver},
20
- watch, Mutex, Semaphore,
20
+ Mutex, Semaphore,
21
21
  },
22
22
  task::JoinHandle,
23
23
  };
24
+ use tokio_util::sync::CancellationToken;
24
25
 
25
26
  pub struct LongPollBuffer<T> {
26
27
  buffered_polls: Mutex<Receiver<pollers::Result<T>>>,
27
- shutdown: watch::Sender<bool>,
28
+ shutdown: CancellationToken,
28
29
  /// This semaphore exists to ensure that we only poll server as many times as core actually
29
30
  /// *asked* it to be polled - otherwise we might spin and buffer polls constantly. This also
30
31
  /// means unit tests can continue to function in a predictable manner when calling mocks.
@@ -56,6 +57,7 @@ where
56
57
  poll_fn: impl Fn() -> FT + Send + Sync + 'static,
57
58
  max_pollers: usize,
58
59
  buffer_size: usize,
60
+ shutdown: CancellationToken,
59
61
  ) -> Self
60
62
  where
61
63
  FT: Future<Output = pollers::Result<T>> + Send,
@@ -63,28 +65,27 @@ where
63
65
  let (tx, rx) = channel(buffer_size);
64
66
  let polls_requested = Arc::new(Semaphore::new(0));
65
67
  let active_pollers = Arc::new(AtomicUsize::new(0));
66
- let (shutdown_tx, shutdown_rx) = watch::channel(false);
67
68
  let join_handles = FuturesUnordered::new();
68
69
  let pf = Arc::new(poll_fn);
69
70
  for _ in 0..max_pollers {
70
71
  let tx = tx.clone();
71
72
  let pf = pf.clone();
72
- let mut shutdown = shutdown_rx.clone();
73
+ let shutdown = shutdown.clone();
73
74
  let polls_requested = polls_requested.clone();
74
75
  let ap = active_pollers.clone();
75
76
  let jh = tokio::spawn(async move {
76
77
  loop {
77
- if *shutdown.borrow() {
78
+ if shutdown.is_cancelled() {
78
79
  break;
79
80
  }
80
81
  let sp = tokio::select! {
81
82
  sp = polls_requested.acquire() => sp.expect("Polls semaphore not dropped"),
82
- _ = shutdown.changed() => continue,
83
+ _ = shutdown.cancelled() => continue,
83
84
  };
84
85
  let _active_guard = ActiveCounter::new(ap.as_ref());
85
86
  let r = tokio::select! {
86
87
  r = pf() => r,
87
- _ = shutdown.changed() => continue,
88
+ _ = shutdown.cancelled() => continue,
88
89
  };
89
90
  sp.forget();
90
91
  let _ = tx.send(r).await;
@@ -94,7 +95,7 @@ where
94
95
  }
95
96
  Self {
96
97
  buffered_polls: Mutex::new(rx),
97
- shutdown: shutdown_tx,
98
+ shutdown,
98
99
  polls_requested,
99
100
  join_handles,
100
101
  num_pollers_changed: None,
@@ -142,11 +143,11 @@ where
142
143
  }
143
144
 
144
145
  fn notify_shutdown(&self) {
145
- let _ = self.shutdown.send(true);
146
+ self.shutdown.cancel();
146
147
  }
147
148
 
148
149
  async fn shutdown(mut self) {
149
- let _ = self.shutdown.send(true);
150
+ self.notify_shutdown();
150
151
  while self.join_handles.next().await.is_some() {}
151
152
  }
152
153
 
@@ -203,6 +204,7 @@ pub(crate) fn new_workflow_task_buffer(
203
204
  is_sticky: bool,
204
205
  concurrent_pollers: usize,
205
206
  buffer_size: usize,
207
+ shutdown: CancellationToken,
206
208
  ) -> PollWorkflowTaskBuffer {
207
209
  LongPollBuffer::new(
208
210
  move || {
@@ -212,6 +214,7 @@ pub(crate) fn new_workflow_task_buffer(
212
214
  },
213
215
  concurrent_pollers,
214
216
  buffer_size,
217
+ shutdown,
215
218
  )
216
219
  }
217
220
 
@@ -222,6 +225,7 @@ pub(crate) fn new_activity_task_buffer(
222
225
  concurrent_pollers: usize,
223
226
  buffer_size: usize,
224
227
  max_tps: Option<f64>,
228
+ shutdown: CancellationToken,
225
229
  ) -> PollActivityTaskBuffer {
226
230
  LongPollBuffer::new(
227
231
  move || {
@@ -231,6 +235,7 @@ pub(crate) fn new_activity_task_buffer(
231
235
  },
232
236
  concurrent_pollers,
233
237
  buffer_size,
238
+ shutdown,
234
239
  )
235
240
  }
236
241
 
@@ -262,6 +267,7 @@ mod tests {
262
267
  false,
263
268
  1,
264
269
  1,
270
+ CancellationToken::new(),
265
271
  );
266
272
 
267
273
  // Poll a bunch of times, "interrupting" it each time, we should only actually have polled
@@ -1,6 +1,6 @@
1
1
  use crate::{
2
- worker::LocalActivityExecutionResult, workflow::LEGACY_QUERY_ID, CompleteActivityError,
3
- TaskToken,
2
+ worker::{LocalActivityExecutionResult, LEGACY_QUERY_ID},
3
+ CompleteActivityError, TaskToken,
4
4
  };
5
5
  use anyhow::anyhow;
6
6
  use std::{
@@ -15,7 +15,7 @@ use temporal_sdk_core_protos::{
15
15
  activity_result::{activity_execution_result, activity_execution_result::Status},
16
16
  common::{
17
17
  decode_change_marker_details, extract_local_activity_marker_data,
18
- extract_local_activity_marker_details, Payload as SDKPayload, RetryPolicy,
18
+ extract_local_activity_marker_details,
19
19
  },
20
20
  external_data::LocalActivityMarkerData,
21
21
  workflow_activation::{
@@ -28,7 +28,7 @@ use temporal_sdk_core_protos::{
28
28
  workflow_completion,
29
29
  },
30
30
  temporal::api::{
31
- common::v1::{Payload, WorkflowExecution},
31
+ common::v1::{Payload, RetryPolicy, WorkflowExecution},
32
32
  enums::v1::EventType,
33
33
  failure::v1::Failure,
34
34
  history::v1::{history_event, History, HistoryEvent, MarkerRecordedEventAttributes},
@@ -264,8 +264,8 @@ pub struct ValidScheduleLA {
264
264
  pub activity_type: String,
265
265
  pub attempt: u32,
266
266
  pub original_schedule_time: Option<SystemTime>,
267
- pub headers: HashMap<String, SDKPayload>,
268
- pub arguments: Vec<SDKPayload>,
267
+ pub headers: HashMap<String, Payload>,
268
+ pub arguments: Vec<Payload>,
269
269
  pub schedule_to_start_timeout: Option<Duration>,
270
270
  pub close_timeouts: LACloseTimeouts,
271
271
  pub retry_policy: RetryPolicy,
@@ -359,9 +359,7 @@ impl ValidScheduleLA {
359
359
  ))
360
360
  }
361
361
  };
362
- let retry_policy = v
363
- .retry_policy
364
- .ok_or_else(|| anyhow!("Retry policy must be defined!"))?;
362
+ let retry_policy = v.retry_policy.unwrap_or_default();
365
363
  let local_retry_threshold = v
366
364
  .local_retry_threshold
367
365
  .clone()
@@ -1,5 +1,8 @@
1
1
  use std::time::Duration;
2
- use temporal_sdk_core_protos::{coresdk::common::RetryPolicy, utilities::TryIntoOrNone};
2
+ use temporal_sdk_core_protos::{
3
+ temporal::api::{common::v1::RetryPolicy, failure::v1::ApplicationFailureInfo},
4
+ utilities::TryIntoOrNone,
5
+ };
3
6
 
4
7
  pub(crate) trait RetryPolicyExt {
5
8
  /// Ask this retry policy if a retry should be performed. Caller provides the current attempt
@@ -7,11 +10,31 @@ pub(crate) trait RetryPolicyExt {
7
10
  ///
8
11
  /// Returns `None` if it should not, otherwise a duration indicating how long to wait before
9
12
  /// performing the retry.
10
- fn should_retry(&self, attempt_number: usize, err_type_str: &str) -> Option<Duration>;
13
+ ///
14
+ /// Applies defaults to missing fields:
15
+ /// `initial_interval` - 1 second
16
+ /// `maximum_interval` - 100 x initial_interval
17
+ /// `backoff_coefficient` - 2.0
18
+ fn should_retry(
19
+ &self,
20
+ attempt_number: usize,
21
+ application_failure: Option<&ApplicationFailureInfo>,
22
+ ) -> Option<Duration>;
11
23
  }
12
24
 
13
25
  impl RetryPolicyExt for RetryPolicy {
14
- fn should_retry(&self, attempt_number: usize, err_type_str: &str) -> Option<Duration> {
26
+ fn should_retry(
27
+ &self,
28
+ attempt_number: usize,
29
+ application_failure: Option<&ApplicationFailureInfo>,
30
+ ) -> Option<Duration> {
31
+ let non_retryable = application_failure
32
+ .map(|f| f.non_retryable)
33
+ .unwrap_or_default();
34
+ if non_retryable {
35
+ return None;
36
+ }
37
+ let err_type_str = application_failure.map_or("", |f| &f.r#type);
15
38
  let realmax = self.maximum_attempts.max(0);
16
39
  if realmax > 0 && attempt_number >= realmax as usize {
17
40
  return None;
@@ -23,7 +46,11 @@ impl RetryPolicyExt for RetryPolicy {
23
46
  }
24
47
  }
25
48
 
26
- let converted_interval = self.initial_interval.clone().try_into_or_none();
49
+ let converted_interval = self
50
+ .initial_interval
51
+ .clone()
52
+ .try_into_or_none()
53
+ .or(Some(Duration::from_secs(1)));
27
54
  if attempt_number == 1 {
28
55
  return converted_interval;
29
56
  }
@@ -74,32 +101,32 @@ mod tests {
74
101
  maximum_attempts: 10,
75
102
  non_retryable_error_types: vec![],
76
103
  };
77
- let res = rp.should_retry(1, "").unwrap();
104
+ let res = rp.should_retry(1, None).unwrap();
78
105
  assert_eq!(res.as_millis(), 1_000);
79
- let res = rp.should_retry(2, "").unwrap();
106
+ let res = rp.should_retry(2, None).unwrap();
80
107
  assert_eq!(res.as_millis(), 2_000);
81
- let res = rp.should_retry(3, "").unwrap();
108
+ let res = rp.should_retry(3, None).unwrap();
82
109
  assert_eq!(res.as_millis(), 4_000);
83
- let res = rp.should_retry(4, "").unwrap();
110
+ let res = rp.should_retry(4, None).unwrap();
84
111
  assert_eq!(res.as_millis(), 8_000);
85
- let res = rp.should_retry(5, "").unwrap();
112
+ let res = rp.should_retry(5, None).unwrap();
86
113
  assert_eq!(res.as_millis(), 10_000);
87
- let res = rp.should_retry(6, "").unwrap();
114
+ let res = rp.should_retry(6, None).unwrap();
88
115
  assert_eq!(res.as_millis(), 10_000);
89
116
  // Max attempts - no retry
90
- assert!(rp.should_retry(10, "").is_none());
117
+ assert!(rp.should_retry(10, None).is_none());
91
118
  }
92
119
 
93
120
  #[test]
94
121
  fn no_interval_no_backoff() {
95
122
  let rp = RetryPolicy {
96
123
  initial_interval: None,
97
- backoff_coefficient: 2.0,
124
+ backoff_coefficient: 0.,
98
125
  maximum_interval: None,
99
126
  maximum_attempts: 10,
100
127
  non_retryable_error_types: vec![],
101
128
  };
102
- assert!(rp.should_retry(1, "").is_none());
129
+ assert!(rp.should_retry(1, None).is_some());
103
130
  }
104
131
 
105
132
  #[test]
@@ -112,7 +139,7 @@ mod tests {
112
139
  non_retryable_error_types: vec![],
113
140
  };
114
141
  for i in 0..50 {
115
- assert!(rp.should_retry(i, "").is_some());
142
+ assert!(rp.should_retry(i, None).is_some());
116
143
  }
117
144
  }
118
145
 
@@ -126,7 +153,7 @@ mod tests {
126
153
  non_retryable_error_types: vec![],
127
154
  };
128
155
  for i in 0..50 {
129
- assert!(rp.should_retry(i, "").is_some());
156
+ assert!(rp.should_retry(i, None).is_some());
130
157
  }
131
158
  }
132
159
 
@@ -139,6 +166,36 @@ mod tests {
139
166
  maximum_attempts: 10,
140
167
  non_retryable_error_types: vec!["no retry".to_string()],
141
168
  };
142
- assert!(rp.should_retry(1, "no retry").is_none());
169
+ assert!(rp
170
+ .should_retry(
171
+ 1,
172
+ Some(&ApplicationFailureInfo {
173
+ r#type: "no retry".to_string(),
174
+ non_retryable: false,
175
+ details: None,
176
+ })
177
+ )
178
+ .is_none());
179
+ }
180
+
181
+ #[test]
182
+ fn no_non_retryable_application_failure() {
183
+ let rp = RetryPolicy {
184
+ initial_interval: Some(Duration::from_secs(1).into()),
185
+ backoff_coefficient: 2.0,
186
+ maximum_interval: Some(Duration::from_secs(10).into()),
187
+ maximum_attempts: 10,
188
+ non_retryable_error_types: vec![],
189
+ };
190
+ assert!(rp
191
+ .should_retry(
192
+ 1,
193
+ Some(&ApplicationFailureInfo {
194
+ r#type: "".to_string(),
195
+ non_retryable: true,
196
+ details: None,
197
+ })
198
+ )
199
+ .is_none());
143
200
  }
144
201
  }
@@ -1,4 +1,5 @@
1
1
  use super::TELEM_SERVICE_NAME;
2
+ use crate::telemetry::GLOBAL_TELEM_DAT;
2
3
  use opentelemetry::{
3
4
  global,
4
5
  metrics::{Counter, Descriptor, InstrumentKind, Meter, ValueRecorder},
@@ -16,9 +17,6 @@ use std::{borrow::Cow, sync::Arc, time::Duration};
16
17
  /// appropriate k/vs have already been set.
17
18
  #[derive(Default, Clone, Debug)]
18
19
  pub(crate) struct MetricsContext {
19
- // TODO: Ideally this would hold bound metrics, but using them is basically impossible because
20
- // of lifetime issues: https://github.com/open-telemetry/opentelemetry-rust/issues/629
21
- // Use once fixed.
22
20
  kvs: Arc<Vec<KeyValue>>,
23
21
  }
24
22
 
@@ -159,6 +157,18 @@ lazy_static::lazy_static! {
159
157
  global::meter(TELEM_SERVICE_NAME)
160
158
  };
161
159
  }
160
+ fn metric_prefix() -> &'static str {
161
+ GLOBAL_TELEM_DAT
162
+ .get()
163
+ .map(|gtd| {
164
+ if gtd.no_temporal_prefix_for_metrics {
165
+ ""
166
+ } else {
167
+ "temporal_"
168
+ }
169
+ })
170
+ .unwrap_or("")
171
+ }
162
172
 
163
173
  /// Define a temporal metric. All metrics are kept private to this file, and should be accessed
164
174
  /// through functions on the [MetricsContext]
@@ -166,14 +176,14 @@ macro_rules! tm {
166
176
  (ctr, $ident:ident, $name:expr) => {
167
177
  lazy_static::lazy_static! {
168
178
  static ref $ident: Counter<u64> = {
169
- METRIC_METER.u64_counter($name).init()
179
+ METRIC_METER.u64_counter(metric_prefix().to_string() + $name).init()
170
180
  };
171
181
  }
172
182
  };
173
183
  (vr_u64, $ident:ident, $name:expr) => {
174
184
  lazy_static::lazy_static! {
175
185
  static ref $ident: ValueRecorder<u64> = {
176
- METRIC_METER.u64_value_recorder($name).init()
186
+ METRIC_METER.u64_value_recorder(metric_prefix().to_string() + $name).init()
177
187
  };
178
188
  }
179
189
  };
@@ -334,8 +344,12 @@ impl AggregatorSelector for SDKAggSelector {
334
344
  }
335
345
 
336
346
  if *descriptor.instrument_kind() == InstrumentKind::ValueRecorder {
347
+ let dname = descriptor
348
+ .name()
349
+ .strip_prefix(metric_prefix())
350
+ .unwrap_or_else(|| descriptor.name());
337
351
  // Some recorders are just gauges
338
- match descriptor.name() {
352
+ match dname {
339
353
  STICKY_CACHE_SIZE_NAME | NUM_POLLERS_NAME | TASK_SLOTS_AVAILABLE_NAME => {
340
354
  return Some(Arc::new(last_value()))
341
355
  }
@@ -343,7 +357,7 @@ impl AggregatorSelector for SDKAggSelector {
343
357
  }
344
358
 
345
359
  // Other recorders will select their appropriate buckets
346
- let buckets = match descriptor.name() {
360
+ let buckets = match dname {
347
361
  WF_E2E_LATENCY_NAME => WF_LATENCY_MS_BUCKETS,
348
362
  WF_TASK_EXECUTION_LATENCY_NAME | WF_TASK_REPLAY_LATENCY_NAME => WF_TASK_MS_BUCKETS,
349
363
  WF_TASK_SCHED_TO_START_LATENCY_NAME | ACT_SCHED_TO_START_LATENCY_NAME => {