@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.
- package/Cargo.lock +64 -119
- package/Cargo.toml +1 -1
- package/index.js +3 -2
- package/package.json +3 -3
- package/releases/aarch64-apple-darwin/index.node +0 -0
- package/releases/aarch64-unknown-linux-gnu/index.node +0 -0
- package/releases/x86_64-apple-darwin/index.node +0 -0
- package/releases/x86_64-pc-windows-msvc/index.node +0 -0
- package/releases/x86_64-unknown-linux-gnu/index.node +0 -0
- package/sdk-core/.cargo/config.toml +1 -2
- package/sdk-core/.github/workflows/per-pr.yml +2 -0
- package/sdk-core/AGENTS.md +7 -0
- package/sdk-core/Cargo.toml +9 -5
- package/sdk-core/README.md +6 -5
- package/sdk-core/client/Cargo.toml +3 -2
- package/sdk-core/client/src/lib.rs +17 -8
- package/sdk-core/client/src/metrics.rs +57 -23
- package/sdk-core/client/src/raw.rs +33 -15
- package/sdk-core/core/Cargo.toml +11 -9
- package/sdk-core/core/benches/workflow_replay.rs +114 -15
- package/sdk-core/core/src/core_tests/activity_tasks.rs +18 -18
- package/sdk-core/core/src/core_tests/child_workflows.rs +4 -4
- package/sdk-core/core/src/core_tests/determinism.rs +6 -6
- package/sdk-core/core/src/core_tests/local_activities.rs +20 -20
- package/sdk-core/core/src/core_tests/mod.rs +40 -5
- package/sdk-core/core/src/core_tests/queries.rs +25 -16
- package/sdk-core/core/src/core_tests/replay_flag.rs +3 -3
- package/sdk-core/core/src/core_tests/updates.rs +3 -3
- package/sdk-core/core/src/core_tests/workers.rs +9 -7
- package/sdk-core/core/src/core_tests/workflow_tasks.rs +40 -42
- package/sdk-core/core/src/ephemeral_server/mod.rs +1 -19
- package/sdk-core/core/src/lib.rs +10 -1
- package/sdk-core/core/src/pollers/poll_buffer.rs +2 -2
- package/sdk-core/core/src/replay/mod.rs +3 -3
- package/sdk-core/core/src/telemetry/metrics.rs +306 -152
- package/sdk-core/core/src/telemetry/mod.rs +11 -4
- package/sdk-core/core/src/telemetry/otel.rs +134 -131
- package/sdk-core/core/src/telemetry/prometheus_meter.rs +885 -0
- package/sdk-core/core/src/telemetry/prometheus_server.rs +48 -28
- package/sdk-core/core/src/test_help/mod.rs +27 -12
- package/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +7 -7
- package/sdk-core/core/src/worker/activities.rs +4 -4
- package/sdk-core/core/src/worker/client/mocks.rs +10 -3
- package/sdk-core/core/src/worker/client.rs +68 -5
- package/sdk-core/core/src/worker/heartbeat.rs +229 -0
- package/sdk-core/core/src/worker/mod.rs +35 -14
- package/sdk-core/core/src/worker/tuner/resource_based.rs +4 -4
- package/sdk-core/core/src/worker/workflow/history_update.rs +71 -19
- package/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +1 -2
- package/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +1 -1
- package/sdk-core/core/src/worker/workflow/machines/nexus_operation_state_machine.rs +31 -48
- package/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +1 -2
- package/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +3 -3
- package/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +4 -1
- package/sdk-core/core/src/worker/workflow/managed_run.rs +1 -1
- package/sdk-core/core/src/worker/workflow/mod.rs +15 -15
- package/sdk-core/core-api/Cargo.toml +2 -2
- package/sdk-core/core-api/src/envconfig.rs +204 -99
- package/sdk-core/core-api/src/lib.rs +9 -0
- package/sdk-core/core-api/src/telemetry/metrics.rs +548 -100
- package/sdk-core/core-api/src/worker.rs +11 -5
- package/sdk-core/core-c-bridge/Cargo.toml +49 -0
- package/sdk-core/core-c-bridge/build.rs +26 -0
- package/sdk-core/core-c-bridge/include/temporal-sdk-core-c-bridge.h +817 -0
- package/sdk-core/core-c-bridge/src/client.rs +679 -0
- package/sdk-core/core-c-bridge/src/lib.rs +245 -0
- package/sdk-core/core-c-bridge/src/metric.rs +682 -0
- package/sdk-core/core-c-bridge/src/random.rs +61 -0
- package/sdk-core/core-c-bridge/src/runtime.rs +445 -0
- package/sdk-core/core-c-bridge/src/testing.rs +282 -0
- package/sdk-core/core-c-bridge/src/tests/context.rs +644 -0
- package/sdk-core/core-c-bridge/src/tests/mod.rs +178 -0
- package/sdk-core/core-c-bridge/src/tests/utils.rs +108 -0
- package/sdk-core/core-c-bridge/src/worker.rs +1069 -0
- package/sdk-core/etc/deps.svg +64 -64
- package/sdk-core/sdk/src/activity_context.rs +6 -4
- package/sdk-core/sdk/src/lib.rs +49 -27
- package/sdk-core/sdk/src/workflow_future.rs +18 -25
- package/sdk-core/sdk-core-protos/protos/api_upstream/README.md +4 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/buf.yaml +0 -2
- package/sdk-core/sdk-core-protos/protos/api_upstream/openapi/openapiv2.json +630 -83
- package/sdk-core/sdk-core-protos/protos/api_upstream/openapi/openapiv3.yaml +632 -78
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/batch/v1/message.proto +4 -4
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/command/v1/message.proto +6 -4
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/common/v1/message.proto +2 -2
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/deployment/v1/message.proto +32 -2
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/common.proto +10 -1
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/deployment.proto +26 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +2 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/reset.proto +4 -4
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/failure/v1/message.proto +2 -2
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/history/v1/message.proto +47 -31
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/nexus/v1/message.proto +4 -4
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/schedule/v1/message.proto +7 -1
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/worker/v1/message.proto +134 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflow/v1/message.proto +14 -11
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +148 -37
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +21 -0
- package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +4 -4
- package/sdk-core/sdk-core-protos/src/history_builder.rs +9 -5
- package/sdk-core/sdk-core-protos/src/lib.rs +96 -6
- package/sdk-core/test-utils/src/lib.rs +11 -3
- package/sdk-core/tests/cloud_tests.rs +3 -3
- package/sdk-core/tests/heavy_tests.rs +11 -3
- package/sdk-core/tests/integ_tests/client_tests.rs +12 -13
- package/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +1 -1
- package/sdk-core/tests/integ_tests/metrics_tests.rs +188 -83
- package/sdk-core/tests/integ_tests/polling_tests.rs +1 -1
- package/sdk-core/tests/integ_tests/queries_tests.rs +56 -40
- package/sdk-core/tests/integ_tests/update_tests.rs +2 -7
- package/sdk-core/tests/integ_tests/worker_tests.rs +3 -4
- package/sdk-core/tests/integ_tests/worker_versioning_tests.rs +3 -7
- package/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +3 -5
- package/sdk-core/tests/integ_tests/workflow_tests/nexus.rs +24 -17
- package/src/client.rs +6 -0
- 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 = "
|
|
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,
|
|
21
|
+
WORKFLOW_TASK_SCHED_TO_START_LATENCY_HISTOGRAM_NAME,
|
|
17
22
|
};
|
|
18
23
|
#[cfg(feature = "otel")]
|
|
19
|
-
pub use otel::
|
|
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.
|
|
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,
|
|
22
|
-
SdkMeterProvider, Temporality,
|
|
20
|
+
Aggregation, Instrument, InstrumentKind, MeterProviderBuilder, PeriodicReader,
|
|
21
|
+
SdkMeterProvider, Temporality,
|
|
23
22
|
},
|
|
24
23
|
};
|
|
25
|
-
use std::{collections::HashMap,
|
|
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,
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
let buckets = default_buckets_for(metric_name, use_seconds);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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(
|
|
97
|
-
{
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
) ->
|
|
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) ->
|
|
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) ->
|
|
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) ->
|
|
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) ->
|
|
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.
|
|
217
|
+
DurationHistogram::Seconds(self.create_histogram_f64(params))
|
|
255
218
|
} else {
|
|
256
219
|
params.unit = "ms".into();
|
|
257
|
-
DurationHistogram::Milliseconds(self.
|
|
258
|
-
})
|
|
220
|
+
DurationHistogram::Milliseconds(self.create_histogram(params))
|
|
221
|
+
}))
|
|
259
222
|
}
|
|
260
223
|
|
|
261
|
-
fn gauge(&self, params: MetricParameters) ->
|
|
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) ->
|
|
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(
|
|
286
|
-
Seconds(
|
|
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
|
-
|
|
289
|
-
|
|
275
|
+
|
|
276
|
+
impl HistogramDurationBase for DurationHistogramBase {
|
|
277
|
+
fn records(&self, value: Duration) {
|
|
290
278
|
match self {
|
|
291
|
-
|
|
292
|
-
|
|
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;
|