temporalio 0.4.0-aarch64-linux-musl

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 (183) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +2 -0
  3. data/Gemfile +27 -0
  4. data/Rakefile +101 -0
  5. data/lib/temporalio/activity/complete_async_error.rb +11 -0
  6. data/lib/temporalio/activity/context.rb +123 -0
  7. data/lib/temporalio/activity/definition.rb +192 -0
  8. data/lib/temporalio/activity/info.rb +67 -0
  9. data/lib/temporalio/activity.rb +12 -0
  10. data/lib/temporalio/api/activity/v1/message.rb +25 -0
  11. data/lib/temporalio/api/batch/v1/message.rb +36 -0
  12. data/lib/temporalio/api/cloud/account/v1/message.rb +28 -0
  13. data/lib/temporalio/api/cloud/cloudservice/v1/request_response.rb +126 -0
  14. data/lib/temporalio/api/cloud/cloudservice/v1/service.rb +25 -0
  15. data/lib/temporalio/api/cloud/cloudservice.rb +3 -0
  16. data/lib/temporalio/api/cloud/identity/v1/message.rb +41 -0
  17. data/lib/temporalio/api/cloud/namespace/v1/message.rb +42 -0
  18. data/lib/temporalio/api/cloud/nexus/v1/message.rb +31 -0
  19. data/lib/temporalio/api/cloud/operation/v1/message.rb +28 -0
  20. data/lib/temporalio/api/cloud/region/v1/message.rb +24 -0
  21. data/lib/temporalio/api/cloud/resource/v1/message.rb +23 -0
  22. data/lib/temporalio/api/cloud/sink/v1/message.rb +24 -0
  23. data/lib/temporalio/api/cloud/usage/v1/message.rb +31 -0
  24. data/lib/temporalio/api/command/v1/message.rb +46 -0
  25. data/lib/temporalio/api/common/v1/grpc_status.rb +23 -0
  26. data/lib/temporalio/api/common/v1/message.rb +48 -0
  27. data/lib/temporalio/api/deployment/v1/message.rb +38 -0
  28. data/lib/temporalio/api/enums/v1/batch_operation.rb +22 -0
  29. data/lib/temporalio/api/enums/v1/command_type.rb +21 -0
  30. data/lib/temporalio/api/enums/v1/common.rb +26 -0
  31. data/lib/temporalio/api/enums/v1/deployment.rb +23 -0
  32. data/lib/temporalio/api/enums/v1/event_type.rb +21 -0
  33. data/lib/temporalio/api/enums/v1/failed_cause.rb +26 -0
  34. data/lib/temporalio/api/enums/v1/namespace.rb +23 -0
  35. data/lib/temporalio/api/enums/v1/nexus.rb +21 -0
  36. data/lib/temporalio/api/enums/v1/query.rb +22 -0
  37. data/lib/temporalio/api/enums/v1/reset.rb +23 -0
  38. data/lib/temporalio/api/enums/v1/schedule.rb +21 -0
  39. data/lib/temporalio/api/enums/v1/task_queue.rb +25 -0
  40. data/lib/temporalio/api/enums/v1/update.rb +22 -0
  41. data/lib/temporalio/api/enums/v1/workflow.rb +31 -0
  42. data/lib/temporalio/api/errordetails/v1/message.rb +44 -0
  43. data/lib/temporalio/api/export/v1/message.rb +24 -0
  44. data/lib/temporalio/api/failure/v1/message.rb +37 -0
  45. data/lib/temporalio/api/filter/v1/message.rb +27 -0
  46. data/lib/temporalio/api/history/v1/message.rb +92 -0
  47. data/lib/temporalio/api/namespace/v1/message.rb +31 -0
  48. data/lib/temporalio/api/nexus/v1/message.rb +41 -0
  49. data/lib/temporalio/api/operatorservice/v1/request_response.rb +49 -0
  50. data/lib/temporalio/api/operatorservice/v1/service.rb +23 -0
  51. data/lib/temporalio/api/operatorservice.rb +3 -0
  52. data/lib/temporalio/api/payload_visitor.rb +1581 -0
  53. data/lib/temporalio/api/protocol/v1/message.rb +23 -0
  54. data/lib/temporalio/api/query/v1/message.rb +28 -0
  55. data/lib/temporalio/api/replication/v1/message.rb +26 -0
  56. data/lib/temporalio/api/schedule/v1/message.rb +43 -0
  57. data/lib/temporalio/api/sdk/v1/enhanced_stack_trace.rb +25 -0
  58. data/lib/temporalio/api/sdk/v1/task_complete_metadata.rb +21 -0
  59. data/lib/temporalio/api/sdk/v1/user_metadata.rb +23 -0
  60. data/lib/temporalio/api/sdk/v1/workflow_metadata.rb +23 -0
  61. data/lib/temporalio/api/taskqueue/v1/message.rb +48 -0
  62. data/lib/temporalio/api/testservice/v1/request_response.rb +31 -0
  63. data/lib/temporalio/api/testservice/v1/service.rb +23 -0
  64. data/lib/temporalio/api/update/v1/message.rb +33 -0
  65. data/lib/temporalio/api/version/v1/message.rb +26 -0
  66. data/lib/temporalio/api/workflow/v1/message.rb +51 -0
  67. data/lib/temporalio/api/workflowservice/v1/request_response.rb +233 -0
  68. data/lib/temporalio/api/workflowservice/v1/service.rb +23 -0
  69. data/lib/temporalio/api/workflowservice.rb +3 -0
  70. data/lib/temporalio/api.rb +15 -0
  71. data/lib/temporalio/cancellation.rb +170 -0
  72. data/lib/temporalio/client/activity_id_reference.rb +32 -0
  73. data/lib/temporalio/client/async_activity_handle.rb +85 -0
  74. data/lib/temporalio/client/connection/cloud_service.rb +726 -0
  75. data/lib/temporalio/client/connection/operator_service.rb +201 -0
  76. data/lib/temporalio/client/connection/service.rb +42 -0
  77. data/lib/temporalio/client/connection/test_service.rb +111 -0
  78. data/lib/temporalio/client/connection/workflow_service.rb +1251 -0
  79. data/lib/temporalio/client/connection.rb +316 -0
  80. data/lib/temporalio/client/interceptor.rb +455 -0
  81. data/lib/temporalio/client/schedule.rb +991 -0
  82. data/lib/temporalio/client/schedule_handle.rb +126 -0
  83. data/lib/temporalio/client/with_start_workflow_operation.rb +115 -0
  84. data/lib/temporalio/client/workflow_execution.rb +119 -0
  85. data/lib/temporalio/client/workflow_execution_count.rb +36 -0
  86. data/lib/temporalio/client/workflow_execution_status.rb +18 -0
  87. data/lib/temporalio/client/workflow_handle.rb +389 -0
  88. data/lib/temporalio/client/workflow_query_reject_condition.rb +14 -0
  89. data/lib/temporalio/client/workflow_update_handle.rb +65 -0
  90. data/lib/temporalio/client/workflow_update_wait_stage.rb +17 -0
  91. data/lib/temporalio/client.rb +607 -0
  92. data/lib/temporalio/common_enums.rb +41 -0
  93. data/lib/temporalio/contrib/open_telemetry.rb +470 -0
  94. data/lib/temporalio/converters/data_converter.rb +99 -0
  95. data/lib/temporalio/converters/failure_converter.rb +202 -0
  96. data/lib/temporalio/converters/payload_codec.rb +26 -0
  97. data/lib/temporalio/converters/payload_converter/binary_null.rb +34 -0
  98. data/lib/temporalio/converters/payload_converter/binary_plain.rb +35 -0
  99. data/lib/temporalio/converters/payload_converter/binary_protobuf.rb +42 -0
  100. data/lib/temporalio/converters/payload_converter/composite.rb +66 -0
  101. data/lib/temporalio/converters/payload_converter/encoding.rb +35 -0
  102. data/lib/temporalio/converters/payload_converter/json_plain.rb +44 -0
  103. data/lib/temporalio/converters/payload_converter/json_protobuf.rb +41 -0
  104. data/lib/temporalio/converters/payload_converter.rb +71 -0
  105. data/lib/temporalio/converters/raw_value.rb +20 -0
  106. data/lib/temporalio/converters.rb +9 -0
  107. data/lib/temporalio/error/failure.rb +219 -0
  108. data/lib/temporalio/error.rb +156 -0
  109. data/lib/temporalio/internal/bridge/3.2/temporalio_bridge.so +0 -0
  110. data/lib/temporalio/internal/bridge/3.3/temporalio_bridge.so +0 -0
  111. data/lib/temporalio/internal/bridge/3.4/temporalio_bridge.so +0 -0
  112. data/lib/temporalio/internal/bridge/api/activity_result/activity_result.rb +34 -0
  113. data/lib/temporalio/internal/bridge/api/activity_task/activity_task.rb +31 -0
  114. data/lib/temporalio/internal/bridge/api/child_workflow/child_workflow.rb +33 -0
  115. data/lib/temporalio/internal/bridge/api/common/common.rb +27 -0
  116. data/lib/temporalio/internal/bridge/api/core_interface.rb +40 -0
  117. data/lib/temporalio/internal/bridge/api/external_data/external_data.rb +27 -0
  118. data/lib/temporalio/internal/bridge/api/nexus/nexus.rb +33 -0
  119. data/lib/temporalio/internal/bridge/api/workflow_activation/workflow_activation.rb +56 -0
  120. data/lib/temporalio/internal/bridge/api/workflow_commands/workflow_commands.rb +57 -0
  121. data/lib/temporalio/internal/bridge/api/workflow_completion/workflow_completion.rb +31 -0
  122. data/lib/temporalio/internal/bridge/api.rb +3 -0
  123. data/lib/temporalio/internal/bridge/client.rb +95 -0
  124. data/lib/temporalio/internal/bridge/runtime.rb +56 -0
  125. data/lib/temporalio/internal/bridge/testing.rb +69 -0
  126. data/lib/temporalio/internal/bridge/worker.rb +85 -0
  127. data/lib/temporalio/internal/bridge.rb +36 -0
  128. data/lib/temporalio/internal/client/implementation.rb +922 -0
  129. data/lib/temporalio/internal/metric.rb +122 -0
  130. data/lib/temporalio/internal/proto_utils.rb +165 -0
  131. data/lib/temporalio/internal/worker/activity_worker.rb +385 -0
  132. data/lib/temporalio/internal/worker/multi_runner.rb +213 -0
  133. data/lib/temporalio/internal/worker/workflow_instance/child_workflow_handle.rb +54 -0
  134. data/lib/temporalio/internal/worker/workflow_instance/context.rb +383 -0
  135. data/lib/temporalio/internal/worker/workflow_instance/details.rb +46 -0
  136. data/lib/temporalio/internal/worker/workflow_instance/external_workflow_handle.rb +32 -0
  137. data/lib/temporalio/internal/worker/workflow_instance/externally_immutable_hash.rb +22 -0
  138. data/lib/temporalio/internal/worker/workflow_instance/handler_execution.rb +25 -0
  139. data/lib/temporalio/internal/worker/workflow_instance/handler_hash.rb +41 -0
  140. data/lib/temporalio/internal/worker/workflow_instance/illegal_call_tracer.rb +97 -0
  141. data/lib/temporalio/internal/worker/workflow_instance/inbound_implementation.rb +62 -0
  142. data/lib/temporalio/internal/worker/workflow_instance/outbound_implementation.rb +400 -0
  143. data/lib/temporalio/internal/worker/workflow_instance/replay_safe_logger.rb +37 -0
  144. data/lib/temporalio/internal/worker/workflow_instance/replay_safe_metric.rb +40 -0
  145. data/lib/temporalio/internal/worker/workflow_instance/scheduler.rb +183 -0
  146. data/lib/temporalio/internal/worker/workflow_instance.rb +774 -0
  147. data/lib/temporalio/internal/worker/workflow_worker.rb +239 -0
  148. data/lib/temporalio/internal.rb +7 -0
  149. data/lib/temporalio/metric.rb +109 -0
  150. data/lib/temporalio/retry_policy.rb +74 -0
  151. data/lib/temporalio/runtime/metric_buffer.rb +94 -0
  152. data/lib/temporalio/runtime.rb +352 -0
  153. data/lib/temporalio/scoped_logger.rb +96 -0
  154. data/lib/temporalio/search_attributes.rb +356 -0
  155. data/lib/temporalio/testing/activity_environment.rb +160 -0
  156. data/lib/temporalio/testing/workflow_environment.rb +406 -0
  157. data/lib/temporalio/testing.rb +10 -0
  158. data/lib/temporalio/version.rb +5 -0
  159. data/lib/temporalio/worker/activity_executor/fiber.rb +49 -0
  160. data/lib/temporalio/worker/activity_executor/thread_pool.rb +46 -0
  161. data/lib/temporalio/worker/activity_executor.rb +55 -0
  162. data/lib/temporalio/worker/interceptor.rb +365 -0
  163. data/lib/temporalio/worker/thread_pool.rb +237 -0
  164. data/lib/temporalio/worker/tuner.rb +189 -0
  165. data/lib/temporalio/worker/workflow_executor/thread_pool.rb +235 -0
  166. data/lib/temporalio/worker/workflow_executor.rb +26 -0
  167. data/lib/temporalio/worker/workflow_replayer.rb +350 -0
  168. data/lib/temporalio/worker.rb +603 -0
  169. data/lib/temporalio/workflow/activity_cancellation_type.rb +20 -0
  170. data/lib/temporalio/workflow/child_workflow_cancellation_type.rb +21 -0
  171. data/lib/temporalio/workflow/child_workflow_handle.rb +43 -0
  172. data/lib/temporalio/workflow/definition.rb +598 -0
  173. data/lib/temporalio/workflow/external_workflow_handle.rb +41 -0
  174. data/lib/temporalio/workflow/future.rb +151 -0
  175. data/lib/temporalio/workflow/handler_unfinished_policy.rb +13 -0
  176. data/lib/temporalio/workflow/info.rb +104 -0
  177. data/lib/temporalio/workflow/parent_close_policy.rb +19 -0
  178. data/lib/temporalio/workflow/update_info.rb +20 -0
  179. data/lib/temporalio/workflow.rb +575 -0
  180. data/lib/temporalio/workflow_history.rb +47 -0
  181. data/lib/temporalio.rb +11 -0
  182. data/temporalio.gemspec +29 -0
  183. metadata +258 -0
@@ -0,0 +1,352 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'temporalio/internal/bridge'
4
+ require 'temporalio/internal/bridge/runtime'
5
+ require 'temporalio/internal/metric'
6
+ require 'temporalio/metric'
7
+ require 'temporalio/runtime/metric_buffer'
8
+
9
+ module Temporalio
10
+ # Runtime for Temporal Ruby SDK.
11
+ #
12
+ # Only one global {Runtime} needs to exist. Users are encouraged to use {default}. To configure it, create a runtime
13
+ # before any clients are created, and set it via {default=}. Every time a new runtime is created, a new internal Rust
14
+ # thread pool is created.
15
+ class Runtime
16
+ TelemetryOptions = Data.define(
17
+ :logging,
18
+ :metrics
19
+ )
20
+
21
+ # Telemetry options for the runtime.
22
+ #
23
+ # @!attribute logging
24
+ # @return [LoggingOptions, nil] Logging options, default is new {LoggingOptions} with no parameters. Can be set
25
+ # to nil to disable logging.
26
+ # @!attribute metrics
27
+ # @return [MetricsOptions, nil] Metrics options.
28
+ class TelemetryOptions
29
+ # Create telemetry options.
30
+ #
31
+ # @param logging [LoggingOptions, nil] Logging options, default is new {LoggingOptions} with no parameters. Can be
32
+ # set to nil to disable logging.
33
+ # @param metrics [MetricsOptions, nil] Metrics options.
34
+ def initialize(logging: LoggingOptions.new, metrics: nil)
35
+ super
36
+ end
37
+
38
+ # @!visibility private
39
+ def _to_bridge
40
+ # @type self: TelemetryOptions
41
+ Internal::Bridge::Runtime::TelemetryOptions.new(
42
+ logging: logging&._to_bridge,
43
+ metrics: metrics&._to_bridge
44
+ )
45
+ end
46
+ end
47
+
48
+ LoggingOptions = Data.define(
49
+ :log_filter
50
+ # TODO(cretz): forward_to
51
+ )
52
+
53
+ # Logging options for runtime telemetry.
54
+ #
55
+ # @!attribute log_filter
56
+ # @return [LoggingFilterOptions, String] Logging filter for Core, default is new {LoggingFilterOptions} with no
57
+ # parameters.
58
+ class LoggingOptions
59
+ # Create logging options
60
+ #
61
+ # @param log_filter [LoggingFilterOptions, String] Logging filter for Core.
62
+ def initialize(log_filter: LoggingFilterOptions.new)
63
+ super
64
+ end
65
+
66
+ # @!visibility private
67
+ def _to_bridge
68
+ # @type self: LoggingOptions
69
+ Internal::Bridge::Runtime::LoggingOptions.new(
70
+ log_filter: if log_filter.is_a?(String)
71
+ log_filter
72
+ elsif log_filter.is_a?(LoggingFilterOptions)
73
+ log_filter._to_bridge
74
+ else
75
+ raise 'Log filter must be string or LoggingFilterOptions'
76
+ end
77
+ )
78
+ end
79
+ end
80
+
81
+ LoggingFilterOptions = Data.define(
82
+ :core_level,
83
+ :other_level
84
+ )
85
+
86
+ # Logging filter options for Core.
87
+ #
88
+ # @!attribute core_level
89
+ # @return ['TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR'] Log level for Core log messages.
90
+ # @!attribute other_level
91
+ # @return ['TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR'] Log level for other Rust log messages.
92
+ class LoggingFilterOptions
93
+ # Create logging filter options.
94
+ #
95
+ # @param core_level ['TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR'] Log level for Core log messages.
96
+ # @!attribute other_level ['TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR'] Log level for other Rust log messages.
97
+ def initialize(core_level: 'WARN', other_level: 'ERROR')
98
+ super
99
+ end
100
+
101
+ # @!visibility private
102
+ def _to_bridge
103
+ # @type self: LoggingFilterOptions
104
+ "#{other_level},temporal_sdk_core=#{core_level},temporal_client=#{core_level},temporal_sdk=#{core_level}"
105
+ end
106
+ end
107
+
108
+ MetricsOptions = Data.define(
109
+ :opentelemetry,
110
+ :prometheus,
111
+ :buffer,
112
+ :attach_service_name,
113
+ :global_tags,
114
+ :metric_prefix
115
+ )
116
+
117
+ # Metrics options for runtime telemetry. Either {opentelemetry} or {prometheus} required, but not both.
118
+ #
119
+ # @!attribute opentelemetry
120
+ # @return [OpenTelemetryMetricsOptions, nil] OpenTelemetry options if using OpenTelemetry. This is mutually
121
+ # exclusive with `prometheus` and `buffer`.
122
+ # @!attribute prometheus
123
+ # @return [PrometheusMetricsOptions, nil] Prometheus options if using Prometheus. This is mutually exclusive with
124
+ # `opentelemetry` and `buffer`.
125
+ # @!attribute buffer
126
+ # @return [MetricBuffer, nil] Metric buffer to send all metrics to. This is mutually exclusive with `prometheus`
127
+ # and `opentelemetry`.
128
+ # @!attribute attach_service_name
129
+ # @return [Boolean] Whether to put the service_name on every metric.
130
+ # @!attribute global_tags
131
+ # @return [Hash<String, String>, nil] Resource tags to be applied to all metrics.
132
+ # @!attribute metric_prefix
133
+ # @return [String, nil] Prefix to put on every Temporal metric. If unset, defaults to `temporal_`.
134
+ class MetricsOptions
135
+ # Create metrics options. Either `opentelemetry` or `prometheus` required, but not both.
136
+ #
137
+ # @param opentelemetry [OpenTelemetryMetricsOptions, nil] OpenTelemetry options if using OpenTelemetry. This is
138
+ # mutually exclusive with `prometheus` and `buffer`.
139
+ # @param prometheus [PrometheusMetricsOptions, nil] Prometheus options if using Prometheus. This is mutually
140
+ # exclusive with `opentelemetry` and `buffer`.
141
+ # @param buffer [MetricBuffer, nil] Metric buffer to send all metrics to. This is mutually exclusive with
142
+ # `prometheus` and `opentelemetry`.
143
+ # @param attach_service_name [Boolean] Whether to put the service_name on every metric.
144
+ # @param global_tags [Hash<String, String>, nil] Resource tags to be applied to all metrics.
145
+ # @param metric_prefix [String, nil] Prefix to put on every Temporal metric. If unset, defaults to `temporal_`.
146
+ def initialize(
147
+ opentelemetry: nil,
148
+ prometheus: nil,
149
+ buffer: nil,
150
+ attach_service_name: true,
151
+ global_tags: nil,
152
+ metric_prefix: nil
153
+ )
154
+ if [opentelemetry, prometheus, buffer].count { |v| !v.nil? } > 1
155
+ raise 'Can only have one of opentelemetry, prometheus, or buffer'
156
+ end
157
+
158
+ super
159
+ end
160
+
161
+ # @!visibility private
162
+ def _to_bridge
163
+ # @type self: MetricsOptions
164
+ Internal::Bridge::Runtime::MetricsOptions.new(
165
+ opentelemetry: opentelemetry&._to_bridge,
166
+ prometheus: prometheus&._to_bridge,
167
+ buffered_with_size: buffer&._buffer_size,
168
+ attach_service_name:,
169
+ global_tags:,
170
+ metric_prefix:
171
+ )
172
+ end
173
+ end
174
+
175
+ OpenTelemetryMetricsOptions = Data.define(
176
+ :url,
177
+ :headers,
178
+ :metric_periodicity,
179
+ :metric_temporality,
180
+ :durations_as_seconds,
181
+ :http,
182
+ :histogram_bucket_overrides
183
+ )
184
+
185
+ # Options for exporting metrics to OpenTelemetry.
186
+ #
187
+ # @!attribute url
188
+ # @return [String] URL for OpenTelemetry endpoint.
189
+ # @!attribute headers
190
+ # @return [Hash<String, String>, nil] Headers for OpenTelemetry endpoint.
191
+ # @!attribute metric_periodicity
192
+ # @return [Float, nil] How frequently metrics should be exported, unset uses internal default.
193
+ # @!attribute metric_temporality
194
+ # @return [MetricTemporality] How frequently metrics should be exported, default is
195
+ # {MetricTemporality::CUMULATIVE}.
196
+ # @!attribute durations_as_seconds
197
+ # @return [Boolean] Whether to use float seconds instead of integer milliseconds for durations, default is
198
+ # +false+.
199
+ # @!attribute http
200
+ # @return [Boolean] True if the protocol is HTTP, false if gRPC (the default).
201
+ # @!attribute histogram_bucket_overrides
202
+ # @return [Hash<String, Array<Numeric>>, nil] Override default histogram buckets. Key of the hash it the metric
203
+ # name, value is an array of floats for the set of buckets.
204
+ class OpenTelemetryMetricsOptions
205
+ # OpenTelemetry metric temporality.
206
+ module MetricTemporality
207
+ CUMULATIVE = 1
208
+ DELTA = 2
209
+ end
210
+
211
+ # Create OpenTelemetry options.
212
+ #
213
+ # @param url [String] URL for OpenTelemetry endpoint.
214
+ # @param headers [Hash<String, String>, nil] Headers for OpenTelemetry endpoint.
215
+ # @param metric_periodicity [Float, nil] How frequently metrics should be exported, unset uses internal default.
216
+ # @param metric_temporality [MetricTemporality] How frequently metrics should be exported.
217
+ # @param durations_as_seconds [Boolean] Whether to use float seconds instead of integer milliseconds for
218
+ # durations.
219
+ # @param http [Boolean] True if the protocol is HTTP, false if gRPC (the default).
220
+ # @param histogram_bucket_overrides [Hash<String, Array<Numeric>>, nil] Override default histogram buckets. Key of
221
+ # the hash it the metric name, value is an array of floats for the set of buckets.
222
+ def initialize(
223
+ url:,
224
+ headers: nil,
225
+ metric_periodicity: nil,
226
+ metric_temporality: MetricTemporality::CUMULATIVE,
227
+ durations_as_seconds: false,
228
+ http: false,
229
+ histogram_bucket_overrides: nil
230
+ )
231
+ super
232
+ end
233
+
234
+ # @!visibility private
235
+ def _to_bridge
236
+ # @type self: OpenTelemetryMetricsOptions
237
+ Internal::Bridge::Runtime::OpenTelemetryMetricsOptions.new(
238
+ url:,
239
+ headers:,
240
+ metric_periodicity:,
241
+ metric_temporality_delta: case metric_temporality
242
+ when MetricTemporality::CUMULATIVE then false
243
+ when MetricTemporality::DELTA then true
244
+ else raise 'Unrecognized metric temporality'
245
+ end,
246
+ durations_as_seconds:,
247
+ http:,
248
+ histogram_bucket_overrides:
249
+ )
250
+ end
251
+ end
252
+
253
+ PrometheusMetricsOptions = Data.define(
254
+ :bind_address,
255
+ :counters_total_suffix,
256
+ :unit_suffix,
257
+ :durations_as_seconds,
258
+ :histogram_bucket_overrides
259
+ )
260
+
261
+ # Options for exporting metrics to Prometheus.
262
+ #
263
+ # @!attribute bind_address
264
+ # @return [String] Address to bind to for Prometheus endpoint.
265
+ # @!attribute counters_total_suffix
266
+ # @return [Boolean] If `true`, all counters will include a `_total` suffix.
267
+ # @!attribute unit_suffix
268
+ # @return [Boolean] If `true`, all histograms will include the unit in their name as a suffix.
269
+ # @!attribute durations_as_seconds
270
+ # @return [Boolean] Whether to use float seconds instead of integer milliseconds for durations.
271
+ # @!attribute histogram_bucket_overrides
272
+ # @return [Hash<String, Array<Numeric>>, nil] Override default histogram buckets. Key of the hash it the metric
273
+ # name, value is an array of floats for the set of buckets.
274
+ class PrometheusMetricsOptions
275
+ # Create Prometheus options.
276
+ #
277
+ # @param bind_address [String] Address to bind to for Prometheus endpoint.
278
+ # @param counters_total_suffix [Boolean] If `true`, all counters will include a `_total` suffix.
279
+ # @param unit_suffix [Boolean] If `true`, all histograms will include the unit in their name as a suffix.
280
+ # @param durations_as_seconds [Boolean] Whether to use float seconds instead of integer milliseconds for
281
+ # durations.
282
+ # @param histogram_bucket_overrides [Hash<String, Array<Numeric>>, nil] Override default histogram buckets. Key of
283
+ # the hash it the metric name, value is an array of floats for the set of buckets.
284
+ def initialize(
285
+ bind_address:,
286
+ counters_total_suffix: false,
287
+ unit_suffix: false,
288
+ durations_as_seconds: false,
289
+ histogram_bucket_overrides: nil
290
+ )
291
+ super
292
+ end
293
+
294
+ # @!visibility private
295
+ def _to_bridge
296
+ # @type self: PrometheusMetricsOptions
297
+ Internal::Bridge::Runtime::PrometheusMetricsOptions.new(
298
+ bind_address:,
299
+ counters_total_suffix:,
300
+ unit_suffix:,
301
+ durations_as_seconds:,
302
+ histogram_bucket_overrides:
303
+ )
304
+ end
305
+ end
306
+
307
+ # Default runtime, lazily created upon first access. If needing a different default, make sure it is updated via
308
+ # {default=} before this is called (either directly or as a parameter to something like {Client}).
309
+ #
310
+ # @return [Runtime] Default runtime.
311
+ def self.default
312
+ @default ||= Runtime.new
313
+ end
314
+
315
+ # Set the default runtime. Must be called before {default} accessed.
316
+ #
317
+ # @param runtime [Runtime] Runtime to set as default.
318
+ # @raise If default has already been accessed.
319
+ def self.default=(runtime)
320
+ raise 'Runtime already set or requested' unless @default.nil?
321
+
322
+ @default = runtime
323
+ end
324
+
325
+ # @return [Metric::Meter] Metric meter that can create and record metric values.
326
+ attr_reader :metric_meter
327
+
328
+ # Create new Runtime. For most users, this should only be done once globally. In addition to creating a Rust thread
329
+ # pool, this also consumes a Ruby thread for its lifetime.
330
+ #
331
+ # @param telemetry [TelemetryOptions] Telemetry options to set.
332
+ def initialize(telemetry: TelemetryOptions.new)
333
+ # Set runtime on the buffer which will fail if the buffer is used on another runtime
334
+ telemetry.metrics&.buffer&._set_runtime(self)
335
+
336
+ @core_runtime = Internal::Bridge::Runtime.new(
337
+ Internal::Bridge::Runtime::Options.new(telemetry: telemetry._to_bridge)
338
+ )
339
+ @metric_meter = Internal::Metric::Meter.create_from_runtime(self) || Metric::Meter.null
340
+ # We need a thread to run the command loop
341
+ # TODO(cretz): Is this something users should be concerned about or need control over?
342
+ Thread.new do
343
+ @core_runtime.run_command_loop
344
+ end
345
+ end
346
+
347
+ # @!visibility private
348
+ def _core_runtime
349
+ @core_runtime
350
+ end
351
+ end
352
+ end
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'delegate'
4
+ require 'logger'
5
+
6
+ module Temporalio
7
+ # Implementation via delegator to {::Logger} that puts scoped values on the log message and appends them to the log
8
+ # message.
9
+ class ScopedLogger < SimpleDelegator
10
+ # @!attribute scoped_values_getter
11
+ # @return [Proc, nil] Proc to call to get scoped values when needed.
12
+ attr_accessor :scoped_values_getter
13
+
14
+ # @!attribute scoped_values_getter
15
+ # @return [Boolean] Whether the scoped value appending is disabled.
16
+ attr_accessor :disable_scoped_values
17
+
18
+ # @see Logger.add
19
+ def add(severity, message = nil, progname = nil)
20
+ return true if (severity || Logger::Unknown) < level
21
+ return super if scoped_values_getter.nil? || @disable_scoped_values
22
+
23
+ scoped_values = scoped_values_getter.call
24
+ return super if scoped_values.nil?
25
+
26
+ if message.nil?
27
+ if block_given?
28
+ message = yield
29
+ else
30
+ message = progname
31
+ progname = nil
32
+ end
33
+ end
34
+ # For exceptions we need to dup and append here, for everything else we
35
+ # need to delegate to a log message
36
+ new_message = if message.is_a?(Exception)
37
+ message.exception("#{message.message} #{scoped_values}")
38
+ else
39
+ LogMessage.new(message, scoped_values)
40
+ end
41
+ super(severity, new_message, progname)
42
+ end
43
+ alias log add
44
+
45
+ # @see Logger.debug
46
+ def debug(progname = nil, &)
47
+ add(Logger::DEBUG, nil, progname, &)
48
+ end
49
+
50
+ # @see Logger.info
51
+ def info(progname = nil, &)
52
+ add(Logger::INFO, nil, progname, &)
53
+ end
54
+
55
+ # @see Logger.warn
56
+ def warn(progname = nil, &)
57
+ add(Logger::WARN, nil, progname, &)
58
+ end
59
+
60
+ # @see Logger.error
61
+ def error(progname = nil, &)
62
+ add(Logger::ERROR, nil, progname, &)
63
+ end
64
+
65
+ # @see Logger.fatal
66
+ def fatal(progname = nil, &)
67
+ add(Logger::FATAL, nil, progname, &)
68
+ end
69
+
70
+ # @see Logger.unknown
71
+ def unknown(progname = nil, &)
72
+ add(Logger::UNKNOWN, nil, progname, &)
73
+ end
74
+
75
+ # Scoped log message wrapping original log message.
76
+ class LogMessage
77
+ # @return [Object] Original log message.
78
+ attr_reader :message
79
+
80
+ # @return [Object] Scoped values.
81
+ attr_reader :scoped_values
82
+
83
+ # @!visibility private
84
+ def initialize(message, scoped_values)
85
+ @message = message
86
+ @scoped_values = scoped_values
87
+ end
88
+
89
+ # @return [String] Message with scoped values appended.
90
+ def inspect
91
+ message_str = message.is_a?(String) ? message : message.inspect
92
+ "#{message_str} #{scoped_values}"
93
+ end
94
+ end
95
+ end
96
+ end