temporalio 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (232) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +175 -4
  3. data/bridge/Cargo.lock +44 -21
  4. data/bridge/Cargo.toml +1 -0
  5. data/bridge/sdk-core/Cargo.toml +1 -1
  6. data/bridge/sdk-core/README.md +1 -4
  7. data/bridge/sdk-core/client/Cargo.toml +1 -1
  8. data/bridge/sdk-core/client/src/lib.rs +12 -20
  9. data/bridge/sdk-core/client/src/raw.rs +9 -8
  10. data/bridge/sdk-core/client/src/retry.rs +100 -23
  11. data/bridge/sdk-core/core/Cargo.toml +7 -7
  12. data/bridge/sdk-core/core/benches/workflow_replay.rs +13 -10
  13. data/bridge/sdk-core/core/src/abstractions.rs +22 -22
  14. data/bridge/sdk-core/core/src/core_tests/activity_tasks.rs +146 -43
  15. data/bridge/sdk-core/core/src/core_tests/local_activities.rs +419 -9
  16. data/bridge/sdk-core/core/src/core_tests/queries.rs +247 -89
  17. data/bridge/sdk-core/core/src/core_tests/workers.rs +2 -2
  18. data/bridge/sdk-core/core/src/core_tests/workflow_cancels.rs +1 -1
  19. data/bridge/sdk-core/core/src/core_tests/workflow_tasks.rs +47 -27
  20. data/bridge/sdk-core/core/src/lib.rs +139 -32
  21. data/bridge/sdk-core/core/src/protosext/mod.rs +1 -1
  22. data/bridge/sdk-core/core/src/replay/mod.rs +185 -41
  23. data/bridge/sdk-core/core/src/telemetry/log_export.rs +190 -0
  24. data/bridge/sdk-core/core/src/telemetry/metrics.rs +184 -139
  25. data/bridge/sdk-core/core/src/telemetry/mod.rs +310 -315
  26. data/bridge/sdk-core/core/src/telemetry/prometheus_server.rs +4 -3
  27. data/bridge/sdk-core/core/src/test_help/mod.rs +23 -9
  28. data/bridge/sdk-core/core/src/worker/activities/local_activities.rs +12 -6
  29. data/bridge/sdk-core/core/src/worker/activities.rs +40 -23
  30. data/bridge/sdk-core/core/src/worker/client/mocks.rs +1 -1
  31. data/bridge/sdk-core/core/src/worker/client.rs +30 -4
  32. data/bridge/sdk-core/core/src/worker/mod.rs +23 -19
  33. data/bridge/sdk-core/core/src/worker/workflow/driven_workflow.rs +10 -19
  34. data/bridge/sdk-core/core/src/worker/workflow/history_update.rs +99 -25
  35. data/bridge/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +1 -5
  36. data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +1 -5
  37. data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +1 -5
  38. data/bridge/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +3 -5
  39. data/bridge/sdk-core/core/src/worker/workflow/machines/complete_workflow_state_machine.rs +1 -5
  40. data/bridge/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +2 -6
  41. data/bridge/sdk-core/core/src/worker/workflow/machines/fail_workflow_state_machine.rs +1 -5
  42. data/bridge/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +24 -22
  43. data/bridge/sdk-core/core/src/worker/workflow/machines/mod.rs +12 -38
  44. data/bridge/sdk-core/core/src/worker/workflow/machines/modify_workflow_properties_state_machine.rs +178 -0
  45. data/bridge/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +1 -5
  46. data/bridge/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +1 -5
  47. data/bridge/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +1 -5
  48. data/bridge/sdk-core/core/src/worker/workflow/machines/transition_coverage.rs +8 -2
  49. data/bridge/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +1 -5
  50. data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_machines/local_acts.rs +1 -1
  51. data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +233 -217
  52. data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_task_state_machine.rs +1 -6
  53. data/bridge/sdk-core/core/src/worker/workflow/managed_run/managed_wf_test.rs +4 -4
  54. data/bridge/sdk-core/core/src/worker/workflow/managed_run.rs +13 -5
  55. data/bridge/sdk-core/core/src/worker/workflow/mod.rs +86 -29
  56. data/bridge/sdk-core/core/src/worker/workflow/wft_poller.rs +2 -2
  57. data/bridge/sdk-core/core/src/worker/workflow/workflow_stream.rs +56 -11
  58. data/bridge/sdk-core/core-api/Cargo.toml +4 -3
  59. data/bridge/sdk-core/core-api/src/lib.rs +1 -43
  60. data/bridge/sdk-core/core-api/src/telemetry.rs +147 -0
  61. data/bridge/sdk-core/core-api/src/worker.rs +13 -0
  62. data/bridge/sdk-core/etc/deps.svg +115 -140
  63. data/bridge/sdk-core/etc/regen-depgraph.sh +5 -0
  64. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.stderr +1 -1
  65. data/bridge/sdk-core/histories/evict_while_la_running_no_interference-23_history.bin +0 -0
  66. data/bridge/sdk-core/histories/evict_while_la_running_no_interference-85_history.bin +0 -0
  67. data/bridge/sdk-core/protos/api_upstream/buf.yaml +0 -3
  68. data/bridge/sdk-core/protos/api_upstream/build/go.mod +7 -0
  69. data/bridge/sdk-core/protos/api_upstream/build/go.sum +5 -0
  70. data/bridge/sdk-core/protos/api_upstream/{temporal/api/update/v1/message.proto → build/tools.go} +6 -23
  71. data/bridge/sdk-core/protos/api_upstream/go.mod +6 -0
  72. data/bridge/sdk-core/protos/api_upstream/temporal/api/batch/v1/message.proto +12 -9
  73. data/bridge/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +20 -19
  74. data/bridge/sdk-core/protos/api_upstream/temporal/api/common/v1/message.proto +2 -2
  75. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/batch_operation.proto +3 -2
  76. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/command_type.proto +4 -4
  77. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/common.proto +3 -2
  78. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/event_type.proto +5 -3
  79. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +23 -2
  80. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/{cluster.proto → interaction_type.proto} +10 -11
  81. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/namespace.proto +2 -2
  82. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/query.proto +2 -2
  83. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/reset.proto +2 -2
  84. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/schedule.proto +2 -2
  85. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +2 -2
  86. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/update.proto +2 -13
  87. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/workflow.proto +2 -2
  88. data/bridge/sdk-core/protos/api_upstream/temporal/api/errordetails/v1/message.proto +2 -2
  89. data/bridge/sdk-core/protos/api_upstream/temporal/api/failure/v1/message.proto +2 -2
  90. data/bridge/sdk-core/protos/api_upstream/temporal/api/filter/v1/message.proto +2 -2
  91. data/bridge/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +26 -19
  92. data/bridge/sdk-core/protos/api_upstream/temporal/api/interaction/v1/message.proto +87 -0
  93. data/bridge/sdk-core/protos/api_upstream/temporal/api/namespace/v1/message.proto +2 -2
  94. data/bridge/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +21 -61
  95. data/bridge/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/service.proto +2 -21
  96. data/bridge/sdk-core/protos/api_upstream/temporal/api/query/v1/message.proto +2 -2
  97. data/bridge/sdk-core/protos/api_upstream/temporal/api/replication/v1/message.proto +2 -2
  98. data/bridge/sdk-core/protos/api_upstream/temporal/api/schedule/v1/message.proto +110 -31
  99. data/bridge/sdk-core/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +4 -4
  100. data/bridge/sdk-core/protos/api_upstream/temporal/api/version/v1/message.proto +2 -2
  101. data/bridge/sdk-core/protos/api_upstream/temporal/api/workflow/v1/message.proto +3 -2
  102. data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +60 -16
  103. data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +17 -3
  104. data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +2 -0
  105. data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +8 -1
  106. data/bridge/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/request_response.proto +2 -2
  107. data/bridge/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/service.proto +2 -2
  108. data/bridge/sdk-core/sdk/Cargo.toml +2 -2
  109. data/bridge/sdk-core/sdk/src/interceptors.rs +36 -3
  110. data/bridge/sdk-core/sdk/src/lib.rs +7 -5
  111. data/bridge/sdk-core/sdk/src/workflow_context.rs +13 -2
  112. data/bridge/sdk-core/sdk/src/workflow_future.rs +3 -7
  113. data/bridge/sdk-core/sdk-core-protos/Cargo.toml +1 -1
  114. data/bridge/sdk-core/sdk-core-protos/build.rs +0 -1
  115. data/bridge/sdk-core/sdk-core-protos/src/history_builder.rs +65 -18
  116. data/bridge/sdk-core/sdk-core-protos/src/history_info.rs +22 -22
  117. data/bridge/sdk-core/sdk-core-protos/src/lib.rs +104 -44
  118. data/bridge/sdk-core/test-utils/Cargo.toml +2 -1
  119. data/bridge/sdk-core/test-utils/src/lib.rs +81 -29
  120. data/bridge/sdk-core/tests/integ_tests/heartbeat_tests.rs +5 -2
  121. data/bridge/sdk-core/tests/integ_tests/metrics_tests.rs +37 -0
  122. data/bridge/sdk-core/tests/integ_tests/polling_tests.rs +0 -13
  123. data/bridge/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +167 -13
  124. data/bridge/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +53 -0
  125. data/bridge/sdk-core/tests/integ_tests/workflow_tests/replay.rs +106 -20
  126. data/bridge/sdk-core/tests/integ_tests/workflow_tests.rs +18 -8
  127. data/bridge/sdk-core/tests/main.rs +6 -4
  128. data/bridge/src/connection.rs +81 -62
  129. data/bridge/src/lib.rs +92 -33
  130. data/bridge/src/runtime.rs +9 -2
  131. data/bridge/src/worker.rs +53 -2
  132. data/lib/bridge.so +0 -0
  133. data/lib/gen/temporal/api/batch/v1/message_pb.rb +8 -6
  134. data/lib/gen/temporal/api/command/v1/message_pb.rb +17 -9
  135. data/lib/gen/temporal/api/common/v1/message_pb.rb +1 -1
  136. data/lib/gen/temporal/api/enums/v1/batch_operation_pb.rb +2 -1
  137. data/lib/gen/temporal/api/enums/v1/command_type_pb.rb +3 -1
  138. data/lib/gen/temporal/api/enums/v1/common_pb.rb +2 -1
  139. data/lib/gen/temporal/api/enums/v1/event_type_pb.rb +3 -2
  140. data/lib/gen/temporal/api/enums/v1/failed_cause_pb.rb +7 -1
  141. data/lib/gen/temporal/api/enums/v1/interaction_type_pb.rb +25 -0
  142. data/lib/gen/temporal/api/enums/v1/namespace_pb.rb +1 -1
  143. data/lib/gen/temporal/api/enums/v1/query_pb.rb +1 -1
  144. data/lib/gen/temporal/api/enums/v1/reset_pb.rb +1 -1
  145. data/lib/gen/temporal/api/enums/v1/schedule_pb.rb +1 -1
  146. data/lib/gen/temporal/api/enums/v1/task_queue_pb.rb +1 -1
  147. data/lib/gen/temporal/api/enums/v1/update_pb.rb +1 -6
  148. data/lib/gen/temporal/api/enums/v1/workflow_pb.rb +1 -1
  149. data/lib/gen/temporal/api/errordetails/v1/message_pb.rb +1 -1
  150. data/lib/gen/temporal/api/failure/v1/message_pb.rb +1 -1
  151. data/lib/gen/temporal/api/filter/v1/message_pb.rb +1 -1
  152. data/lib/gen/temporal/api/history/v1/message_pb.rb +19 -18
  153. data/lib/gen/temporal/api/interaction/v1/message_pb.rb +49 -0
  154. data/lib/gen/temporal/api/namespace/v1/message_pb.rb +1 -1
  155. data/lib/gen/temporal/api/operatorservice/v1/request_response_pb.rb +11 -51
  156. data/lib/gen/temporal/api/operatorservice/v1/service_pb.rb +1 -1
  157. data/lib/gen/temporal/api/query/v1/message_pb.rb +1 -1
  158. data/lib/gen/temporal/api/replication/v1/message_pb.rb +1 -1
  159. data/lib/gen/temporal/api/schedule/v1/message_pb.rb +22 -1
  160. data/lib/gen/temporal/api/taskqueue/v1/message_pb.rb +2 -2
  161. data/lib/gen/temporal/api/version/v1/message_pb.rb +1 -1
  162. data/lib/gen/temporal/api/workflow/v1/message_pb.rb +2 -1
  163. data/lib/gen/temporal/api/workflowservice/v1/request_response_pb.rb +27 -10
  164. data/lib/gen/temporal/api/workflowservice/v1/service_pb.rb +1 -1
  165. data/lib/gen/temporal/sdk/core/workflow_activation/workflow_activation_pb.rb +1 -0
  166. data/lib/gen/temporal/sdk/core/workflow_commands/workflow_commands_pb.rb +5 -1
  167. data/lib/temporalio/activity/context.rb +97 -0
  168. data/lib/temporalio/activity/info.rb +67 -0
  169. data/lib/temporalio/activity.rb +85 -0
  170. data/lib/temporalio/bridge/error.rb +8 -0
  171. data/lib/temporalio/bridge.rb +14 -0
  172. data/lib/{temporal → temporalio}/client/implementation.rb +49 -48
  173. data/lib/{temporal → temporalio}/client/workflow_handle.rb +35 -35
  174. data/lib/{temporal → temporalio}/client.rb +19 -32
  175. data/lib/{temporal → temporalio}/connection.rb +238 -223
  176. data/lib/{temporal → temporalio}/data_converter.rb +76 -35
  177. data/lib/{temporal → temporalio}/error/failure.rb +6 -6
  178. data/lib/{temporal → temporalio}/error/workflow_failure.rb +4 -2
  179. data/lib/{temporal → temporalio}/errors.rb +19 -1
  180. data/lib/{temporal → temporalio}/failure_converter/base.rb +5 -5
  181. data/lib/{temporal → temporalio}/failure_converter/basic.rb +58 -52
  182. data/lib/temporalio/failure_converter.rb +7 -0
  183. data/lib/{temporal → temporalio}/interceptor/chain.rb +2 -1
  184. data/lib/{temporal → temporalio}/interceptor/client.rb +22 -1
  185. data/lib/{temporal → temporalio}/payload_codec/base.rb +5 -5
  186. data/lib/{temporal → temporalio}/payload_converter/base.rb +3 -3
  187. data/lib/{temporal → temporalio}/payload_converter/bytes.rb +4 -3
  188. data/lib/{temporal → temporalio}/payload_converter/composite.rb +7 -5
  189. data/lib/{temporal → temporalio}/payload_converter/encoding_base.rb +4 -4
  190. data/lib/{temporal → temporalio}/payload_converter/json.rb +4 -3
  191. data/lib/{temporal → temporalio}/payload_converter/nil.rb +4 -3
  192. data/lib/temporalio/payload_converter.rb +14 -0
  193. data/lib/{temporal → temporalio}/retry_policy.rb +4 -4
  194. data/lib/{temporal → temporalio}/retry_state.rb +1 -1
  195. data/lib/temporalio/runtime.rb +25 -0
  196. data/lib/{temporal → temporalio}/timeout_type.rb +2 -2
  197. data/lib/temporalio/version.rb +3 -0
  198. data/lib/temporalio/worker/activity_runner.rb +92 -0
  199. data/lib/temporalio/worker/activity_worker.rb +138 -0
  200. data/lib/temporalio/worker/reactor.rb +46 -0
  201. data/lib/temporalio/worker/runner.rb +63 -0
  202. data/lib/temporalio/worker/sync_worker.rb +88 -0
  203. data/lib/temporalio/worker/thread_pool_executor.rb +51 -0
  204. data/lib/temporalio/worker.rb +198 -0
  205. data/lib/{temporal → temporalio}/workflow/execution_info.rb +4 -4
  206. data/lib/{temporal → temporalio}/workflow/execution_status.rb +1 -1
  207. data/lib/{temporal → temporalio}/workflow/id_reuse_policy.rb +6 -6
  208. data/lib/{temporal → temporalio}/workflow/query_reject_condition.rb +5 -5
  209. data/lib/temporalio.rb +12 -3
  210. data/temporalio.gemspec +7 -3
  211. metadata +79 -56
  212. data/bridge/sdk-core/bridge-ffi/Cargo.toml +0 -24
  213. data/bridge/sdk-core/bridge-ffi/LICENSE.txt +0 -23
  214. data/bridge/sdk-core/bridge-ffi/build.rs +0 -25
  215. data/bridge/sdk-core/bridge-ffi/include/sdk-core-bridge.h +0 -249
  216. data/bridge/sdk-core/bridge-ffi/src/lib.rs +0 -825
  217. data/bridge/sdk-core/bridge-ffi/src/wrappers.rs +0 -211
  218. data/bridge/sdk-core/core/src/log_export.rs +0 -62
  219. data/bridge/sdk-core/core/src/worker/workflow/machines/mutable_side_effect_state_machine.rs +0 -127
  220. data/bridge/sdk-core/core/src/worker/workflow/machines/side_effect_state_machine.rs +0 -71
  221. data/bridge/sdk-core/protos/api_upstream/temporal/api/cluster/v1/message.proto +0 -83
  222. data/bridge/sdk-core/protos/local/temporal/sdk/core/bridge/bridge.proto +0 -210
  223. data/bridge/sdk-core/sdk/src/conversions.rs +0 -8
  224. data/lib/gen/temporal/api/cluster/v1/message_pb.rb +0 -67
  225. data/lib/gen/temporal/api/enums/v1/cluster_pb.rb +0 -26
  226. data/lib/gen/temporal/api/update/v1/message_pb.rb +0 -26
  227. data/lib/temporal/bridge.rb +0 -14
  228. data/lib/temporal/failure_converter.rb +0 -8
  229. data/lib/temporal/payload_converter.rb +0 -14
  230. data/lib/temporal/runtime.rb +0 -22
  231. data/lib/temporal/version.rb +0 -3
  232. data/lib/temporal.rb +0 -8
@@ -0,0 +1,190 @@
1
+ use parking_lot::Mutex;
2
+ use ringbuf::{Consumer, HeapRb, Producer};
3
+ use std::{collections::HashMap, sync::Arc, time::SystemTime};
4
+ use temporal_sdk_core_api::telemetry::CoreLog;
5
+ use tracing_subscriber::Layer;
6
+
7
+ const RB_SIZE: usize = 2048;
8
+
9
+ pub(super) type CoreLogsOut = Consumer<CoreLog, Arc<HeapRb<CoreLog>>>;
10
+
11
+ pub(super) struct CoreLogExportLayer {
12
+ logs_in: Mutex<Producer<CoreLog, Arc<HeapRb<CoreLog>>>>,
13
+ }
14
+
15
+ #[derive(Debug)]
16
+ struct CoreLogFieldStorage(HashMap<String, serde_json::Value>);
17
+
18
+ impl CoreLogExportLayer {
19
+ pub(super) fn new() -> (Self, CoreLogsOut) {
20
+ let (lin, lout) = HeapRb::new(RB_SIZE).split();
21
+ (
22
+ Self {
23
+ logs_in: Mutex::new(lin),
24
+ },
25
+ lout,
26
+ )
27
+ }
28
+ }
29
+
30
+ impl<S> Layer<S> for CoreLogExportLayer
31
+ where
32
+ S: tracing::Subscriber,
33
+ S: for<'lookup> tracing_subscriber::registry::LookupSpan<'lookup>,
34
+ {
35
+ fn on_new_span(
36
+ &self,
37
+ attrs: &tracing::span::Attributes<'_>,
38
+ id: &tracing::span::Id,
39
+ ctx: tracing_subscriber::layer::Context<'_, S>,
40
+ ) {
41
+ let span = ctx.span(id).unwrap();
42
+ let mut fields = HashMap::new();
43
+ let mut visitor = JsonVisitor(&mut fields);
44
+ attrs.record(&mut visitor);
45
+ let storage = CoreLogFieldStorage(fields);
46
+ let mut extensions = span.extensions_mut();
47
+ extensions.insert(storage);
48
+ }
49
+
50
+ fn on_record(
51
+ &self,
52
+ id: &tracing::span::Id,
53
+ values: &tracing::span::Record<'_>,
54
+ ctx: tracing_subscriber::layer::Context<'_, S>,
55
+ ) {
56
+ let span = ctx.span(id).unwrap();
57
+
58
+ let mut extensions_mut = span.extensions_mut();
59
+ let custom_field_storage: &mut CoreLogFieldStorage =
60
+ extensions_mut.get_mut::<CoreLogFieldStorage>().unwrap();
61
+ let json_data = &mut custom_field_storage.0;
62
+
63
+ let mut visitor = JsonVisitor(json_data);
64
+ values.record(&mut visitor);
65
+ }
66
+
67
+ fn on_event(&self, event: &tracing::Event<'_>, ctx: tracing_subscriber::layer::Context<'_, S>) {
68
+ let mut fields = HashMap::new();
69
+ let mut visitor = JsonVisitor(&mut fields);
70
+ event.record(&mut visitor);
71
+
72
+ let mut spans = vec![];
73
+ if let Some(scope) = ctx.event_scope(event) {
74
+ for span in scope.from_root() {
75
+ let extensions = span.extensions();
76
+ let storage = extensions.get::<CoreLogFieldStorage>().unwrap();
77
+ let field_data = &storage.0;
78
+ for (k, v) in field_data {
79
+ fields.insert(k.to_string(), v.clone());
80
+ }
81
+ spans.push(span.name().to_string());
82
+ }
83
+ }
84
+
85
+ // "message" is the magic default field keyname for the string passed to the event
86
+ let message = fields.remove("message").unwrap_or_default();
87
+ let log = CoreLog {
88
+ target: event.metadata().target().to_string(),
89
+ // This weird as_str dance prevents adding extra quotes
90
+ message: message.as_str().unwrap_or_default().to_string(),
91
+ timestamp: SystemTime::now(),
92
+ level: *event.metadata().level(),
93
+ fields,
94
+ span_contexts: spans,
95
+ };
96
+ let _ = self.logs_in.lock().push(log);
97
+ }
98
+ }
99
+
100
+ struct JsonVisitor<'a>(&'a mut HashMap<String, serde_json::Value>);
101
+
102
+ impl<'a> tracing::field::Visit for JsonVisitor<'a> {
103
+ fn record_f64(&mut self, field: &tracing::field::Field, value: f64) {
104
+ self.0
105
+ .insert(field.name().to_string(), serde_json::json!(value));
106
+ }
107
+
108
+ fn record_i64(&mut self, field: &tracing::field::Field, value: i64) {
109
+ self.0
110
+ .insert(field.name().to_string(), serde_json::json!(value));
111
+ }
112
+
113
+ fn record_u64(&mut self, field: &tracing::field::Field, value: u64) {
114
+ self.0
115
+ .insert(field.name().to_string(), serde_json::json!(value));
116
+ }
117
+
118
+ fn record_bool(&mut self, field: &tracing::field::Field, value: bool) {
119
+ self.0
120
+ .insert(field.name().to_string(), serde_json::json!(value));
121
+ }
122
+
123
+ fn record_str(&mut self, field: &tracing::field::Field, value: &str) {
124
+ self.0
125
+ .insert(field.name().to_string(), serde_json::json!(value));
126
+ }
127
+
128
+ fn record_error(
129
+ &mut self,
130
+ field: &tracing::field::Field,
131
+ value: &(dyn std::error::Error + 'static),
132
+ ) {
133
+ self.0.insert(
134
+ field.name().to_string(),
135
+ serde_json::json!(value.to_string()),
136
+ );
137
+ }
138
+
139
+ fn record_debug(&mut self, field: &tracing::field::Field, value: &dyn std::fmt::Debug) {
140
+ self.0.insert(
141
+ field.name().to_string(),
142
+ serde_json::json!(format!("{:?}", value)),
143
+ );
144
+ }
145
+ }
146
+
147
+ #[cfg(test)]
148
+ mod tests {
149
+ use crate::{telemetry::construct_filter_string, telemetry_init};
150
+ use temporal_sdk_core_api::telemetry::{CoreTelemetry, Logger, TelemetryOptionsBuilder};
151
+ use tracing::Level;
152
+
153
+ #[instrument(fields(bros = "brohemian"))]
154
+ fn instrumented(thing: &str) {
155
+ warn!("warn");
156
+ info!(foo = "bar", "info");
157
+ debug!("debug");
158
+ }
159
+
160
+ #[tokio::test]
161
+ async fn test_forwarding_output() {
162
+ let opts = TelemetryOptionsBuilder::default()
163
+ .logging(Logger::Forward {
164
+ filter: construct_filter_string(Level::INFO, Level::WARN),
165
+ })
166
+ .build()
167
+ .unwrap();
168
+ let instance = telemetry_init(opts).unwrap();
169
+ let _g = tracing::subscriber::set_default(instance.trace_subscriber.clone());
170
+
171
+ let top_span = span!(Level::INFO, "yayspan", huh = "wat");
172
+ let _guard = top_span.enter();
173
+ info!("Whata?");
174
+ instrumented("hi");
175
+ info!("Donezo");
176
+
177
+ let logs = instance.fetch_buffered_logs();
178
+ // Verify debug log was not forwarded
179
+ assert!(!logs.iter().any(|l| l.message == "debug"));
180
+ assert_eq!(logs.len(), 4);
181
+ // Ensure fields are attached to events properly
182
+ let info_msg = &logs[2];
183
+ assert_eq!(info_msg.message, "info");
184
+ assert_eq!(info_msg.fields.len(), 4);
185
+ assert_eq!(info_msg.fields.get("huh"), Some(&"wat".into()));
186
+ assert_eq!(info_msg.fields.get("foo"), Some(&"bar".into()));
187
+ assert_eq!(info_msg.fields.get("bros"), Some(&"brohemian".into()));
188
+ assert_eq!(info_msg.fields.get("thing"), Some(&"hi".into()));
189
+ }
190
+ }
@@ -1,38 +1,73 @@
1
- use super::TELEM_SERVICE_NAME;
2
- use crate::telemetry::GLOBAL_TELEM_DAT;
3
- use opentelemetry::sdk::metrics::aggregators::Aggregator;
4
- use opentelemetry::sdk::metrics::sdk_api::{Descriptor, InstrumentKind};
1
+ use crate::telemetry::TelemetryInstance;
5
2
  use opentelemetry::{
6
- global,
7
- metrics::{Counter, Histogram, Meter},
3
+ metrics::{noop::NoopMeterProvider, Counter, Histogram, Meter, MeterProvider},
8
4
  sdk::{
9
5
  export::metrics::AggregatorSelector,
10
- metrics::aggregators::{histogram, last_value, sum},
6
+ metrics::{
7
+ aggregators::{histogram, last_value, sum, Aggregator},
8
+ sdk_api::{Descriptor, InstrumentKind},
9
+ },
11
10
  },
12
11
  Context, KeyValue,
13
12
  };
14
13
  use std::{sync::Arc, time::Duration};
14
+ use temporal_sdk_core_api::telemetry::CoreTelemetry;
15
15
 
16
16
  /// Used to track context associated with metrics, and record/update them
17
17
  ///
18
18
  /// Possible improvement: make generic over some type tag so that methods are only exposed if the
19
19
  /// appropriate k/vs have already been set.
20
- #[derive(Default, Clone, Debug)]
20
+ #[derive(Clone)]
21
21
  pub(crate) struct MetricsContext {
22
22
  ctx: Context,
23
23
  kvs: Arc<Vec<KeyValue>>,
24
+ instruments: Arc<Instruments>,
25
+ }
26
+
27
+ struct Instruments {
28
+ wf_completed_counter: Counter<u64>,
29
+ wf_canceled_counter: Counter<u64>,
30
+ wf_failed_counter: Counter<u64>,
31
+ wf_cont_counter: Counter<u64>,
32
+ wf_e2e_latency: Histogram<u64>,
33
+ wf_task_queue_poll_empty_counter: Counter<u64>,
34
+ wf_task_queue_poll_succeed_counter: Counter<u64>,
35
+ wf_task_execution_failure_counter: Counter<u64>,
36
+ wf_task_sched_to_start_latency: Histogram<u64>,
37
+ wf_task_replay_latency: Histogram<u64>,
38
+ wf_task_execution_latency: Histogram<u64>,
39
+ act_poll_no_task: Counter<u64>,
40
+ act_task_received_counter: Counter<u64>,
41
+ act_execution_failed: Counter<u64>,
42
+ act_sched_to_start_latency: Histogram<u64>,
43
+ act_exec_latency: Histogram<u64>,
44
+ worker_registered: Counter<u64>,
45
+ num_pollers: Histogram<u64>,
46
+ task_slots_available: Histogram<u64>,
47
+ sticky_cache_hit: Counter<u64>,
48
+ sticky_cache_miss: Counter<u64>,
49
+ sticky_cache_size: Histogram<u64>,
24
50
  }
25
51
 
26
52
  impl MetricsContext {
27
- fn new(kvs: Vec<KeyValue>) -> Self {
53
+ pub(crate) fn no_op() -> Self {
28
54
  Self {
29
- ctx: Context::current(),
30
- kvs: Arc::new(kvs),
55
+ ctx: Default::default(),
56
+ kvs: Default::default(),
57
+ instruments: Arc::new(Instruments::new_explicit(
58
+ &NoopMeterProvider::new().meter("fakemeter"),
59
+ "fakemetrics",
60
+ )),
31
61
  }
32
62
  }
33
63
 
34
- pub(crate) fn top_level(namespace: String) -> Self {
35
- Self::new(vec![KeyValue::new(KEY_NAMESPACE, namespace)])
64
+ pub(crate) fn top_level(namespace: String, telemetry: &TelemetryInstance) -> Self {
65
+ let kvs = vec![KeyValue::new(KEY_NAMESPACE, namespace)];
66
+ Self {
67
+ ctx: Context::current(),
68
+ kvs: Arc::new(kvs),
69
+ instruments: Arc::new(Instruments::new(telemetry)),
70
+ }
36
71
  }
37
72
 
38
73
  pub(crate) fn with_task_q(mut self, tq: String) -> Self {
@@ -47,155 +82,219 @@ impl MetricsContext {
47
82
  Self {
48
83
  ctx: Context::current(),
49
84
  kvs,
85
+ instruments: self.instruments.clone(),
50
86
  }
51
87
  }
52
88
 
53
89
  /// A workflow task queue poll succeeded
54
90
  pub(crate) fn wf_tq_poll_ok(&self) {
55
- WF_TASK_QUEUE_POLL_SUCCEED_COUNTER.add(&self.ctx, 1, &self.kvs);
91
+ self.instruments
92
+ .wf_task_queue_poll_succeed_counter
93
+ .add(&self.ctx, 1, &self.kvs);
56
94
  }
57
95
 
58
96
  /// A workflow task queue poll timed out / had empty response
59
97
  pub(crate) fn wf_tq_poll_empty(&self) {
60
- WF_TASK_QUEUE_POLL_EMPTY_COUNTER.add(&self.ctx, 1, &self.kvs);
98
+ self.instruments
99
+ .wf_task_queue_poll_empty_counter
100
+ .add(&self.ctx, 1, &self.kvs);
61
101
  }
62
102
 
63
103
  /// A workflow task execution failed
64
104
  pub(crate) fn wf_task_failed(&self) {
65
- WF_TASK_EXECUTION_FAILURE_COUNTER.add(&self.ctx, 1, &self.kvs);
105
+ self.instruments
106
+ .wf_task_execution_failure_counter
107
+ .add(&self.ctx, 1, &self.kvs);
66
108
  }
67
109
 
68
110
  /// A workflow completed successfully
69
111
  pub(crate) fn wf_completed(&self) {
70
- WF_COMPLETED_COUNTER.add(&self.ctx, 1, &self.kvs);
112
+ self.instruments
113
+ .wf_completed_counter
114
+ .add(&self.ctx, 1, &self.kvs);
71
115
  }
72
116
 
73
117
  /// A workflow ended cancelled
74
118
  pub(crate) fn wf_canceled(&self) {
75
- WF_CANCELED_COUNTER.add(&self.ctx, 1, &self.kvs);
119
+ self.instruments
120
+ .wf_canceled_counter
121
+ .add(&self.ctx, 1, &self.kvs);
76
122
  }
77
123
 
78
124
  /// A workflow ended failed
79
125
  pub(crate) fn wf_failed(&self) {
80
- WF_FAILED_COUNTER.add(&self.ctx, 1, &self.kvs);
126
+ self.instruments
127
+ .wf_failed_counter
128
+ .add(&self.ctx, 1, &self.kvs);
81
129
  }
82
130
 
83
131
  /// A workflow continued as new
84
132
  pub(crate) fn wf_continued_as_new(&self) {
85
- WF_CONT_COUNTER.add(&self.ctx, 1, &self.kvs);
133
+ self.instruments
134
+ .wf_cont_counter
135
+ .add(&self.ctx, 1, &self.kvs);
86
136
  }
87
137
 
88
138
  /// Record workflow total execution time in milliseconds
89
139
  pub(crate) fn wf_e2e_latency(&self, dur: Duration) {
90
- WF_E2E_LATENCY.record(&self.ctx, dur.as_millis() as u64, &self.kvs);
140
+ self.instruments
141
+ .wf_e2e_latency
142
+ .record(&self.ctx, dur.as_millis() as u64, &self.kvs);
91
143
  }
92
144
 
93
145
  /// Record workflow task schedule to start time in millis
94
146
  pub(crate) fn wf_task_sched_to_start_latency(&self, dur: Duration) {
95
- WF_TASK_SCHED_TO_START_LATENCY.record(&self.ctx, dur.as_millis() as u64, &self.kvs);
147
+ self.instruments.wf_task_sched_to_start_latency.record(
148
+ &self.ctx,
149
+ dur.as_millis() as u64,
150
+ &self.kvs,
151
+ );
96
152
  }
97
153
 
98
154
  /// Record workflow task execution time in milliseconds
99
155
  pub(crate) fn wf_task_latency(&self, dur: Duration) {
100
- WF_TASK_EXECUTION_LATENCY.record(&self.ctx, dur.as_millis() as u64, &self.kvs);
156
+ self.instruments.wf_task_execution_latency.record(
157
+ &self.ctx,
158
+ dur.as_millis() as u64,
159
+ &self.kvs,
160
+ );
101
161
  }
102
162
 
103
163
  /// Record time it takes to catch up on replaying a WFT
104
164
  pub(crate) fn wf_task_replay_latency(&self, dur: Duration) {
105
- WF_TASK_REPLAY_LATENCY.record(&self.ctx, dur.as_millis() as u64, &self.kvs);
165
+ self.instruments.wf_task_replay_latency.record(
166
+ &self.ctx,
167
+ dur.as_millis() as u64,
168
+ &self.kvs,
169
+ );
106
170
  }
107
171
 
108
172
  /// An activity long poll timed out
109
173
  pub(crate) fn act_poll_timeout(&self) {
110
- ACT_POLL_NO_TASK.add(&self.ctx, 1, &self.kvs);
174
+ self.instruments
175
+ .act_poll_no_task
176
+ .add(&self.ctx, 1, &self.kvs);
177
+ }
178
+
179
+ /// A count of activity tasks received
180
+ pub(crate) fn act_task_received(&self) {
181
+ self.instruments
182
+ .act_task_received_counter
183
+ .add(&self.ctx, 1, &self.kvs);
111
184
  }
112
185
 
113
186
  /// An activity execution failed
114
187
  pub(crate) fn act_execution_failed(&self) {
115
- ACT_EXECUTION_FAILED.add(&self.ctx, 1, &self.kvs);
188
+ self.instruments
189
+ .act_execution_failed
190
+ .add(&self.ctx, 1, &self.kvs);
116
191
  }
117
192
 
118
193
  /// Record activity task schedule to start time in millis
119
194
  pub(crate) fn act_sched_to_start_latency(&self, dur: Duration) {
120
- ACT_SCHED_TO_START_LATENCY.record(&self.ctx, dur.as_millis() as u64, &self.kvs);
195
+ self.instruments.act_sched_to_start_latency.record(
196
+ &self.ctx,
197
+ dur.as_millis() as u64,
198
+ &self.kvs,
199
+ );
121
200
  }
122
201
 
123
202
  /// Record time it took to complete activity execution, from the time core generated the
124
203
  /// activity task, to the time lang responded with a completion (failure or success).
125
204
  pub(crate) fn act_execution_latency(&self, dur: Duration) {
126
- ACT_EXEC_LATENCY.record(&self.ctx, dur.as_millis() as u64, &self.kvs);
205
+ self.instruments
206
+ .act_exec_latency
207
+ .record(&self.ctx, dur.as_millis() as u64, &self.kvs);
127
208
  }
128
209
 
129
210
  /// A worker was registered
130
211
  pub(crate) fn worker_registered(&self) {
131
- WORKER_REGISTERED.add(&self.ctx, 1, &self.kvs);
212
+ self.instruments
213
+ .worker_registered
214
+ .add(&self.ctx, 1, &self.kvs);
132
215
  }
133
216
 
134
217
  /// Record current number of available task slots. Context should have worker type set.
135
218
  pub(crate) fn available_task_slots(&self, num: usize) {
136
- TASK_SLOTS_AVAILABLE.record(&self.ctx, num as u64, &self.kvs)
219
+ self.instruments
220
+ .task_slots_available
221
+ .record(&self.ctx, num as u64, &self.kvs)
137
222
  }
138
223
 
139
224
  /// Record current number of pollers. Context should include poller type / task queue tag.
140
225
  pub(crate) fn record_num_pollers(&self, num: usize) {
141
- NUM_POLLERS.record(&self.ctx, num as u64, &self.kvs);
226
+ self.instruments
227
+ .num_pollers
228
+ .record(&self.ctx, num as u64, &self.kvs);
142
229
  }
143
230
 
144
231
  /// A workflow task found a cached workflow to run against
145
232
  pub(crate) fn sticky_cache_hit(&self) {
146
- STICKY_CACHE_HIT.add(&self.ctx, 1, &self.kvs);
233
+ self.instruments
234
+ .sticky_cache_hit
235
+ .add(&self.ctx, 1, &self.kvs);
147
236
  }
148
237
 
149
238
  /// A workflow task did not find a cached workflow
150
239
  pub(crate) fn sticky_cache_miss(&self) {
151
- STICKY_CACHE_MISS.add(&self.ctx, 1, &self.kvs);
240
+ self.instruments
241
+ .sticky_cache_miss
242
+ .add(&self.ctx, 1, &self.kvs);
152
243
  }
153
244
 
154
245
  /// Record current cache size (in number of wfs, not bytes)
155
246
  pub(crate) fn cache_size(&self, size: u64) {
156
- STICKY_CACHE_SIZE.record(&self.ctx, size, &self.kvs);
247
+ self.instruments
248
+ .sticky_cache_size
249
+ .record(&self.ctx, size, &self.kvs);
157
250
  }
158
251
  }
159
252
 
160
- lazy_static::lazy_static! {
161
- pub(crate) static ref METRIC_METER: Meter = {
162
- #[cfg(not(test))]
163
- if crate::telemetry::GLOBAL_TELEM_DAT.get().is_none() {
164
- panic!("Tried to use a metric but telemetry has not been initialized")
165
- }
166
- global::meter(TELEM_SERVICE_NAME)
167
- };
168
- }
169
- fn metric_prefix() -> &'static str {
170
- GLOBAL_TELEM_DAT
171
- .get()
172
- .map(|gtd| {
173
- if gtd.no_temporal_prefix_for_metrics {
174
- ""
175
- } else {
176
- "temporal_"
177
- }
178
- })
179
- .unwrap_or("")
180
- }
253
+ impl Instruments {
254
+ fn new(telem: &TelemetryInstance) -> Self {
255
+ let no_op_meter: Meter;
256
+ let meter = if let Some(meter) = telem.get_metric_meter() {
257
+ meter
258
+ } else {
259
+ no_op_meter = NoopMeterProvider::default().meter("no_op");
260
+ &no_op_meter
261
+ };
262
+ Self::new_explicit(meter, telem.metric_prefix)
263
+ }
181
264
 
182
- /// Define a temporal metric. All metrics are kept private to this file, and should be accessed
183
- /// through functions on the [MetricsContext]
184
- macro_rules! tm {
185
- (ctr, $ident:ident, $name:expr) => {
186
- lazy_static::lazy_static! {
187
- static ref $ident: Counter<u64> = {
188
- METRIC_METER.u64_counter(metric_prefix().to_string() + $name).init()
189
- };
190
- }
191
- };
192
- (vr_u64, $ident:ident, $name:expr) => {
193
- lazy_static::lazy_static! {
194
- static ref $ident: Histogram<u64> = {
195
- METRIC_METER.u64_histogram(metric_prefix().to_string() + $name).init()
196
- };
265
+ fn new_explicit(meter: &Meter, metric_prefix: &'static str) -> Self {
266
+ let ctr = |name: &'static str| -> Counter<u64> {
267
+ meter.u64_counter(metric_prefix.to_string() + name).init()
268
+ };
269
+ let hst = |name: &'static str| -> Histogram<u64> {
270
+ meter.u64_histogram(metric_prefix.to_string() + name).init()
271
+ };
272
+ Self {
273
+ wf_completed_counter: ctr("workflow_completed"),
274
+ wf_canceled_counter: ctr("workflow_canceled"),
275
+ wf_failed_counter: ctr("workflow_failed"),
276
+ wf_cont_counter: ctr("workflow_continue_as_new"),
277
+ wf_e2e_latency: hst(WF_E2E_LATENCY_NAME),
278
+ wf_task_queue_poll_empty_counter: ctr("workflow_task_queue_poll_empty"),
279
+ wf_task_queue_poll_succeed_counter: ctr("workflow_task_queue_poll_succeed"),
280
+ wf_task_execution_failure_counter: ctr("workflow_task_queue_poll_failed"),
281
+ wf_task_sched_to_start_latency: hst(WF_TASK_SCHED_TO_START_LATENCY_NAME),
282
+ wf_task_replay_latency: hst(WF_TASK_REPLAY_LATENCY_NAME),
283
+ wf_task_execution_latency: hst(WF_TASK_EXECUTION_LATENCY_NAME),
284
+ act_poll_no_task: ctr("activity_poll_no_task"),
285
+ act_task_received_counter: ctr("activity_task_received"),
286
+ act_execution_failed: ctr("activity_execution_failed"),
287
+ act_sched_to_start_latency: hst(ACT_SCHED_TO_START_LATENCY_NAME),
288
+ act_exec_latency: hst(ACT_EXEC_LATENCY_NAME),
289
+ // name kept as worker start for compat with old sdk / what users expect
290
+ worker_registered: ctr("worker_start"),
291
+ num_pollers: hst(NUM_POLLERS_NAME),
292
+ task_slots_available: hst(TASK_SLOTS_AVAILABLE_NAME),
293
+ sticky_cache_hit: ctr("sticky_cache_hit"),
294
+ sticky_cache_miss: ctr("sticky_cache_miss"),
295
+ sticky_cache_size: hst(STICKY_CACHE_SIZE_NAME),
197
296
  }
198
- };
297
+ }
199
298
  }
200
299
 
201
300
  const KEY_NAMESPACE: &str = "namespace";
@@ -204,6 +303,7 @@ const KEY_TASK_QUEUE: &str = "task_queue";
204
303
  const KEY_ACT_TYPE: &str = "activity_type";
205
304
  const KEY_POLLER_TYPE: &str = "poller_type";
206
305
  const KEY_WORKER_TYPE: &str = "worker_type";
306
+ const KEY_EAGER: &str = "eager";
207
307
 
208
308
  pub(crate) fn workflow_poller() -> KeyValue {
209
309
  KeyValue::new(KEY_POLLER_TYPE, "workflow_task")
@@ -224,85 +324,27 @@ pub(crate) fn workflow_type(ty: String) -> KeyValue {
224
324
  KeyValue::new(KEY_WF_TYPE, ty)
225
325
  }
226
326
  pub(crate) fn workflow_worker_type() -> KeyValue {
227
- KeyValue {
228
- key: opentelemetry::Key::from_static_str(KEY_WORKER_TYPE),
229
- value: opentelemetry::Value::String("WorkflowWorker".into()),
230
- }
327
+ KeyValue::new(KEY_WORKER_TYPE, "WorkflowWorker")
231
328
  }
232
329
  pub(crate) fn activity_worker_type() -> KeyValue {
233
- KeyValue {
234
- key: opentelemetry::Key::from_static_str(KEY_WORKER_TYPE),
235
- value: opentelemetry::Value::String("ActivityWorker".into()),
236
- }
330
+ KeyValue::new(KEY_WORKER_TYPE, "ActivityWorker")
237
331
  }
238
332
  pub(crate) fn local_activity_worker_type() -> KeyValue {
239
- KeyValue {
240
- key: opentelemetry::Key::from_static_str(KEY_WORKER_TYPE),
241
- value: opentelemetry::Value::String("LocalActivityWorker".into()),
242
- }
333
+ KeyValue::new(KEY_WORKER_TYPE, "LocalActivityWorker")
334
+ }
335
+ pub(crate) fn eager(is_eager: bool) -> KeyValue {
336
+ KeyValue::new(KEY_EAGER, is_eager)
243
337
  }
244
338
 
245
- tm!(ctr, WF_COMPLETED_COUNTER, "workflow_completed");
246
- tm!(ctr, WF_CANCELED_COUNTER, "workflow_canceled");
247
- tm!(ctr, WF_FAILED_COUNTER, "workflow_failed");
248
- tm!(ctr, WF_CONT_COUNTER, "workflow_continue_as_new");
249
339
  const WF_E2E_LATENCY_NAME: &str = "workflow_endtoend_latency";
250
- tm!(vr_u64, WF_E2E_LATENCY, WF_E2E_LATENCY_NAME);
251
-
252
- tm!(
253
- ctr,
254
- WF_TASK_QUEUE_POLL_EMPTY_COUNTER,
255
- "workflow_task_queue_poll_empty"
256
- );
257
- tm!(
258
- ctr,
259
- WF_TASK_QUEUE_POLL_SUCCEED_COUNTER,
260
- "workflow_task_queue_poll_succeed"
261
- );
262
- tm!(
263
- ctr,
264
- WF_TASK_EXECUTION_FAILURE_COUNTER,
265
- "workflow_task_execution_failed"
266
- );
267
340
  const WF_TASK_SCHED_TO_START_LATENCY_NAME: &str = "workflow_task_schedule_to_start_latency";
268
- tm!(
269
- vr_u64,
270
- WF_TASK_SCHED_TO_START_LATENCY,
271
- WF_TASK_SCHED_TO_START_LATENCY_NAME
272
- );
273
341
  const WF_TASK_REPLAY_LATENCY_NAME: &str = "workflow_task_replay_latency";
274
- tm!(vr_u64, WF_TASK_REPLAY_LATENCY, WF_TASK_REPLAY_LATENCY_NAME);
275
342
  const WF_TASK_EXECUTION_LATENCY_NAME: &str = "workflow_task_execution_latency";
276
- tm!(
277
- vr_u64,
278
- WF_TASK_EXECUTION_LATENCY,
279
- WF_TASK_EXECUTION_LATENCY_NAME
280
- );
281
-
282
- tm!(ctr, ACT_POLL_NO_TASK, "activity_poll_no_task");
283
- tm!(ctr, ACT_EXECUTION_FAILED, "activity_execution_failed");
284
- // Act task unregistered can't be known by core right now since it's not well defined as an
285
- // activity result. We could add a flag to the failed activity result if desired.
286
343
  const ACT_SCHED_TO_START_LATENCY_NAME: &str = "activity_schedule_to_start_latency";
287
- tm!(
288
- vr_u64,
289
- ACT_SCHED_TO_START_LATENCY,
290
- ACT_SCHED_TO_START_LATENCY_NAME
291
- );
292
344
  const ACT_EXEC_LATENCY_NAME: &str = "activity_execution_latency";
293
- tm!(vr_u64, ACT_EXEC_LATENCY, ACT_EXEC_LATENCY_NAME);
294
-
295
- // name kept as worker start for compat with old sdk / what users expect
296
- tm!(ctr, WORKER_REGISTERED, "worker_start");
297
345
  const NUM_POLLERS_NAME: &str = "num_pollers";
298
- tm!(vr_u64, NUM_POLLERS, NUM_POLLERS_NAME);
299
346
  const TASK_SLOTS_AVAILABLE_NAME: &str = "worker_task_slots_available";
300
- tm!(vr_u64, TASK_SLOTS_AVAILABLE, TASK_SLOTS_AVAILABLE_NAME);
301
-
302
- tm!(ctr, STICKY_CACHE_HIT, "sticky_cache_hit");
303
- tm!(ctr, STICKY_CACHE_MISS, "sticky_cache_miss");
304
347
  const STICKY_CACHE_SIZE_NAME: &str = "sticky_cache_size";
305
- tm!(vr_u64, STICKY_CACHE_SIZE, STICKY_CACHE_SIZE_NAME);
306
348
 
307
349
  /// Artisanal, handcrafted latency buckets for workflow e2e latency which should expose a useful
308
350
  /// set of buckets for < 1 day runtime workflows. Beyond that, this metric probably isn't very
@@ -335,15 +377,18 @@ static WF_TASK_MS_BUCKETS: &[f64] = &[1., 10., 20., 50., 100., 200., 500., 1000.
335
377
  static ACT_EXE_MS_BUCKETS: &[f64] = &[50., 100., 500., 1000., 5000., 10_000., 60_000.];
336
378
 
337
379
  /// Schedule-to-start latency buckets for both WFT and AT
338
- static TASK_SCHED_TO_START_MS_BUCKETS: &[f64] = &[100., 500., 1000., 5000., 10_000.];
380
+ static TASK_SCHED_TO_START_MS_BUCKETS: &[f64] =
381
+ &[100., 500., 1000., 5000., 10_000., 100_000., 1_000_000.];
339
382
 
340
383
  /// Default buckets. Should never really be used as they will be meaningless for many things, but
341
384
  /// broadly it's trying to represent latencies in millis.
342
385
  pub(super) static DEFAULT_MS_BUCKETS: &[f64] = &[50., 100., 500., 1000., 2500., 10_000.];
343
386
 
344
387
  /// Chooses appropriate aggregators for our metrics
345
- #[derive(Debug)]
346
- pub struct SDKAggSelector;
388
+ #[derive(Debug, Clone)]
389
+ pub struct SDKAggSelector {
390
+ pub metric_prefix: &'static str,
391
+ }
347
392
 
348
393
  impl AggregatorSelector for SDKAggSelector {
349
394
  fn aggregator_for(&self, descriptor: &Descriptor) -> Option<Arc<dyn Aggregator + Send + Sync>> {
@@ -355,7 +400,7 @@ impl AggregatorSelector for SDKAggSelector {
355
400
  if *descriptor.instrument_kind() == InstrumentKind::Histogram {
356
401
  let dname = descriptor
357
402
  .name()
358
- .strip_prefix(metric_prefix())
403
+ .strip_prefix(self.metric_prefix)
359
404
  .unwrap_or_else(|| descriptor.name());
360
405
  // Some recorders are just gauges
361
406
  match dname {