temporalio 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +175 -4
- data/bridge/Cargo.lock +44 -21
- data/bridge/Cargo.toml +1 -0
- data/bridge/sdk-core/Cargo.toml +1 -1
- data/bridge/sdk-core/README.md +1 -4
- data/bridge/sdk-core/client/Cargo.toml +1 -1
- data/bridge/sdk-core/client/src/lib.rs +12 -20
- data/bridge/sdk-core/client/src/raw.rs +9 -8
- data/bridge/sdk-core/client/src/retry.rs +100 -23
- data/bridge/sdk-core/core/Cargo.toml +7 -7
- data/bridge/sdk-core/core/benches/workflow_replay.rs +13 -10
- data/bridge/sdk-core/core/src/abstractions.rs +22 -22
- data/bridge/sdk-core/core/src/core_tests/activity_tasks.rs +146 -43
- data/bridge/sdk-core/core/src/core_tests/local_activities.rs +419 -9
- data/bridge/sdk-core/core/src/core_tests/queries.rs +247 -89
- data/bridge/sdk-core/core/src/core_tests/workers.rs +2 -2
- data/bridge/sdk-core/core/src/core_tests/workflow_cancels.rs +1 -1
- data/bridge/sdk-core/core/src/core_tests/workflow_tasks.rs +47 -27
- data/bridge/sdk-core/core/src/lib.rs +139 -32
- data/bridge/sdk-core/core/src/protosext/mod.rs +1 -1
- data/bridge/sdk-core/core/src/replay/mod.rs +185 -41
- data/bridge/sdk-core/core/src/telemetry/log_export.rs +190 -0
- data/bridge/sdk-core/core/src/telemetry/metrics.rs +184 -139
- data/bridge/sdk-core/core/src/telemetry/mod.rs +310 -315
- data/bridge/sdk-core/core/src/telemetry/prometheus_server.rs +4 -3
- data/bridge/sdk-core/core/src/test_help/mod.rs +23 -9
- data/bridge/sdk-core/core/src/worker/activities/local_activities.rs +12 -6
- data/bridge/sdk-core/core/src/worker/activities.rs +40 -23
- data/bridge/sdk-core/core/src/worker/client/mocks.rs +1 -1
- data/bridge/sdk-core/core/src/worker/client.rs +30 -4
- data/bridge/sdk-core/core/src/worker/mod.rs +23 -19
- data/bridge/sdk-core/core/src/worker/workflow/driven_workflow.rs +10 -19
- data/bridge/sdk-core/core/src/worker/workflow/history_update.rs +99 -25
- data/bridge/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +1 -5
- data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +1 -5
- data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +1 -5
- data/bridge/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +3 -5
- data/bridge/sdk-core/core/src/worker/workflow/machines/complete_workflow_state_machine.rs +1 -5
- data/bridge/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +2 -6
- data/bridge/sdk-core/core/src/worker/workflow/machines/fail_workflow_state_machine.rs +1 -5
- data/bridge/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +24 -22
- data/bridge/sdk-core/core/src/worker/workflow/machines/mod.rs +12 -38
- data/bridge/sdk-core/core/src/worker/workflow/machines/modify_workflow_properties_state_machine.rs +178 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +1 -5
- data/bridge/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +1 -5
- data/bridge/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +1 -5
- data/bridge/sdk-core/core/src/worker/workflow/machines/transition_coverage.rs +8 -2
- data/bridge/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +1 -5
- data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_machines/local_acts.rs +1 -1
- data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +233 -217
- data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_task_state_machine.rs +1 -6
- data/bridge/sdk-core/core/src/worker/workflow/managed_run/managed_wf_test.rs +4 -4
- data/bridge/sdk-core/core/src/worker/workflow/managed_run.rs +13 -5
- data/bridge/sdk-core/core/src/worker/workflow/mod.rs +86 -29
- data/bridge/sdk-core/core/src/worker/workflow/wft_poller.rs +2 -2
- data/bridge/sdk-core/core/src/worker/workflow/workflow_stream.rs +56 -11
- data/bridge/sdk-core/core-api/Cargo.toml +4 -3
- data/bridge/sdk-core/core-api/src/lib.rs +1 -43
- data/bridge/sdk-core/core-api/src/telemetry.rs +147 -0
- data/bridge/sdk-core/core-api/src/worker.rs +13 -0
- data/bridge/sdk-core/etc/deps.svg +115 -140
- data/bridge/sdk-core/etc/regen-depgraph.sh +5 -0
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.stderr +1 -1
- data/bridge/sdk-core/histories/evict_while_la_running_no_interference-23_history.bin +0 -0
- data/bridge/sdk-core/histories/evict_while_la_running_no_interference-85_history.bin +0 -0
- data/bridge/sdk-core/protos/api_upstream/buf.yaml +0 -3
- data/bridge/sdk-core/protos/api_upstream/build/go.mod +7 -0
- data/bridge/sdk-core/protos/api_upstream/build/go.sum +5 -0
- data/bridge/sdk-core/protos/api_upstream/{temporal/api/update/v1/message.proto → build/tools.go} +6 -23
- data/bridge/sdk-core/protos/api_upstream/go.mod +6 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/batch/v1/message.proto +12 -9
- data/bridge/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +20 -19
- data/bridge/sdk-core/protos/api_upstream/temporal/api/common/v1/message.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/batch_operation.proto +3 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/command_type.proto +4 -4
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/common.proto +3 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/event_type.proto +5 -3
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +23 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/{cluster.proto → interaction_type.proto} +10 -11
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/namespace.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/query.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/reset.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/schedule.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/update.proto +2 -13
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/workflow.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/errordetails/v1/message.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/failure/v1/message.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/filter/v1/message.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +26 -19
- data/bridge/sdk-core/protos/api_upstream/temporal/api/interaction/v1/message.proto +87 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/namespace/v1/message.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +21 -61
- data/bridge/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/service.proto +2 -21
- data/bridge/sdk-core/protos/api_upstream/temporal/api/query/v1/message.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/replication/v1/message.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/schedule/v1/message.proto +110 -31
- data/bridge/sdk-core/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +4 -4
- data/bridge/sdk-core/protos/api_upstream/temporal/api/version/v1/message.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/workflow/v1/message.proto +3 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +60 -16
- data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +17 -3
- data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +2 -0
- data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +8 -1
- data/bridge/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/request_response.proto +2 -2
- data/bridge/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/service.proto +2 -2
- data/bridge/sdk-core/sdk/Cargo.toml +2 -2
- data/bridge/sdk-core/sdk/src/interceptors.rs +36 -3
- data/bridge/sdk-core/sdk/src/lib.rs +7 -5
- data/bridge/sdk-core/sdk/src/workflow_context.rs +13 -2
- data/bridge/sdk-core/sdk/src/workflow_future.rs +3 -7
- data/bridge/sdk-core/sdk-core-protos/Cargo.toml +1 -1
- data/bridge/sdk-core/sdk-core-protos/build.rs +0 -1
- data/bridge/sdk-core/sdk-core-protos/src/history_builder.rs +65 -18
- data/bridge/sdk-core/sdk-core-protos/src/history_info.rs +22 -22
- data/bridge/sdk-core/sdk-core-protos/src/lib.rs +104 -44
- data/bridge/sdk-core/test-utils/Cargo.toml +2 -1
- data/bridge/sdk-core/test-utils/src/lib.rs +81 -29
- data/bridge/sdk-core/tests/integ_tests/heartbeat_tests.rs +5 -2
- data/bridge/sdk-core/tests/integ_tests/metrics_tests.rs +37 -0
- data/bridge/sdk-core/tests/integ_tests/polling_tests.rs +0 -13
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +167 -13
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +53 -0
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/replay.rs +106 -20
- data/bridge/sdk-core/tests/integ_tests/workflow_tests.rs +18 -8
- data/bridge/sdk-core/tests/main.rs +6 -4
- data/bridge/src/connection.rs +81 -62
- data/bridge/src/lib.rs +92 -33
- data/bridge/src/runtime.rs +9 -2
- data/bridge/src/worker.rs +53 -2
- data/lib/bridge.so +0 -0
- data/lib/gen/temporal/api/batch/v1/message_pb.rb +8 -6
- data/lib/gen/temporal/api/command/v1/message_pb.rb +17 -9
- data/lib/gen/temporal/api/common/v1/message_pb.rb +1 -1
- data/lib/gen/temporal/api/enums/v1/batch_operation_pb.rb +2 -1
- data/lib/gen/temporal/api/enums/v1/command_type_pb.rb +3 -1
- data/lib/gen/temporal/api/enums/v1/common_pb.rb +2 -1
- data/lib/gen/temporal/api/enums/v1/event_type_pb.rb +3 -2
- data/lib/gen/temporal/api/enums/v1/failed_cause_pb.rb +7 -1
- data/lib/gen/temporal/api/enums/v1/interaction_type_pb.rb +25 -0
- data/lib/gen/temporal/api/enums/v1/namespace_pb.rb +1 -1
- data/lib/gen/temporal/api/enums/v1/query_pb.rb +1 -1
- data/lib/gen/temporal/api/enums/v1/reset_pb.rb +1 -1
- data/lib/gen/temporal/api/enums/v1/schedule_pb.rb +1 -1
- data/lib/gen/temporal/api/enums/v1/task_queue_pb.rb +1 -1
- data/lib/gen/temporal/api/enums/v1/update_pb.rb +1 -6
- data/lib/gen/temporal/api/enums/v1/workflow_pb.rb +1 -1
- data/lib/gen/temporal/api/errordetails/v1/message_pb.rb +1 -1
- data/lib/gen/temporal/api/failure/v1/message_pb.rb +1 -1
- data/lib/gen/temporal/api/filter/v1/message_pb.rb +1 -1
- data/lib/gen/temporal/api/history/v1/message_pb.rb +19 -18
- data/lib/gen/temporal/api/interaction/v1/message_pb.rb +49 -0
- data/lib/gen/temporal/api/namespace/v1/message_pb.rb +1 -1
- data/lib/gen/temporal/api/operatorservice/v1/request_response_pb.rb +11 -51
- data/lib/gen/temporal/api/operatorservice/v1/service_pb.rb +1 -1
- data/lib/gen/temporal/api/query/v1/message_pb.rb +1 -1
- data/lib/gen/temporal/api/replication/v1/message_pb.rb +1 -1
- data/lib/gen/temporal/api/schedule/v1/message_pb.rb +22 -1
- data/lib/gen/temporal/api/taskqueue/v1/message_pb.rb +2 -2
- data/lib/gen/temporal/api/version/v1/message_pb.rb +1 -1
- data/lib/gen/temporal/api/workflow/v1/message_pb.rb +2 -1
- data/lib/gen/temporal/api/workflowservice/v1/request_response_pb.rb +27 -10
- data/lib/gen/temporal/api/workflowservice/v1/service_pb.rb +1 -1
- data/lib/gen/temporal/sdk/core/workflow_activation/workflow_activation_pb.rb +1 -0
- data/lib/gen/temporal/sdk/core/workflow_commands/workflow_commands_pb.rb +5 -1
- data/lib/temporalio/activity/context.rb +97 -0
- data/lib/temporalio/activity/info.rb +67 -0
- data/lib/temporalio/activity.rb +85 -0
- data/lib/temporalio/bridge/error.rb +8 -0
- data/lib/temporalio/bridge.rb +14 -0
- data/lib/{temporal → temporalio}/client/implementation.rb +49 -48
- data/lib/{temporal → temporalio}/client/workflow_handle.rb +35 -35
- data/lib/{temporal → temporalio}/client.rb +19 -32
- data/lib/{temporal → temporalio}/connection.rb +238 -223
- data/lib/{temporal → temporalio}/data_converter.rb +76 -35
- data/lib/{temporal → temporalio}/error/failure.rb +6 -6
- data/lib/{temporal → temporalio}/error/workflow_failure.rb +4 -2
- data/lib/{temporal → temporalio}/errors.rb +19 -1
- data/lib/{temporal → temporalio}/failure_converter/base.rb +5 -5
- data/lib/{temporal → temporalio}/failure_converter/basic.rb +58 -52
- data/lib/temporalio/failure_converter.rb +7 -0
- data/lib/{temporal → temporalio}/interceptor/chain.rb +2 -1
- data/lib/{temporal → temporalio}/interceptor/client.rb +22 -1
- data/lib/{temporal → temporalio}/payload_codec/base.rb +5 -5
- data/lib/{temporal → temporalio}/payload_converter/base.rb +3 -3
- data/lib/{temporal → temporalio}/payload_converter/bytes.rb +4 -3
- data/lib/{temporal → temporalio}/payload_converter/composite.rb +7 -5
- data/lib/{temporal → temporalio}/payload_converter/encoding_base.rb +4 -4
- data/lib/{temporal → temporalio}/payload_converter/json.rb +4 -3
- data/lib/{temporal → temporalio}/payload_converter/nil.rb +4 -3
- data/lib/temporalio/payload_converter.rb +14 -0
- data/lib/{temporal → temporalio}/retry_policy.rb +4 -4
- data/lib/{temporal → temporalio}/retry_state.rb +1 -1
- data/lib/temporalio/runtime.rb +25 -0
- data/lib/{temporal → temporalio}/timeout_type.rb +2 -2
- data/lib/temporalio/version.rb +3 -0
- data/lib/temporalio/worker/activity_runner.rb +92 -0
- data/lib/temporalio/worker/activity_worker.rb +138 -0
- data/lib/temporalio/worker/reactor.rb +46 -0
- data/lib/temporalio/worker/runner.rb +63 -0
- data/lib/temporalio/worker/sync_worker.rb +88 -0
- data/lib/temporalio/worker/thread_pool_executor.rb +51 -0
- data/lib/temporalio/worker.rb +198 -0
- data/lib/{temporal → temporalio}/workflow/execution_info.rb +4 -4
- data/lib/{temporal → temporalio}/workflow/execution_status.rb +1 -1
- data/lib/{temporal → temporalio}/workflow/id_reuse_policy.rb +6 -6
- data/lib/{temporal → temporalio}/workflow/query_reject_condition.rb +5 -5
- data/lib/temporalio.rb +12 -3
- data/temporalio.gemspec +7 -3
- metadata +79 -56
- data/bridge/sdk-core/bridge-ffi/Cargo.toml +0 -24
- data/bridge/sdk-core/bridge-ffi/LICENSE.txt +0 -23
- data/bridge/sdk-core/bridge-ffi/build.rs +0 -25
- data/bridge/sdk-core/bridge-ffi/include/sdk-core-bridge.h +0 -249
- data/bridge/sdk-core/bridge-ffi/src/lib.rs +0 -825
- data/bridge/sdk-core/bridge-ffi/src/wrappers.rs +0 -211
- data/bridge/sdk-core/core/src/log_export.rs +0 -62
- data/bridge/sdk-core/core/src/worker/workflow/machines/mutable_side_effect_state_machine.rs +0 -127
- data/bridge/sdk-core/core/src/worker/workflow/machines/side_effect_state_machine.rs +0 -71
- data/bridge/sdk-core/protos/api_upstream/temporal/api/cluster/v1/message.proto +0 -83
- data/bridge/sdk-core/protos/local/temporal/sdk/core/bridge/bridge.proto +0 -210
- data/bridge/sdk-core/sdk/src/conversions.rs +0 -8
- data/lib/gen/temporal/api/cluster/v1/message_pb.rb +0 -67
- data/lib/gen/temporal/api/enums/v1/cluster_pb.rb +0 -26
- data/lib/gen/temporal/api/update/v1/message_pb.rb +0 -26
- data/lib/temporal/bridge.rb +0 -14
- data/lib/temporal/failure_converter.rb +0 -8
- data/lib/temporal/payload_converter.rb +0 -14
- data/lib/temporal/runtime.rb +0 -22
- data/lib/temporal/version.rb +0 -3
- data/lib/temporal.rb +0 -8
|
@@ -1,17 +1,20 @@
|
|
|
1
|
+
//! This module helps with the initialization and management of telemetry. IE: Metrics and tracing.
|
|
2
|
+
//! Logs from core are all traces, which may be exported to the console, in memory, or externally.
|
|
3
|
+
|
|
4
|
+
mod log_export;
|
|
1
5
|
pub(crate) mod metrics;
|
|
2
6
|
mod prometheus_server;
|
|
3
7
|
|
|
4
|
-
use crate::{
|
|
5
|
-
log_export::
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
use crate::telemetry::{
|
|
9
|
+
log_export::{CoreLogExportLayer, CoreLogsOut},
|
|
10
|
+
metrics::SDKAggSelector,
|
|
11
|
+
prometheus_server::PromServer,
|
|
8
12
|
};
|
|
13
|
+
use crossbeam::channel::Receiver;
|
|
9
14
|
use itertools::Itertools;
|
|
10
|
-
use log::LevelFilter;
|
|
11
15
|
use once_cell::sync::OnceCell;
|
|
12
16
|
use opentelemetry::{
|
|
13
|
-
|
|
14
|
-
metrics::Meter,
|
|
17
|
+
metrics::{Meter, MeterProvider},
|
|
15
18
|
runtime,
|
|
16
19
|
sdk::{
|
|
17
20
|
export::metrics::aggregation::{self, Temporality, TemporalitySelector},
|
|
@@ -21,369 +24,361 @@ use opentelemetry::{
|
|
|
21
24
|
KeyValue,
|
|
22
25
|
};
|
|
23
26
|
use opentelemetry_otlp::WithExportConfig;
|
|
24
|
-
use parking_lot::
|
|
27
|
+
use parking_lot::Mutex;
|
|
25
28
|
use std::{
|
|
26
|
-
|
|
29
|
+
cell::RefCell,
|
|
30
|
+
collections::VecDeque,
|
|
27
31
|
convert::TryInto,
|
|
28
|
-
|
|
32
|
+
env,
|
|
33
|
+
sync::{
|
|
34
|
+
atomic::{AtomicBool, Ordering},
|
|
35
|
+
Arc,
|
|
36
|
+
},
|
|
29
37
|
time::Duration,
|
|
30
38
|
};
|
|
31
|
-
use temporal_sdk_core_api::
|
|
39
|
+
use temporal_sdk_core_api::telemetry::{
|
|
40
|
+
CoreLog, CoreTelemetry, Logger, MetricTemporality, MetricsExporter, OtelCollectorOptions,
|
|
41
|
+
TelemetryOptions, TraceExporter,
|
|
42
|
+
};
|
|
32
43
|
use tonic::metadata::MetadataMap;
|
|
33
|
-
use
|
|
34
|
-
use
|
|
44
|
+
use tracing::{Level, Subscriber};
|
|
45
|
+
use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Layer};
|
|
35
46
|
|
|
36
47
|
const TELEM_SERVICE_NAME: &str = "temporal-core-sdk";
|
|
37
|
-
static DEFAULT_FILTER: &str = "temporal_sdk_core=INFO";
|
|
38
|
-
static GLOBAL_TELEM_DAT: OnceCell<GlobalTelemDat> = OnceCell::new();
|
|
39
|
-
static TELETM_MUTEX: Mutex<()> = const_mutex(());
|
|
40
|
-
|
|
41
|
-
fn default_resource_kvs() -> &'static [KeyValue] {
|
|
42
|
-
static INSTANCE: OnceCell<[KeyValue; 1]> = OnceCell::new();
|
|
43
|
-
INSTANCE.get_or_init(|| [KeyValue::new("service.name", TELEM_SERVICE_NAME)])
|
|
44
|
-
}
|
|
45
|
-
fn default_resource() -> Resource {
|
|
46
|
-
Resource::new(default_resource_kvs().iter().cloned())
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/// Options for exporting to an OpenTelemetry Collector
|
|
50
|
-
#[derive(Debug, Clone)]
|
|
51
|
-
pub struct OtelCollectorOptions {
|
|
52
|
-
/// The url of the OTel collector to export telemetry and metrics to. Lang SDK should also
|
|
53
|
-
/// export to this same collector.
|
|
54
|
-
pub url: Url,
|
|
55
|
-
/// Optional set of HTTP headers to send to the Collector, e.g for authentication.
|
|
56
|
-
pub headers: HashMap<String, String>,
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/// Control where traces are exported
|
|
60
|
-
#[derive(Debug, Clone)]
|
|
61
|
-
pub enum TraceExporter {
|
|
62
|
-
/// Export traces to an OpenTelemetry Collector <https://opentelemetry.io/docs/collector/>.
|
|
63
|
-
Otel(OtelCollectorOptions),
|
|
64
|
-
}
|
|
65
48
|
|
|
66
|
-
///
|
|
67
|
-
|
|
68
|
-
pub
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
49
|
+
/// Help you construct an [EnvFilter] compatible filter string which will forward all core module
|
|
50
|
+
/// traces at `core_level` and all others (from 3rd party modules, etc) at `other_levl.
|
|
51
|
+
pub fn construct_filter_string(core_level: Level, other_level: Level) -> String {
|
|
52
|
+
format!(
|
|
53
|
+
"{o},temporal_sdk_core={l},temporal_client={l},temporal_sdk={l}",
|
|
54
|
+
o = other_level,
|
|
55
|
+
l = core_level
|
|
56
|
+
)
|
|
73
57
|
}
|
|
74
58
|
|
|
75
|
-
///
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/// Telemetry configuration options. Construct with [TelemetryOptionsBuilder]
|
|
85
|
-
#[derive(Debug, Clone, derive_builder::Builder)]
|
|
86
|
-
#[non_exhaustive]
|
|
87
|
-
pub struct TelemetryOptions {
|
|
88
|
-
/// A string in the [EnvFilter] format which specifies what tracing data is included in
|
|
89
|
-
/// telemetry, log forwarded to lang, or console output. May be overridden by the
|
|
90
|
-
/// `TEMPORAL_TRACING_FILTER` env variable.
|
|
91
|
-
#[builder(default = "DEFAULT_FILTER.to_string()")]
|
|
92
|
-
pub tracing_filter: String,
|
|
93
|
-
|
|
94
|
-
/// Optional trace exporter - set as None to disable.
|
|
95
|
-
#[builder(setter(into, strip_option), default)]
|
|
96
|
-
pub tracing: Option<TraceExporter>,
|
|
97
|
-
/// Optional logger - set as None to disable.
|
|
98
|
-
#[builder(setter(into, strip_option), default)]
|
|
99
|
-
pub logging: Option<Logger>,
|
|
100
|
-
/// Optional metrics exporter - set as None to disable.
|
|
101
|
-
#[builder(setter(into, strip_option), default)]
|
|
102
|
-
pub metrics: Option<MetricsExporter>,
|
|
103
|
-
|
|
104
|
-
/// If set true, do not prefix metrics with `temporal_`. Will be removed eventually as
|
|
105
|
-
/// the prefix is consistent with other SDKs.
|
|
106
|
-
#[builder(default)]
|
|
107
|
-
pub no_temporal_prefix_for_metrics: bool,
|
|
108
|
-
|
|
109
|
-
/// Specifies the aggregation temporality for metric export. Defaults to cumulative.
|
|
110
|
-
#[builder(default = "MetricTemporality::Cumulative")]
|
|
111
|
-
pub metric_temporality: MetricTemporality,
|
|
59
|
+
/// Holds initialized tracing/metrics exporters, etc
|
|
60
|
+
pub struct TelemetryInstance {
|
|
61
|
+
metric_prefix: &'static str,
|
|
62
|
+
logs_out: Option<Mutex<CoreLogsOut>>,
|
|
63
|
+
metrics: Option<(Box<dyn MeterProvider + Send + Sync + 'static>, Meter)>,
|
|
64
|
+
trace_subscriber: Arc<dyn Subscriber + Send + Sync>,
|
|
65
|
+
_keepalive_rx: Receiver<()>,
|
|
112
66
|
}
|
|
113
67
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
68
|
+
impl TelemetryInstance {
|
|
69
|
+
fn new(
|
|
70
|
+
trace_subscriber: Arc<dyn Subscriber + Send + Sync>,
|
|
71
|
+
logs_out: Option<Mutex<CoreLogsOut>>,
|
|
72
|
+
metric_prefix: &'static str,
|
|
73
|
+
mut meter_provider: Option<Box<dyn MeterProvider + Send + Sync + 'static>>,
|
|
74
|
+
keepalive_rx: Receiver<()>,
|
|
75
|
+
) -> Self {
|
|
76
|
+
let metrics = meter_provider.take().map(|mp| {
|
|
77
|
+
let meter = mp.meter(TELEM_SERVICE_NAME);
|
|
78
|
+
(mp, meter)
|
|
79
|
+
});
|
|
80
|
+
Self {
|
|
81
|
+
metric_prefix,
|
|
82
|
+
logs_out,
|
|
83
|
+
metrics,
|
|
84
|
+
trace_subscriber,
|
|
85
|
+
_keepalive_rx: keepalive_rx,
|
|
133
86
|
}
|
|
134
87
|
}
|
|
135
|
-
}
|
|
136
88
|
|
|
137
|
-
|
|
138
|
-
///
|
|
139
|
-
pub fn
|
|
140
|
-
|
|
141
|
-
DEFAULT_FILTER
|
|
142
|
-
} else {
|
|
143
|
-
&self.tracing_filter
|
|
144
|
-
})
|
|
89
|
+
/// Returns a trace subscriber which can be used with the tracing crate, or with our own
|
|
90
|
+
/// [set_trace_subscriber_for_current_thread] function.
|
|
91
|
+
pub fn trace_subscriber(&self) -> Arc<dyn Subscriber + Send + Sync> {
|
|
92
|
+
self.trace_subscriber.clone()
|
|
145
93
|
}
|
|
146
94
|
}
|
|
147
95
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
96
|
+
thread_local! {
|
|
97
|
+
static SUB_GUARD: RefCell<Option<tracing::subscriber::DefaultGuard>> = RefCell::new(None);
|
|
98
|
+
}
|
|
99
|
+
/// Set the trace subscriber for the current thread. This must be done in every thread which uses
|
|
100
|
+
/// core stuff, otherwise traces/logs will not be collected on that thread. For example, if using
|
|
101
|
+
/// a multithreaded Tokio runtime, you should ensure that said runtime uses
|
|
102
|
+
/// [on_thread_start](https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html#method.on_thread_start)
|
|
103
|
+
/// or a similar mechanism to call this for each thread within the runtime.
|
|
104
|
+
pub fn set_trace_subscriber_for_current_thread(sub: impl Subscriber + Send + Sync + 'static) {
|
|
105
|
+
SUB_GUARD.with(|sg| {
|
|
106
|
+
if sg.borrow().is_none() {
|
|
107
|
+
let g = tracing::subscriber::set_default(sub);
|
|
108
|
+
*sg.borrow_mut() = Some(g);
|
|
109
|
+
}
|
|
110
|
+
})
|
|
152
111
|
}
|
|
153
112
|
|
|
154
|
-
///
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
core_export_logger: Option<CoreExportLogger>,
|
|
158
|
-
runtime: Option<tokio::runtime::Runtime>,
|
|
159
|
-
prom_srv: Option<PromServer>,
|
|
160
|
-
no_temporal_prefix_for_metrics: bool,
|
|
113
|
+
/// Undoes [set_trace_subscriber_for_current_thread]
|
|
114
|
+
pub fn remove_trace_subscriber_for_current_thread() {
|
|
115
|
+
SUB_GUARD.with(|sg| sg.take());
|
|
161
116
|
}
|
|
162
117
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
if let Some(srv) = &self.prom_srv {
|
|
169
|
-
self.runtime
|
|
170
|
-
.as_ref()
|
|
171
|
-
.expect("Telemetry runtime is initted")
|
|
172
|
-
.spawn(srv.run());
|
|
173
|
-
}
|
|
118
|
+
fn metric_prefix(opts: &TelemetryOptions) -> &'static str {
|
|
119
|
+
if opts.no_temporal_prefix_for_metrics {
|
|
120
|
+
""
|
|
121
|
+
} else {
|
|
122
|
+
"temporal_"
|
|
174
123
|
}
|
|
175
124
|
}
|
|
176
125
|
|
|
177
|
-
impl CoreTelemetry for
|
|
126
|
+
impl CoreTelemetry for TelemetryInstance {
|
|
178
127
|
fn fetch_buffered_logs(&self) -> Vec<CoreLog> {
|
|
179
|
-
|
|
128
|
+
if let Some(logs_out) = self.logs_out.as_ref() {
|
|
129
|
+
logs_out.lock().pop_iter().collect()
|
|
130
|
+
} else {
|
|
131
|
+
vec![]
|
|
132
|
+
}
|
|
180
133
|
}
|
|
181
134
|
|
|
182
135
|
fn get_metric_meter(&self) -> Option<&Meter> {
|
|
183
|
-
|
|
184
|
-
return Some(&METRIC_METER);
|
|
185
|
-
}
|
|
186
|
-
None
|
|
136
|
+
self.metrics.as_ref().map(|(_, m)| m)
|
|
187
137
|
}
|
|
188
138
|
}
|
|
189
139
|
|
|
190
|
-
/// Initialize tracing subscribers/output and logging export
|
|
191
|
-
///
|
|
140
|
+
/// Initialize tracing subscribers/output and logging export, returning a [TelemetryInstance]
|
|
141
|
+
/// which can be used to register default / global tracing subscribers.
|
|
142
|
+
///
|
|
143
|
+
/// You should only call this once per unique [TelemetryOptions]
|
|
192
144
|
///
|
|
193
145
|
/// See [TelemetryOptions] docs for more on configuration.
|
|
194
|
-
pub fn telemetry_init(opts:
|
|
195
|
-
// TODO: Per-layer filtering has been implemented but does not yet support
|
|
196
|
-
// env-filter. When it does, allow filtering logs/telemetry separately.
|
|
197
|
-
|
|
198
|
-
// Ensure we don't pointlessly spawn threads that won't do anything or call telem dat's init 2x
|
|
199
|
-
let guard = TELETM_MUTEX.lock();
|
|
200
|
-
if let Some(gtd) = GLOBAL_TELEM_DAT.get() {
|
|
201
|
-
return Ok(gtd);
|
|
202
|
-
}
|
|
203
|
-
|
|
146
|
+
pub fn telemetry_init(opts: TelemetryOptions) -> Result<TelemetryInstance, anyhow::Error> {
|
|
204
147
|
// This is a bit odd, but functional. It's desirable to create a separate tokio runtime for
|
|
205
148
|
// metrics handling, since tests typically use a single-threaded runtime and initializing
|
|
206
149
|
// pipeline requires us to know if the runtime is single or multithreaded, we will crash
|
|
207
150
|
// in one case or the other. There does not seem to be a way to tell from the current runtime
|
|
208
151
|
// handle if it is single or multithreaded. Additionally, we can isolate metrics work this
|
|
209
152
|
// way which is nice.
|
|
210
|
-
let
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
Logger::Forward(filter) => {
|
|
245
|
-
log::set_max_level(*filter);
|
|
246
|
-
globaldat.core_export_logger = Some(CoreExportLogger::new(*filter));
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
if let Some(ref metrics) = opts.metrics {
|
|
252
|
-
match metrics {
|
|
253
|
-
MetricsExporter::Prometheus(addr) => {
|
|
254
|
-
let srv = PromServer::new(*addr, opts.metric_temporality.to_selector())?;
|
|
255
|
-
globaldat.prom_srv = Some(srv);
|
|
256
|
-
}
|
|
257
|
-
MetricsExporter::Otel(OtelCollectorOptions { url, headers }) => {
|
|
258
|
-
runtime.block_on(async {
|
|
259
|
-
let metrics = opentelemetry_otlp::new_pipeline()
|
|
260
|
-
.metrics(
|
|
261
|
-
SDKAggSelector,
|
|
262
|
-
opts.metric_temporality.to_selector(),
|
|
263
|
-
runtime::Tokio,
|
|
153
|
+
let (tx, rx) = crossbeam::channel::bounded(0);
|
|
154
|
+
let (keepalive_tx, keepalive_rx) = crossbeam::channel::bounded(0);
|
|
155
|
+
let jh = std::thread::spawn(move || -> Result<(), anyhow::Error> {
|
|
156
|
+
let runtime = tokio::runtime::Builder::new_multi_thread()
|
|
157
|
+
.thread_name("telemetry")
|
|
158
|
+
.worker_threads(2)
|
|
159
|
+
.enable_all()
|
|
160
|
+
.build()?;
|
|
161
|
+
// Parts of telem dat ====
|
|
162
|
+
let mut logs_out = None;
|
|
163
|
+
let metric_prefix = metric_prefix(&opts);
|
|
164
|
+
// =======================
|
|
165
|
+
|
|
166
|
+
// Tracing subscriber layers =========
|
|
167
|
+
let mut console_pretty_layer = None;
|
|
168
|
+
let mut console_compact_layer = None;
|
|
169
|
+
let mut forward_layer = None;
|
|
170
|
+
let mut export_layer = None;
|
|
171
|
+
// ===================================
|
|
172
|
+
|
|
173
|
+
if let Some(ref logger) = opts.logging {
|
|
174
|
+
match logger {
|
|
175
|
+
Logger::Console { filter } => {
|
|
176
|
+
// This is silly dupe but can't be avoided without boxing.
|
|
177
|
+
if env::var("TEMPORAL_CORE_PRETTY_LOGS").is_ok() {
|
|
178
|
+
console_pretty_layer = Some(
|
|
179
|
+
tracing_subscriber::fmt::layer()
|
|
180
|
+
.with_target(false)
|
|
181
|
+
.event_format(
|
|
182
|
+
tracing_subscriber::fmt::format()
|
|
183
|
+
.pretty()
|
|
184
|
+
.with_source_location(false),
|
|
264
185
|
)
|
|
265
|
-
.
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
.
|
|
274
|
-
|
|
275
|
-
)),
|
|
186
|
+
.with_filter(EnvFilter::new(filter)),
|
|
187
|
+
)
|
|
188
|
+
} else {
|
|
189
|
+
console_compact_layer = Some(
|
|
190
|
+
tracing_subscriber::fmt::layer()
|
|
191
|
+
.with_target(false)
|
|
192
|
+
.event_format(
|
|
193
|
+
tracing_subscriber::fmt::format()
|
|
194
|
+
.compact()
|
|
195
|
+
.with_source_location(false),
|
|
276
196
|
)
|
|
277
|
-
.
|
|
278
|
-
|
|
279
|
-
Result::<(), anyhow::Error>::Ok(())
|
|
280
|
-
})?;
|
|
197
|
+
.with_filter(EnvFilter::new(filter)),
|
|
198
|
+
)
|
|
281
199
|
}
|
|
282
|
-
}
|
|
200
|
+
}
|
|
201
|
+
Logger::Forward { filter } => {
|
|
202
|
+
let (export_layer, lo) = CoreLogExportLayer::new();
|
|
203
|
+
logs_out = Some(Mutex::new(lo));
|
|
204
|
+
forward_layer = Some(export_layer.with_filter(EnvFilter::new(filter)));
|
|
205
|
+
}
|
|
283
206
|
};
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
let meter_provider = if let Some(ref metrics) = opts.metrics {
|
|
210
|
+
let aggregator = SDKAggSelector { metric_prefix };
|
|
211
|
+
match metrics {
|
|
212
|
+
MetricsExporter::Prometheus(addr) => {
|
|
213
|
+
let srv = PromServer::new(
|
|
214
|
+
*addr,
|
|
215
|
+
aggregator,
|
|
216
|
+
metric_temporality_to_selector(opts.metric_temporality),
|
|
217
|
+
)?;
|
|
218
|
+
let mp = srv.exporter.meter_provider()?;
|
|
219
|
+
runtime.spawn(async move { srv.run().await });
|
|
220
|
+
Some(Box::new(mp) as Box<dyn MeterProvider + Send + Sync>)
|
|
221
|
+
}
|
|
222
|
+
MetricsExporter::Otel(OtelCollectorOptions {
|
|
223
|
+
url,
|
|
224
|
+
headers,
|
|
225
|
+
metric_periodicity,
|
|
226
|
+
}) => runtime.block_on(async {
|
|
227
|
+
let metrics = opentelemetry_otlp::new_pipeline()
|
|
228
|
+
.metrics(
|
|
229
|
+
aggregator,
|
|
230
|
+
metric_temporality_to_selector(opts.metric_temporality),
|
|
231
|
+
runtime::Tokio,
|
|
232
|
+
)
|
|
233
|
+
.with_period(metric_periodicity.unwrap_or_else(|| Duration::from_secs(1)))
|
|
234
|
+
.with_resource(default_resource())
|
|
235
|
+
.with_exporter(
|
|
236
|
+
opentelemetry_otlp::new_exporter()
|
|
237
|
+
.tonic()
|
|
238
|
+
.with_endpoint(url.to_string())
|
|
239
|
+
.with_metadata(MetadataMap::from_headers(headers.try_into()?)),
|
|
240
|
+
)
|
|
241
|
+
.build()?;
|
|
242
|
+
Ok::<_, anyhow::Error>(Some(
|
|
243
|
+
Box::new(metrics) as Box<dyn MeterProvider + Send + Sync>
|
|
244
|
+
))
|
|
245
|
+
})?,
|
|
246
|
+
}
|
|
247
|
+
} else {
|
|
248
|
+
None
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
if let Some(ref tracing) = opts.tracing {
|
|
252
|
+
match &tracing.exporter {
|
|
253
|
+
TraceExporter::Otel(OtelCollectorOptions { url, headers, .. }) => {
|
|
254
|
+
runtime.block_on(async {
|
|
255
|
+
let tracer_cfg = Config::default().with_resource(default_resource());
|
|
256
|
+
let tracer = opentelemetry_otlp::new_pipeline()
|
|
257
|
+
.tracing()
|
|
258
|
+
.with_exporter(
|
|
259
|
+
opentelemetry_otlp::new_exporter()
|
|
260
|
+
.tonic()
|
|
261
|
+
.with_endpoint(url.to_string())
|
|
262
|
+
.with_metadata(MetadataMap::from_headers(headers.try_into()?)),
|
|
263
|
+
)
|
|
264
|
+
.with_trace_config(tracer_cfg)
|
|
265
|
+
.install_batch(runtime::Tokio)?;
|
|
266
|
+
|
|
267
|
+
let opentelemetry = tracing_opentelemetry::layer()
|
|
268
|
+
.with_tracer(tracer)
|
|
269
|
+
.with_filter(EnvFilter::new(&tracing.filter));
|
|
270
|
+
|
|
271
|
+
export_layer = Some(opentelemetry);
|
|
272
|
+
Result::<(), anyhow::Error>::Ok(())
|
|
273
|
+
})?;
|
|
274
|
+
}
|
|
331
275
|
};
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
let reg = tracing_subscriber::registry()
|
|
279
|
+
.with(console_pretty_layer)
|
|
280
|
+
.with(console_compact_layer)
|
|
281
|
+
.with(forward_layer)
|
|
282
|
+
.with(export_layer);
|
|
283
|
+
|
|
284
|
+
tx.send(TelemetryInstance::new(
|
|
285
|
+
Arc::new(reg),
|
|
286
|
+
logs_out,
|
|
287
|
+
metric_prefix,
|
|
288
|
+
meter_provider,
|
|
289
|
+
keepalive_rx,
|
|
290
|
+
))
|
|
291
|
+
.expect("Must be able to send telem instance out of thread");
|
|
292
|
+
// Now keep the thread alive until the telemetry instance is dropped by trying to send
|
|
293
|
+
// something forever
|
|
294
|
+
let _ = keepalive_tx.send(());
|
|
295
|
+
Ok(())
|
|
296
|
+
});
|
|
297
|
+
match rx.recv() {
|
|
298
|
+
Ok(ti) => Ok(ti),
|
|
299
|
+
Err(_) => {
|
|
300
|
+
// Immediately join the thread since something went wrong in it
|
|
301
|
+
jh.join().expect("Telemetry must init cleanly")?;
|
|
302
|
+
// This can't happen. The rx channel can't be dropped unless the thread errored.
|
|
303
|
+
unreachable!("Impossible error in telemetry init thread");
|
|
304
|
+
}
|
|
305
|
+
}
|
|
342
306
|
}
|
|
343
307
|
|
|
344
|
-
///
|
|
345
|
-
///
|
|
346
|
-
pub fn
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
.
|
|
308
|
+
/// Initialize telemetry/tracing globally. Useful for testing. Only takes affect when called
|
|
309
|
+
/// the first time. Subsequent calls are ignored.
|
|
310
|
+
pub fn telemetry_init_global(opts: TelemetryOptions) -> Result<(), anyhow::Error> {
|
|
311
|
+
static INITTED: AtomicBool = AtomicBool::new(false);
|
|
312
|
+
if INITTED
|
|
313
|
+
.compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed)
|
|
314
|
+
.is_ok()
|
|
350
315
|
{
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
vec![]
|
|
316
|
+
let ti = telemetry_init(opts)?;
|
|
317
|
+
tracing::subscriber::set_global_default(ti.trace_subscriber())?;
|
|
354
318
|
}
|
|
319
|
+
Ok(())
|
|
355
320
|
}
|
|
356
321
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
322
|
+
fn default_resource_kvs() -> &'static [KeyValue] {
|
|
323
|
+
static INSTANCE: OnceCell<[KeyValue; 1]> = OnceCell::new();
|
|
324
|
+
INSTANCE.get_or_init(|| [KeyValue::new("service.name", TELEM_SERVICE_NAME)])
|
|
325
|
+
}
|
|
326
|
+
fn default_resource() -> Resource {
|
|
327
|
+
Resource::new(default_resource_kvs().iter().cloned())
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
fn metric_temporality_to_selector(
|
|
331
|
+
t: MetricTemporality,
|
|
332
|
+
) -> impl TemporalitySelector + Send + Sync + Clone {
|
|
333
|
+
match t {
|
|
334
|
+
MetricTemporality::Cumulative => {
|
|
335
|
+
aggregation::constant_temporality_selector(Temporality::Cumulative)
|
|
336
|
+
}
|
|
337
|
+
MetricTemporality::Delta => aggregation::constant_temporality_selector(Temporality::Delta),
|
|
338
|
+
}
|
|
369
339
|
}
|
|
370
340
|
|
|
371
|
-
#[allow(dead_code)] // Not always used, called to enable for debugging when needed
|
|
372
341
|
#[cfg(test)]
|
|
373
|
-
pub
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
342
|
+
pub mod test_initters {
|
|
343
|
+
use super::*;
|
|
344
|
+
use temporal_sdk_core_api::telemetry::{TelemetryOptionsBuilder, TraceExportConfig};
|
|
345
|
+
|
|
346
|
+
#[allow(dead_code)] // Not always used, called to enable for debugging when needed
|
|
347
|
+
pub fn test_telem_console() {
|
|
348
|
+
telemetry_init_global(
|
|
349
|
+
TelemetryOptionsBuilder::default()
|
|
350
|
+
.logging(Logger::Console {
|
|
351
|
+
filter: construct_filter_string(Level::DEBUG, Level::WARN),
|
|
352
|
+
})
|
|
353
|
+
.build()
|
|
354
|
+
.unwrap(),
|
|
355
|
+
)
|
|
356
|
+
.unwrap();
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
#[allow(dead_code)] // Not always used, called to enable for debugging when needed
|
|
360
|
+
pub fn test_telem_collector() {
|
|
361
|
+
telemetry_init_global(
|
|
362
|
+
TelemetryOptionsBuilder::default()
|
|
363
|
+
.logging(Logger::Console {
|
|
364
|
+
filter: construct_filter_string(Level::DEBUG, Level::WARN),
|
|
365
|
+
})
|
|
366
|
+
.tracing(TraceExportConfig {
|
|
367
|
+
filter: construct_filter_string(Level::DEBUG, Level::WARN),
|
|
368
|
+
exporter: TraceExporter::Otel(OtelCollectorOptions {
|
|
369
|
+
url: "grpc://localhost:4317".parse().unwrap(),
|
|
370
|
+
headers: Default::default(),
|
|
371
|
+
metric_periodicity: None,
|
|
372
|
+
}),
|
|
373
|
+
})
|
|
374
|
+
.build()
|
|
375
|
+
.unwrap(),
|
|
376
|
+
)
|
|
377
|
+
.unwrap();
|
|
378
|
+
}
|
|
386
379
|
}
|
|
380
|
+
#[cfg(test)]
|
|
381
|
+
pub use test_initters::*;
|
|
387
382
|
|
|
388
383
|
/// A trait for using [Display] on the contents of vecs, etc, which don't implement it.
|
|
389
384
|
///
|