temporalio 0.0.1 → 0.0.2

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 (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
@@ -1,17 +1,20 @@
1
+ //! This module helps with the initialization and management of telemetry. IE: Metrics and tracing.
2
+ //! Logs from core are all traces, which may be exported to the console, in memory, or externally.
3
+
4
+ mod log_export;
1
5
  pub(crate) mod metrics;
2
6
  mod prometheus_server;
3
7
 
4
- use crate::{
5
- log_export::CoreExportLogger,
6
- telemetry::{metrics::SDKAggSelector, prometheus_server::PromServer},
7
- CoreLog, METRIC_METER,
8
+ use crate::telemetry::{
9
+ log_export::{CoreLogExportLayer, CoreLogsOut},
10
+ metrics::SDKAggSelector,
11
+ prometheus_server::PromServer,
8
12
  };
13
+ use crossbeam::channel::Receiver;
9
14
  use itertools::Itertools;
10
- use log::LevelFilter;
11
15
  use once_cell::sync::OnceCell;
12
16
  use opentelemetry::{
13
- global,
14
- metrics::Meter,
17
+ metrics::{Meter, MeterProvider},
15
18
  runtime,
16
19
  sdk::{
17
20
  export::metrics::aggregation::{self, Temporality, TemporalitySelector},
@@ -21,369 +24,361 @@ use opentelemetry::{
21
24
  KeyValue,
22
25
  };
23
26
  use opentelemetry_otlp::WithExportConfig;
24
- use parking_lot::{const_mutex, Mutex};
27
+ use parking_lot::Mutex;
25
28
  use std::{
26
- collections::{HashMap, VecDeque},
29
+ cell::RefCell,
30
+ collections::VecDeque,
27
31
  convert::TryInto,
28
- net::SocketAddr,
32
+ env,
33
+ sync::{
34
+ atomic::{AtomicBool, Ordering},
35
+ Arc,
36
+ },
29
37
  time::Duration,
30
38
  };
31
- use temporal_sdk_core_api::CoreTelemetry;
39
+ use temporal_sdk_core_api::telemetry::{
40
+ CoreLog, CoreTelemetry, Logger, MetricTemporality, MetricsExporter, OtelCollectorOptions,
41
+ TelemetryOptions, TraceExporter,
42
+ };
32
43
  use tonic::metadata::MetadataMap;
33
- use tracing_subscriber::{filter::ParseError, layer::SubscriberExt, EnvFilter};
34
- use url::Url;
44
+ use tracing::{Level, Subscriber};
45
+ use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Layer};
35
46
 
36
47
  const TELEM_SERVICE_NAME: &str = "temporal-core-sdk";
37
- static DEFAULT_FILTER: &str = "temporal_sdk_core=INFO";
38
- static GLOBAL_TELEM_DAT: OnceCell<GlobalTelemDat> = OnceCell::new();
39
- static TELETM_MUTEX: Mutex<()> = const_mutex(());
40
-
41
- fn default_resource_kvs() -> &'static [KeyValue] {
42
- static INSTANCE: OnceCell<[KeyValue; 1]> = OnceCell::new();
43
- INSTANCE.get_or_init(|| [KeyValue::new("service.name", TELEM_SERVICE_NAME)])
44
- }
45
- fn default_resource() -> Resource {
46
- Resource::new(default_resource_kvs().iter().cloned())
47
- }
48
-
49
- /// Options for exporting to an OpenTelemetry Collector
50
- #[derive(Debug, Clone)]
51
- pub struct OtelCollectorOptions {
52
- /// The url of the OTel collector to export telemetry and metrics to. Lang SDK should also
53
- /// export to this same collector.
54
- pub url: Url,
55
- /// Optional set of HTTP headers to send to the Collector, e.g for authentication.
56
- pub headers: HashMap<String, String>,
57
- }
58
-
59
- /// Control where traces are exported
60
- #[derive(Debug, Clone)]
61
- pub enum TraceExporter {
62
- /// Export traces to an OpenTelemetry Collector <https://opentelemetry.io/docs/collector/>.
63
- Otel(OtelCollectorOptions),
64
- }
65
48
 
66
- /// Control where metrics are exported
67
- #[derive(Debug, Clone)]
68
- pub enum MetricsExporter {
69
- /// Export metrics to an OpenTelemetry Collector <https://opentelemetry.io/docs/collector/>.
70
- Otel(OtelCollectorOptions),
71
- /// Expose metrics directly via an embedded http server bound to the provided address.
72
- Prometheus(SocketAddr),
49
+ /// Help you construct an [EnvFilter] compatible filter string which will forward all core module
50
+ /// traces at `core_level` and all others (from 3rd party modules, etc) at `other_levl.
51
+ pub fn construct_filter_string(core_level: Level, other_level: Level) -> String {
52
+ format!(
53
+ "{o},temporal_sdk_core={l},temporal_client={l},temporal_sdk={l}",
54
+ o = other_level,
55
+ l = core_level
56
+ )
73
57
  }
74
58
 
75
- /// Control where logs go
76
- #[derive(Debug, Clone, Copy)]
77
- pub enum Logger {
78
- /// Log directly to console.
79
- Console,
80
- /// Forward logs to Lang - collectable with `fetch_global_buffered_logs`.
81
- Forward(LevelFilter),
82
- }
83
-
84
- /// Telemetry configuration options. Construct with [TelemetryOptionsBuilder]
85
- #[derive(Debug, Clone, derive_builder::Builder)]
86
- #[non_exhaustive]
87
- pub struct TelemetryOptions {
88
- /// A string in the [EnvFilter] format which specifies what tracing data is included in
89
- /// telemetry, log forwarded to lang, or console output. May be overridden by the
90
- /// `TEMPORAL_TRACING_FILTER` env variable.
91
- #[builder(default = "DEFAULT_FILTER.to_string()")]
92
- pub tracing_filter: String,
93
-
94
- /// Optional trace exporter - set as None to disable.
95
- #[builder(setter(into, strip_option), default)]
96
- pub tracing: Option<TraceExporter>,
97
- /// Optional logger - set as None to disable.
98
- #[builder(setter(into, strip_option), default)]
99
- pub logging: Option<Logger>,
100
- /// Optional metrics exporter - set as None to disable.
101
- #[builder(setter(into, strip_option), default)]
102
- pub metrics: Option<MetricsExporter>,
103
-
104
- /// If set true, do not prefix metrics with `temporal_`. Will be removed eventually as
105
- /// the prefix is consistent with other SDKs.
106
- #[builder(default)]
107
- pub no_temporal_prefix_for_metrics: bool,
108
-
109
- /// Specifies the aggregation temporality for metric export. Defaults to cumulative.
110
- #[builder(default = "MetricTemporality::Cumulative")]
111
- pub metric_temporality: MetricTemporality,
59
+ /// Holds initialized tracing/metrics exporters, etc
60
+ pub struct TelemetryInstance {
61
+ metric_prefix: &'static str,
62
+ logs_out: Option<Mutex<CoreLogsOut>>,
63
+ metrics: Option<(Box<dyn MeterProvider + Send + Sync + 'static>, Meter)>,
64
+ trace_subscriber: Arc<dyn Subscriber + Send + Sync>,
65
+ _keepalive_rx: Receiver<()>,
112
66
  }
113
67
 
114
- /// Types of aggregation temporality for metric export.
115
- /// See: <https://github.com/open-telemetry/opentelemetry-specification/blob/ce50e4634efcba8da445cc23523243cb893905cb/specification/metrics/datamodel.md#temporality>
116
- #[derive(Debug, Clone, Copy)]
117
- pub enum MetricTemporality {
118
- /// Successive data points repeat the starting timestamp
119
- Cumulative,
120
- /// Successive data points advance the starting timestamp
121
- Delta,
122
- }
123
-
124
- impl MetricTemporality {
125
- fn to_selector(self) -> impl TemporalitySelector + Send + Sync + Clone {
126
- match self {
127
- MetricTemporality::Cumulative => {
128
- aggregation::constant_temporality_selector(Temporality::Cumulative)
129
- }
130
- MetricTemporality::Delta => {
131
- aggregation::constant_temporality_selector(Temporality::Delta)
132
- }
68
+ impl TelemetryInstance {
69
+ fn new(
70
+ trace_subscriber: Arc<dyn Subscriber + Send + Sync>,
71
+ logs_out: Option<Mutex<CoreLogsOut>>,
72
+ metric_prefix: &'static str,
73
+ mut meter_provider: Option<Box<dyn MeterProvider + Send + Sync + 'static>>,
74
+ keepalive_rx: Receiver<()>,
75
+ ) -> Self {
76
+ let metrics = meter_provider.take().map(|mp| {
77
+ let meter = mp.meter(TELEM_SERVICE_NAME);
78
+ (mp, meter)
79
+ });
80
+ Self {
81
+ metric_prefix,
82
+ logs_out,
83
+ metrics,
84
+ trace_subscriber,
85
+ _keepalive_rx: keepalive_rx,
133
86
  }
134
87
  }
135
- }
136
88
 
137
- impl TelemetryOptions {
138
- /// Construct an [EnvFilter] from given `tracing_filter`.
139
- pub fn try_get_env_filter(&self) -> Result<EnvFilter, ParseError> {
140
- EnvFilter::try_new(if self.tracing_filter.is_empty() {
141
- DEFAULT_FILTER
142
- } else {
143
- &self.tracing_filter
144
- })
89
+ /// Returns a trace subscriber which can be used with the tracing crate, or with our own
90
+ /// [set_trace_subscriber_for_current_thread] function.
91
+ pub fn trace_subscriber(&self) -> Arc<dyn Subscriber + Send + Sync> {
92
+ self.trace_subscriber.clone()
145
93
  }
146
94
  }
147
95
 
148
- impl Default for TelemetryOptions {
149
- fn default() -> Self {
150
- TelemetryOptionsBuilder::default().build().unwrap()
151
- }
96
+ thread_local! {
97
+ static SUB_GUARD: RefCell<Option<tracing::subscriber::DefaultGuard>> = RefCell::new(None);
98
+ }
99
+ /// Set the trace subscriber for the current thread. This must be done in every thread which uses
100
+ /// core stuff, otherwise traces/logs will not be collected on that thread. For example, if using
101
+ /// a multithreaded Tokio runtime, you should ensure that said runtime uses
102
+ /// [on_thread_start](https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html#method.on_thread_start)
103
+ /// or a similar mechanism to call this for each thread within the runtime.
104
+ pub fn set_trace_subscriber_for_current_thread(sub: impl Subscriber + Send + Sync + 'static) {
105
+ SUB_GUARD.with(|sg| {
106
+ if sg.borrow().is_none() {
107
+ let g = tracing::subscriber::set_default(sub);
108
+ *sg.borrow_mut() = Some(g);
109
+ }
110
+ })
152
111
  }
153
112
 
154
- /// Things that need to not be dropped while telemetry is ongoing
155
- #[derive(Default)]
156
- pub struct GlobalTelemDat {
157
- core_export_logger: Option<CoreExportLogger>,
158
- runtime: Option<tokio::runtime::Runtime>,
159
- prom_srv: Option<PromServer>,
160
- no_temporal_prefix_for_metrics: bool,
113
+ /// Undoes [set_trace_subscriber_for_current_thread]
114
+ pub fn remove_trace_subscriber_for_current_thread() {
115
+ SUB_GUARD.with(|sg| sg.take());
161
116
  }
162
117
 
163
- impl GlobalTelemDat {
164
- fn init(&'static self) {
165
- if let Some(loggr) = &self.core_export_logger {
166
- let _ = log::set_logger(loggr);
167
- }
168
- if let Some(srv) = &self.prom_srv {
169
- self.runtime
170
- .as_ref()
171
- .expect("Telemetry runtime is initted")
172
- .spawn(srv.run());
173
- }
118
+ fn metric_prefix(opts: &TelemetryOptions) -> &'static str {
119
+ if opts.no_temporal_prefix_for_metrics {
120
+ ""
121
+ } else {
122
+ "temporal_"
174
123
  }
175
124
  }
176
125
 
177
- impl CoreTelemetry for GlobalTelemDat {
126
+ impl CoreTelemetry for TelemetryInstance {
178
127
  fn fetch_buffered_logs(&self) -> Vec<CoreLog> {
179
- fetch_global_buffered_logs()
128
+ if let Some(logs_out) = self.logs_out.as_ref() {
129
+ logs_out.lock().pop_iter().collect()
130
+ } else {
131
+ vec![]
132
+ }
180
133
  }
181
134
 
182
135
  fn get_metric_meter(&self) -> Option<&Meter> {
183
- if GLOBAL_TELEM_DAT.get().is_some() {
184
- return Some(&METRIC_METER);
185
- }
186
- None
136
+ self.metrics.as_ref().map(|(_, m)| m)
187
137
  }
188
138
  }
189
139
 
190
- /// Initialize tracing subscribers/output and logging export. If this function is called more than
191
- /// once, subsequent calls do nothing.
140
+ /// Initialize tracing subscribers/output and logging export, returning a [TelemetryInstance]
141
+ /// which can be used to register default / global tracing subscribers.
142
+ ///
143
+ /// You should only call this once per unique [TelemetryOptions]
192
144
  ///
193
145
  /// See [TelemetryOptions] docs for more on configuration.
194
- pub fn telemetry_init(opts: &TelemetryOptions) -> Result<&'static GlobalTelemDat, anyhow::Error> {
195
- // TODO: Per-layer filtering has been implemented but does not yet support
196
- // env-filter. When it does, allow filtering logs/telemetry separately.
197
-
198
- // Ensure we don't pointlessly spawn threads that won't do anything or call telem dat's init 2x
199
- let guard = TELETM_MUTEX.lock();
200
- if let Some(gtd) = GLOBAL_TELEM_DAT.get() {
201
- return Ok(gtd);
202
- }
203
-
146
+ pub fn telemetry_init(opts: TelemetryOptions) -> Result<TelemetryInstance, anyhow::Error> {
204
147
  // This is a bit odd, but functional. It's desirable to create a separate tokio runtime for
205
148
  // metrics handling, since tests typically use a single-threaded runtime and initializing
206
149
  // pipeline requires us to know if the runtime is single or multithreaded, we will crash
207
150
  // in one case or the other. There does not seem to be a way to tell from the current runtime
208
151
  // handle if it is single or multithreaded. Additionally, we can isolate metrics work this
209
152
  // way which is nice.
210
- let opts = opts.clone();
211
- std::thread::spawn(move || {
212
- let res = GLOBAL_TELEM_DAT.get_or_try_init::<_, anyhow::Error>(move || {
213
- // Ensure closure captures the mutex guard
214
- let _ = &*guard;
215
-
216
- let runtime = tokio::runtime::Builder::new_multi_thread()
217
- .thread_name("telemetry")
218
- .worker_threads(2)
219
- .enable_all()
220
- .build()?;
221
- let mut globaldat = GlobalTelemDat {
222
- no_temporal_prefix_for_metrics: opts.no_temporal_prefix_for_metrics,
223
- ..Default::default()
224
- };
225
-
226
- if let Some(ref logger) = opts.logging {
227
- match logger {
228
- Logger::Console => {
229
- // TODO: this is duplicated below and is quite ugly, remove the duplication
230
- if opts.tracing.is_none() {
231
- let pretty_fmt = tracing_subscriber::fmt::format()
232
- .pretty()
233
- .with_source_location(false);
234
- let reg = tracing_subscriber::registry()
235
- .with((opts).try_get_env_filter()?)
236
- .with(
237
- tracing_subscriber::fmt::layer()
238
- .with_target(false)
239
- .event_format(pretty_fmt),
240
- );
241
- tracing::subscriber::set_global_default(reg)?;
242
- }
243
- }
244
- Logger::Forward(filter) => {
245
- log::set_max_level(*filter);
246
- globaldat.core_export_logger = Some(CoreExportLogger::new(*filter));
247
- }
248
- };
249
- };
250
-
251
- if let Some(ref metrics) = opts.metrics {
252
- match metrics {
253
- MetricsExporter::Prometheus(addr) => {
254
- let srv = PromServer::new(*addr, opts.metric_temporality.to_selector())?;
255
- globaldat.prom_srv = Some(srv);
256
- }
257
- MetricsExporter::Otel(OtelCollectorOptions { url, headers }) => {
258
- runtime.block_on(async {
259
- let metrics = opentelemetry_otlp::new_pipeline()
260
- .metrics(
261
- SDKAggSelector,
262
- opts.metric_temporality.to_selector(),
263
- runtime::Tokio,
153
+ let (tx, rx) = crossbeam::channel::bounded(0);
154
+ let (keepalive_tx, keepalive_rx) = crossbeam::channel::bounded(0);
155
+ let jh = std::thread::spawn(move || -> Result<(), anyhow::Error> {
156
+ let runtime = tokio::runtime::Builder::new_multi_thread()
157
+ .thread_name("telemetry")
158
+ .worker_threads(2)
159
+ .enable_all()
160
+ .build()?;
161
+ // Parts of telem dat ====
162
+ let mut logs_out = None;
163
+ let metric_prefix = metric_prefix(&opts);
164
+ // =======================
165
+
166
+ // Tracing subscriber layers =========
167
+ let mut console_pretty_layer = None;
168
+ let mut console_compact_layer = None;
169
+ let mut forward_layer = None;
170
+ let mut export_layer = None;
171
+ // ===================================
172
+
173
+ if let Some(ref logger) = opts.logging {
174
+ match logger {
175
+ Logger::Console { filter } => {
176
+ // This is silly dupe but can't be avoided without boxing.
177
+ if env::var("TEMPORAL_CORE_PRETTY_LOGS").is_ok() {
178
+ console_pretty_layer = Some(
179
+ tracing_subscriber::fmt::layer()
180
+ .with_target(false)
181
+ .event_format(
182
+ tracing_subscriber::fmt::format()
183
+ .pretty()
184
+ .with_source_location(false),
264
185
  )
265
- .with_period(Duration::from_secs(1))
266
- .with_resource(default_resource())
267
- .with_exporter(
268
- // No joke exporter builder literally not cloneable for some insane
269
- // reason
270
- opentelemetry_otlp::new_exporter()
271
- .tonic()
272
- .with_endpoint(url.to_string())
273
- .with_metadata(MetadataMap::from_headers(
274
- headers.try_into()?,
275
- )),
186
+ .with_filter(EnvFilter::new(filter)),
187
+ )
188
+ } else {
189
+ console_compact_layer = Some(
190
+ tracing_subscriber::fmt::layer()
191
+ .with_target(false)
192
+ .event_format(
193
+ tracing_subscriber::fmt::format()
194
+ .compact()
195
+ .with_source_location(false),
276
196
  )
277
- .build()?;
278
- global::set_meter_provider(metrics);
279
- Result::<(), anyhow::Error>::Ok(())
280
- })?;
197
+ .with_filter(EnvFilter::new(filter)),
198
+ )
281
199
  }
282
- };
200
+ }
201
+ Logger::Forward { filter } => {
202
+ let (export_layer, lo) = CoreLogExportLayer::new();
203
+ logs_out = Some(Mutex::new(lo));
204
+ forward_layer = Some(export_layer.with_filter(EnvFilter::new(filter)));
205
+ }
283
206
  };
284
-
285
- if let Some(ref tracing) = opts.tracing {
286
- match tracing {
287
- TraceExporter::Otel(OtelCollectorOptions { url, headers }) => {
288
- runtime.block_on(async {
289
- let tracer_cfg = Config::default().with_resource(default_resource());
290
- let tracer = opentelemetry_otlp::new_pipeline()
291
- .tracing()
292
- .with_exporter(
293
- opentelemetry_otlp::new_exporter()
294
- .tonic()
295
- .with_endpoint(url.to_string())
296
- .with_metadata(MetadataMap::from_headers(
297
- headers.try_into()?,
298
- )),
299
- )
300
- .with_trace_config(tracer_cfg)
301
- .install_batch(runtime::Tokio)?;
302
-
303
- let opentelemetry = tracing_opentelemetry::layer().with_tracer(tracer);
304
-
305
- // TODO: remove all of this duplicate code
306
- if let Some(Logger::Console) = opts.logging {
307
- let pretty_fmt = tracing_subscriber::fmt::format()
308
- .pretty()
309
- .with_source_location(false);
310
- let reg = tracing_subscriber::registry()
311
- .with(opentelemetry)
312
- .with(opts.try_get_env_filter()?)
313
- .with(
314
- tracing_subscriber::fmt::layer()
315
- .with_target(false)
316
- .event_format(pretty_fmt),
317
- );
318
- // Can't use try_init here as it will blow away our custom logger if we do
319
- tracing::subscriber::set_global_default(reg)?;
320
- } else {
321
- let reg = tracing_subscriber::registry()
322
- .with(opentelemetry)
323
- .with(opts.try_get_env_filter()?);
324
- // Can't use try_init here as it will blow away our custom logger if we do
325
- tracing::subscriber::set_global_default(reg)?;
326
- }
327
- Result::<(), anyhow::Error>::Ok(())
328
- })?;
329
- }
330
- };
207
+ };
208
+
209
+ let meter_provider = if let Some(ref metrics) = opts.metrics {
210
+ let aggregator = SDKAggSelector { metric_prefix };
211
+ match metrics {
212
+ MetricsExporter::Prometheus(addr) => {
213
+ let srv = PromServer::new(
214
+ *addr,
215
+ aggregator,
216
+ metric_temporality_to_selector(opts.metric_temporality),
217
+ )?;
218
+ let mp = srv.exporter.meter_provider()?;
219
+ runtime.spawn(async move { srv.run().await });
220
+ Some(Box::new(mp) as Box<dyn MeterProvider + Send + Sync>)
221
+ }
222
+ MetricsExporter::Otel(OtelCollectorOptions {
223
+ url,
224
+ headers,
225
+ metric_periodicity,
226
+ }) => runtime.block_on(async {
227
+ let metrics = opentelemetry_otlp::new_pipeline()
228
+ .metrics(
229
+ aggregator,
230
+ metric_temporality_to_selector(opts.metric_temporality),
231
+ runtime::Tokio,
232
+ )
233
+ .with_period(metric_periodicity.unwrap_or_else(|| Duration::from_secs(1)))
234
+ .with_resource(default_resource())
235
+ .with_exporter(
236
+ opentelemetry_otlp::new_exporter()
237
+ .tonic()
238
+ .with_endpoint(url.to_string())
239
+ .with_metadata(MetadataMap::from_headers(headers.try_into()?)),
240
+ )
241
+ .build()?;
242
+ Ok::<_, anyhow::Error>(Some(
243
+ Box::new(metrics) as Box<dyn MeterProvider + Send + Sync>
244
+ ))
245
+ })?,
246
+ }
247
+ } else {
248
+ None
249
+ };
250
+
251
+ if let Some(ref tracing) = opts.tracing {
252
+ match &tracing.exporter {
253
+ TraceExporter::Otel(OtelCollectorOptions { url, headers, .. }) => {
254
+ runtime.block_on(async {
255
+ let tracer_cfg = Config::default().with_resource(default_resource());
256
+ let tracer = opentelemetry_otlp::new_pipeline()
257
+ .tracing()
258
+ .with_exporter(
259
+ opentelemetry_otlp::new_exporter()
260
+ .tonic()
261
+ .with_endpoint(url.to_string())
262
+ .with_metadata(MetadataMap::from_headers(headers.try_into()?)),
263
+ )
264
+ .with_trace_config(tracer_cfg)
265
+ .install_batch(runtime::Tokio)?;
266
+
267
+ let opentelemetry = tracing_opentelemetry::layer()
268
+ .with_tracer(tracer)
269
+ .with_filter(EnvFilter::new(&tracing.filter));
270
+
271
+ export_layer = Some(opentelemetry);
272
+ Result::<(), anyhow::Error>::Ok(())
273
+ })?;
274
+ }
331
275
  };
332
-
333
- globaldat.runtime = Some(runtime);
334
- Ok(globaldat)
335
- })?;
336
-
337
- res.init();
338
- Result::<_, anyhow::Error>::Ok(res)
339
- })
340
- .join()
341
- .expect("Telemetry initialization panicked")
276
+ };
277
+
278
+ let reg = tracing_subscriber::registry()
279
+ .with(console_pretty_layer)
280
+ .with(console_compact_layer)
281
+ .with(forward_layer)
282
+ .with(export_layer);
283
+
284
+ tx.send(TelemetryInstance::new(
285
+ Arc::new(reg),
286
+ logs_out,
287
+ metric_prefix,
288
+ meter_provider,
289
+ keepalive_rx,
290
+ ))
291
+ .expect("Must be able to send telem instance out of thread");
292
+ // Now keep the thread alive until the telemetry instance is dropped by trying to send
293
+ // something forever
294
+ let _ = keepalive_tx.send(());
295
+ Ok(())
296
+ });
297
+ match rx.recv() {
298
+ Ok(ti) => Ok(ti),
299
+ Err(_) => {
300
+ // Immediately join the thread since something went wrong in it
301
+ jh.join().expect("Telemetry must init cleanly")?;
302
+ // This can't happen. The rx channel can't be dropped unless the thread errored.
303
+ unreachable!("Impossible error in telemetry init thread");
304
+ }
305
+ }
342
306
  }
343
307
 
344
- /// Returned buffered logs for export to lang from the global logging instance.
345
- /// If [telemetry_init] has not been called, always returns an empty vec.
346
- pub fn fetch_global_buffered_logs() -> Vec<CoreLog> {
347
- if let Some(loggr) = GLOBAL_TELEM_DAT
348
- .get()
349
- .and_then(|gd| gd.core_export_logger.as_ref())
308
+ /// Initialize telemetry/tracing globally. Useful for testing. Only takes affect when called
309
+ /// the first time. Subsequent calls are ignored.
310
+ pub fn telemetry_init_global(opts: TelemetryOptions) -> Result<(), anyhow::Error> {
311
+ static INITTED: AtomicBool = AtomicBool::new(false);
312
+ if INITTED
313
+ .compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed)
314
+ .is_ok()
350
315
  {
351
- loggr.drain()
352
- } else {
353
- vec![]
316
+ let ti = telemetry_init(opts)?;
317
+ tracing::subscriber::set_global_default(ti.trace_subscriber())?;
354
318
  }
319
+ Ok(())
355
320
  }
356
321
 
357
- #[allow(dead_code)] // Not always used, called to enable for debugging when needed
358
- #[cfg(test)]
359
- pub(crate) fn test_telem_console() {
360
- telemetry_init(&TelemetryOptions {
361
- tracing_filter: "temporal_sdk_core=DEBUG,temporal_sdk=DEBUG".to_string(),
362
- logging: Some(Logger::Console),
363
- tracing: None,
364
- metrics: None,
365
- no_temporal_prefix_for_metrics: false,
366
- metric_temporality: MetricTemporality::Cumulative,
367
- })
368
- .unwrap();
322
+ fn default_resource_kvs() -> &'static [KeyValue] {
323
+ static INSTANCE: OnceCell<[KeyValue; 1]> = OnceCell::new();
324
+ INSTANCE.get_or_init(|| [KeyValue::new("service.name", TELEM_SERVICE_NAME)])
325
+ }
326
+ fn default_resource() -> Resource {
327
+ Resource::new(default_resource_kvs().iter().cloned())
328
+ }
329
+
330
+ fn metric_temporality_to_selector(
331
+ t: MetricTemporality,
332
+ ) -> impl TemporalitySelector + Send + Sync + Clone {
333
+ match t {
334
+ MetricTemporality::Cumulative => {
335
+ aggregation::constant_temporality_selector(Temporality::Cumulative)
336
+ }
337
+ MetricTemporality::Delta => aggregation::constant_temporality_selector(Temporality::Delta),
338
+ }
369
339
  }
370
340
 
371
- #[allow(dead_code)] // Not always used, called to enable for debugging when needed
372
341
  #[cfg(test)]
373
- pub(crate) fn test_telem_collector() {
374
- telemetry_init(&TelemetryOptions {
375
- tracing_filter: "temporal_sdk_core=DEBUG,temporal_sdk=DEBUG".to_string(),
376
- logging: Some(Logger::Console),
377
- tracing: Some(TraceExporter::Otel(OtelCollectorOptions {
378
- url: "grpc://localhost:4317".parse().unwrap(),
379
- headers: Default::default(),
380
- })),
381
- metrics: None,
382
- no_temporal_prefix_for_metrics: false,
383
- metric_temporality: MetricTemporality::Cumulative,
384
- })
385
- .unwrap();
342
+ pub mod test_initters {
343
+ use super::*;
344
+ use temporal_sdk_core_api::telemetry::{TelemetryOptionsBuilder, TraceExportConfig};
345
+
346
+ #[allow(dead_code)] // Not always used, called to enable for debugging when needed
347
+ pub fn test_telem_console() {
348
+ telemetry_init_global(
349
+ TelemetryOptionsBuilder::default()
350
+ .logging(Logger::Console {
351
+ filter: construct_filter_string(Level::DEBUG, Level::WARN),
352
+ })
353
+ .build()
354
+ .unwrap(),
355
+ )
356
+ .unwrap();
357
+ }
358
+
359
+ #[allow(dead_code)] // Not always used, called to enable for debugging when needed
360
+ pub fn test_telem_collector() {
361
+ telemetry_init_global(
362
+ TelemetryOptionsBuilder::default()
363
+ .logging(Logger::Console {
364
+ filter: construct_filter_string(Level::DEBUG, Level::WARN),
365
+ })
366
+ .tracing(TraceExportConfig {
367
+ filter: construct_filter_string(Level::DEBUG, Level::WARN),
368
+ exporter: TraceExporter::Otel(OtelCollectorOptions {
369
+ url: "grpc://localhost:4317".parse().unwrap(),
370
+ headers: Default::default(),
371
+ metric_periodicity: None,
372
+ }),
373
+ })
374
+ .build()
375
+ .unwrap(),
376
+ )
377
+ .unwrap();
378
+ }
386
379
  }
380
+ #[cfg(test)]
381
+ pub use test_initters::*;
387
382
 
388
383
  /// A trait for using [Display] on the contents of vecs, etc, which don't implement it.
389
384
  ///