Skip to content

Commit afdc280

Browse files
authored
feat: expose runtime environment info option (temporalio#1747)
1 parent 6d1c6a4 commit afdc280

5 files changed

Lines changed: 38 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ to include examples, links to docs, or any other relevant information.
2020

2121
### Added
2222

23+
- Added the `Runtime(disable_environment_info=...)` option to control whether
24+
runtime, hosting, and platform information is included in worker heartbeats.
25+
2326
- `temporalio.workflow.uuid7()` generates a determinism-safe, time-sortable
2427
UUIDv7 (RFC 9562) from workflow time and the workflow's deterministic random
2528
generator, complementing the existing `workflow.uuid4()`

temporalio/bridge/runtime.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class RuntimeOptions:
9999

100100
telemetry: TelemetryConfig
101101
worker_heartbeat_interval_millis: int | None = 60_000 # 60s
102+
disable_environment_info: bool = False
102103

103104

104105
# WARNING: This must match Rust runtime::BufferedLogEntry

temporalio/bridge/src/runtime.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ pub struct PrometheusConfig {
9191
pub struct RuntimeOptions {
9292
telemetry: TelemetryConfig,
9393
worker_heartbeat_interval_millis: Option<u64>,
94+
disable_environment_info: bool,
9495
}
9596

9697
const FORWARD_LOG_BUFFER_SIZE: usize = 2048;
@@ -100,6 +101,7 @@ pub fn init_runtime(options: RuntimeOptions) -> PyResult<RuntimeRef> {
100101
let RuntimeOptions {
101102
telemetry: TelemetryConfig { logging, metrics },
102103
worker_heartbeat_interval_millis,
104+
disable_environment_info,
103105
} = options;
104106

105107
// Have to build/start telemetry config pieces
@@ -134,6 +136,7 @@ pub fn init_runtime(options: RuntimeOptions) -> PyResult<RuntimeRef> {
134136
.build(),
135137
)
136138
.heartbeat_interval(worker_heartbeat_interval_millis.map(Duration::from_millis))
139+
.disable_environment_info(disable_environment_info)
137140
.build()
138141
.map_err(|err| PyValueError::new_err(format!("Invalid runtime options: {err}")))?;
139142

temporalio/runtime.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def __init__(
118118
*,
119119
telemetry: TelemetryConfig,
120120
worker_heartbeat_interval: timedelta | None = timedelta(seconds=60),
121+
disable_environment_info: bool = False,
121122
) -> None:
122123
"""Create a runtime with the provided configuration.
123124
@@ -128,6 +129,8 @@ def __init__(
128129
``runtime_options``.
129130
worker_heartbeat_interval: Interval for worker heartbeats. ``None``
130131
disables heartbeating. Interval must be between 1s and 60s.
132+
disable_environment_info: Whether to omit runtime, hosting, and
133+
platform information from worker heartbeats.
131134
132135
Raises:
133136
ValueError: If both ```runtime_options`` is a negative value.
@@ -142,6 +145,7 @@ def __init__(
142145
runtime_options = temporalio.bridge.runtime.RuntimeOptions(
143146
telemetry=telemetry._to_bridge_config(),
144147
worker_heartbeat_interval_millis=heartbeat_millis,
148+
disable_environment_info=disable_environment_info,
145149
)
146150

147151
self._core_runtime = temporalio.bridge.runtime.Runtime(options=runtime_options)

tests/test_runtime.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
import pytest
1111

12+
import temporalio.bridge.metric
13+
import temporalio.bridge.runtime
1214
from temporalio import workflow
1315
from temporalio.client import Client
1416
from temporalio.runtime import (
@@ -369,6 +371,31 @@ def test_runtime_options_invalid_heartbeat() -> None:
369371
)
370372

371373

374+
def test_runtime_environment_info_option(monkeypatch: pytest.MonkeyPatch) -> None:
375+
captured_options = []
376+
377+
class MockRuntime:
378+
def __init__(self, *, options: Any) -> None:
379+
captured_options.append(options)
380+
381+
monkeypatch.setattr(temporalio.bridge.runtime, "Runtime", MockRuntime)
382+
monkeypatch.setattr(
383+
temporalio.bridge.metric.MetricMeter, "create", staticmethod(lambda _: None)
384+
)
385+
386+
Runtime(telemetry=TelemetryConfig())
387+
Runtime(telemetry=TelemetryConfig(), disable_environment_info=True)
388+
389+
assert [option.disable_environment_info for option in captured_options] == [
390+
False,
391+
True,
392+
]
393+
394+
395+
def test_runtime_environment_info_can_be_enabled() -> None:
396+
Runtime(telemetry=TelemetryConfig(), disable_environment_info=False)
397+
398+
372399
def test_runtime_ref_creates_default():
373400
ref = _RuntimeRef()
374401
assert not ref._default_runtime

0 commit comments

Comments
 (0)