@temporalio/core-bridge 0.22.0 → 1.0.0-rc.1
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 +120 -15
- package/Cargo.toml +3 -1
- package/README.md +1 -1
- package/index.d.ts +137 -33
- package/package.json +6 -6
- 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/.buildkite/docker/docker-compose.yaml +4 -2
- package/sdk-core/ARCHITECTURE.md +9 -7
- package/sdk-core/README.md +5 -1
- package/sdk-core/arch_docs/diagrams/workflow_internals.svg +1 -0
- package/sdk-core/bridge-ffi/src/lib.rs +1 -1
- package/sdk-core/bridge-ffi/src/wrappers.rs +60 -37
- package/sdk-core/client/Cargo.toml +1 -0
- package/sdk-core/client/src/lib.rs +50 -15
- package/sdk-core/client/src/raw.rs +167 -55
- package/sdk-core/client/src/retry.rs +9 -4
- package/sdk-core/client/src/workflow_handle/mod.rs +4 -2
- package/sdk-core/core/Cargo.toml +2 -0
- package/sdk-core/core/benches/workflow_replay.rs +1 -7
- package/sdk-core/core/src/abstractions.rs +137 -16
- package/sdk-core/core/src/core_tests/activity_tasks.rs +258 -63
- package/sdk-core/core/src/core_tests/child_workflows.rs +1 -2
- package/sdk-core/core/src/core_tests/determinism.rs +2 -2
- package/sdk-core/core/src/core_tests/local_activities.rs +8 -7
- package/sdk-core/core/src/core_tests/queries.rs +146 -60
- package/sdk-core/core/src/core_tests/replay_flag.rs +1 -1
- package/sdk-core/core/src/core_tests/workers.rs +39 -23
- package/sdk-core/core/src/core_tests/workflow_cancels.rs +1 -1
- package/sdk-core/core/src/core_tests/workflow_tasks.rs +387 -280
- package/sdk-core/core/src/lib.rs +8 -5
- package/sdk-core/core/src/pollers/poll_buffer.rs +16 -10
- package/sdk-core/core/src/protosext/mod.rs +7 -9
- package/sdk-core/core/src/retry_logic.rs +73 -16
- package/sdk-core/core/src/telemetry/metrics.rs +21 -7
- package/sdk-core/core/src/telemetry/mod.rs +182 -110
- package/sdk-core/core/src/test_help/mod.rs +341 -109
- package/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +18 -9
- package/sdk-core/core/src/worker/activities/local_activities.rs +22 -25
- package/sdk-core/core/src/worker/activities.rs +156 -29
- package/sdk-core/core/src/worker/client.rs +1 -0
- package/sdk-core/core/src/worker/mod.rs +132 -659
- package/sdk-core/core/src/{workflow → worker/workflow}/bridge.rs +1 -1
- package/sdk-core/core/src/{workflow → worker/workflow}/driven_workflow.rs +1 -1
- package/sdk-core/core/src/{workflow → worker/workflow}/history_update.rs +16 -2
- package/sdk-core/core/src/{workflow → worker/workflow}/machines/activity_state_machine.rs +39 -4
- package/sdk-core/core/src/{workflow → worker/workflow}/machines/cancel_external_state_machine.rs +5 -2
- package/sdk-core/core/src/{workflow → worker/workflow}/machines/cancel_workflow_state_machine.rs +1 -1
- package/sdk-core/core/src/{workflow → worker/workflow}/machines/child_workflow_state_machine.rs +2 -4
- package/sdk-core/core/src/{workflow → worker/workflow}/machines/complete_workflow_state_machine.rs +0 -0
- package/sdk-core/core/src/{workflow → worker/workflow}/machines/continue_as_new_workflow_state_machine.rs +1 -1
- package/sdk-core/core/src/{workflow → worker/workflow}/machines/fail_workflow_state_machine.rs +0 -0
- package/sdk-core/core/src/{workflow → worker/workflow}/machines/local_activity_state_machine.rs +2 -5
- package/sdk-core/core/src/{workflow → worker/workflow}/machines/mod.rs +1 -1
- package/sdk-core/core/src/{workflow → worker/workflow}/machines/mutable_side_effect_state_machine.rs +0 -0
- package/sdk-core/core/src/{workflow → worker/workflow}/machines/patch_state_machine.rs +1 -1
- package/sdk-core/core/src/{workflow → worker/workflow}/machines/side_effect_state_machine.rs +0 -0
- package/sdk-core/core/src/{workflow → worker/workflow}/machines/signal_external_state_machine.rs +4 -2
- package/sdk-core/core/src/{workflow → worker/workflow}/machines/timer_state_machine.rs +1 -2
- package/sdk-core/core/src/{workflow → worker/workflow}/machines/transition_coverage.rs +1 -1
- package/sdk-core/core/src/{workflow → worker/workflow}/machines/upsert_search_attributes_state_machine.rs +5 -7
- package/sdk-core/core/src/{workflow → worker/workflow}/machines/workflow_machines/local_acts.rs +2 -2
- package/sdk-core/core/src/{workflow → worker/workflow}/machines/workflow_machines.rs +40 -16
- package/sdk-core/core/src/{workflow → worker/workflow}/machines/workflow_task_state_machine.rs +0 -0
- package/sdk-core/core/src/worker/workflow/managed_run/managed_wf_test.rs +198 -0
- package/sdk-core/core/src/worker/workflow/managed_run.rs +627 -0
- package/sdk-core/core/src/worker/workflow/mod.rs +1115 -0
- package/sdk-core/core/src/worker/workflow/run_cache.rs +143 -0
- package/sdk-core/core/src/worker/workflow/wft_poller.rs +88 -0
- package/sdk-core/core/src/worker/workflow/workflow_stream.rs +936 -0
- package/sdk-core/core-api/src/errors.rs +3 -10
- package/sdk-core/core-api/src/lib.rs +2 -1
- package/sdk-core/core-api/src/worker.rs +26 -2
- package/sdk-core/etc/dynamic-config.yaml +2 -0
- package/sdk-core/integ-with-otel.sh +1 -1
- package/sdk-core/protos/api_upstream/Makefile +4 -4
- package/sdk-core/protos/api_upstream/api-linter.yaml +2 -0
- package/sdk-core/protos/api_upstream/buf.yaml +8 -9
- package/sdk-core/protos/api_upstream/temporal/api/cluster/v1/message.proto +83 -0
- package/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +7 -1
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/cluster.proto +40 -0
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +3 -0
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/reset.proto +3 -1
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/schedule.proto +60 -0
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/workflow.proto +3 -0
- package/sdk-core/protos/api_upstream/temporal/api/errordetails/v1/message.proto +32 -4
- package/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +69 -19
- package/sdk-core/protos/api_upstream/temporal/api/namespace/v1/message.proto +13 -0
- package/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +163 -0
- package/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/service.proto +97 -0
- package/sdk-core/protos/api_upstream/temporal/api/schedule/v1/message.proto +300 -0
- package/sdk-core/protos/api_upstream/temporal/api/workflow/v1/message.proto +25 -0
- package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +180 -3
- package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +53 -3
- package/sdk-core/protos/local/temporal/sdk/core/activity_result/activity_result.proto +2 -2
- package/sdk-core/protos/local/temporal/sdk/core/activity_task/activity_task.proto +6 -5
- package/sdk-core/protos/local/temporal/sdk/core/bridge/bridge.proto +27 -6
- package/sdk-core/protos/local/temporal/sdk/core/child_workflow/child_workflow.proto +2 -1
- package/sdk-core/protos/local/temporal/sdk/core/common/common.proto +0 -64
- package/sdk-core/protos/local/temporal/sdk/core/core_interface.proto +2 -1
- package/sdk-core/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +11 -8
- package/sdk-core/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +30 -25
- package/sdk-core/sdk/src/activity_context.rs +12 -5
- package/sdk-core/sdk/src/app_data.rs +37 -0
- package/sdk-core/sdk/src/lib.rs +76 -43
- package/sdk-core/sdk/src/workflow_context/options.rs +8 -6
- package/sdk-core/sdk/src/workflow_context.rs +14 -19
- package/sdk-core/sdk/src/workflow_future.rs +11 -6
- package/sdk-core/sdk-core-protos/src/history_builder.rs +19 -5
- package/sdk-core/sdk-core-protos/src/history_info.rs +11 -6
- package/sdk-core/sdk-core-protos/src/lib.rs +87 -176
- package/sdk-core/test-utils/src/histfetch.rs +1 -1
- package/sdk-core/test-utils/src/lib.rs +93 -77
- package/sdk-core/tests/integ_tests/client_tests.rs +2 -2
- package/sdk-core/tests/integ_tests/heartbeat_tests.rs +11 -9
- package/sdk-core/tests/integ_tests/polling_tests.rs +12 -0
- package/sdk-core/tests/integ_tests/queries_tests.rs +39 -22
- package/sdk-core/tests/integ_tests/workflow_tests/activities.rs +49 -4
- package/sdk-core/tests/integ_tests/workflow_tests/appdata_propagation.rs +61 -0
- package/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +1 -1
- package/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +74 -13
- package/sdk-core/tests/integ_tests/workflow_tests/replay.rs +19 -0
- package/sdk-core/tests/integ_tests/workflow_tests/resets.rs +1 -1
- package/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +6 -3
- package/sdk-core/tests/integ_tests/workflow_tests.rs +10 -23
- package/sdk-core/tests/load_tests.rs +8 -3
- package/sdk-core/tests/main.rs +7 -3
- package/src/conversions.rs +149 -70
- package/src/errors.rs +10 -21
- package/src/lib.rs +400 -319
- package/sdk-core/core/src/pending_activations.rs +0 -173
- package/sdk-core/core/src/worker/wft_delivery.rs +0 -81
- package/sdk-core/core/src/workflow/mod.rs +0 -478
- package/sdk-core/core/src/workflow/workflow_tasks/cache_manager.rs +0 -194
- package/sdk-core/core/src/workflow/workflow_tasks/concurrency_manager.rs +0 -418
- package/sdk-core/core/src/workflow/workflow_tasks/mod.rs +0 -989
|
@@ -18,13 +18,18 @@ use opentelemetry::{
|
|
|
18
18
|
};
|
|
19
19
|
use opentelemetry_otlp::WithExportConfig;
|
|
20
20
|
use parking_lot::{const_mutex, Mutex};
|
|
21
|
-
use std::{
|
|
21
|
+
use std::{
|
|
22
|
+
collections::{HashMap, VecDeque},
|
|
23
|
+
convert::TryInto,
|
|
24
|
+
net::SocketAddr,
|
|
25
|
+
time::Duration,
|
|
26
|
+
};
|
|
22
27
|
use temporal_sdk_core_api::CoreTelemetry;
|
|
23
|
-
use
|
|
28
|
+
use tonic::metadata::MetadataMap;
|
|
29
|
+
use tracing_subscriber::{filter::ParseError, layer::SubscriberExt, EnvFilter};
|
|
24
30
|
use url::Url;
|
|
25
31
|
|
|
26
32
|
const TELEM_SERVICE_NAME: &str = "temporal-core-sdk";
|
|
27
|
-
const LOG_FILTER_ENV_VAR: &str = "TEMPORAL_TRACING_FILTER";
|
|
28
33
|
static DEFAULT_FILTER: &str = "temporal_sdk_core=INFO";
|
|
29
34
|
static GLOBAL_TELEM_DAT: OnceCell<GlobalTelemDat> = OnceCell::new();
|
|
30
35
|
static TELETM_MUTEX: Mutex<()> = const_mutex(());
|
|
@@ -37,39 +42,76 @@ fn default_resource() -> Resource {
|
|
|
37
42
|
Resource::new(default_resource_kvs().iter().cloned())
|
|
38
43
|
}
|
|
39
44
|
|
|
45
|
+
/// Options for exporting to an OpenTelemetry Collector
|
|
46
|
+
#[derive(Debug, Clone)]
|
|
47
|
+
pub struct OtelCollectorOptions {
|
|
48
|
+
/// The url of the OTel collector to export telemetry and metrics to. Lang SDK should also
|
|
49
|
+
/// export to this same collector.
|
|
50
|
+
pub url: Url,
|
|
51
|
+
/// Optional set of HTTP headers to send to the Collector, e.g for authentication.
|
|
52
|
+
pub headers: HashMap<String, String>,
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/// Control where traces are exported
|
|
56
|
+
#[derive(Debug, Clone)]
|
|
57
|
+
pub enum TraceExporter {
|
|
58
|
+
/// Export traces to an OpenTelemetry Collector <https://opentelemetry.io/docs/collector/>.
|
|
59
|
+
Otel(OtelCollectorOptions),
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/// Control where metrics are exported
|
|
63
|
+
#[derive(Debug, Clone)]
|
|
64
|
+
pub enum MetricsExporter {
|
|
65
|
+
/// Export metrics to an OpenTelemetry Collector <https://opentelemetry.io/docs/collector/>.
|
|
66
|
+
Otel(OtelCollectorOptions),
|
|
67
|
+
/// Expose metrics directly via an embedded http server bound to the provided address.
|
|
68
|
+
Prometheus(SocketAddr),
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/// Control where logs go
|
|
72
|
+
#[derive(Debug, Clone)]
|
|
73
|
+
pub enum Logger {
|
|
74
|
+
/// Log directly to console.
|
|
75
|
+
Console,
|
|
76
|
+
/// Forward logs to Lang - collectable with `fetch_global_buffered_logs`.
|
|
77
|
+
Forward(LevelFilter),
|
|
78
|
+
}
|
|
79
|
+
|
|
40
80
|
/// Telemetry configuration options. Construct with [TelemetryOptionsBuilder]
|
|
41
81
|
#[derive(Debug, Clone, derive_builder::Builder)]
|
|
42
82
|
#[non_exhaustive]
|
|
43
83
|
pub struct TelemetryOptions {
|
|
44
|
-
/// The url of the OTel collector to export telemetry and metrics to. Lang SDK should also
|
|
45
|
-
/// export to this same collector. If unset, telemetry is not exported and tracing data goes
|
|
46
|
-
/// to the console instead.
|
|
47
|
-
#[builder(setter(into, strip_option), default)]
|
|
48
|
-
pub otel_collector_url: Option<Url>,
|
|
49
84
|
/// A string in the [EnvFilter] format which specifies what tracing data is included in
|
|
50
85
|
/// telemetry, log forwarded to lang, or console output. May be overridden by the
|
|
51
86
|
/// `TEMPORAL_TRACING_FILTER` env variable.
|
|
52
87
|
#[builder(default = "DEFAULT_FILTER.to_string()")]
|
|
53
88
|
pub tracing_filter: String,
|
|
54
|
-
|
|
55
|
-
///
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
///
|
|
59
|
-
/// Default is INFO. If set to `Off`, the mechanism is disabled entirely (saves on perf).
|
|
60
|
-
/// If set to anything besides `Off`, any console output directly from core is disabled.
|
|
61
|
-
#[builder(setter(into), default = "LevelFilter::Info")]
|
|
62
|
-
pub log_forwarding_level: LevelFilter,
|
|
63
|
-
/// If set, prometheus metrics will be exposed directly via an embedded http server bound to
|
|
64
|
-
/// the provided address. Useful if users would like to collect metrics with prometheus but
|
|
65
|
-
/// do not want to run an OTel collector. **Note**: If this is set metrics will *not* be sent
|
|
66
|
-
/// to the OTel collector if it is also set, only traces will be.
|
|
89
|
+
|
|
90
|
+
/// Optional trace exporter - set as None to disable.
|
|
91
|
+
#[builder(setter(into, strip_option), default)]
|
|
92
|
+
pub tracing: Option<TraceExporter>,
|
|
93
|
+
/// Optional logger - set as None to disable.
|
|
67
94
|
#[builder(setter(into, strip_option), default)]
|
|
68
|
-
pub
|
|
69
|
-
///
|
|
70
|
-
|
|
95
|
+
pub logging: Option<Logger>,
|
|
96
|
+
/// Optional metrics exporter - set as None to disable.
|
|
97
|
+
#[builder(setter(into, strip_option), default)]
|
|
98
|
+
pub metrics: Option<MetricsExporter>,
|
|
99
|
+
|
|
100
|
+
/// If set true, do not prefix metrics with `temporal_`. Will be removed eventually as
|
|
101
|
+
/// the prefix is consistent with other SDKs.
|
|
71
102
|
#[builder(default)]
|
|
72
|
-
pub
|
|
103
|
+
pub no_temporal_prefix_for_metrics: bool,
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
impl TelemetryOptions {
|
|
107
|
+
/// Construct an [EnvFilter] from given `tracing_filter`.
|
|
108
|
+
pub fn try_get_env_filter(&self) -> Result<EnvFilter, ParseError> {
|
|
109
|
+
EnvFilter::try_new(if self.tracing_filter.is_empty() {
|
|
110
|
+
DEFAULT_FILTER
|
|
111
|
+
} else {
|
|
112
|
+
&self.tracing_filter
|
|
113
|
+
})
|
|
114
|
+
}
|
|
73
115
|
}
|
|
74
116
|
|
|
75
117
|
impl Default for TelemetryOptions {
|
|
@@ -85,6 +127,7 @@ pub struct GlobalTelemDat {
|
|
|
85
127
|
core_export_logger: Option<CoreExportLogger>,
|
|
86
128
|
runtime: Option<tokio::runtime::Runtime>,
|
|
87
129
|
prom_srv: Option<PromServer>,
|
|
130
|
+
no_temporal_prefix_for_metrics: bool,
|
|
88
131
|
}
|
|
89
132
|
|
|
90
133
|
impl GlobalTelemDat {
|
|
@@ -140,93 +183,119 @@ pub fn telemetry_init(opts: &TelemetryOptions) -> Result<&'static GlobalTelemDat
|
|
|
140
183
|
// Ensure closure captures the mutex guard
|
|
141
184
|
let _ = &*guard;
|
|
142
185
|
|
|
143
|
-
if opts.totally_disable {
|
|
144
|
-
return Ok(GlobalTelemDat {
|
|
145
|
-
metric_push_controller: None,
|
|
146
|
-
core_export_logger: None,
|
|
147
|
-
runtime: None,
|
|
148
|
-
prom_srv: None,
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
|
|
152
186
|
let runtime = tokio::runtime::Builder::new_multi_thread()
|
|
153
187
|
.thread_name("telemetry")
|
|
154
188
|
.worker_threads(2)
|
|
155
189
|
.enable_all()
|
|
156
190
|
.build()?;
|
|
157
|
-
let mut globaldat = GlobalTelemDat
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
log::set_max_level(opts.log_forwarding_level);
|
|
162
|
-
globaldat.core_export_logger =
|
|
163
|
-
Some(CoreExportLogger::new(opts.log_forwarding_level));
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
let filter_layer = EnvFilter::try_from_env(LOG_FILTER_ENV_VAR).or_else(|_| {
|
|
167
|
-
let filter = if opts.tracing_filter.is_empty() {
|
|
168
|
-
DEFAULT_FILTER
|
|
169
|
-
} else {
|
|
170
|
-
&opts.tracing_filter
|
|
171
|
-
};
|
|
172
|
-
EnvFilter::try_new(filter)
|
|
173
|
-
})?;
|
|
191
|
+
let mut globaldat = GlobalTelemDat {
|
|
192
|
+
no_temporal_prefix_for_metrics: opts.no_temporal_prefix_for_metrics,
|
|
193
|
+
..Default::default()
|
|
194
|
+
};
|
|
174
195
|
|
|
175
|
-
if let Some(
|
|
176
|
-
|
|
177
|
-
|
|
196
|
+
if let Some(ref logger) = opts.logging {
|
|
197
|
+
match logger {
|
|
198
|
+
Logger::Console => {
|
|
199
|
+
// TODO: this is duplicated below and is quite ugly, remove the duplication
|
|
200
|
+
if opts.tracing.is_none() {
|
|
201
|
+
let pretty_fmt = tracing_subscriber::fmt::format()
|
|
202
|
+
.pretty()
|
|
203
|
+
.with_source_location(false);
|
|
204
|
+
let reg = tracing_subscriber::registry()
|
|
205
|
+
.with((&opts).try_get_env_filter()?)
|
|
206
|
+
.with(
|
|
207
|
+
tracing_subscriber::fmt::layer()
|
|
208
|
+
.with_target(false)
|
|
209
|
+
.event_format(pretty_fmt),
|
|
210
|
+
);
|
|
211
|
+
tracing::subscriber::set_global_default(reg)?;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
Logger::Forward(filter) => {
|
|
215
|
+
log::set_max_level(*filter);
|
|
216
|
+
globaldat.core_export_logger = Some(CoreExportLogger::new(*filter));
|
|
217
|
+
}
|
|
218
|
+
};
|
|
178
219
|
};
|
|
179
220
|
|
|
180
|
-
if let Some(
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
.build()?;
|
|
209
|
-
global::set_meter_provider(metrics.provider());
|
|
210
|
-
globaldat.metric_push_controller = Some(metrics);
|
|
221
|
+
if let Some(ref metrics) = opts.metrics {
|
|
222
|
+
match metrics {
|
|
223
|
+
MetricsExporter::Prometheus(addr) => {
|
|
224
|
+
let srv = PromServer::new(*addr)?;
|
|
225
|
+
globaldat.prom_srv = Some(srv);
|
|
226
|
+
}
|
|
227
|
+
MetricsExporter::Otel(OtelCollectorOptions { url, headers }) => {
|
|
228
|
+
runtime.block_on(async {
|
|
229
|
+
let metrics = opentelemetry_otlp::new_pipeline()
|
|
230
|
+
.metrics(|f| runtime.spawn(f), tokio_interval_stream)
|
|
231
|
+
.with_aggregator_selector(SDKAggSelector)
|
|
232
|
+
.with_period(Duration::from_secs(1))
|
|
233
|
+
.with_resource(default_resource_kvs().iter().cloned())
|
|
234
|
+
.with_exporter(
|
|
235
|
+
// No joke exporter builder literally not cloneable for some insane
|
|
236
|
+
// reason
|
|
237
|
+
opentelemetry_otlp::new_exporter()
|
|
238
|
+
.tonic()
|
|
239
|
+
.with_endpoint(url.to_string())
|
|
240
|
+
.with_metadata(MetadataMap::from_headers(
|
|
241
|
+
headers.try_into()?,
|
|
242
|
+
)),
|
|
243
|
+
)
|
|
244
|
+
.build()?;
|
|
245
|
+
global::set_meter_provider(metrics.provider());
|
|
246
|
+
globaldat.metric_push_controller = Some(metrics);
|
|
247
|
+
Result::<(), anyhow::Error>::Ok(())
|
|
248
|
+
})?;
|
|
211
249
|
}
|
|
250
|
+
};
|
|
251
|
+
};
|
|
212
252
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
253
|
+
if let Some(ref tracing) = opts.tracing {
|
|
254
|
+
match tracing {
|
|
255
|
+
TraceExporter::Otel(OtelCollectorOptions { url, headers }) => {
|
|
256
|
+
runtime.block_on(async {
|
|
257
|
+
let tracer_cfg = Config::default().with_resource(default_resource());
|
|
258
|
+
let tracer = opentelemetry_otlp::new_pipeline()
|
|
259
|
+
.tracing()
|
|
260
|
+
.with_exporter(
|
|
261
|
+
opentelemetry_otlp::new_exporter()
|
|
262
|
+
.tonic()
|
|
263
|
+
.with_endpoint(url.to_string())
|
|
264
|
+
.with_metadata(MetadataMap::from_headers(
|
|
265
|
+
headers.try_into()?,
|
|
266
|
+
)),
|
|
267
|
+
)
|
|
268
|
+
.with_trace_config(tracer_cfg)
|
|
269
|
+
.install_batch(opentelemetry::runtime::Tokio)?;
|
|
270
|
+
|
|
271
|
+
let opentelemetry = tracing_opentelemetry::layer().with_tracer(tracer);
|
|
272
|
+
|
|
273
|
+
// TODO: remove all of this duplicate code
|
|
274
|
+
if let Some(Logger::Console) = opts.logging {
|
|
275
|
+
let pretty_fmt = tracing_subscriber::fmt::format()
|
|
276
|
+
.pretty()
|
|
277
|
+
.with_source_location(false);
|
|
278
|
+
let reg = tracing_subscriber::registry()
|
|
279
|
+
.with(opentelemetry)
|
|
280
|
+
.with(opts.try_get_env_filter()?)
|
|
281
|
+
.with(
|
|
282
|
+
tracing_subscriber::fmt::layer()
|
|
283
|
+
.with_target(false)
|
|
284
|
+
.event_format(pretty_fmt),
|
|
285
|
+
);
|
|
286
|
+
// Can't use try_init here as it will blow away our custom logger if we do
|
|
287
|
+
tracing::subscriber::set_global_default(reg)?;
|
|
288
|
+
} else {
|
|
289
|
+
let reg = tracing_subscriber::registry()
|
|
290
|
+
.with(opentelemetry)
|
|
291
|
+
.with(opts.try_get_env_filter()?);
|
|
292
|
+
// Can't use try_init here as it will blow away our custom logger if we do
|
|
293
|
+
tracing::subscriber::set_global_default(reg)?;
|
|
294
|
+
}
|
|
295
|
+
Result::<(), anyhow::Error>::Ok(())
|
|
296
|
+
})?;
|
|
297
|
+
}
|
|
298
|
+
};
|
|
230
299
|
};
|
|
231
300
|
|
|
232
301
|
globaldat.runtime = Some(runtime);
|
|
@@ -257,11 +326,11 @@ pub fn fetch_global_buffered_logs() -> Vec<CoreLog> {
|
|
|
257
326
|
#[cfg(test)]
|
|
258
327
|
pub(crate) fn test_telem_console() {
|
|
259
328
|
telemetry_init(&TelemetryOptions {
|
|
260
|
-
otel_collector_url: None,
|
|
261
329
|
tracing_filter: "temporal_sdk_core=DEBUG,temporal_sdk=DEBUG".to_string(),
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
330
|
+
logging: Some(Logger::Console),
|
|
331
|
+
tracing: None,
|
|
332
|
+
metrics: None,
|
|
333
|
+
no_temporal_prefix_for_metrics: false,
|
|
265
334
|
})
|
|
266
335
|
.unwrap();
|
|
267
336
|
}
|
|
@@ -270,11 +339,14 @@ pub(crate) fn test_telem_console() {
|
|
|
270
339
|
#[cfg(test)]
|
|
271
340
|
pub(crate) fn test_telem_collector() {
|
|
272
341
|
telemetry_init(&TelemetryOptions {
|
|
273
|
-
otel_collector_url: Some("grpc://localhost:4317".parse().unwrap()),
|
|
274
342
|
tracing_filter: "temporal_sdk_core=DEBUG,temporal_sdk=DEBUG".to_string(),
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
343
|
+
logging: Some(Logger::Console),
|
|
344
|
+
tracing: Some(TraceExporter::Otel(OtelCollectorOptions {
|
|
345
|
+
url: "grpc://localhost:4317".parse().unwrap(),
|
|
346
|
+
headers: Default::default(),
|
|
347
|
+
})),
|
|
348
|
+
metrics: None,
|
|
349
|
+
no_temporal_prefix_for_metrics: false,
|
|
278
350
|
})
|
|
279
351
|
.unwrap();
|
|
280
352
|
}
|