Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ to include examples, links to docs, or any other relevant information.

### Added

- Added `LoggingConfig.format` to select compact, pretty, or newline-delimited JSON output for
Core logs written to the console.

- Added the `Runtime(disable_environment_info=...)` option to control whether
runtime, hosting, and platform information is included in worker heartbeats.

Expand Down
13 changes: 13 additions & 0 deletions temporalio/bridge/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions temporalio/bridge/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class LoggingConfig:

filter: str
forward_to: Callable[[Sequence[BufferedLogEntry]], None] | None
format: str | None


@dataclass(frozen=True)
Expand Down
14 changes: 12 additions & 2 deletions temporalio/bridge/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use temporalio_common::telemetry::metrics::core::MetricCallBufferer;
use temporalio_common::telemetry::metrics::CoreMeter;
use temporalio_common::telemetry::{
build_otlp_metric_exporter, start_prometheus_metric_exporter, CoreLog, CoreLogStreamConsumer,
Logger, MetricTemporality, OtelCollectorOptions, OtlpProtocol, PrometheusExporterOptions,
TelemetryOptions,
Logger, LoggerFormat, MetricTemporality, OtelCollectorOptions, OtlpProtocol,
PrometheusExporterOptions, TelemetryOptions,
};
use temporalio_sdk_core::telemetry::MetricsCallBuffer;
use temporalio_sdk_core::{CoreRuntime, TokioRuntimeBuilder};
Expand Down Expand Up @@ -48,6 +48,7 @@ pub struct TelemetryConfig {
pub struct LoggingConfig {
filter: String,
forward_to: Option<Py<PyAny>>,
format: Option<String>,
}

#[pyclass]
Expand Down Expand Up @@ -121,6 +122,15 @@ pub fn init_runtime(options: RuntimeOptions) -> PyResult<RuntimeRef> {
} else {
Logger::Console {
filter: logging_conf.filter.to_string(),
format: logging_conf
.format
.map(|format| match format.as_str() {
"compact" => Ok(LoggerFormat::Compact),
"pretty" => Ok(LoggerFormat::Pretty),
"json" => Ok(LoggerFormat::Json),
_ => Err(PyValueError::new_err("Unrecognized logging format")),
})
.transpose()?,
}
})
} else {
Expand Down
15 changes: 15 additions & 0 deletions temporalio/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ def formatted(self) -> str:
return ",".join(parts)


class LoggingFormat(Enum):
"""Format for Core logs written to the console."""

COMPACT = "compact"
PRETTY = "pretty"
JSON = "json"


@dataclass(frozen=True)
class LoggingConfig:
"""Configuration for runtime logging."""
Expand All @@ -207,6 +215,12 @@ class LoggingConfig:
See the :py:class:`LogForwardingConfig` docs for more info.
"""

format: LoggingFormat | None = None
"""Format for Core logs written to the console. This is ignored when
:py:attr:`forwarding` is set. If unset, Core preserves its existing output
selection, including ``TEMPORAL_CORE_PRETTY_LOGS`` support.
"""

default: ClassVar[LoggingConfig]
"""Default logging configuration of Core WARN level and other ERROR
level.
Expand All @@ -218,6 +232,7 @@ def _to_bridge_config(self) -> temporalio.bridge.runtime.LoggingConfig:
if isinstance(self.filter, str)
else self.filter.formatted(),
forward_to=None if not self.forwarding else self.forwarding._on_logs,
format=None if not self.format else self.format.value,
)


Expand Down
6 changes: 6 additions & 0 deletions tests/test_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from temporalio.runtime import (
LogForwardingConfig,
LoggingConfig,
LoggingFormat,
OpenTelemetryConfig,
PrometheusConfig,
Runtime,
Expand Down Expand Up @@ -143,6 +144,11 @@ async def log_queue_len() -> int:
)


def test_runtime_console_logging_format():
config = LoggingConfig(filter="INFO", format=LoggingFormat.JSON)._to_bridge_config()
assert config.format == "json"


@workflow.defn
class TaskFailWorkflow:
@workflow.run
Expand Down
Loading