Skip to content

Commit

Permalink
fix logging of extra metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
jgbradley1 committed Jan 27, 2025
1 parent 46b2a8c commit c6ad3f6
Showing 1 changed file with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _format_details(self, details: Dict[str, Any] | None = None) -> Dict[str, An
"""
if not isinstance(details, dict) or (details is None):
return {}
return {"custom_dimensions": {**self._properties, **unwrap_dict(details)}}
return {**self._properties, **unwrap_dict(details)}

def workflow_start(self, name: str, instance: object) -> None:
"""Execute this callback when a workflow starts."""
Expand All @@ -101,10 +101,7 @@ def workflow_start(self, name: str, instance: object) -> None:
else ""
) # will take the form "(1/4)"
message += f"Workflow{workflow_progress}: {name} started."
details = {
"workflow_name": name,
# "workflow_instance": str(instance),
}
details = {"workflow_name": name}
if self._index_name:
details["index_name"] = self._index_name
self._logger.info(
Expand All @@ -120,10 +117,7 @@ def workflow_end(self, name: str, instance: object) -> None:
else ""
) # will take the form "(1/4)"
message += f"Workflow{workflow_progress}: {name} complete."
details = {
"workflow_name": name,
# "workflow_instance": str(instance),
}
details = {"workflow_name": name}
if self._index_name:
details["index_name"] = self._index_name
self._logger.info(
Expand All @@ -135,10 +129,9 @@ def error(
message: str,
cause: Optional[BaseException] = None,
stack: Optional[str] = None,
details: Optional[dict] = None,
details: Optional[dict] = {},
) -> None:
"""A call back handler for when an error occurs."""
details = {} if details is None else details
details = {"cause": str(cause), "stack": stack, **details}
self._logger.error(
message,
Expand All @@ -162,7 +155,7 @@ def log(self, message: str, details: Optional[dict] = None) -> None:

def unwrap_dict(input_dict, parent_key="", sep="_"):
"""
Recursively unwraps a nested dictionary by flattening it into a single-level dictionary.
Recursively unwrap/flatten a dictionary.
Args:
input_dict (dict): The input dictionary to be unwrapped.
Expand Down

0 comments on commit c6ad3f6

Please sign in to comment.