Skip to content

Commit 0f2f1b4

Browse files
chore: feature cleanup (#1236)
* chore: feature cleanup * trim down features * remove extra features * fix formatting
1 parent 2872b53 commit 0f2f1b4

7 files changed

Lines changed: 65 additions & 32 deletions

File tree

crates/client/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ rand = "0.10"
5252
[dependencies.temporalio-common]
5353
path = "../common"
5454
version = "0.3"
55+
default-features = false
5556

5657
[dev-dependencies]
5758
assert_matches = "1"

crates/common/Cargo.toml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ exclude = ["protos/*/.github/*"]
1414
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1515

1616
[features]
17-
history_builders = ["rand"]
17+
history_builders = ["dep:rand"]
1818
otel = ["dep:opentelemetry", "dep:opentelemetry_sdk", "dep:opentelemetry-otlp"]
1919
prometheus = [
2020
"dep:prometheus",
@@ -26,12 +26,8 @@ prometheus = [
2626
envconfig = ["dep:toml", "dep:dirs"]
2727
serde_serialize = []
2828
test-utilities = ["history_builders"]
29-
core-based-sdk = [
30-
"prometheus",
31-
"envconfig",
32-
"dep:ringbuf",
33-
"dep:futures-channel",
34-
]
29+
core-telemetry-bridge = ["dep:ringbuf", "dep:futures-channel"]
30+
core-based-sdk = ["core-telemetry-bridge", "prometheus", "envconfig"]
3531

3632
[dependencies]
3733
anyhow = "1.0"
@@ -85,7 +81,10 @@ tokio = { version = "1.47", default-features = false, features = [
8581
"rt",
8682
], optional = true }
8783
toml = { version = "1.0", optional = true }
88-
tonic = { workspace = true, default-features = false, features = ["transport", "codegen"] }
84+
tonic = { workspace = true, default-features = false, features = [
85+
"transport",
86+
"codegen",
87+
] }
8988
tonic-prost = { workspace = true }
9089
tracing = "0.1"
9190
# TODO [rust-sdk-branch]: Is it reasonable to make this optional?

crates/common/src/telemetry.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/// Metric instrument types and the [`CoreMeter`] trait.
44
pub mod metrics;
55

6-
#[cfg(feature = "core-based-sdk")]
6+
#[cfg(feature = "core-telemetry-bridge")]
77
mod log_export;
88
#[cfg(feature = "otel")]
99
mod otel;
@@ -31,10 +31,10 @@ use tracing::{Level, Subscriber};
3131
use tracing_subscriber::{EnvFilter, Layer, layer::SubscriberExt};
3232
use url::Url;
3333

34-
#[cfg(feature = "core-based-sdk")]
34+
#[cfg(feature = "core-telemetry-bridge")]
3535
use crate::telemetry::log_export::CoreLogConsumerLayer;
3636

37-
#[cfg(feature = "core-based-sdk")]
37+
#[cfg(feature = "core-telemetry-bridge")]
3838
pub use log_export::{CoreLogBuffer, CoreLogBufferedConsumer, CoreLogStreamConsumer};
3939
#[cfg(feature = "otel")]
4040
pub use otel::build_otlp_metric_exporter;
@@ -200,13 +200,13 @@ pub enum Logger {
200200
/// An [EnvFilter](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/struct.EnvFilter.html) filter string.
201201
filter: String,
202202
},
203-
#[cfg(feature = "core-based-sdk")]
203+
#[cfg(feature = "core-telemetry-bridge")]
204204
/// Forward logs to Lang - collectable with `fetch_global_buffered_logs`.
205205
Forward {
206206
/// An [EnvFilter](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/struct.EnvFilter.html) filter string.
207207
filter: String,
208208
},
209-
#[cfg(feature = "core-based-sdk")]
209+
#[cfg(feature = "core-telemetry-bridge")]
210210
/// Push logs to Lang. Can be used with
211211
/// temporalio_sdk_core::telemetry::log_export::CoreLogBufferedConsumer to buffer.
212212
Push {
@@ -277,7 +277,7 @@ pub trait CoreLogConsumer: Send + Sync + Debug {
277277
fn on_log(&self, log: CoreLog);
278278
}
279279

280-
#[cfg(feature = "core-based-sdk")]
280+
#[cfg(feature = "core-telemetry-bridge")]
281281
const FORWARD_LOG_BUFFER_SIZE: usize = 2048;
282282

283283
/// Help you construct an [EnvFilter] compatible filter string which will forward all core module
@@ -291,7 +291,7 @@ pub fn construct_filter_string(core_level: Level, other_level: Level) -> String
291291
/// Holds initialized tracing/metrics exporters, etc
292292
pub struct TelemetryInstance {
293293
metric_prefix: String,
294-
#[cfg(feature = "core-based-sdk")]
294+
#[cfg(feature = "core-telemetry-bridge")]
295295
logs_out: Option<parking_lot::Mutex<CoreLogBuffer>>,
296296
metrics: Option<Arc<dyn CoreMeter + 'static>>,
297297
/// The tracing subscriber which is associated with this telemetry instance. May be `None` if
@@ -372,7 +372,7 @@ pub fn remove_trace_subscriber_for_current_thread() {
372372
SUB_GUARD.take();
373373
}
374374

375-
#[cfg(feature = "core-based-sdk")]
375+
#[cfg(feature = "core-telemetry-bridge")]
376376
impl CoreTelemetry for TelemetryInstance {
377377
fn fetch_buffered_logs(&self) -> Vec<CoreLog> {
378378
if let Some(logs_out) = self.logs_out.as_ref() {
@@ -390,13 +390,13 @@ impl CoreTelemetry for TelemetryInstance {
390390
///
391391
/// See [TelemetryOptions] docs for more on configuration.
392392
pub fn telemetry_init(opts: TelemetryOptions) -> Result<TelemetryInstance, anyhow::Error> {
393-
#[cfg(feature = "core-based-sdk")]
393+
#[cfg(feature = "core-telemetry-bridge")]
394394
let mut logs_out = None;
395395

396396
// Tracing subscriber layers =========
397397
let mut console_pretty_layer = None;
398398
let mut console_compact_layer = None;
399-
#[cfg(feature = "core-based-sdk")]
399+
#[cfg(feature = "core-telemetry-bridge")]
400400
let mut forward_layer = None;
401401
// ===================================
402402

@@ -431,14 +431,14 @@ pub fn telemetry_init(opts: TelemetryOptions) -> Result<TelemetryInstance, anyho
431431
)
432432
}
433433
}
434-
#[cfg(feature = "core-based-sdk")]
434+
#[cfg(feature = "core-telemetry-bridge")]
435435
Logger::Forward { filter } => {
436436
let (export_layer, lo) =
437437
CoreLogConsumerLayer::new_buffered(FORWARD_LOG_BUFFER_SIZE);
438438
logs_out = Some(parking_lot::Mutex::new(lo));
439439
forward_layer = Some(export_layer.with_filter(EnvFilter::new(filter)));
440440
}
441-
#[cfg(feature = "core-based-sdk")]
441+
#[cfg(feature = "core-telemetry-bridge")]
442442
Logger::Push { filter, consumer } => {
443443
forward_layer = Some(
444444
CoreLogConsumerLayer::new(consumer).with_filter(EnvFilter::new(filter)),
@@ -448,7 +448,7 @@ pub fn telemetry_init(opts: TelemetryOptions) -> Result<TelemetryInstance, anyho
448448
let reg = tracing_subscriber::registry()
449449
.with(console_pretty_layer)
450450
.with(console_compact_layer);
451-
#[cfg(feature = "core-based-sdk")]
451+
#[cfg(feature = "core-telemetry-bridge")]
452452
let reg = reg.with(forward_layer);
453453

454454
Arc::new(reg) as Arc<dyn Subscriber + Send + Sync>
@@ -457,7 +457,7 @@ pub fn telemetry_init(opts: TelemetryOptions) -> Result<TelemetryInstance, anyho
457457

458458
Ok(TelemetryInstance {
459459
metric_prefix: opts.metric_prefix,
460-
#[cfg(feature = "core-based-sdk")]
460+
#[cfg(feature = "core-telemetry-bridge")]
461461
logs_out,
462462
metrics: opts.metrics,
463463
trace_subscriber: tracing_sub,

crates/common/src/telemetry/metrics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::{
1111
time::Duration,
1212
};
1313

14-
#[cfg(feature = "core-based-sdk")]
14+
#[cfg(feature = "core-telemetry-bridge")]
1515
pub mod core;
1616

1717
/// The string name (which may be prefixed) for this metric
@@ -377,10 +377,10 @@ pub enum MetricAttributes {
377377
labels: Arc<OrderedPromLabelSet>,
378378
},
379379
/// Buffered attributes used by core-based SDKs for deferred metric initialization.
380-
#[cfg(feature = "core-based-sdk")]
380+
#[cfg(feature = "core-telemetry-bridge")]
381381
Buffer(core::BufferAttributes),
382382
/// Dynamic attributes backed by a lang-side custom implementation.
383-
#[cfg(feature = "core-based-sdk")]
383+
#[cfg(feature = "core-telemetry-bridge")]
384384
Dynamic(Arc<dyn core::CustomMetricAttributes>),
385385
/// No-op attributes that store labels but do not record.
386386
NoOp(Arc<HashMap<String, String>>),

crates/sdk-core/Cargo.toml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ repository = "https://github.com/temporalio/sdk-rust"
1010
keywords = ["temporal", "workflow"]
1111
categories = ["development-tools"]
1212
exclude = ["machine_coverage/*"]
13-
rust-version = "1.88.0" # due to cargo msrv find
13+
# due to cargo msrv find
14+
rust-version = "1.88.0"
1415

1516
[lib]
1617

1718
[features]
18-
default = []
19+
default = ["envconfig", "prometheus"]
20+
envconfig = ["temporalio-client/envconfig", "temporalio-common/envconfig"]
21+
prometheus = ["temporalio-common/prometheus"]
1922
otel = [
2023
"dep:opentelemetry",
2124
"dep:opentelemetry_sdk",
@@ -95,7 +98,12 @@ tokio = { version = "1.47", default-features = false, features = [
9598
] }
9699
tokio-util = { version = "0.7", features = ["io", "io-util"] }
97100
tokio-stream = { version = "0.1", default-features = false }
98-
tonic = { workspace = true, default-features = false, features = ["tls-ring", "tls-native-roots", "transport", "codegen"] }
101+
tonic = { workspace = true, default-features = false, features = [
102+
"tls-ring",
103+
"tls-native-roots",
104+
"transport",
105+
"codegen",
106+
] }
99107
tracing = "0.1"
100108
url = "2.5"
101109
uuid = { version = "1.18", default-features = false, features = ["v4"] }
@@ -110,11 +118,13 @@ zip = { version = "8.4", optional = true, default-features = false, features = [
110118
[dependencies.temporalio-common]
111119
path = "../common"
112120
version = "0.3"
113-
features = ["core-based-sdk", "history_builders", "test-utilities"]
121+
default-features = false
122+
features = ["core-telemetry-bridge", "history_builders"]
114123

115124
[dependencies.temporalio-client]
116125
path = "../client"
117126
version = "0.3"
127+
default-features = false
118128
features = ["core-based-sdk"]
119129

120130
[dependencies.temporalio-macros]
@@ -139,6 +149,9 @@ hyper-util = { version = "0.1", features = [
139149
rstest = "0.26"
140150
semver = "1.0"
141151
temporalio-sdk = { path = "../sdk" }
152+
temporalio-common = { path = "../common", version = "0.3", default-features = false, features = [
153+
"test-utilities",
154+
] }
142155
tokio = { version = "1.47", default-features = false, features = [
143156
"rt",
144157
"rt-multi-thread",

crates/sdk/Cargo.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ default-features = false
4646
[dependencies.temporalio-common]
4747
path = "../common"
4848
version = "0.3"
49+
default-features = false
4950

5051
[dependencies.temporalio-client]
5152
path = "../client"
5253
version = "0.3"
54+
default-features = false
5355

5456
[dependencies.temporalio-macros]
5557
path = "../macros"
@@ -60,9 +62,11 @@ futures = "0.3"
6062
rstest = "0.26"
6163

6264
[features]
63-
default = []
64-
antithesis_assertions = ["temporalio-sdk-core/antithesis_assertions"]
65-
examples = ["serde/derive", "dep:serde_json"]
65+
default = ["envconfig", "prometheus"]
66+
envconfig = ["temporalio-sdk-core/envconfig"]
67+
prometheus = ["temporalio-sdk-core/prometheus"]
68+
otel = ["temporalio-sdk-core/otel"]
69+
examples = ["serde/derive", "dep:serde_json", "envconfig"]
6670

6771
[dependencies.serde_json]
6872
version = "1"

crates/sdk/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,22 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
107107
}
108108
```
109109

110+
## Crate Features
111+
112+
The SDK enables a few convenience integrations by default. Users who want a smaller dependency
113+
graph can disable defaults and opt back into the integrations they use:
114+
115+
```toml
116+
temporalio-sdk = { version = "0.3", default-features = false, features = ["envconfig"] }
117+
```
118+
119+
- `envconfig` - enabled by default. Adds `ClientOptions::load_from_config` and related helpers for
120+
loading connection settings from environment variables and `temporal.toml` files.
121+
- `prometheus` - enabled by default. Adds the Prometheus metrics exporter in
122+
`temporalio_common::telemetry` for serving SDK metrics from a HTTP endpoint.
123+
- `otel` - optional. Adds the OpenTelemetry metrics exporter in `temporalio_common::telemetry` for
124+
sending SDK metrics to an OpenTelemetry collector.
125+
110126
## Workflows in detail
111127

112128
Workflows are the core abstraction in Temporal. They are defined as structs with associated methods:

0 commit comments

Comments
 (0)