-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Log forwarding #405
Closed
Closed
Log forwarding #405
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,9 +8,9 @@ | |||||
from dataclasses import dataclass, field | ||||||
from datetime import timedelta | ||||||
from enum import Enum | ||||||
from typing import ClassVar, Mapping, NewType, Optional, Sequence, Union | ||||||
from typing import Any, ClassVar, Dict, Mapping, NewType, Optional, Sequence, Union | ||||||
|
||||||
from typing_extensions import Literal, Protocol | ||||||
from typing_extensions import Protocol | ||||||
|
||||||
import temporalio.bridge.metric | ||||||
import temporalio.bridge.runtime | ||||||
|
@@ -70,6 +70,8 @@ def __init__(self, *, telemetry: TelemetryConfig) -> None: | |||||
self._core_runtime = temporalio.bridge.runtime.Runtime( | ||||||
telemetry=telemetry._to_bridge_config() | ||||||
) | ||||||
if telemetry.logging and isinstance(telemetry.logging.buffer, LogBuffer): | ||||||
telemetry.logging.buffer._runtime = self | ||||||
if isinstance(telemetry.metrics, MetricBuffer): | ||||||
telemetry.metrics._runtime = self | ||||||
core_meter = temporalio.bridge.metric.MetricMeter.create(self._core_runtime) | ||||||
|
@@ -114,6 +116,10 @@ class LoggingConfig: | |||||
filter: Union[TelemetryFilter, str] | ||||||
"""Filter for logging. Can use :py:class:`TelemetryFilter` or raw string.""" | ||||||
|
||||||
buffer: Optional[LogBuffer] = None | ||||||
"""Buffer to send logs too. If set, logs are sent to this buffer instead of | ||||||
console.""" | ||||||
|
||||||
default: ClassVar[LoggingConfig] | ||||||
"""Default logging configuration of Core WARN level and other ERROR | ||||||
level. | ||||||
|
@@ -124,8 +130,7 @@ def _to_bridge_config(self) -> temporalio.bridge.runtime.LoggingConfig: | |||||
filter=self.filter | ||||||
if isinstance(self.filter, str) | ||||||
else self.filter.formatted(), | ||||||
# Log forwarding not currently supported in Python | ||||||
forward=False, | ||||||
forward=self.buffer is not None, | ||||||
) | ||||||
|
||||||
|
||||||
|
@@ -220,6 +225,93 @@ def retrieve_updates(self) -> Sequence[BufferedMetricUpdate]: | |||||
return self._runtime._core_runtime.retrieve_buffered_metrics() | ||||||
|
||||||
|
||||||
class LogBuffer: | ||||||
"""A buffer that can be set on :py:class:`LoggnigConfig` to record logs | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
instead of having them sent to console. | ||||||
|
||||||
.. warning:: | ||||||
It is important that :py:meth:`retrieve_logs` is called regularly to | ||||||
drain the buffer or log entries may be lost. | ||||||
""" | ||||||
|
||||||
def __init__(self) -> None: | ||||||
"""Create a log buffer.""" | ||||||
self._runtime: Optional[Runtime] = None | ||||||
|
||||||
def retrieve_logs(self) -> Sequence[BufferedLogEntry]: | ||||||
"""Drain the buffer and return all log entries. | ||||||
|
||||||
.. warning:: | ||||||
It is important that this is called regularly. See | ||||||
:py:class:`LogBuffer` warning. | ||||||
|
||||||
Returns: | ||||||
A sequence of log entries. | ||||||
""" | ||||||
if not self._runtime: | ||||||
raise RuntimeError("Attempting to retrieve logs before runtime created") | ||||||
return self._runtime._core_runtime.retrieve_buffered_logs() | ||||||
|
||||||
|
||||||
BufferedLogLevel = NewType("BufferedLogLevel", str) | ||||||
"""Representation of a log level for a buffered log entry.""" | ||||||
|
||||||
BUFFERED_LOG_LEVEL_TRACE = BufferedLogLevel("TRACE") | ||||||
"""Trace log level.""" | ||||||
|
||||||
BUFFERED_LOG_LEVEL_DEBUG = BufferedLogLevel("DEBUG") | ||||||
"""Debug log level.""" | ||||||
|
||||||
BUFFERED_LOG_LEVEL_INFO = BufferedLogLevel("INFO") | ||||||
"""Info log level.""" | ||||||
|
||||||
BUFFERED_LOG_LEVEL_WARN = BufferedLogLevel("WARN") | ||||||
"""Warn log level.""" | ||||||
|
||||||
BUFFERED_LOG_LEVEL_ERROR = BufferedLogLevel("ERROR") | ||||||
"""Error log level.""" | ||||||
|
||||||
|
||||||
# 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 timestamp_millis(self) -> int: | ||||||
"""Milliseconds since Unix epoch.""" | ||||||
... | ||||||
|
||||||
@property | ||||||
def level(self) -> BufferedLogLevel: | ||||||
"""Log level.""" | ||||||
... | ||||||
|
||||||
@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. | ||||||
""" | ||||||
... | ||||||
|
||||||
|
||||||
@dataclass(frozen=True) | ||||||
class TelemetryConfig: | ||||||
"""Configuration for Core telemetry.""" | ||||||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nifty