Skip to content
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

Initial commit for logging all metaflow exceptions #2106

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions metaflow/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,13 @@ def start(
ctx.obj.monitor.start()
_system_monitor.init_system_monitor(ctx.obj.flow.name, ctx.obj.monitor)

current._update_env(
{
"system_logger": _system_logger,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you help me with an example of how this is consumed? happy to chat on slack too.

"system_monitor": _system_monitor,
}
)

ctx.obj.metadata = [m for m in METADATA_PROVIDERS if m.TYPE == metadata][0](
ctx.obj.environment, ctx.obj.flow, ctx.obj.event_logger, ctx.obj.monitor
)
Expand Down
16 changes: 16 additions & 0 deletions metaflow/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ class MetaflowException(Exception):
def __init__(self, msg="", lineno=None):
self.message = msg
self.line_no = lineno

# We can do this check only if a config like METAFLOW_LOG_EXCEPTIONS is set
from metaflow import current

if hasattr(current, "system_logger") and hasattr(current, "system_monitor"):
# Wait for the system logger and monitor to be initialized
from metaflow.system import _system_logger, _system_monitor

with _system_monitor.count("metaflow.exception"):
_system_logger.log_event(
level="error",
module="metaflow.exception",
name=self.__class__.__name__,
payload={"msg": msg},
)

super(MetaflowException, self).__init__()

def __str__(self):
Expand Down
7 changes: 7 additions & 0 deletions metaflow/system/system_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,18 @@ def _init_logger_outside_flow(self):
from .system_utils import init_environment_outside_flow
from metaflow.plugins import LOGGING_SIDECARS
from metaflow.metaflow_config import DEFAULT_EVENT_LOGGER
from metaflow.metaflow_current import current

self._flow_name = "not_a_real_flow"
_flow = DummyFlow(self._flow_name)
_environment = init_environment_outside_flow(_flow)
_logger = LOGGING_SIDECARS[DEFAULT_EVENT_LOGGER](_flow, _environment)

current._update_env(
{
"system_logger": self,
}
)
return _logger

@property
Expand Down
6 changes: 6 additions & 0 deletions metaflow/system/system_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,17 @@ def _init_system_monitor_outside_flow(self):
from .system_utils import init_environment_outside_flow
from metaflow.plugins import MONITOR_SIDECARS
from metaflow.metaflow_config import DEFAULT_MONITOR
from metaflow.metaflow_current import current

self._flow_name = "not_a_real_flow"
_flow = DummyFlow(self._flow_name)
_environment = init_environment_outside_flow(_flow)
_monitor = MONITOR_SIDECARS[DEFAULT_MONITOR](_flow, _environment)
current._update_env(
{
"system_monitor": self,
}
)
return _monitor

@property
Expand Down
Loading