-
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
Sdk core related updates #191
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
539289b
Update core
cretz 8bde477
Disable eager activity support
cretz 0e1d2a2
Allow changing client headers
cretz 4adf1ac
Update core, move to using runtime
cretz 29e80ec
Several Rust updates/fixes
cretz 0cfd8fb
Merge remote-tracking branch 'remotes/origin/main' into sdk-core-upgrade
cretz c357de4
Test fixes
cretz 07eaf36
Minor doc update
cretz 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
126 changes: 64 additions & 62 deletions
126
temporalio/bridge/proto/workflow_commands/workflow_commands_pb2.py
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
"""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 ClassVar, Mapping, Optional | ||
|
||
import temporalio.bridge.temporal_sdk_bridge | ||
|
||
_default_runtime: Optional[Runtime] = None | ||
|
||
|
||
class Runtime: | ||
"""Runtime for SDK Core. | ||
|
||
Users are encouraged to use :py:meth:`default`. It can be set with | ||
:py:meth:`set_default`. | ||
""" | ||
|
||
@staticmethod | ||
def default() -> Runtime: | ||
"""Get the default runtime, creating if not already created. | ||
|
||
If the default runtime needs to be different, it should be done with | ||
:py:meth:`set_default` before this is called or ever used. | ||
|
||
Returns: | ||
The default runtime. | ||
""" | ||
global _default_runtime | ||
if not _default_runtime: | ||
_default_runtime = Runtime(telemetry=TelemetryConfig()) | ||
return _default_runtime | ||
|
||
@staticmethod | ||
def set_default(runtime: Runtime, *, error_if_already_set: bool = True) -> None: | ||
"""Set the default runtime to the given runtime. | ||
|
||
This should be called before any Temporal client is created, but can | ||
change the existing one. Any clients and workers created with the | ||
previous runtime will stay on that runtime. | ||
|
||
Args: | ||
runtime: The runtime to set. | ||
error_if_already_set: If True and default is already set, this will | ||
raise a RuntimeError. | ||
""" | ||
global _default_runtime | ||
if _default_runtime and error_if_already_set: | ||
raise RuntimeError("Runtime default already set") | ||
_default_runtime = runtime | ||
|
||
def __init__(self, *, telemetry: TelemetryConfig) -> None: | ||
"""Create a default runtime with the given telemetry config.""" | ||
self._ref = temporalio.bridge.temporal_sdk_bridge.init_runtime(telemetry) | ||
|
||
|
||
def format_filter(core_level: str, other_level: str) -> str: | ||
"""Helper to build a filter from Core and other level. | ||
|
||
Levels can be ``ERROR``, ``WARN``, ``INFO``, ``DEBUG``, or ``TRACE``. | ||
|
||
Args: | ||
core_level: Level for SDK Core. | ||
other_level: Level for other things besides Core. | ||
|
||
Returns: | ||
Formatted string for use as a ``filter`` in telemetry configs. | ||
""" | ||
return f"{other_level},temporal_sdk_core={core_level},temporal_client={core_level},temporal_sdk={core_level}" | ||
|
||
|
||
@dataclass(frozen=True) | ||
class TracingConfig: | ||
"""Configuration for Core tracing.""" | ||
|
||
filter: str | ||
"""Filter string for tracing. Use :py:func:`format_filter`.""" | ||
|
||
opentelemetry: OpenTelemetryConfig | ||
"""Configuration for OpenTelemetry tracing collector.""" | ||
|
||
|
||
@dataclass(frozen=True) | ||
class LoggingConfig: | ||
"""Configuration for Core logging.""" | ||
|
||
filter: str | ||
"""Filter string for logging. Use :py:func:`format_filter`.""" | ||
|
||
forward: bool = False | ||
"""If true, logs are not on console but instead forwarded.""" | ||
|
||
default: ClassVar[LoggingConfig] | ||
"""Default logging configuration of Core WARN level and other ERROR | ||
level. | ||
""" | ||
|
||
|
||
LoggingConfig.default = LoggingConfig(filter=format_filter("WARN", "ERROR")) | ||
|
||
|
||
@dataclass(frozen=True) | ||
class MetricsConfig: | ||
"""Configuration for Core metrics. | ||
|
||
One and only one of :py:attr:`opentelemetry` or :py:attr:`prometheus` must | ||
be set. | ||
""" | ||
|
||
opentelemetry: Optional[OpenTelemetryConfig] = None | ||
"""Configuration for OpenTelemetry metrics collector.""" | ||
|
||
prometheus: Optional[PrometheusConfig] = None | ||
"""Configuration for Prometheus metrics endpoint.""" | ||
|
||
|
||
@dataclass(frozen=True) | ||
class OpenTelemetryConfig: | ||
"""Configuration for OpenTelemetry collector.""" | ||
|
||
url: str | ||
headers: Mapping[str, str] | ||
|
||
|
||
@dataclass(frozen=True) | ||
class PrometheusConfig: | ||
"""Configuration for Prometheus metrics endpoint.""" | ||
|
||
bind_address: str | ||
|
||
|
||
@dataclass(frozen=True) | ||
class TelemetryConfig: | ||
"""Configuration for Core telemetry.""" | ||
|
||
tracing: Optional[TracingConfig] = None | ||
"""Tracing configuration.""" | ||
|
||
logging: Optional[LoggingConfig] = LoggingConfig.default | ||
"""Logging configuration.""" | ||
|
||
metrics: Optional[PrometheusConfig] = None | ||
"""Metrics configuration.""" |
Submodule sdk-core
updated
66 files
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.
Are we exposing this to users?
forward
isn't implemented for Python.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.
This entire
temporalio.bridge
bridge package (and children) is marked "unstable" because I knew this type of change was coming and future changes may come. Now that we have a concept of a "runtime" I do want to have a discussion about solidifying runtime/telemetry API outside oftemporalio.bridge
. Included in that discussion is whether to support forwarding and how. In the meantime, I just mirrored core options even though we don't expose the forwarded logs themselves (yet).