@temporalio/core-bridge 1.14.2-canary-release-testing.0 → 1.16.0
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 +794 -650
- package/bridge-macros/src/derive_tryintojs.rs +40 -0
- package/lib/native.d.ts +24 -3
- package/package.json +4 -4
- 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/.github/workflows/per-pr.yml +6 -6
- package/sdk-core/AGENTS.md +42 -31
- package/sdk-core/Cargo.toml +4 -1
- package/sdk-core/README.md +19 -13
- package/sdk-core/crates/client/Cargo.toml +4 -0
- package/sdk-core/crates/client/README.md +139 -0
- package/sdk-core/crates/client/src/async_activity_handle.rs +297 -0
- package/sdk-core/crates/client/src/callback_based.rs +7 -0
- package/sdk-core/crates/client/src/errors.rs +294 -0
- package/sdk-core/crates/client/src/{raw.rs → grpc.rs} +370 -159
- package/sdk-core/crates/client/src/lib.rs +920 -1326
- package/sdk-core/crates/client/src/metrics.rs +24 -33
- package/sdk-core/crates/client/src/options_structs.rs +457 -0
- package/sdk-core/crates/client/src/replaceable.rs +5 -4
- package/sdk-core/crates/client/src/request_extensions.rs +8 -9
- package/sdk-core/crates/client/src/retry.rs +99 -54
- package/sdk-core/crates/client/src/{worker/mod.rs → worker.rs} +104 -29
- package/sdk-core/crates/client/src/workflow_handle.rs +826 -0
- package/sdk-core/crates/common/Cargo.toml +62 -3
- package/sdk-core/crates/common/build.rs +742 -12
- package/sdk-core/crates/common/protos/api_upstream/.github/workflows/ci.yml +2 -0
- package/sdk-core/crates/common/protos/api_upstream/.github/workflows/create-release.yml +0 -5
- package/sdk-core/crates/common/protos/api_upstream/Makefile +2 -1
- package/sdk-core/crates/common/protos/api_upstream/README.md +8 -0
- package/sdk-core/crates/common/protos/api_upstream/cmd/check-path-conflicts/main.go +137 -0
- package/sdk-core/crates/common/protos/api_upstream/openapi/openapiv2.json +3329 -2647
- package/sdk-core/crates/common/protos/api_upstream/openapi/openapiv3.yaml +2734 -708
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/activity/v1/message.proto +155 -3
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/command/v1/message.proto +26 -0
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/common/v1/message.proto +8 -1
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/deployment/v1/message.proto +27 -1
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/enums/v1/activity.proto +81 -0
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/enums/v1/event_type.proto +4 -0
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +4 -0
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +15 -0
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/enums/v1/workflow.proto +63 -15
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/errordetails/v1/message.proto +8 -0
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/failure/v1/message.proto +1 -0
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/history/v1/message.proto +111 -17
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/namespace/v1/message.proto +21 -0
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/nexus/v1/message.proto +20 -1
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +4 -0
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/schedule/v1/message.proto +2 -2
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +2 -0
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/worker/v1/message.proto +4 -7
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/workflow/v1/message.proto +80 -22
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +347 -23
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +242 -43
- package/sdk-core/crates/common/protos/local/temporal/sdk/core/core_interface.proto +15 -0
- package/sdk-core/crates/common/protos/local/temporal/sdk/core/nexus/nexus.proto +9 -2
- package/sdk-core/crates/common/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +8 -0
- package/sdk-core/crates/common/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +22 -5
- package/sdk-core/crates/common/src/activity_definition.rs +20 -0
- package/sdk-core/crates/common/src/data_converters.rs +770 -0
- package/sdk-core/crates/common/src/envconfig.rs +5 -0
- package/sdk-core/crates/common/src/lib.rs +15 -211
- package/sdk-core/crates/common/src/payload_visitor.rs +648 -0
- package/sdk-core/crates/common/src/priority.rs +110 -0
- package/sdk-core/crates/common/src/protos/canned_histories.rs +19 -0
- package/sdk-core/crates/common/src/protos/history_builder.rs +45 -0
- package/sdk-core/crates/common/src/protos/history_info.rs +2 -0
- package/sdk-core/crates/common/src/protos/mod.rs +134 -27
- package/sdk-core/crates/common/src/protos/task_token.rs +3 -3
- package/sdk-core/crates/common/src/protos/utilities.rs +11 -0
- package/sdk-core/crates/{sdk-core → common}/src/telemetry/log_export.rs +11 -16
- package/sdk-core/crates/common/src/telemetry/metrics/core.rs +125 -0
- package/sdk-core/crates/common/src/telemetry/metrics.rs +272 -225
- package/sdk-core/crates/{sdk-core → common}/src/telemetry/otel.rs +8 -13
- package/sdk-core/crates/{sdk-core → common}/src/telemetry/prometheus_meter.rs +49 -50
- package/sdk-core/crates/{sdk-core → common}/src/telemetry/prometheus_server.rs +2 -3
- package/sdk-core/crates/common/src/telemetry.rs +278 -19
- package/sdk-core/crates/common/src/worker.rs +68 -636
- package/sdk-core/crates/common/src/workflow_definition.rs +60 -0
- package/sdk-core/crates/macros/Cargo.toml +5 -1
- package/sdk-core/crates/macros/src/activities_definitions.rs +585 -0
- package/sdk-core/crates/macros/src/fsm_impl.rs +507 -0
- package/sdk-core/crates/macros/src/lib.rs +138 -512
- package/sdk-core/crates/macros/src/macro_utils.rs +106 -0
- package/sdk-core/crates/macros/src/workflow_definitions.rs +1224 -0
- package/sdk-core/crates/sdk/Cargo.toml +19 -6
- package/sdk-core/crates/sdk/README.md +415 -0
- package/sdk-core/crates/sdk/src/activities.rs +417 -0
- package/sdk-core/crates/sdk/src/interceptors.rs +1 -1
- package/sdk-core/crates/sdk/src/lib.rs +759 -442
- package/sdk-core/crates/sdk/src/workflow_context/options.rs +64 -35
- package/sdk-core/crates/sdk/src/workflow_context.rs +1033 -289
- package/sdk-core/crates/sdk/src/workflow_future.rs +277 -213
- package/sdk-core/crates/sdk/src/workflows.rs +711 -0
- package/sdk-core/crates/sdk-core/Cargo.toml +59 -65
- package/sdk-core/crates/sdk-core/benches/workflow_replay_bench.rs +45 -54
- package/sdk-core/crates/sdk-core/machine_coverage/ActivityMachine_Coverage.puml +1 -1
- package/sdk-core/crates/sdk-core/src/abstractions.rs +6 -10
- package/sdk-core/crates/sdk-core/src/core_tests/activity_tasks.rs +6 -5
- package/sdk-core/crates/sdk-core/src/core_tests/mod.rs +22 -21
- package/sdk-core/crates/sdk-core/src/core_tests/queries.rs +21 -25
- package/sdk-core/crates/sdk-core/src/core_tests/replay_flag.rs +7 -10
- package/sdk-core/crates/sdk-core/src/core_tests/updates.rs +14 -17
- package/sdk-core/crates/sdk-core/src/core_tests/workers.rs +647 -27
- package/sdk-core/crates/sdk-core/src/core_tests/workflow_tasks.rs +46 -41
- package/sdk-core/crates/sdk-core/src/ephemeral_server/mod.rs +13 -16
- package/sdk-core/crates/sdk-core/src/histfetch.rs +20 -10
- package/sdk-core/crates/sdk-core/src/lib.rs +60 -123
- package/sdk-core/crates/sdk-core/src/pollers/mod.rs +4 -9
- package/sdk-core/crates/sdk-core/src/pollers/poll_buffer.rs +411 -32
- package/sdk-core/crates/sdk-core/src/protosext/mod.rs +2 -2
- package/sdk-core/crates/sdk-core/src/replay/mod.rs +14 -5
- package/sdk-core/crates/sdk-core/src/telemetry/metrics.rs +183 -198
- package/sdk-core/crates/sdk-core/src/telemetry/mod.rs +3 -281
- package/sdk-core/crates/sdk-core/src/test_help/integ_helpers.rs +35 -16
- package/sdk-core/crates/sdk-core/src/test_help/unit_helpers.rs +3 -6
- package/sdk-core/crates/sdk-core/src/worker/activities/activity_heartbeat_manager.rs +1 -0
- package/sdk-core/crates/sdk-core/src/worker/activities/local_activities.rs +11 -14
- package/sdk-core/crates/sdk-core/src/worker/activities.rs +16 -19
- package/sdk-core/crates/sdk-core/src/worker/client/mocks.rs +11 -5
- package/sdk-core/crates/sdk-core/src/worker/client.rs +104 -86
- package/sdk-core/crates/sdk-core/src/worker/heartbeat.rs +10 -14
- package/sdk-core/crates/sdk-core/src/worker/mod.rs +1175 -241
- package/sdk-core/crates/sdk-core/src/worker/nexus.rs +150 -23
- package/sdk-core/crates/sdk-core/src/worker/slot_provider.rs +2 -2
- package/sdk-core/crates/sdk-core/src/worker/tuner/fixed_size.rs +2 -2
- package/sdk-core/crates/sdk-core/src/worker/tuner/resource_based.rs +25 -27
- package/sdk-core/crates/sdk-core/src/worker/tuner.rs +64 -44
- package/sdk-core/crates/sdk-core/src/worker/workflow/driven_workflow.rs +9 -3
- package/sdk-core/crates/sdk-core/src/worker/workflow/machines/patch_state_machine.rs +5 -8
- package/sdk-core/crates/sdk-core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +21 -22
- package/sdk-core/crates/sdk-core/src/worker/workflow/machines/workflow_machines.rs +28 -4
- package/sdk-core/crates/sdk-core/src/worker/workflow/managed_run.rs +20 -41
- package/sdk-core/crates/sdk-core/src/worker/workflow/mod.rs +50 -9
- package/sdk-core/crates/sdk-core/src/worker/workflow/run_cache.rs +4 -7
- package/sdk-core/crates/sdk-core/src/worker/workflow/wft_extraction.rs +2 -4
- package/sdk-core/crates/sdk-core/src/worker/workflow/wft_poller.rs +8 -9
- package/sdk-core/crates/sdk-core/src/worker/workflow/workflow_stream.rs +1 -3
- package/sdk-core/crates/sdk-core/tests/activities_procmacro.rs +6 -0
- package/sdk-core/crates/sdk-core/tests/activities_trybuild/basic_pass.rs +54 -0
- package/sdk-core/crates/sdk-core/tests/activities_trybuild/invalid_self_type_fail.rs +18 -0
- package/sdk-core/crates/sdk-core/tests/activities_trybuild/invalid_self_type_fail.stderr +5 -0
- package/sdk-core/crates/sdk-core/tests/activities_trybuild/missing_context_fail.rs +14 -0
- package/sdk-core/crates/sdk-core/tests/activities_trybuild/missing_context_fail.stderr +5 -0
- package/sdk-core/crates/sdk-core/tests/activities_trybuild/multi_arg_pass.rs +48 -0
- package/sdk-core/crates/sdk-core/tests/activities_trybuild/no_input_pass.rs +14 -0
- package/sdk-core/crates/sdk-core/tests/activities_trybuild/no_return_type_pass.rs +19 -0
- package/sdk-core/crates/sdk-core/tests/cloud_tests.rs +14 -5
- package/sdk-core/crates/sdk-core/tests/common/activity_functions.rs +55 -0
- package/sdk-core/crates/sdk-core/tests/common/mod.rs +281 -236
- package/sdk-core/crates/sdk-core/tests/common/workflows.rs +41 -28
- package/sdk-core/crates/sdk-core/tests/global_metric_tests.rs +9 -14
- package/sdk-core/crates/sdk-core/tests/heavy_tests/fuzzy_workflow.rs +73 -66
- package/sdk-core/crates/sdk-core/tests/heavy_tests.rs +306 -268
- package/sdk-core/crates/sdk-core/tests/integ_tests/async_activity_client_tests.rs +230 -0
- package/sdk-core/crates/sdk-core/tests/integ_tests/client_tests.rs +94 -57
- package/sdk-core/crates/sdk-core/tests/integ_tests/data_converter_tests.rs +381 -0
- package/sdk-core/crates/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +37 -38
- package/sdk-core/crates/sdk-core/tests/integ_tests/heartbeat_tests.rs +49 -40
- package/sdk-core/crates/sdk-core/tests/integ_tests/metrics_tests.rs +447 -300
- package/sdk-core/crates/sdk-core/tests/integ_tests/pagination_tests.rs +50 -45
- package/sdk-core/crates/sdk-core/tests/integ_tests/polling_tests.rs +157 -157
- package/sdk-core/crates/sdk-core/tests/integ_tests/queries_tests.rs +103 -89
- package/sdk-core/crates/sdk-core/tests/integ_tests/update_tests.rs +609 -463
- package/sdk-core/crates/sdk-core/tests/integ_tests/visibility_tests.rs +80 -62
- package/sdk-core/crates/sdk-core/tests/integ_tests/worker_heartbeat_tests.rs +389 -265
- package/sdk-core/crates/sdk-core/tests/integ_tests/worker_tests.rs +250 -185
- package/sdk-core/crates/sdk-core/tests/integ_tests/worker_versioning_tests.rs +52 -49
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_client_tests.rs +180 -0
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/activities.rs +437 -327
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +82 -58
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +56 -30
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +364 -251
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/client_interactions.rs +552 -0
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +110 -46
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +243 -149
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/eager.rs +98 -32
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +1475 -1040
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +73 -43
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/nexus.rs +402 -245
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/patches.rs +343 -207
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/queries.rs +415 -0
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/replay.rs +96 -36
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/resets.rs +155 -140
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/signals.rs +183 -113
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +85 -44
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/timers.rs +142 -48
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +73 -56
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests.rs +365 -242
- package/sdk-core/crates/sdk-core/tests/main.rs +22 -16
- package/sdk-core/crates/sdk-core/tests/manual_tests.rs +233 -187
- package/sdk-core/crates/sdk-core/tests/runner.rs +4 -6
- package/sdk-core/crates/sdk-core/tests/shared_tests/mod.rs +73 -27
- package/sdk-core/crates/sdk-core/tests/shared_tests/priority.rs +107 -84
- package/sdk-core/crates/sdk-core/tests/workflows_procmacro.rs +6 -0
- package/sdk-core/crates/sdk-core/tests/workflows_trybuild/async_query_fail.rs +26 -0
- package/sdk-core/crates/sdk-core/tests/workflows_trybuild/async_query_fail.stderr +5 -0
- package/sdk-core/crates/sdk-core/tests/workflows_trybuild/basic_pass.rs +49 -0
- package/sdk-core/crates/sdk-core/tests/workflows_trybuild/minimal_pass.rs +21 -0
- package/sdk-core/crates/sdk-core/tests/workflows_trybuild/mut_query_fail.rs +26 -0
- package/sdk-core/crates/sdk-core/tests/workflows_trybuild/mut_query_fail.stderr +5 -0
- package/sdk-core/crates/sdk-core/tests/workflows_trybuild/sync_run_fail.rs +21 -0
- package/sdk-core/crates/sdk-core/tests/workflows_trybuild/sync_run_fail.stderr +5 -0
- package/sdk-core/crates/sdk-core-c-bridge/Cargo.toml +8 -1
- package/sdk-core/crates/sdk-core-c-bridge/include/temporal-sdk-core-c-bridge.h +37 -26
- package/sdk-core/crates/sdk-core-c-bridge/src/client.rs +180 -87
- package/sdk-core/crates/sdk-core-c-bridge/src/lib.rs +89 -5
- package/sdk-core/crates/sdk-core-c-bridge/src/metric.rs +10 -16
- package/sdk-core/crates/sdk-core-c-bridge/src/runtime.rs +59 -67
- package/sdk-core/crates/sdk-core-c-bridge/src/testing.rs +10 -10
- package/sdk-core/crates/sdk-core-c-bridge/src/tests/context.rs +57 -22
- package/sdk-core/crates/sdk-core-c-bridge/src/tests/mod.rs +108 -12
- package/sdk-core/crates/sdk-core-c-bridge/src/tests/utils.rs +9 -52
- package/sdk-core/crates/sdk-core-c-bridge/src/worker.rs +74 -91
- package/sdk-core/rustfmt.toml +2 -1
- package/src/client.rs +206 -289
- package/src/helpers/try_into_js.rs +88 -2
- package/src/metrics.rs +277 -35
- package/src/runtime.rs +94 -45
- package/src/testing.rs +9 -16
- package/src/worker.rs +86 -68
- package/ts/native.ts +39 -3
- package/sdk-core/crates/client/src/workflow_handle/mod.rs +0 -212
- package/sdk-core/crates/common/src/errors.rs +0 -85
- package/sdk-core/crates/common/tests/worker_task_types_test.rs +0 -129
- package/sdk-core/crates/macros/LICENSE.txt +0 -21
- package/sdk-core/crates/sdk/src/activity_context.rs +0 -238
- package/sdk-core/crates/sdk/src/app_data.rs +0 -37
- package/sdk-core/crates/sdk-core/tests/integ_tests/activity_functions.rs +0 -5
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/appdata_propagation.rs +0 -61
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
//! that will match the generated structs in this module.
|
|
4
4
|
|
|
5
5
|
pub mod constants;
|
|
6
|
+
/// Utility functions for working with protobuf types.
|
|
6
7
|
pub mod utilities;
|
|
7
8
|
|
|
8
9
|
#[cfg(feature = "test-utilities")]
|
|
10
|
+
/// Pre-built test histories for common workflow patterns.
|
|
9
11
|
pub mod canned_histories;
|
|
10
12
|
#[cfg(feature = "history_builders")]
|
|
11
13
|
mod history_builder;
|
|
@@ -15,6 +17,8 @@ mod task_token;
|
|
|
15
17
|
#[cfg(feature = "test-utilities")]
|
|
16
18
|
pub mod test_utils;
|
|
17
19
|
|
|
20
|
+
use std::time::Duration;
|
|
21
|
+
|
|
18
22
|
#[cfg(feature = "history_builders")]
|
|
19
23
|
pub use history_builder::{
|
|
20
24
|
DEFAULT_ACTIVITY_TYPE, DEFAULT_WORKFLOW_TYPE, TestHistoryBuilder, default_act_sched,
|
|
@@ -24,12 +28,23 @@ pub use history_builder::{
|
|
|
24
28
|
pub use history_info::HistoryInfo;
|
|
25
29
|
pub use task_token::TaskToken;
|
|
26
30
|
|
|
31
|
+
/// Payload metadata key that identifies the encoding format.
|
|
27
32
|
pub static ENCODING_PAYLOAD_KEY: &str = "encoding";
|
|
33
|
+
/// The metadata value for JSON-encoded payloads.
|
|
28
34
|
pub static JSON_ENCODING_VAL: &str = "json/plain";
|
|
35
|
+
/// The details key used in patched marker payloads.
|
|
29
36
|
pub static PATCHED_MARKER_DETAILS_KEY: &str = "patch-data";
|
|
30
37
|
/// The search attribute key used when registering change versions
|
|
31
38
|
pub static VERSION_SEARCH_ATTR_KEY: &str = "TemporalChangeVersion";
|
|
32
39
|
|
|
40
|
+
macro_rules! include_proto_with_serde {
|
|
41
|
+
($pkg:tt) => {
|
|
42
|
+
tonic::include_proto!($pkg);
|
|
43
|
+
|
|
44
|
+
include!(concat!(env!("OUT_DIR"), concat!("/", $pkg, ".serde.rs")));
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
33
48
|
#[allow(
|
|
34
49
|
clippy::large_enum_variant,
|
|
35
50
|
clippy::derive_partial_eq_without_eq,
|
|
@@ -70,7 +85,7 @@ pub mod coresdk {
|
|
|
70
85
|
|
|
71
86
|
#[allow(clippy::module_inception)]
|
|
72
87
|
pub mod activity_task {
|
|
73
|
-
use crate::protos::{coresdk::ActivityTaskCompletion, task_token::
|
|
88
|
+
use crate::protos::{coresdk::ActivityTaskCompletion, task_token::format_task_token};
|
|
74
89
|
use std::fmt::{Display, Formatter};
|
|
75
90
|
tonic::include_proto!("coresdk.activity_task");
|
|
76
91
|
|
|
@@ -119,7 +134,7 @@ pub mod coresdk {
|
|
|
119
134
|
write!(
|
|
120
135
|
f,
|
|
121
136
|
"ActivityTaskCompletion(token: {}",
|
|
122
|
-
|
|
137
|
+
format_task_token(&self.task_token),
|
|
123
138
|
)?;
|
|
124
139
|
if let Some(r) = self.result.as_ref().and_then(|r| r.status.as_ref()) {
|
|
125
140
|
write!(f, ", {r}")?;
|
|
@@ -270,9 +285,7 @@ pub mod coresdk {
|
|
|
270
285
|
match self.status {
|
|
271
286
|
Some(activity_resolution::Status::Failed(Failure {
|
|
272
287
|
failure: Some(ref f),
|
|
273
|
-
})) => f
|
|
274
|
-
.is_timeout()
|
|
275
|
-
.or_else(|| f.cause.as_ref().and_then(|c| c.is_timeout())),
|
|
288
|
+
})) => f.is_timeout(),
|
|
276
289
|
_ => None,
|
|
277
290
|
}
|
|
278
291
|
}
|
|
@@ -520,6 +533,8 @@ pub mod coresdk {
|
|
|
520
533
|
continue_as_new_suggested: false,
|
|
521
534
|
deployment_version_for_current_task: None,
|
|
522
535
|
last_sdk_version: String::new(),
|
|
536
|
+
suggest_continue_as_new_reasons: vec![],
|
|
537
|
+
target_worker_deployment_version_changed: false,
|
|
523
538
|
}
|
|
524
539
|
}
|
|
525
540
|
|
|
@@ -820,16 +835,35 @@ pub mod coresdk {
|
|
|
820
835
|
nexus_task_completion::Status::Completed(c) => {
|
|
821
836
|
write!(f, "{c}")
|
|
822
837
|
}
|
|
823
|
-
nexus_task_completion::Status::Error(e) => {
|
|
824
|
-
write!(f, "{e}")
|
|
825
|
-
}
|
|
826
838
|
nexus_task_completion::Status::AckCancel(_) => {
|
|
827
839
|
write!(f, "AckCancel")
|
|
828
840
|
}
|
|
841
|
+
#[allow(deprecated)]
|
|
842
|
+
nexus_task_completion::Status::Error(error) => {
|
|
843
|
+
write!(f, "Error({error:?})")
|
|
844
|
+
}
|
|
845
|
+
nexus_task_completion::Status::Failure(failure) => {
|
|
846
|
+
write!(f, "{failure}")
|
|
847
|
+
}
|
|
829
848
|
}?;
|
|
830
849
|
write!(f, ")")
|
|
831
850
|
}
|
|
832
851
|
}
|
|
852
|
+
|
|
853
|
+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
854
|
+
pub enum NexusOperationErrorState {
|
|
855
|
+
Failed,
|
|
856
|
+
Canceled,
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
impl Display for NexusOperationErrorState {
|
|
860
|
+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
861
|
+
match self {
|
|
862
|
+
Self::Failed => write!(f, "failed"),
|
|
863
|
+
Self::Canceled => write!(f, "canceled"),
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
}
|
|
833
867
|
}
|
|
834
868
|
|
|
835
869
|
pub mod workflow_commands {
|
|
@@ -941,11 +975,12 @@ pub mod coresdk {
|
|
|
941
975
|
|
|
942
976
|
impl Display for UpsertWorkflowSearchAttributes {
|
|
943
977
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
978
|
+
let keys: Vec<_> = self
|
|
979
|
+
.search_attributes
|
|
980
|
+
.as_ref()
|
|
981
|
+
.map(|sa| sa.indexed_fields.keys().collect())
|
|
982
|
+
.unwrap_or_default();
|
|
983
|
+
write!(f, "UpsertWorkflowSearchAttributes({:?})", keys)
|
|
949
984
|
}
|
|
950
985
|
}
|
|
951
986
|
|
|
@@ -1313,7 +1348,13 @@ pub mod coresdk {
|
|
|
1313
1348
|
pub fn is_timeout(&self) -> Option<crate::protos::temporal::api::enums::v1::TimeoutType> {
|
|
1314
1349
|
match &self.failure_info {
|
|
1315
1350
|
Some(FailureInfo::TimeoutFailureInfo(ti)) => Some(ti.timeout_type()),
|
|
1316
|
-
_ =>
|
|
1351
|
+
_ => {
|
|
1352
|
+
if let Some(c) = &self.cause {
|
|
1353
|
+
c.is_timeout()
|
|
1354
|
+
} else {
|
|
1355
|
+
None
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1317
1358
|
}
|
|
1318
1359
|
}
|
|
1319
1360
|
|
|
@@ -1538,6 +1579,7 @@ pub mod coresdk {
|
|
|
1538
1579
|
Ok(Payload {
|
|
1539
1580
|
metadata,
|
|
1540
1581
|
data: as_json.into_bytes(),
|
|
1582
|
+
external_payloads: Default::default(),
|
|
1541
1583
|
})
|
|
1542
1584
|
}
|
|
1543
1585
|
}
|
|
@@ -1778,7 +1820,7 @@ pub mod temporal {
|
|
|
1778
1820
|
fn from(s: workflow_commands::UpsertWorkflowSearchAttributes) -> Self {
|
|
1779
1821
|
Self::UpsertWorkflowSearchAttributesCommandAttributes(
|
|
1780
1822
|
UpsertWorkflowSearchAttributesCommandAttributes {
|
|
1781
|
-
search_attributes:
|
|
1823
|
+
search_attributes: s.search_attributes,
|
|
1782
1824
|
},
|
|
1783
1825
|
)
|
|
1784
1826
|
}
|
|
@@ -1843,7 +1885,7 @@ pub mod temporal {
|
|
|
1843
1885
|
task_queue: Some(s.task_queue.into()),
|
|
1844
1886
|
header: Some(s.headers.into()),
|
|
1845
1887
|
memo: Some(s.memo.into()),
|
|
1846
|
-
search_attributes:
|
|
1888
|
+
search_attributes: s.search_attributes,
|
|
1847
1889
|
input: s.input.into_payloads(),
|
|
1848
1890
|
workflow_id_reuse_policy: s.workflow_id_reuse_policy,
|
|
1849
1891
|
workflow_execution_timeout: s.workflow_execution_timeout,
|
|
@@ -1901,12 +1943,9 @@ pub mod temporal {
|
|
|
1901
1943
|
Some(c.headers.into())
|
|
1902
1944
|
},
|
|
1903
1945
|
retry_policy: c.retry_policy,
|
|
1904
|
-
search_attributes:
|
|
1905
|
-
None
|
|
1906
|
-
} else {
|
|
1907
|
-
Some(c.search_attributes.into())
|
|
1908
|
-
},
|
|
1946
|
+
search_attributes: c.search_attributes,
|
|
1909
1947
|
inherit_build_id,
|
|
1948
|
+
initial_versioning_behavior: c.initial_versioning_behavior,
|
|
1910
1949
|
..Default::default()
|
|
1911
1950
|
},
|
|
1912
1951
|
)
|
|
@@ -1929,6 +1968,8 @@ pub mod temporal {
|
|
|
1929
1968
|
operation: c.operation,
|
|
1930
1969
|
input: c.input,
|
|
1931
1970
|
schedule_to_close_timeout: c.schedule_to_close_timeout,
|
|
1971
|
+
schedule_to_start_timeout: c.schedule_to_start_timeout,
|
|
1972
|
+
start_to_close_timeout: c.start_to_close_timeout,
|
|
1932
1973
|
nexus_header: c.nexus_header,
|
|
1933
1974
|
},
|
|
1934
1975
|
)
|
|
@@ -2002,7 +2043,7 @@ pub mod temporal {
|
|
|
2002
2043
|
collections::HashMap,
|
|
2003
2044
|
fmt::{Display, Formatter},
|
|
2004
2045
|
};
|
|
2005
|
-
|
|
2046
|
+
include_proto_with_serde!("temporal.api.common.v1");
|
|
2006
2047
|
|
|
2007
2048
|
impl<T> From<T> for Payload
|
|
2008
2049
|
where
|
|
@@ -2016,6 +2057,7 @@ pub mod temporal {
|
|
|
2016
2057
|
Self {
|
|
2017
2058
|
metadata,
|
|
2018
2059
|
data: v.as_ref().to_vec(),
|
|
2060
|
+
external_payloads: Default::default(),
|
|
2019
2061
|
}
|
|
2020
2062
|
}
|
|
2021
2063
|
}
|
|
@@ -2134,12 +2176,17 @@ pub mod temporal {
|
|
|
2134
2176
|
}
|
|
2135
2177
|
pub mod enums {
|
|
2136
2178
|
pub mod v1 {
|
|
2137
|
-
|
|
2179
|
+
include_proto_with_serde!("temporal.api.enums.v1");
|
|
2180
|
+
}
|
|
2181
|
+
}
|
|
2182
|
+
pub mod errordetails {
|
|
2183
|
+
pub mod v1 {
|
|
2184
|
+
tonic::include_proto!("temporal.api.errordetails.v1");
|
|
2138
2185
|
}
|
|
2139
2186
|
}
|
|
2140
2187
|
pub mod failure {
|
|
2141
2188
|
pub mod v1 {
|
|
2142
|
-
|
|
2189
|
+
include_proto_with_serde!("temporal.api.failure.v1");
|
|
2143
2190
|
}
|
|
2144
2191
|
}
|
|
2145
2192
|
pub mod filter {
|
|
@@ -2352,6 +2399,10 @@ pub mod temporal {
|
|
|
2352
2399
|
Attributes::WorkflowExecutionOptionsUpdatedEventAttributes(_) => true,
|
|
2353
2400
|
Attributes::NexusOperationCancelRequestCompletedEventAttributes(_) => false,
|
|
2354
2401
|
Attributes::NexusOperationCancelRequestFailedEventAttributes(_) => false,
|
|
2402
|
+
// !! Ignorable !!
|
|
2403
|
+
Attributes::WorkflowExecutionPausedEventAttributes(_) => true,
|
|
2404
|
+
// !! Ignorable !!
|
|
2405
|
+
Attributes::WorkflowExecutionUnpausedEventAttributes(_) => true,
|
|
2355
2406
|
}
|
|
2356
2407
|
} else {
|
|
2357
2408
|
false
|
|
@@ -2431,6 +2482,8 @@ pub mod temporal {
|
|
|
2431
2482
|
Attributes::WorkflowExecutionOptionsUpdatedEventAttributes(_) => { EventType::WorkflowExecutionOptionsUpdated }
|
|
2432
2483
|
Attributes::NexusOperationCancelRequestCompletedEventAttributes(_) => { EventType::NexusOperationCancelRequestCompleted }
|
|
2433
2484
|
Attributes::NexusOperationCancelRequestFailedEventAttributes(_) => { EventType::NexusOperationCancelRequestFailed }
|
|
2485
|
+
Attributes::WorkflowExecutionPausedEventAttributes(_) => { EventType::WorkflowExecutionPaused }
|
|
2486
|
+
Attributes::WorkflowExecutionUnpausedEventAttributes(_) => { EventType::WorkflowExecutionUnpaused }
|
|
2434
2487
|
}
|
|
2435
2488
|
}
|
|
2436
2489
|
}
|
|
@@ -2540,13 +2593,20 @@ pub mod temporal {
|
|
|
2540
2593
|
use crate::protos::{
|
|
2541
2594
|
camel_case_to_screaming_snake,
|
|
2542
2595
|
temporal::api::{
|
|
2543
|
-
common
|
|
2544
|
-
|
|
2596
|
+
common::{
|
|
2597
|
+
self,
|
|
2598
|
+
v1::link::{WorkflowEvent, workflow_event},
|
|
2599
|
+
},
|
|
2545
2600
|
enums::v1::EventType,
|
|
2601
|
+
failure,
|
|
2546
2602
|
},
|
|
2547
2603
|
};
|
|
2548
2604
|
use anyhow::{anyhow, bail};
|
|
2549
|
-
use
|
|
2605
|
+
use prost::Name;
|
|
2606
|
+
use std::{
|
|
2607
|
+
collections::HashMap,
|
|
2608
|
+
fmt::{Display, Formatter},
|
|
2609
|
+
};
|
|
2550
2610
|
use tonic::transport::Uri;
|
|
2551
2611
|
|
|
2552
2612
|
tonic::include_proto!("temporal.api.nexus.v1");
|
|
@@ -2583,6 +2643,11 @@ pub mod temporal {
|
|
|
2583
2643
|
}
|
|
2584
2644
|
}
|
|
2585
2645
|
|
|
2646
|
+
pub enum NexusTaskFailure {
|
|
2647
|
+
Legacy(HandlerError),
|
|
2648
|
+
Temporal(failure::v1::Failure),
|
|
2649
|
+
}
|
|
2650
|
+
|
|
2586
2651
|
static SCHEME_PREFIX: &str = "temporal://";
|
|
2587
2652
|
|
|
2588
2653
|
/// Attempt to parse a nexus lint into a workflow event link
|
|
@@ -2664,6 +2729,30 @@ pub mod temporal {
|
|
|
2664
2729
|
})),
|
|
2665
2730
|
})
|
|
2666
2731
|
}
|
|
2732
|
+
|
|
2733
|
+
impl TryFrom<failure::v1::Failure> for Failure {
|
|
2734
|
+
type Error = serde_json::Error;
|
|
2735
|
+
|
|
2736
|
+
fn try_from(mut f: failure::v1::Failure) -> Result<Self, Self::Error> {
|
|
2737
|
+
// 1. Remove message from failure
|
|
2738
|
+
let message = std::mem::take(&mut f.message);
|
|
2739
|
+
|
|
2740
|
+
// 2. Serialize Failure as JSON
|
|
2741
|
+
let details = serde_json::to_vec(&f)?;
|
|
2742
|
+
|
|
2743
|
+
// 3. Package Temporal Failure as Nexus Failure
|
|
2744
|
+
Ok(Failure {
|
|
2745
|
+
message,
|
|
2746
|
+
stack_trace: f.stack_trace,
|
|
2747
|
+
metadata: HashMap::from([(
|
|
2748
|
+
"type".to_string(),
|
|
2749
|
+
failure::v1::Failure::full_name().into(),
|
|
2750
|
+
)]),
|
|
2751
|
+
details,
|
|
2752
|
+
cause: None,
|
|
2753
|
+
})
|
|
2754
|
+
}
|
|
2755
|
+
}
|
|
2667
2756
|
}
|
|
2668
2757
|
}
|
|
2669
2758
|
pub mod workflowservice {
|
|
@@ -2779,6 +2868,18 @@ pub mod temporal {
|
|
|
2779
2868
|
}
|
|
2780
2869
|
}
|
|
2781
2870
|
|
|
2871
|
+
#[allow(
|
|
2872
|
+
clippy::all,
|
|
2873
|
+
missing_docs,
|
|
2874
|
+
rustdoc::broken_intra_doc_links,
|
|
2875
|
+
rustdoc::bare_urls
|
|
2876
|
+
)]
|
|
2877
|
+
pub mod google {
|
|
2878
|
+
pub mod rpc {
|
|
2879
|
+
tonic::include_proto!("google.rpc");
|
|
2880
|
+
}
|
|
2881
|
+
}
|
|
2882
|
+
|
|
2782
2883
|
#[allow(
|
|
2783
2884
|
clippy::all,
|
|
2784
2885
|
missing_docs,
|
|
@@ -2812,6 +2913,12 @@ pub fn camel_case_to_screaming_snake(val: &str) -> String {
|
|
|
2812
2913
|
out
|
|
2813
2914
|
}
|
|
2814
2915
|
|
|
2916
|
+
/// Convert a protobuf [`prost_types::Timestamp`] to a [`std::time::SystemTime`].
|
|
2917
|
+
pub fn proto_ts_to_system_time(ts: &prost_types::Timestamp) -> Option<std::time::SystemTime> {
|
|
2918
|
+
std::time::SystemTime::UNIX_EPOCH
|
|
2919
|
+
.checked_add(Duration::from_secs(ts.seconds as u64) + Duration::from_nanos(ts.nanos as u64))
|
|
2920
|
+
}
|
|
2921
|
+
|
|
2815
2922
|
#[cfg(test)]
|
|
2816
2923
|
mod tests {
|
|
2817
2924
|
use crate::protos::temporal::api::failure::v1::Failure;
|
|
@@ -36,13 +36,13 @@ impl TaskToken {
|
|
|
36
36
|
|
|
37
37
|
impl Display for TaskToken {
|
|
38
38
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
39
|
-
f.write_str(&
|
|
39
|
+
f.write_str(&format_task_token(&self.0))
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
impl Debug for TaskToken {
|
|
44
44
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
45
|
-
f.write_str(&format!("TaskToken({})",
|
|
45
|
+
f.write_str(&format!("TaskToken({})", format_task_token(&self.0)))
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
@@ -52,6 +52,6 @@ impl Borrow<[u8]> for TaskToken {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
pub(crate) fn
|
|
55
|
+
pub(crate) fn format_task_token(tt: &[u8]) -> String {
|
|
56
56
|
BASE64_STANDARD.encode(tt)
|
|
57
57
|
}
|
|
@@ -2,6 +2,7 @@ use std::collections::HashMap;
|
|
|
2
2
|
|
|
3
3
|
use prost::{EncodeError, Message};
|
|
4
4
|
|
|
5
|
+
/// Extension trait for converting `Option<F>` to `Option<T>`, returning `None` on failure.
|
|
5
6
|
pub trait TryIntoOrNone<F, T> {
|
|
6
7
|
/// Turn an option of something into an option of another thing, trying to convert along the way
|
|
7
8
|
/// and returning `None` if that conversion fails
|
|
@@ -26,6 +27,16 @@ pub fn pack_any<T: Message>(type_url: String, msg: &T) -> Result<prost_types::An
|
|
|
26
27
|
Ok(prost_types::Any { type_url, value })
|
|
27
28
|
}
|
|
28
29
|
|
|
30
|
+
/// Decode a specific protobuf message type from gRPC status details bytes.
|
|
31
|
+
///
|
|
32
|
+
/// The details bytes should be the serialized `google.rpc.Status` message from
|
|
33
|
+
/// `tonic::Status::details()`.
|
|
34
|
+
pub fn decode_status_detail<T: Message + Default>(details: &[u8]) -> Option<T> {
|
|
35
|
+
let status = super::google::rpc::Status::decode(details).ok()?;
|
|
36
|
+
let first_detail = status.details.first()?;
|
|
37
|
+
T::decode(first_detail.value.as_slice()).ok()
|
|
38
|
+
}
|
|
39
|
+
|
|
29
40
|
/// Given a header map, lowercase all the keys and return it as a new map.
|
|
30
41
|
/// Any keys that are duplicated after lowercasing will clobber each other in undefined ordering.
|
|
31
42
|
pub fn normalize_http_headers(headers: HashMap<String, String>) -> HashMap<String, String> {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
use crate::telemetry::{CoreLog, CoreLogConsumer};
|
|
1
2
|
use futures_channel::mpsc::{Receiver, Sender, channel};
|
|
2
3
|
use parking_lot::Mutex;
|
|
3
4
|
use ringbuf::{HeapRb, consumer::Consumer, producer::Producer, traits::Split};
|
|
4
5
|
use std::{collections::HashMap, fmt, sync::Arc, time::SystemTime};
|
|
5
|
-
use temporalio_common::telemetry::{CoreLog, CoreLogConsumer};
|
|
6
6
|
use tracing_subscriber::Layer;
|
|
7
7
|
|
|
8
8
|
#[derive(Debug)]
|
|
@@ -215,18 +215,15 @@ impl tracing::field::Visit for JsonVisitor<'_> {
|
|
|
215
215
|
|
|
216
216
|
#[cfg(test)]
|
|
217
217
|
mod tests {
|
|
218
|
-
use crate::{
|
|
219
|
-
|
|
220
|
-
telemetry_init,
|
|
218
|
+
use crate::telemetry::{
|
|
219
|
+
CoreLog, CoreLogConsumer, CoreLogStreamConsumer, CoreTelemetry, Logger, TelemetryOptions,
|
|
220
|
+
construct_filter_string, telemetry_init,
|
|
221
221
|
};
|
|
222
222
|
use futures_util::stream::StreamExt;
|
|
223
223
|
use std::{
|
|
224
224
|
fmt,
|
|
225
225
|
sync::{Arc, Mutex},
|
|
226
226
|
};
|
|
227
|
-
use temporalio_common::telemetry::{
|
|
228
|
-
CoreLog, CoreLogConsumer, CoreTelemetry, Logger, TelemetryOptionsBuilder,
|
|
229
|
-
};
|
|
230
227
|
use tracing::Level;
|
|
231
228
|
|
|
232
229
|
#[instrument(fields(bros = "brohemian"))]
|
|
@@ -246,6 +243,7 @@ mod tests {
|
|
|
246
243
|
|
|
247
244
|
fn assert_logs(logs: Vec<CoreLog>) {
|
|
248
245
|
// Verify debug log was not forwarded
|
|
246
|
+
dbg!(&logs);
|
|
249
247
|
assert!(!logs.iter().any(|l| l.message == "debug"));
|
|
250
248
|
assert_eq!(logs.len(), 4);
|
|
251
249
|
// Ensure fields are attached to events properly
|
|
@@ -260,12 +258,11 @@ mod tests {
|
|
|
260
258
|
|
|
261
259
|
#[tokio::test]
|
|
262
260
|
async fn test_forwarding_output() {
|
|
263
|
-
let opts =
|
|
261
|
+
let opts = TelemetryOptions::builder()
|
|
264
262
|
.logging(Logger::Forward {
|
|
265
263
|
filter: construct_filter_string(Level::INFO, Level::WARN),
|
|
266
264
|
})
|
|
267
|
-
.build()
|
|
268
|
-
.unwrap();
|
|
265
|
+
.build();
|
|
269
266
|
let instance = telemetry_init(opts).unwrap();
|
|
270
267
|
let _g = tracing::subscriber::set_default(instance.trace_subscriber().unwrap().clone());
|
|
271
268
|
|
|
@@ -290,13 +287,12 @@ mod tests {
|
|
|
290
287
|
#[tokio::test]
|
|
291
288
|
async fn test_push_output() {
|
|
292
289
|
let consumer = Arc::new(CaptureConsumer(Mutex::new(Vec::new())));
|
|
293
|
-
let opts =
|
|
290
|
+
let opts = TelemetryOptions::builder()
|
|
294
291
|
.logging(Logger::Push {
|
|
295
292
|
filter: construct_filter_string(Level::INFO, Level::WARN),
|
|
296
293
|
consumer: consumer.clone(),
|
|
297
294
|
})
|
|
298
|
-
.build()
|
|
299
|
-
.unwrap();
|
|
295
|
+
.build();
|
|
300
296
|
let instance = telemetry_init(opts).unwrap();
|
|
301
297
|
let _g = tracing::subscriber::set_default(instance.trace_subscriber().unwrap().clone());
|
|
302
298
|
|
|
@@ -308,13 +304,12 @@ mod tests {
|
|
|
308
304
|
async fn test_push_stream_output() {
|
|
309
305
|
let (consumer, stream) = CoreLogStreamConsumer::new(100);
|
|
310
306
|
let consumer = Arc::new(consumer);
|
|
311
|
-
let opts =
|
|
307
|
+
let opts = TelemetryOptions::builder()
|
|
312
308
|
.logging(Logger::Push {
|
|
313
309
|
filter: construct_filter_string(Level::INFO, Level::WARN),
|
|
314
310
|
consumer: consumer.clone(),
|
|
315
311
|
})
|
|
316
|
-
.build()
|
|
317
|
-
.unwrap();
|
|
312
|
+
.build();
|
|
318
313
|
let instance = telemetry_init(opts).unwrap();
|
|
319
314
|
let _g = tracing::subscriber::set_default(instance.trace_subscriber().unwrap().clone());
|
|
320
315
|
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
//! Metrics related code only needed by core and core-based SDKs
|
|
2
|
+
|
|
3
|
+
use crate::telemetry::metrics::{MetricKeyValue, MetricParameters};
|
|
4
|
+
use std::{
|
|
5
|
+
any::Any,
|
|
6
|
+
fmt::Debug,
|
|
7
|
+
sync::{Arc, OnceLock},
|
|
8
|
+
time::Duration,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/// A reference to some attributes created lang side.
|
|
12
|
+
pub trait CustomMetricAttributes: Debug + Send + Sync {
|
|
13
|
+
/// Must be implemented to work around existing type system restrictions, see
|
|
14
|
+
/// [here](https://internals.rust-lang.org/t/downcast-not-from-any-but-from-any-trait/16736/12)
|
|
15
|
+
fn as_any(self: Arc<Self>) -> Arc<dyn Any + Send + Sync>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/// Events produced by the metrics buffering layer for deferred processing by lang.
|
|
19
|
+
#[derive(Debug, Clone)]
|
|
20
|
+
pub enum MetricEvent<I: BufferInstrumentRef> {
|
|
21
|
+
/// Request to create a new metric instrument.
|
|
22
|
+
Create {
|
|
23
|
+
/// Parameters (name, description, unit) for the new instrument.
|
|
24
|
+
params: MetricParameters,
|
|
25
|
+
/// Once you receive this event, call `set` on this with the initialized instrument
|
|
26
|
+
/// reference
|
|
27
|
+
populate_into: LazyBufferInstrument<I>,
|
|
28
|
+
/// The kind of metric instrument to create.
|
|
29
|
+
kind: MetricKind,
|
|
30
|
+
},
|
|
31
|
+
/// Request to create a new set of metric attributes.
|
|
32
|
+
CreateAttributes {
|
|
33
|
+
/// Once you receive this event, call `set` on this with the initialized attributes
|
|
34
|
+
populate_into: BufferAttributes,
|
|
35
|
+
/// If not `None`, use these already-initialized attributes as the base (extended with
|
|
36
|
+
/// `attributes`) for the ones you are about to initialize.
|
|
37
|
+
append_from: Option<BufferAttributes>,
|
|
38
|
+
/// The key-value pairs for the new attribute set.
|
|
39
|
+
attributes: Vec<MetricKeyValue>,
|
|
40
|
+
},
|
|
41
|
+
/// A metric recording to apply to an already-created instrument.
|
|
42
|
+
Update {
|
|
43
|
+
/// The instrument to record against.
|
|
44
|
+
instrument: LazyBufferInstrument<I>,
|
|
45
|
+
/// The attributes to associate with this recording.
|
|
46
|
+
attributes: BufferAttributes,
|
|
47
|
+
/// The value to record.
|
|
48
|
+
update: MetricUpdateVal,
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
|
+
/// The kind of metric instrument to create.
|
|
52
|
+
#[derive(Debug, Clone, Copy)]
|
|
53
|
+
pub enum MetricKind {
|
|
54
|
+
/// A monotonically increasing `u64` counter.
|
|
55
|
+
Counter,
|
|
56
|
+
/// A `u64` gauge that can go up or down.
|
|
57
|
+
Gauge,
|
|
58
|
+
/// An `f64` gauge that can go up or down.
|
|
59
|
+
GaugeF64,
|
|
60
|
+
/// A `u64` histogram for recording distributions.
|
|
61
|
+
Histogram,
|
|
62
|
+
/// An `f64` histogram for recording distributions.
|
|
63
|
+
HistogramF64,
|
|
64
|
+
/// A histogram that records [`Duration`] values.
|
|
65
|
+
HistogramDuration,
|
|
66
|
+
}
|
|
67
|
+
/// The value to record when updating a metric instrument.
|
|
68
|
+
#[derive(Debug, Clone, Copy)]
|
|
69
|
+
pub enum MetricUpdateVal {
|
|
70
|
+
/// A `u64` delta increment (for counters/histograms).
|
|
71
|
+
Delta(u64),
|
|
72
|
+
/// An `f64` delta increment (for f64 histograms).
|
|
73
|
+
DeltaF64(f64),
|
|
74
|
+
/// An absolute `u64` value (for gauges).
|
|
75
|
+
Value(u64),
|
|
76
|
+
/// An absolute `f64` value (for f64 gauges).
|
|
77
|
+
ValueF64(f64),
|
|
78
|
+
/// A duration observation (for duration histograms).
|
|
79
|
+
Duration(Duration),
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/// Collects buffered metric events for later replay into a real metrics backend.
|
|
83
|
+
pub trait MetricCallBufferer<I: BufferInstrumentRef>: Send + Sync {
|
|
84
|
+
/// Drain and return all buffered metric events.
|
|
85
|
+
fn retrieve(&self) -> Vec<MetricEvent<I>>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/// A lazy reference to some metrics buffer attributes
|
|
89
|
+
pub type BufferAttributes = LazyRef<Arc<dyn CustomMetricAttributes + 'static>>;
|
|
90
|
+
|
|
91
|
+
/// Types lang uses to contain references to its lang-side defined instrument references must
|
|
92
|
+
/// implement this marker trait
|
|
93
|
+
pub trait BufferInstrumentRef {}
|
|
94
|
+
/// A lazy reference to a metrics buffer instrument
|
|
95
|
+
pub type LazyBufferInstrument<T> = LazyRef<Arc<T>>;
|
|
96
|
+
|
|
97
|
+
/// A shared, lazily-initialized reference. Created as an empty "hole" and filled later via [`set`](Self::set).
|
|
98
|
+
#[derive(Debug, Clone)]
|
|
99
|
+
pub struct LazyRef<T> {
|
|
100
|
+
to_be_initted: Arc<OnceLock<T>>,
|
|
101
|
+
}
|
|
102
|
+
impl<T> LazyRef<T> {
|
|
103
|
+
/// Create an uninitialized hole that must be filled with [`set`](Self::set) before use.
|
|
104
|
+
pub fn hole() -> Self {
|
|
105
|
+
Self {
|
|
106
|
+
to_be_initted: Arc::new(OnceLock::new()),
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/// Get the reference you previously initialized
|
|
111
|
+
///
|
|
112
|
+
/// # Panics
|
|
113
|
+
/// If `set` has not already been called. You must set the reference before using it.
|
|
114
|
+
pub fn get(&self) -> &T {
|
|
115
|
+
self.to_be_initted
|
|
116
|
+
.get()
|
|
117
|
+
.expect("You must initialize the reference before using it")
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/// Assigns a value to fill this reference.
|
|
121
|
+
/// Returns according to semantics of [OnceLock].
|
|
122
|
+
pub fn set(&self, val: T) -> Result<(), T> {
|
|
123
|
+
self.to_be_initted.set(val)
|
|
124
|
+
}
|
|
125
|
+
}
|