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

feat(ingest): various logging improvements #11126

Merged
merged 1 commit into from
Aug 9, 2024
Merged
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
2 changes: 2 additions & 0 deletions metadata-ingestion/src/datahub/ingestion/sink/datahub_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ def _write_done_callback(
record_urn = _get_urn(record_envelope)
if record_urn:
e.info["urn"] = record_urn
if workunit_id := record_envelope.metadata.get("workunit_id"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

ayy python 3.8

e.info["workunit_id"] = workunit_id
Comment on lines +205 to +206
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure metadata key existence before accessing.

The code assumes the existence of the workunit_id key in record_envelope.metadata. Consider using get to safely access the key and handle cases where it might not exist.

workunit_id = record_envelope.metadata.get("workunit_id")
if workunit_id:
    e.info["workunit_id"] = workunit_id


if not self.treat_errors_as_warnings:
self.report.report_failure({"error": e.message, "info": e.info})
Expand Down
14 changes: 11 additions & 3 deletions metadata-ingestion/src/datahub/telemetry/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def init_tracking(self) -> None:
if not self.enabled or self.mp is None or self.tracking_init is True:
return

logger.debug("Sending init Telemetry")
logger.debug("Sending init telemetry")
try:
self.mp.people_set(
self.client_id,
Expand All @@ -310,13 +310,21 @@ def ping(
if not self.enabled or self.mp is None:
return

properties = properties or {}

# send event
try:
logger.debug(f"Sending telemetry for {event_name}")
if event_name == "function-call":
logger.debug(
f"Sending telemetry for {event_name} {properties.get('function')}, status {properties.get('status')}"
)
else:
logger.debug(f"Sending telemetry for {event_name}")

properties = {
**_default_telemetry_properties(),
**self._server_props(server),
**(properties or {}),
**properties,
}
self.mp.track(self.client_id, event_name, properties)
except Exception as e:
Expand Down
5 changes: 5 additions & 0 deletions metadata-ingestion/src/datahub/utilities/logging_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
"acryl_datahub_cloud",
]
IN_MEMORY_LOG_BUFFER_SIZE = 2000 # lines
IN_MEMORY_LOG_BUFFER_MAX_LINE_LENGTH = 2000 # characters

Comment on lines +38 to +39
Copy link
Contributor

Choose a reason for hiding this comment

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

Define IN_MEMORY_LOG_BUFFER_MAX_LINE_LENGTH as a configurable parameter.

Consider making IN_MEMORY_LOG_BUFFER_MAX_LINE_LENGTH configurable through an environment variable or configuration file to allow flexibility in adjusting the log line length limit without modifying the code.

IN_MEMORY_LOG_BUFFER_MAX_LINE_LENGTH = int(os.getenv("LOG_BUFFER_MAX_LINE_LENGTH", 2000))


NO_COLOR = os.environ.get("NO_COLOR", False)

Expand Down Expand Up @@ -159,6 +161,9 @@ def __init__(self, maxlen: Optional[int] = None) -> None:
self._buffer: Deque[str] = collections.deque(maxlen=maxlen)

def write(self, line: str) -> None:
if len(line) > IN_MEMORY_LOG_BUFFER_MAX_LINE_LENGTH:
line = line[:IN_MEMORY_LOG_BUFFER_MAX_LINE_LENGTH] + "[truncated]"

self._buffer.append(line)

def clear(self) -> None:
Expand Down
Loading