forked from temporalio/sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime.py
More file actions
130 lines (95 loc) · 3.79 KB
/
Copy pathruntime.py
File metadata and controls
130 lines (95 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
"""Telemetry for SDK Core. (unstable)
Nothing in this module should be considered stable. The API may change.
"""
from __future__ import annotations
from dataclasses import dataclass
from typing import Any, Callable, Dict, Mapping, Optional, Sequence, Type
from typing_extensions import Protocol
import temporalio.bridge.temporal_sdk_bridge
class Runtime:
"""Runtime for SDK Core."""
@staticmethod
def _raise_in_thread(thread_id: int, exc_type: Type[BaseException]) -> bool:
"""Internal helper for raising an exception in thread."""
return temporalio.bridge.temporal_sdk_bridge.raise_in_thread(
thread_id, exc_type
)
def __init__(self, *, telemetry: TelemetryConfig) -> None:
"""Create SDK Core runtime."""
self._ref = temporalio.bridge.temporal_sdk_bridge.init_runtime(telemetry)
def retrieve_buffered_metrics(self, durations_as_seconds: bool) -> Sequence[Any]:
"""Get buffered metrics."""
return self._ref.retrieve_buffered_metrics(durations_as_seconds)
def write_test_info_log(self, message: str, extra_data: str) -> None:
"""Write a test core log at INFO level."""
self._ref.write_test_info_log(message, extra_data)
def write_test_debug_log(self, message: str, extra_data: str) -> None:
"""Write a test core log at DEBUG level."""
self._ref.write_test_debug_log(message, extra_data)
@dataclass(frozen=True)
class LoggingConfig:
"""Python representation of the Rust struct for logging config."""
filter: str
forward_to: Optional[Callable[[Sequence[BufferedLogEntry]], None]]
@dataclass(frozen=True)
class MetricsConfig:
"""Python representation of the Rust struct for metrics config."""
opentelemetry: Optional[OpenTelemetryConfig]
prometheus: Optional[PrometheusConfig]
buffered_with_size: int
attach_service_name: bool
global_tags: Optional[Mapping[str, str]]
metric_prefix: Optional[str]
@dataclass(frozen=True)
class OpenTelemetryConfig:
"""Python representation of the Rust struct for OpenTelemetry config."""
url: str
headers: Mapping[str, str]
metric_periodicity_millis: Optional[int]
metric_temporality_delta: bool
durations_as_seconds: bool
http: bool
@dataclass(frozen=True)
class PrometheusConfig:
"""Python representation of the Rust struct for Prometheus config."""
bind_address: str
counters_total_suffix: bool
unit_suffix: bool
durations_as_seconds: bool
histogram_bucket_overrides: Optional[Mapping[str, Sequence[float]]] = None
@dataclass(frozen=True)
class TelemetryConfig:
"""Python representation of the Rust struct for telemetry config."""
logging: Optional[LoggingConfig]
metrics: Optional[MetricsConfig]
# WARNING: This must match Rust runtime::BufferedLogEntry
class BufferedLogEntry(Protocol):
"""A buffered log entry."""
@property
def target(self) -> str:
"""Target category for the log entry."""
...
@property
def message(self) -> str:
"""Log message."""
...
@property
def time(self) -> float:
"""Time as from ``time.time`` since Unix epoch."""
...
@property
def level(self) -> int:
"""Python log level, with trace as 9."""
...
@property
def fields(self) -> Dict[str, Any]:
"""Additional log entry fields.
Requesting this property performs a conversion from the internal
representation to the Python representation on every request. Therefore
callers should store the result instead of repeatedly calling.
Raises:
Exception: If the internal representation cannot be converted. This
should not happen and if it does it is considered a bug in the
SDK and should be reported.
"""
...