From dbf96fdbd5edb3dcb0da0590de6e3dd5b4bc270b Mon Sep 17 00:00:00 2001 From: Yaroslav Taben Date: Mon, 3 Apr 2023 13:17:06 -0400 Subject: [PATCH] Pass through global telemetry tags (#303) --- temporalio/bridge/runtime.py | 1 + temporalio/bridge/src/runtime.rs | 4 ++++ temporalio/runtime.py | 6 +++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/temporalio/bridge/runtime.py b/temporalio/bridge/runtime.py index af1230d0..bf4aa65a 100644 --- a/temporalio/bridge/runtime.py +++ b/temporalio/bridge/runtime.py @@ -73,3 +73,4 @@ class TelemetryConfig: tracing: Optional[TracingConfig] logging: Optional[LoggingConfig] metrics: Optional[MetricsConfig] + global_tags: Mapping[str, str] diff --git a/temporalio/bridge/src/runtime.rs b/temporalio/bridge/src/runtime.rs index 7b1978c9..158e5530 100644 --- a/temporalio/bridge/src/runtime.rs +++ b/temporalio/bridge/src/runtime.rs @@ -30,6 +30,7 @@ pub struct TelemetryConfig { tracing: Option, logging: Option, metrics: Option, + global_tags: Option> } #[derive(FromPyObject)] @@ -129,6 +130,9 @@ impl TryFrom for TelemetryOptions { )); }); } + if let Some(v) = conf.global_tags { + build.global_tags(v); + } build .build() .map_err(|err| PyValueError::new_err(format!("Invalid telemetry config: {}", err))) diff --git a/temporalio/runtime.py b/temporalio/runtime.py index c1251335..65ec3bef 100644 --- a/temporalio/runtime.py +++ b/temporalio/runtime.py @@ -5,7 +5,7 @@ from __future__ import annotations -from dataclasses import dataclass +from dataclasses import dataclass, field from datetime import timedelta from typing import ClassVar, Mapping, Optional, Union @@ -175,6 +175,9 @@ class TelemetryConfig: metrics: Optional[Union[OpenTelemetryConfig, PrometheusConfig]] = None """Metrics configuration.""" + global_tags: Mapping[str, str] = field(default_factory=dict) + """OTel resource tags to be applied to all metrics and traces""" + def _to_bridge_config(self) -> temporalio.bridge.runtime.TelemetryConfig: return temporalio.bridge.runtime.TelemetryConfig( tracing=None if not self.tracing else self.tracing._to_bridge_config(), @@ -189,4 +192,5 @@ def _to_bridge_config(self) -> temporalio.bridge.runtime.TelemetryConfig: if not isinstance(self.metrics, PrometheusConfig) else self.metrics._to_bridge_config(), ), + global_tags=self.global_tags, )