@temporalio/core-bridge 1.12.0 → 1.12.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 (116) hide show
  1. package/Cargo.lock +64 -119
  2. package/Cargo.toml +1 -1
  3. package/index.js +3 -2
  4. package/package.json +3 -3
  5. package/releases/aarch64-apple-darwin/index.node +0 -0
  6. package/releases/aarch64-unknown-linux-gnu/index.node +0 -0
  7. package/releases/x86_64-apple-darwin/index.node +0 -0
  8. package/releases/x86_64-pc-windows-msvc/index.node +0 -0
  9. package/releases/x86_64-unknown-linux-gnu/index.node +0 -0
  10. package/sdk-core/.cargo/config.toml +1 -2
  11. package/sdk-core/.github/workflows/per-pr.yml +2 -0
  12. package/sdk-core/AGENTS.md +7 -0
  13. package/sdk-core/Cargo.toml +9 -5
  14. package/sdk-core/README.md +6 -5
  15. package/sdk-core/client/Cargo.toml +3 -2
  16. package/sdk-core/client/src/lib.rs +17 -8
  17. package/sdk-core/client/src/metrics.rs +57 -23
  18. package/sdk-core/client/src/raw.rs +33 -15
  19. package/sdk-core/core/Cargo.toml +11 -9
  20. package/sdk-core/core/benches/workflow_replay.rs +114 -15
  21. package/sdk-core/core/src/core_tests/activity_tasks.rs +18 -18
  22. package/sdk-core/core/src/core_tests/child_workflows.rs +4 -4
  23. package/sdk-core/core/src/core_tests/determinism.rs +6 -6
  24. package/sdk-core/core/src/core_tests/local_activities.rs +20 -20
  25. package/sdk-core/core/src/core_tests/mod.rs +40 -5
  26. package/sdk-core/core/src/core_tests/queries.rs +25 -16
  27. package/sdk-core/core/src/core_tests/replay_flag.rs +3 -3
  28. package/sdk-core/core/src/core_tests/updates.rs +3 -3
  29. package/sdk-core/core/src/core_tests/workers.rs +9 -7
  30. package/sdk-core/core/src/core_tests/workflow_tasks.rs +40 -42
  31. package/sdk-core/core/src/ephemeral_server/mod.rs +1 -19
  32. package/sdk-core/core/src/lib.rs +10 -1
  33. package/sdk-core/core/src/pollers/poll_buffer.rs +2 -2
  34. package/sdk-core/core/src/replay/mod.rs +3 -3
  35. package/sdk-core/core/src/telemetry/metrics.rs +306 -152
  36. package/sdk-core/core/src/telemetry/mod.rs +11 -4
  37. package/sdk-core/core/src/telemetry/otel.rs +134 -131
  38. package/sdk-core/core/src/telemetry/prometheus_meter.rs +885 -0
  39. package/sdk-core/core/src/telemetry/prometheus_server.rs +48 -28
  40. package/sdk-core/core/src/test_help/mod.rs +27 -12
  41. package/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +7 -7
  42. package/sdk-core/core/src/worker/activities.rs +4 -4
  43. package/sdk-core/core/src/worker/client/mocks.rs +10 -3
  44. package/sdk-core/core/src/worker/client.rs +68 -5
  45. package/sdk-core/core/src/worker/heartbeat.rs +229 -0
  46. package/sdk-core/core/src/worker/mod.rs +35 -14
  47. package/sdk-core/core/src/worker/tuner/resource_based.rs +4 -4
  48. package/sdk-core/core/src/worker/workflow/history_update.rs +71 -19
  49. package/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +1 -2
  50. package/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +1 -1
  51. package/sdk-core/core/src/worker/workflow/machines/nexus_operation_state_machine.rs +31 -48
  52. package/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +1 -2
  53. package/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +3 -3
  54. package/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +4 -1
  55. package/sdk-core/core/src/worker/workflow/managed_run.rs +1 -1
  56. package/sdk-core/core/src/worker/workflow/mod.rs +15 -15
  57. package/sdk-core/core-api/Cargo.toml +2 -2
  58. package/sdk-core/core-api/src/envconfig.rs +204 -99
  59. package/sdk-core/core-api/src/lib.rs +9 -0
  60. package/sdk-core/core-api/src/telemetry/metrics.rs +548 -100
  61. package/sdk-core/core-api/src/worker.rs +11 -5
  62. package/sdk-core/core-c-bridge/Cargo.toml +49 -0
  63. package/sdk-core/core-c-bridge/build.rs +26 -0
  64. package/sdk-core/core-c-bridge/include/temporal-sdk-core-c-bridge.h +817 -0
  65. package/sdk-core/core-c-bridge/src/client.rs +679 -0
  66. package/sdk-core/core-c-bridge/src/lib.rs +245 -0
  67. package/sdk-core/core-c-bridge/src/metric.rs +682 -0
  68. package/sdk-core/core-c-bridge/src/random.rs +61 -0
  69. package/sdk-core/core-c-bridge/src/runtime.rs +445 -0
  70. package/sdk-core/core-c-bridge/src/testing.rs +282 -0
  71. package/sdk-core/core-c-bridge/src/tests/context.rs +644 -0
  72. package/sdk-core/core-c-bridge/src/tests/mod.rs +178 -0
  73. package/sdk-core/core-c-bridge/src/tests/utils.rs +108 -0
  74. package/sdk-core/core-c-bridge/src/worker.rs +1069 -0
  75. package/sdk-core/etc/deps.svg +64 -64
  76. package/sdk-core/sdk/src/activity_context.rs +6 -4
  77. package/sdk-core/sdk/src/lib.rs +49 -27
  78. package/sdk-core/sdk/src/workflow_future.rs +18 -25
  79. package/sdk-core/sdk-core-protos/protos/api_upstream/README.md +4 -0
  80. package/sdk-core/sdk-core-protos/protos/api_upstream/buf.yaml +0 -2
  81. package/sdk-core/sdk-core-protos/protos/api_upstream/openapi/openapiv2.json +630 -83
  82. package/sdk-core/sdk-core-protos/protos/api_upstream/openapi/openapiv3.yaml +632 -78
  83. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/batch/v1/message.proto +4 -4
  84. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/command/v1/message.proto +6 -4
  85. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/common/v1/message.proto +2 -2
  86. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/deployment/v1/message.proto +32 -2
  87. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/common.proto +10 -1
  88. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/deployment.proto +26 -0
  89. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +2 -0
  90. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/reset.proto +4 -4
  91. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/failure/v1/message.proto +2 -2
  92. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/history/v1/message.proto +47 -31
  93. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/nexus/v1/message.proto +4 -4
  94. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/schedule/v1/message.proto +7 -1
  95. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/worker/v1/message.proto +134 -0
  96. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflow/v1/message.proto +14 -11
  97. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +148 -37
  98. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +21 -0
  99. package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +4 -4
  100. package/sdk-core/sdk-core-protos/src/history_builder.rs +9 -5
  101. package/sdk-core/sdk-core-protos/src/lib.rs +96 -6
  102. package/sdk-core/test-utils/src/lib.rs +11 -3
  103. package/sdk-core/tests/cloud_tests.rs +3 -3
  104. package/sdk-core/tests/heavy_tests.rs +11 -3
  105. package/sdk-core/tests/integ_tests/client_tests.rs +12 -13
  106. package/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +1 -1
  107. package/sdk-core/tests/integ_tests/metrics_tests.rs +188 -83
  108. package/sdk-core/tests/integ_tests/polling_tests.rs +1 -1
  109. package/sdk-core/tests/integ_tests/queries_tests.rs +56 -40
  110. package/sdk-core/tests/integ_tests/update_tests.rs +2 -7
  111. package/sdk-core/tests/integ_tests/worker_tests.rs +3 -4
  112. package/sdk-core/tests/integ_tests/worker_versioning_tests.rs +3 -7
  113. package/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +3 -5
  114. package/sdk-core/tests/integ_tests/workflow_tests/nexus.rs +24 -17
  115. package/src/client.rs +6 -0
  116. package/src/metrics.rs +6 -6
@@ -5,18 +5,25 @@ mod log_export;
5
5
  pub(crate) mod metrics;
6
6
  #[cfg(feature = "otel")]
7
7
  mod otel;
8
- #[cfg(feature = "otel")]
8
+ #[cfg(feature = "prom")]
9
+ mod prometheus_meter;
10
+ #[cfg(feature = "prom")]
9
11
  mod prometheus_server;
10
12
 
13
+ // Always export bucket configuration function since it's used by both OTel and Prometheus
14
+ pub use metrics::default_buckets_for;
15
+
11
16
  #[cfg(feature = "otel")]
12
17
  pub use metrics::{
13
18
  ACTIVITY_EXEC_LATENCY_HISTOGRAM_NAME, ACTIVITY_SCHED_TO_START_LATENCY_HISTOGRAM_NAME,
14
19
  MetricsCallBuffer, WORKFLOW_E2E_LATENCY_HISTOGRAM_NAME,
15
20
  WORKFLOW_TASK_EXECUTION_LATENCY_HISTOGRAM_NAME, WORKFLOW_TASK_REPLAY_LATENCY_HISTOGRAM_NAME,
16
- WORKFLOW_TASK_SCHED_TO_START_LATENCY_HISTOGRAM_NAME, default_buckets_for,
21
+ WORKFLOW_TASK_SCHED_TO_START_LATENCY_HISTOGRAM_NAME,
17
22
  };
18
23
  #[cfg(feature = "otel")]
19
- pub use otel::{build_otlp_metric_exporter, start_prometheus_metric_exporter};
24
+ pub use otel::build_otlp_metric_exporter;
25
+ #[cfg(feature = "prom")]
26
+ pub use prometheus_server::start_prometheus_metric_exporter;
20
27
 
21
28
  pub use log_export::{CoreLogBuffer, CoreLogBufferedConsumer, CoreLogStreamConsumer};
22
29
 
@@ -145,7 +152,7 @@ pub fn set_trace_subscriber_for_current_thread(sub: impl Subscriber + Send + Syn
145
152
 
146
153
  /// Undoes [set_trace_subscriber_for_current_thread]
147
154
  pub fn remove_trace_subscriber_for_current_thread() {
148
- SUB_GUARD.with(|sg| sg.take());
155
+ SUB_GUARD.take();
149
156
  }
150
157
 
151
158
  impl CoreTelemetry for TelemetryInstance {
@@ -7,7 +7,6 @@ use super::{
7
7
  WORKFLOW_TASK_REPLAY_LATENCY_HISTOGRAM_NAME,
8
8
  WORKFLOW_TASK_SCHED_TO_START_LATENCY_HISTOGRAM_NAME,
9
9
  },
10
- prometheus_server::PromServer,
11
10
  };
12
11
  use crate::{abstractions::dbg_panic, telemetry::metrics::DEFAULT_S_BUCKETS};
13
12
  use opentelemetry::{
@@ -16,38 +15,43 @@ use opentelemetry::{
16
15
  };
17
16
  use opentelemetry_otlp::{WithExportConfig, WithHttpConfig, WithTonicConfig};
18
17
  use opentelemetry_sdk::{
19
- Resource,
18
+ Resource, metrics,
20
19
  metrics::{
21
- Aggregation, Instrument, InstrumentKind, MeterProviderBuilder, MetricError, PeriodicReader,
22
- SdkMeterProvider, Temporality, View, new_view,
20
+ Aggregation, Instrument, InstrumentKind, MeterProviderBuilder, PeriodicReader,
21
+ SdkMeterProvider, Temporality,
23
22
  },
24
23
  };
25
- use std::{collections::HashMap, net::SocketAddr, sync::Arc, time::Duration};
24
+ use std::{collections::HashMap, sync::Arc, time::Duration};
26
25
  use temporal_sdk_core_api::telemetry::{
27
26
  HistogramBucketOverrides, MetricTemporality, OtelCollectorOptions, OtlpProtocol,
28
- PrometheusExporterOptions,
29
27
  metrics::{
30
- CoreMeter, Counter, Gauge, GaugeF64, Histogram, HistogramDuration, HistogramF64,
28
+ CoreMeter, Counter, Gauge, GaugeF64, Histogram, HistogramBase, HistogramDuration,
29
+ HistogramDurationBase, HistogramF64, HistogramF64Base, MetricAttributable,
31
30
  MetricAttributes, MetricParameters, NewAttributes,
32
31
  },
33
32
  };
34
- use tokio::task::AbortHandle;
35
33
  use tonic::{metadata::MetadataMap, transport::ClientTlsConfig};
36
34
 
37
- /// A specialized `Result` type for metric operations.
38
- type Result<T> = std::result::Result<T, MetricError>;
39
-
40
- fn histo_view(metric_name: &'static str, use_seconds: bool) -> Result<Box<dyn View>> {
41
- let buckets = default_buckets_for(metric_name, use_seconds);
42
- new_view(
43
- Instrument::new().name(format!("*{metric_name}")),
44
- opentelemetry_sdk::metrics::Stream::new().aggregation(
45
- Aggregation::ExplicitBucketHistogram {
46
- boundaries: buckets.to_vec(),
47
- record_min_max: true,
48
- },
49
- ),
50
- )
35
+ fn histo_view(
36
+ metric_name: &'static str,
37
+ use_seconds: bool,
38
+ ) -> impl Fn(&Instrument) -> Option<metrics::Stream> + Send + Sync + 'static {
39
+ let buckets = default_buckets_for(metric_name, use_seconds).to_vec();
40
+ move |ins: &Instrument| {
41
+ if ins.name().ends_with(metric_name) {
42
+ Some(
43
+ metrics::Stream::builder()
44
+ .with_aggregation(Aggregation::ExplicitBucketHistogram {
45
+ boundaries: buckets.clone(),
46
+ record_min_max: true,
47
+ })
48
+ .build()
49
+ .expect("Hardcoded metric stream always builds"),
50
+ )
51
+ } else {
52
+ None
53
+ }
54
+ }
51
55
  }
52
56
 
53
57
  pub(super) fn augment_meter_provider_with_defaults(
@@ -55,68 +59,73 @@ pub(super) fn augment_meter_provider_with_defaults(
55
59
  global_tags: &HashMap<String, String>,
56
60
  use_seconds: bool,
57
61
  bucket_overrides: HistogramBucketOverrides,
58
- ) -> Result<MeterProviderBuilder> {
62
+ ) -> Result<MeterProviderBuilder, anyhow::Error> {
59
63
  for (name, buckets) in bucket_overrides.overrides {
60
- mpb = mpb.with_view(new_view(
61
- Instrument::new().name(format!("*{name}")),
62
- opentelemetry_sdk::metrics::Stream::new().aggregation(
63
- Aggregation::ExplicitBucketHistogram {
64
- boundaries: buckets,
65
- record_min_max: true,
66
- },
67
- ),
68
- )?)
64
+ mpb = mpb.with_view(move |ins: &Instrument| {
65
+ if ins.name().contains(&name) {
66
+ Some(
67
+ metrics::Stream::builder()
68
+ .with_aggregation(Aggregation::ExplicitBucketHistogram {
69
+ boundaries: buckets.clone(),
70
+ record_min_max: true,
71
+ })
72
+ .build()
73
+ .expect("Hardcoded metric stream always builds"),
74
+ )
75
+ } else {
76
+ None
77
+ }
78
+ });
69
79
  }
70
80
  let mut mpb = mpb
71
- .with_view(histo_view(
72
- WORKFLOW_E2E_LATENCY_HISTOGRAM_NAME,
73
- use_seconds,
74
- )?)
81
+ .with_view(histo_view(WORKFLOW_E2E_LATENCY_HISTOGRAM_NAME, use_seconds))
75
82
  .with_view(histo_view(
76
83
  WORKFLOW_TASK_EXECUTION_LATENCY_HISTOGRAM_NAME,
77
84
  use_seconds,
78
- )?)
85
+ ))
79
86
  .with_view(histo_view(
80
87
  WORKFLOW_TASK_REPLAY_LATENCY_HISTOGRAM_NAME,
81
88
  use_seconds,
82
- )?)
89
+ ))
83
90
  .with_view(histo_view(
84
91
  WORKFLOW_TASK_SCHED_TO_START_LATENCY_HISTOGRAM_NAME,
85
92
  use_seconds,
86
- )?)
93
+ ))
87
94
  .with_view(histo_view(
88
95
  ACTIVITY_SCHED_TO_START_LATENCY_HISTOGRAM_NAME,
89
96
  use_seconds,
90
- )?)
97
+ ))
91
98
  .with_view(histo_view(
92
99
  ACTIVITY_EXEC_LATENCY_HISTOGRAM_NAME,
93
100
  use_seconds,
94
- )?);
101
+ ));
95
102
  // Fallback default
96
- mpb = mpb.with_view(new_view(
97
- {
98
- let mut i = Instrument::new();
99
- i.kind = Some(InstrumentKind::Histogram);
100
- i
101
- },
102
- opentelemetry_sdk::metrics::Stream::new().aggregation(
103
- Aggregation::ExplicitBucketHistogram {
104
- boundaries: if use_seconds {
105
- DEFAULT_S_BUCKETS.to_vec()
106
- } else {
107
- DEFAULT_MS_BUCKETS.to_vec()
108
- },
109
- record_min_max: true,
110
- },
111
- ),
112
- )?);
103
+ mpb = mpb.with_view(move |ins: &Instrument| {
104
+ if ins.kind() == InstrumentKind::Histogram {
105
+ Some(
106
+ metrics::Stream::builder()
107
+ .with_aggregation(Aggregation::ExplicitBucketHistogram {
108
+ boundaries: if use_seconds {
109
+ DEFAULT_S_BUCKETS.to_vec()
110
+ } else {
111
+ DEFAULT_MS_BUCKETS.to_vec()
112
+ },
113
+ record_min_max: true,
114
+ })
115
+ .build()
116
+ .expect("Hardcoded metric stream always builds"),
117
+ )
118
+ } else {
119
+ None
120
+ }
121
+ });
113
122
  Ok(mpb.with_resource(default_resource(global_tags)))
114
123
  }
115
124
 
116
125
  /// Create an OTel meter that can be used as a [CoreMeter] to export metrics over OTLP.
117
126
  pub fn build_otlp_metric_exporter(
118
127
  opts: OtelCollectorOptions,
119
- ) -> std::result::Result<CoreOtelMeter, anyhow::Error> {
128
+ ) -> Result<CoreOtelMeter, anyhow::Error> {
120
129
  let exporter = match opts.protocol {
121
130
  OtlpProtocol::Grpc => {
122
131
  let mut exporter = opentelemetry_otlp::MetricExporter::builder()
@@ -154,40 +163,6 @@ pub fn build_otlp_metric_exporter(
154
163
  })
155
164
  }
156
165
 
157
- pub struct StartedPromServer {
158
- pub meter: Arc<CoreOtelMeter>,
159
- pub bound_addr: SocketAddr,
160
- pub abort_handle: AbortHandle,
161
- }
162
-
163
- /// Builds and runs a prometheus endpoint which can be scraped by prom instances for metrics export.
164
- /// Returns the meter that can be used as a [CoreMeter].
165
- ///
166
- /// Requires a Tokio runtime to exist, and will block briefly while binding the server endpoint.
167
- pub fn start_prometheus_metric_exporter(
168
- opts: PrometheusExporterOptions,
169
- ) -> std::result::Result<StartedPromServer, anyhow::Error> {
170
- let (srv, exporter) = PromServer::new(&opts)?;
171
- let meter_provider = augment_meter_provider_with_defaults(
172
- MeterProviderBuilder::default().with_reader(exporter),
173
- &opts.global_tags,
174
- opts.use_seconds_for_durations,
175
- opts.histogram_bucket_overrides,
176
- )?
177
- .build();
178
- let bound_addr = srv.bound_addr()?;
179
- let handle = tokio::spawn(async move { srv.run().await });
180
- Ok(StartedPromServer {
181
- meter: Arc::new(CoreOtelMeter {
182
- meter: meter_provider.meter(TELEM_SERVICE_NAME),
183
- use_seconds_for_durations: opts.use_seconds_for_durations,
184
- _mp: meter_provider,
185
- }),
186
- bound_addr,
187
- abort_handle: handle.abort_handle(),
188
- })
189
- }
190
-
191
166
  #[derive(Debug)]
192
167
  pub struct CoreOtelMeter {
193
168
  pub meter: Meter,
@@ -218,81 +193,109 @@ impl CoreMeter for CoreOtelMeter {
218
193
  }
219
194
  }
220
195
 
221
- fn counter(&self, params: MetricParameters) -> Arc<dyn Counter> {
222
- Arc::new(
196
+ fn counter(&self, params: MetricParameters) -> Counter {
197
+ Counter::new(Arc::new(
223
198
  self.meter
224
199
  .u64_counter(params.name)
225
200
  .with_unit(params.unit)
226
201
  .with_description(params.description)
227
202
  .build(),
228
- )
203
+ ))
229
204
  }
230
205
 
231
- fn histogram(&self, params: MetricParameters) -> Arc<dyn Histogram> {
232
- Arc::new(
233
- self.meter
234
- .u64_histogram(params.name)
235
- .with_unit(params.unit)
236
- .with_description(params.description)
237
- .build(),
238
- )
206
+ fn histogram(&self, params: MetricParameters) -> Histogram {
207
+ Histogram::new(Arc::new(self.create_histogram(params)))
239
208
  }
240
209
 
241
- fn histogram_f64(&self, params: MetricParameters) -> Arc<dyn HistogramF64> {
242
- Arc::new(
243
- self.meter
244
- .f64_histogram(params.name)
245
- .with_unit(params.unit)
246
- .with_description(params.description)
247
- .build(),
248
- )
210
+ fn histogram_f64(&self, params: MetricParameters) -> HistogramF64 {
211
+ HistogramF64::new(Arc::new(self.create_histogram_f64(params)))
249
212
  }
250
213
 
251
- fn histogram_duration(&self, mut params: MetricParameters) -> Arc<dyn HistogramDuration> {
252
- Arc::new(if self.use_seconds_for_durations {
214
+ fn histogram_duration(&self, mut params: MetricParameters) -> HistogramDuration {
215
+ HistogramDuration::new(Arc::new(if self.use_seconds_for_durations {
253
216
  params.unit = "s".into();
254
- DurationHistogram::Seconds(self.histogram_f64(params))
217
+ DurationHistogram::Seconds(self.create_histogram_f64(params))
255
218
  } else {
256
219
  params.unit = "ms".into();
257
- DurationHistogram::Milliseconds(self.histogram(params))
258
- })
220
+ DurationHistogram::Milliseconds(self.create_histogram(params))
221
+ }))
259
222
  }
260
223
 
261
- fn gauge(&self, params: MetricParameters) -> Arc<dyn Gauge> {
262
- Arc::new(
224
+ fn gauge(&self, params: MetricParameters) -> Gauge {
225
+ Gauge::new(Arc::new(
263
226
  self.meter
264
227
  .u64_gauge(params.name)
265
228
  .with_unit(params.unit)
266
229
  .with_description(params.description)
267
230
  .build(),
268
- )
231
+ ))
269
232
  }
270
233
 
271
- fn gauge_f64(&self, params: MetricParameters) -> Arc<dyn GaugeF64> {
272
- Arc::new(
234
+ fn gauge_f64(&self, params: MetricParameters) -> GaugeF64 {
235
+ GaugeF64::new(Arc::new(
273
236
  self.meter
274
237
  .f64_gauge(params.name)
275
238
  .with_unit(params.unit)
276
239
  .with_description(params.description)
277
240
  .build(),
278
- )
241
+ ))
242
+ }
243
+ }
244
+
245
+ impl CoreOtelMeter {
246
+ fn create_histogram(&self, params: MetricParameters) -> opentelemetry::metrics::Histogram<u64> {
247
+ self.meter
248
+ .u64_histogram(params.name)
249
+ .with_unit(params.unit)
250
+ .with_description(params.description)
251
+ .build()
252
+ }
253
+
254
+ fn create_histogram_f64(
255
+ &self,
256
+ params: MetricParameters,
257
+ ) -> opentelemetry::metrics::Histogram<f64> {
258
+ self.meter
259
+ .f64_histogram(params.name)
260
+ .with_unit(params.unit)
261
+ .with_description(params.description)
262
+ .build()
279
263
  }
280
264
  }
281
265
 
282
- /// A histogram being used to record durations.
283
- #[derive(Clone)]
284
266
  enum DurationHistogram {
285
- Milliseconds(Arc<dyn Histogram>),
286
- Seconds(Arc<dyn HistogramF64>),
267
+ Milliseconds(opentelemetry::metrics::Histogram<u64>),
268
+ Seconds(opentelemetry::metrics::Histogram<f64>),
269
+ }
270
+
271
+ enum DurationHistogramBase {
272
+ Millis(Box<dyn HistogramBase>),
273
+ Secs(Box<dyn HistogramF64Base>),
287
274
  }
288
- impl HistogramDuration for DurationHistogram {
289
- fn record(&self, value: Duration, attributes: &MetricAttributes) {
275
+
276
+ impl HistogramDurationBase for DurationHistogramBase {
277
+ fn records(&self, value: Duration) {
290
278
  match self {
291
- DurationHistogram::Milliseconds(h) => h.record(value.as_millis() as u64, attributes),
292
- DurationHistogram::Seconds(h) => h.record(value.as_secs_f64(), attributes),
279
+ DurationHistogramBase::Millis(h) => h.records(value.as_millis() as u64),
280
+ DurationHistogramBase::Secs(h) => h.records(value.as_secs_f64()),
293
281
  }
294
282
  }
295
283
  }
284
+ impl MetricAttributable<Box<dyn HistogramDurationBase>> for DurationHistogram {
285
+ fn with_attributes(
286
+ &self,
287
+ attributes: &MetricAttributes,
288
+ ) -> Result<Box<dyn HistogramDurationBase>, Box<dyn std::error::Error>> {
289
+ Ok(match self {
290
+ DurationHistogram::Milliseconds(h) => Box::new(DurationHistogramBase::Millis(
291
+ h.with_attributes(attributes)?,
292
+ )),
293
+ DurationHistogram::Seconds(h) => {
294
+ Box::new(DurationHistogramBase::Secs(h.with_attributes(attributes)?))
295
+ }
296
+ })
297
+ }
298
+ }
296
299
 
297
300
  fn default_resource_instance() -> &'static Resource {
298
301
  use std::sync::OnceLock;