Skip to content

Commit

Permalink
Pass through global telemetry tags (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
ytaben authored Apr 3, 2023
1 parent 4ad2e64 commit dbf96fd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions temporalio/bridge/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,4 @@ class TelemetryConfig:
tracing: Optional[TracingConfig]
logging: Optional[LoggingConfig]
metrics: Optional[MetricsConfig]
global_tags: Mapping[str, str]
4 changes: 4 additions & 0 deletions temporalio/bridge/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct TelemetryConfig {
tracing: Option<TracingConfig>,
logging: Option<LoggingConfig>,
metrics: Option<MetricsConfig>,
global_tags: Option<HashMap<String, String>>
}

#[derive(FromPyObject)]
Expand Down Expand Up @@ -129,6 +130,9 @@ impl TryFrom<TelemetryConfig> 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)))
Expand Down
6 changes: 5 additions & 1 deletion temporalio/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(),
Expand All @@ -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,
)

0 comments on commit dbf96fd

Please sign in to comment.